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
& ~CHAR_MODIFIER_MASK
) == '?')
1496 return 0177 | (c
& CHAR_MODIFIER_MASK
);
1497 else if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
1498 return c
| ctrl_modifier
;
1499 /* ASCII control chars are made from letters (both cases),
1500 as well as the non-letters within 0100...0137. */
1501 else if ((c
& 0137) >= 0101 && (c
& 0137) <= 0132)
1502 return (c
& (037 | ~0177));
1503 else if ((c
& 0177) >= 0100 && (c
& 0177) <= 0137)
1504 return (c
& (037 | ~0177));
1506 return c
| ctrl_modifier
;
1516 /* An octal escape, as in ANSI C. */
1518 register int i
= c
- '0';
1519 register int count
= 0;
1522 if ((c
= READCHAR
) >= '0' && c
<= '7')
1537 /* A hex escape, as in ANSI C. */
1543 if (c
>= '0' && c
<= '9')
1548 else if ((c
>= 'a' && c
<= 'f')
1549 || (c
>= 'A' && c
<= 'F'))
1552 if (c
>= 'a' && c
<= 'f')
1567 if (BASE_LEADING_CODE_P (c
))
1568 c
= read_multibyte (c
, readcharfun
);
1573 /* If the next token is ')' or ']' or '.', we store that character
1574 in *PCH and the return value is not interesting. Else, we store
1575 zero in *PCH and we read and return one lisp object.
1577 FIRST_IN_LIST is nonzero if this is the first element of a list. */
1580 read1 (readcharfun
, pch
, first_in_list
)
1581 register Lisp_Object readcharfun
;
1586 int uninterned_symbol
= 0;
1593 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1598 return read_list (0, readcharfun
);
1601 return read_vector (readcharfun
, 0);
1618 tmp
= read_vector (readcharfun
, 0);
1619 if (XVECTOR (tmp
)->size
< CHAR_TABLE_STANDARD_SLOTS
1620 || XVECTOR (tmp
)->size
> CHAR_TABLE_STANDARD_SLOTS
+ 10)
1621 error ("Invalid size char-table");
1622 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1623 XCHAR_TABLE (tmp
)->top
= Qt
;
1632 tmp
= read_vector (readcharfun
, 0);
1633 if (XVECTOR (tmp
)->size
!= SUB_CHAR_TABLE_STANDARD_SLOTS
)
1634 error ("Invalid size char-table");
1635 XSETCHAR_TABLE (tmp
, XCHAR_TABLE (tmp
));
1636 XCHAR_TABLE (tmp
)->top
= Qnil
;
1639 Fsignal (Qinvalid_read_syntax
,
1640 Fcons (make_string ("#^^", 3), Qnil
));
1642 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#^", 2), Qnil
));
1647 length
= read1 (readcharfun
, pch
, first_in_list
);
1651 Lisp_Object tmp
, val
;
1652 int size_in_chars
= ((XFASTINT (length
) + BITS_PER_CHAR
- 1)
1656 tmp
= read1 (readcharfun
, pch
, first_in_list
);
1657 if (size_in_chars
!= XSTRING (tmp
)->size
1658 /* We used to print 1 char too many
1659 when the number of bits was a multiple of 8.
1660 Accept such input in case it came from an old version. */
1661 && ! (XFASTINT (length
)
1662 == (XSTRING (tmp
)->size
- 1) * BITS_PER_CHAR
))
1663 Fsignal (Qinvalid_read_syntax
,
1664 Fcons (make_string ("#&...", 5), Qnil
));
1666 val
= Fmake_bool_vector (length
, Qnil
);
1667 bcopy (XSTRING (tmp
)->data
, XBOOL_VECTOR (val
)->data
,
1669 /* Clear the extraneous bits in the last byte. */
1670 if (XINT (length
) != size_in_chars
* BITS_PER_CHAR
)
1671 XBOOL_VECTOR (val
)->data
[size_in_chars
- 1]
1672 &= (1 << (XINT (length
) % BITS_PER_CHAR
)) - 1;
1675 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#&...", 5),
1680 /* Accept compiled functions at read-time so that we don't have to
1681 build them using function calls. */
1683 tmp
= read_vector (readcharfun
, 1);
1684 return Fmake_byte_code (XVECTOR (tmp
)->size
,
1685 XVECTOR (tmp
)->contents
);
1687 #ifdef USE_TEXT_PROPERTIES
1691 struct gcpro gcpro1
;
1694 /* Read the string itself. */
1695 tmp
= read1 (readcharfun
, &ch
, 0);
1696 if (ch
!= 0 || !STRINGP (tmp
))
1697 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1699 /* Read the intervals and their properties. */
1702 Lisp_Object beg
, end
, plist
;
1704 beg
= read1 (readcharfun
, &ch
, 0);
1708 end
= read1 (readcharfun
, &ch
, 0);
1710 plist
= read1 (readcharfun
, &ch
, 0);
1712 Fsignal (Qinvalid_read_syntax
,
1713 Fcons (build_string ("invalid string property list"),
1715 Fset_text_properties (beg
, end
, plist
, tmp
);
1721 /* #@NUMBER is used to skip NUMBER following characters.
1722 That's used in .elc files to skip over doc strings
1723 and function definitions. */
1728 /* Read a decimal integer. */
1729 while ((c
= READCHAR
) >= 0
1730 && c
>= '0' && c
<= '9')
1738 if (load_force_doc_strings
&& EQ (readcharfun
, Qget_file_char
))
1740 /* If we are supposed to force doc strings into core right now,
1741 record the last string that we skipped,
1742 and record where in the file it comes from. */
1744 /* But first exchange saved_doc_string
1745 with prev_saved_doc_string, so we save two strings. */
1747 char *temp
= saved_doc_string
;
1748 int temp_size
= saved_doc_string_size
;
1749 int temp_pos
= saved_doc_string_position
;
1750 int temp_len
= saved_doc_string_length
;
1752 saved_doc_string
= prev_saved_doc_string
;
1753 saved_doc_string_size
= prev_saved_doc_string_size
;
1754 saved_doc_string_position
= prev_saved_doc_string_position
;
1755 saved_doc_string_length
= prev_saved_doc_string_length
;
1757 prev_saved_doc_string
= temp
;
1758 prev_saved_doc_string_size
= temp_size
;
1759 prev_saved_doc_string_position
= temp_pos
;
1760 prev_saved_doc_string_length
= temp_len
;
1763 if (saved_doc_string_size
== 0)
1765 saved_doc_string_size
= nskip
+ 100;
1766 saved_doc_string
= (char *) xmalloc (saved_doc_string_size
);
1768 if (nskip
> saved_doc_string_size
)
1770 saved_doc_string_size
= nskip
+ 100;
1771 saved_doc_string
= (char *) xrealloc (saved_doc_string
,
1772 saved_doc_string_size
);
1775 saved_doc_string_position
= ftell (instream
);
1777 /* Copy that many characters into saved_doc_string. */
1778 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1779 saved_doc_string
[i
] = c
= READCHAR
;
1781 saved_doc_string_length
= i
;
1785 /* Skip that many characters. */
1786 for (i
= 0; i
< nskip
&& c
>= 0; i
++)
1793 return Vload_file_name
;
1795 return Fcons (Qfunction
, Fcons (read0 (readcharfun
), Qnil
));
1796 /* #:foo is the uninterned symbol named foo. */
1799 uninterned_symbol
= 1;
1803 /* Reader forms that can reuse previously read objects. */
1804 if (c
>= '0' && c
<= '9')
1809 /* Read a non-negative integer. */
1810 while (c
>= '0' && c
<= '9')
1816 /* #n=object returns object, but associates it with n for #n#. */
1819 /* Make a placeholder for #n# to use temporarily */
1820 Lisp_Object placeholder
;
1823 placeholder
= Fcons(Qnil
, Qnil
);
1824 cell
= Fcons (make_number (n
), placeholder
);
1825 read_objects
= Fcons (cell
, read_objects
);
1827 /* Read the object itself. */
1828 tem
= read0 (readcharfun
);
1830 /* Now put it everywhere the placeholder was... */
1831 substitute_object_in_subtree (tem
, placeholder
);
1833 /* ...and #n# will use the real value from now on. */
1834 Fsetcdr (cell
, tem
);
1838 /* #n# returns a previously read object. */
1841 tem
= Fassq (make_number (n
), read_objects
);
1844 /* Fall through to error message. */
1846 /* Fall through to error message. */
1850 Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("#", 1), Qnil
));
1853 while ((c
= READCHAR
) >= 0 && c
!= '\n');
1858 return Fcons (Qquote
, Fcons (read0 (readcharfun
), Qnil
));
1868 new_backquote_flag
= 1;
1869 value
= read0 (readcharfun
);
1870 new_backquote_flag
= 0;
1872 return Fcons (Qbackquote
, Fcons (value
, Qnil
));
1876 if (new_backquote_flag
)
1878 Lisp_Object comma_type
= Qnil
;
1883 comma_type
= Qcomma_at
;
1885 comma_type
= Qcomma_dot
;
1888 if (ch
>= 0) UNREAD (ch
);
1889 comma_type
= Qcomma
;
1892 new_backquote_flag
= 0;
1893 value
= read0 (readcharfun
);
1894 new_backquote_flag
= 1;
1895 return Fcons (comma_type
, Fcons (value
, Qnil
));
1902 register Lisp_Object val
;
1905 if (c
< 0) return Fsignal (Qend_of_file
, Qnil
);
1908 c
= read_escape (readcharfun
, 0);
1909 else if (BASE_LEADING_CODE_P (c
))
1910 c
= read_multibyte (c
, readcharfun
);
1912 return make_number (c
);
1917 register char *p
= read_buffer
;
1918 register char *end
= read_buffer
+ read_buffer_size
;
1920 /* Nonzero if we saw an escape sequence specifying
1921 a multibyte character. */
1922 int force_multibyte
= 0;
1923 /* Nonzero if we saw an escape sequence specifying
1924 a single-byte character. */
1925 int force_singlebyte
= 0;
1929 while ((c
= READCHAR
) >= 0
1932 if (end
- p
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
1934 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
1935 p
+= new - read_buffer
;
1936 read_buffer
+= new - read_buffer
;
1937 end
= read_buffer
+ read_buffer_size
;
1942 c
= read_escape (readcharfun
, 1);
1944 /* C is -1 if \ newline has just been seen */
1947 if (p
== read_buffer
)
1952 /* If an escape specifies a non-ASCII single-byte character,
1953 this must be a unibyte string. */
1954 if (SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
))
1955 && ! ASCII_BYTE_P ((c
& ~CHAR_MODIFIER_MASK
)))
1956 force_singlebyte
= 1;
1959 if (! SINGLE_BYTE_CHAR_P ((c
& ~CHAR_MODIFIER_MASK
)))
1961 unsigned char workbuf
[4];
1962 unsigned char *str
= workbuf
;
1965 /* Any modifiers for a multibyte character are invalid. */
1966 if (c
& CHAR_MODIFIER_MASK
)
1967 error ("Invalid modifier in string");
1968 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
1970 force_multibyte
= 1;
1972 bcopy (str
, p
, length
);
1977 /* Allow `\C- ' and `\C-?'. */
1978 if (c
== (CHAR_CTL
| ' '))
1980 else if (c
== (CHAR_CTL
| '?'))
1985 /* Shift modifier is valid only with [A-Za-z]. */
1986 if ((c
& 0377) >= 'A' && (c
& 0377) <= 'Z')
1988 else if ((c
& 0377) >= 'a' && (c
& 0377) <= 'z')
1989 c
= (c
& ~CHAR_SHIFT
) - ('a' - 'A');
1993 /* Move the meta bit to the right place for a string. */
1994 c
= (c
& ~CHAR_META
) | 0x80;
1996 error ("Invalid modifier in string");
2001 return Fsignal (Qend_of_file
, Qnil
);
2003 /* If purifying, and string starts with \ newline,
2004 return zero instead. This is for doc strings
2005 that we are really going to find in etc/DOC.nn.nn */
2006 if (!NILP (Vpurify_flag
) && NILP (Vdoc_file_name
) && cancel
)
2007 return make_number (0);
2009 if (force_multibyte
)
2010 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2011 else if (force_singlebyte
)
2012 nchars
= p
- read_buffer
;
2013 else if (load_convert_to_unibyte
)
2016 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2017 if (p
- read_buffer
!= nchars
)
2019 string
= make_multibyte_string (read_buffer
, nchars
,
2021 return Fstring_make_unibyte (string
);
2024 else if (EQ (readcharfun
, Qget_file_char
)
2025 || EQ (readcharfun
, Qlambda
))
2026 /* Nowadays, reading directly from a file
2027 is used only for compiled Emacs Lisp files,
2028 and those always use the Emacs internal encoding.
2029 Meanwhile, Qlambda is used for reading dynamic byte code
2030 (compiled with byte-compile-dynamic = t). */
2031 nchars
= multibyte_chars_in_text (read_buffer
, p
- read_buffer
);
2033 /* In all other cases, if we read these bytes as
2034 separate characters, treat them as separate characters now. */
2035 nchars
= p
- read_buffer
;
2038 return make_pure_string (read_buffer
, nchars
, p
- read_buffer
,
2040 || (p
- read_buffer
!= nchars
)));
2041 return make_specified_string (read_buffer
, nchars
, p
- read_buffer
,
2043 || (p
- read_buffer
!= nchars
)));
2048 #ifdef LISP_FLOAT_TYPE
2049 /* If a period is followed by a number, then we should read it
2050 as a floating point number. Otherwise, it denotes a dotted
2052 int next_char
= READCHAR
;
2055 if (! (next_char
>= '0' && next_char
<= '9'))
2062 /* Otherwise, we fall through! Note that the atom-reading loop
2063 below will now loop at least once, assuring that we will not
2064 try to UNREAD two characters in a row. */
2068 if (c
<= 040) goto retry
;
2070 register char *p
= read_buffer
;
2074 register char *end
= read_buffer
+ read_buffer_size
;
2077 && !(c
== '\"' || c
== '\'' || c
== ';' || c
== '?'
2078 || c
== '(' || c
== ')'
2079 #ifndef LISP_FLOAT_TYPE
2080 /* If we have floating-point support, then we need
2081 to allow <digits><dot><digits>. */
2083 #endif /* not LISP_FLOAT_TYPE */
2084 || c
== '[' || c
== ']' || c
== '#'
2087 if (end
- p
< MAX_LENGTH_OF_MULTI_BYTE_FORM
)
2089 register char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2090 p
+= new - read_buffer
;
2091 read_buffer
+= new - read_buffer
;
2092 end
= read_buffer
+ read_buffer_size
;
2100 if (! SINGLE_BYTE_CHAR_P (c
))
2102 unsigned char workbuf
[4];
2103 unsigned char *str
= workbuf
;
2106 length
= non_ascii_char_to_string (c
, workbuf
, &str
);
2108 bcopy (str
, p
, length
);
2119 char *new = (char *) xrealloc (read_buffer
, read_buffer_size
*= 2);
2120 p
+= new - read_buffer
;
2121 read_buffer
+= new - read_buffer
;
2122 /* end = read_buffer + read_buffer_size; */
2129 if (!quoted
&& !uninterned_symbol
)
2132 register Lisp_Object val
;
2134 if (*p1
== '+' || *p1
== '-') p1
++;
2135 /* Is it an integer? */
2138 while (p1
!= p
&& (c
= *p1
) >= '0' && c
<= '9') p1
++;
2139 #ifdef LISP_FLOAT_TYPE
2140 /* Integers can have trailing decimal points. */
2141 if (p1
> read_buffer
&& p1
< p
&& *p1
== '.') p1
++;
2144 /* It is an integer. */
2146 #ifdef LISP_FLOAT_TYPE
2150 if (sizeof (int) == sizeof (EMACS_INT
))
2151 XSETINT (val
, atoi (read_buffer
));
2152 else if (sizeof (long) == sizeof (EMACS_INT
))
2153 XSETINT (val
, atol (read_buffer
));
2159 #ifdef LISP_FLOAT_TYPE
2160 if (isfloat_string (read_buffer
))
2162 /* Compute NaN and infinities using 0.0 in a variable,
2163 to cope with compilers that think they are smarter
2169 /* Negate the value ourselves. This treats 0, NaNs,
2170 and infinity properly on IEEE floating point hosts,
2171 and works around a common bug where atof ("-0.0")
2173 int negative
= read_buffer
[0] == '-';
2175 /* The only way p[-1] can be 'F' or 'N', after isfloat_string
2176 returns 1, is if the input ends in e+INF or e+NaN. */
2183 value
= zero
/ zero
;
2186 value
= atof (read_buffer
+ negative
);
2190 return make_float (negative
? - value
: value
);
2195 if (uninterned_symbol
)
2196 return make_symbol (read_buffer
);
2198 return intern (read_buffer
);
2204 /* List of nodes we've seen during substitute_object_in_subtree. */
2205 static Lisp_Object seen_list
;
2208 substitute_object_in_subtree (object
, placeholder
)
2210 Lisp_Object placeholder
;
2212 Lisp_Object check_object
;
2214 /* We haven't seen any objects when we start. */
2217 /* Make all the substitutions. */
2219 = substitute_object_recurse (object
, placeholder
, object
);
2221 /* Clear seen_list because we're done with it. */
2224 /* The returned object here is expected to always eq the
2226 if (!EQ (check_object
, object
))
2227 error ("Unexpected mutation error in reader");
2230 /* Feval doesn't get called from here, so no gc protection is needed. */
2231 #define SUBSTITUTE(get_val, set_val) \
2233 Lisp_Object old_value = get_val; \
2234 Lisp_Object true_value \
2235 = substitute_object_recurse (object, placeholder,\
2238 if (!EQ (old_value, true_value)) \
2245 substitute_object_recurse (object
, placeholder
, subtree
)
2247 Lisp_Object placeholder
;
2248 Lisp_Object subtree
;
2250 /* If we find the placeholder, return the target object. */
2251 if (EQ (placeholder
, subtree
))
2254 /* If we've been to this node before, don't explore it again. */
2255 if (!EQ (Qnil
, Fmemq (subtree
, seen_list
)))
2258 /* If this node can be the entry point to a cycle, remember that
2259 we've seen it. It can only be such an entry point if it was made
2260 by #n=, which means that we can find it as a value in
2262 if (!EQ (Qnil
, Frassq (subtree
, read_objects
)))
2263 seen_list
= Fcons (subtree
, seen_list
);
2265 /* Recurse according to subtree's type.
2266 Every branch must return a Lisp_Object. */
2267 switch (XTYPE (subtree
))
2269 case Lisp_Vectorlike
:
2272 int length
= Flength(subtree
);
2273 for (i
= 0; i
< length
; i
++)
2275 Lisp_Object idx
= make_number (i
);
2276 SUBSTITUTE (Faref (subtree
, idx
),
2277 Faset (subtree
, idx
, true_value
));
2284 SUBSTITUTE (Fcar_safe (subtree
),
2285 Fsetcar (subtree
, true_value
));
2286 SUBSTITUTE (Fcdr_safe (subtree
),
2287 Fsetcdr (subtree
, true_value
));
2291 #ifdef USE_TEXT_PROPERTIES
2294 /* Check for text properties in each interval.
2295 substitute_in_interval contains part of the logic. */
2297 INTERVAL root_interval
= XSTRING (subtree
)->intervals
;
2298 Lisp_Object arg
= Fcons (object
, placeholder
);
2300 traverse_intervals (root_interval
, 1, 0,
2301 &substitute_in_interval
, arg
);
2305 #endif /* defined USE_TEXT_PROPERTIES */
2307 /* Other types don't recurse any further. */
2313 /* Helper function for substitute_object_recurse. */
2315 substitute_in_interval (interval
, arg
)
2319 Lisp_Object object
= Fcar (arg
);
2320 Lisp_Object placeholder
= Fcdr (arg
);
2322 SUBSTITUTE(interval
->plist
, interval
->plist
= true_value
);
2326 #ifdef LISP_FLOAT_TYPE
2343 if (*cp
== '+' || *cp
== '-')
2346 if (*cp
>= '0' && *cp
<= '9')
2349 while (*cp
>= '0' && *cp
<= '9')
2357 if (*cp
>= '0' && *cp
<= '9')
2360 while (*cp
>= '0' && *cp
<= '9')
2363 if (*cp
== 'e' || *cp
== 'E')
2367 if (*cp
== '+' || *cp
== '-')
2371 if (*cp
>= '0' && *cp
<= '9')
2374 while (*cp
>= '0' && *cp
<= '9')
2377 else if (cp
== start
)
2379 else if (cp
[-1] == '+' && cp
[0] == 'I' && cp
[1] == 'N' && cp
[2] == 'F')
2384 else if (cp
[-1] == '+' && cp
[0] == 'N' && cp
[1] == 'a' && cp
[2] == 'N')
2390 return (((*cp
== 0) || (*cp
== ' ') || (*cp
== '\t') || (*cp
== '\n') || (*cp
== '\r') || (*cp
== '\f'))
2391 && (state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
)
2392 || state
== (DOT_CHAR
|TRAIL_INT
)
2393 || state
== (LEAD_INT
|E_CHAR
|EXP_INT
)
2394 || state
== (LEAD_INT
|DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)
2395 || state
== (DOT_CHAR
|TRAIL_INT
|E_CHAR
|EXP_INT
)));
2397 #endif /* LISP_FLOAT_TYPE */
2400 read_vector (readcharfun
, bytecodeflag
)
2401 Lisp_Object readcharfun
;
2406 register Lisp_Object
*ptr
;
2407 register Lisp_Object tem
, item
, vector
;
2408 register struct Lisp_Cons
*otem
;
2411 tem
= read_list (1, readcharfun
);
2412 len
= Flength (tem
);
2413 vector
= (read_pure
? make_pure_vector (XINT (len
)) : Fmake_vector (len
, Qnil
));
2415 size
= XVECTOR (vector
)->size
;
2416 ptr
= XVECTOR (vector
)->contents
;
2417 for (i
= 0; i
< size
; i
++)
2420 /* If `load-force-doc-strings' is t when reading a lazily-loaded
2421 bytecode object, the docstring containing the bytecode and
2422 constants values must be treated as unibyte and passed to
2423 Fread, to get the actual bytecode string and constants vector. */
2424 if (bytecodeflag
&& load_force_doc_strings
)
2426 if (i
== COMPILED_BYTECODE
)
2428 if (!STRINGP (item
))
2429 error ("invalid byte code");
2431 /* Delay handling the bytecode slot until we know whether
2432 it is lazily-loaded (we can tell by whether the
2433 constants slot is nil). */
2434 ptr
[COMPILED_CONSTANTS
] = item
;
2437 else if (i
== COMPILED_CONSTANTS
)
2439 Lisp_Object bytestr
= ptr
[COMPILED_CONSTANTS
];
2443 /* Coerce string to unibyte (like string-as-unibyte,
2444 but without generating extra garbage and
2445 guaranteeing no change in the contents). */
2446 XSTRING (bytestr
)->size
= STRING_BYTES (XSTRING (bytestr
));
2447 SET_STRING_BYTES (XSTRING (bytestr
), -1);
2449 item
= Fread (bytestr
);
2451 error ("invalid byte code");
2453 otem
= XCONS (item
);
2454 bytestr
= XCONS (item
)->car
;
2455 item
= XCONS (item
)->cdr
;
2459 /* Now handle the bytecode slot. */
2460 ptr
[COMPILED_BYTECODE
] = read_pure
? Fpurecopy (bytestr
) : bytestr
;
2463 ptr
[i
] = read_pure
? Fpurecopy (item
) : item
;
2471 /* FLAG = 1 means check for ] to terminate rather than ) and .
2472 FLAG = -1 means check for starting with defun
2473 and make structure pure. */
2476 read_list (flag
, readcharfun
)
2478 register Lisp_Object readcharfun
;
2480 /* -1 means check next element for defun,
2481 0 means don't check,
2482 1 means already checked and found defun. */
2483 int defunflag
= flag
< 0 ? -1 : 0;
2484 Lisp_Object val
, tail
;
2485 register Lisp_Object elt
, tem
;
2486 struct gcpro gcpro1
, gcpro2
;
2487 /* 0 is the normal case.
2488 1 means this list is a doc reference; replace it with the number 0.
2489 2 means this list is a doc reference; replace it with the doc string. */
2490 int doc_reference
= 0;
2492 /* Initialize this to 1 if we are reading a list. */
2493 int first_in_list
= flag
<= 0;
2502 elt
= read1 (readcharfun
, &ch
, first_in_list
);
2507 /* While building, if the list starts with #$, treat it specially. */
2508 if (EQ (elt
, Vload_file_name
)
2510 && !NILP (Vpurify_flag
))
2512 if (NILP (Vdoc_file_name
))
2513 /* We have not yet called Snarf-documentation, so assume
2514 this file is described in the DOC-MM.NN file
2515 and Snarf-documentation will fill in the right value later.
2516 For now, replace the whole list with 0. */
2519 /* We have already called Snarf-documentation, so make a relative
2520 file name for this file, so it can be found properly
2521 in the installed Lisp directory.
2522 We don't use Fexpand_file_name because that would make
2523 the directory absolute now. */
2524 elt
= concat2 (build_string ("../lisp/"),
2525 Ffile_name_nondirectory (elt
));
2527 else if (EQ (elt
, Vload_file_name
)
2529 && load_force_doc_strings
)
2538 Fsignal (Qinvalid_read_syntax
,
2539 Fcons (make_string (") or . in a vector", 18), Qnil
));
2547 XCONS (tail
)->cdr
= read0 (readcharfun
);
2549 val
= read0 (readcharfun
);
2550 read1 (readcharfun
, &ch
, 0);
2554 if (doc_reference
== 1)
2555 return make_number (0);
2556 if (doc_reference
== 2)
2558 /* Get a doc string from the file we are loading.
2559 If it's in saved_doc_string, get it from there. */
2560 int pos
= XINT (XCONS (val
)->cdr
);
2561 /* Position is negative for user variables. */
2562 if (pos
< 0) pos
= -pos
;
2563 if (pos
>= saved_doc_string_position
2564 && pos
< (saved_doc_string_position
2565 + saved_doc_string_length
))
2567 int start
= pos
- saved_doc_string_position
;
2570 /* Process quoting with ^A,
2571 and find the end of the string,
2572 which is marked with ^_ (037). */
2573 for (from
= start
, to
= start
;
2574 saved_doc_string
[from
] != 037;)
2576 int c
= saved_doc_string
[from
++];
2579 c
= saved_doc_string
[from
++];
2581 saved_doc_string
[to
++] = c
;
2583 saved_doc_string
[to
++] = 0;
2585 saved_doc_string
[to
++] = 037;
2588 saved_doc_string
[to
++] = c
;
2591 return make_string (saved_doc_string
+ start
,
2594 /* Look in prev_saved_doc_string the same way. */
2595 else if (pos
>= prev_saved_doc_string_position
2596 && pos
< (prev_saved_doc_string_position
2597 + prev_saved_doc_string_length
))
2599 int start
= pos
- prev_saved_doc_string_position
;
2602 /* Process quoting with ^A,
2603 and find the end of the string,
2604 which is marked with ^_ (037). */
2605 for (from
= start
, to
= start
;
2606 prev_saved_doc_string
[from
] != 037;)
2608 int c
= prev_saved_doc_string
[from
++];
2611 c
= prev_saved_doc_string
[from
++];
2613 prev_saved_doc_string
[to
++] = c
;
2615 prev_saved_doc_string
[to
++] = 0;
2617 prev_saved_doc_string
[to
++] = 037;
2620 prev_saved_doc_string
[to
++] = c
;
2623 return make_string (prev_saved_doc_string
+ start
,
2627 return get_doc_string (val
, 0, 0);
2632 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string (". in wrong context", 18), Qnil
));
2634 return Fsignal (Qinvalid_read_syntax
, Fcons (make_string ("] in a list", 11), Qnil
));
2636 tem
= (read_pure
&& flag
<= 0
2637 ? pure_cons (elt
, Qnil
)
2638 : Fcons (elt
, Qnil
));
2640 XCONS (tail
)->cdr
= tem
;
2645 defunflag
= EQ (elt
, Qdefun
);
2646 else if (defunflag
> 0)
2651 Lisp_Object Vobarray
;
2652 Lisp_Object initial_obarray
;
2654 /* oblookup stores the bucket number here, for the sake of Funintern. */
2656 int oblookup_last_bucket_number
;
2658 static int hash_string ();
2659 Lisp_Object
oblookup ();
2661 /* Get an error if OBARRAY is not an obarray.
2662 If it is one, return it. */
2665 check_obarray (obarray
)
2666 Lisp_Object obarray
;
2668 while (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2670 /* If Vobarray is now invalid, force it to be valid. */
2671 if (EQ (Vobarray
, obarray
)) Vobarray
= initial_obarray
;
2673 obarray
= wrong_type_argument (Qvectorp
, obarray
);
2678 /* Intern the C string STR: return a symbol with that name,
2679 interned in the current obarray. */
2686 int len
= strlen (str
);
2687 Lisp_Object obarray
;
2690 if (!VECTORP (obarray
) || XVECTOR (obarray
)->size
== 0)
2691 obarray
= check_obarray (obarray
);
2692 tem
= oblookup (obarray
, str
, len
, len
);
2695 return Fintern (make_string (str
, len
), obarray
);
2698 /* Create an uninterned symbol with name STR. */
2704 int len
= strlen (str
);
2706 return Fmake_symbol ((!NILP (Vpurify_flag
)
2707 ? make_pure_string (str
, len
, len
, 0)
2708 : make_string (str
, len
)));
2711 DEFUN ("intern", Fintern
, Sintern
, 1, 2, 0,
2712 "Return the canonical symbol whose name is STRING.\n\
2713 If there is none, one is created by this function and returned.\n\
2714 A second optional argument specifies the obarray to use;\n\
2715 it defaults to the value of `obarray'.")
2717 Lisp_Object string
, obarray
;
2719 register Lisp_Object tem
, sym
, *ptr
;
2721 if (NILP (obarray
)) obarray
= Vobarray
;
2722 obarray
= check_obarray (obarray
);
2724 CHECK_STRING (string
, 0);
2726 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2727 XSTRING (string
)->size
,
2728 STRING_BYTES (XSTRING (string
)));
2729 if (!INTEGERP (tem
))
2732 if (!NILP (Vpurify_flag
))
2733 string
= Fpurecopy (string
);
2734 sym
= Fmake_symbol (string
);
2735 XSYMBOL (sym
)->obarray
= obarray
;
2737 if ((XSTRING (string
)->data
[0] == ':')
2738 && EQ (obarray
, initial_obarray
))
2739 XSYMBOL (sym
)->value
= sym
;
2741 ptr
= &XVECTOR (obarray
)->contents
[XINT (tem
)];
2743 XSYMBOL (sym
)->next
= XSYMBOL (*ptr
);
2745 XSYMBOL (sym
)->next
= 0;
2750 DEFUN ("intern-soft", Fintern_soft
, Sintern_soft
, 1, 2, 0,
2751 "Return the canonical symbol whose name is STRING, or nil if none exists.\n\
2752 A second optional argument specifies the obarray to use;\n\
2753 it defaults to the value of `obarray'.")
2755 Lisp_Object string
, obarray
;
2757 register Lisp_Object tem
;
2759 if (NILP (obarray
)) obarray
= Vobarray
;
2760 obarray
= check_obarray (obarray
);
2762 CHECK_STRING (string
, 0);
2764 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2765 XSTRING (string
)->size
,
2766 STRING_BYTES (XSTRING (string
)));
2767 if (!INTEGERP (tem
))
2772 DEFUN ("unintern", Funintern
, Sunintern
, 1, 2, 0,
2773 "Delete the symbol named NAME, if any, from OBARRAY.\n\
2774 The value is t if a symbol was found and deleted, nil otherwise.\n\
2775 NAME may be a string or a symbol. If it is a symbol, that symbol\n\
2776 is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
2777 OBARRAY defaults to the value of the variable `obarray'.")
2779 Lisp_Object name
, obarray
;
2781 register Lisp_Object string
, tem
;
2784 if (NILP (obarray
)) obarray
= Vobarray
;
2785 obarray
= check_obarray (obarray
);
2788 XSETSTRING (string
, XSYMBOL (name
)->name
);
2791 CHECK_STRING (name
, 0);
2795 tem
= oblookup (obarray
, XSTRING (string
)->data
,
2796 XSTRING (string
)->size
,
2797 STRING_BYTES (XSTRING (string
)));
2800 /* If arg was a symbol, don't delete anything but that symbol itself. */
2801 if (SYMBOLP (name
) && !EQ (name
, tem
))
2804 XSYMBOL (tem
)->obarray
= Qnil
;
2806 hash
= oblookup_last_bucket_number
;
2808 if (EQ (XVECTOR (obarray
)->contents
[hash
], tem
))
2810 if (XSYMBOL (tem
)->next
)
2811 XSETSYMBOL (XVECTOR (obarray
)->contents
[hash
], XSYMBOL (tem
)->next
);
2813 XSETINT (XVECTOR (obarray
)->contents
[hash
], 0);
2817 Lisp_Object tail
, following
;
2819 for (tail
= XVECTOR (obarray
)->contents
[hash
];
2820 XSYMBOL (tail
)->next
;
2823 XSETSYMBOL (following
, XSYMBOL (tail
)->next
);
2824 if (EQ (following
, tem
))
2826 XSYMBOL (tail
)->next
= XSYMBOL (following
)->next
;
2835 /* Return the symbol in OBARRAY whose names matches the string
2836 of SIZE characters (SIZE_BYTE bytes) at PTR.
2837 If there is no such symbol in OBARRAY, return nil.
2839 Also store the bucket number in oblookup_last_bucket_number. */
2842 oblookup (obarray
, ptr
, size
, size_byte
)
2843 Lisp_Object obarray
;
2845 int size
, size_byte
;
2849 register Lisp_Object tail
;
2850 Lisp_Object bucket
, tem
;
2852 if (!VECTORP (obarray
)
2853 || (obsize
= XVECTOR (obarray
)->size
) == 0)
2855 obarray
= check_obarray (obarray
);
2856 obsize
= XVECTOR (obarray
)->size
;
2858 /* This is sometimes needed in the middle of GC. */
2859 obsize
&= ~ARRAY_MARK_FLAG
;
2860 /* Combining next two lines breaks VMS C 2.3. */
2861 hash
= hash_string (ptr
, size_byte
);
2863 bucket
= XVECTOR (obarray
)->contents
[hash
];
2864 oblookup_last_bucket_number
= hash
;
2865 if (XFASTINT (bucket
) == 0)
2867 else if (!SYMBOLP (bucket
))
2868 error ("Bad data in guts of obarray"); /* Like CADR error message */
2870 for (tail
= bucket
; ; XSETSYMBOL (tail
, XSYMBOL (tail
)->next
))
2872 if (STRING_BYTES (XSYMBOL (tail
)->name
) == size_byte
2873 && XSYMBOL (tail
)->name
->size
== size
2874 && !bcmp (XSYMBOL (tail
)->name
->data
, ptr
, size_byte
))
2876 else if (XSYMBOL (tail
)->next
== 0)
2879 XSETINT (tem
, hash
);
2884 hash_string (ptr
, len
)
2888 register unsigned char *p
= ptr
;
2889 register unsigned char *end
= p
+ len
;
2890 register unsigned char c
;
2891 register int hash
= 0;
2896 if (c
>= 0140) c
-= 40;
2897 hash
= ((hash
<<3) + (hash
>>28) + c
);
2899 return hash
& 07777777777;
2903 map_obarray (obarray
, fn
, arg
)
2904 Lisp_Object obarray
;
2905 void (*fn
) P_ ((Lisp_Object
, Lisp_Object
));
2909 register Lisp_Object tail
;
2910 CHECK_VECTOR (obarray
, 1);
2911 for (i
= XVECTOR (obarray
)->size
- 1; i
>= 0; i
--)
2913 tail
= XVECTOR (obarray
)->contents
[i
];
2918 if (XSYMBOL (tail
)->next
== 0)
2920 XSETSYMBOL (tail
, XSYMBOL (tail
)->next
);
2926 mapatoms_1 (sym
, function
)
2927 Lisp_Object sym
, function
;
2929 call1 (function
, sym
);
2932 DEFUN ("mapatoms", Fmapatoms
, Smapatoms
, 1, 2, 0,
2933 "Call FUNCTION on every symbol in OBARRAY.\n\
2934 OBARRAY defaults to the value of `obarray'.")
2936 Lisp_Object function
, obarray
;
2940 if (NILP (obarray
)) obarray
= Vobarray
;
2941 obarray
= check_obarray (obarray
);
2943 map_obarray (obarray
, mapatoms_1
, function
);
2947 #define OBARRAY_SIZE 1511
2952 Lisp_Object oblength
;
2956 XSETFASTINT (oblength
, OBARRAY_SIZE
);
2958 Qnil
= Fmake_symbol (make_pure_string ("nil", 3, 3, 0));
2959 Vobarray
= Fmake_vector (oblength
, make_number (0));
2960 initial_obarray
= Vobarray
;
2961 staticpro (&initial_obarray
);
2962 /* Intern nil in the obarray */
2963 XSYMBOL (Qnil
)->obarray
= Vobarray
;
2964 /* These locals are to kludge around a pyramid compiler bug. */
2965 hash
= hash_string ("nil", 3);
2966 /* Separate statement here to avoid VAXC bug. */
2967 hash
%= OBARRAY_SIZE
;
2968 tem
= &XVECTOR (Vobarray
)->contents
[hash
];
2971 Qunbound
= Fmake_symbol (make_pure_string ("unbound", 7, 7, 0));
2972 XSYMBOL (Qnil
)->function
= Qunbound
;
2973 XSYMBOL (Qunbound
)->value
= Qunbound
;
2974 XSYMBOL (Qunbound
)->function
= Qunbound
;
2977 XSYMBOL (Qnil
)->value
= Qnil
;
2978 XSYMBOL (Qnil
)->plist
= Qnil
;
2979 XSYMBOL (Qt
)->value
= Qt
;
2981 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */
2984 Qvariable_documentation
= intern ("variable-documentation");
2985 staticpro (&Qvariable_documentation
);
2987 read_buffer_size
= 100 + MAX_LENGTH_OF_MULTI_BYTE_FORM
;
2988 read_buffer
= (char *) malloc (read_buffer_size
);
2993 struct Lisp_Subr
*sname
;
2996 sym
= intern (sname
->symbol_name
);
2997 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3000 #ifdef NOTDEF /* use fset in subr.el now */
3002 defalias (sname
, string
)
3003 struct Lisp_Subr
*sname
;
3007 sym
= intern (string
);
3008 XSETSUBR (XSYMBOL (sym
)->function
, sname
);
3012 /* Define an "integer variable"; a symbol whose value is forwarded
3013 to a C variable of type int. Sample call: */
3014 /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */
3016 defvar_int (namestring
, address
)
3020 Lisp_Object sym
, val
;
3021 sym
= intern (namestring
);
3022 val
= allocate_misc ();
3023 XMISCTYPE (val
) = Lisp_Misc_Intfwd
;
3024 XINTFWD (val
)->intvar
= address
;
3025 XSYMBOL (sym
)->value
= val
;
3028 /* Similar but define a variable whose value is T if address contains 1,
3029 NIL if address contains 0 */
3031 defvar_bool (namestring
, address
)
3035 Lisp_Object sym
, val
;
3036 sym
= intern (namestring
);
3037 val
= allocate_misc ();
3038 XMISCTYPE (val
) = Lisp_Misc_Boolfwd
;
3039 XBOOLFWD (val
)->boolvar
= address
;
3040 XSYMBOL (sym
)->value
= val
;
3043 /* Similar but define a variable whose value is the Lisp Object stored
3044 at address. Two versions: with and without gc-marking of the C
3045 variable. The nopro version is used when that variable will be
3046 gc-marked for some other reason, since marking the same slot twice
3047 can cause trouble with strings. */
3049 defvar_lisp_nopro (namestring
, address
)
3051 Lisp_Object
*address
;
3053 Lisp_Object sym
, val
;
3054 sym
= intern (namestring
);
3055 val
= allocate_misc ();
3056 XMISCTYPE (val
) = Lisp_Misc_Objfwd
;
3057 XOBJFWD (val
)->objvar
= address
;
3058 XSYMBOL (sym
)->value
= val
;
3062 defvar_lisp (namestring
, address
)
3064 Lisp_Object
*address
;
3066 defvar_lisp_nopro (namestring
, address
);
3067 staticpro (address
);
3072 /* Similar but define a variable whose value is the Lisp Object stored in
3073 the current buffer. address is the address of the slot in the buffer
3074 that is current now. */
3077 defvar_per_buffer (namestring
, address
, type
, doc
)
3079 Lisp_Object
*address
;
3083 Lisp_Object sym
, val
;
3085 extern struct buffer buffer_local_symbols
;
3087 sym
= intern (namestring
);
3088 val
= allocate_misc ();
3089 offset
= (char *)address
- (char *)current_buffer
;
3091 XMISCTYPE (val
) = Lisp_Misc_Buffer_Objfwd
;
3092 XBUFFER_OBJFWD (val
)->offset
= offset
;
3093 XSYMBOL (sym
)->value
= val
;
3094 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_symbols
) = sym
;
3095 *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
) = type
;
3096 if (XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
)) == 0)
3097 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
3098 slot of buffer_local_flags */
3102 #endif /* standalone */
3104 /* Similar but define a variable whose value is the Lisp Object stored
3105 at a particular offset in the current kboard object. */
3108 defvar_kboard (namestring
, offset
)
3112 Lisp_Object sym
, val
;
3113 sym
= intern (namestring
);
3114 val
= allocate_misc ();
3115 XMISCTYPE (val
) = Lisp_Misc_Kboard_Objfwd
;
3116 XKBOARD_OBJFWD (val
)->offset
= offset
;
3117 XSYMBOL (sym
)->value
= val
;
3120 /* Record the value of load-path used at the start of dumping
3121 so we can see if the site changed it later during dumping. */
3122 static Lisp_Object dump_path
;
3128 int turn_off_warning
= 0;
3130 #ifdef HAVE_SETLOCALE
3131 /* Make sure numbers are parsed as we expect. */
3132 setlocale (LC_NUMERIC
, "C");
3133 #endif /* HAVE_SETLOCALE */
3135 /* Compute the default load-path. */
3137 normal
= PATH_LOADSEARCH
;
3138 Vload_path
= decode_env_path (0, normal
);
3140 if (NILP (Vpurify_flag
))
3141 normal
= PATH_LOADSEARCH
;
3143 normal
= PATH_DUMPLOADSEARCH
;
3145 /* In a dumped Emacs, we normally have to reset the value of
3146 Vload_path from PATH_LOADSEARCH, since the value that was dumped
3147 uses ../lisp, instead of the path of the installed elisp
3148 libraries. However, if it appears that Vload_path was changed
3149 from the default before dumping, don't override that value. */
3152 if (! NILP (Fequal (dump_path
, Vload_path
)))
3154 Vload_path
= decode_env_path (0, normal
);
3155 if (!NILP (Vinstallation_directory
))
3157 /* Add to the path the lisp subdir of the
3158 installation dir, if it exists. */
3159 Lisp_Object tem
, tem1
;
3160 tem
= Fexpand_file_name (build_string ("lisp"),
3161 Vinstallation_directory
);
3162 tem1
= Ffile_exists_p (tem
);
3165 if (NILP (Fmember (tem
, Vload_path
)))
3167 turn_off_warning
= 1;
3168 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3172 /* That dir doesn't exist, so add the build-time
3173 Lisp dirs instead. */
3174 Vload_path
= nconc2 (Vload_path
, dump_path
);
3176 /* Add leim under the installation dir, if it exists. */
3177 tem
= Fexpand_file_name (build_string ("leim"),
3178 Vinstallation_directory
);
3179 tem1
= Ffile_exists_p (tem
);
3182 if (NILP (Fmember (tem
, Vload_path
)))
3183 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3186 /* Add site-list under the installation dir, if it exists. */
3187 tem
= Fexpand_file_name (build_string ("site-lisp"),
3188 Vinstallation_directory
);
3189 tem1
= Ffile_exists_p (tem
);
3192 if (NILP (Fmember (tem
, Vload_path
)))
3193 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3196 /* If Emacs was not built in the source directory,
3197 and it is run from where it was built, add to load-path
3198 the lisp, leim and site-lisp dirs under that directory. */
3200 if (NILP (Fequal (Vinstallation_directory
, Vsource_directory
)))
3204 tem
= Fexpand_file_name (build_string ("src/Makefile"),
3205 Vinstallation_directory
);
3206 tem1
= Ffile_exists_p (tem
);
3208 /* Don't be fooled if they moved the entire source tree
3209 AFTER dumping Emacs. If the build directory is indeed
3210 different from the source dir, src/Makefile.in and
3211 src/Makefile will not be found together. */
3212 tem
= Fexpand_file_name (build_string ("src/Makefile.in"),
3213 Vinstallation_directory
);
3214 tem2
= Ffile_exists_p (tem
);
3215 if (!NILP (tem1
) && NILP (tem2
))
3217 tem
= Fexpand_file_name (build_string ("lisp"),
3220 if (NILP (Fmember (tem
, Vload_path
)))
3221 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3223 tem
= Fexpand_file_name (build_string ("leim"),
3226 if (NILP (Fmember (tem
, Vload_path
)))
3227 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3229 tem
= Fexpand_file_name (build_string ("site-lisp"),
3232 if (NILP (Fmember (tem
, Vload_path
)))
3233 Vload_path
= nconc2 (Vload_path
, Fcons (tem
, Qnil
));
3241 /* NORMAL refers to the lisp dir in the source directory. */
3242 /* We used to add ../lisp at the front here, but
3243 that caused trouble because it was copied from dump_path
3244 into Vload_path, aboe, when Vinstallation_directory was non-nil.
3245 It should be unnecessary. */
3246 Vload_path
= decode_env_path (0, normal
);
3247 dump_path
= Vload_path
;
3252 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
3253 almost never correct, thereby causing a warning to be printed out that
3254 confuses users. Since PATH_LOADSEARCH is always overridden by the
3255 EMACSLOADPATH environment variable below, disable the warning on NT. */
3257 /* Warn if dirs in the *standard* path don't exist. */
3258 if (!turn_off_warning
)
3260 Lisp_Object path_tail
;
3262 for (path_tail
= Vload_path
;
3264 path_tail
= XCONS (path_tail
)->cdr
)
3266 Lisp_Object dirfile
;
3267 dirfile
= Fcar (path_tail
);
3268 if (STRINGP (dirfile
))
3270 dirfile
= Fdirectory_file_name (dirfile
);
3271 if (access (XSTRING (dirfile
)->data
, 0) < 0)
3272 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
3273 XCONS (path_tail
)->car
);
3277 #endif /* WINDOWSNT */
3279 /* If the EMACSLOADPATH environment variable is set, use its value.
3280 This doesn't apply if we're dumping. */
3282 if (NILP (Vpurify_flag
)
3283 && egetenv ("EMACSLOADPATH"))
3285 Vload_path
= decode_env_path ("EMACSLOADPATH", normal
);
3289 load_in_progress
= 0;
3290 Vload_file_name
= Qnil
;
3292 load_descriptor_list
= Qnil
;
3294 Vstandard_input
= Qt
;
3297 /* Print a warning, using format string FORMAT, that directory DIRNAME
3298 does not exist. Print it on stderr and put it in *Message*. */
3301 dir_warning (format
, dirname
)
3303 Lisp_Object dirname
;
3306 = (char *) alloca (XSTRING (dirname
)->size
+ strlen (format
) + 5);
3308 fprintf (stderr
, format
, XSTRING (dirname
)->data
);
3309 sprintf (buffer
, format
, XSTRING (dirname
)->data
);
3310 /* Don't log the warning before we've initialized!! */
3312 message_dolog (buffer
, strlen (buffer
), 0, STRING_MULTIBYTE (dirname
));
3319 defsubr (&Sread_from_string
);
3321 defsubr (&Sintern_soft
);
3322 defsubr (&Sunintern
);
3324 defsubr (&Seval_buffer
);
3325 defsubr (&Seval_region
);
3326 defsubr (&Sread_char
);
3327 defsubr (&Sread_char_exclusive
);
3328 defsubr (&Sread_event
);
3329 defsubr (&Sget_file_char
);
3330 defsubr (&Smapatoms
);
3332 DEFVAR_LISP ("obarray", &Vobarray
,
3333 "Symbol table for use by `intern' and `read'.\n\
3334 It is a vector whose length ought to be prime for best results.\n\
3335 The vector's contents don't make sense if examined from Lisp programs;\n\
3336 to find all the symbols in an obarray, use `mapatoms'.");
3338 DEFVAR_LISP ("values", &Vvalues
,
3339 "List of values of all expressions which were read, evaluated and printed.\n\
3340 Order is reverse chronological.");
3342 DEFVAR_LISP ("standard-input", &Vstandard_input
,
3343 "Stream for read to get input from.\n\
3344 See documentation of `read' for possible values.");
3345 Vstandard_input
= Qt
;
3347 DEFVAR_LISP ("load-path", &Vload_path
,
3348 "*List of directories to search for files to load.\n\
3349 Each element is a string (directory name) or nil (try default directory).\n\
3350 Initialized based on EMACSLOADPATH environment variable, if any,\n\
3351 otherwise to default specified by file `epaths.h' when Emacs was built.");
3353 DEFVAR_BOOL ("load-in-progress", &load_in_progress
,
3354 "Non-nil iff inside of `load'.");
3356 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist
,
3357 "An alist of expressions to be evalled when particular files are loaded.\n\
3358 Each element looks like (FILENAME FORMS...).\n\
3359 When `load' is run and the file-name argument is FILENAME,\n\
3360 the FORMS in the corresponding element are executed at the end of loading.\n\n\
3361 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\
3362 with no directory specified, since that is how `load' is normally called.\n\
3363 An error in FORMS does not undo the load,\n\
3364 but does prevent execution of the rest of the FORMS.");
3365 Vafter_load_alist
= Qnil
;
3367 DEFVAR_LISP ("load-history", &Vload_history
,
3368 "Alist mapping source file names to symbols and features.\n\
3369 Each alist element is a list that starts with a file name,\n\
3370 except for one element (optional) that starts with nil and describes\n\
3371 definitions evaluated from buffers not visiting files.\n\
3372 The remaining elements of each list are symbols defined as functions\n\
3373 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.");
3374 Vload_history
= Qnil
;
3376 DEFVAR_LISP ("load-file-name", &Vload_file_name
,
3377 "Full name of file being loaded by `load'.");
3378 Vload_file_name
= Qnil
;
3380 DEFVAR_LISP ("user-init-file", &Vuser_init_file
,
3381 "File name, including directory, of user's initialization file.");
3382 Vuser_init_file
= Qnil
;
3384 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list
,
3385 "Used for internal purposes by `load'.");
3386 Vcurrent_load_list
= Qnil
;
3388 DEFVAR_LISP ("load-read-function", &Vload_read_function
,
3389 "Function used by `load' and `eval-region' for reading expressions.\n\
3390 The default is nil, which means use the function `read'.");
3391 Vload_read_function
= Qnil
;
3393 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function
,
3394 "Function called in `load' for loading an Emacs lisp source file.\n\
3395 This function is for doing code conversion before reading the source file.\n\
3396 If nil, loading is done without any code conversion.\n\
3397 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\
3398 FULLNAME is the full name of FILE.\n\
3399 See `load' for the meaning of the remaining arguments.");
3400 Vload_source_file_function
= Qnil
;
3402 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings
,
3403 "Non-nil means `load' should force-load all dynamic doc strings.\n\
3404 This is useful when the file being loaded is a temporary copy.");
3405 load_force_doc_strings
= 0;
3407 DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte
,
3408 "Non-nil means `load' converts strings to unibyte whenever possible.\n\
3409 This is normally used in `load-with-code-conversion'\n\
3410 for loading non-compiled files.");
3411 load_convert_to_unibyte
= 0;
3413 DEFVAR_LISP ("source-directory", &Vsource_directory
,
3414 "Directory in which Emacs sources were found when Emacs was built.\n\
3415 You cannot count on them to still be there!");
3417 = Fexpand_file_name (build_string ("../"),
3418 Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH
)));
3420 DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list
,
3421 "List of files that were preloaded (when dumping Emacs).");
3422 Vpreloaded_file_list
= Qnil
;
3424 /* Vsource_directory was initialized in init_lread. */
3426 load_descriptor_list
= Qnil
;
3427 staticpro (&load_descriptor_list
);
3429 Qcurrent_load_list
= intern ("current-load-list");
3430 staticpro (&Qcurrent_load_list
);
3432 Qstandard_input
= intern ("standard-input");
3433 staticpro (&Qstandard_input
);
3435 Qread_char
= intern ("read-char");
3436 staticpro (&Qread_char
);
3438 Qget_file_char
= intern ("get-file-char");
3439 staticpro (&Qget_file_char
);
3441 Qbackquote
= intern ("`");
3442 staticpro (&Qbackquote
);
3443 Qcomma
= intern (",");
3444 staticpro (&Qcomma
);
3445 Qcomma_at
= intern (",@");
3446 staticpro (&Qcomma_at
);
3447 Qcomma_dot
= intern (",.");
3448 staticpro (&Qcomma_dot
);
3450 Qinhibit_file_name_operation
= intern ("inhibit-file-name-operation");
3451 staticpro (&Qinhibit_file_name_operation
);
3453 Qascii_character
= intern ("ascii-character");
3454 staticpro (&Qascii_character
);
3456 Qfunction
= intern ("function");
3457 staticpro (&Qfunction
);
3459 Qload
= intern ("load");
3462 Qload_file_name
= intern ("load-file-name");
3463 staticpro (&Qload_file_name
);
3465 staticpro (&dump_path
);
3467 staticpro (&read_objects
);
3468 read_objects
= Qnil
;
3469 staticpro (&seen_list
);