Commit | Line | Data |
---|---|---|
078e7b4a | 1 | /* Lisp parsing and input streams. |
df6c90d8 | 2 | Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 98, 99, 2000, 2001 |
33046fc9 | 3 | Free Software Foundation, Inc. |
078e7b4a JB |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
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 | |
46947372 | 9 | the Free Software Foundation; either version 2, or (at your option) |
078e7b4a JB |
10 | any later version. |
11 | ||
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. | |
16 | ||
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 | |
3b7ad313 EN |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
078e7b4a JB |
21 | |
22 | ||
98280b76 | 23 | #include <config.h> |
078e7b4a JB |
24 | #include <stdio.h> |
25 | #include <sys/types.h> | |
26 | #include <sys/stat.h> | |
27 | #include <sys/file.h> | |
2c1b5dbe | 28 | #include <errno.h> |
078e7b4a | 29 | #include "lisp.h" |
95384e1e | 30 | #include "intervals.h" |
078e7b4a | 31 | #include "buffer.h" |
fe0e03f3 | 32 | #include "charset.h" |
57bda87a | 33 | #include <epaths.h> |
078e7b4a | 34 | #include "commands.h" |
e37c0805 | 35 | #include "keyboard.h" |
7bd279cd | 36 | #include "termhooks.h" |
078e7b4a JB |
37 | |
38 | #ifdef lint | |
39 | #include <sys/inode.h> | |
40 | #endif /* lint */ | |
41 | ||
79051982 RS |
42 | #ifdef MSDOS |
43 | #if __DJGPP__ < 2 | |
44 | #include <unistd.h> /* to get X_OK */ | |
45 | #endif | |
46 | #include "msdos.h" | |
47 | #endif | |
48 | ||
c1a2f60a AS |
49 | #ifdef HAVE_UNISTD_H |
50 | #include <unistd.h> | |
51 | #endif | |
52 | ||
078e7b4a JB |
53 | #ifndef X_OK |
54 | #define X_OK 01 | |
55 | #endif | |
56 | ||
078e7b4a | 57 | #include <math.h> |
078e7b4a | 58 | |
c011e9a5 RS |
59 | #ifdef HAVE_SETLOCALE |
60 | #include <locale.h> | |
61 | #endif /* HAVE_SETLOCALE */ | |
62 | ||
f7d279f0 RS |
63 | #ifndef O_RDONLY |
64 | #define O_RDONLY 0 | |
65 | #endif | |
66 | ||
79cf851c | 67 | #ifdef HAVE_FSEEKO |
68c45bf0 PE |
68 | #define file_offset off_t |
69 | #define file_tell ftello | |
70 | #else | |
71 | #define file_offset long | |
72 | #define file_tell ftell | |
73 | #endif | |
74 | ||
03695ace | 75 | #ifndef USE_CRT_DLL |
2c1b5dbe | 76 | extern int errno; |
03695ace | 77 | #endif |
2c1b5dbe | 78 | |
8a1f1537 | 79 | Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list; |
078e7b4a | 80 | Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist; |
20ea2964 | 81 | Lisp_Object Qascii_character, Qload, Qload_file_name; |
2b6cae0c | 82 | Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction; |
74549846 | 83 | Lisp_Object Qinhibit_file_name_operation; |
7bd279cd RS |
84 | |
85 | extern Lisp_Object Qevent_symbol_element_mask; | |
74549846 | 86 | extern Lisp_Object Qfile_exists_p; |
078e7b4a JB |
87 | |
88 | /* non-zero if inside `load' */ | |
89 | int load_in_progress; | |
90 | ||
1521a8fa RS |
91 | /* Directory in which the sources were found. */ |
92 | Lisp_Object Vsource_directory; | |
93 | ||
e61b9b87 SM |
94 | /* Search path and suffixes for files to be loaded. */ |
95 | Lisp_Object Vload_path, Vload_suffixes, default_suffixes; | |
078e7b4a | 96 | |
4116ab9f KH |
97 | /* File name of user's init file. */ |
98 | Lisp_Object Vuser_init_file; | |
99 | ||
ae321d28 RS |
100 | /* This is the user-visible association list that maps features to |
101 | lists of defs in their load files. */ | |
102 | Lisp_Object Vload_history; | |
103 | ||
20ea2964 | 104 | /* This is used to build the load history. */ |
ae321d28 RS |
105 | Lisp_Object Vcurrent_load_list; |
106 | ||
4b104c41 RS |
107 | /* List of files that were preloaded. */ |
108 | Lisp_Object Vpreloaded_file_list; | |
109 | ||
20ea2964 RS |
110 | /* Name of file actually being read by `load'. */ |
111 | Lisp_Object Vload_file_name; | |
112 | ||
84a15045 RS |
113 | /* Function to use for reading, in `load' and friends. */ |
114 | Lisp_Object Vload_read_function; | |
115 | ||
4ad679f9 EN |
116 | /* The association list of objects read with the #n=object form. |
117 | Each member of the list has the form (n . object), and is used to | |
118 | look up the object for the corresponding #n# construct. | |
119 | It must be set to nil before all top-level calls to read0. */ | |
120 | Lisp_Object read_objects; | |
121 | ||
b2a30870 RS |
122 | /* Nonzero means load should forcibly load all dynamic doc strings. */ |
123 | static int load_force_doc_strings; | |
124 | ||
94e554db RS |
125 | /* Nonzero means read should convert strings to unibyte. */ |
126 | static int load_convert_to_unibyte; | |
127 | ||
fe0e03f3 KH |
128 | /* Function to use for loading an Emacs lisp source file (not |
129 | compiled) instead of readevalloop. */ | |
130 | Lisp_Object Vload_source_file_function; | |
131 | ||
1ffcc3b1 DL |
132 | /* List of all DEFVAR_BOOL variables. Used by the byte optimizer. */ |
133 | Lisp_Object Vbyte_boolean_vars; | |
134 | ||
d2c6be7f RS |
135 | /* List of descriptors now open for Fload. */ |
136 | static Lisp_Object load_descriptor_list; | |
137 | ||
b2a30870 | 138 | /* File for get_file_char to read from. Use by load. */ |
078e7b4a JB |
139 | static FILE *instream; |
140 | ||
141 | /* When nonzero, read conses in pure space */ | |
142 | static int read_pure; | |
143 | ||
b2a30870 | 144 | /* For use within read-from-string (this reader is non-reentrant!!) */ |
078e7b4a | 145 | static int read_from_string_index; |
bed23cb2 | 146 | static int read_from_string_index_byte; |
078e7b4a | 147 | static int read_from_string_limit; |
17634846 | 148 | |
6f7f43d5 RS |
149 | /* Number of bytes left to read in the buffer character |
150 | that `readchar' has already advanced over. */ | |
151 | static int readchar_backlog; | |
152 | ||
c15cfd1f | 153 | /* This contains the last string skipped with #@. */ |
b2a30870 RS |
154 | static char *saved_doc_string; |
155 | /* Length of buffer allocated in saved_doc_string. */ | |
156 | static int saved_doc_string_size; | |
157 | /* Length of actual data in saved_doc_string. */ | |
158 | static int saved_doc_string_length; | |
159 | /* This is the file position that string came from. */ | |
68c45bf0 | 160 | static file_offset saved_doc_string_position; |
b2a30870 | 161 | |
c15cfd1f RS |
162 | /* This contains the previous string skipped with #@. |
163 | We copy it from saved_doc_string when a new string | |
164 | is put in saved_doc_string. */ | |
165 | static char *prev_saved_doc_string; | |
166 | /* Length of buffer allocated in prev_saved_doc_string. */ | |
167 | static int prev_saved_doc_string_size; | |
168 | /* Length of actual data in prev_saved_doc_string. */ | |
169 | static int prev_saved_doc_string_length; | |
170 | /* This is the file position that string came from. */ | |
68c45bf0 | 171 | static file_offset prev_saved_doc_string_position; |
c15cfd1f | 172 | |
17634846 RS |
173 | /* Nonzero means inside a new-style backquote |
174 | with no surrounding parentheses. | |
175 | Fread initializes this to zero, so we need not specbind it | |
176 | or worry about what happens to it when there is an error. */ | |
177 | static int new_backquote_flag; | |
7ee3bd7b GM |
178 | |
179 | /* A list of file names for files being loaded in Fload. Used to | |
180 | check for recursive loads. */ | |
181 | ||
182 | static Lisp_Object Vloads_in_progress; | |
183 | ||
550a625e GM |
184 | /* Non-zero means load dangerous compiled Lisp files. */ |
185 | ||
186 | int load_dangerous_libraries; | |
187 | ||
188 | /* A regular expression used to detect files compiled with Emacs. */ | |
189 | ||
190 | static Lisp_Object Vbytecomp_version_regexp; | |
191 | ||
a742d646 | 192 | static void to_multibyte P_ ((char **, char **, int *)); |
550a625e GM |
193 | static void readevalloop P_ ((Lisp_Object, FILE*, Lisp_Object, |
194 | Lisp_Object (*) (), int, | |
195 | Lisp_Object, Lisp_Object)); | |
196 | static Lisp_Object load_unwind P_ ((Lisp_Object)); | |
197 | static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object)); | |
198 | ||
078e7b4a JB |
199 | \f |
200 | /* Handle unreading and rereading of characters. | |
201 | Write READCHAR to read a character, | |
fe0e03f3 KH |
202 | UNREAD(c) to unread c to be read again. |
203 | ||
204 | These macros actually read/unread a byte code, multibyte characters | |
205 | are not handled here. The caller should manage them if necessary. | |
206 | */ | |
078e7b4a JB |
207 | |
208 | #define READCHAR readchar (readcharfun) | |
209 | #define UNREAD(c) unreadchar (readcharfun, c) | |
210 | ||
211 | static int | |
212 | readchar (readcharfun) | |
213 | Lisp_Object readcharfun; | |
214 | { | |
215 | Lisp_Object tem; | |
95384e1e | 216 | register int c; |
078e7b4a | 217 | |
cfff016d | 218 | if (BUFFERP (readcharfun)) |
078e7b4a | 219 | { |
bed23cb2 | 220 | register struct buffer *inbuffer = XBUFFER (readcharfun); |
078e7b4a | 221 | |
bed23cb2 RS |
222 | int pt_byte = BUF_PT_BYTE (inbuffer); |
223 | int orig_pt_byte = pt_byte; | |
6f7f43d5 | 224 | |
00a9a935 RS |
225 | if (readchar_backlog > 0) |
226 | /* We get the address of the byte just passed, | |
227 | which is the last byte of the character. | |
228 | The other bytes in this character are consecutive with it, | |
229 | because the gap can't be in the middle of a character. */ | |
230 | return *(BUF_BYTE_ADDRESS (inbuffer, BUF_PT_BYTE (inbuffer) - 1) | |
231 | - --readchar_backlog); | |
232 | ||
bed23cb2 RS |
233 | if (pt_byte >= BUF_ZV_BYTE (inbuffer)) |
234 | return -1; | |
078e7b4a | 235 | |
00a9a935 RS |
236 | readchar_backlog = -1; |
237 | ||
bed23cb2 RS |
238 | if (! NILP (inbuffer->enable_multibyte_characters)) |
239 | { | |
00a9a935 | 240 | /* Fetch the character code from the buffer. */ |
bed23cb2 RS |
241 | unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte); |
242 | BUF_INC_POS (inbuffer, pt_byte); | |
243 | c = STRING_CHAR (p, pt_byte - orig_pt_byte); | |
244 | } | |
245 | else | |
246 | { | |
247 | c = BUF_FETCH_BYTE (inbuffer, pt_byte); | |
248 | pt_byte++; | |
6f7f43d5 | 249 | } |
bed23cb2 | 250 | SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte); |
6f7f43d5 | 251 | |
bed23cb2 | 252 | return c; |
078e7b4a | 253 | } |
cfff016d | 254 | if (MARKERP (readcharfun)) |
078e7b4a | 255 | { |
bed23cb2 | 256 | register struct buffer *inbuffer = XMARKER (readcharfun)->buffer; |
078e7b4a | 257 | |
bed23cb2 RS |
258 | int bytepos = marker_byte_position (readcharfun); |
259 | int orig_bytepos = bytepos; | |
6f7f43d5 | 260 | |
00a9a935 RS |
261 | if (readchar_backlog > 0) |
262 | /* We get the address of the byte just passed, | |
263 | which is the last byte of the character. | |
264 | The other bytes in this character are consecutive with it, | |
265 | because the gap can't be in the middle of a character. */ | |
266 | return *(BUF_BYTE_ADDRESS (inbuffer, XMARKER (readcharfun)->bytepos - 1) | |
267 | - --readchar_backlog); | |
268 | ||
bed23cb2 RS |
269 | if (bytepos >= BUF_ZV_BYTE (inbuffer)) |
270 | return -1; | |
6f7f43d5 | 271 | |
00a9a935 RS |
272 | readchar_backlog = -1; |
273 | ||
bed23cb2 RS |
274 | if (! NILP (inbuffer->enable_multibyte_characters)) |
275 | { | |
00a9a935 | 276 | /* Fetch the character code from the buffer. */ |
bed23cb2 RS |
277 | unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos); |
278 | BUF_INC_POS (inbuffer, bytepos); | |
279 | c = STRING_CHAR (p, bytepos - orig_bytepos); | |
280 | } | |
281 | else | |
282 | { | |
283 | c = BUF_FETCH_BYTE (inbuffer, bytepos); | |
284 | bytepos++; | |
6f7f43d5 RS |
285 | } |
286 | ||
bed23cb2 RS |
287 | XMARKER (readcharfun)->bytepos = bytepos; |
288 | XMARKER (readcharfun)->charpos++; | |
289 | ||
290 | return c; | |
078e7b4a | 291 | } |
ad0153e4 RS |
292 | |
293 | if (EQ (readcharfun, Qlambda)) | |
294 | return read_bytecode_char (0); | |
295 | ||
078e7b4a | 296 | if (EQ (readcharfun, Qget_file_char)) |
2c1b5dbe KH |
297 | { |
298 | c = getc (instream); | |
299 | #ifdef EINTR | |
300 | /* Interrupted reads have been observed while reading over the network */ | |
301 | while (c == EOF && ferror (instream) && errno == EINTR) | |
302 | { | |
303 | clearerr (instream); | |
304 | c = getc (instream); | |
305 | } | |
306 | #endif | |
307 | return c; | |
308 | } | |
078e7b4a | 309 | |
cfff016d | 310 | if (STRINGP (readcharfun)) |
078e7b4a | 311 | { |
bed23cb2 | 312 | if (read_from_string_index >= read_from_string_limit) |
078e7b4a | 313 | c = -1; |
f0354c03 | 314 | else |
bed23cb2 RS |
315 | FETCH_STRING_CHAR_ADVANCE (c, readcharfun, |
316 | read_from_string_index, | |
317 | read_from_string_index_byte); | |
6f7f43d5 | 318 | |
078e7b4a JB |
319 | return c; |
320 | } | |
321 | ||
322 | tem = call0 (readcharfun); | |
323 | ||
265a9e55 | 324 | if (NILP (tem)) |
078e7b4a JB |
325 | return -1; |
326 | return XINT (tem); | |
327 | } | |
328 | ||
329 | /* Unread the character C in the way appropriate for the stream READCHARFUN. | |
330 | If the stream is a user function, call it with the char as argument. */ | |
331 | ||
332 | static void | |
333 | unreadchar (readcharfun, c) | |
334 | Lisp_Object readcharfun; | |
335 | int c; | |
336 | { | |
92fddec9 KH |
337 | if (c == -1) |
338 | /* Don't back up the pointer if we're unreading the end-of-input mark, | |
339 | since readchar didn't advance it when we read it. */ | |
340 | ; | |
cfff016d | 341 | else if (BUFFERP (readcharfun)) |
d7760ca9 | 342 | { |
bed23cb2 RS |
343 | struct buffer *b = XBUFFER (readcharfun); |
344 | int bytepos = BUF_PT_BYTE (b); | |
d7760ca9 | 345 | |
00a9a935 RS |
346 | if (readchar_backlog >= 0) |
347 | readchar_backlog++; | |
bed23cb2 | 348 | else |
00a9a935 RS |
349 | { |
350 | BUF_PT (b)--; | |
351 | if (! NILP (b->enable_multibyte_characters)) | |
352 | BUF_DEC_POS (b, bytepos); | |
353 | else | |
354 | bytepos--; | |
d7760ca9 | 355 | |
00a9a935 RS |
356 | BUF_PT_BYTE (b) = bytepos; |
357 | } | |
d7760ca9 | 358 | } |
cfff016d | 359 | else if (MARKERP (readcharfun)) |
d7760ca9 | 360 | { |
bed23cb2 RS |
361 | struct buffer *b = XMARKER (readcharfun)->buffer; |
362 | int bytepos = XMARKER (readcharfun)->bytepos; | |
d7760ca9 | 363 | |
00a9a935 RS |
364 | if (readchar_backlog >= 0) |
365 | readchar_backlog++; | |
bed23cb2 | 366 | else |
00a9a935 RS |
367 | { |
368 | XMARKER (readcharfun)->charpos--; | |
369 | if (! NILP (b->enable_multibyte_characters)) | |
370 | BUF_DEC_POS (b, bytepos); | |
371 | else | |
372 | bytepos--; | |
d7760ca9 | 373 | |
00a9a935 RS |
374 | XMARKER (readcharfun)->bytepos = bytepos; |
375 | } | |
d7760ca9 | 376 | } |
cfff016d | 377 | else if (STRINGP (readcharfun)) |
bed23cb2 RS |
378 | { |
379 | read_from_string_index--; | |
380 | read_from_string_index_byte | |
381 | = string_char_to_byte (readcharfun, read_from_string_index); | |
382 | } | |
ad0153e4 RS |
383 | else if (EQ (readcharfun, Qlambda)) |
384 | read_bytecode_char (1); | |
078e7b4a JB |
385 | else if (EQ (readcharfun, Qget_file_char)) |
386 | ungetc (c, instream); | |
387 | else | |
388 | call1 (readcharfun, make_number (c)); | |
389 | } | |
390 | ||
391 | static Lisp_Object read0 (), read1 (), read_list (), read_vector (); | |
6f7f43d5 | 392 | static int read_multibyte (); |
9e062b6c RS |
393 | static Lisp_Object substitute_object_recurse (); |
394 | static void substitute_object_in_subtree (), substitute_in_interval (); | |
395 | ||
078e7b4a | 396 | \f |
bed23cb2 | 397 | /* Get a character from the tty. */ |
078e7b4a | 398 | |
3d9b22be JB |
399 | extern Lisp_Object read_char (); |
400 | ||
f42be754 JB |
401 | /* Read input events until we get one that's acceptable for our purposes. |
402 | ||
403 | If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed | |
404 | until we get a character we like, and then stuffed into | |
405 | unread_switch_frame. | |
406 | ||
407 | If ASCII_REQUIRED is non-zero, we check function key events to see | |
408 | if the unmodified version of the symbol has a Qascii_character | |
409 | property, and use that character, if present. | |
410 | ||
411 | If ERROR_NONASCII is non-zero, we signal an error if the input we | |
412 | get isn't an ASCII character with modifiers. If it's zero but | |
413 | ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII | |
bb49a192 RS |
414 | character. |
415 | ||
416 | If INPUT_METHOD is nonzero, we invoke the current input method | |
417 | if the character warrants that. */ | |
cc39bc38 | 418 | |
f42be754 | 419 | Lisp_Object |
bb49a192 RS |
420 | read_filtered_event (no_switch_frame, ascii_required, error_nonascii, |
421 | input_method) | |
422 | int no_switch_frame, ascii_required, error_nonascii, input_method; | |
f42be754 | 423 | { |
153a17b7 KH |
424 | register Lisp_Object val, delayed_switch_frame; |
425 | ||
5dbf89bc | 426 | #ifdef HAVE_WINDOW_SYSTEM |
df6c90d8 GM |
427 | if (display_hourglass_p) |
428 | cancel_hourglass (); | |
5dbf89bc GM |
429 | #endif |
430 | ||
153a17b7 | 431 | delayed_switch_frame = Qnil; |
f42be754 JB |
432 | |
433 | /* Read until we get an acceptable event. */ | |
434 | retry: | |
bb49a192 RS |
435 | val = read_char (0, 0, 0, |
436 | (input_method ? Qnil : Qt), | |
437 | 0); | |
f42be754 | 438 | |
cfff016d | 439 | if (BUFFERP (val)) |
6c82d689 KH |
440 | goto retry; |
441 | ||
f42be754 | 442 | /* switch-frame events are put off until after the next ASCII |
8e6208c5 | 443 | character. This is better than signaling an error just because |
f42be754 JB |
444 | the last characters were typed to a separate minibuffer frame, |
445 | for example. Eventually, some code which can deal with | |
446 | switch-frame events will read it and process it. */ | |
447 | if (no_switch_frame | |
448 | && EVENT_HAS_PARAMETERS (val) | |
449 | && EQ (EVENT_HEAD (val), Qswitch_frame)) | |
450 | { | |
451 | delayed_switch_frame = val; | |
452 | goto retry; | |
453 | } | |
454 | ||
455 | if (ascii_required) | |
456 | { | |
457 | /* Convert certain symbols to their ASCII equivalents. */ | |
cfff016d | 458 | if (SYMBOLP (val)) |
f42be754 | 459 | { |
95384e1e | 460 | Lisp_Object tem, tem1; |
f42be754 JB |
461 | tem = Fget (val, Qevent_symbol_element_mask); |
462 | if (!NILP (tem)) | |
463 | { | |
464 | tem1 = Fget (Fcar (tem), Qascii_character); | |
465 | /* Merge this symbol's modifier bits | |
466 | with the ASCII equivalent of its basic code. */ | |
467 | if (!NILP (tem1)) | |
baf69866 | 468 | XSETFASTINT (val, XINT (tem1) | XINT (Fcar (Fcdr (tem)))); |
f42be754 JB |
469 | } |
470 | } | |
471 | ||
472 | /* If we don't have a character now, deal with it appropriately. */ | |
cfff016d | 473 | if (!INTEGERP (val)) |
f42be754 JB |
474 | { |
475 | if (error_nonascii) | |
476 | { | |
1ec84625 | 477 | Vunread_command_events = Fcons (val, Qnil); |
f42be754 JB |
478 | error ("Non-character input-event"); |
479 | } | |
480 | else | |
481 | goto retry; | |
482 | } | |
483 | } | |
484 | ||
485 | if (! NILP (delayed_switch_frame)) | |
486 | unread_switch_frame = delayed_switch_frame; | |
487 | ||
5dbf89bc | 488 | #ifdef HAVE_WINDOW_SYSTEM |
df6c90d8 GM |
489 | if (display_hourglass_p) |
490 | start_hourglass (); | |
5dbf89bc | 491 | #endif |
f42be754 | 492 | return val; |
f42be754 JB |
493 | } |
494 | ||
bb49a192 | 495 | DEFUN ("read-char", Fread_char, Sread_char, 0, 2, 0, |
5de38842 PJ |
496 | doc: /* Read a character from the command input (keyboard or macro). |
497 | It is returned as a number. | |
498 | If the user generates an event which is not a character (i.e. a mouse | |
499 | click or function key event), `read-char' signals an error. As an | |
500 | exception, switch-frame events are put off until non-ASCII events can | |
501 | be read. | |
502 | If you want to read non-character events, or ignore them, call | |
503 | `read-event' or `read-char-exclusive' instead. | |
504 | ||
505 | If the optional argument PROMPT is non-nil, display that as a prompt. | |
506 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | |
507 | input method is turned on in the current buffer, that input method | |
508 | is used for reading a character. */) | |
509 | (prompt, inherit_input_method) | |
fc351d2f | 510 | Lisp_Object prompt, inherit_input_method; |
078e7b4a | 511 | { |
bb49a192 RS |
512 | if (! NILP (prompt)) |
513 | message_with_string ("%s", prompt, 0); | |
fc351d2f | 514 | return read_filtered_event (1, 1, 1, ! NILP (inherit_input_method)); |
078e7b4a JB |
515 | } |
516 | ||
bb49a192 | 517 | DEFUN ("read-event", Fread_event, Sread_event, 0, 2, 0, |
5de38842 PJ |
518 | doc: /* Read an event object from the input stream. |
519 | If the optional argument PROMPT is non-nil, display that as a prompt. | |
520 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | |
521 | input method is turned on in the current buffer, that input method | |
522 | is used for reading a character. */) | |
523 | (prompt, inherit_input_method) | |
fc351d2f | 524 | Lisp_Object prompt, inherit_input_method; |
078e7b4a | 525 | { |
bb49a192 RS |
526 | if (! NILP (prompt)) |
527 | message_with_string ("%s", prompt, 0); | |
fc351d2f | 528 | return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method)); |
078e7b4a JB |
529 | } |
530 | ||
bb49a192 | 531 | DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 2, 0, |
5de38842 PJ |
532 | doc: /* Read a character from the command input (keyboard or macro). |
533 | It is returned as a number. Non-character events are ignored. | |
534 | ||
535 | If the optional argument PROMPT is non-nil, display that as a prompt. | |
536 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | |
537 | input method is turned on in the current buffer, that input method | |
538 | is used for reading a character. */) | |
539 | (prompt, inherit_input_method) | |
fc351d2f | 540 | Lisp_Object prompt, inherit_input_method; |
078e7b4a | 541 | { |
bb49a192 RS |
542 | if (! NILP (prompt)) |
543 | message_with_string ("%s", prompt, 0); | |
fc351d2f | 544 | return read_filtered_event (1, 1, 0, ! NILP (inherit_input_method)); |
078e7b4a | 545 | } |
078e7b4a JB |
546 | |
547 | DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0, | |
5de38842 PJ |
548 | doc: /* Don't use this yourself. */) |
549 | () | |
078e7b4a JB |
550 | { |
551 | register Lisp_Object val; | |
1805de4f | 552 | XSETINT (val, getc (instream)); |
078e7b4a JB |
553 | return val; |
554 | } | |
da84f340 GM |
555 | |
556 | ||
550a625e | 557 | \f |
da84f340 GM |
558 | /* Value is non-zero if the file asswociated with file descriptor FD |
559 | is a compiled Lisp file that's safe to load. Only files compiled | |
560 | with Emacs are safe to load. Files compiled with XEmacs can lead | |
561 | to a crash in Fbyte_code because of an incompatible change in the | |
562 | byte compiler. */ | |
563 | ||
564 | static int | |
565 | safe_to_load_p (fd) | |
566 | int fd; | |
567 | { | |
568 | char buf[512]; | |
569 | int nbytes, i; | |
570 | int safe_p = 1; | |
571 | ||
572 | /* Read the first few bytes from the file, and look for a line | |
573 | specifying the byte compiler version used. */ | |
574 | nbytes = emacs_read (fd, buf, sizeof buf - 1); | |
575 | if (nbytes > 0) | |
576 | { | |
577 | buf[nbytes] = '\0'; | |
578 | ||
579 | /* Skip to the next newline, skipping over the initial `ELC' | |
580 | with NUL bytes following it. */ | |
581 | for (i = 0; i < nbytes && buf[i] != '\n'; ++i) | |
582 | ; | |
583 | ||
584 | if (i < nbytes | |
585 | && fast_c_string_match_ignore_case (Vbytecomp_version_regexp, | |
586 | buf + i) < 0) | |
587 | safe_p = 0; | |
588 | } | |
589 | ||
590 | lseek (fd, 0, SEEK_SET); | |
591 | return safe_p; | |
592 | } | |
593 | ||
594 | ||
7ee3bd7b GM |
595 | /* Callback for record_unwind_protect. Restore the old load list OLD, |
596 | after loading a file successfully. */ | |
597 | ||
598 | static Lisp_Object | |
599 | record_load_unwind (old) | |
600 | Lisp_Object old; | |
601 | { | |
602 | return Vloads_in_progress = old; | |
603 | } | |
604 | ||
605 | ||
f0a50954 | 606 | DEFUN ("load", Fload, Sload, 1, 5, 0, |
5de38842 PJ |
607 | doc: /* Execute a file of Lisp code named FILE. |
608 | First try FILE with `.elc' appended, then try with `.el', | |
609 | then try FILE unmodified. Environment variable references in FILE | |
610 | are replaced with their values by calling `substitute-in-file-name'. | |
611 | This function searches the directories in `load-path'. | |
612 | If optional second arg NOERROR is non-nil, | |
613 | report no error if FILE doesn't exist. | |
614 | Print messages at start and end of loading unless | |
615 | optional third arg NOMESSAGE is non-nil. | |
616 | If optional fourth arg NOSUFFIX is non-nil, don't try adding | |
617 | suffixes `.elc' or `.el' to the specified name FILE. | |
618 | If optional fifth arg MUST-SUFFIX is non-nil, insist on | |
619 | the suffix `.elc' or `.el'; don't accept just FILE unless | |
620 | it ends in one of those suffixes or includes a directory name. | |
621 | Return t if file exists. */) | |
622 | (file, noerror, nomessage, nosuffix, must_suffix) | |
f0a50954 | 623 | Lisp_Object file, noerror, nomessage, nosuffix, must_suffix; |
078e7b4a JB |
624 | { |
625 | register FILE *stream; | |
626 | register int fd = -1; | |
627 | register Lisp_Object lispstream; | |
078e7b4a JB |
628 | int count = specpdl_ptr - specpdl; |
629 | Lisp_Object temp; | |
630 | struct gcpro gcpro1; | |
631 | Lisp_Object found; | |
04fc68e7 RS |
632 | /* 1 means we printed the ".el is newer" message. */ |
633 | int newer = 0; | |
634 | /* 1 means we are loading a compiled file. */ | |
635 | int compiled = 0; | |
c2225d00 | 636 | Lisp_Object handler; |
456c67a4 | 637 | int safe_p = 1; |
229ba775 | 638 | char *fmode = "r"; |
317073d5 | 639 | #ifdef DOS_NT |
229ba775 | 640 | fmode = "rt"; |
317073d5 | 641 | #endif /* DOS_NT */ |
078e7b4a | 642 | |
b7826503 | 643 | CHECK_STRING (file); |
078e7b4a | 644 | |
c2225d00 | 645 | /* If file name is magic, call the handler. */ |
e61b9b87 SM |
646 | /* This shouldn't be necessary any more now that `openp' handles it right. |
647 | handler = Ffind_file_name_handler (file, Qload); | |
648 | if (!NILP (handler)) | |
649 | return call5 (handler, Qload, file, noerror, nomessage, nosuffix); */ | |
c2225d00 | 650 | |
07a0bda3 RS |
651 | /* Do this after the handler to avoid |
652 | the need to gcpro noerror, nomessage and nosuffix. | |
e61b9b87 SM |
653 | (Below here, we care only whether they are nil or not.) |
654 | The presence of this call is the result of a historical accident: | |
655 | it used to be in every file-operations and when it got removed | |
656 | everywhere, it accidentally stayed here. Since then, enough people | |
657 | supposedly have things like (load "$PROJECT/foo.el") in their .emacs | |
658 | that it seemed risky to remove. */ | |
0745dce9 | 659 | file = Fsubstitute_in_file_name (file); |
07a0bda3 | 660 | |
078e7b4a JB |
661 | /* Avoid weird lossage with null string as arg, |
662 | since it would try to load a directory as a Lisp file */ | |
0745dce9 | 663 | if (XSTRING (file)->size > 0) |
078e7b4a | 664 | { |
471aa4a0 | 665 | int size = STRING_BYTES (XSTRING (file)); |
e61b9b87 | 666 | Lisp_Object tmp[2]; |
211f7dcd | 667 | |
0745dce9 | 668 | GCPRO1 (file); |
211f7dcd RS |
669 | |
670 | if (! NILP (must_suffix)) | |
671 | { | |
672 | /* Don't insist on adding a suffix if FILE already ends with one. */ | |
673 | if (size > 3 | |
674 | && !strcmp (XSTRING (file)->data + size - 3, ".el")) | |
675 | must_suffix = Qnil; | |
676 | else if (size > 4 | |
677 | && !strcmp (XSTRING (file)->data + size - 4, ".elc")) | |
678 | must_suffix = Qnil; | |
679 | /* Don't insist on adding a suffix | |
680 | if the argument includes a directory name. */ | |
681 | else if (! NILP (Ffile_name_directory (file))) | |
682 | must_suffix = Qnil; | |
683 | } | |
684 | ||
f0a50954 | 685 | fd = openp (Vload_path, file, |
e61b9b87 SM |
686 | (!NILP (nosuffix) ? Qnil |
687 | : !NILP (must_suffix) ? Vload_suffixes | |
688 | : Fappend (2, (tmp[0] = Vload_suffixes, | |
689 | tmp[1] = default_suffixes, | |
690 | tmp))), | |
078e7b4a | 691 | &found, 0); |
5a6e5452 | 692 | UNGCPRO; |
078e7b4a JB |
693 | } |
694 | ||
96dc0f4e | 695 | if (fd == -1) |
078e7b4a | 696 | { |
265a9e55 | 697 | if (NILP (noerror)) |
078e7b4a JB |
698 | while (1) |
699 | Fsignal (Qfile_error, Fcons (build_string ("Cannot open load file"), | |
0745dce9 | 700 | Fcons (file, Qnil))); |
078e7b4a JB |
701 | else |
702 | return Qnil; | |
703 | } | |
704 | ||
ba0d1195 | 705 | /* Tell startup.el whether or not we found the user's init file. */ |
4116ab9f KH |
706 | if (EQ (Qt, Vuser_init_file)) |
707 | Vuser_init_file = found; | |
708 | ||
96dc0f4e MB |
709 | /* If FD is -2, that means openp found a magic file. */ |
710 | if (fd == -2) | |
74549846 | 711 | { |
5e24a1f7 KH |
712 | if (NILP (Fequal (found, file))) |
713 | /* If FOUND is a different file name from FILE, | |
714 | find its handler even if we have already inhibited | |
715 | the `load' operation on FILE. */ | |
716 | handler = Ffind_file_name_handler (found, Qt); | |
717 | else | |
718 | handler = Ffind_file_name_handler (found, Qload); | |
719 | if (! NILP (handler)) | |
720 | return call5 (handler, Qload, found, noerror, nomessage, Qt); | |
74549846 RS |
721 | } |
722 | ||
550a625e GM |
723 | /* Check if we're stuck in a recursive load cycle. |
724 | ||
725 | 2000-09-21: It's not possible to just check for the file loaded | |
726 | being a member of Vloads_in_progress. This fails because of the | |
727 | way the byte compiler currently works; `provide's are not | |
728 | evaluted, see font-lock.el/jit-lock.el as an example. This | |
729 | leads to a certain amount of ``normal'' recursion. | |
730 | ||
731 | Also, just loading a file recursively is not always an error in | |
732 | the general case; the second load may do something different. */ | |
3ba6fd9a RS |
733 | { |
734 | int count = 0; | |
735 | Lisp_Object tem; | |
736 | for (tem = Vloads_in_progress; CONSP (tem); tem = XCDR (tem)) | |
737 | if (!NILP (Fequal (found, XCAR (tem)))) | |
738 | count++; | |
739 | if (count > 3) | |
740 | Fsignal (Qerror, Fcons (build_string ("Recursive load"), | |
741 | Fcons (found, Vloads_in_progress))); | |
742 | record_unwind_protect (record_load_unwind, Vloads_in_progress); | |
743 | Vloads_in_progress = Fcons (found, Vloads_in_progress); | |
744 | } | |
7ee3bd7b | 745 | |
471aa4a0 | 746 | if (!bcmp (&(XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 4]), |
96dc0f4e MB |
747 | ".elc", 4)) |
748 | /* Load .elc files directly, but not when they are | |
749 | remote and have no handler! */ | |
078e7b4a | 750 | { |
96dc0f4e | 751 | if (fd != -2) |
da84f340 | 752 | { |
96dc0f4e MB |
753 | struct stat s1, s2; |
754 | int result; | |
da84f340 | 755 | |
96dc0f4e MB |
756 | if (!safe_to_load_p (fd)) |
757 | { | |
758 | safe_p = 0; | |
759 | if (!load_dangerous_libraries) | |
760 | error ("File `%s' was not compiled in Emacs", | |
761 | XSTRING (found)->data); | |
762 | else if (!NILP (nomessage)) | |
763 | message_with_string ("File `%s' not compiled in Emacs", found, 1); | |
764 | } | |
04fc68e7 | 765 | |
96dc0f4e MB |
766 | compiled = 1; |
767 | ||
26fbf20b | 768 | #ifdef DOS_NT |
96dc0f4e | 769 | fmode = "rb"; |
26fbf20b | 770 | #endif /* DOS_NT */ |
96dc0f4e MB |
771 | stat ((char *)XSTRING (found)->data, &s1); |
772 | XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 1] = 0; | |
773 | result = stat ((char *)XSTRING (found)->data, &s2); | |
774 | if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime) | |
775 | { | |
776 | /* Make the progress messages mention that source is newer. */ | |
777 | newer = 1; | |
04fc68e7 | 778 | |
96dc0f4e MB |
779 | /* If we won't print another message, mention this anyway. */ |
780 | if (! NILP (nomessage)) | |
781 | message_with_string ("Source file `%s' newer than byte-compiled file", | |
782 | found, 1); | |
783 | } | |
784 | XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 1] = 'c'; | |
51ac6f83 | 785 | } |
078e7b4a | 786 | } |
fe0e03f3 KH |
787 | else |
788 | { | |
789 | /* We are loading a source file (*.el). */ | |
790 | if (!NILP (Vload_source_file_function)) | |
791 | { | |
7ee3bd7b | 792 | Lisp_Object val; |
96dc0f4e MB |
793 | |
794 | if (fd >= 0) | |
68c45bf0 | 795 | emacs_close (fd); |
7ee3bd7b GM |
796 | val = call4 (Vload_source_file_function, found, file, |
797 | NILP (noerror) ? Qnil : Qt, | |
798 | NILP (nomessage) ? Qnil : Qt); | |
799 | return unbind_to (count, val); | |
fe0e03f3 KH |
800 | } |
801 | } | |
078e7b4a | 802 | |
229ba775 | 803 | #ifdef WINDOWSNT |
68c45bf0 | 804 | emacs_close (fd); |
229ba775 EZ |
805 | stream = fopen ((char *) XSTRING (found)->data, fmode); |
806 | #else /* not WINDOWSNT */ | |
807 | stream = fdopen (fd, fmode); | |
808 | #endif /* not WINDOWSNT */ | |
078e7b4a JB |
809 | if (stream == 0) |
810 | { | |
68c45bf0 | 811 | emacs_close (fd); |
0745dce9 | 812 | error ("Failure to create stdio stream for %s", XSTRING (file)->data); |
078e7b4a JB |
813 | } |
814 | ||
4b104c41 RS |
815 | if (! NILP (Vpurify_flag)) |
816 | Vpreloaded_file_list = Fcons (file, Vpreloaded_file_list); | |
817 | ||
04fc68e7 RS |
818 | if (NILP (nomessage)) |
819 | { | |
da84f340 GM |
820 | if (!safe_p) |
821 | message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...", | |
822 | file, 1); | |
823 | else if (!compiled) | |
e28552a4 | 824 | message_with_string ("Loading %s (source)...", file, 1); |
db5cae4b | 825 | else if (newer) |
e28552a4 RS |
826 | message_with_string ("Loading %s (compiled; note, source file is newer)...", |
827 | file, 1); | |
db5cae4b | 828 | else /* The typical case; compiled file newer than source file. */ |
e28552a4 | 829 | message_with_string ("Loading %s...", file, 1); |
04fc68e7 | 830 | } |
078e7b4a | 831 | |
0745dce9 | 832 | GCPRO1 (file); |
838abf56 | 833 | lispstream = Fcons (Qnil, Qnil); |
f5df591a KR |
834 | XSETCARFASTINT (lispstream, (EMACS_UINT)stream >> 16); |
835 | XSETCDRFASTINT (lispstream, (EMACS_UINT)stream & 0xffff); | |
078e7b4a | 836 | record_unwind_protect (load_unwind, lispstream); |
d2c6be7f | 837 | record_unwind_protect (load_descriptor_unwind, load_descriptor_list); |
20ea2964 | 838 | specbind (Qload_file_name, found); |
74549846 | 839 | specbind (Qinhibit_file_name_operation, Qnil); |
d2c6be7f RS |
840 | load_descriptor_list |
841 | = Fcons (make_number (fileno (stream)), load_descriptor_list); | |
078e7b4a | 842 | load_in_progress++; |
976350af | 843 | readevalloop (Qget_file_char, stream, file, Feval, 0, Qnil, Qnil); |
078e7b4a JB |
844 | unbind_to (count, Qnil); |
845 | ||
846 | /* Run any load-hooks for this file. */ | |
0745dce9 | 847 | temp = Fassoc (file, Vafter_load_alist); |
265a9e55 | 848 | if (!NILP (temp)) |
078e7b4a JB |
849 | Fprogn (Fcdr (temp)); |
850 | UNGCPRO; | |
851 | ||
b2a30870 RS |
852 | if (saved_doc_string) |
853 | free (saved_doc_string); | |
854 | saved_doc_string = 0; | |
855 | saved_doc_string_size = 0; | |
856 | ||
c15cfd1f | 857 | if (prev_saved_doc_string) |
3cb65b0e | 858 | xfree (prev_saved_doc_string); |
c15cfd1f RS |
859 | prev_saved_doc_string = 0; |
860 | prev_saved_doc_string_size = 0; | |
861 | ||
265a9e55 | 862 | if (!noninteractive && NILP (nomessage)) |
04fc68e7 | 863 | { |
da84f340 GM |
864 | if (!safe_p) |
865 | message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done", | |
866 | file, 1); | |
867 | else if (!compiled) | |
e28552a4 | 868 | message_with_string ("Loading %s (source)...done", file, 1); |
db5cae4b | 869 | else if (newer) |
e28552a4 RS |
870 | message_with_string ("Loading %s (compiled; note, source file is newer)...done", |
871 | file, 1); | |
db5cae4b | 872 | else /* The typical case; compiled file newer than source file. */ |
e28552a4 | 873 | message_with_string ("Loading %s...done", file, 1); |
04fc68e7 | 874 | } |
7ee3bd7b | 875 | |
078e7b4a JB |
876 | return Qt; |
877 | } | |
878 | ||
879 | static Lisp_Object | |
880 | load_unwind (stream) /* used as unwind-protect function in load */ | |
881 | Lisp_Object stream; | |
882 | { | |
c1d497be KR |
883 | fclose ((FILE *) (XFASTINT (XCAR (stream)) << 16 |
884 | | XFASTINT (XCDR (stream)))); | |
078e7b4a JB |
885 | if (--load_in_progress < 0) load_in_progress = 0; |
886 | return Qnil; | |
887 | } | |
888 | ||
d2c6be7f RS |
889 | static Lisp_Object |
890 | load_descriptor_unwind (oldlist) | |
891 | Lisp_Object oldlist; | |
892 | { | |
893 | load_descriptor_list = oldlist; | |
838abf56 | 894 | return Qnil; |
d2c6be7f RS |
895 | } |
896 | ||
897 | /* Close all descriptors in use for Floads. | |
898 | This is used when starting a subprocess. */ | |
899 | ||
900 | void | |
901 | close_load_descs () | |
902 | { | |
f3849f25 | 903 | #ifndef WINDOWSNT |
d2c6be7f | 904 | Lisp_Object tail; |
c1d497be | 905 | for (tail = load_descriptor_list; !NILP (tail); tail = XCDR (tail)) |
68c45bf0 | 906 | emacs_close (XFASTINT (XCAR (tail))); |
f3849f25 | 907 | #endif |
d2c6be7f | 908 | } |
078e7b4a JB |
909 | \f |
910 | static int | |
911 | complete_filename_p (pathname) | |
912 | Lisp_Object pathname; | |
913 | { | |
914 | register unsigned char *s = XSTRING (pathname)->data; | |
317073d5 RS |
915 | return (IS_DIRECTORY_SEP (s[0]) |
916 | || (XSTRING (pathname)->size > 2 | |
917 | && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2])) | |
078e7b4a JB |
918 | #ifdef ALTOS |
919 | || *s == '@' | |
920 | #endif | |
921 | #ifdef VMS | |
922 | || index (s, ':') | |
923 | #endif /* VMS */ | |
924 | ); | |
925 | } | |
926 | ||
927 | /* Search for a file whose name is STR, looking in directories | |
928 | in the Lisp list PATH, and trying suffixes from SUFFIX. | |
078e7b4a JB |
929 | On success, returns a file descriptor. On failure, returns -1. |
930 | ||
e61b9b87 SM |
931 | SUFFIXES is a list of strings containing possible suffixes. |
932 | The empty suffix is automatically added iff the list is empty. | |
933 | ||
078e7b4a JB |
934 | EXEC_ONLY nonzero means don't open the files, |
935 | just look for one that is executable. In this case, | |
936 | returns 1 on success. | |
937 | ||
938 | If STOREPTR is nonzero, it points to a slot where the name of | |
939 | the file actually found should be stored as a Lisp string. | |
74549846 RS |
940 | nil is stored there on failure. |
941 | ||
96dc0f4e | 942 | If the file we find is remote, return -2 |
74549846 RS |
943 | but store the found remote file name in *STOREPTR. |
944 | We do not check for remote files if EXEC_ONLY is nonzero. */ | |
078e7b4a JB |
945 | |
946 | int | |
e61b9b87 | 947 | openp (path, str, suffixes, storeptr, exec_only) |
078e7b4a | 948 | Lisp_Object path, str; |
e61b9b87 | 949 | Lisp_Object suffixes; |
078e7b4a JB |
950 | Lisp_Object *storeptr; |
951 | int exec_only; | |
952 | { | |
953 | register int fd; | |
954 | int fn_size = 100; | |
955 | char buf[100]; | |
956 | register char *fn = buf; | |
957 | int absolute = 0; | |
958 | int want_size; | |
74549846 | 959 | Lisp_Object filename; |
078e7b4a | 960 | struct stat st; |
e61b9b87 SM |
961 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
962 | Lisp_Object string, tail; | |
963 | int max_suffix_len = 0; | |
964 | ||
965 | for (tail = suffixes; CONSP (tail); tail = XCDR (tail)) | |
966 | { | |
f5df591a | 967 | CHECK_STRING_CAR (tail); |
e61b9b87 | 968 | max_suffix_len = max (max_suffix_len, |
990ff03c | 969 | STRING_BYTES (XSTRING (XCAR (tail)))); |
e61b9b87 | 970 | } |
078e7b4a | 971 | |
990ff03c GM |
972 | string = filename = Qnil; |
973 | GCPRO5 (str, string, filename, path, suffixes); | |
974 | ||
078e7b4a JB |
975 | if (storeptr) |
976 | *storeptr = Qnil; | |
977 | ||
978 | if (complete_filename_p (str)) | |
979 | absolute = 1; | |
980 | ||
e61b9b87 | 981 | for (; CONSP (path); path = XCDR (path)) |
078e7b4a | 982 | { |
e61b9b87 | 983 | filename = Fexpand_file_name (str, XCAR (path)); |
078e7b4a JB |
984 | if (!complete_filename_p (filename)) |
985 | /* If there are non-absolute elts in PATH (eg ".") */ | |
986 | /* Of course, this could conceivably lose if luser sets | |
987 | default-directory to be something non-absolute... */ | |
988 | { | |
989 | filename = Fexpand_file_name (filename, current_buffer->directory); | |
990 | if (!complete_filename_p (filename)) | |
991 | /* Give up on this path element! */ | |
992 | continue; | |
993 | } | |
994 | ||
995 | /* Calculate maximum size of any filename made from | |
996 | this path element/specified file name and any possible suffix. */ | |
e61b9b87 | 997 | want_size = max_suffix_len + STRING_BYTES (XSTRING (filename)) + 1; |
078e7b4a JB |
998 | if (fn_size < want_size) |
999 | fn = (char *) alloca (fn_size = 100 + want_size); | |
1000 | ||
078e7b4a | 1001 | /* Loop over suffixes. */ |
e61b9b87 SM |
1002 | for (tail = NILP (suffixes) ? default_suffixes : suffixes; |
1003 | CONSP (tail); tail = XCDR (tail)) | |
078e7b4a | 1004 | { |
e61b9b87 | 1005 | int lsuffix = STRING_BYTES (XSTRING (XCAR (tail))); |
74549846 | 1006 | Lisp_Object handler; |
078e7b4a | 1007 | |
c49afcd7 RS |
1008 | /* Concatenate path element/specified name with the suffix. |
1009 | If the directory starts with /:, remove that. */ | |
1010 | if (XSTRING (filename)->size > 2 | |
1011 | && XSTRING (filename)->data[0] == '/' | |
1012 | && XSTRING (filename)->data[1] == ':') | |
1013 | { | |
1014 | strncpy (fn, XSTRING (filename)->data + 2, | |
471aa4a0 KH |
1015 | STRING_BYTES (XSTRING (filename)) - 2); |
1016 | fn[STRING_BYTES (XSTRING (filename)) - 2] = 0; | |
c49afcd7 RS |
1017 | } |
1018 | else | |
1019 | { | |
471aa4a0 KH |
1020 | strncpy (fn, XSTRING (filename)->data, |
1021 | STRING_BYTES (XSTRING (filename))); | |
1022 | fn[STRING_BYTES (XSTRING (filename))] = 0; | |
c49afcd7 RS |
1023 | } |
1024 | ||
078e7b4a | 1025 | if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */ |
e61b9b87 SM |
1026 | strncat (fn, XSTRING (XCAR (tail))->data, lsuffix); |
1027 | ||
74549846 | 1028 | /* Check that the file exists and is not a directory. */ |
e61b9b87 SM |
1029 | /* We used to only check for handlers on non-absolute file names: |
1030 | if (absolute) | |
1031 | handler = Qnil; | |
1032 | else | |
1033 | handler = Ffind_file_name_handler (filename, Qfile_exists_p); | |
1034 | It's not clear why that was the case and it breaks things like | |
1035 | (load "/bar.el") where the file is actually "/bar.el.gz". */ | |
1036 | handler = Ffind_file_name_handler (filename, Qfile_exists_p); | |
1037 | if (!NILP (handler) && !exec_only) | |
078e7b4a | 1038 | { |
74549846 | 1039 | int exists; |
078e7b4a | 1040 | |
74549846 | 1041 | string = build_string (fn); |
e61b9b87 SM |
1042 | exists = !NILP (Ffile_readable_p (string)); |
1043 | if (exists && !NILP (Ffile_directory_p (build_string (fn)))) | |
74549846 RS |
1044 | exists = 0; |
1045 | ||
1046 | if (exists) | |
078e7b4a JB |
1047 | { |
1048 | /* We succeeded; return this descriptor and filename. */ | |
1049 | if (storeptr) | |
1050 | *storeptr = build_string (fn); | |
5ef2a3c0 | 1051 | UNGCPRO; |
96dc0f4e | 1052 | return -2; |
74549846 RS |
1053 | } |
1054 | } | |
1055 | else | |
1056 | { | |
1057 | int exists = (stat (fn, &st) >= 0 | |
1058 | && (st.st_mode & S_IFMT) != S_IFDIR); | |
1059 | if (exists) | |
1060 | { | |
1061 | /* Check that we can access or open it. */ | |
1062 | if (exec_only) | |
1063 | fd = (access (fn, X_OK) == 0) ? 1 : -1; | |
1064 | else | |
68c45bf0 | 1065 | fd = emacs_open (fn, O_RDONLY, 0); |
74549846 RS |
1066 | |
1067 | if (fd >= 0) | |
1068 | { | |
1069 | /* We succeeded; return this descriptor and filename. */ | |
1070 | if (storeptr) | |
1071 | *storeptr = build_string (fn); | |
1072 | UNGCPRO; | |
1073 | return fd; | |
1074 | } | |
078e7b4a JB |
1075 | } |
1076 | } | |
078e7b4a | 1077 | } |
5a6e5452 | 1078 | if (absolute) |
5ef2a3c0 | 1079 | break; |
078e7b4a JB |
1080 | } |
1081 | ||
5ef2a3c0 KH |
1082 | UNGCPRO; |
1083 | return -1; | |
078e7b4a JB |
1084 | } |
1085 | ||
1086 | \f | |
ae321d28 RS |
1087 | /* Merge the list we've accumulated of globals from the current input source |
1088 | into the load_history variable. The details depend on whether | |
1089 | the source has an associated file name or not. */ | |
1090 | ||
1091 | static void | |
1092 | build_load_history (stream, source) | |
1093 | FILE *stream; | |
1094 | Lisp_Object source; | |
1095 | { | |
1096 | register Lisp_Object tail, prev, newelt; | |
1097 | register Lisp_Object tem, tem2; | |
1098 | register int foundit, loading; | |
1099 | ||
1100 | loading = stream || !NARROWED; | |
1101 | ||
1102 | tail = Vload_history; | |
1103 | prev = Qnil; | |
1104 | foundit = 0; | |
1105 | while (!NILP (tail)) | |
1106 | { | |
1107 | tem = Fcar (tail); | |
1108 | ||
1109 | /* Find the feature's previous assoc list... */ | |
1110 | if (!NILP (Fequal (source, Fcar (tem)))) | |
1111 | { | |
1112 | foundit = 1; | |
1113 | ||
1114 | /* If we're loading, remove it. */ | |
1115 | if (loading) | |
1116 | { | |
1117 | if (NILP (prev)) | |
1118 | Vload_history = Fcdr (tail); | |
1119 | else | |
1120 | Fsetcdr (prev, Fcdr (tail)); | |
1121 | } | |
1122 | ||
1123 | /* Otherwise, cons on new symbols that are not already members. */ | |
1124 | else | |
1125 | { | |
1126 | tem2 = Vcurrent_load_list; | |
1127 | ||
1128 | while (CONSP (tem2)) | |
1129 | { | |
1130 | newelt = Fcar (tem2); | |
1131 | ||
1132 | if (NILP (Fmemq (newelt, tem))) | |
1133 | Fsetcar (tail, Fcons (Fcar (tem), | |
1134 | Fcons (newelt, Fcdr (tem)))); | |
1135 | ||
1136 | tem2 = Fcdr (tem2); | |
1137 | QUIT; | |
1138 | } | |
1139 | } | |
1140 | } | |
1141 | else | |
1142 | prev = tail; | |
1143 | tail = Fcdr (tail); | |
1144 | QUIT; | |
1145 | } | |
1146 | ||
8a1f1537 RS |
1147 | /* If we're loading, cons the new assoc onto the front of load-history, |
1148 | the most-recently-loaded position. Also do this if we didn't find | |
1149 | an existing member for the current source. */ | |
1150 | if (loading || !foundit) | |
1151 | Vload_history = Fcons (Fnreverse (Vcurrent_load_list), | |
1152 | Vload_history); | |
ae321d28 RS |
1153 | } |
1154 | ||
078e7b4a | 1155 | Lisp_Object |
232ccf27 DL |
1156 | unreadpure (junk) /* Used as unwind-protect function in readevalloop */ |
1157 | Lisp_Object junk; | |
078e7b4a JB |
1158 | { |
1159 | read_pure = 0; | |
1160 | return Qnil; | |
1161 | } | |
1162 | ||
94e554db RS |
1163 | static Lisp_Object |
1164 | readevalloop_1 (old) | |
1165 | Lisp_Object old; | |
1166 | { | |
1167 | load_convert_to_unibyte = ! NILP (old); | |
1168 | return Qnil; | |
1169 | } | |
1170 | ||
9c97398c GM |
1171 | /* Signal an `end-of-file' error, if possible with file name |
1172 | information. */ | |
1173 | ||
1174 | static void | |
1175 | end_of_file_error () | |
1176 | { | |
1177 | Lisp_Object data; | |
1178 | ||
1179 | if (STRINGP (Vload_file_name)) | |
1180 | data = Fcons (Vload_file_name, Qnil); | |
1181 | else | |
1182 | data = Qnil; | |
1183 | ||
1184 | Fsignal (Qend_of_file, data); | |
1185 | } | |
1186 | ||
94e554db | 1187 | /* UNIBYTE specifies how to set load_convert_to_unibyte |
976350af RS |
1188 | for this invocation. |
1189 | READFUN, if non-nil, is used instead of `read'. */ | |
94e554db | 1190 | |
078e7b4a | 1191 | static void |
976350af | 1192 | readevalloop (readcharfun, stream, sourcename, evalfun, printflag, unibyte, readfun) |
078e7b4a | 1193 | Lisp_Object readcharfun; |
ae321d28 RS |
1194 | FILE *stream; |
1195 | Lisp_Object sourcename; | |
078e7b4a JB |
1196 | Lisp_Object (*evalfun) (); |
1197 | int printflag; | |
976350af | 1198 | Lisp_Object unibyte, readfun; |
078e7b4a JB |
1199 | { |
1200 | register int c; | |
1201 | register Lisp_Object val; | |
1202 | int count = specpdl_ptr - specpdl; | |
8a1f1537 | 1203 | struct gcpro gcpro1; |
49cf7ff4 | 1204 | struct buffer *b = 0; |
f38952fe | 1205 | int continue_reading_p; |
49cf7ff4 RS |
1206 | |
1207 | if (BUFFERP (readcharfun)) | |
1208 | b = XBUFFER (readcharfun); | |
1209 | else if (MARKERP (readcharfun)) | |
1210 | b = XMARKER (readcharfun)->buffer; | |
078e7b4a JB |
1211 | |
1212 | specbind (Qstandard_input, readcharfun); | |
8a1f1537 | 1213 | specbind (Qcurrent_load_list, Qnil); |
94e554db RS |
1214 | record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil); |
1215 | load_convert_to_unibyte = !NILP (unibyte); | |
078e7b4a | 1216 | |
00a9a935 | 1217 | readchar_backlog = -1; |
6f7f43d5 | 1218 | |
8a1f1537 | 1219 | GCPRO1 (sourcename); |
ae321d28 | 1220 | |
ae321d28 RS |
1221 | LOADHIST_ATTACH (sourcename); |
1222 | ||
f38952fe GM |
1223 | continue_reading_p = 1; |
1224 | while (continue_reading_p) | |
078e7b4a | 1225 | { |
49cf7ff4 RS |
1226 | if (b != 0 && NILP (b->name)) |
1227 | error ("Reading from killed buffer"); | |
1228 | ||
078e7b4a JB |
1229 | instream = stream; |
1230 | c = READCHAR; | |
1231 | if (c == ';') | |
1232 | { | |
1233 | while ((c = READCHAR) != '\n' && c != -1); | |
1234 | continue; | |
1235 | } | |
1236 | if (c < 0) break; | |
6069d957 RS |
1237 | |
1238 | /* Ignore whitespace here, so we can detect eof. */ | |
1239 | if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r') | |
1240 | continue; | |
078e7b4a | 1241 | |
265a9e55 | 1242 | if (!NILP (Vpurify_flag) && c == '(') |
078e7b4a | 1243 | { |
0e326373 | 1244 | int count1 = specpdl_ptr - specpdl; |
078e7b4a JB |
1245 | record_unwind_protect (unreadpure, Qnil); |
1246 | val = read_list (-1, readcharfun); | |
0e326373 | 1247 | unbind_to (count1, Qnil); |
078e7b4a JB |
1248 | } |
1249 | else | |
1250 | { | |
1251 | UNREAD (c); | |
4ad679f9 | 1252 | read_objects = Qnil; |
f38952fe GM |
1253 | if (!NILP (readfun)) |
1254 | { | |
1255 | val = call1 (readfun, readcharfun); | |
1256 | ||
1257 | /* If READCHARFUN has set point to ZV, we should | |
1258 | stop reading, even if the form read sets point | |
1259 | to a different value when evaluated. */ | |
1260 | if (BUFFERP (readcharfun)) | |
1261 | { | |
1262 | struct buffer *b = XBUFFER (readcharfun); | |
1263 | if (BUF_PT (b) == BUF_ZV (b)) | |
1264 | continue_reading_p = 0; | |
1265 | } | |
1266 | } | |
976350af | 1267 | else if (! NILP (Vload_read_function)) |
84a15045 | 1268 | val = call1 (Vload_read_function, readcharfun); |
976350af RS |
1269 | else |
1270 | val = read0 (readcharfun); | |
078e7b4a JB |
1271 | } |
1272 | ||
1273 | val = (*evalfun) (val); | |
f38952fe | 1274 | |
078e7b4a JB |
1275 | if (printflag) |
1276 | { | |
1277 | Vvalues = Fcons (val, Vvalues); | |
1278 | if (EQ (Vstandard_output, Qt)) | |
1279 | Fprin1 (val, Qnil); | |
1280 | else | |
1281 | Fprint (val, Qnil); | |
1282 | } | |
1283 | } | |
1284 | ||
ae321d28 | 1285 | build_load_history (stream, sourcename); |
ae321d28 RS |
1286 | UNGCPRO; |
1287 | ||
078e7b4a JB |
1288 | unbind_to (count, Qnil); |
1289 | } | |
1290 | ||
1076254d | 1291 | DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 5, "", |
5de38842 PJ |
1292 | doc: /* Execute the current buffer as Lisp code. |
1293 | Programs can pass two arguments, BUFFER and PRINTFLAG. | |
1294 | BUFFER is the buffer to evaluate (nil means use current buffer). | |
1295 | PRINTFLAG controls printing of output: | |
1296 | nil means discard it; anything else is stream for print. | |
1297 | ||
1298 | If the optional third argument FILENAME is non-nil, | |
1299 | it specifies the file name to use for `load-history'. | |
1300 | The optional fourth argument UNIBYTE specifies `load-convert-to-unibyte' | |
1301 | for this invocation. | |
1302 | ||
1303 | The optional fifth argument DO-ALLOW-PRINT, if not-nil, specifies that | |
1304 | `print' and related functions should work normally even if PRINTFLAG is nil. | |
1305 | ||
1306 | This function preserves the position of point. */) | |
1307 | (buffer, printflag, filename, unibyte, do_allow_print) | |
1076254d | 1308 | Lisp_Object buffer, printflag, filename, unibyte, do_allow_print; |
228d4b1c JA |
1309 | { |
1310 | int count = specpdl_ptr - specpdl; | |
1311 | Lisp_Object tem, buf; | |
1312 | ||
9391b698 | 1313 | if (NILP (buffer)) |
228d4b1c JA |
1314 | buf = Fcurrent_buffer (); |
1315 | else | |
9391b698 | 1316 | buf = Fget_buffer (buffer); |
dfdb645c | 1317 | if (NILP (buf)) |
13febd85 | 1318 | error ("No such buffer"); |
228d4b1c | 1319 | |
1076254d | 1320 | if (NILP (printflag) && NILP (do_allow_print)) |
228d4b1c JA |
1321 | tem = Qsymbolp; |
1322 | else | |
1323 | tem = printflag; | |
13febd85 RS |
1324 | |
1325 | if (NILP (filename)) | |
1326 | filename = XBUFFER (buf)->filename; | |
1327 | ||
228d4b1c JA |
1328 | specbind (Qstandard_output, tem); |
1329 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
1330 | BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); | |
976350af | 1331 | readevalloop (buf, 0, filename, Feval, !NILP (printflag), unibyte, Qnil); |
cb09ab7a | 1332 | unbind_to (count, Qnil); |
228d4b1c JA |
1333 | |
1334 | return Qnil; | |
1335 | } | |
1336 | ||
976350af | 1337 | DEFUN ("eval-region", Feval_region, Seval_region, 2, 4, "r", |
5de38842 PJ |
1338 | doc: /* Execute the region as Lisp code. |
1339 | When called from programs, expects two arguments, | |
1340 | giving starting and ending indices in the current buffer | |
1341 | of the text to be executed. | |
1342 | Programs can pass third argument PRINTFLAG which controls output: | |
1343 | nil means discard it; anything else is stream for printing it. | |
1344 | Also the fourth argument READ-FUNCTION, if non-nil, is used | |
1345 | instead of `read' to read each expression. It gets one argument | |
1346 | which is the input stream for reading characters. | |
1347 | ||
1348 | This function does not move point. */) | |
1349 | (start, end, printflag, read_function) | |
976350af | 1350 | Lisp_Object start, end, printflag, read_function; |
078e7b4a JB |
1351 | { |
1352 | int count = specpdl_ptr - specpdl; | |
ae321d28 RS |
1353 | Lisp_Object tem, cbuf; |
1354 | ||
1355 | cbuf = Fcurrent_buffer (); | |
078e7b4a | 1356 | |
265a9e55 | 1357 | if (NILP (printflag)) |
078e7b4a JB |
1358 | tem = Qsymbolp; |
1359 | else | |
1360 | tem = printflag; | |
1361 | specbind (Qstandard_output, tem); | |
1362 | ||
265a9e55 | 1363 | if (NILP (printflag)) |
078e7b4a JB |
1364 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
1365 | record_unwind_protect (save_restriction_restore, save_restriction_save ()); | |
1366 | ||
9391b698 EN |
1367 | /* This both uses start and checks its type. */ |
1368 | Fgoto_char (start); | |
1369 | Fnarrow_to_region (make_number (BEGV), end); | |
94e554db | 1370 | readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval, |
976350af | 1371 | !NILP (printflag), Qnil, read_function); |
078e7b4a JB |
1372 | |
1373 | return unbind_to (count, Qnil); | |
1374 | } | |
1375 | ||
078e7b4a JB |
1376 | \f |
1377 | DEFUN ("read", Fread, Sread, 0, 1, 0, | |
5de38842 PJ |
1378 | doc: /* Read one Lisp expression as text from STREAM, return as Lisp object. |
1379 | If STREAM is nil, use the value of `standard-input' (which see). | |
1380 | STREAM or the value of `standard-input' may be: | |
1381 | a buffer (read from point and advance it) | |
1382 | a marker (read from where it points and advance it) | |
1383 | a function (call it with no arguments for each character, | |
1384 | call it with a char as argument to push a char back) | |
1385 | a string (takes text from string, starting at the beginning) | |
1386 | t (read text line using minibuffer and use it, or read from | |
1387 | standard input in batch mode). */) | |
1388 | (stream) | |
5be02dff | 1389 | Lisp_Object stream; |
078e7b4a JB |
1390 | { |
1391 | extern Lisp_Object Fread_minibuffer (); | |
1392 | ||
5be02dff KH |
1393 | if (NILP (stream)) |
1394 | stream = Vstandard_input; | |
1395 | if (EQ (stream, Qt)) | |
1396 | stream = Qread_char; | |
078e7b4a | 1397 | |
00a9a935 | 1398 | readchar_backlog = -1; |
17634846 | 1399 | new_backquote_flag = 0; |
4ad679f9 | 1400 | read_objects = Qnil; |
17634846 | 1401 | |
5be02dff | 1402 | if (EQ (stream, Qread_char)) |
078e7b4a | 1403 | return Fread_minibuffer (build_string ("Lisp expression: "), Qnil); |
078e7b4a | 1404 | |
5be02dff KH |
1405 | if (STRINGP (stream)) |
1406 | return Fcar (Fread_from_string (stream, Qnil, Qnil)); | |
078e7b4a | 1407 | |
5be02dff | 1408 | return read0 (stream); |
078e7b4a JB |
1409 | } |
1410 | ||
1411 | DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0, | |
5de38842 PJ |
1412 | doc: /* Read one Lisp expression which is represented as text by STRING. |
1413 | Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX). | |
1414 | START and END optionally delimit a substring of STRING from which to read; | |
1415 | they default to 0 and (length STRING) respectively. */) | |
1416 | (string, start, end) | |
078e7b4a JB |
1417 | Lisp_Object string, start, end; |
1418 | { | |
1419 | int startval, endval; | |
1420 | Lisp_Object tem; | |
1421 | ||
b7826503 | 1422 | CHECK_STRING (string); |
078e7b4a | 1423 | |
265a9e55 | 1424 | if (NILP (end)) |
bed23cb2 | 1425 | endval = XSTRING (string)->size; |
078e7b4a | 1426 | else |
e28552a4 | 1427 | { |
b7826503 | 1428 | CHECK_NUMBER (end); |
8028e0ed | 1429 | endval = XINT (end); |
bed23cb2 | 1430 | if (endval < 0 || endval > XSTRING (string)->size) |
078e7b4a JB |
1431 | args_out_of_range (string, end); |
1432 | } | |
1433 | ||
265a9e55 | 1434 | if (NILP (start)) |
078e7b4a JB |
1435 | startval = 0; |
1436 | else | |
e28552a4 | 1437 | { |
b7826503 | 1438 | CHECK_NUMBER (start); |
8028e0ed | 1439 | startval = XINT (start); |
078e7b4a JB |
1440 | if (startval < 0 || startval > endval) |
1441 | args_out_of_range (string, start); | |
1442 | } | |
1443 | ||
1444 | read_from_string_index = startval; | |
bed23cb2 | 1445 | read_from_string_index_byte = string_char_to_byte (string, startval); |
078e7b4a JB |
1446 | read_from_string_limit = endval; |
1447 | ||
17634846 | 1448 | new_backquote_flag = 0; |
4ad679f9 | 1449 | read_objects = Qnil; |
17634846 | 1450 | |
078e7b4a | 1451 | tem = read0 (string); |
bed23cb2 | 1452 | return Fcons (tem, make_number (read_from_string_index)); |
078e7b4a JB |
1453 | } |
1454 | \f | |
6428369f KH |
1455 | /* Use this for recursive reads, in contexts where internal tokens |
1456 | are not allowed. */ | |
e28552a4 | 1457 | |
078e7b4a JB |
1458 | static Lisp_Object |
1459 | read0 (readcharfun) | |
1460 | Lisp_Object readcharfun; | |
1461 | { | |
1462 | register Lisp_Object val; | |
e28552a4 | 1463 | int c; |
078e7b4a | 1464 | |
17634846 | 1465 | val = read1 (readcharfun, &c, 0); |
6428369f | 1466 | if (c) |
93d75e4c RS |
1467 | Fsignal (Qinvalid_read_syntax, Fcons (Fmake_string (make_number (1), |
1468 | make_number (c)), | |
e28552a4 | 1469 | Qnil)); |
078e7b4a JB |
1470 | |
1471 | return val; | |
1472 | } | |
1473 | \f | |
1474 | static int read_buffer_size; | |
1475 | static char *read_buffer; | |
1476 | ||
fe0e03f3 KH |
1477 | /* Read multibyte form and return it as a character. C is a first |
1478 | byte of multibyte form, and rest of them are read from | |
1479 | READCHARFUN. */ | |
6f7f43d5 | 1480 | |
fe0e03f3 KH |
1481 | static int |
1482 | read_multibyte (c, readcharfun) | |
1483 | register int c; | |
1484 | Lisp_Object readcharfun; | |
1485 | { | |
1486 | /* We need the actual character code of this multibyte | |
1487 | characters. */ | |
449fea39 | 1488 | unsigned char str[MAX_MULTIBYTE_LENGTH]; |
fe0e03f3 | 1489 | int len = 0; |
0d5e5843 | 1490 | int bytes; |
fe0e03f3 KH |
1491 | |
1492 | str[len++] = c; | |
1493 | while ((c = READCHAR) >= 0xA0 | |
449fea39 | 1494 | && len < MAX_MULTIBYTE_LENGTH) |
fe0e03f3 KH |
1495 | str[len++] = c; |
1496 | UNREAD (c); | |
0d5e5843 KH |
1497 | if (UNIBYTE_STR_AS_MULTIBYTE_P (str, len, bytes)) |
1498 | return STRING_CHAR (str, len); | |
1499 | /* The byte sequence is not valid as multibyte. Unread all bytes | |
1500 | but the first one, and return the first byte. */ | |
1501 | while (--len > 0) | |
1502 | UNREAD (str[len]); | |
1503 | return str[0]; | |
fe0e03f3 KH |
1504 | } |
1505 | ||
6f7f43d5 RS |
1506 | /* Read a \-escape sequence, assuming we already read the `\'. */ |
1507 | ||
078e7b4a | 1508 | static int |
e7fc914b | 1509 | read_escape (readcharfun, stringp) |
078e7b4a | 1510 | Lisp_Object readcharfun; |
e7fc914b | 1511 | int stringp; |
078e7b4a JB |
1512 | { |
1513 | register int c = READCHAR; | |
1514 | switch (c) | |
1515 | { | |
f3849f25 | 1516 | case -1: |
da3b886d | 1517 | end_of_file_error (); |
f3849f25 | 1518 | |
078e7b4a | 1519 | case 'a': |
265a9e55 | 1520 | return '\007'; |
078e7b4a JB |
1521 | case 'b': |
1522 | return '\b'; | |
f405a585 RS |
1523 | case 'd': |
1524 | return 0177; | |
078e7b4a JB |
1525 | case 'e': |
1526 | return 033; | |
1527 | case 'f': | |
1528 | return '\f'; | |
1529 | case 'n': | |
1530 | return '\n'; | |
1531 | case 'r': | |
1532 | return '\r'; | |
1533 | case 't': | |
1534 | return '\t'; | |
1535 | case 'v': | |
1536 | return '\v'; | |
1537 | case '\n': | |
1538 | return -1; | |
e28552a4 | 1539 | case ' ': |
e7fc914b KH |
1540 | if (stringp) |
1541 | return -1; | |
1542 | return ' '; | |
078e7b4a JB |
1543 | |
1544 | case 'M': | |
1545 | c = READCHAR; | |
1546 | if (c != '-') | |
1547 | error ("Invalid escape character syntax"); | |
1548 | c = READCHAR; | |
1549 | if (c == '\\') | |
e7fc914b | 1550 | c = read_escape (readcharfun, 0); |
7bd279cd | 1551 | return c | meta_modifier; |
f405a585 RS |
1552 | |
1553 | case 'S': | |
1554 | c = READCHAR; | |
1555 | if (c != '-') | |
1556 | error ("Invalid escape character syntax"); | |
1557 | c = READCHAR; | |
1558 | if (c == '\\') | |
e7fc914b | 1559 | c = read_escape (readcharfun, 0); |
7bd279cd RS |
1560 | return c | shift_modifier; |
1561 | ||
1562 | case 'H': | |
1563 | c = READCHAR; | |
1564 | if (c != '-') | |
1565 | error ("Invalid escape character syntax"); | |
1566 | c = READCHAR; | |
1567 | if (c == '\\') | |
e7fc914b | 1568 | c = read_escape (readcharfun, 0); |
7bd279cd RS |
1569 | return c | hyper_modifier; |
1570 | ||
1571 | case 'A': | |
1572 | c = READCHAR; | |
1573 | if (c != '-') | |
1574 | error ("Invalid escape character syntax"); | |
1575 | c = READCHAR; | |
1576 | if (c == '\\') | |
e7fc914b | 1577 | c = read_escape (readcharfun, 0); |
7bd279cd RS |
1578 | return c | alt_modifier; |
1579 | ||
1580 | case 's': | |
1581 | c = READCHAR; | |
1582 | if (c != '-') | |
1583 | error ("Invalid escape character syntax"); | |
1584 | c = READCHAR; | |
1585 | if (c == '\\') | |
e7fc914b | 1586 | c = read_escape (readcharfun, 0); |
7bd279cd | 1587 | return c | super_modifier; |
078e7b4a JB |
1588 | |
1589 | case 'C': | |
1590 | c = READCHAR; | |
1591 | if (c != '-') | |
1592 | error ("Invalid escape character syntax"); | |
1593 | case '^': | |
1594 | c = READCHAR; | |
1595 | if (c == '\\') | |
e7fc914b | 1596 | c = read_escape (readcharfun, 0); |
164d590d KH |
1597 | if ((c & ~CHAR_MODIFIER_MASK) == '?') |
1598 | return 0177 | (c & CHAR_MODIFIER_MASK); | |
1599 | else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))) | |
1600 | return c | ctrl_modifier; | |
f405a585 RS |
1601 | /* ASCII control chars are made from letters (both cases), |
1602 | as well as the non-letters within 0100...0137. */ | |
1603 | else if ((c & 0137) >= 0101 && (c & 0137) <= 0132) | |
1604 | return (c & (037 | ~0177)); | |
1605 | else if ((c & 0177) >= 0100 && (c & 0177) <= 0137) | |
1606 | return (c & (037 | ~0177)); | |
078e7b4a | 1607 | else |
7bd279cd | 1608 | return c | ctrl_modifier; |
078e7b4a JB |
1609 | |
1610 | case '0': | |
1611 | case '1': | |
1612 | case '2': | |
1613 | case '3': | |
1614 | case '4': | |
1615 | case '5': | |
1616 | case '6': | |
1617 | case '7': | |
1618 | /* An octal escape, as in ANSI C. */ | |
1619 | { | |
1620 | register int i = c - '0'; | |
1621 | register int count = 0; | |
1622 | while (++count < 3) | |
1623 | { | |
1624 | if ((c = READCHAR) >= '0' && c <= '7') | |
1625 | { | |
1626 | i *= 8; | |
1627 | i += c - '0'; | |
1628 | } | |
1629 | else | |
1630 | { | |
1631 | UNREAD (c); | |
1632 | break; | |
1633 | } | |
1634 | } | |
1635 | return i; | |
1636 | } | |
1637 | ||
1638 | case 'x': | |
1639 | /* A hex escape, as in ANSI C. */ | |
1640 | { | |
1641 | int i = 0; | |
1642 | while (1) | |
1643 | { | |
1644 | c = READCHAR; | |
1645 | if (c >= '0' && c <= '9') | |
1646 | { | |
1647 | i *= 16; | |
1648 | i += c - '0'; | |
1649 | } | |
1650 | else if ((c >= 'a' && c <= 'f') | |
1651 | || (c >= 'A' && c <= 'F')) | |
1652 | { | |
1653 | i *= 16; | |
1654 | if (c >= 'a' && c <= 'f') | |
1655 | i += c - 'a' + 10; | |
1656 | else | |
1657 | i += c - 'A' + 10; | |
1658 | } | |
1659 | else | |
1660 | { | |
1661 | UNREAD (c); | |
1662 | break; | |
1663 | } | |
1664 | } | |
1665 | return i; | |
1666 | } | |
1667 | ||
1668 | default: | |
fe0e03f3 KH |
1669 | if (BASE_LEADING_CODE_P (c)) |
1670 | c = read_multibyte (c, readcharfun); | |
078e7b4a JB |
1671 | return c; |
1672 | } | |
1673 | } | |
1674 | ||
bf5d1a17 GM |
1675 | |
1676 | /* Read an integer in radix RADIX using READCHARFUN to read | |
1677 | characters. RADIX must be in the interval [2..36]; if it isn't, a | |
1678 | read error is signaled . Value is the integer read. Signals an | |
1679 | error if encountering invalid read syntax or if RADIX is out of | |
1680 | range. */ | |
1681 | ||
1682 | static Lisp_Object | |
1683 | read_integer (readcharfun, radix) | |
1684 | Lisp_Object readcharfun; | |
1685 | int radix; | |
1686 | { | |
5e37dc22 GM |
1687 | int ndigits = 0, invalid_p, c, sign = 0; |
1688 | EMACS_INT number = 0; | |
bf5d1a17 GM |
1689 | |
1690 | if (radix < 2 || radix > 36) | |
1691 | invalid_p = 1; | |
1692 | else | |
1693 | { | |
1694 | number = ndigits = invalid_p = 0; | |
1695 | sign = 1; | |
1696 | ||
1697 | c = READCHAR; | |
1698 | if (c == '-') | |
1699 | { | |
1700 | c = READCHAR; | |
1701 | sign = -1; | |
1702 | } | |
1703 | else if (c == '+') | |
1704 | c = READCHAR; | |
1705 | ||
1706 | while (c >= 0) | |
1707 | { | |
1708 | int digit; | |
1709 | ||
1710 | if (c >= '0' && c <= '9') | |
1711 | digit = c - '0'; | |
1712 | else if (c >= 'a' && c <= 'z') | |
1713 | digit = c - 'a' + 10; | |
1714 | else if (c >= 'A' && c <= 'Z') | |
1715 | digit = c - 'A' + 10; | |
1716 | else | |
b632fa48 GM |
1717 | { |
1718 | UNREAD (c); | |
1719 | break; | |
1720 | } | |
bf5d1a17 GM |
1721 | |
1722 | if (digit < 0 || digit >= radix) | |
1723 | invalid_p = 1; | |
1724 | ||
1725 | number = radix * number + digit; | |
1726 | ++ndigits; | |
1727 | c = READCHAR; | |
1728 | } | |
1729 | } | |
1730 | ||
1731 | if (ndigits == 0 || invalid_p) | |
1732 | { | |
1733 | char buf[50]; | |
1734 | sprintf (buf, "integer, radix %d", radix); | |
1735 | Fsignal (Qinvalid_read_syntax, Fcons (build_string (buf), Qnil)); | |
1736 | } | |
1737 | ||
1738 | return make_number (sign * number); | |
1739 | } | |
1740 | ||
1741 | ||
a742d646 GM |
1742 | /* Convert unibyte text in read_buffer to multibyte. |
1743 | ||
1744 | Initially, *P is a pointer after the end of the unibyte text, and | |
1745 | the pointer *END points after the end of read_buffer. | |
1746 | ||
1747 | If read_buffer doesn't have enough room to hold the result | |
1748 | of the conversion, reallocate it and adjust *P and *END. | |
1749 | ||
1750 | At the end, make *P point after the result of the conversion, and | |
1751 | return in *NCHARS the number of characters in the converted | |
1752 | text. */ | |
1753 | ||
1754 | static void | |
1755 | to_multibyte (p, end, nchars) | |
1756 | char **p, **end; | |
1757 | int *nchars; | |
1758 | { | |
1759 | int nbytes; | |
1760 | ||
1761 | parse_str_as_multibyte (read_buffer, *p - read_buffer, &nbytes, nchars); | |
b4a3be43 | 1762 | if (read_buffer_size < 2 * nbytes) |
a742d646 GM |
1763 | { |
1764 | int offset = *p - read_buffer; | |
fe957e65 | 1765 | read_buffer_size = 2 * max (read_buffer_size, nbytes); |
a742d646 GM |
1766 | read_buffer = (char *) xrealloc (read_buffer, read_buffer_size); |
1767 | *p = read_buffer + offset; | |
1768 | *end = read_buffer + read_buffer_size; | |
1769 | } | |
1770 | ||
1771 | if (nbytes != *nchars) | |
1772 | nbytes = str_as_multibyte (read_buffer, read_buffer_size, | |
1773 | *p - read_buffer, nchars); | |
1774 | ||
1775 | *p = read_buffer + nbytes; | |
1776 | } | |
1777 | ||
1778 | ||
6428369f KH |
1779 | /* If the next token is ')' or ']' or '.', we store that character |
1780 | in *PCH and the return value is not interesting. Else, we store | |
17634846 RS |
1781 | zero in *PCH and we read and return one lisp object. |
1782 | ||
1783 | FIRST_IN_LIST is nonzero if this is the first element of a list. */ | |
1784 | ||
078e7b4a | 1785 | static Lisp_Object |
17634846 | 1786 | read1 (readcharfun, pch, first_in_list) |
078e7b4a | 1787 | register Lisp_Object readcharfun; |
e28552a4 | 1788 | int *pch; |
17634846 | 1789 | int first_in_list; |
078e7b4a JB |
1790 | { |
1791 | register int c; | |
4ad679f9 EN |
1792 | int uninterned_symbol = 0; |
1793 | ||
6428369f | 1794 | *pch = 0; |
078e7b4a JB |
1795 | |
1796 | retry: | |
1797 | ||
1798 | c = READCHAR; | |
9c97398c GM |
1799 | if (c < 0) |
1800 | end_of_file_error (); | |
078e7b4a JB |
1801 | |
1802 | switch (c) | |
1803 | { | |
1804 | case '(': | |
1805 | return read_list (0, readcharfun); | |
1806 | ||
1807 | case '[': | |
c15cfd1f | 1808 | return read_vector (readcharfun, 0); |
078e7b4a JB |
1809 | |
1810 | case ')': | |
1811 | case ']': | |
078e7b4a | 1812 | { |
6428369f KH |
1813 | *pch = c; |
1814 | return Qnil; | |
078e7b4a JB |
1815 | } |
1816 | ||
1817 | case '#': | |
200f684e | 1818 | c = READCHAR; |
c2390933 RS |
1819 | if (c == '^') |
1820 | { | |
1821 | c = READCHAR; | |
1822 | if (c == '[') | |
1823 | { | |
1824 | Lisp_Object tmp; | |
c15cfd1f | 1825 | tmp = read_vector (readcharfun, 0); |
c2390933 RS |
1826 | if (XVECTOR (tmp)->size < CHAR_TABLE_STANDARD_SLOTS |
1827 | || XVECTOR (tmp)->size > CHAR_TABLE_STANDARD_SLOTS + 10) | |
1828 | error ("Invalid size char-table"); | |
1829 | XSETCHAR_TABLE (tmp, XCHAR_TABLE (tmp)); | |
3701b5de | 1830 | XCHAR_TABLE (tmp)->top = Qt; |
c2390933 RS |
1831 | return tmp; |
1832 | } | |
3701b5de KH |
1833 | else if (c == '^') |
1834 | { | |
1835 | c = READCHAR; | |
1836 | if (c == '[') | |
1837 | { | |
1838 | Lisp_Object tmp; | |
c15cfd1f | 1839 | tmp = read_vector (readcharfun, 0); |
3701b5de KH |
1840 | if (XVECTOR (tmp)->size != SUB_CHAR_TABLE_STANDARD_SLOTS) |
1841 | error ("Invalid size char-table"); | |
1842 | XSETCHAR_TABLE (tmp, XCHAR_TABLE (tmp)); | |
1843 | XCHAR_TABLE (tmp)->top = Qnil; | |
1844 | return tmp; | |
1845 | } | |
1846 | Fsignal (Qinvalid_read_syntax, | |
1847 | Fcons (make_string ("#^^", 3), Qnil)); | |
1848 | } | |
c2390933 RS |
1849 | Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#^", 2), Qnil)); |
1850 | } | |
1851 | if (c == '&') | |
1852 | { | |
1853 | Lisp_Object length; | |
1854 | length = read1 (readcharfun, pch, first_in_list); | |
1855 | c = READCHAR; | |
1856 | if (c == '"') | |
1857 | { | |
1858 | Lisp_Object tmp, val; | |
90ed3ec5 | 1859 | int size_in_chars = ((XFASTINT (length) + BITS_PER_CHAR - 1) |
68be917d | 1860 | / BITS_PER_CHAR); |
c2390933 RS |
1861 | |
1862 | UNREAD (c); | |
1863 | tmp = read1 (readcharfun, pch, first_in_list); | |
90ed3ec5 RS |
1864 | if (size_in_chars != XSTRING (tmp)->size |
1865 | /* We used to print 1 char too many | |
1866 | when the number of bits was a multiple of 8. | |
1867 | Accept such input in case it came from an old version. */ | |
1868 | && ! (XFASTINT (length) | |
1869 | == (XSTRING (tmp)->size - 1) * BITS_PER_CHAR)) | |
c2390933 | 1870 | Fsignal (Qinvalid_read_syntax, |
ec3bbd7d | 1871 | Fcons (make_string ("#&...", 5), Qnil)); |
c2390933 RS |
1872 | |
1873 | val = Fmake_bool_vector (length, Qnil); | |
1874 | bcopy (XSTRING (tmp)->data, XBOOL_VECTOR (val)->data, | |
1875 | size_in_chars); | |
67d3b149 EZ |
1876 | /* Clear the extraneous bits in the last byte. */ |
1877 | if (XINT (length) != size_in_chars * BITS_PER_CHAR) | |
1878 | XBOOL_VECTOR (val)->data[size_in_chars - 1] | |
1879 | &= (1 << (XINT (length) % BITS_PER_CHAR)) - 1; | |
c2390933 RS |
1880 | return val; |
1881 | } | |
ec3bbd7d | 1882 | Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#&...", 5), |
039dc30b | 1883 | Qnil)); |
c2390933 | 1884 | } |
200f684e RS |
1885 | if (c == '[') |
1886 | { | |
1887 | /* Accept compiled functions at read-time so that we don't have to | |
1888 | build them using function calls. */ | |
748ef62f | 1889 | Lisp_Object tmp; |
c15cfd1f | 1890 | tmp = read_vector (readcharfun, 1); |
748ef62f RS |
1891 | return Fmake_byte_code (XVECTOR (tmp)->size, |
1892 | XVECTOR (tmp)->contents); | |
200f684e | 1893 | } |
748ef62f RS |
1894 | if (c == '(') |
1895 | { | |
1896 | Lisp_Object tmp; | |
1897 | struct gcpro gcpro1; | |
e28552a4 | 1898 | int ch; |
748ef62f RS |
1899 | |
1900 | /* Read the string itself. */ | |
17634846 | 1901 | tmp = read1 (readcharfun, &ch, 0); |
6428369f | 1902 | if (ch != 0 || !STRINGP (tmp)) |
748ef62f RS |
1903 | Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil)); |
1904 | GCPRO1 (tmp); | |
1905 | /* Read the intervals and their properties. */ | |
1906 | while (1) | |
1907 | { | |
1908 | Lisp_Object beg, end, plist; | |
1909 | ||
17634846 | 1910 | beg = read1 (readcharfun, &ch, 0); |
7ee3bd7b | 1911 | end = plist = Qnil; |
6428369f KH |
1912 | if (ch == ')') |
1913 | break; | |
1914 | if (ch == 0) | |
17634846 | 1915 | end = read1 (readcharfun, &ch, 0); |
6428369f | 1916 | if (ch == 0) |
17634846 | 1917 | plist = read1 (readcharfun, &ch, 0); |
6428369f | 1918 | if (ch) |
748ef62f | 1919 | Fsignal (Qinvalid_read_syntax, |
6428369f KH |
1920 | Fcons (build_string ("invalid string property list"), |
1921 | Qnil)); | |
748ef62f RS |
1922 | Fset_text_properties (beg, end, plist, tmp); |
1923 | } | |
1924 | UNGCPRO; | |
1925 | return tmp; | |
1926 | } | |
339ee979 | 1927 | |
20ea2964 RS |
1928 | /* #@NUMBER is used to skip NUMBER following characters. |
1929 | That's used in .elc files to skip over doc strings | |
1930 | and function definitions. */ | |
1931 | if (c == '@') | |
1932 | { | |
1933 | int i, nskip = 0; | |
1934 | ||
1935 | /* Read a decimal integer. */ | |
1936 | while ((c = READCHAR) >= 0 | |
1937 | && c >= '0' && c <= '9') | |
1938 | { | |
1939 | nskip *= 10; | |
1940 | nskip += c - '0'; | |
1941 | } | |
1942 | if (c >= 0) | |
1943 | UNREAD (c); | |
1944 | ||
b2a30870 RS |
1945 | if (load_force_doc_strings && EQ (readcharfun, Qget_file_char)) |
1946 | { | |
1947 | /* If we are supposed to force doc strings into core right now, | |
1948 | record the last string that we skipped, | |
1949 | and record where in the file it comes from. */ | |
c15cfd1f RS |
1950 | |
1951 | /* But first exchange saved_doc_string | |
1952 | with prev_saved_doc_string, so we save two strings. */ | |
1953 | { | |
1954 | char *temp = saved_doc_string; | |
1955 | int temp_size = saved_doc_string_size; | |
68c45bf0 | 1956 | file_offset temp_pos = saved_doc_string_position; |
c15cfd1f RS |
1957 | int temp_len = saved_doc_string_length; |
1958 | ||
1959 | saved_doc_string = prev_saved_doc_string; | |
1960 | saved_doc_string_size = prev_saved_doc_string_size; | |
1961 | saved_doc_string_position = prev_saved_doc_string_position; | |
1962 | saved_doc_string_length = prev_saved_doc_string_length; | |
1963 | ||
1964 | prev_saved_doc_string = temp; | |
1965 | prev_saved_doc_string_size = temp_size; | |
1966 | prev_saved_doc_string_position = temp_pos; | |
1967 | prev_saved_doc_string_length = temp_len; | |
1968 | } | |
1969 | ||
b2a30870 RS |
1970 | if (saved_doc_string_size == 0) |
1971 | { | |
1972 | saved_doc_string_size = nskip + 100; | |
11938f10 | 1973 | saved_doc_string = (char *) xmalloc (saved_doc_string_size); |
b2a30870 RS |
1974 | } |
1975 | if (nskip > saved_doc_string_size) | |
1976 | { | |
1977 | saved_doc_string_size = nskip + 100; | |
11938f10 KH |
1978 | saved_doc_string = (char *) xrealloc (saved_doc_string, |
1979 | saved_doc_string_size); | |
b2a30870 RS |
1980 | } |
1981 | ||
68c45bf0 | 1982 | saved_doc_string_position = file_tell (instream); |
b2a30870 RS |
1983 | |
1984 | /* Copy that many characters into saved_doc_string. */ | |
1985 | for (i = 0; i < nskip && c >= 0; i++) | |
1986 | saved_doc_string[i] = c = READCHAR; | |
1987 | ||
1988 | saved_doc_string_length = i; | |
1989 | } | |
1990 | else | |
b2a30870 RS |
1991 | { |
1992 | /* Skip that many characters. */ | |
1993 | for (i = 0; i < nskip && c >= 0; i++) | |
1994 | c = READCHAR; | |
1995 | } | |
d49f0c1a | 1996 | |
20ea2964 RS |
1997 | goto retry; |
1998 | } | |
1999 | if (c == '$') | |
2000 | return Vload_file_name; | |
2b6cae0c RS |
2001 | if (c == '\'') |
2002 | return Fcons (Qfunction, Fcons (read0 (readcharfun), Qnil)); | |
4ad679f9 EN |
2003 | /* #:foo is the uninterned symbol named foo. */ |
2004 | if (c == ':') | |
2005 | { | |
2006 | uninterned_symbol = 1; | |
2007 | c = READCHAR; | |
2008 | goto default_label; | |
2009 | } | |
2010 | /* Reader forms that can reuse previously read objects. */ | |
2011 | if (c >= '0' && c <= '9') | |
2012 | { | |
2013 | int n = 0; | |
2014 | Lisp_Object tem; | |
2b6cae0c | 2015 | |
4ad679f9 EN |
2016 | /* Read a non-negative integer. */ |
2017 | while (c >= '0' && c <= '9') | |
2018 | { | |
2019 | n *= 10; | |
2020 | n += c - '0'; | |
2021 | c = READCHAR; | |
2022 | } | |
2023 | /* #n=object returns object, but associates it with n for #n#. */ | |
2024 | if (c == '=') | |
2025 | { | |
9e062b6c RS |
2026 | /* Make a placeholder for #n# to use temporarily */ |
2027 | Lisp_Object placeholder; | |
2028 | Lisp_Object cell; | |
2029 | ||
2030 | placeholder = Fcons(Qnil, Qnil); | |
2031 | cell = Fcons (make_number (n), placeholder); | |
2032 | read_objects = Fcons (cell, read_objects); | |
2033 | ||
2034 | /* Read the object itself. */ | |
4ad679f9 | 2035 | tem = read0 (readcharfun); |
9e062b6c RS |
2036 | |
2037 | /* Now put it everywhere the placeholder was... */ | |
2038 | substitute_object_in_subtree (tem, placeholder); | |
2039 | ||
2040 | /* ...and #n# will use the real value from now on. */ | |
2041 | Fsetcdr (cell, tem); | |
2042 | ||
4ad679f9 EN |
2043 | return tem; |
2044 | } | |
2045 | /* #n# returns a previously read object. */ | |
2046 | if (c == '#') | |
2047 | { | |
2048 | tem = Fassq (make_number (n), read_objects); | |
2049 | if (CONSP (tem)) | |
2050 | return XCDR (tem); | |
2051 | /* Fall through to error message. */ | |
2052 | } | |
bf5d1a17 GM |
2053 | else if (c == 'r' || c == 'R') |
2054 | return read_integer (readcharfun, n); | |
2055 | ||
4ad679f9 EN |
2056 | /* Fall through to error message. */ |
2057 | } | |
bf5d1a17 GM |
2058 | else if (c == 'x' || c == 'X') |
2059 | return read_integer (readcharfun, 16); | |
2060 | else if (c == 'o' || c == 'O') | |
2061 | return read_integer (readcharfun, 8); | |
2062 | else if (c == 'b' || c == 'B') | |
2063 | return read_integer (readcharfun, 2); | |
20ea2964 | 2064 | |
200f684e | 2065 | UNREAD (c); |
748ef62f | 2066 | Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil)); |
078e7b4a JB |
2067 | |
2068 | case ';': | |
2069 | while ((c = READCHAR) >= 0 && c != '\n'); | |
2070 | goto retry; | |
2071 | ||
2072 | case '\'': | |
2073 | { | |
2074 | return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil)); | |
2075 | } | |
2076 | ||
17634846 RS |
2077 | case '`': |
2078 | if (first_in_list) | |
2079 | goto default_label; | |
2080 | else | |
2081 | { | |
2082 | Lisp_Object value; | |
2083 | ||
0ffbbdeb | 2084 | new_backquote_flag++; |
17634846 | 2085 | value = read0 (readcharfun); |
0ffbbdeb | 2086 | new_backquote_flag--; |
17634846 RS |
2087 | |
2088 | return Fcons (Qbackquote, Fcons (value, Qnil)); | |
2089 | } | |
2090 | ||
2091 | case ',': | |
2092 | if (new_backquote_flag) | |
2093 | { | |
2094 | Lisp_Object comma_type = Qnil; | |
2095 | Lisp_Object value; | |
2096 | int ch = READCHAR; | |
2097 | ||
2098 | if (ch == '@') | |
2099 | comma_type = Qcomma_at; | |
2100 | else if (ch == '.') | |
2101 | comma_type = Qcomma_dot; | |
2102 | else | |
2103 | { | |
2104 | if (ch >= 0) UNREAD (ch); | |
2105 | comma_type = Qcomma; | |
2106 | } | |
2107 | ||
0ffbbdeb | 2108 | new_backquote_flag--; |
17634846 | 2109 | value = read0 (readcharfun); |
0ffbbdeb | 2110 | new_backquote_flag++; |
17634846 RS |
2111 | return Fcons (comma_type, Fcons (value, Qnil)); |
2112 | } | |
2113 | else | |
2114 | goto default_label; | |
2115 | ||
078e7b4a JB |
2116 | case '?': |
2117 | { | |
078e7b4a | 2118 | c = READCHAR; |
9c97398c GM |
2119 | if (c < 0) |
2120 | end_of_file_error (); | |
078e7b4a JB |
2121 | |
2122 | if (c == '\\') | |
e7fc914b | 2123 | c = read_escape (readcharfun, 0); |
fe0e03f3 KH |
2124 | else if (BASE_LEADING_CODE_P (c)) |
2125 | c = read_multibyte (c, readcharfun); | |
078e7b4a | 2126 | |
6f7f43d5 | 2127 | return make_number (c); |
078e7b4a JB |
2128 | } |
2129 | ||
00a9a935 | 2130 | case '"': |
078e7b4a | 2131 | { |
a742d646 GM |
2132 | char *p = read_buffer; |
2133 | char *end = read_buffer + read_buffer_size; | |
078e7b4a | 2134 | register int c; |
e7fc914b KH |
2135 | /* Nonzero if we saw an escape sequence specifying |
2136 | a multibyte character. */ | |
2137 | int force_multibyte = 0; | |
2138 | /* Nonzero if we saw an escape sequence specifying | |
2139 | a single-byte character. */ | |
2140 | int force_singlebyte = 0; | |
078e7b4a | 2141 | int cancel = 0; |
e7fc914b | 2142 | int nchars; |
078e7b4a JB |
2143 | |
2144 | while ((c = READCHAR) >= 0 | |
2145 | && c != '\"') | |
2146 | { | |
449fea39 | 2147 | if (end - p < MAX_MULTIBYTE_LENGTH) |
078e7b4a | 2148 | { |
5d65df0d GM |
2149 | int offset = p - read_buffer; |
2150 | read_buffer = (char *) xrealloc (read_buffer, | |
2151 | read_buffer_size *= 2); | |
2152 | p = read_buffer + offset; | |
078e7b4a JB |
2153 | end = read_buffer + read_buffer_size; |
2154 | } | |
bed23cb2 | 2155 | |
078e7b4a | 2156 | if (c == '\\') |
03e88613 | 2157 | { |
e7fc914b | 2158 | c = read_escape (readcharfun, 1); |
bed23cb2 RS |
2159 | |
2160 | /* C is -1 if \ newline has just been seen */ | |
2161 | if (c == -1) | |
03e88613 | 2162 | { |
bed23cb2 RS |
2163 | if (p == read_buffer) |
2164 | cancel = 1; | |
03e88613 RS |
2165 | continue; |
2166 | } | |
bed23cb2 | 2167 | |
94e554db RS |
2168 | /* If an escape specifies a non-ASCII single-byte character, |
2169 | this must be a unibyte string. */ | |
164d590d KH |
2170 | if (SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)) |
2171 | && ! ASCII_BYTE_P ((c & ~CHAR_MODIFIER_MASK))) | |
e7fc914b | 2172 | force_singlebyte = 1; |
03e88613 | 2173 | } |
6f7f43d5 | 2174 | |
164d590d | 2175 | if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))) |
078e7b4a | 2176 | { |
164d590d KH |
2177 | /* Any modifiers for a multibyte character are invalid. */ |
2178 | if (c & CHAR_MODIFIER_MASK) | |
2179 | error ("Invalid modifier in string"); | |
449fea39 KH |
2180 | p += CHAR_STRING (c, p); |
2181 | force_multibyte = 1; | |
078e7b4a JB |
2182 | } |
2183 | else | |
f943104a | 2184 | { |
988c2f83 RS |
2185 | /* Allow `\C- ' and `\C-?'. */ |
2186 | if (c == (CHAR_CTL | ' ')) | |
2187 | c = 0; | |
2188 | else if (c == (CHAR_CTL | '?')) | |
2189 | c = 127; | |
2190 | ||
164d590d KH |
2191 | if (c & CHAR_SHIFT) |
2192 | { | |
2193 | /* Shift modifier is valid only with [A-Za-z]. */ | |
2194 | if ((c & 0377) >= 'A' && (c & 0377) <= 'Z') | |
2195 | c &= ~CHAR_SHIFT; | |
2196 | else if ((c & 0377) >= 'a' && (c & 0377) <= 'z') | |
2197 | c = (c & ~CHAR_SHIFT) - ('a' - 'A'); | |
2198 | } | |
2199 | ||
f943104a KH |
2200 | if (c & CHAR_META) |
2201 | /* Move the meta bit to the right place for a string. */ | |
2202 | c = (c & ~CHAR_META) | 0x80; | |
2203 | if (c & ~0xff) | |
2204 | error ("Invalid modifier in string"); | |
2205 | *p++ = c; | |
2206 | } | |
078e7b4a | 2207 | } |
6f7f43d5 | 2208 | if (c < 0) |
9c97398c | 2209 | end_of_file_error (); |
078e7b4a JB |
2210 | |
2211 | /* If purifying, and string starts with \ newline, | |
2212 | return zero instead. This is for doc strings | |
08564963 | 2213 | that we are really going to find in etc/DOC.nn.nn */ |
265a9e55 | 2214 | if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel) |
078e7b4a JB |
2215 | return make_number (0); |
2216 | ||
6f46329a | 2217 | if (force_multibyte) |
a742d646 | 2218 | to_multibyte (&p, &end, &nchars); |
6f46329a RS |
2219 | else if (force_singlebyte) |
2220 | nchars = p - read_buffer; | |
94e554db RS |
2221 | else if (load_convert_to_unibyte) |
2222 | { | |
2223 | Lisp_Object string; | |
a742d646 | 2224 | to_multibyte (&p, &end, &nchars); |
94e554db RS |
2225 | if (p - read_buffer != nchars) |
2226 | { | |
2227 | string = make_multibyte_string (read_buffer, nchars, | |
2228 | p - read_buffer); | |
2229 | return Fstring_make_unibyte (string); | |
2230 | } | |
2231 | } | |
8db9dc66 RS |
2232 | else if (EQ (readcharfun, Qget_file_char) |
2233 | || EQ (readcharfun, Qlambda)) | |
a742d646 GM |
2234 | { |
2235 | /* Nowadays, reading directly from a file is used only for | |
2236 | compiled Emacs Lisp files, and those always use the | |
2237 | Emacs internal encoding. Meanwhile, Qlambda is used | |
2238 | for reading dynamic byte code (compiled with | |
2239 | byte-compile-dynamic = t). */ | |
2240 | to_multibyte (&p, &end, &nchars); | |
2241 | } | |
e28552a4 | 2242 | else |
bed23cb2 RS |
2243 | /* In all other cases, if we read these bytes as |
2244 | separate characters, treat them as separate characters now. */ | |
e7fc914b KH |
2245 | nchars = p - read_buffer; |
2246 | ||
2247 | if (read_pure) | |
491f16a2 RS |
2248 | return make_pure_string (read_buffer, nchars, p - read_buffer, |
2249 | (force_multibyte | |
2250 | || (p - read_buffer != nchars))); | |
2251 | return make_specified_string (read_buffer, nchars, p - read_buffer, | |
2252 | (force_multibyte | |
2253 | || (p - read_buffer != nchars))); | |
078e7b4a JB |
2254 | } |
2255 | ||
109d300c JB |
2256 | case '.': |
2257 | { | |
109d300c JB |
2258 | int next_char = READCHAR; |
2259 | UNREAD (next_char); | |
2260 | ||
035eec48 GM |
2261 | if (next_char <= 040 |
2262 | || index ("\"'`,(", next_char)) | |
109d300c | 2263 | { |
6428369f KH |
2264 | *pch = c; |
2265 | return Qnil; | |
109d300c JB |
2266 | } |
2267 | ||
2268 | /* Otherwise, we fall through! Note that the atom-reading loop | |
2269 | below will now loop at least once, assuring that we will not | |
2270 | try to UNREAD two characters in a row. */ | |
2271 | } | |
078e7b4a | 2272 | default: |
17634846 | 2273 | default_label: |
078e7b4a JB |
2274 | if (c <= 040) goto retry; |
2275 | { | |
38404229 | 2276 | char *p = read_buffer; |
481c6336 | 2277 | int quoted = 0; |
078e7b4a JB |
2278 | |
2279 | { | |
38404229 | 2280 | char *end = read_buffer + read_buffer_size; |
078e7b4a | 2281 | |
6f7f43d5 | 2282 | while (c > 040 |
38404229 | 2283 | && !(c == '\"' || c == '\'' || c == ';' |
6f7f43d5 | 2284 | || c == '(' || c == ')' |
38404229 | 2285 | || c == '[' || c == ']' || c == '#')) |
078e7b4a | 2286 | { |
449fea39 | 2287 | if (end - p < MAX_MULTIBYTE_LENGTH) |
078e7b4a | 2288 | { |
5d65df0d GM |
2289 | int offset = p - read_buffer; |
2290 | read_buffer = (char *) xrealloc (read_buffer, | |
2291 | read_buffer_size *= 2); | |
2292 | p = read_buffer + offset; | |
078e7b4a JB |
2293 | end = read_buffer + read_buffer_size; |
2294 | } | |
38404229 | 2295 | |
078e7b4a | 2296 | if (c == '\\') |
481c6336 RS |
2297 | { |
2298 | c = READCHAR; | |
4ab11c09 GM |
2299 | if (c == -1) |
2300 | end_of_file_error (); | |
481c6336 RS |
2301 | quoted = 1; |
2302 | } | |
6f7f43d5 | 2303 | |
bed23cb2 | 2304 | if (! SINGLE_BYTE_CHAR_P (c)) |
449fea39 | 2305 | p += CHAR_STRING (c, p); |
bed23cb2 RS |
2306 | else |
2307 | *p++ = c; | |
6f7f43d5 | 2308 | |
078e7b4a JB |
2309 | c = READCHAR; |
2310 | } | |
2311 | ||
2312 | if (p == end) | |
2313 | { | |
5d65df0d GM |
2314 | int offset = p - read_buffer; |
2315 | read_buffer = (char *) xrealloc (read_buffer, | |
2316 | read_buffer_size *= 2); | |
2317 | p = read_buffer + offset; | |
2318 | end = read_buffer + read_buffer_size; | |
078e7b4a JB |
2319 | } |
2320 | *p = 0; | |
2321 | if (c >= 0) | |
2322 | UNREAD (c); | |
2323 | } | |
2324 | ||
4ad679f9 | 2325 | if (!quoted && !uninterned_symbol) |
481c6336 RS |
2326 | { |
2327 | register char *p1; | |
2328 | register Lisp_Object val; | |
2329 | p1 = read_buffer; | |
2330 | if (*p1 == '+' || *p1 == '-') p1++; | |
2331 | /* Is it an integer? */ | |
2332 | if (p1 != p) | |
2333 | { | |
2334 | while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++; | |
481c6336 RS |
2335 | /* Integers can have trailing decimal points. */ |
2336 | if (p1 > read_buffer && p1 < p && *p1 == '.') p1++; | |
481c6336 RS |
2337 | if (p1 == p) |
2338 | /* It is an integer. */ | |
2339 | { | |
481c6336 RS |
2340 | if (p1[-1] == '.') |
2341 | p1[-1] = '\0'; | |
faca07fb RS |
2342 | if (sizeof (int) == sizeof (EMACS_INT)) |
2343 | XSETINT (val, atoi (read_buffer)); | |
2344 | else if (sizeof (long) == sizeof (EMACS_INT)) | |
2345 | XSETINT (val, atol (read_buffer)); | |
2346 | else | |
2347 | abort (); | |
481c6336 RS |
2348 | return val; |
2349 | } | |
2350 | } | |
481c6336 | 2351 | if (isfloat_string (read_buffer)) |
eb659c41 | 2352 | { |
a8972052 PE |
2353 | /* Compute NaN and infinities using 0.0 in a variable, |
2354 | to cope with compilers that think they are smarter | |
5e24a1f7 | 2355 | than we are. */ |
3c329963 | 2356 | double zero = 0.0; |
a8972052 PE |
2357 | |
2358 | double value; | |
2359 | ||
2360 | /* Negate the value ourselves. This treats 0, NaNs, | |
2361 | and infinity properly on IEEE floating point hosts, | |
2362 | and works around a common bug where atof ("-0.0") | |
2363 | drops the sign. */ | |
2364 | int negative = read_buffer[0] == '-'; | |
2365 | ||
2366 | /* The only way p[-1] can be 'F' or 'N', after isfloat_string | |
eb659c41 | 2367 | returns 1, is if the input ends in e+INF or e+NaN. */ |
a8972052 | 2368 | switch (p[-1]) |
eb659c41 | 2369 | { |
a8972052 PE |
2370 | case 'F': |
2371 | value = 1.0 / zero; | |
2372 | break; | |
2373 | case 'N': | |
2374 | value = zero / zero; | |
2375 | break; | |
2376 | default: | |
2377 | value = atof (read_buffer + negative); | |
2378 | break; | |
eb659c41 | 2379 | } |
a8972052 PE |
2380 | |
2381 | return make_float (negative ? - value : value); | |
eb659c41 | 2382 | } |
481c6336 | 2383 | } |
078e7b4a | 2384 | |
4ad679f9 EN |
2385 | if (uninterned_symbol) |
2386 | return make_symbol (read_buffer); | |
2387 | else | |
2388 | return intern (read_buffer); | |
078e7b4a JB |
2389 | } |
2390 | } | |
2391 | } | |
2392 | \f | |
9e062b6c RS |
2393 | |
2394 | /* List of nodes we've seen during substitute_object_in_subtree. */ | |
2395 | static Lisp_Object seen_list; | |
2396 | ||
2397 | static void | |
2398 | substitute_object_in_subtree (object, placeholder) | |
2399 | Lisp_Object object; | |
2400 | Lisp_Object placeholder; | |
2401 | { | |
2402 | Lisp_Object check_object; | |
2403 | ||
2404 | /* We haven't seen any objects when we start. */ | |
2405 | seen_list = Qnil; | |
2406 | ||
2407 | /* Make all the substitutions. */ | |
2408 | check_object | |
2409 | = substitute_object_recurse (object, placeholder, object); | |
2410 | ||
2411 | /* Clear seen_list because we're done with it. */ | |
2412 | seen_list = Qnil; | |
2413 | ||
2414 | /* The returned object here is expected to always eq the | |
2415 | original. */ | |
2416 | if (!EQ (check_object, object)) | |
2417 | error ("Unexpected mutation error in reader"); | |
2418 | } | |
2419 | ||
2420 | /* Feval doesn't get called from here, so no gc protection is needed. */ | |
2421 | #define SUBSTITUTE(get_val, set_val) \ | |
2422 | { \ | |
2423 | Lisp_Object old_value = get_val; \ | |
2424 | Lisp_Object true_value \ | |
2425 | = substitute_object_recurse (object, placeholder,\ | |
2426 | old_value); \ | |
2427 | \ | |
2428 | if (!EQ (old_value, true_value)) \ | |
2429 | { \ | |
2430 | set_val; \ | |
2431 | } \ | |
2432 | } | |
2433 | ||
2434 | static Lisp_Object | |
2435 | substitute_object_recurse (object, placeholder, subtree) | |
2436 | Lisp_Object object; | |
2437 | Lisp_Object placeholder; | |
2438 | Lisp_Object subtree; | |
2439 | { | |
2440 | /* If we find the placeholder, return the target object. */ | |
2441 | if (EQ (placeholder, subtree)) | |
2442 | return object; | |
2443 | ||
2444 | /* If we've been to this node before, don't explore it again. */ | |
2445 | if (!EQ (Qnil, Fmemq (subtree, seen_list))) | |
2446 | return subtree; | |
2447 | ||
2448 | /* If this node can be the entry point to a cycle, remember that | |
2449 | we've seen it. It can only be such an entry point if it was made | |
2450 | by #n=, which means that we can find it as a value in | |
2451 | read_objects. */ | |
2452 | if (!EQ (Qnil, Frassq (subtree, read_objects))) | |
2453 | seen_list = Fcons (subtree, seen_list); | |
2454 | ||
2455 | /* Recurse according to subtree's type. | |
2456 | Every branch must return a Lisp_Object. */ | |
2457 | switch (XTYPE (subtree)) | |
2458 | { | |
2459 | case Lisp_Vectorlike: | |
2460 | { | |
2461 | int i; | |
7c752c80 | 2462 | int length = XINT (Flength(subtree)); |
9e062b6c RS |
2463 | for (i = 0; i < length; i++) |
2464 | { | |
2465 | Lisp_Object idx = make_number (i); | |
2466 | SUBSTITUTE (Faref (subtree, idx), | |
2467 | Faset (subtree, idx, true_value)); | |
2468 | } | |
2469 | return subtree; | |
2470 | } | |
2471 | ||
2472 | case Lisp_Cons: | |
2473 | { | |
2474 | SUBSTITUTE (Fcar_safe (subtree), | |
e61b9b87 | 2475 | Fsetcar (subtree, true_value)); |
9e062b6c | 2476 | SUBSTITUTE (Fcdr_safe (subtree), |
e61b9b87 | 2477 | Fsetcdr (subtree, true_value)); |
9e062b6c RS |
2478 | return subtree; |
2479 | } | |
2480 | ||
9e062b6c RS |
2481 | case Lisp_String: |
2482 | { | |
2483 | /* Check for text properties in each interval. | |
e61b9b87 | 2484 | substitute_in_interval contains part of the logic. */ |
9e062b6c RS |
2485 | |
2486 | INTERVAL root_interval = XSTRING (subtree)->intervals; | |
2487 | Lisp_Object arg = Fcons (object, placeholder); | |
2488 | ||
0d74b006 SM |
2489 | traverse_intervals_noorder (root_interval, |
2490 | &substitute_in_interval, arg); | |
9e062b6c RS |
2491 | |
2492 | return subtree; | |
2493 | } | |
9e062b6c RS |
2494 | |
2495 | /* Other types don't recurse any further. */ | |
2496 | default: | |
2497 | return subtree; | |
2498 | } | |
2499 | } | |
2500 | ||
2501 | /* Helper function for substitute_object_recurse. */ | |
2502 | static void | |
2503 | substitute_in_interval (interval, arg) | |
2504 | INTERVAL interval; | |
2505 | Lisp_Object arg; | |
2506 | { | |
2507 | Lisp_Object object = Fcar (arg); | |
2508 | Lisp_Object placeholder = Fcdr (arg); | |
2509 | ||
2510 | SUBSTITUTE(interval->plist, interval->plist = true_value); | |
2511 | } | |
2512 | ||
2513 | \f | |
078e7b4a JB |
2514 | #define LEAD_INT 1 |
2515 | #define DOT_CHAR 2 | |
2516 | #define TRAIL_INT 4 | |
2517 | #define E_CHAR 8 | |
2518 | #define EXP_INT 16 | |
2519 | ||
2520 | int | |
2521 | isfloat_string (cp) | |
2522 | register char *cp; | |
2523 | { | |
c1a2f60a | 2524 | register int state; |
078e7b4a | 2525 | |
d8578e58 RS |
2526 | char *start = cp; |
2527 | ||
078e7b4a JB |
2528 | state = 0; |
2529 | if (*cp == '+' || *cp == '-') | |
2530 | cp++; | |
2531 | ||
075027b1 | 2532 | if (*cp >= '0' && *cp <= '9') |
078e7b4a JB |
2533 | { |
2534 | state |= LEAD_INT; | |
075027b1 RS |
2535 | while (*cp >= '0' && *cp <= '9') |
2536 | cp++; | |
078e7b4a JB |
2537 | } |
2538 | if (*cp == '.') | |
2539 | { | |
2540 | state |= DOT_CHAR; | |
2541 | cp++; | |
2542 | } | |
075027b1 | 2543 | if (*cp >= '0' && *cp <= '9') |
078e7b4a JB |
2544 | { |
2545 | state |= TRAIL_INT; | |
075027b1 | 2546 | while (*cp >= '0' && *cp <= '9') |
078e7b4a JB |
2547 | cp++; |
2548 | } | |
a35f88bf | 2549 | if (*cp == 'e' || *cp == 'E') |
078e7b4a JB |
2550 | { |
2551 | state |= E_CHAR; | |
2552 | cp++; | |
e73997a1 RS |
2553 | if (*cp == '+' || *cp == '-') |
2554 | cp++; | |
078e7b4a | 2555 | } |
078e7b4a | 2556 | |
075027b1 | 2557 | if (*cp >= '0' && *cp <= '9') |
078e7b4a JB |
2558 | { |
2559 | state |= EXP_INT; | |
075027b1 | 2560 | while (*cp >= '0' && *cp <= '9') |
078e7b4a JB |
2561 | cp++; |
2562 | } | |
d8578e58 RS |
2563 | else if (cp == start) |
2564 | ; | |
eb659c41 RS |
2565 | else if (cp[-1] == '+' && cp[0] == 'I' && cp[1] == 'N' && cp[2] == 'F') |
2566 | { | |
2567 | state |= EXP_INT; | |
2568 | cp += 3; | |
2569 | } | |
2570 | else if (cp[-1] == '+' && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N') | |
2571 | { | |
2572 | state |= EXP_INT; | |
2573 | cp += 3; | |
2574 | } | |
2575 | ||
37579d7c | 2576 | return (((*cp == 0) || (*cp == ' ') || (*cp == '\t') || (*cp == '\n') || (*cp == '\r') || (*cp == '\f')) |
078e7b4a | 2577 | && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT) |
151bdc83 | 2578 | || state == (DOT_CHAR|TRAIL_INT) |
078e7b4a | 2579 | || state == (LEAD_INT|E_CHAR|EXP_INT) |
151bdc83 JB |
2580 | || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT) |
2581 | || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT))); | |
078e7b4a | 2582 | } |
cc94f3b2 | 2583 | |
078e7b4a JB |
2584 | \f |
2585 | static Lisp_Object | |
c15cfd1f | 2586 | read_vector (readcharfun, bytecodeflag) |
078e7b4a | 2587 | Lisp_Object readcharfun; |
c15cfd1f | 2588 | int bytecodeflag; |
078e7b4a JB |
2589 | { |
2590 | register int i; | |
2591 | register int size; | |
2592 | register Lisp_Object *ptr; | |
c15cfd1f | 2593 | register Lisp_Object tem, item, vector; |
078e7b4a JB |
2594 | register struct Lisp_Cons *otem; |
2595 | Lisp_Object len; | |
2596 | ||
2597 | tem = read_list (1, readcharfun); | |
2598 | len = Flength (tem); | |
2599 | vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil)); | |
2600 | ||
078e7b4a JB |
2601 | size = XVECTOR (vector)->size; |
2602 | ptr = XVECTOR (vector)->contents; | |
2603 | for (i = 0; i < size; i++) | |
2604 | { | |
c15cfd1f RS |
2605 | item = Fcar (tem); |
2606 | /* If `load-force-doc-strings' is t when reading a lazily-loaded | |
2607 | bytecode object, the docstring containing the bytecode and | |
2608 | constants values must be treated as unibyte and passed to | |
2609 | Fread, to get the actual bytecode string and constants vector. */ | |
2610 | if (bytecodeflag && load_force_doc_strings) | |
2611 | { | |
2612 | if (i == COMPILED_BYTECODE) | |
2613 | { | |
2614 | if (!STRINGP (item)) | |
2615 | error ("invalid byte code"); | |
2616 | ||
2617 | /* Delay handling the bytecode slot until we know whether | |
2618 | it is lazily-loaded (we can tell by whether the | |
2619 | constants slot is nil). */ | |
2620 | ptr[COMPILED_CONSTANTS] = item; | |
2621 | item = Qnil; | |
2622 | } | |
2623 | else if (i == COMPILED_CONSTANTS) | |
2624 | { | |
2625 | Lisp_Object bytestr = ptr[COMPILED_CONSTANTS]; | |
2626 | ||
2627 | if (NILP (item)) | |
2628 | { | |
2629 | /* Coerce string to unibyte (like string-as-unibyte, | |
2630 | but without generating extra garbage and | |
2631 | guaranteeing no change in the contents). */ | |
2632 | XSTRING (bytestr)->size = STRING_BYTES (XSTRING (bytestr)); | |
2633 | SET_STRING_BYTES (XSTRING (bytestr), -1); | |
2634 | ||
2635 | item = Fread (bytestr); | |
2636 | if (!CONSP (item)) | |
2637 | error ("invalid byte code"); | |
2638 | ||
2639 | otem = XCONS (item); | |
c1d497be KR |
2640 | bytestr = XCAR (item); |
2641 | item = XCDR (item); | |
c15cfd1f RS |
2642 | free_cons (otem); |
2643 | } | |
2644 | ||
2645 | /* Now handle the bytecode slot. */ | |
2646 | ptr[COMPILED_BYTECODE] = read_pure ? Fpurecopy (bytestr) : bytestr; | |
2647 | } | |
2648 | } | |
2649 | ptr[i] = read_pure ? Fpurecopy (item) : item; | |
078e7b4a JB |
2650 | otem = XCONS (tem); |
2651 | tem = Fcdr (tem); | |
2652 | free_cons (otem); | |
2653 | } | |
2654 | return vector; | |
2655 | } | |
2656 | ||
6f7f43d5 RS |
2657 | /* FLAG = 1 means check for ] to terminate rather than ) and . |
2658 | FLAG = -1 means check for starting with defun | |
078e7b4a JB |
2659 | and make structure pure. */ |
2660 | ||
2661 | static Lisp_Object | |
2662 | read_list (flag, readcharfun) | |
2663 | int flag; | |
2664 | register Lisp_Object readcharfun; | |
2665 | { | |
2666 | /* -1 means check next element for defun, | |
2667 | 0 means don't check, | |
2668 | 1 means already checked and found defun. */ | |
2669 | int defunflag = flag < 0 ? -1 : 0; | |
2670 | Lisp_Object val, tail; | |
2671 | register Lisp_Object elt, tem; | |
2672 | struct gcpro gcpro1, gcpro2; | |
821d417e | 2673 | /* 0 is the normal case. |
b2a30870 RS |
2674 | 1 means this list is a doc reference; replace it with the number 0. |
2675 | 2 means this list is a doc reference; replace it with the doc string. */ | |
821d417e | 2676 | int doc_reference = 0; |
078e7b4a | 2677 | |
17634846 RS |
2678 | /* Initialize this to 1 if we are reading a list. */ |
2679 | int first_in_list = flag <= 0; | |
2680 | ||
078e7b4a JB |
2681 | val = Qnil; |
2682 | tail = Qnil; | |
2683 | ||
2684 | while (1) | |
2685 | { | |
e28552a4 | 2686 | int ch; |
078e7b4a | 2687 | GCPRO2 (val, tail); |
17634846 | 2688 | elt = read1 (readcharfun, &ch, first_in_list); |
078e7b4a | 2689 | UNGCPRO; |
20ea2964 | 2690 | |
17634846 RS |
2691 | first_in_list = 0; |
2692 | ||
821d417e | 2693 | /* While building, if the list starts with #$, treat it specially. */ |
20ea2964 | 2694 | if (EQ (elt, Vload_file_name) |
d49f0c1a | 2695 | && ! NILP (elt) |
821d417e RS |
2696 | && !NILP (Vpurify_flag)) |
2697 | { | |
2698 | if (NILP (Vdoc_file_name)) | |
2699 | /* We have not yet called Snarf-documentation, so assume | |
2700 | this file is described in the DOC-MM.NN file | |
2701 | and Snarf-documentation will fill in the right value later. | |
2702 | For now, replace the whole list with 0. */ | |
2703 | doc_reference = 1; | |
2704 | else | |
2705 | /* We have already called Snarf-documentation, so make a relative | |
2706 | file name for this file, so it can be found properly | |
2707 | in the installed Lisp directory. | |
2708 | We don't use Fexpand_file_name because that would make | |
2709 | the directory absolute now. */ | |
2710 | elt = concat2 (build_string ("../lisp/"), | |
2711 | Ffile_name_nondirectory (elt)); | |
2712 | } | |
b2a30870 | 2713 | else if (EQ (elt, Vload_file_name) |
d49f0c1a | 2714 | && ! NILP (elt) |
b2a30870 RS |
2715 | && load_force_doc_strings) |
2716 | doc_reference = 2; | |
20ea2964 | 2717 | |
6428369f | 2718 | if (ch) |
078e7b4a JB |
2719 | { |
2720 | if (flag > 0) | |
2721 | { | |
6428369f | 2722 | if (ch == ']') |
078e7b4a | 2723 | return val; |
821d417e RS |
2724 | Fsignal (Qinvalid_read_syntax, |
2725 | Fcons (make_string (") or . in a vector", 18), Qnil)); | |
078e7b4a | 2726 | } |
6428369f | 2727 | if (ch == ')') |
078e7b4a | 2728 | return val; |
6428369f | 2729 | if (ch == '.') |
078e7b4a JB |
2730 | { |
2731 | GCPRO2 (val, tail); | |
265a9e55 | 2732 | if (!NILP (tail)) |
f5df591a | 2733 | XSETCDR (tail, read0 (readcharfun)); |
078e7b4a JB |
2734 | else |
2735 | val = read0 (readcharfun); | |
17634846 | 2736 | read1 (readcharfun, &ch, 0); |
078e7b4a | 2737 | UNGCPRO; |
6428369f | 2738 | if (ch == ')') |
821d417e RS |
2739 | { |
2740 | if (doc_reference == 1) | |
2741 | return make_number (0); | |
b2a30870 RS |
2742 | if (doc_reference == 2) |
2743 | { | |
2744 | /* Get a doc string from the file we are loading. | |
2745 | If it's in saved_doc_string, get it from there. */ | |
c1d497be | 2746 | int pos = XINT (XCDR (val)); |
c15cfd1f RS |
2747 | /* Position is negative for user variables. */ |
2748 | if (pos < 0) pos = -pos; | |
b2a30870 RS |
2749 | if (pos >= saved_doc_string_position |
2750 | && pos < (saved_doc_string_position | |
2751 | + saved_doc_string_length)) | |
2752 | { | |
2753 | int start = pos - saved_doc_string_position; | |
2754 | int from, to; | |
2755 | ||
2756 | /* Process quoting with ^A, | |
2757 | and find the end of the string, | |
2758 | which is marked with ^_ (037). */ | |
2759 | for (from = start, to = start; | |
2760 | saved_doc_string[from] != 037;) | |
2761 | { | |
2762 | int c = saved_doc_string[from++]; | |
2763 | if (c == 1) | |
2764 | { | |
2765 | c = saved_doc_string[from++]; | |
2766 | if (c == 1) | |
2767 | saved_doc_string[to++] = c; | |
2768 | else if (c == '0') | |
2769 | saved_doc_string[to++] = 0; | |
2770 | else if (c == '_') | |
2771 | saved_doc_string[to++] = 037; | |
2772 | } | |
2773 | else | |
2774 | saved_doc_string[to++] = c; | |
2775 | } | |
2776 | ||
2777 | return make_string (saved_doc_string + start, | |
2778 | to - start); | |
2779 | } | |
c15cfd1f RS |
2780 | /* Look in prev_saved_doc_string the same way. */ |
2781 | else if (pos >= prev_saved_doc_string_position | |
2782 | && pos < (prev_saved_doc_string_position | |
2783 | + prev_saved_doc_string_length)) | |
2784 | { | |
2785 | int start = pos - prev_saved_doc_string_position; | |
2786 | int from, to; | |
2787 | ||
2788 | /* Process quoting with ^A, | |
2789 | and find the end of the string, | |
2790 | which is marked with ^_ (037). */ | |
2791 | for (from = start, to = start; | |
2792 | prev_saved_doc_string[from] != 037;) | |
2793 | { | |
2794 | int c = prev_saved_doc_string[from++]; | |
2795 | if (c == 1) | |
2796 | { | |
2797 | c = prev_saved_doc_string[from++]; | |
2798 | if (c == 1) | |
2799 | prev_saved_doc_string[to++] = c; | |
2800 | else if (c == '0') | |
2801 | prev_saved_doc_string[to++] = 0; | |
2802 | else if (c == '_') | |
2803 | prev_saved_doc_string[to++] = 037; | |
2804 | } | |
2805 | else | |
2806 | prev_saved_doc_string[to++] = c; | |
2807 | } | |
2808 | ||
2809 | return make_string (prev_saved_doc_string + start, | |
2810 | to - start); | |
2811 | } | |
b2a30870 | 2812 | else |
6fe9cce5 | 2813 | return get_doc_string (val, 0, 0); |
b2a30870 RS |
2814 | } |
2815 | ||
821d417e RS |
2816 | return val; |
2817 | } | |
078e7b4a JB |
2818 | return Fsignal (Qinvalid_read_syntax, Fcons (make_string (". in wrong context", 18), Qnil)); |
2819 | } | |
2820 | return Fsignal (Qinvalid_read_syntax, Fcons (make_string ("] in a list", 11), Qnil)); | |
2821 | } | |
2822 | tem = (read_pure && flag <= 0 | |
2823 | ? pure_cons (elt, Qnil) | |
2824 | : Fcons (elt, Qnil)); | |
265a9e55 | 2825 | if (!NILP (tail)) |
f5df591a | 2826 | XSETCDR (tail, tem); |
078e7b4a JB |
2827 | else |
2828 | val = tem; | |
2829 | tail = tem; | |
2830 | if (defunflag < 0) | |
2831 | defunflag = EQ (elt, Qdefun); | |
2832 | else if (defunflag > 0) | |
2833 | read_pure = 1; | |
2834 | } | |
2835 | } | |
2836 | \f | |
2837 | Lisp_Object Vobarray; | |
2838 | Lisp_Object initial_obarray; | |
2839 | ||
d007f5c8 RS |
2840 | /* oblookup stores the bucket number here, for the sake of Funintern. */ |
2841 | ||
2842 | int oblookup_last_bucket_number; | |
2843 | ||
2844 | static int hash_string (); | |
2845 | Lisp_Object oblookup (); | |
2846 | ||
2847 | /* Get an error if OBARRAY is not an obarray. | |
2848 | If it is one, return it. */ | |
2849 | ||
078e7b4a JB |
2850 | Lisp_Object |
2851 | check_obarray (obarray) | |
2852 | Lisp_Object obarray; | |
2853 | { | |
cfff016d | 2854 | while (!VECTORP (obarray) || XVECTOR (obarray)->size == 0) |
078e7b4a JB |
2855 | { |
2856 | /* If Vobarray is now invalid, force it to be valid. */ | |
2857 | if (EQ (Vobarray, obarray)) Vobarray = initial_obarray; | |
2858 | ||
2859 | obarray = wrong_type_argument (Qvectorp, obarray); | |
2860 | } | |
2861 | return obarray; | |
2862 | } | |
2863 | ||
d007f5c8 RS |
2864 | /* Intern the C string STR: return a symbol with that name, |
2865 | interned in the current obarray. */ | |
078e7b4a JB |
2866 | |
2867 | Lisp_Object | |
2868 | intern (str) | |
2869 | char *str; | |
2870 | { | |
2871 | Lisp_Object tem; | |
2872 | int len = strlen (str); | |
153a17b7 | 2873 | Lisp_Object obarray; |
078e7b4a | 2874 | |
153a17b7 | 2875 | obarray = Vobarray; |
cfff016d | 2876 | if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0) |
078e7b4a | 2877 | obarray = check_obarray (obarray); |
e28552a4 | 2878 | tem = oblookup (obarray, str, len, len); |
cfff016d | 2879 | if (SYMBOLP (tem)) |
078e7b4a | 2880 | return tem; |
87631ef7 | 2881 | return Fintern (make_string (str, len), obarray); |
078e7b4a | 2882 | } |
4ad679f9 EN |
2883 | |
2884 | /* Create an uninterned symbol with name STR. */ | |
2885 | ||
2886 | Lisp_Object | |
2887 | make_symbol (str) | |
2888 | char *str; | |
2889 | { | |
2890 | int len = strlen (str); | |
2891 | ||
2892 | return Fmake_symbol ((!NILP (Vpurify_flag) | |
491f16a2 | 2893 | ? make_pure_string (str, len, len, 0) |
4ad679f9 EN |
2894 | : make_string (str, len))); |
2895 | } | |
d007f5c8 | 2896 | \f |
078e7b4a | 2897 | DEFUN ("intern", Fintern, Sintern, 1, 2, 0, |
5de38842 PJ |
2898 | doc: /* Return the canonical symbol whose name is STRING. |
2899 | If there is none, one is created by this function and returned. | |
2900 | A second optional argument specifies the obarray to use; | |
2901 | it defaults to the value of `obarray'. */) | |
2902 | (string, obarray) | |
9391b698 | 2903 | Lisp_Object string, obarray; |
078e7b4a JB |
2904 | { |
2905 | register Lisp_Object tem, sym, *ptr; | |
2906 | ||
265a9e55 | 2907 | if (NILP (obarray)) obarray = Vobarray; |
078e7b4a JB |
2908 | obarray = check_obarray (obarray); |
2909 | ||
b7826503 | 2910 | CHECK_STRING (string); |
078e7b4a | 2911 | |
e28552a4 RS |
2912 | tem = oblookup (obarray, XSTRING (string)->data, |
2913 | XSTRING (string)->size, | |
fc932ac6 | 2914 | STRING_BYTES (XSTRING (string))); |
cfff016d | 2915 | if (!INTEGERP (tem)) |
078e7b4a JB |
2916 | return tem; |
2917 | ||
265a9e55 | 2918 | if (!NILP (Vpurify_flag)) |
9391b698 EN |
2919 | string = Fpurecopy (string); |
2920 | sym = Fmake_symbol (string); | |
44c6c019 GM |
2921 | |
2922 | if (EQ (obarray, initial_obarray)) | |
2923 | XSYMBOL (sym)->interned = SYMBOL_INTERNED_IN_INITIAL_OBARRAY; | |
2924 | else | |
2925 | XSYMBOL (sym)->interned = SYMBOL_INTERNED; | |
078e7b4a | 2926 | |
bdd47b1c | 2927 | if ((XSTRING (string)->data[0] == ':') |
a458d45d | 2928 | && EQ (obarray, initial_obarray)) |
44c6c019 GM |
2929 | { |
2930 | XSYMBOL (sym)->constant = 1; | |
2931 | XSYMBOL (sym)->value = sym; | |
2932 | } | |
a0549832 | 2933 | |
078e7b4a | 2934 | ptr = &XVECTOR (obarray)->contents[XINT (tem)]; |
cfff016d | 2935 | if (SYMBOLP (*ptr)) |
078e7b4a JB |
2936 | XSYMBOL (sym)->next = XSYMBOL (*ptr); |
2937 | else | |
2938 | XSYMBOL (sym)->next = 0; | |
2939 | *ptr = sym; | |
2940 | return sym; | |
2941 | } | |
2942 | ||
2943 | DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0, | |
5de38842 PJ |
2944 | doc: /* Return the canonical symbol named NAME, or nil if none exists. |
2945 | NAME may be a string or a symbol. If it is a symbol, that exact | |
2946 | symbol is searched for. | |
2947 | A second optional argument specifies the obarray to use; | |
2948 | it defaults to the value of `obarray'. */) | |
2949 | (name, obarray) | |
b55048d4 | 2950 | Lisp_Object name, obarray; |
078e7b4a JB |
2951 | { |
2952 | register Lisp_Object tem; | |
b55048d4 | 2953 | struct Lisp_String *string; |
078e7b4a | 2954 | |
265a9e55 | 2955 | if (NILP (obarray)) obarray = Vobarray; |
078e7b4a JB |
2956 | obarray = check_obarray (obarray); |
2957 | ||
b55048d4 GM |
2958 | if (!SYMBOLP (name)) |
2959 | { | |
b7826503 | 2960 | CHECK_STRING (name); |
b55048d4 GM |
2961 | string = XSTRING (name); |
2962 | } | |
2963 | else | |
2964 | string = XSYMBOL (name)->name; | |
078e7b4a | 2965 | |
b55048d4 GM |
2966 | tem = oblookup (obarray, string->data, string->size, STRING_BYTES (string)); |
2967 | if (INTEGERP (tem) || (SYMBOLP (name) && !EQ (name, tem))) | |
2968 | return Qnil; | |
2969 | else | |
078e7b4a | 2970 | return tem; |
078e7b4a | 2971 | } |
d007f5c8 RS |
2972 | \f |
2973 | DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0, | |
5de38842 PJ |
2974 | doc: /* Delete the symbol named NAME, if any, from OBARRAY. |
2975 | The value is t if a symbol was found and deleted, nil otherwise. | |
2976 | NAME may be a string or a symbol. If it is a symbol, that symbol | |
2977 | is deleted, if it belongs to OBARRAY--no other symbol is deleted. | |
2978 | OBARRAY defaults to the value of the variable `obarray'. */) | |
2979 | (name, obarray) | |
d007f5c8 RS |
2980 | Lisp_Object name, obarray; |
2981 | { | |
2982 | register Lisp_Object string, tem; | |
2983 | int hash; | |
2984 | ||
2985 | if (NILP (obarray)) obarray = Vobarray; | |
2986 | obarray = check_obarray (obarray); | |
2987 | ||
2988 | if (SYMBOLP (name)) | |
2989 | XSETSTRING (string, XSYMBOL (name)->name); | |
2990 | else | |
2991 | { | |
b7826503 | 2992 | CHECK_STRING (name); |
d007f5c8 RS |
2993 | string = name; |
2994 | } | |
2995 | ||
e28552a4 RS |
2996 | tem = oblookup (obarray, XSTRING (string)->data, |
2997 | XSTRING (string)->size, | |
fc932ac6 | 2998 | STRING_BYTES (XSTRING (string))); |
d007f5c8 RS |
2999 | if (INTEGERP (tem)) |
3000 | return Qnil; | |
3001 | /* If arg was a symbol, don't delete anything but that symbol itself. */ | |
3002 | if (SYMBOLP (name) && !EQ (name, tem)) | |
3003 | return Qnil; | |
3004 | ||
44c6c019 GM |
3005 | XSYMBOL (tem)->interned = SYMBOL_UNINTERNED; |
3006 | XSYMBOL (tem)->constant = 0; | |
3007 | XSYMBOL (tem)->indirect_variable = 0; | |
ca69c42f | 3008 | |
d007f5c8 RS |
3009 | hash = oblookup_last_bucket_number; |
3010 | ||
3011 | if (EQ (XVECTOR (obarray)->contents[hash], tem)) | |
b2a30870 RS |
3012 | { |
3013 | if (XSYMBOL (tem)->next) | |
3014 | XSETSYMBOL (XVECTOR (obarray)->contents[hash], XSYMBOL (tem)->next); | |
3015 | else | |
3016 | XSETINT (XVECTOR (obarray)->contents[hash], 0); | |
3017 | } | |
d007f5c8 RS |
3018 | else |
3019 | { | |
3020 | Lisp_Object tail, following; | |
3021 | ||
3022 | for (tail = XVECTOR (obarray)->contents[hash]; | |
3023 | XSYMBOL (tail)->next; | |
3024 | tail = following) | |
3025 | { | |
3026 | XSETSYMBOL (following, XSYMBOL (tail)->next); | |
3027 | if (EQ (following, tem)) | |
3028 | { | |
3029 | XSYMBOL (tail)->next = XSYMBOL (following)->next; | |
3030 | break; | |
3031 | } | |
3032 | } | |
3033 | } | |
3034 | ||
3035 | return Qt; | |
3036 | } | |
3037 | \f | |
3038 | /* Return the symbol in OBARRAY whose names matches the string | |
e28552a4 RS |
3039 | of SIZE characters (SIZE_BYTE bytes) at PTR. |
3040 | If there is no such symbol in OBARRAY, return nil. | |
d007f5c8 RS |
3041 | |
3042 | Also store the bucket number in oblookup_last_bucket_number. */ | |
078e7b4a JB |
3043 | |
3044 | Lisp_Object | |
e28552a4 | 3045 | oblookup (obarray, ptr, size, size_byte) |
078e7b4a JB |
3046 | Lisp_Object obarray; |
3047 | register char *ptr; | |
e28552a4 | 3048 | int size, size_byte; |
078e7b4a | 3049 | { |
7a70b397 RS |
3050 | int hash; |
3051 | int obsize; | |
078e7b4a JB |
3052 | register Lisp_Object tail; |
3053 | Lisp_Object bucket, tem; | |
3054 | ||
cfff016d | 3055 | if (!VECTORP (obarray) |
7c79a684 | 3056 | || (obsize = XVECTOR (obarray)->size) == 0) |
078e7b4a JB |
3057 | { |
3058 | obarray = check_obarray (obarray); | |
3059 | obsize = XVECTOR (obarray)->size; | |
3060 | } | |
519418b3 RS |
3061 | /* This is sometimes needed in the middle of GC. */ |
3062 | obsize &= ~ARRAY_MARK_FLAG; | |
078e7b4a | 3063 | /* Combining next two lines breaks VMS C 2.3. */ |
e28552a4 | 3064 | hash = hash_string (ptr, size_byte); |
078e7b4a JB |
3065 | hash %= obsize; |
3066 | bucket = XVECTOR (obarray)->contents[hash]; | |
d007f5c8 | 3067 | oblookup_last_bucket_number = hash; |
078e7b4a JB |
3068 | if (XFASTINT (bucket) == 0) |
3069 | ; | |
cfff016d | 3070 | else if (!SYMBOLP (bucket)) |
078e7b4a | 3071 | error ("Bad data in guts of obarray"); /* Like CADR error message */ |
d007f5c8 RS |
3072 | else |
3073 | for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next)) | |
078e7b4a | 3074 | { |
fc932ac6 | 3075 | if (STRING_BYTES (XSYMBOL (tail)->name) == size_byte |
e28552a4 RS |
3076 | && XSYMBOL (tail)->name->size == size |
3077 | && !bcmp (XSYMBOL (tail)->name->data, ptr, size_byte)) | |
078e7b4a JB |
3078 | return tail; |
3079 | else if (XSYMBOL (tail)->next == 0) | |
3080 | break; | |
3081 | } | |
1805de4f | 3082 | XSETINT (tem, hash); |
078e7b4a JB |
3083 | return tem; |
3084 | } | |
3085 | ||
3086 | static int | |
3087 | hash_string (ptr, len) | |
3088 | unsigned char *ptr; | |
3089 | int len; | |
3090 | { | |
3091 | register unsigned char *p = ptr; | |
3092 | register unsigned char *end = p + len; | |
3093 | register unsigned char c; | |
3094 | register int hash = 0; | |
3095 | ||
3096 | while (p != end) | |
3097 | { | |
3098 | c = *p++; | |
3099 | if (c >= 0140) c -= 40; | |
3100 | hash = ((hash<<3) + (hash>>28) + c); | |
3101 | } | |
3102 | return hash & 07777777777; | |
3103 | } | |
d007f5c8 | 3104 | \f |
078e7b4a JB |
3105 | void |
3106 | map_obarray (obarray, fn, arg) | |
3107 | Lisp_Object obarray; | |
d5b28a9d | 3108 | void (*fn) P_ ((Lisp_Object, Lisp_Object)); |
078e7b4a JB |
3109 | Lisp_Object arg; |
3110 | { | |
3111 | register int i; | |
3112 | register Lisp_Object tail; | |
b7826503 | 3113 | CHECK_VECTOR (obarray); |
078e7b4a JB |
3114 | for (i = XVECTOR (obarray)->size - 1; i >= 0; i--) |
3115 | { | |
3116 | tail = XVECTOR (obarray)->contents[i]; | |
4f5c4403 | 3117 | if (SYMBOLP (tail)) |
078e7b4a JB |
3118 | while (1) |
3119 | { | |
3120 | (*fn) (tail, arg); | |
3121 | if (XSYMBOL (tail)->next == 0) | |
3122 | break; | |
1805de4f | 3123 | XSETSYMBOL (tail, XSYMBOL (tail)->next); |
078e7b4a JB |
3124 | } |
3125 | } | |
3126 | } | |
3127 | ||
d5b28a9d | 3128 | void |
078e7b4a JB |
3129 | mapatoms_1 (sym, function) |
3130 | Lisp_Object sym, function; | |
3131 | { | |
3132 | call1 (function, sym); | |
3133 | } | |
3134 | ||
3135 | DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0, | |
5de38842 PJ |
3136 | doc: /* Call FUNCTION on every symbol in OBARRAY. |
3137 | OBARRAY defaults to the value of `obarray'. */) | |
3138 | (function, obarray) | |
078e7b4a JB |
3139 | Lisp_Object function, obarray; |
3140 | { | |
265a9e55 | 3141 | if (NILP (obarray)) obarray = Vobarray; |
078e7b4a JB |
3142 | obarray = check_obarray (obarray); |
3143 | ||
3144 | map_obarray (obarray, mapatoms_1, function); | |
3145 | return Qnil; | |
3146 | } | |
3147 | ||
5e88a39e | 3148 | #define OBARRAY_SIZE 1511 |
078e7b4a JB |
3149 | |
3150 | void | |
3151 | init_obarray () | |
3152 | { | |
3153 | Lisp_Object oblength; | |
3154 | int hash; | |
3155 | Lisp_Object *tem; | |
3156 | ||
baf69866 | 3157 | XSETFASTINT (oblength, OBARRAY_SIZE); |
078e7b4a | 3158 | |
491f16a2 | 3159 | Qnil = Fmake_symbol (make_pure_string ("nil", 3, 3, 0)); |
078e7b4a JB |
3160 | Vobarray = Fmake_vector (oblength, make_number (0)); |
3161 | initial_obarray = Vobarray; | |
3162 | staticpro (&initial_obarray); | |
3163 | /* Intern nil in the obarray */ | |
44c6c019 GM |
3164 | XSYMBOL (Qnil)->interned = SYMBOL_INTERNED_IN_INITIAL_OBARRAY; |
3165 | XSYMBOL (Qnil)->constant = 1; | |
3166 | ||
078e7b4a JB |
3167 | /* These locals are to kludge around a pyramid compiler bug. */ |
3168 | hash = hash_string ("nil", 3); | |
3169 | /* Separate statement here to avoid VAXC bug. */ | |
3170 | hash %= OBARRAY_SIZE; | |
3171 | tem = &XVECTOR (Vobarray)->contents[hash]; | |
3172 | *tem = Qnil; | |
3173 | ||
491f16a2 | 3174 | Qunbound = Fmake_symbol (make_pure_string ("unbound", 7, 7, 0)); |
078e7b4a JB |
3175 | XSYMBOL (Qnil)->function = Qunbound; |
3176 | XSYMBOL (Qunbound)->value = Qunbound; | |
3177 | XSYMBOL (Qunbound)->function = Qunbound; | |
3178 | ||
3179 | Qt = intern ("t"); | |
3180 | XSYMBOL (Qnil)->value = Qnil; | |
3181 | XSYMBOL (Qnil)->plist = Qnil; | |
3182 | XSYMBOL (Qt)->value = Qt; | |
44c6c019 | 3183 | XSYMBOL (Qt)->constant = 1; |
078e7b4a JB |
3184 | |
3185 | /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */ | |
3186 | Vpurify_flag = Qt; | |
3187 | ||
3188 | Qvariable_documentation = intern ("variable-documentation"); | |
0f73bb1c | 3189 | staticpro (&Qvariable_documentation); |
078e7b4a | 3190 | |
449fea39 | 3191 | read_buffer_size = 100 + MAX_MULTIBYTE_LENGTH; |
3cb65b0e | 3192 | read_buffer = (char *) xmalloc (read_buffer_size); |
078e7b4a JB |
3193 | } |
3194 | \f | |
3195 | void | |
3196 | defsubr (sname) | |
3197 | struct Lisp_Subr *sname; | |
3198 | { | |
3199 | Lisp_Object sym; | |
3200 | sym = intern (sname->symbol_name); | |
1805de4f | 3201 | XSETSUBR (XSYMBOL (sym)->function, sname); |
078e7b4a JB |
3202 | } |
3203 | ||
3204 | #ifdef NOTDEF /* use fset in subr.el now */ | |
3205 | void | |
3206 | defalias (sname, string) | |
3207 | struct Lisp_Subr *sname; | |
3208 | char *string; | |
3209 | { | |
3210 | Lisp_Object sym; | |
3211 | sym = intern (string); | |
1805de4f | 3212 | XSETSUBR (XSYMBOL (sym)->function, sname); |
078e7b4a JB |
3213 | } |
3214 | #endif /* NOTDEF */ | |
3215 | ||
078e7b4a | 3216 | /* Define an "integer variable"; a symbol whose value is forwarded |
1a0f90f7 | 3217 | to a C variable of type int. Sample call: */ |
5de38842 | 3218 | /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */ |
078e7b4a | 3219 | void |
e9e00ff2 | 3220 | defvar_int (namestring, address) |
078e7b4a JB |
3221 | char *namestring; |
3222 | int *address; | |
078e7b4a | 3223 | { |
1a0f90f7 | 3224 | Lisp_Object sym, val; |
078e7b4a | 3225 | sym = intern (namestring); |
1a0f90f7 | 3226 | val = allocate_misc (); |
47e28b2c | 3227 | XMISCTYPE (val) = Lisp_Misc_Intfwd; |
fc1e7df5 | 3228 | XINTFWD (val)->intvar = address; |
44c6c019 | 3229 | SET_SYMBOL_VALUE (sym, val); |
078e7b4a JB |
3230 | } |
3231 | ||
3232 | /* Similar but define a variable whose value is T if address contains 1, | |
1a0f90f7 | 3233 | NIL if address contains 0 */ |
078e7b4a | 3234 | void |
e9e00ff2 | 3235 | defvar_bool (namestring, address) |
078e7b4a JB |
3236 | char *namestring; |
3237 | int *address; | |
078e7b4a | 3238 | { |
1a0f90f7 | 3239 | Lisp_Object sym, val; |
078e7b4a | 3240 | sym = intern (namestring); |
1a0f90f7 | 3241 | val = allocate_misc (); |
47e28b2c | 3242 | XMISCTYPE (val) = Lisp_Misc_Boolfwd; |
fc1e7df5 | 3243 | XBOOLFWD (val)->boolvar = address; |
44c6c019 | 3244 | SET_SYMBOL_VALUE (sym, val); |
1ffcc3b1 | 3245 | Vbyte_boolean_vars = Fcons (sym, Vbyte_boolean_vars); |
078e7b4a JB |
3246 | } |
3247 | ||
1a0f90f7 KH |
3248 | /* Similar but define a variable whose value is the Lisp Object stored |
3249 | at address. Two versions: with and without gc-marking of the C | |
3250 | variable. The nopro version is used when that variable will be | |
3251 | gc-marked for some other reason, since marking the same slot twice | |
3252 | can cause trouble with strings. */ | |
078e7b4a | 3253 | void |
1a0f90f7 | 3254 | defvar_lisp_nopro (namestring, address) |
078e7b4a JB |
3255 | char *namestring; |
3256 | Lisp_Object *address; | |
078e7b4a | 3257 | { |
1a0f90f7 | 3258 | Lisp_Object sym, val; |
078e7b4a | 3259 | sym = intern (namestring); |
1a0f90f7 | 3260 | val = allocate_misc (); |
47e28b2c | 3261 | XMISCTYPE (val) = Lisp_Misc_Objfwd; |
fc1e7df5 | 3262 | XOBJFWD (val)->objvar = address; |
44c6c019 | 3263 | SET_SYMBOL_VALUE (sym, val); |
078e7b4a JB |
3264 | } |
3265 | ||
078e7b4a | 3266 | void |
1a0f90f7 | 3267 | defvar_lisp (namestring, address) |
078e7b4a JB |
3268 | char *namestring; |
3269 | Lisp_Object *address; | |
078e7b4a | 3270 | { |
1a0f90f7 KH |
3271 | defvar_lisp_nopro (namestring, address); |
3272 | staticpro (address); | |
078e7b4a JB |
3273 | } |
3274 | ||
078e7b4a | 3275 | /* Similar but define a variable whose value is the Lisp Object stored in |
2836d9a4 KH |
3276 | the current buffer. address is the address of the slot in the buffer |
3277 | that is current now. */ | |
078e7b4a JB |
3278 | |
3279 | void | |
4360b0c6 | 3280 | defvar_per_buffer (namestring, address, type, doc) |
078e7b4a JB |
3281 | char *namestring; |
3282 | Lisp_Object *address; | |
4360b0c6 | 3283 | Lisp_Object type; |
078e7b4a JB |
3284 | char *doc; |
3285 | { | |
1a0f90f7 | 3286 | Lisp_Object sym, val; |
078e7b4a JB |
3287 | int offset; |
3288 | extern struct buffer buffer_local_symbols; | |
3289 | ||
3290 | sym = intern (namestring); | |
1a0f90f7 | 3291 | val = allocate_misc (); |
078e7b4a JB |
3292 | offset = (char *)address - (char *)current_buffer; |
3293 | ||
47e28b2c | 3294 | XMISCTYPE (val) = Lisp_Misc_Buffer_Objfwd; |
fc1e7df5 | 3295 | XBUFFER_OBJFWD (val)->offset = offset; |
44c6c019 | 3296 | SET_SYMBOL_VALUE (sym, val); |
11fd416e GM |
3297 | PER_BUFFER_SYMBOL (offset) = sym; |
3298 | PER_BUFFER_TYPE (offset) = type; | |
cf611f01 | 3299 | |
11fd416e | 3300 | if (PER_BUFFER_IDX (offset) == 0) |
078e7b4a JB |
3301 | /* Did a DEFVAR_PER_BUFFER without initializing the corresponding |
3302 | slot of buffer_local_flags */ | |
3303 | abort (); | |
3304 | } | |
3305 | ||
950c215d KH |
3306 | |
3307 | /* Similar but define a variable whose value is the Lisp Object stored | |
4ac38690 | 3308 | at a particular offset in the current kboard object. */ |
950c215d KH |
3309 | |
3310 | void | |
4ac38690 | 3311 | defvar_kboard (namestring, offset) |
950c215d KH |
3312 | char *namestring; |
3313 | int offset; | |
3314 | { | |
3315 | Lisp_Object sym, val; | |
3316 | sym = intern (namestring); | |
3317 | val = allocate_misc (); | |
47e28b2c | 3318 | XMISCTYPE (val) = Lisp_Misc_Kboard_Objfwd; |
4ac38690 | 3319 | XKBOARD_OBJFWD (val)->offset = offset; |
44c6c019 | 3320 | SET_SYMBOL_VALUE (sym, val); |
950c215d | 3321 | } |
078e7b4a | 3322 | \f |
11938f10 KH |
3323 | /* Record the value of load-path used at the start of dumping |
3324 | so we can see if the site changed it later during dumping. */ | |
3325 | static Lisp_Object dump_path; | |
3326 | ||
d5b28a9d | 3327 | void |
279499f0 | 3328 | init_lread () |
078e7b4a | 3329 | { |
46947372 | 3330 | char *normal; |
e73997a1 | 3331 | int turn_off_warning = 0; |
078e7b4a | 3332 | |
279499f0 | 3333 | /* Compute the default load-path. */ |
46947372 JB |
3334 | #ifdef CANNOT_DUMP |
3335 | normal = PATH_LOADSEARCH; | |
e065a56e | 3336 | Vload_path = decode_env_path (0, normal); |
46947372 JB |
3337 | #else |
3338 | if (NILP (Vpurify_flag)) | |
3339 | normal = PATH_LOADSEARCH; | |
279499f0 | 3340 | else |
46947372 | 3341 | normal = PATH_DUMPLOADSEARCH; |
279499f0 | 3342 | |
46947372 JB |
3343 | /* In a dumped Emacs, we normally have to reset the value of |
3344 | Vload_path from PATH_LOADSEARCH, since the value that was dumped | |
3345 | uses ../lisp, instead of the path of the installed elisp | |
3346 | libraries. However, if it appears that Vload_path was changed | |
3347 | from the default before dumping, don't override that value. */ | |
4746118a JB |
3348 | if (initialized) |
3349 | { | |
4746118a | 3350 | if (! NILP (Fequal (dump_path, Vload_path))) |
80667d53 RS |
3351 | { |
3352 | Vload_path = decode_env_path (0, normal); | |
74180aa4 | 3353 | if (!NILP (Vinstallation_directory)) |
80667d53 | 3354 | { |
74180aa4 | 3355 | /* Add to the path the lisp subdir of the |
3a3056e5 RS |
3356 | installation dir, if it exists. */ |
3357 | Lisp_Object tem, tem1; | |
74180aa4 RS |
3358 | tem = Fexpand_file_name (build_string ("lisp"), |
3359 | Vinstallation_directory); | |
3a3056e5 RS |
3360 | tem1 = Ffile_exists_p (tem); |
3361 | if (!NILP (tem1)) | |
3362 | { | |
3363 | if (NILP (Fmember (tem, Vload_path))) | |
e73997a1 RS |
3364 | { |
3365 | turn_off_warning = 1; | |
3366 | Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil)); | |
3367 | } | |
3a3056e5 RS |
3368 | } |
3369 | else | |
3370 | /* That dir doesn't exist, so add the build-time | |
3371 | Lisp dirs instead. */ | |
3372 | Vload_path = nconc2 (Vload_path, dump_path); | |
c478f98c | 3373 | |
9fbc0116 RS |
3374 | /* Add leim under the installation dir, if it exists. */ |
3375 | tem = Fexpand_file_name (build_string ("leim"), | |
3376 | Vinstallation_directory); | |
3377 | tem1 = Ffile_exists_p (tem); | |
3378 | if (!NILP (tem1)) | |
3379 | { | |
3380 | if (NILP (Fmember (tem, Vload_path))) | |
3381 | Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil)); | |
3382 | } | |
3383 | ||
c478f98c RS |
3384 | /* Add site-list under the installation dir, if it exists. */ |
3385 | tem = Fexpand_file_name (build_string ("site-lisp"), | |
3386 | Vinstallation_directory); | |
3387 | tem1 = Ffile_exists_p (tem); | |
3388 | if (!NILP (tem1)) | |
3389 | { | |
3390 | if (NILP (Fmember (tem, Vload_path))) | |
3391 | Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil)); | |
3392 | } | |
0f337465 RS |
3393 | |
3394 | /* If Emacs was not built in the source directory, | |
9fbc0116 RS |
3395 | and it is run from where it was built, add to load-path |
3396 | the lisp, leim and site-lisp dirs under that directory. */ | |
0f337465 RS |
3397 | |
3398 | if (NILP (Fequal (Vinstallation_directory, Vsource_directory))) | |
3399 | { | |
33046fc9 RS |
3400 | Lisp_Object tem2; |
3401 | ||
0f337465 RS |
3402 | tem = Fexpand_file_name (build_string ("src/Makefile"), |
3403 | Vinstallation_directory); | |
3404 | tem1 = Ffile_exists_p (tem); | |
33046fc9 RS |
3405 | |
3406 | /* Don't be fooled if they moved the entire source tree | |
3407 | AFTER dumping Emacs. If the build directory is indeed | |
3408 | different from the source dir, src/Makefile.in and | |
3409 | src/Makefile will not be found together. */ | |
3410 | tem = Fexpand_file_name (build_string ("src/Makefile.in"), | |
3411 | Vinstallation_directory); | |
3412 | tem2 = Ffile_exists_p (tem); | |
3413 | if (!NILP (tem1) && NILP (tem2)) | |
0f337465 RS |
3414 | { |
3415 | tem = Fexpand_file_name (build_string ("lisp"), | |
3416 | Vsource_directory); | |
3417 | ||
3418 | if (NILP (Fmember (tem, Vload_path))) | |
3419 | Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil)); | |
3420 | ||
9fbc0116 RS |
3421 | tem = Fexpand_file_name (build_string ("leim"), |
3422 | Vsource_directory); | |
3423 | ||
3424 | if (NILP (Fmember (tem, Vload_path))) | |
3425 | Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil)); | |
3426 | ||
0f337465 RS |
3427 | tem = Fexpand_file_name (build_string ("site-lisp"), |
3428 | Vsource_directory); | |
3429 | ||
3430 | if (NILP (Fmember (tem, Vload_path))) | |
3431 | Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil)); | |
3432 | } | |
3433 | } | |
80667d53 RS |
3434 | } |
3435 | } | |
4746118a JB |
3436 | } |
3437 | else | |
11938f10 | 3438 | { |
7b396c6c RS |
3439 | /* NORMAL refers to the lisp dir in the source directory. */ |
3440 | /* We used to add ../lisp at the front here, but | |
3441 | that caused trouble because it was copied from dump_path | |
3442 | into Vload_path, aboe, when Vinstallation_directory was non-nil. | |
3443 | It should be unnecessary. */ | |
3444 | Vload_path = decode_env_path (0, normal); | |
11938f10 KH |
3445 | dump_path = Vload_path; |
3446 | } | |
46947372 | 3447 | #endif |
279499f0 | 3448 | |
317073d5 RS |
3449 | #ifndef WINDOWSNT |
3450 | /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is | |
3451 | almost never correct, thereby causing a warning to be printed out that | |
8e6208c5 | 3452 | confuses users. Since PATH_LOADSEARCH is always overridden by the |
317073d5 RS |
3453 | EMACSLOADPATH environment variable below, disable the warning on NT. */ |
3454 | ||
078e7b4a | 3455 | /* Warn if dirs in the *standard* path don't exist. */ |
e73997a1 RS |
3456 | if (!turn_off_warning) |
3457 | { | |
3458 | Lisp_Object path_tail; | |
078e7b4a | 3459 | |
e73997a1 RS |
3460 | for (path_tail = Vload_path; |
3461 | !NILP (path_tail); | |
c1d497be | 3462 | path_tail = XCDR (path_tail)) |
e73997a1 RS |
3463 | { |
3464 | Lisp_Object dirfile; | |
3465 | dirfile = Fcar (path_tail); | |
3466 | if (STRINGP (dirfile)) | |
3467 | { | |
3468 | dirfile = Fdirectory_file_name (dirfile); | |
3469 | if (access (XSTRING (dirfile)->data, 0) < 0) | |
85496b8c | 3470 | dir_warning ("Warning: Lisp directory `%s' does not exist.\n", |
c1d497be | 3471 | XCAR (path_tail)); |
e73997a1 RS |
3472 | } |
3473 | } | |
3474 | } | |
317073d5 | 3475 | #endif /* WINDOWSNT */ |
46947372 JB |
3476 | |
3477 | /* If the EMACSLOADPATH environment variable is set, use its value. | |
3478 | This doesn't apply if we're dumping. */ | |
ffd9c2a1 | 3479 | #ifndef CANNOT_DUMP |
46947372 JB |
3480 | if (NILP (Vpurify_flag) |
3481 | && egetenv ("EMACSLOADPATH")) | |
ffd9c2a1 | 3482 | #endif |
279499f0 | 3483 | Vload_path = decode_env_path ("EMACSLOADPATH", normal); |
279499f0 JB |
3484 | |
3485 | Vvalues = Qnil; | |
3486 | ||
078e7b4a | 3487 | load_in_progress = 0; |
4e53f562 | 3488 | Vload_file_name = Qnil; |
d2c6be7f RS |
3489 | |
3490 | load_descriptor_list = Qnil; | |
8f6b0411 RS |
3491 | |
3492 | Vstandard_input = Qt; | |
f74b0705 | 3493 | Vloads_in_progress = Qnil; |
078e7b4a JB |
3494 | } |
3495 | ||
85496b8c RS |
3496 | /* Print a warning, using format string FORMAT, that directory DIRNAME |
3497 | does not exist. Print it on stderr and put it in *Message*. */ | |
3498 | ||
d5b28a9d | 3499 | void |
85496b8c RS |
3500 | dir_warning (format, dirname) |
3501 | char *format; | |
3502 | Lisp_Object dirname; | |
3503 | { | |
3504 | char *buffer | |
3505 | = (char *) alloca (XSTRING (dirname)->size + strlen (format) + 5); | |
3506 | ||
3507 | fprintf (stderr, format, XSTRING (dirname)->data); | |
3508 | sprintf (buffer, format, XSTRING (dirname)->data); | |
9b69357e GV |
3509 | /* Don't log the warning before we've initialized!! */ |
3510 | if (initialized) | |
3511 | message_dolog (buffer, strlen (buffer), 0, STRING_MULTIBYTE (dirname)); | |
85496b8c RS |
3512 | } |
3513 | ||
078e7b4a | 3514 | void |
279499f0 | 3515 | syms_of_lread () |
078e7b4a JB |
3516 | { |
3517 | defsubr (&Sread); | |
3518 | defsubr (&Sread_from_string); | |
3519 | defsubr (&Sintern); | |
3520 | defsubr (&Sintern_soft); | |
d007f5c8 | 3521 | defsubr (&Sunintern); |
078e7b4a | 3522 | defsubr (&Sload); |
228d4b1c | 3523 | defsubr (&Seval_buffer); |
078e7b4a JB |
3524 | defsubr (&Seval_region); |
3525 | defsubr (&Sread_char); | |
3526 | defsubr (&Sread_char_exclusive); | |
078e7b4a | 3527 | defsubr (&Sread_event); |
078e7b4a JB |
3528 | defsubr (&Sget_file_char); |
3529 | defsubr (&Smapatoms); | |
3530 | ||
3531 | DEFVAR_LISP ("obarray", &Vobarray, | |
5de38842 PJ |
3532 | doc: /* Symbol table for use by `intern' and `read'. |
3533 | It is a vector whose length ought to be prime for best results. | |
3534 | The vector's contents don't make sense if examined from Lisp programs; | |
3535 | to find all the symbols in an obarray, use `mapatoms'. */); | |
078e7b4a JB |
3536 | |
3537 | DEFVAR_LISP ("values", &Vvalues, | |
5de38842 PJ |
3538 | doc: /* List of values of all expressions which were read, evaluated and printed. |
3539 | Order is reverse chronological. */); | |
078e7b4a JB |
3540 | |
3541 | DEFVAR_LISP ("standard-input", &Vstandard_input, | |
5de38842 PJ |
3542 | doc: /* Stream for read to get input from. |
3543 | See documentation of `read' for possible values. */); | |
078e7b4a JB |
3544 | Vstandard_input = Qt; |
3545 | ||
3546 | DEFVAR_LISP ("load-path", &Vload_path, | |
5de38842 PJ |
3547 | doc: /* *List of directories to search for files to load. |
3548 | Each element is a string (directory name) or nil (try default directory). | |
3549 | Initialized based on EMACSLOADPATH environment variable, if any, | |
3550 | otherwise to default specified by file `epaths.h' when Emacs was built. */); | |
078e7b4a | 3551 | |
e61b9b87 | 3552 | DEFVAR_LISP ("load-suffixes", &Vload_suffixes, |
5de38842 PJ |
3553 | doc: /* *List of suffixes to try for files to load. |
3554 | This list should not include the empty string. */); | |
e61b9b87 SM |
3555 | Vload_suffixes = Fcons (build_string (".elc"), |
3556 | Fcons (build_string (".el"), Qnil)); | |
ddb716ef SM |
3557 | /* We don't use empty_string because it's not initialized yet. */ |
3558 | default_suffixes = Fcons (build_string (""), Qnil); | |
e61b9b87 SM |
3559 | staticpro (&default_suffixes); |
3560 | ||
078e7b4a | 3561 | DEFVAR_BOOL ("load-in-progress", &load_in_progress, |
5de38842 | 3562 | doc: /* Non-nil iff inside of `load'. */); |
078e7b4a JB |
3563 | |
3564 | DEFVAR_LISP ("after-load-alist", &Vafter_load_alist, | |
5de38842 PJ |
3565 | doc: /* An alist of expressions to be evalled when particular files are loaded. |
3566 | Each element looks like (FILENAME FORMS...). | |
3567 | When `load' is run and the file-name argument is FILENAME, | |
3568 | the FORMS in the corresponding element are executed at the end of loading. | |
3569 | ||
3570 | FILENAME must match exactly! Normally FILENAME is the name of a library, | |
3571 | with no directory specified, since that is how `load' is normally called. | |
3572 | An error in FORMS does not undo the load, | |
3573 | but does prevent execution of the rest of the FORMS. | |
3574 | FILENAME can also be a symbol (a feature) and FORMS are then executed | |
3575 | when the corresponding call to `provide' is made. */); | |
078e7b4a JB |
3576 | Vafter_load_alist = Qnil; |
3577 | ||
ae321d28 | 3578 | DEFVAR_LISP ("load-history", &Vload_history, |
5de38842 PJ |
3579 | doc: /* Alist mapping source file names to symbols and features. |
3580 | Each alist element is a list that starts with a file name, | |
3581 | except for one element (optional) that starts with nil and describes | |
3582 | definitions evaluated from buffers not visiting files. | |
3583 | The remaining elements of each list are symbols defined as functions | |
3584 | or variables, and cons cells `(provide . FEATURE)', `(require . FEATURE)', | |
3585 | and `(autoload . SYMBOL)'. */); | |
ae321d28 RS |
3586 | Vload_history = Qnil; |
3587 | ||
20ea2964 | 3588 | DEFVAR_LISP ("load-file-name", &Vload_file_name, |
5de38842 | 3589 | doc: /* Full name of file being loaded by `load'. */); |
20ea2964 RS |
3590 | Vload_file_name = Qnil; |
3591 | ||
4116ab9f | 3592 | DEFVAR_LISP ("user-init-file", &Vuser_init_file, |
5de38842 PJ |
3593 | doc: /* File name, including directory, of user's initialization file. |
3594 | If the file loaded had extension `.elc' and there was a corresponding `.el' | |
3595 | file, this variable contains the name of the .el file, suitable for use | |
3596 | by functions like `custom-save-all' which edit the init file. */); | |
4116ab9f KH |
3597 | Vuser_init_file = Qnil; |
3598 | ||
8a1f1537 | 3599 | DEFVAR_LISP ("current-load-list", &Vcurrent_load_list, |
5de38842 | 3600 | doc: /* Used for internal purposes by `load'. */); |
ae321d28 RS |
3601 | Vcurrent_load_list = Qnil; |
3602 | ||
84a15045 | 3603 | DEFVAR_LISP ("load-read-function", &Vload_read_function, |
5de38842 PJ |
3604 | doc: /* Function used by `load' and `eval-region' for reading expressions. |
3605 | The default is nil, which means use the function `read'. */); | |
84a15045 RS |
3606 | Vload_read_function = Qnil; |
3607 | ||
fe0e03f3 | 3608 | DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function, |
5de38842 PJ |
3609 | doc: /* Function called in `load' for loading an Emacs lisp source file. |
3610 | This function is for doing code conversion before reading the source file. | |
3611 | If nil, loading is done without any code conversion. | |
3612 | Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where | |
3613 | FULLNAME is the full name of FILE. | |
3614 | See `load' for the meaning of the remaining arguments. */); | |
fe0e03f3 KH |
3615 | Vload_source_file_function = Qnil; |
3616 | ||
b2a30870 | 3617 | DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings, |
5de38842 PJ |
3618 | doc: /* Non-nil means `load' should force-load all dynamic doc strings. |
3619 | This is useful when the file being loaded is a temporary copy. */); | |
b2a30870 RS |
3620 | load_force_doc_strings = 0; |
3621 | ||
94e554db | 3622 | DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte, |
5de38842 PJ |
3623 | doc: /* Non-nil means `read' converts strings to unibyte whenever possible. |
3624 | This is normally bound by `load' and `eval-buffer' to control `read', | |
3625 | and is not meant for users to change. */); | |
94e554db RS |
3626 | load_convert_to_unibyte = 0; |
3627 | ||
1521a8fa | 3628 | DEFVAR_LISP ("source-directory", &Vsource_directory, |
5de38842 PJ |
3629 | doc: /* Directory in which Emacs sources were found when Emacs was built. |
3630 | You cannot count on them to still be there! */); | |
a90ba1e2 KH |
3631 | Vsource_directory |
3632 | = Fexpand_file_name (build_string ("../"), | |
3633 | Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH))); | |
3634 | ||
4b104c41 | 3635 | DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list, |
5de38842 | 3636 | doc: /* List of files that were preloaded (when dumping Emacs). */); |
4b104c41 RS |
3637 | Vpreloaded_file_list = Qnil; |
3638 | ||
1ffcc3b1 | 3639 | DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars, |
5de38842 | 3640 | doc: /* List of all DEFVAR_BOOL variables, used by the byte code optimizer. */); |
1ffcc3b1 DL |
3641 | Vbyte_boolean_vars = Qnil; |
3642 | ||
da84f340 | 3643 | DEFVAR_BOOL ("load-dangerous-libraries", &load_dangerous_libraries, |
5de38842 PJ |
3644 | doc: /* Non-nil means load dangerous compiled Lisp files. |
3645 | Some versions of XEmacs use different byte codes than Emacs. These | |
3646 | incompatible byte codes can make Emacs crash when it tries to execute | |
3647 | them. */); | |
da84f340 GM |
3648 | load_dangerous_libraries = 0; |
3649 | ||
bb970e67 | 3650 | DEFVAR_LISP ("bytecomp-version-regexp", &Vbytecomp_version_regexp, |
5de38842 PJ |
3651 | doc: /* Regular expression matching safe to load compiled Lisp files. |
3652 | When Emacs loads a compiled Lisp file, it reads the first 512 bytes | |
3653 | from the file, and matches them against this regular expression. | |
3654 | When the regular expression matches, the file is considered to be safe | |
3655 | to load. See also `load-dangerous-libraries'. */); | |
bb970e67 | 3656 | Vbytecomp_version_regexp |
f2e7d5eb | 3657 | = build_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)"); |
da84f340 | 3658 | |
a90ba1e2 KH |
3659 | /* Vsource_directory was initialized in init_lread. */ |
3660 | ||
d2c6be7f RS |
3661 | load_descriptor_list = Qnil; |
3662 | staticpro (&load_descriptor_list); | |
3663 | ||
8a1f1537 RS |
3664 | Qcurrent_load_list = intern ("current-load-list"); |
3665 | staticpro (&Qcurrent_load_list); | |
3666 | ||
078e7b4a JB |
3667 | Qstandard_input = intern ("standard-input"); |
3668 | staticpro (&Qstandard_input); | |
3669 | ||
3670 | Qread_char = intern ("read-char"); | |
3671 | staticpro (&Qread_char); | |
3672 | ||
3673 | Qget_file_char = intern ("get-file-char"); | |
3674 | staticpro (&Qget_file_char); | |
7bd279cd | 3675 | |
17634846 RS |
3676 | Qbackquote = intern ("`"); |
3677 | staticpro (&Qbackquote); | |
3678 | Qcomma = intern (","); | |
3679 | staticpro (&Qcomma); | |
3680 | Qcomma_at = intern (",@"); | |
3681 | staticpro (&Qcomma_at); | |
3682 | Qcomma_dot = intern (",."); | |
3683 | staticpro (&Qcomma_dot); | |
3684 | ||
74549846 RS |
3685 | Qinhibit_file_name_operation = intern ("inhibit-file-name-operation"); |
3686 | staticpro (&Qinhibit_file_name_operation); | |
3687 | ||
7bd279cd RS |
3688 | Qascii_character = intern ("ascii-character"); |
3689 | staticpro (&Qascii_character); | |
c2225d00 | 3690 | |
2b6cae0c RS |
3691 | Qfunction = intern ("function"); |
3692 | staticpro (&Qfunction); | |
3693 | ||
c2225d00 RS |
3694 | Qload = intern ("load"); |
3695 | staticpro (&Qload); | |
20ea2964 RS |
3696 | |
3697 | Qload_file_name = intern ("load-file-name"); | |
3698 | staticpro (&Qload_file_name); | |
11938f10 KH |
3699 | |
3700 | staticpro (&dump_path); | |
4ad679f9 EN |
3701 | |
3702 | staticpro (&read_objects); | |
3703 | read_objects = Qnil; | |
9e062b6c RS |
3704 | staticpro (&seen_list); |
3705 | ||
7ee3bd7b GM |
3706 | Vloads_in_progress = Qnil; |
3707 | staticpro (&Vloads_in_progress); | |
078e7b4a | 3708 | } |