Commit | Line | Data |
---|---|---|
078e7b4a | 1 | /* Lisp parsing and input streams. |
039c6cc3 | 2 | |
ba318903 PE |
3 | Copyright (C) 1985-1989, 1993-1995, 1997-2014 Free Software Foundation, |
4 | Inc. | |
078e7b4a JB |
5 | |
6 | This file is part of GNU Emacs. | |
7 | ||
9ec0b715 | 8 | GNU Emacs is free software: you can redistribute it and/or modify |
078e7b4a | 9 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
078e7b4a JB |
12 | |
13 | GNU Emacs is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
078e7b4a JB |
20 | |
21 | ||
98280b76 | 22 | #include <config.h> |
406af475 | 23 | #include "sysstdio.h" |
078e7b4a JB |
24 | #include <sys/types.h> |
25 | #include <sys/stat.h> | |
26 | #include <sys/file.h> | |
2c1b5dbe | 27 | #include <errno.h> |
9660f5fc | 28 | #include <limits.h> /* For CHAR_BIT. */ |
39adff0d | 29 | #include <stat-time.h> |
078e7b4a | 30 | #include "lisp.h" |
95384e1e | 31 | #include "intervals.h" |
1571601b | 32 | #include "character.h" |
e5560ff7 | 33 | #include "buffer.h" |
fe0e03f3 | 34 | #include "charset.h" |
8792be66 | 35 | #include "coding.h" |
57bda87a | 36 | #include <epaths.h> |
078e7b4a | 37 | #include "commands.h" |
e37c0805 | 38 | #include "keyboard.h" |
428a555e | 39 | #include "frame.h" |
7bd279cd | 40 | #include "termhooks.h" |
66cd0949 | 41 | #include "blockinput.h" |
078e7b4a | 42 | |
79051982 | 43 | #ifdef MSDOS |
79051982 RS |
44 | #include "msdos.h" |
45 | #endif | |
46 | ||
9e059e3f GM |
47 | #ifdef HAVE_NS |
48 | #include "nsterm.h" | |
49 | #endif | |
50 | ||
c1a2f60a | 51 | #include <unistd.h> |
078e7b4a | 52 | |
c011e9a5 RS |
53 | #ifdef HAVE_SETLOCALE |
54 | #include <locale.h> | |
55 | #endif /* HAVE_SETLOCALE */ | |
56 | ||
bcdec28b | 57 | #include <fcntl.h> |
f7d279f0 | 58 | |
79cf851c | 59 | #ifdef HAVE_FSEEKO |
68c45bf0 PE |
60 | #define file_offset off_t |
61 | #define file_tell ftello | |
62 | #else | |
63 | #define file_offset long | |
64 | #define file_tell ftell | |
65 | #endif | |
66 | ||
d23d13c0 BT |
67 | static SCM obarrays; |
68 | ||
48def666 | 69 | /* Hash table read constants. */ |
955cbe7b PE |
70 | static Lisp_Object Qhash_table, Qdata; |
71 | static Lisp_Object Qtest, Qsize; | |
72 | static Lisp_Object Qweakness; | |
73 | static Lisp_Object Qrehash_size; | |
74 | static Lisp_Object Qrehash_threshold; | |
75 | ||
76 | static Lisp_Object Qread_char, Qget_file_char, Qcurrent_load_list; | |
77 | Lisp_Object Qstandard_input; | |
29208e82 | 78 | Lisp_Object Qvariable_documentation; |
955cbe7b | 79 | static Lisp_Object Qascii_character, Qload, Qload_file_name; |
2b6cae0c | 80 | Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction; |
955cbe7b PE |
81 | static Lisp_Object Qinhibit_file_name_operation; |
82 | static Lisp_Object Qeval_buffer_list; | |
8be3a09c | 83 | Lisp_Object Qlexical_binding; |
955cbe7b | 84 | static Lisp_Object Qfile_truename, Qdo_after_load_evaluation; /* ACM 2006/5/16 */ |
7bd279cd | 85 | |
8792be66 KH |
86 | /* Used instead of Qget_file_char while loading *.elc files compiled |
87 | by Emacs 21 or older. */ | |
88 | static Lisp_Object Qget_emacs_mule_file_char; | |
89 | ||
90 | static Lisp_Object Qload_force_doc_strings; | |
91 | ||
2baf5e76 | 92 | static Lisp_Object Qload_in_progress; |
ece435a5 | 93 | |
4ad679f9 EN |
94 | /* The association list of objects read with the #n=object form. |
95 | Each member of the list has the form (n . object), and is used to | |
96 | look up the object for the corresponding #n# construct. | |
97 | It must be set to nil before all top-level calls to read0. */ | |
1e3890d1 | 98 | static Lisp_Object read_objects; |
4ad679f9 | 99 | |
b2a30870 | 100 | /* File for get_file_char to read from. Use by load. */ |
078e7b4a JB |
101 | static FILE *instream; |
102 | ||
b2a30870 | 103 | /* For use within read-from-string (this reader is non-reentrant!!) */ |
d311d28c PE |
104 | static ptrdiff_t read_from_string_index; |
105 | static ptrdiff_t read_from_string_index_byte; | |
106 | static ptrdiff_t read_from_string_limit; | |
17634846 | 107 | |
abb13b09 | 108 | /* Number of characters read in the current call to Fread or |
48def666 | 109 | Fread_from_string. */ |
da43f021 | 110 | static EMACS_INT readchar_count; |
6f7f43d5 | 111 | |
c15cfd1f | 112 | /* This contains the last string skipped with #@. */ |
b2a30870 RS |
113 | static char *saved_doc_string; |
114 | /* Length of buffer allocated in saved_doc_string. */ | |
bfbbd7e7 | 115 | static ptrdiff_t saved_doc_string_size; |
b2a30870 | 116 | /* Length of actual data in saved_doc_string. */ |
bfbbd7e7 | 117 | static ptrdiff_t saved_doc_string_length; |
b2a30870 | 118 | /* This is the file position that string came from. */ |
68c45bf0 | 119 | static file_offset saved_doc_string_position; |
b2a30870 | 120 | |
c15cfd1f RS |
121 | /* This contains the previous string skipped with #@. |
122 | We copy it from saved_doc_string when a new string | |
123 | is put in saved_doc_string. */ | |
124 | static char *prev_saved_doc_string; | |
125 | /* Length of buffer allocated in prev_saved_doc_string. */ | |
bfbbd7e7 | 126 | static ptrdiff_t prev_saved_doc_string_size; |
c15cfd1f | 127 | /* Length of actual data in prev_saved_doc_string. */ |
bfbbd7e7 | 128 | static ptrdiff_t prev_saved_doc_string_length; |
c15cfd1f | 129 | /* This is the file position that string came from. */ |
68c45bf0 | 130 | static file_offset prev_saved_doc_string_position; |
c15cfd1f | 131 | |
7cded46f | 132 | /* True means inside a new-style backquote |
17634846 | 133 | with no surrounding parentheses. |
7cded46f | 134 | Fread initializes this to false, so we need not specbind it |
17634846 | 135 | or worry about what happens to it when there is an error. */ |
7cded46f | 136 | static bool new_backquote_flag; |
29208e82 | 137 | static Lisp_Object Qold_style_backquotes; |
7ee3bd7b GM |
138 | |
139 | /* A list of file names for files being loaded in Fload. Used to | |
140 | check for recursive loads. */ | |
141 | ||
9942fa0c | 142 | static Lisp_Object Vloads_in_progress; |
7ee3bd7b | 143 | |
f57e2426 J |
144 | static int read_emacs_mule_char (int, int (*) (int, Lisp_Object), |
145 | Lisp_Object); | |
8792be66 | 146 | |
7cded46f | 147 | static void readevalloop (Lisp_Object, FILE *, Lisp_Object, bool, |
f57e2426 J |
148 | Lisp_Object, Lisp_Object, |
149 | Lisp_Object, Lisp_Object); | |
078e7b4a | 150 | \f |
8792be66 KH |
151 | /* Functions that read one byte from the current source READCHARFUN |
152 | or unreads one byte. If the integer argument C is -1, it returns | |
153 | one read byte, or -1 when there's no more byte in the source. If C | |
154 | is 0 or positive, it unreads C, and the return value is not | |
155 | interesting. */ | |
156 | ||
f57e2426 J |
157 | static int readbyte_for_lambda (int, Lisp_Object); |
158 | static int readbyte_from_file (int, Lisp_Object); | |
159 | static int readbyte_from_string (int, Lisp_Object); | |
8792be66 | 160 | |
078e7b4a JB |
161 | /* Handle unreading and rereading of characters. |
162 | Write READCHAR to read a character, | |
fe0e03f3 KH |
163 | UNREAD(c) to unread c to be read again. |
164 | ||
8792be66 | 165 | These macros correctly read/unread multibyte characters. */ |
078e7b4a | 166 | |
1202434b | 167 | #define READCHAR readchar (readcharfun, NULL) |
078e7b4a JB |
168 | #define UNREAD(c) unreadchar (readcharfun, c) |
169 | ||
1202434b KH |
170 | /* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source. */ |
171 | #define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte) | |
172 | ||
8792be66 | 173 | /* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char, |
8f924df7 KH |
174 | Qlambda, or a cons, we use this to keep an unread character because |
175 | a file stream can't handle multibyte-char unreading. The value -1 | |
48def666 | 176 | means that there's no unread character. */ |
8792be66 KH |
177 | static int unread_char; |
178 | ||
078e7b4a | 179 | static int |
fce31d69 | 180 | readchar (Lisp_Object readcharfun, bool *multibyte) |
078e7b4a JB |
181 | { |
182 | Lisp_Object tem; | |
95384e1e | 183 | register int c; |
f57e2426 | 184 | int (*readbyte) (int, Lisp_Object); |
8792be66 KH |
185 | unsigned char buf[MAX_MULTIBYTE_LENGTH]; |
186 | int i, len; | |
7cded46f | 187 | bool emacs_mule_encoding = 0; |
078e7b4a | 188 | |
1202434b KH |
189 | if (multibyte) |
190 | *multibyte = 0; | |
191 | ||
abb13b09 | 192 | readchar_count++; |
177c0ea7 | 193 | |
cfff016d | 194 | if (BUFFERP (readcharfun)) |
078e7b4a | 195 | { |
bed23cb2 | 196 | register struct buffer *inbuffer = XBUFFER (readcharfun); |
078e7b4a | 197 | |
d311d28c | 198 | ptrdiff_t pt_byte = BUF_PT_BYTE (inbuffer); |
00a9a935 | 199 | |
15acfe41 GM |
200 | if (! BUFFER_LIVE_P (inbuffer)) |
201 | return -1; | |
202 | ||
bed23cb2 RS |
203 | if (pt_byte >= BUF_ZV_BYTE (inbuffer)) |
204 | return -1; | |
078e7b4a | 205 | |
4b4deea2 | 206 | if (! NILP (BVAR (inbuffer, enable_multibyte_characters))) |
bed23cb2 | 207 | { |
00a9a935 | 208 | /* Fetch the character code from the buffer. */ |
bed23cb2 RS |
209 | unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte); |
210 | BUF_INC_POS (inbuffer, pt_byte); | |
62a6e103 | 211 | c = STRING_CHAR (p); |
1202434b KH |
212 | if (multibyte) |
213 | *multibyte = 1; | |
bed23cb2 RS |
214 | } |
215 | else | |
216 | { | |
217 | c = BUF_FETCH_BYTE (inbuffer, pt_byte); | |
200fc949 | 218 | if (! ASCII_CHAR_P (c)) |
8792be66 | 219 | c = BYTE8_TO_CHAR (c); |
bed23cb2 | 220 | pt_byte++; |
6f7f43d5 | 221 | } |
bed23cb2 | 222 | SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte); |
6f7f43d5 | 223 | |
bed23cb2 | 224 | return c; |
078e7b4a | 225 | } |
cfff016d | 226 | if (MARKERP (readcharfun)) |
078e7b4a | 227 | { |
bed23cb2 | 228 | register struct buffer *inbuffer = XMARKER (readcharfun)->buffer; |
078e7b4a | 229 | |
d311d28c | 230 | ptrdiff_t bytepos = marker_byte_position (readcharfun); |
00a9a935 | 231 | |
bed23cb2 RS |
232 | if (bytepos >= BUF_ZV_BYTE (inbuffer)) |
233 | return -1; | |
6f7f43d5 | 234 | |
4b4deea2 | 235 | if (! NILP (BVAR (inbuffer, enable_multibyte_characters))) |
bed23cb2 | 236 | { |
00a9a935 | 237 | /* Fetch the character code from the buffer. */ |
bed23cb2 RS |
238 | unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos); |
239 | BUF_INC_POS (inbuffer, bytepos); | |
62a6e103 | 240 | c = STRING_CHAR (p); |
1202434b KH |
241 | if (multibyte) |
242 | *multibyte = 1; | |
bed23cb2 RS |
243 | } |
244 | else | |
245 | { | |
246 | c = BUF_FETCH_BYTE (inbuffer, bytepos); | |
200fc949 | 247 | if (! ASCII_CHAR_P (c)) |
8792be66 | 248 | c = BYTE8_TO_CHAR (c); |
bed23cb2 | 249 | bytepos++; |
6f7f43d5 RS |
250 | } |
251 | ||
bed23cb2 RS |
252 | XMARKER (readcharfun)->bytepos = bytepos; |
253 | XMARKER (readcharfun)->charpos++; | |
254 | ||
255 | return c; | |
078e7b4a | 256 | } |
ad0153e4 RS |
257 | |
258 | if (EQ (readcharfun, Qlambda)) | |
8792be66 KH |
259 | { |
260 | readbyte = readbyte_for_lambda; | |
261 | goto read_multibyte; | |
262 | } | |
ad0153e4 | 263 | |
078e7b4a | 264 | if (EQ (readcharfun, Qget_file_char)) |
2c1b5dbe | 265 | { |
8792be66 KH |
266 | readbyte = readbyte_from_file; |
267 | goto read_multibyte; | |
2c1b5dbe | 268 | } |
078e7b4a | 269 | |
cfff016d | 270 | if (STRINGP (readcharfun)) |
078e7b4a | 271 | { |
bed23cb2 | 272 | if (read_from_string_index >= read_from_string_limit) |
078e7b4a | 273 | c = -1; |
1202434b KH |
274 | else if (STRING_MULTIBYTE (readcharfun)) |
275 | { | |
276 | if (multibyte) | |
277 | *multibyte = 1; | |
278 | FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, readcharfun, | |
279 | read_from_string_index, | |
280 | read_from_string_index_byte); | |
281 | } | |
f0354c03 | 282 | else |
1202434b KH |
283 | { |
284 | c = SREF (readcharfun, read_from_string_index_byte); | |
285 | read_from_string_index++; | |
286 | read_from_string_index_byte++; | |
287 | } | |
078e7b4a JB |
288 | return c; |
289 | } | |
290 | ||
8792be66 KH |
291 | if (CONSP (readcharfun)) |
292 | { | |
293 | /* This is the case that read_vector is reading from a unibyte | |
294 | string that contains a byte sequence previously skipped | |
295 | because of #@NUMBER. The car part of readcharfun is that | |
296 | string, and the cdr part is a value of readcharfun given to | |
297 | read_vector. */ | |
298 | readbyte = readbyte_from_string; | |
299 | if (EQ (XCDR (readcharfun), Qget_emacs_mule_file_char)) | |
300 | emacs_mule_encoding = 1; | |
301 | goto read_multibyte; | |
302 | } | |
8f924df7 | 303 | |
8792be66 KH |
304 | if (EQ (readcharfun, Qget_emacs_mule_file_char)) |
305 | { | |
306 | readbyte = readbyte_from_file; | |
307 | emacs_mule_encoding = 1; | |
308 | goto read_multibyte; | |
309 | } | |
078e7b4a JB |
310 | |
311 | tem = call0 (readcharfun); | |
312 | ||
265a9e55 | 313 | if (NILP (tem)) |
078e7b4a JB |
314 | return -1; |
315 | return XINT (tem); | |
8792be66 KH |
316 | |
317 | read_multibyte: | |
318 | if (unread_char >= 0) | |
319 | { | |
320 | c = unread_char; | |
321 | unread_char = -1; | |
322 | return c; | |
323 | } | |
324 | c = (*readbyte) (-1, readcharfun); | |
75a65c7e | 325 | if (c < 0) |
1202434b KH |
326 | return c; |
327 | if (multibyte) | |
328 | *multibyte = 1; | |
200fc949 | 329 | if (ASCII_CHAR_P (c)) |
8792be66 KH |
330 | return c; |
331 | if (emacs_mule_encoding) | |
332 | return read_emacs_mule_char (c, readbyte, readcharfun); | |
333 | i = 0; | |
334 | buf[i++] = c; | |
335 | len = BYTES_BY_CHAR_HEAD (c); | |
336 | while (i < len) | |
337 | { | |
338 | c = (*readbyte) (-1, readcharfun); | |
339 | if (c < 0 || ! TRAILING_CODE_P (c)) | |
340 | { | |
341 | while (--i > 1) | |
342 | (*readbyte) (buf[i], readcharfun); | |
343 | return BYTE8_TO_CHAR (buf[0]); | |
344 | } | |
345 | buf[i++] = c; | |
346 | } | |
62a6e103 | 347 | return STRING_CHAR (buf); |
078e7b4a JB |
348 | } |
349 | ||
d2e24f92 SM |
350 | #define FROM_FILE_P(readcharfun) \ |
351 | (EQ (readcharfun, Qget_file_char) \ | |
352 | || EQ (readcharfun, Qget_emacs_mule_file_char)) | |
353 | ||
75a65c7e SM |
354 | static void |
355 | skip_dyn_bytes (Lisp_Object readcharfun, ptrdiff_t n) | |
356 | { | |
d2e24f92 | 357 | if (FROM_FILE_P (readcharfun)) |
75a65c7e SM |
358 | { |
359 | block_input (); /* FIXME: Not sure if it's needed. */ | |
360 | fseek (instream, n, SEEK_CUR); | |
361 | unblock_input (); | |
362 | } | |
363 | else | |
364 | { /* We're not reading directly from a file. In that case, it's difficult | |
365 | to reliably count bytes, since these are usually meant for the file's | |
366 | encoding, whereas we're now typically in the internal encoding. | |
367 | But luckily, skip_dyn_bytes is used to skip over a single | |
368 | dynamic-docstring (or dynamic byte-code) which is always quoted such | |
369 | that \037 is the final char. */ | |
370 | int c; | |
371 | do { | |
372 | c = READCHAR; | |
373 | } while (c >= 0 && c != '\037'); | |
374 | } | |
375 | } | |
376 | ||
759fd763 SM |
377 | static void |
378 | skip_dyn_eof (Lisp_Object readcharfun) | |
379 | { | |
380 | if (FROM_FILE_P (readcharfun)) | |
381 | { | |
382 | block_input (); /* FIXME: Not sure if it's needed. */ | |
383 | fseek (instream, 0, SEEK_END); | |
384 | unblock_input (); | |
385 | } | |
386 | else | |
387 | while (READCHAR >= 0); | |
388 | } | |
389 | ||
078e7b4a JB |
390 | /* Unread the character C in the way appropriate for the stream READCHARFUN. |
391 | If the stream is a user function, call it with the char as argument. */ | |
392 | ||
393 | static void | |
971de7fb | 394 | unreadchar (Lisp_Object readcharfun, int c) |
078e7b4a | 395 | { |
abb13b09 | 396 | readchar_count--; |
92fddec9 KH |
397 | if (c == -1) |
398 | /* Don't back up the pointer if we're unreading the end-of-input mark, | |
399 | since readchar didn't advance it when we read it. */ | |
400 | ; | |
cfff016d | 401 | else if (BUFFERP (readcharfun)) |
d7760ca9 | 402 | { |
bed23cb2 | 403 | struct buffer *b = XBUFFER (readcharfun); |
d311d28c PE |
404 | ptrdiff_t charpos = BUF_PT (b); |
405 | ptrdiff_t bytepos = BUF_PT_BYTE (b); | |
d7760ca9 | 406 | |
4b4deea2 | 407 | if (! NILP (BVAR (b, enable_multibyte_characters))) |
8792be66 | 408 | BUF_DEC_POS (b, bytepos); |
bed23cb2 | 409 | else |
8792be66 | 410 | bytepos--; |
d7760ca9 | 411 | |
cffc6f3b | 412 | SET_BUF_PT_BOTH (b, charpos - 1, bytepos); |
d7760ca9 | 413 | } |
cfff016d | 414 | else if (MARKERP (readcharfun)) |
d7760ca9 | 415 | { |
bed23cb2 | 416 | struct buffer *b = XMARKER (readcharfun)->buffer; |
d311d28c | 417 | ptrdiff_t bytepos = XMARKER (readcharfun)->bytepos; |
d7760ca9 | 418 | |
8792be66 | 419 | XMARKER (readcharfun)->charpos--; |
4b4deea2 | 420 | if (! NILP (BVAR (b, enable_multibyte_characters))) |
8792be66 | 421 | BUF_DEC_POS (b, bytepos); |
bed23cb2 | 422 | else |
8792be66 | 423 | bytepos--; |
d7760ca9 | 424 | |
8792be66 | 425 | XMARKER (readcharfun)->bytepos = bytepos; |
d7760ca9 | 426 | } |
cfff016d | 427 | else if (STRINGP (readcharfun)) |
bed23cb2 RS |
428 | { |
429 | read_from_string_index--; | |
430 | read_from_string_index_byte | |
431 | = string_char_to_byte (readcharfun, read_from_string_index); | |
432 | } | |
8792be66 KH |
433 | else if (CONSP (readcharfun)) |
434 | { | |
435 | unread_char = c; | |
436 | } | |
ad0153e4 | 437 | else if (EQ (readcharfun, Qlambda)) |
8792be66 KH |
438 | { |
439 | unread_char = c; | |
440 | } | |
d2e24f92 | 441 | else if (FROM_FILE_P (readcharfun)) |
8792be66 | 442 | { |
75a65c7e | 443 | unread_char = c; |
8792be66 | 444 | } |
078e7b4a JB |
445 | else |
446 | call1 (readcharfun, make_number (c)); | |
447 | } | |
448 | ||
8792be66 | 449 | static int |
971de7fb | 450 | readbyte_for_lambda (int c, Lisp_Object readcharfun) |
8792be66 KH |
451 | { |
452 | return read_bytecode_char (c >= 0); | |
453 | } | |
454 | ||
455 | ||
456 | static int | |
971de7fb | 457 | readbyte_from_file (int c, Lisp_Object readcharfun) |
8792be66 KH |
458 | { |
459 | if (c >= 0) | |
460 | { | |
4d7e6e51 | 461 | block_input (); |
8792be66 | 462 | ungetc (c, instream); |
4d7e6e51 | 463 | unblock_input (); |
8792be66 KH |
464 | return 0; |
465 | } | |
466 | ||
4d7e6e51 | 467 | block_input (); |
8792be66 | 468 | c = getc (instream); |
d85d3839 | 469 | |
48def666 | 470 | /* Interrupted reads have been observed while reading over the network. */ |
d85d3839 MB |
471 | while (c == EOF && ferror (instream) && errno == EINTR) |
472 | { | |
4d7e6e51 | 473 | unblock_input (); |
d85d3839 | 474 | QUIT; |
4d7e6e51 | 475 | block_input (); |
57cb2e6f | 476 | clearerr (instream); |
d85d3839 | 477 | c = getc (instream); |
66cd0949 | 478 | } |
d85d3839 | 479 | |
4d7e6e51 | 480 | unblock_input (); |
57cb2e6f | 481 | |
8792be66 KH |
482 | return (c == EOF ? -1 : c); |
483 | } | |
484 | ||
485 | static int | |
971de7fb | 486 | readbyte_from_string (int c, Lisp_Object readcharfun) |
8792be66 KH |
487 | { |
488 | Lisp_Object string = XCAR (readcharfun); | |
489 | ||
490 | if (c >= 0) | |
491 | { | |
492 | read_from_string_index--; | |
493 | read_from_string_index_byte | |
494 | = string_char_to_byte (string, read_from_string_index); | |
495 | } | |
8f924df7 | 496 | |
8792be66 KH |
497 | if (read_from_string_index >= read_from_string_limit) |
498 | c = -1; | |
499 | else | |
500 | FETCH_STRING_CHAR_ADVANCE (c, string, | |
501 | read_from_string_index, | |
502 | read_from_string_index_byte); | |
503 | return c; | |
504 | } | |
505 | ||
506 | ||
507 | /* Read one non-ASCII character from INSTREAM. The character is | |
508 | encoded in `emacs-mule' and the first byte is already read in | |
509 | C. */ | |
510 | ||
8792be66 | 511 | static int |
971de7fb | 512 | read_emacs_mule_char (int c, int (*readbyte) (int, Lisp_Object), Lisp_Object readcharfun) |
8792be66 KH |
513 | { |
514 | /* Emacs-mule coding uses at most 4-byte for one character. */ | |
515 | unsigned char buf[4]; | |
516 | int len = emacs_mule_bytes[c]; | |
517 | struct charset *charset; | |
518 | int i; | |
519 | unsigned code; | |
520 | ||
521 | if (len == 1) | |
522 | /* C is not a valid leading-code of `emacs-mule'. */ | |
523 | return BYTE8_TO_CHAR (c); | |
524 | ||
525 | i = 0; | |
526 | buf[i++] = c; | |
527 | while (i < len) | |
528 | { | |
529 | c = (*readbyte) (-1, readcharfun); | |
530 | if (c < 0xA0) | |
531 | { | |
532 | while (--i > 1) | |
533 | (*readbyte) (buf[i], readcharfun); | |
534 | return BYTE8_TO_CHAR (buf[0]); | |
535 | } | |
536 | buf[i++] = c; | |
537 | } | |
538 | ||
539 | if (len == 2) | |
540 | { | |
b84ae584 | 541 | charset = CHARSET_FROM_ID (emacs_mule_charset[buf[0]]); |
8792be66 KH |
542 | code = buf[1] & 0x7F; |
543 | } | |
544 | else if (len == 3) | |
545 | { | |
546 | if (buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_11 | |
547 | || buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_12) | |
548 | { | |
b84ae584 | 549 | charset = CHARSET_FROM_ID (emacs_mule_charset[buf[1]]); |
8792be66 KH |
550 | code = buf[2] & 0x7F; |
551 | } | |
552 | else | |
553 | { | |
b84ae584 | 554 | charset = CHARSET_FROM_ID (emacs_mule_charset[buf[0]]); |
8792be66 KH |
555 | code = ((buf[1] << 8) | buf[2]) & 0x7F7F; |
556 | } | |
557 | } | |
558 | else | |
559 | { | |
b84ae584 | 560 | charset = CHARSET_FROM_ID (emacs_mule_charset[buf[1]]); |
8f924df7 | 561 | code = ((buf[2] << 8) | buf[3]) & 0x7F7F; |
8792be66 KH |
562 | } |
563 | c = DECODE_CHAR (charset, code); | |
564 | if (c < 0) | |
565 | Fsignal (Qinvalid_read_syntax, | |
6c6f1994 | 566 | list1 (build_string ("invalid multibyte form"))); |
8792be66 KH |
567 | return c; |
568 | } | |
569 | ||
570 | ||
f57e2426 J |
571 | static Lisp_Object read_internal_start (Lisp_Object, Lisp_Object, |
572 | Lisp_Object); | |
573 | static Lisp_Object read0 (Lisp_Object); | |
7cded46f | 574 | static Lisp_Object read1 (Lisp_Object, int *, bool); |
abb13b09 | 575 | |
7cded46f PE |
576 | static Lisp_Object read_list (bool, Lisp_Object); |
577 | static Lisp_Object read_vector (Lisp_Object, bool); | |
abb13b09 | 578 | |
f57e2426 J |
579 | static Lisp_Object substitute_object_recurse (Lisp_Object, Lisp_Object, |
580 | Lisp_Object); | |
581 | static void substitute_object_in_subtree (Lisp_Object, | |
582 | Lisp_Object); | |
583 | static void substitute_in_interval (INTERVAL, Lisp_Object); | |
9e062b6c | 584 | |
078e7b4a | 585 | \f |
bed23cb2 | 586 | /* Get a character from the tty. */ |
078e7b4a | 587 | |
f42be754 JB |
588 | /* Read input events until we get one that's acceptable for our purposes. |
589 | ||
7cded46f | 590 | If NO_SWITCH_FRAME, switch-frame events are stashed |
f42be754 JB |
591 | until we get a character we like, and then stuffed into |
592 | unread_switch_frame. | |
593 | ||
7cded46f | 594 | If ASCII_REQUIRED, check function key events to see |
f42be754 JB |
595 | if the unmodified version of the symbol has a Qascii_character |
596 | property, and use that character, if present. | |
597 | ||
7cded46f PE |
598 | If ERROR_NONASCII, signal an error if the input we |
599 | get isn't an ASCII character with modifiers. If it's false but | |
600 | ASCII_REQUIRED is true, just re-read until we get an ASCII | |
bb49a192 RS |
601 | character. |
602 | ||
7cded46f | 603 | If INPUT_METHOD, invoke the current input method |
50e48299 CY |
604 | if the character warrants that. |
605 | ||
7cded46f | 606 | If SECONDS is a number, wait that many seconds for input, and |
50e48299 | 607 | return Qnil if no input arrives within that time. */ |
cc39bc38 | 608 | |
2f7c71a1 | 609 | static Lisp_Object |
7cded46f PE |
610 | read_filtered_event (bool no_switch_frame, bool ascii_required, |
611 | bool error_nonascii, bool input_method, Lisp_Object seconds) | |
f42be754 | 612 | { |
4332cf50 | 613 | Lisp_Object val, delayed_switch_frame; |
43aac990 | 614 | struct timespec end_time; |
153a17b7 | 615 | |
5dbf89bc | 616 | #ifdef HAVE_WINDOW_SYSTEM |
df6c90d8 GM |
617 | if (display_hourglass_p) |
618 | cancel_hourglass (); | |
5dbf89bc | 619 | #endif |
177c0ea7 | 620 | |
153a17b7 | 621 | delayed_switch_frame = Qnil; |
f42be754 | 622 | |
50e48299 CY |
623 | /* Compute timeout. */ |
624 | if (NUMBERP (seconds)) | |
625 | { | |
51d8b30e | 626 | double duration = extract_float (seconds); |
43aac990 PE |
627 | struct timespec wait_time = dtotimespec (duration); |
628 | end_time = timespec_add (current_timespec (), wait_time); | |
50e48299 CY |
629 | } |
630 | ||
99d0d6dc | 631 | /* Read until we get an acceptable event. */ |
f42be754 | 632 | retry: |
88852d45 | 633 | do |
99d0d6dc | 634 | val = read_char (0, Qnil, (input_method ? Qnil : Qt), 0, |
251bc578 | 635 | NUMBERP (seconds) ? &end_time : NULL); |
9688ff53 | 636 | while (INTEGERP (val) && XINT (val) == -2); /* wrong_kboard_jmpbuf */ |
f42be754 | 637 | |
cfff016d | 638 | if (BUFFERP (val)) |
6c82d689 KH |
639 | goto retry; |
640 | ||
99d0d6dc | 641 | /* `switch-frame' events are put off until after the next ASCII |
8e6208c5 | 642 | character. This is better than signaling an error just because |
f42be754 JB |
643 | the last characters were typed to a separate minibuffer frame, |
644 | for example. Eventually, some code which can deal with | |
645 | switch-frame events will read it and process it. */ | |
646 | if (no_switch_frame | |
647 | && EVENT_HAS_PARAMETERS (val) | |
ca77ee45 | 648 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (val)), Qswitch_frame)) |
f42be754 JB |
649 | { |
650 | delayed_switch_frame = val; | |
651 | goto retry; | |
652 | } | |
653 | ||
50e48299 | 654 | if (ascii_required && !(NUMBERP (seconds) && NILP (val))) |
f42be754 JB |
655 | { |
656 | /* Convert certain symbols to their ASCII equivalents. */ | |
cfff016d | 657 | if (SYMBOLP (val)) |
f42be754 | 658 | { |
95384e1e | 659 | Lisp_Object tem, tem1; |
f42be754 JB |
660 | tem = Fget (val, Qevent_symbol_element_mask); |
661 | if (!NILP (tem)) | |
662 | { | |
663 | tem1 = Fget (Fcar (tem), Qascii_character); | |
664 | /* Merge this symbol's modifier bits | |
665 | with the ASCII equivalent of its basic code. */ | |
666 | if (!NILP (tem1)) | |
baf69866 | 667 | XSETFASTINT (val, XINT (tem1) | XINT (Fcar (Fcdr (tem)))); |
f42be754 JB |
668 | } |
669 | } | |
177c0ea7 | 670 | |
f42be754 | 671 | /* If we don't have a character now, deal with it appropriately. */ |
cfff016d | 672 | if (!INTEGERP (val)) |
f42be754 JB |
673 | { |
674 | if (error_nonascii) | |
675 | { | |
6c6f1994 | 676 | Vunread_command_events = list1 (val); |
f42be754 JB |
677 | error ("Non-character input-event"); |
678 | } | |
679 | else | |
680 | goto retry; | |
681 | } | |
682 | } | |
683 | ||
684 | if (! NILP (delayed_switch_frame)) | |
685 | unread_switch_frame = delayed_switch_frame; | |
686 | ||
67868d27 PJ |
687 | #if 0 |
688 | ||
5dbf89bc | 689 | #ifdef HAVE_WINDOW_SYSTEM |
df6c90d8 GM |
690 | if (display_hourglass_p) |
691 | start_hourglass (); | |
5dbf89bc | 692 | #endif |
67868d27 PJ |
693 | |
694 | #endif | |
695 | ||
f42be754 | 696 | return val; |
f42be754 JB |
697 | } |
698 | ||
a7ca3326 | 699 | DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0, |
5de38842 PJ |
700 | doc: /* Read a character from the command input (keyboard or macro). |
701 | It is returned as a number. | |
fb26c2af KH |
702 | If the character has modifiers, they are resolved and reflected to the |
703 | character code if possible (e.g. C-SPC -> 0). | |
704 | ||
5de38842 PJ |
705 | If the user generates an event which is not a character (i.e. a mouse |
706 | click or function key event), `read-char' signals an error. As an | |
fb26c2af KH |
707 | exception, switch-frame events are put off until non-character events |
708 | can be read. | |
5de38842 PJ |
709 | If you want to read non-character events, or ignore them, call |
710 | `read-event' or `read-char-exclusive' instead. | |
711 | ||
712 | If the optional argument PROMPT is non-nil, display that as a prompt. | |
713 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | |
714 | input method is turned on in the current buffer, that input method | |
50e48299 CY |
715 | is used for reading a character. |
716 | If the optional argument SECONDS is non-nil, it should be a number | |
717 | specifying the maximum number of seconds to wait for input. If no | |
718 | input arrives in that time, return nil. SECONDS may be a | |
719 | floating-point value. */) | |
5842a27b | 720 | (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) |
078e7b4a | 721 | { |
fb26c2af | 722 | Lisp_Object val; |
fb26c2af | 723 | |
bb49a192 RS |
724 | if (! NILP (prompt)) |
725 | message_with_string ("%s", prompt, 0); | |
fb26c2af | 726 | val = read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds); |
66c410ce CY |
727 | |
728 | return (NILP (val) ? Qnil | |
729 | : make_number (char_resolve_modifier_mask (XINT (val)))); | |
078e7b4a JB |
730 | } |
731 | ||
a7ca3326 | 732 | DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0, |
5de38842 PJ |
733 | doc: /* Read an event object from the input stream. |
734 | If the optional argument PROMPT is non-nil, display that as a prompt. | |
735 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | |
736 | input method is turned on in the current buffer, that input method | |
50e48299 CY |
737 | is used for reading a character. |
738 | If the optional argument SECONDS is non-nil, it should be a number | |
739 | specifying the maximum number of seconds to wait for input. If no | |
740 | input arrives in that time, return nil. SECONDS may be a | |
741 | floating-point value. */) | |
5842a27b | 742 | (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) |
078e7b4a | 743 | { |
bb49a192 RS |
744 | if (! NILP (prompt)) |
745 | message_with_string ("%s", prompt, 0); | |
50e48299 | 746 | return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method), seconds); |
078e7b4a JB |
747 | } |
748 | ||
50e48299 | 749 | DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 3, 0, |
5de38842 PJ |
750 | doc: /* Read a character from the command input (keyboard or macro). |
751 | It is returned as a number. Non-character events are ignored. | |
fb26c2af KH |
752 | If the character has modifiers, they are resolved and reflected to the |
753 | character code if possible (e.g. C-SPC -> 0). | |
5de38842 PJ |
754 | |
755 | If the optional argument PROMPT is non-nil, display that as a prompt. | |
756 | If the optional argument INHERIT-INPUT-METHOD is non-nil and some | |
757 | input method is turned on in the current buffer, that input method | |
50e48299 CY |
758 | is used for reading a character. |
759 | If the optional argument SECONDS is non-nil, it should be a number | |
760 | specifying the maximum number of seconds to wait for input. If no | |
761 | input arrives in that time, return nil. SECONDS may be a | |
762 | floating-point value. */) | |
5842a27b | 763 | (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) |
078e7b4a | 764 | { |
fb26c2af | 765 | Lisp_Object val; |
fb26c2af | 766 | |
bb49a192 RS |
767 | if (! NILP (prompt)) |
768 | message_with_string ("%s", prompt, 0); | |
66c410ce | 769 | |
fb26c2af | 770 | val = read_filtered_event (1, 1, 0, ! NILP (inherit_input_method), seconds); |
66c410ce CY |
771 | |
772 | return (NILP (val) ? Qnil | |
773 | : make_number (char_resolve_modifier_mask (XINT (val)))); | |
078e7b4a | 774 | } |
078e7b4a JB |
775 | |
776 | DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0, | |
5de38842 | 777 | doc: /* Don't use this yourself. */) |
5842a27b | 778 | (void) |
078e7b4a JB |
779 | { |
780 | register Lisp_Object val; | |
4d7e6e51 | 781 | block_input (); |
1805de4f | 782 | XSETINT (val, getc (instream)); |
4d7e6e51 | 783 | unblock_input (); |
078e7b4a JB |
784 | return val; |
785 | } | |
da84f340 GM |
786 | |
787 | ||
550a625e | 788 | \f |
b9598260 SM |
789 | |
790 | /* Return true if the lisp code read using READCHARFUN defines a non-nil | |
791 | `lexical-binding' file variable. After returning, the stream is | |
757140ff GM |
792 | positioned following the first line, if it is a comment or #! line, |
793 | otherwise nothing is read. */ | |
b9598260 | 794 | |
7cded46f | 795 | static bool |
c566235d | 796 | lisp_file_lexically_bound_p (Lisp_Object readcharfun) |
b9598260 SM |
797 | { |
798 | int ch = READCHAR; | |
757140ff GM |
799 | |
800 | if (ch == '#') | |
801 | { | |
802 | ch = READCHAR; | |
803 | if (ch != '!') | |
804 | { | |
805 | UNREAD (ch); | |
806 | UNREAD ('#'); | |
807 | return 0; | |
808 | } | |
809 | while (ch != '\n' && ch != EOF) | |
810 | ch = READCHAR; | |
811 | if (ch == '\n') ch = READCHAR; | |
d2dd3694 GM |
812 | /* It is OK to leave the position after a #! line, since |
813 | that is what read1 does. */ | |
757140ff GM |
814 | } |
815 | ||
b9598260 SM |
816 | if (ch != ';') |
817 | /* The first line isn't a comment, just give up. */ | |
818 | { | |
819 | UNREAD (ch); | |
820 | return 0; | |
821 | } | |
822 | else | |
823 | /* Look for an appropriate file-variable in the first line. */ | |
824 | { | |
7cded46f | 825 | bool rv = 0; |
b9598260 | 826 | enum { |
29abe551 | 827 | NOMINAL, AFTER_FIRST_DASH, AFTER_ASTERIX |
b9598260 | 828 | } beg_end_state = NOMINAL; |
7cded46f | 829 | bool in_file_vars = 0; |
b9598260 | 830 | |
7200d79c SM |
831 | #define UPDATE_BEG_END_STATE(ch) \ |
832 | if (beg_end_state == NOMINAL) \ | |
833 | beg_end_state = (ch == '-' ? AFTER_FIRST_DASH : NOMINAL); \ | |
834 | else if (beg_end_state == AFTER_FIRST_DASH) \ | |
835 | beg_end_state = (ch == '*' ? AFTER_ASTERIX : NOMINAL); \ | |
836 | else if (beg_end_state == AFTER_ASTERIX) \ | |
837 | { \ | |
838 | if (ch == '-') \ | |
839 | in_file_vars = !in_file_vars; \ | |
840 | beg_end_state = NOMINAL; \ | |
b9598260 SM |
841 | } |
842 | ||
843 | /* Skip until we get to the file vars, if any. */ | |
844 | do | |
845 | { | |
846 | ch = READCHAR; | |
847 | UPDATE_BEG_END_STATE (ch); | |
848 | } | |
849 | while (!in_file_vars && ch != '\n' && ch != EOF); | |
850 | ||
851 | while (in_file_vars) | |
852 | { | |
06a0259a | 853 | char var[100], val[100]; |
3c346cc3 | 854 | unsigned i; |
b9598260 SM |
855 | |
856 | ch = READCHAR; | |
857 | ||
858 | /* Read a variable name. */ | |
859 | while (ch == ' ' || ch == '\t') | |
860 | ch = READCHAR; | |
861 | ||
06a0259a | 862 | i = 0; |
db7a0b4f | 863 | while (ch != ':' && ch != '\n' && ch != EOF && in_file_vars) |
b9598260 | 864 | { |
06a0259a PE |
865 | if (i < sizeof var - 1) |
866 | var[i++] = ch; | |
b9598260 SM |
867 | UPDATE_BEG_END_STATE (ch); |
868 | ch = READCHAR; | |
869 | } | |
7200d79c | 870 | |
db7a0b4f | 871 | /* Stop scanning if no colon was found before end marker. */ |
ad3a2b41 | 872 | if (!in_file_vars || ch == '\n' || ch == EOF) |
db7a0b4f AS |
873 | break; |
874 | ||
06a0259a PE |
875 | while (i > 0 && (var[i - 1] == ' ' || var[i - 1] == '\t')) |
876 | i--; | |
877 | var[i] = '\0'; | |
b9598260 SM |
878 | |
879 | if (ch == ':') | |
880 | { | |
881 | /* Read a variable value. */ | |
882 | ch = READCHAR; | |
883 | ||
884 | while (ch == ' ' || ch == '\t') | |
885 | ch = READCHAR; | |
886 | ||
06a0259a | 887 | i = 0; |
b9598260 SM |
888 | while (ch != ';' && ch != '\n' && ch != EOF && in_file_vars) |
889 | { | |
06a0259a PE |
890 | if (i < sizeof val - 1) |
891 | val[i++] = ch; | |
b9598260 SM |
892 | UPDATE_BEG_END_STATE (ch); |
893 | ch = READCHAR; | |
894 | } | |
895 | if (! in_file_vars) | |
ad3a2b41 | 896 | /* The value was terminated by an end-marker, which remove. */ |
06a0259a PE |
897 | i -= 3; |
898 | while (i > 0 && (val[i - 1] == ' ' || val[i - 1] == '\t')) | |
899 | i--; | |
900 | val[i] = '\0'; | |
b9598260 SM |
901 | |
902 | if (strcmp (var, "lexical-binding") == 0) | |
903 | /* This is it... */ | |
904 | { | |
905 | rv = (strcmp (val, "nil") != 0); | |
906 | break; | |
907 | } | |
908 | } | |
909 | } | |
910 | ||
911 | while (ch != '\n' && ch != EOF) | |
912 | ch = READCHAR; | |
913 | ||
914 | return rv; | |
915 | } | |
916 | } | |
b9598260 | 917 | \f |
8792be66 | 918 | /* Value is a version number of byte compiled code if the file |
c73bd236 | 919 | associated with file descriptor FD is a compiled Lisp file that's |
8792be66 KH |
920 | safe to load. Only files compiled with Emacs are safe to load. |
921 | Files compiled with XEmacs can lead to a crash in Fbyte_code | |
922 | because of an incompatible change in the byte compiler. */ | |
da84f340 GM |
923 | |
924 | static int | |
7cded46f | 925 | safe_to_load_version (int fd) |
da84f340 GM |
926 | { |
927 | char buf[512]; | |
928 | int nbytes, i; | |
8f924df7 | 929 | int version = 1; |
da84f340 GM |
930 | |
931 | /* Read the first few bytes from the file, and look for a line | |
932 | specifying the byte compiler version used. */ | |
7cded46f | 933 | nbytes = emacs_read (fd, buf, sizeof buf); |
da84f340 GM |
934 | if (nbytes > 0) |
935 | { | |
da84f340 | 936 | /* Skip to the next newline, skipping over the initial `ELC' |
1da3b9e4 | 937 | with NUL bytes following it, but note the version. */ |
da84f340 | 938 | for (i = 0; i < nbytes && buf[i] != '\n'; ++i) |
1da3b9e4 | 939 | if (i == 4) |
8792be66 | 940 | version = buf[i]; |
da84f340 | 941 | |
e6eb4e9e | 942 | if (i >= nbytes |
927f12da | 943 | || fast_c_string_match_ignore_case (Vbytecomp_version_regexp, |
d923b542 | 944 | buf + i, nbytes - i) < 0) |
7cded46f | 945 | version = 0; |
da84f340 GM |
946 | } |
947 | ||
948 | lseek (fd, 0, SEEK_SET); | |
7cded46f | 949 | return version; |
da84f340 GM |
950 | } |
951 | ||
952 | ||
7ee3bd7b GM |
953 | /* Callback for record_unwind_protect. Restore the old load list OLD, |
954 | after loading a file successfully. */ | |
955 | ||
27e498e6 | 956 | static void |
971de7fb | 957 | record_load_unwind (Lisp_Object old) |
7ee3bd7b | 958 | { |
27e498e6 | 959 | Vloads_in_progress = old; |
7ee3bd7b GM |
960 | } |
961 | ||
164c8bfe RS |
962 | /* This handler function is used via internal_condition_case_1. */ |
963 | ||
964 | static Lisp_Object | |
971de7fb | 965 | load_error_handler (Lisp_Object data) |
164c8bfe RS |
966 | { |
967 | return Qnil; | |
968 | } | |
7ee3bd7b | 969 | |
27e498e6 | 970 | static void |
971de7fb | 971 | load_warn_old_style_backquotes (Lisp_Object file) |
1d064697 SM |
972 | { |
973 | if (!NILP (Vold_style_backquotes)) | |
974 | { | |
b636b4c1 | 975 | Lisp_Object args[2]; |
18a4a65e | 976 | args[0] = build_string ("Loading `%s': old-style backquotes detected!"); |
1d064697 SM |
977 | args[1] = file; |
978 | Fmessage (2, args); | |
979 | } | |
1d064697 SM |
980 | } |
981 | ||
a7ca3326 | 982 | DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0, |
971a4293 LT |
983 | doc: /* Return the suffixes that `load' should try if a suffix is \ |
984 | required. | |
985 | This uses the variables `load-suffixes' and `load-file-rep-suffixes'. */) | |
5842a27b | 986 | (void) |
971a4293 LT |
987 | { |
988 | Lisp_Object lst = Qnil, suffixes = Vload_suffixes, suffix, ext; | |
989 | while (CONSP (suffixes)) | |
990 | { | |
991 | Lisp_Object exts = Vload_file_rep_suffixes; | |
992 | suffix = XCAR (suffixes); | |
993 | suffixes = XCDR (suffixes); | |
994 | while (CONSP (exts)) | |
995 | { | |
996 | ext = XCAR (exts); | |
997 | exts = XCDR (exts); | |
998 | lst = Fcons (concat2 (suffix, ext), lst); | |
999 | } | |
1000 | } | |
1001 | return Fnreverse (lst); | |
1002 | } | |
1003 | ||
a7ca3326 | 1004 | DEFUN ("load", Fload, Sload, 1, 5, 0, |
5de38842 PJ |
1005 | doc: /* Execute a file of Lisp code named FILE. |
1006 | First try FILE with `.elc' appended, then try with `.el', | |
971a4293 | 1007 | then try FILE unmodified (the exact suffixes in the exact order are |
88852d45 | 1008 | determined by `load-suffixes'). Environment variable references in |
971a4293 | 1009 | FILE are replaced with their values by calling `substitute-in-file-name'. |
5de38842 | 1010 | This function searches the directories in `load-path'. |
971a4293 | 1011 | |
5de38842 | 1012 | If optional second arg NOERROR is non-nil, |
971a4293 | 1013 | report no error if FILE doesn't exist. |
5de38842 | 1014 | Print messages at start and end of loading unless |
beb0b7f9 EZ |
1015 | optional third arg NOMESSAGE is non-nil (but `force-load-messages' |
1016 | overrides that). | |
5de38842 | 1017 | If optional fourth arg NOSUFFIX is non-nil, don't try adding |
971a4293 | 1018 | suffixes `.elc' or `.el' to the specified name FILE. |
5de38842 | 1019 | If optional fifth arg MUST-SUFFIX is non-nil, insist on |
971a4293 LT |
1020 | the suffix `.elc' or `.el'; don't accept just FILE unless |
1021 | it ends in one of those suffixes or includes a directory name. | |
1022 | ||
c664f463 CY |
1023 | If NOSUFFIX is nil, then if a file could not be found, try looking for |
1024 | a different representation of the file by adding non-empty suffixes to | |
1025 | its name, before trying another file. Emacs uses this feature to find | |
1026 | compressed versions of files when Auto Compression mode is enabled. | |
1027 | If NOSUFFIX is non-nil, disable this feature. | |
1028 | ||
1029 | The suffixes that this function tries out, when NOSUFFIX is nil, are | |
1030 | given by the return value of `get-load-suffixes' and the values listed | |
1031 | in `load-file-rep-suffixes'. If MUST-SUFFIX is non-nil, only the | |
1032 | return value of `get-load-suffixes' is used, i.e. the file name is | |
1033 | required to have a non-empty suffix. | |
0fc213e9 | 1034 | |
aec3bf9f GM |
1035 | When searching suffixes, this function normally stops at the first |
1036 | one that exists. If the option `load-prefer-newer' is non-nil, | |
1037 | however, it tries all suffixes, and uses whichever file is the newest. | |
1038 | ||
0fc213e9 RS |
1039 | Loading a file records its definitions, and its `provide' and |
1040 | `require' calls, in an element of `load-history' whose | |
1041 | car is the file name loaded. See `load-history'. | |
1042 | ||
c7926fe2 EZ |
1043 | While the file is in the process of being loaded, the variable |
1044 | `load-in-progress' is non-nil and the variable `load-file-name' | |
1045 | is bound to the file's name. | |
1046 | ||
971a4293 | 1047 | Return t if the file exists and loads successfully. */) |
a0931322 PE |
1048 | (Lisp_Object file, Lisp_Object noerror, Lisp_Object nomessage, |
1049 | Lisp_Object nosuffix, Lisp_Object must_suffix) | |
078e7b4a | 1050 | { |
5d1922cd | 1051 | FILE *stream = NULL; |
a0931322 | 1052 | int fd; |
2bfa3d3e | 1053 | dynwind_begin (); |
6bb6da3e AM |
1054 | struct gcpro gcpro1, gcpro2, gcpro3; |
1055 | Lisp_Object found, efound, hist_file_name; | |
7cded46f PE |
1056 | /* True means we printed the ".el is newer" message. */ |
1057 | bool newer = 0; | |
1058 | /* True means we are loading a compiled file. */ | |
1059 | bool compiled = 0; | |
c2225d00 | 1060 | Lisp_Object handler; |
7cded46f | 1061 | bool safe_p = 1; |
8ea90aa3 | 1062 | const char *fmode = "r"; |
8792be66 KH |
1063 | int version; |
1064 | ||
317073d5 | 1065 | #ifdef DOS_NT |
229ba775 | 1066 | fmode = "rt"; |
317073d5 | 1067 | #endif /* DOS_NT */ |
078e7b4a | 1068 | |
b7826503 | 1069 | CHECK_STRING (file); |
078e7b4a | 1070 | |
c2225d00 | 1071 | /* If file name is magic, call the handler. */ |
e61b9b87 SM |
1072 | /* This shouldn't be necessary any more now that `openp' handles it right. |
1073 | handler = Ffind_file_name_handler (file, Qload); | |
1074 | if (!NILP (handler)) | |
1075 | return call5 (handler, Qload, file, noerror, nomessage, nosuffix); */ | |
c2225d00 | 1076 | |
07a0bda3 RS |
1077 | /* Do this after the handler to avoid |
1078 | the need to gcpro noerror, nomessage and nosuffix. | |
e61b9b87 SM |
1079 | (Below here, we care only whether they are nil or not.) |
1080 | The presence of this call is the result of a historical accident: | |
6bb6da3e | 1081 | it used to be in every file-operation and when it got removed |
e61b9b87 SM |
1082 | everywhere, it accidentally stayed here. Since then, enough people |
1083 | supposedly have things like (load "$PROJECT/foo.el") in their .emacs | |
1084 | that it seemed risky to remove. */ | |
164c8bfe RS |
1085 | if (! NILP (noerror)) |
1086 | { | |
1087 | file = internal_condition_case_1 (Fsubstitute_in_file_name, file, | |
1088 | Qt, load_error_handler); | |
2bfa3d3e BT |
1089 | if (NILP (file)) { |
1090 | dynwind_end (); | |
1091 | return Qnil; | |
1092 | } | |
164c8bfe RS |
1093 | } |
1094 | else | |
1095 | file = Fsubstitute_in_file_name (file); | |
177c0ea7 | 1096 | |
078e7b4a | 1097 | /* Avoid weird lossage with null string as arg, |
48def666 | 1098 | since it would try to load a directory as a Lisp file. */ |
a0931322 | 1099 | if (SCHARS (file) == 0) |
078e7b4a | 1100 | { |
a0931322 PE |
1101 | fd = -1; |
1102 | errno = ENOENT; | |
1103 | } | |
1104 | else | |
1105 | { | |
1106 | Lisp_Object suffixes; | |
0fc213e9 RS |
1107 | found = Qnil; |
1108 | GCPRO2 (file, found); | |
211f7dcd RS |
1109 | |
1110 | if (! NILP (must_suffix)) | |
1111 | { | |
1112 | /* Don't insist on adding a suffix if FILE already ends with one. */ | |
a0931322 | 1113 | ptrdiff_t size = SBYTES (file); |
211f7dcd | 1114 | if (size > 3 |
42a5b22f | 1115 | && !strcmp (SSDATA (file) + size - 3, ".el")) |
211f7dcd RS |
1116 | must_suffix = Qnil; |
1117 | else if (size > 4 | |
42a5b22f | 1118 | && !strcmp (SSDATA (file) + size - 4, ".elc")) |
211f7dcd RS |
1119 | must_suffix = Qnil; |
1120 | /* Don't insist on adding a suffix | |
1121 | if the argument includes a directory name. */ | |
1122 | else if (! NILP (Ffile_name_directory (file))) | |
1123 | must_suffix = Qnil; | |
1124 | } | |
1125 | ||
a0931322 PE |
1126 | if (!NILP (nosuffix)) |
1127 | suffixes = Qnil; | |
1128 | else | |
1129 | { | |
1130 | suffixes = Fget_load_suffixes (); | |
1131 | if (NILP (must_suffix)) | |
1132 | { | |
1133 | Lisp_Object arg[2]; | |
1134 | arg[0] = suffixes; | |
1135 | arg[1] = Vload_file_rep_suffixes; | |
1136 | suffixes = Fappend (2, arg); | |
1137 | } | |
1138 | } | |
1139 | ||
1f41ee56 | 1140 | fd = openp (Vload_path, file, suffixes, &found, Qnil, load_prefer_newer); |
5a6e5452 | 1141 | UNGCPRO; |
078e7b4a JB |
1142 | } |
1143 | ||
96dc0f4e | 1144 | if (fd == -1) |
078e7b4a | 1145 | { |
265a9e55 | 1146 | if (NILP (noerror)) |
a0931322 | 1147 | report_file_error ("Cannot open load file", file); |
2bfa3d3e | 1148 | dynwind_end (); |
336d4a9c | 1149 | return Qnil; |
078e7b4a JB |
1150 | } |
1151 | ||
ba0d1195 | 1152 | /* Tell startup.el whether or not we found the user's init file. */ |
4116ab9f KH |
1153 | if (EQ (Qt, Vuser_init_file)) |
1154 | Vuser_init_file = found; | |
1155 | ||
96dc0f4e MB |
1156 | /* If FD is -2, that means openp found a magic file. */ |
1157 | if (fd == -2) | |
74549846 | 1158 | { |
5e24a1f7 KH |
1159 | if (NILP (Fequal (found, file))) |
1160 | /* If FOUND is a different file name from FILE, | |
1161 | find its handler even if we have already inhibited | |
1162 | the `load' operation on FILE. */ | |
1163 | handler = Ffind_file_name_handler (found, Qt); | |
1164 | else | |
1165 | handler = Ffind_file_name_handler (found, Qload); | |
2bfa3d3e BT |
1166 | if (! NILP (handler)) { |
1167 | dynwind_end (); | |
1168 | return call5 (handler, Qload, found, noerror, nomessage, Qt); | |
1169 | } | |
35774242 EZ |
1170 | #ifdef DOS_NT |
1171 | /* Tramp has to deal with semi-broken packages that prepend | |
1172 | drive letters to remote files. For that reason, Tramp | |
1173 | catches file operations that test for file existence, which | |
1174 | makes openp think X:/foo.elc files are remote. However, | |
1175 | Tramp does not catch `load' operations for such files, so we | |
1176 | end up with a nil as the `load' handler above. If we would | |
1177 | continue with fd = -2, we will behave wrongly, and in | |
1178 | particular try reading a .elc file in the "rt" mode instead | |
1179 | of "rb". See bug #9311 for the results. To work around | |
1180 | this, we try to open the file locally, and go with that if it | |
1181 | succeeds. */ | |
1182 | fd = emacs_open (SSDATA (ENCODE_FILE (found)), O_RDONLY, 0); | |
1183 | if (fd == -1) | |
1184 | fd = -2; | |
1185 | #endif | |
74549846 RS |
1186 | } |
1187 | ||
9f62b5dd | 1188 | if (fd >= 0) |
b2a069c2 | 1189 | { |
5d1922cd BT |
1190 | record_unwind_protect_ptr (close_file_ptr_unwind, &fd); |
1191 | record_unwind_protect_ptr (fclose_ptr_unwind, &stream); | |
a0931322 PE |
1192 | } |
1193 | ||
550a625e GM |
1194 | /* Check if we're stuck in a recursive load cycle. |
1195 | ||
1196 | 2000-09-21: It's not possible to just check for the file loaded | |
1197 | being a member of Vloads_in_progress. This fails because of the | |
1198 | way the byte compiler currently works; `provide's are not | |
9d438325 | 1199 | evaluated, see font-lock.el/jit-lock.el as an example. This |
550a625e GM |
1200 | leads to a certain amount of ``normal'' recursion. |
1201 | ||
1202 | Also, just loading a file recursively is not always an error in | |
1203 | the general case; the second load may do something different. */ | |
3ba6fd9a | 1204 | { |
0902fe45 | 1205 | int load_count = 0; |
3ba6fd9a RS |
1206 | Lisp_Object tem; |
1207 | for (tem = Vloads_in_progress; CONSP (tem); tem = XCDR (tem)) | |
0902fe45 | 1208 | if (!NILP (Fequal (found, XCAR (tem))) && (++load_count > 3)) |
a0931322 | 1209 | signal_error ("Recursive load", Fcons (found, Vloads_in_progress)); |
3ba6fd9a RS |
1210 | record_unwind_protect (record_load_unwind, Vloads_in_progress); |
1211 | Vloads_in_progress = Fcons (found, Vloads_in_progress); | |
1212 | } | |
7ee3bd7b | 1213 | |
b9598260 SM |
1214 | /* All loads are by default dynamic, unless the file itself specifies |
1215 | otherwise using a file-variable in the first line. This is bound here | |
1216 | so that it takes effect whether or not we use | |
1217 | Vload_source_file_function. */ | |
1218 | specbind (Qlexical_binding, Qnil); | |
1219 | ||
48def666 | 1220 | /* Get the name for load-history. */ |
6bb6da3e | 1221 | hist_file_name = (! NILP (Vpurify_flag) |
a0931322 PE |
1222 | ? concat2 (Ffile_name_directory (file), |
1223 | Ffile_name_nondirectory (found)) | |
6bb6da3e AM |
1224 | : found) ; |
1225 | ||
8792be66 | 1226 | version = -1; |
1bb9a689 | 1227 | |
88852d45 | 1228 | /* Check for the presence of old-style quotes and warn about them. */ |
1d064697 SM |
1229 | specbind (Qold_style_backquotes, Qnil); |
1230 | record_unwind_protect (load_warn_old_style_backquotes, file); | |
1231 | ||
72af86bd | 1232 | if (!memcmp (SDATA (found) + SBYTES (found) - 4, ".elc", 4) |
7cded46f | 1233 | || (fd >= 0 && (version = safe_to_load_version (fd)) > 0)) |
96dc0f4e MB |
1234 | /* Load .elc files directly, but not when they are |
1235 | remote and have no handler! */ | |
078e7b4a | 1236 | { |
96dc0f4e | 1237 | if (fd != -2) |
da84f340 | 1238 | { |
96dc0f4e MB |
1239 | struct stat s1, s2; |
1240 | int result; | |
da84f340 | 1241 | |
6bb6da3e | 1242 | GCPRO3 (file, found, hist_file_name); |
0fc213e9 | 1243 | |
8792be66 | 1244 | if (version < 0 |
7cded46f | 1245 | && ! (version = safe_to_load_version (fd))) |
96dc0f4e MB |
1246 | { |
1247 | safe_p = 0; | |
1248 | if (!load_dangerous_libraries) | |
a0931322 | 1249 | error ("File `%s' was not compiled in Emacs", SDATA (found)); |
beb0b7f9 | 1250 | else if (!NILP (nomessage) && !force_load_messages) |
96dc0f4e MB |
1251 | message_with_string ("File `%s' not compiled in Emacs", found, 1); |
1252 | } | |
04fc68e7 | 1253 | |
96dc0f4e MB |
1254 | compiled = 1; |
1255 | ||
eb191db2 EZ |
1256 | efound = ENCODE_FILE (found); |
1257 | ||
26fbf20b | 1258 | #ifdef DOS_NT |
96dc0f4e | 1259 | fmode = "rb"; |
26fbf20b | 1260 | #endif /* DOS_NT */ |
eb191db2 | 1261 | |
1f41ee56 GM |
1262 | /* openp already checked for newness, no point doing it again. |
1263 | FIXME would be nice to get a message when openp | |
1264 | ignores suffix order due to load_prefer_newer. */ | |
1265 | if (!load_prefer_newer) | |
1266 | { | |
1267 | result = stat (SSDATA (efound), &s1); | |
1268 | if (result == 0) | |
1269 | { | |
1270 | SSET (efound, SBYTES (efound) - 1, 0); | |
1271 | result = stat (SSDATA (efound), &s2); | |
1272 | SSET (efound, SBYTES (efound) - 1, 'c'); | |
1273 | } | |
04fc68e7 | 1274 | |
1f41ee56 GM |
1275 | if (result == 0 |
1276 | && timespec_cmp (get_stat_mtime (&s1), get_stat_mtime (&s2)) < 0) | |
1277 | { | |
1278 | /* Make the progress messages mention that source is newer. */ | |
1279 | newer = 1; | |
1280 | ||
1281 | /* If we won't print another message, mention this anyway. */ | |
1282 | if (!NILP (nomessage) && !force_load_messages) | |
1283 | { | |
1284 | Lisp_Object msg_file; | |
1285 | msg_file = Fsubstring (found, make_number (0), make_number (-1)); | |
1286 | message_with_string ("Source file `%s' newer than byte-compiled file", | |
1287 | msg_file, 1); | |
1288 | } | |
1289 | } | |
1290 | } /* !load_prefer_newer */ | |
0fc213e9 | 1291 | UNGCPRO; |
51ac6f83 | 1292 | } |
078e7b4a | 1293 | } |
fe0e03f3 KH |
1294 | else |
1295 | { | |
1296 | /* We are loading a source file (*.el). */ | |
1297 | if (!NILP (Vload_source_file_function)) | |
1298 | { | |
7ee3bd7b | 1299 | Lisp_Object val; |
96dc0f4e MB |
1300 | |
1301 | if (fd >= 0) | |
a0931322 PE |
1302 | { |
1303 | emacs_close (fd); | |
5d1922cd | 1304 | fd = -1; |
a0931322 | 1305 | } |
6bb6da3e | 1306 | val = call4 (Vload_source_file_function, found, hist_file_name, |
7ee3bd7b | 1307 | NILP (noerror) ? Qnil : Qt, |
beb0b7f9 | 1308 | (NILP (nomessage) || force_load_messages) ? Qnil : Qt); |
2bfa3d3e BT |
1309 | dynwind_end (); |
1310 | return val; | |
fe0e03f3 KH |
1311 | } |
1312 | } | |
078e7b4a | 1313 | |
6bb6da3e | 1314 | GCPRO3 (file, found, hist_file_name); |
0fc213e9 | 1315 | |
a0931322 | 1316 | if (fd < 0) |
35774242 | 1317 | { |
a0931322 PE |
1318 | /* We somehow got here with fd == -2, meaning the file is deemed |
1319 | to be remote. Don't even try to reopen the file locally; | |
1320 | just force a failure. */ | |
1321 | stream = NULL; | |
1322 | errno = EINVAL; | |
35774242 EZ |
1323 | } |
1324 | else | |
078e7b4a | 1325 | { |
a0931322 | 1326 | #ifdef WINDOWSNT |
68c45bf0 | 1327 | emacs_close (fd); |
5d1922cd | 1328 | fd = -1; |
a0931322 PE |
1329 | efound = ENCODE_FILE (found); |
1330 | stream = emacs_fopen (SSDATA (efound), fmode); | |
1331 | #else | |
1332 | stream = fdopen (fd, fmode); | |
1333 | #endif | |
078e7b4a | 1334 | } |
a0931322 PE |
1335 | if (! stream) |
1336 | report_file_error ("Opening stdio stream", file); | |
078e7b4a | 1337 | |
4b104c41 | 1338 | if (! NILP (Vpurify_flag)) |
5e617bc2 | 1339 | Vpreloaded_file_list = Fcons (Fpurecopy (file), Vpreloaded_file_list); |
4b104c41 | 1340 | |
beb0b7f9 | 1341 | if (NILP (nomessage) || force_load_messages) |
04fc68e7 | 1342 | { |
da84f340 GM |
1343 | if (!safe_p) |
1344 | message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...", | |
1345 | file, 1); | |
1346 | else if (!compiled) | |
e28552a4 | 1347 | message_with_string ("Loading %s (source)...", file, 1); |
db5cae4b | 1348 | else if (newer) |
e28552a4 RS |
1349 | message_with_string ("Loading %s (compiled; note, source file is newer)...", |
1350 | file, 1); | |
db5cae4b | 1351 | else /* The typical case; compiled file newer than source file. */ |
e28552a4 | 1352 | message_with_string ("Loading %s...", file, 1); |
04fc68e7 | 1353 | } |
078e7b4a | 1354 | |
20ea2964 | 1355 | specbind (Qload_file_name, found); |
74549846 | 1356 | specbind (Qinhibit_file_name_operation, Qnil); |
2baf5e76 | 1357 | specbind (Qload_in_progress, Qt); |
b9598260 SM |
1358 | |
1359 | instream = stream; | |
1360 | if (lisp_file_lexically_bound_p (Qget_file_char)) | |
1361 | Fset (Qlexical_binding, Qt); | |
1362 | ||
ab2a47e1 | 1363 | if (! version || version >= 22) |
b883cdb2 | 1364 | readevalloop (Qget_file_char, stream, hist_file_name, |
defb1411 | 1365 | 0, Qnil, Qnil, Qnil, Qnil); |
8792be66 KH |
1366 | else |
1367 | { | |
1368 | /* We can't handle a file which was compiled with | |
1369 | byte-compile-dynamic by older version of Emacs. */ | |
1370 | specbind (Qload_force_doc_strings, Qt); | |
defb1411 | 1371 | readevalloop (Qget_emacs_mule_file_char, stream, hist_file_name, |
768d4533 | 1372 | 0, Qnil, Qnil, Qnil, Qnil); |
8792be66 | 1373 | } |
2bfa3d3e | 1374 | dynwind_end (); |
078e7b4a | 1375 | |
48def666 | 1376 | /* Run any eval-after-load forms for this file. */ |
428b13d6 | 1377 | if (!NILP (Ffboundp (Qdo_after_load_evaluation))) |
6bb6da3e AM |
1378 | call1 (Qdo_after_load_evaluation, hist_file_name) ; |
1379 | ||
078e7b4a JB |
1380 | UNGCPRO; |
1381 | ||
97dead2d | 1382 | xfree (saved_doc_string); |
b2a30870 RS |
1383 | saved_doc_string = 0; |
1384 | saved_doc_string_size = 0; | |
1385 | ||
70fdbb46 | 1386 | xfree (prev_saved_doc_string); |
c15cfd1f RS |
1387 | prev_saved_doc_string = 0; |
1388 | prev_saved_doc_string_size = 0; | |
1389 | ||
beb0b7f9 | 1390 | if (!noninteractive && (NILP (nomessage) || force_load_messages)) |
04fc68e7 | 1391 | { |
da84f340 GM |
1392 | if (!safe_p) |
1393 | message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done", | |
1394 | file, 1); | |
1395 | else if (!compiled) | |
e28552a4 | 1396 | message_with_string ("Loading %s (source)...done", file, 1); |
db5cae4b | 1397 | else if (newer) |
e28552a4 RS |
1398 | message_with_string ("Loading %s (compiled; note, source file is newer)...done", |
1399 | file, 1); | |
db5cae4b | 1400 | else /* The typical case; compiled file newer than source file. */ |
e28552a4 | 1401 | message_with_string ("Loading %s...done", file, 1); |
04fc68e7 | 1402 | } |
7ee3bd7b | 1403 | |
078e7b4a JB |
1404 | return Qt; |
1405 | } | |
078e7b4a | 1406 | \f |
7cded46f | 1407 | static bool |
971de7fb | 1408 | complete_filename_p (Lisp_Object pathname) |
078e7b4a | 1409 | { |
7cded46f | 1410 | const unsigned char *s = SDATA (pathname); |
317073d5 | 1411 | return (IS_DIRECTORY_SEP (s[0]) |
d5db4077 | 1412 | || (SCHARS (pathname) > 2 |
7c2fb837 | 1413 | && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2]))); |
078e7b4a JB |
1414 | } |
1415 | ||
86d00812 SM |
1416 | DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, 4, 0, |
1417 | doc: /* Search for FILENAME through PATH. | |
57a131fb | 1418 | Returns the file's name in absolute form, or nil if not found. |
86d00812 SM |
1419 | If SUFFIXES is non-nil, it should be a list of suffixes to append to |
1420 | file name when searching. | |
1421 | If non-nil, PREDICATE is used instead of `file-readable-p'. | |
73dcdb9f | 1422 | PREDICATE can also be an integer to pass to the faccessat(2) function, |
aa56f361 SM |
1423 | in which case file-name-handlers are ignored. |
1424 | This function will normally skip directories, so if you want it to find | |
1425 | directories, make sure the PREDICATE function returns `dir-ok' for them. */) | |
5842a27b | 1426 | (Lisp_Object filename, Lisp_Object path, Lisp_Object suffixes, Lisp_Object predicate) |
86d00812 SM |
1427 | { |
1428 | Lisp_Object file; | |
518c40a2 | 1429 | int fd = openp (path, filename, suffixes, &file, predicate, false); |
a773ed9a | 1430 | if (NILP (predicate) && fd >= 0) |
bacba3c2 | 1431 | emacs_close (fd); |
86d00812 SM |
1432 | return file; |
1433 | } | |
1434 | ||
aa56f361 | 1435 | static Lisp_Object Qdir_ok; |
86d00812 | 1436 | |
078e7b4a JB |
1437 | /* Search for a file whose name is STR, looking in directories |
1438 | in the Lisp list PATH, and trying suffixes from SUFFIX. | |
5f86adcd PE |
1439 | On success, return a file descriptor (or 1 or -2 as described below). |
1440 | On failure, return -1 and set errno. | |
078e7b4a | 1441 | |
e61b9b87 | 1442 | SUFFIXES is a list of strings containing possible suffixes. |
e0f24100 | 1443 | The empty suffix is automatically added if the list is empty. |
e61b9b87 | 1444 | |
86d00812 SM |
1445 | PREDICATE non-nil means don't open the files, |
1446 | just look for one that satisfies the predicate. In this case, | |
5f86adcd | 1447 | return 1 on success. The predicate can be a lisp function or |
86d00812 SM |
1448 | an integer to pass to `access' (in which case file-name-handlers |
1449 | are ignored). | |
078e7b4a JB |
1450 | |
1451 | If STOREPTR is nonzero, it points to a slot where the name of | |
1452 | the file actually found should be stored as a Lisp string. | |
74549846 RS |
1453 | nil is stored there on failure. |
1454 | ||
96dc0f4e | 1455 | If the file we find is remote, return -2 |
1f41ee56 GM |
1456 | but store the found remote file name in *STOREPTR. |
1457 | ||
1458 | If NEWER is true, try all SUFFIXes and return the result for the | |
150622a1 GM |
1459 | newest file that exists. Does not apply to remote files, |
1460 | or if PREDICATE is specified. */ | |
078e7b4a JB |
1461 | |
1462 | int | |
5f86adcd | 1463 | openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, |
518c40a2 | 1464 | Lisp_Object *storeptr, Lisp_Object predicate, bool newer) |
078e7b4a | 1465 | { |
d311d28c | 1466 | ptrdiff_t fn_size = 100; |
078e7b4a | 1467 | char buf[100]; |
7cded46f | 1468 | char *fn = buf; |
518c40a2 | 1469 | bool absolute; |
d311d28c | 1470 | ptrdiff_t want_length; |
74549846 | 1471 | Lisp_Object filename; |
518c40a2 | 1472 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6, gcpro7; |
1f41ee56 | 1473 | Lisp_Object string, tail, encoded_fn, save_string; |
d311d28c | 1474 | ptrdiff_t max_suffix_len = 0; |
5f86adcd | 1475 | int last_errno = ENOENT; |
518c40a2 | 1476 | int save_fd = -1; |
e61b9b87 | 1477 | |
70695f13 PE |
1478 | /* The last-modified time of the newest matching file found. |
1479 | Initialize it to something less than all valid timestamps. */ | |
1480 | struct timespec save_mtime = make_timespec (TYPE_MINIMUM (time_t), -1); | |
1481 | ||
6f8eafd1 SM |
1482 | CHECK_STRING (str); |
1483 | ||
e61b9b87 SM |
1484 | for (tail = suffixes; CONSP (tail); tail = XCDR (tail)) |
1485 | { | |
f5df591a | 1486 | CHECK_STRING_CAR (tail); |
e61b9b87 | 1487 | max_suffix_len = max (max_suffix_len, |
d5db4077 | 1488 | SBYTES (XCAR (tail))); |
e61b9b87 | 1489 | } |
078e7b4a | 1490 | |
518c40a2 PE |
1491 | string = filename = encoded_fn = save_string = Qnil; |
1492 | GCPRO7 (str, string, save_string, filename, path, suffixes, encoded_fn); | |
eb191db2 | 1493 | |
078e7b4a JB |
1494 | if (storeptr) |
1495 | *storeptr = Qnil; | |
1496 | ||
518c40a2 | 1497 | absolute = complete_filename_p (str); |
078e7b4a | 1498 | |
e61b9b87 | 1499 | for (; CONSP (path); path = XCDR (path)) |
078e7b4a | 1500 | { |
e61b9b87 | 1501 | filename = Fexpand_file_name (str, XCAR (path)); |
078e7b4a | 1502 | if (!complete_filename_p (filename)) |
48def666 | 1503 | /* If there are non-absolute elts in PATH (eg "."). */ |
078e7b4a | 1504 | /* Of course, this could conceivably lose if luser sets |
48def666 | 1505 | default-directory to be something non-absolute... */ |
078e7b4a | 1506 | { |
4b4deea2 | 1507 | filename = Fexpand_file_name (filename, BVAR (current_buffer, directory)); |
078e7b4a | 1508 | if (!complete_filename_p (filename)) |
48def666 | 1509 | /* Give up on this path element! */ |
078e7b4a JB |
1510 | continue; |
1511 | } | |
1512 | ||
640ee02d | 1513 | /* Calculate maximum length of any filename made from |
078e7b4a | 1514 | this path element/specified file name and any possible suffix. */ |
640ee02d PE |
1515 | want_length = max_suffix_len + SBYTES (filename); |
1516 | if (fn_size <= want_length) | |
38182d90 | 1517 | fn = alloca (fn_size = 100 + want_length); |
078e7b4a | 1518 | |
078e7b4a | 1519 | /* Loop over suffixes. */ |
6c6f1994 | 1520 | for (tail = NILP (suffixes) ? list1 (empty_unibyte_string) : suffixes; |
e61b9b87 | 1521 | CONSP (tail); tail = XCDR (tail)) |
078e7b4a | 1522 | { |
d0065ff1 EZ |
1523 | Lisp_Object suffix = XCAR (tail); |
1524 | ptrdiff_t fnlen, lsuffix = SBYTES (suffix); | |
74549846 | 1525 | Lisp_Object handler; |
078e7b4a | 1526 | |
c49afcd7 RS |
1527 | /* Concatenate path element/specified name with the suffix. |
1528 | If the directory starts with /:, remove that. */ | |
e99a530f PE |
1529 | int prefixlen = ((SCHARS (filename) > 2 |
1530 | && SREF (filename, 0) == '/' | |
1531 | && SREF (filename, 1) == ':') | |
1532 | ? 2 : 0); | |
1533 | fnlen = SBYTES (filename) - prefixlen; | |
1534 | memcpy (fn, SDATA (filename) + prefixlen, fnlen); | |
d0065ff1 | 1535 | memcpy (fn + fnlen, SDATA (suffix), lsuffix + 1); |
e99a530f | 1536 | fnlen += lsuffix; |
74549846 | 1537 | /* Check that the file exists and is not a directory. */ |
e61b9b87 SM |
1538 | /* We used to only check for handlers on non-absolute file names: |
1539 | if (absolute) | |
1540 | handler = Qnil; | |
1541 | else | |
1542 | handler = Ffind_file_name_handler (filename, Qfile_exists_p); | |
1543 | It's not clear why that was the case and it breaks things like | |
1544 | (load "/bar.el") where the file is actually "/bar.el.gz". */ | |
d0065ff1 EZ |
1545 | /* make_string has its own ideas on when to return a unibyte |
1546 | string and when a multibyte string, but we know better. | |
1547 | We must have a unibyte string when dumping, since | |
1548 | file-name encoding is shaky at best at that time, and in | |
1549 | particular default-file-name-coding-system is reset | |
1550 | several times during loadup. We therefore don't want to | |
1551 | encode the file before passing it to file I/O library | |
1552 | functions. */ | |
1553 | if (!STRING_MULTIBYTE (filename) && !STRING_MULTIBYTE (suffix)) | |
1554 | string = make_unibyte_string (fn, fnlen); | |
1555 | else | |
1556 | string = make_string (fn, fnlen); | |
4773b8ca | 1557 | handler = Ffind_file_name_handler (string, Qfile_exists_p); |
86d00812 SM |
1558 | if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate)) |
1559 | { | |
73dcdb9f | 1560 | bool exists; |
86d00812 SM |
1561 | if (NILP (predicate)) |
1562 | exists = !NILP (Ffile_readable_p (string)); | |
1563 | else | |
aa56f361 SM |
1564 | { |
1565 | Lisp_Object tmp = call1 (predicate, string); | |
5f86adcd | 1566 | if (NILP (tmp)) |
518c40a2 | 1567 | exists = false; |
5f86adcd PE |
1568 | else if (EQ (tmp, Qdir_ok) |
1569 | || NILP (Ffile_directory_p (string))) | |
518c40a2 | 1570 | exists = true; |
5f86adcd PE |
1571 | else |
1572 | { | |
518c40a2 | 1573 | exists = false; |
5f86adcd PE |
1574 | last_errno = EISDIR; |
1575 | } | |
aa56f361 | 1576 | } |
74549846 RS |
1577 | |
1578 | if (exists) | |
078e7b4a | 1579 | { |
1f41ee56 GM |
1580 | /* We succeeded; return this descriptor and filename. */ |
1581 | if (storeptr) | |
1582 | *storeptr = string; | |
1583 | UNGCPRO; | |
1584 | return -2; | |
74549846 RS |
1585 | } |
1586 | } | |
1587 | else | |
1588 | { | |
73dcdb9f | 1589 | int fd; |
4b2dd274 | 1590 | const char *pfn; |
1f41ee56 | 1591 | struct stat st; |
eb191db2 EZ |
1592 | |
1593 | encoded_fn = ENCODE_FILE (string); | |
42a5b22f | 1594 | pfn = SSDATA (encoded_fn); |
f0a80175 | 1595 | |
73dcdb9f PE |
1596 | /* Check that we can access or open it. */ |
1597 | if (NATNUMP (predicate)) | |
5f86adcd PE |
1598 | { |
1599 | fd = -1; | |
1600 | if (INT_MAX < XFASTINT (predicate)) | |
1601 | last_errno = EINVAL; | |
1602 | else if (faccessat (AT_FDCWD, pfn, XFASTINT (predicate), | |
73dcdb9f PE |
1603 | AT_EACCESS) |
1604 | == 0) | |
5f86adcd PE |
1605 | { |
1606 | if (file_directory_p (pfn)) | |
1607 | last_errno = EISDIR; | |
1608 | else | |
1609 | fd = 1; | |
1610 | } | |
1611 | } | |
73dcdb9f PE |
1612 | else |
1613 | { | |
73dcdb9f | 1614 | fd = emacs_open (pfn, O_RDONLY, 0); |
5f86adcd | 1615 | if (fd < 0) |
a0931322 PE |
1616 | { |
1617 | if (errno != ENOENT) | |
1618 | last_errno = errno; | |
1619 | } | |
5f86adcd | 1620 | else |
74549846 | 1621 | { |
5f86adcd PE |
1622 | int err = (fstat (fd, &st) != 0 ? errno |
1623 | : S_ISDIR (st.st_mode) ? EISDIR : 0); | |
1624 | if (err) | |
1625 | { | |
1626 | last_errno = err; | |
1627 | emacs_close (fd); | |
1628 | fd = -1; | |
1629 | } | |
74549846 | 1630 | } |
078e7b4a | 1631 | } |
73dcdb9f PE |
1632 | |
1633 | if (fd >= 0) | |
1634 | { | |
150622a1 | 1635 | if (newer && !NATNUMP (predicate)) |
1f41ee56 GM |
1636 | { |
1637 | struct timespec mtime = get_stat_mtime (&st); | |
1638 | ||
518c40a2 PE |
1639 | if (timespec_cmp (mtime, save_mtime) <= 0) |
1640 | emacs_close (fd); | |
1641 | else | |
1f41ee56 | 1642 | { |
518c40a2 PE |
1643 | if (0 <= save_fd) |
1644 | emacs_close (save_fd); | |
1f41ee56 GM |
1645 | save_fd = fd; |
1646 | save_mtime = mtime; | |
1647 | save_string = string; | |
1648 | } | |
1649 | } | |
1650 | else | |
1651 | { | |
1652 | /* We succeeded; return this descriptor and filename. */ | |
1653 | if (storeptr) | |
1654 | *storeptr = string; | |
1655 | UNGCPRO; | |
1656 | return fd; | |
1657 | } | |
73dcdb9f | 1658 | } |
1f41ee56 GM |
1659 | |
1660 | /* No more suffixes. Return the newest. */ | |
518c40a2 | 1661 | if (0 <= save_fd && ! CONSP (XCDR (tail))) |
1f41ee56 GM |
1662 | { |
1663 | if (storeptr) | |
1664 | *storeptr = save_string; | |
1665 | UNGCPRO; | |
1666 | return save_fd; | |
1667 | } | |
078e7b4a | 1668 | } |
078e7b4a | 1669 | } |
5a6e5452 | 1670 | if (absolute) |
5ef2a3c0 | 1671 | break; |
078e7b4a JB |
1672 | } |
1673 | ||
5ef2a3c0 | 1674 | UNGCPRO; |
5f86adcd | 1675 | errno = last_errno; |
5ef2a3c0 | 1676 | return -1; |
078e7b4a JB |
1677 | } |
1678 | ||
1679 | \f | |
ae321d28 RS |
1680 | /* Merge the list we've accumulated of globals from the current input source |
1681 | into the load_history variable. The details depend on whether | |
b502a9a1 RS |
1682 | the source has an associated file name or not. |
1683 | ||
1684 | FILENAME is the file name that we are loading from. | |
7cded46f PE |
1685 | |
1686 | ENTIRE is true if loading that entire file, false if evaluating | |
1687 | part of it. */ | |
ae321d28 RS |
1688 | |
1689 | static void | |
7cded46f | 1690 | build_load_history (Lisp_Object filename, bool entire) |
ae321d28 | 1691 | { |
7cded46f PE |
1692 | Lisp_Object tail, prev, newelt; |
1693 | Lisp_Object tem, tem2; | |
1694 | bool foundit = 0; | |
ae321d28 RS |
1695 | |
1696 | tail = Vload_history; | |
1697 | prev = Qnil; | |
b502a9a1 | 1698 | |
86d00812 | 1699 | while (CONSP (tail)) |
ae321d28 | 1700 | { |
86d00812 | 1701 | tem = XCAR (tail); |
ae321d28 | 1702 | |
48def666 | 1703 | /* Find the feature's previous assoc list... */ |
b502a9a1 | 1704 | if (!NILP (Fequal (filename, Fcar (tem)))) |
ae321d28 RS |
1705 | { |
1706 | foundit = 1; | |
1707 | ||
48def666 | 1708 | /* If we're loading the entire file, remove old data. */ |
b502a9a1 | 1709 | if (entire) |
86d00812 | 1710 | { |
ae321d28 | 1711 | if (NILP (prev)) |
86d00812 | 1712 | Vload_history = XCDR (tail); |
ae321d28 | 1713 | else |
86d00812 | 1714 | Fsetcdr (prev, XCDR (tail)); |
ae321d28 RS |
1715 | } |
1716 | ||
1717 | /* Otherwise, cons on new symbols that are not already members. */ | |
1718 | else | |
1719 | { | |
1720 | tem2 = Vcurrent_load_list; | |
1721 | ||
1722 | while (CONSP (tem2)) | |
1723 | { | |
86d00812 | 1724 | newelt = XCAR (tem2); |
ae321d28 | 1725 | |
d642e4f9 | 1726 | if (NILP (Fmember (newelt, tem))) |
86d00812 SM |
1727 | Fsetcar (tail, Fcons (XCAR (tem), |
1728 | Fcons (newelt, XCDR (tem)))); | |
ae321d28 | 1729 | |
86d00812 | 1730 | tem2 = XCDR (tem2); |
ae321d28 RS |
1731 | QUIT; |
1732 | } | |
1733 | } | |
1734 | } | |
1735 | else | |
1736 | prev = tail; | |
86d00812 | 1737 | tail = XCDR (tail); |
ae321d28 RS |
1738 | QUIT; |
1739 | } | |
1740 | ||
b502a9a1 RS |
1741 | /* If we're loading an entire file, cons the new assoc onto the |
1742 | front of load-history, the most-recently-loaded position. Also | |
1743 | do this if we didn't find an existing member for the file. */ | |
1744 | if (entire || !foundit) | |
8a1f1537 RS |
1745 | Vload_history = Fcons (Fnreverse (Vcurrent_load_list), |
1746 | Vload_history); | |
ae321d28 RS |
1747 | } |
1748 | ||
27e498e6 PE |
1749 | static void |
1750 | readevalloop_1 (int old) | |
94e554db | 1751 | { |
27e498e6 | 1752 | load_convert_to_unibyte = old; |
94e554db RS |
1753 | } |
1754 | ||
9c97398c GM |
1755 | /* Signal an `end-of-file' error, if possible with file name |
1756 | information. */ | |
1757 | ||
845ca893 | 1758 | static _Noreturn void |
971de7fb | 1759 | end_of_file_error (void) |
9c97398c | 1760 | { |
9c97398c | 1761 | if (STRINGP (Vload_file_name)) |
336d4a9c | 1762 | xsignal1 (Qend_of_file, Vload_file_name); |
9c97398c | 1763 | |
336d4a9c | 1764 | xsignal0 (Qend_of_file); |
9c97398c GM |
1765 | } |
1766 | ||
12b1389c DC |
1767 | static Lisp_Object |
1768 | readevalloop_eager_expand_eval (Lisp_Object val, Lisp_Object macroexpand) | |
1769 | { | |
1770 | /* If we macroexpand the toplevel form non-recursively and it ends | |
1771 | up being a `progn' (or if it was a progn to start), treat each | |
1772 | form in the progn as a top-level form. This way, if one form in | |
1773 | the progn defines a macro, that macro is in effect when we expand | |
1774 | the remaining forms. See similar code in bytecomp.el. */ | |
1775 | val = call2 (macroexpand, val, Qnil); | |
1776 | if (EQ (CAR_SAFE (val), Qprogn)) | |
1777 | { | |
1778 | Lisp_Object subforms = XCDR (val); | |
1779 | val = Qnil; | |
1780 | for (; CONSP (subforms); subforms = XCDR (subforms)) | |
1781 | val = readevalloop_eager_expand_eval (XCAR (subforms), | |
1782 | macroexpand); | |
1783 | } | |
1784 | else | |
1785 | val = eval_sub (call2 (macroexpand, val, Qt)); | |
1786 | ||
1787 | return val; | |
1788 | } | |
1789 | ||
94e554db | 1790 | /* UNIBYTE specifies how to set load_convert_to_unibyte |
976350af | 1791 | for this invocation. |
4c03c46d | 1792 | READFUN, if non-nil, is used instead of `read'. |
1ed7b9ae RS |
1793 | |
1794 | START, END specify region to read in current buffer (from eval-region). | |
1795 | If the input is not from a buffer, they must be nil. */ | |
94e554db | 1796 | |
078e7b4a | 1797 | static void |
dd4c5104 DN |
1798 | readevalloop (Lisp_Object readcharfun, |
1799 | FILE *stream, | |
1800 | Lisp_Object sourcename, | |
7cded46f | 1801 | bool printflag, |
dd4c5104 DN |
1802 | Lisp_Object unibyte, Lisp_Object readfun, |
1803 | Lisp_Object start, Lisp_Object end) | |
078e7b4a JB |
1804 | { |
1805 | register int c; | |
1806 | register Lisp_Object val; | |
2bfa3d3e | 1807 | dynwind_begin (); |
0a37f512 | 1808 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
49cf7ff4 | 1809 | struct buffer *b = 0; |
7cded46f | 1810 | bool continue_reading_p; |
b9598260 | 1811 | Lisp_Object lex_bound; |
7cded46f PE |
1812 | /* True if reading an entire buffer. */ |
1813 | bool whole_buffer = 0; | |
1814 | /* True on the first time around. */ | |
1815 | bool first_sexp = 1; | |
972debf2 SM |
1816 | Lisp_Object macroexpand = intern ("internal-macroexpand-for-load"); |
1817 | ||
1818 | if (NILP (Ffboundp (macroexpand)) | |
1819 | /* Don't macroexpand in .elc files, since it should have been done | |
1820 | already. We actually don't know whether we're in a .elc file or not, | |
735135f9 | 1821 | so we use circumstantial evidence: .el files normally go through |
972debf2 SM |
1822 | Vload_source_file_function -> load-with-code-conversion |
1823 | -> eval-buffer. */ | |
1824 | || EQ (readcharfun, Qget_file_char) | |
1825 | || EQ (readcharfun, Qget_emacs_mule_file_char)) | |
1826 | macroexpand = Qnil; | |
d11db2c8 RS |
1827 | |
1828 | if (MARKERP (readcharfun)) | |
1829 | { | |
1830 | if (NILP (start)) | |
8878319c | 1831 | start = readcharfun; |
d11db2c8 | 1832 | } |
49cf7ff4 RS |
1833 | |
1834 | if (BUFFERP (readcharfun)) | |
1835 | b = XBUFFER (readcharfun); | |
1836 | else if (MARKERP (readcharfun)) | |
1837 | b = XMARKER (readcharfun)->buffer; | |
078e7b4a | 1838 | |
1ed7b9ae RS |
1839 | /* We assume START is nil when input is not from a buffer. */ |
1840 | if (! NILP (start) && !b) | |
1088b922 | 1841 | emacs_abort (); |
1ed7b9ae | 1842 | |
0a37f512 | 1843 | specbind (Qstandard_input, readcharfun); /* GCPROs readcharfun. */ |
8a1f1537 | 1844 | specbind (Qcurrent_load_list, Qnil); |
27e498e6 | 1845 | record_unwind_protect_int (readevalloop_1, load_convert_to_unibyte); |
94e554db | 1846 | load_convert_to_unibyte = !NILP (unibyte); |
078e7b4a | 1847 | |
b9598260 SM |
1848 | /* If lexical binding is active (either because it was specified in |
1849 | the file's header, or via a buffer-local variable), create an empty | |
1850 | lexical environment, otherwise, turn off lexical binding. */ | |
1851 | lex_bound = find_symbol_value (Qlexical_binding); | |
f07a954e | 1852 | specbind (Qinternal_interpreter_environment, |
6c6f1994 PE |
1853 | (NILP (lex_bound) || EQ (lex_bound, Qunbound) |
1854 | ? Qnil : list1 (Qt))); | |
b9598260 | 1855 | |
0a37f512 | 1856 | GCPRO4 (sourcename, readfun, start, end); |
ae321d28 | 1857 | |
48def666 | 1858 | /* Try to ensure sourcename is a truename, except whilst preloading. */ |
6bb6da3e | 1859 | if (NILP (Vpurify_flag) |
91fe9496 SM |
1860 | && !NILP (sourcename) && !NILP (Ffile_name_absolute_p (sourcename)) |
1861 | && !NILP (Ffboundp (Qfile_truename))) | |
6bb6da3e AM |
1862 | sourcename = call1 (Qfile_truename, sourcename) ; |
1863 | ||
ae321d28 RS |
1864 | LOADHIST_ATTACH (sourcename); |
1865 | ||
f38952fe GM |
1866 | continue_reading_p = 1; |
1867 | while (continue_reading_p) | |
078e7b4a | 1868 | { |
2bfa3d3e | 1869 | dynwind_begin (); |
4c03c46d | 1870 | |
e578f381 | 1871 | if (b != 0 && !BUFFER_LIVE_P (b)) |
49cf7ff4 RS |
1872 | error ("Reading from killed buffer"); |
1873 | ||
4c03c46d KS |
1874 | if (!NILP (start)) |
1875 | { | |
721b7d9e | 1876 | /* Switch to the buffer we are reading from. */ |
4c03c46d | 1877 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
721b7d9e RS |
1878 | set_buffer_internal (b); |
1879 | ||
1880 | /* Save point in it. */ | |
4c03c46d | 1881 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
721b7d9e | 1882 | /* Save ZV in it. */ |
4c03c46d | 1883 | record_unwind_protect (save_restriction_restore, save_restriction_save ()); |
721b7d9e RS |
1884 | /* Those get unbound after we read one expression. */ |
1885 | ||
1886 | /* Set point and ZV around stuff to be read. */ | |
4c03c46d | 1887 | Fgoto_char (start); |
d11db2c8 RS |
1888 | if (!NILP (end)) |
1889 | Fnarrow_to_region (make_number (BEGV), end); | |
1890 | ||
1891 | /* Just for cleanliness, convert END to a marker | |
1892 | if it is an integer. */ | |
1893 | if (INTEGERP (end)) | |
1894 | end = Fpoint_max_marker (); | |
4c03c46d KS |
1895 | } |
1896 | ||
d11db2c8 RS |
1897 | /* On the first cycle, we can easily test here |
1898 | whether we are reading the whole buffer. */ | |
1899 | if (b && first_sexp) | |
1900 | whole_buffer = (PT == BEG && ZV == Z); | |
1901 | ||
078e7b4a | 1902 | instream = stream; |
4c03c46d | 1903 | read_next: |
078e7b4a JB |
1904 | c = READCHAR; |
1905 | if (c == ';') | |
1906 | { | |
1907 | while ((c = READCHAR) != '\n' && c != -1); | |
4c03c46d KS |
1908 | goto read_next; |
1909 | } | |
1910 | if (c < 0) | |
1911 | { | |
2bfa3d3e | 1912 | dynwind_end (); |
4c03c46d | 1913 | break; |
078e7b4a | 1914 | } |
6069d957 RS |
1915 | |
1916 | /* Ignore whitespace here, so we can detect eof. */ | |
adef3de7 | 1917 | if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r' |
ed497dd4 | 1918 | || c == 0xa0) /* NBSP */ |
4c03c46d | 1919 | goto read_next; |
078e7b4a | 1920 | |
265a9e55 | 1921 | if (!NILP (Vpurify_flag) && c == '(') |
078e7b4a | 1922 | { |
48def666 | 1923 | val = read_list (0, readcharfun); |
078e7b4a JB |
1924 | } |
1925 | else | |
1926 | { | |
1927 | UNREAD (c); | |
4ad679f9 | 1928 | read_objects = Qnil; |
f38952fe GM |
1929 | if (!NILP (readfun)) |
1930 | { | |
1931 | val = call1 (readfun, readcharfun); | |
1932 | ||
1933 | /* If READCHARFUN has set point to ZV, we should | |
1934 | stop reading, even if the form read sets point | |
1935 | to a different value when evaluated. */ | |
1936 | if (BUFFERP (readcharfun)) | |
1937 | { | |
0902fe45 PE |
1938 | struct buffer *buf = XBUFFER (readcharfun); |
1939 | if (BUF_PT (buf) == BUF_ZV (buf)) | |
f38952fe GM |
1940 | continue_reading_p = 0; |
1941 | } | |
1942 | } | |
976350af | 1943 | else if (! NILP (Vload_read_function)) |
84a15045 | 1944 | val = call1 (Vload_read_function, readcharfun); |
976350af | 1945 | else |
abb13b09 | 1946 | val = read_internal_start (readcharfun, Qnil, Qnil); |
078e7b4a JB |
1947 | } |
1948 | ||
4c03c46d KS |
1949 | if (!NILP (start) && continue_reading_p) |
1950 | start = Fpoint_marker (); | |
d11db2c8 RS |
1951 | |
1952 | /* Restore saved point and BEGV. */ | |
2bfa3d3e | 1953 | dynwind_end (); |
4c03c46d | 1954 | |
d11db2c8 | 1955 | /* Now eval what we just read. */ |
972debf2 | 1956 | if (!NILP (macroexpand)) |
12b1389c DC |
1957 | val = readevalloop_eager_expand_eval (val, macroexpand); |
1958 | else | |
1959 | val = eval_sub (val); | |
f38952fe | 1960 | |
078e7b4a JB |
1961 | if (printflag) |
1962 | { | |
1963 | Vvalues = Fcons (val, Vvalues); | |
1964 | if (EQ (Vstandard_output, Qt)) | |
1965 | Fprin1 (val, Qnil); | |
1966 | else | |
1967 | Fprint (val, Qnil); | |
1968 | } | |
d11db2c8 RS |
1969 | |
1970 | first_sexp = 0; | |
078e7b4a JB |
1971 | } |
1972 | ||
8878319c | 1973 | build_load_history (sourcename, |
d11db2c8 | 1974 | stream || whole_buffer); |
b502a9a1 | 1975 | |
ae321d28 RS |
1976 | UNGCPRO; |
1977 | ||
2bfa3d3e | 1978 | dynwind_end (); |
078e7b4a JB |
1979 | } |
1980 | ||
1076254d | 1981 | DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 5, "", |
5de38842 | 1982 | doc: /* Execute the current buffer as Lisp code. |
72097cd9 CY |
1983 | When called from a Lisp program (i.e., not interactively), this |
1984 | function accepts up to five optional arguments: | |
5de38842 PJ |
1985 | BUFFER is the buffer to evaluate (nil means use current buffer). |
1986 | PRINTFLAG controls printing of output: | |
72097cd9 CY |
1987 | A value of nil means discard it; anything else is stream for print. |
1988 | FILENAME specifies the file name to use for `load-history'. | |
1989 | UNIBYTE, if non-nil, specifies `load-convert-to-unibyte' for this | |
1990 | invocation. | |
1991 | DO-ALLOW-PRINT, if non-nil, specifies that `print' and related | |
1992 | functions should work normally even if PRINTFLAG is nil. | |
5de38842 PJ |
1993 | |
1994 | This function preserves the position of point. */) | |
5842a27b | 1995 | (Lisp_Object buffer, Lisp_Object printflag, Lisp_Object filename, Lisp_Object unibyte, Lisp_Object do_allow_print) |
228d4b1c | 1996 | { |
2bfa3d3e | 1997 | dynwind_begin (); |
228d4b1c JA |
1998 | Lisp_Object tem, buf; |
1999 | ||
9391b698 | 2000 | if (NILP (buffer)) |
228d4b1c JA |
2001 | buf = Fcurrent_buffer (); |
2002 | else | |
9391b698 | 2003 | buf = Fget_buffer (buffer); |
dfdb645c | 2004 | if (NILP (buf)) |
13febd85 | 2005 | error ("No such buffer"); |
228d4b1c | 2006 | |
1076254d | 2007 | if (NILP (printflag) && NILP (do_allow_print)) |
228d4b1c JA |
2008 | tem = Qsymbolp; |
2009 | else | |
2010 | tem = printflag; | |
13febd85 RS |
2011 | |
2012 | if (NILP (filename)) | |
4b4deea2 | 2013 | filename = BVAR (XBUFFER (buf), filename); |
13febd85 | 2014 | |
3f39f996 | 2015 | specbind (Qeval_buffer_list, Fcons (buf, Veval_buffer_list)); |
228d4b1c JA |
2016 | specbind (Qstandard_output, tem); |
2017 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
bf1c0f27 | 2018 | BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); |
7200d79c | 2019 | specbind (Qlexical_binding, lisp_file_lexically_bound_p (buf) ? Qt : Qnil); |
defb1411 | 2020 | readevalloop (buf, 0, filename, |
4c03c46d | 2021 | !NILP (printflag), unibyte, Qnil, Qnil, Qnil); |
2bfa3d3e | 2022 | dynwind_end (); |
228d4b1c JA |
2023 | |
2024 | return Qnil; | |
2025 | } | |
2026 | ||
976350af | 2027 | DEFUN ("eval-region", Feval_region, Seval_region, 2, 4, "r", |
5de38842 PJ |
2028 | doc: /* Execute the region as Lisp code. |
2029 | When called from programs, expects two arguments, | |
2030 | giving starting and ending indices in the current buffer | |
2031 | of the text to be executed. | |
2032 | Programs can pass third argument PRINTFLAG which controls output: | |
51d8b30e | 2033 | A value of nil means discard it; anything else is stream for printing it. |
5de38842 PJ |
2034 | Also the fourth argument READ-FUNCTION, if non-nil, is used |
2035 | instead of `read' to read each expression. It gets one argument | |
2036 | which is the input stream for reading characters. | |
2037 | ||
2038 | This function does not move point. */) | |
5842a27b | 2039 | (Lisp_Object start, Lisp_Object end, Lisp_Object printflag, Lisp_Object read_function) |
078e7b4a | 2040 | { |
e4769531 | 2041 | /* FIXME: Do the eval-sexp-add-defvars dance! */ |
2bfa3d3e | 2042 | dynwind_begin (); |
ae321d28 RS |
2043 | Lisp_Object tem, cbuf; |
2044 | ||
2045 | cbuf = Fcurrent_buffer (); | |
078e7b4a | 2046 | |
265a9e55 | 2047 | if (NILP (printflag)) |
078e7b4a JB |
2048 | tem = Qsymbolp; |
2049 | else | |
2050 | tem = printflag; | |
2051 | specbind (Qstandard_output, tem); | |
3f39f996 | 2052 | specbind (Qeval_buffer_list, Fcons (cbuf, Veval_buffer_list)); |
078e7b4a | 2053 | |
48def666 | 2054 | /* `readevalloop' calls functions which check the type of start and end. */ |
f619ad4c | 2055 | readevalloop (cbuf, 0, BVAR (XBUFFER (cbuf), filename), |
4c03c46d KS |
2056 | !NILP (printflag), Qnil, read_function, |
2057 | start, end); | |
078e7b4a | 2058 | |
2bfa3d3e BT |
2059 | dynwind_end (); |
2060 | return Qnil; | |
078e7b4a JB |
2061 | } |
2062 | ||
078e7b4a | 2063 | \f |
a7ca3326 | 2064 | DEFUN ("read", Fread, Sread, 0, 1, 0, |
5de38842 PJ |
2065 | doc: /* Read one Lisp expression as text from STREAM, return as Lisp object. |
2066 | If STREAM is nil, use the value of `standard-input' (which see). | |
2067 | STREAM or the value of `standard-input' may be: | |
2068 | a buffer (read from point and advance it) | |
2069 | a marker (read from where it points and advance it) | |
2070 | a function (call it with no arguments for each character, | |
2071 | call it with a char as argument to push a char back) | |
2072 | a string (takes text from string, starting at the beginning) | |
2073 | t (read text line using minibuffer and use it, or read from | |
2074 | standard input in batch mode). */) | |
5842a27b | 2075 | (Lisp_Object stream) |
078e7b4a | 2076 | { |
5be02dff KH |
2077 | if (NILP (stream)) |
2078 | stream = Vstandard_input; | |
2079 | if (EQ (stream, Qt)) | |
2080 | stream = Qread_char; | |
5be02dff | 2081 | if (EQ (stream, Qread_char)) |
b483c570 | 2082 | /* FIXME: ?! When is this used !? */ |
30c7e542 SM |
2083 | return call1 (intern ("read-minibuffer"), |
2084 | build_string ("Lisp expression: ")); | |
078e7b4a | 2085 | |
abb13b09 | 2086 | return read_internal_start (stream, Qnil, Qnil); |
078e7b4a JB |
2087 | } |
2088 | ||
a7ca3326 | 2089 | DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0, |
5de38842 PJ |
2090 | doc: /* Read one Lisp expression which is represented as text by STRING. |
2091 | Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX). | |
a4824228 | 2092 | FINAL-STRING-INDEX is an integer giving the position of the next |
a239d4e9 | 2093 | remaining character in STRING. |
5de38842 PJ |
2094 | START and END optionally delimit a substring of STRING from which to read; |
2095 | they default to 0 and (length STRING) respectively. */) | |
5842a27b | 2096 | (Lisp_Object string, Lisp_Object start, Lisp_Object end) |
078e7b4a | 2097 | { |
2530ceaf | 2098 | Lisp_Object ret; |
b7826503 | 2099 | CHECK_STRING (string); |
48def666 | 2100 | /* `read_internal_start' sets `read_from_string_index'. */ |
2530ceaf | 2101 | ret = read_internal_start (string, start, end); |
5135ab39 | 2102 | return Fcons (ret, make_number (read_from_string_index)); |
abb13b09 | 2103 | } |
078e7b4a | 2104 | |
abb13b09 | 2105 | /* Function to set up the global context we need in toplevel read |
48def666 | 2106 | calls. */ |
abb13b09 | 2107 | static Lisp_Object |
971de7fb | 2108 | read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end) |
48def666 | 2109 | /* `start', `end' only used when stream is a string. */ |
abb13b09 CW |
2110 | { |
2111 | Lisp_Object retval; | |
078e7b4a | 2112 | |
abb13b09 | 2113 | readchar_count = 0; |
17634846 | 2114 | new_backquote_flag = 0; |
4ad679f9 | 2115 | read_objects = Qnil; |
abb13b09 CW |
2116 | if (EQ (Vread_with_symbol_positions, Qt) |
2117 | || EQ (Vread_with_symbol_positions, stream)) | |
2118 | Vread_symbol_positions_list = Qnil; | |
2119 | ||
8f924df7 KH |
2120 | if (STRINGP (stream) |
2121 | || ((CONSP (stream) && STRINGP (XCAR (stream))))) | |
abb13b09 | 2122 | { |
d311d28c | 2123 | ptrdiff_t startval, endval; |
8f924df7 | 2124 | Lisp_Object string; |
078e7b4a | 2125 | |
8f924df7 KH |
2126 | if (STRINGP (stream)) |
2127 | string = stream; | |
2128 | else | |
2129 | string = XCAR (stream); | |
078e7b4a | 2130 | |
abb13b09 | 2131 | if (NILP (end)) |
8f924df7 | 2132 | endval = SCHARS (string); |
abb13b09 CW |
2133 | else |
2134 | { | |
2135 | CHECK_NUMBER (end); | |
d311d28c | 2136 | if (! (0 <= XINT (end) && XINT (end) <= SCHARS (string))) |
8f924df7 | 2137 | args_out_of_range (string, end); |
d311d28c | 2138 | endval = XINT (end); |
abb13b09 | 2139 | } |
17634846 | 2140 | |
abb13b09 CW |
2141 | if (NILP (start)) |
2142 | startval = 0; | |
2143 | else | |
2144 | { | |
2145 | CHECK_NUMBER (start); | |
d311d28c | 2146 | if (! (0 <= XINT (start) && XINT (start) <= endval)) |
8f924df7 | 2147 | args_out_of_range (string, start); |
d311d28c | 2148 | startval = XINT (start); |
abb13b09 CW |
2149 | } |
2150 | read_from_string_index = startval; | |
8f924df7 | 2151 | read_from_string_index_byte = string_char_to_byte (string, startval); |
abb13b09 CW |
2152 | read_from_string_limit = endval; |
2153 | } | |
177c0ea7 | 2154 | |
abb13b09 CW |
2155 | retval = read0 (stream); |
2156 | if (EQ (Vread_with_symbol_positions, Qt) | |
2157 | || EQ (Vread_with_symbol_positions, stream)) | |
2158 | Vread_symbol_positions_list = Fnreverse (Vread_symbol_positions_list); | |
2159 | return retval; | |
078e7b4a JB |
2160 | } |
2161 | \f | |
336d4a9c KS |
2162 | |
2163 | /* Signal Qinvalid_read_syntax error. | |
2164 | S is error string of length N (if > 0) */ | |
2165 | ||
845ca893 | 2166 | static _Noreturn void |
e4d29b33 | 2167 | invalid_syntax (const char *s) |
336d4a9c | 2168 | { |
e4d29b33 | 2169 | xsignal1 (Qinvalid_read_syntax, build_string (s)); |
336d4a9c KS |
2170 | } |
2171 | ||
2172 | ||
6428369f | 2173 | /* Use this for recursive reads, in contexts where internal tokens |
48def666 | 2174 | are not allowed. */ |
e28552a4 | 2175 | |
078e7b4a | 2176 | static Lisp_Object |
971de7fb | 2177 | read0 (Lisp_Object readcharfun) |
078e7b4a JB |
2178 | { |
2179 | register Lisp_Object val; | |
e28552a4 | 2180 | int c; |
078e7b4a | 2181 | |
17634846 | 2182 | val = read1 (readcharfun, &c, 0); |
336d4a9c KS |
2183 | if (!c) |
2184 | return val; | |
078e7b4a | 2185 | |
336d4a9c KS |
2186 | xsignal1 (Qinvalid_read_syntax, |
2187 | Fmake_string (make_number (1), make_number (c))); | |
078e7b4a JB |
2188 | } |
2189 | \f | |
82cb60d3 | 2190 | static ptrdiff_t read_buffer_size; |
078e7b4a JB |
2191 | static char *read_buffer; |
2192 | ||
f6f79b37 | 2193 | /* Read a \-escape sequence, assuming we already read the `\'. |
8f924df7 | 2194 | If the escape sequence forces unibyte, return eight-bit char. */ |
6f7f43d5 | 2195 | |
078e7b4a | 2196 | static int |
7cded46f | 2197 | read_escape (Lisp_Object readcharfun, bool stringp) |
078e7b4a | 2198 | { |
7cded46f | 2199 | int c = READCHAR; |
9735b9ce | 2200 | /* \u allows up to four hex digits, \U up to eight. Default to the |
48def666 | 2201 | behavior for \u, and change this value in the case that \U is seen. */ |
71b169b8 | 2202 | int unicode_hex_count = 4; |
f6f79b37 | 2203 | |
078e7b4a JB |
2204 | switch (c) |
2205 | { | |
f3849f25 | 2206 | case -1: |
da3b886d | 2207 | end_of_file_error (); |
f3849f25 | 2208 | |
078e7b4a | 2209 | case 'a': |
265a9e55 | 2210 | return '\007'; |
078e7b4a JB |
2211 | case 'b': |
2212 | return '\b'; | |
f405a585 RS |
2213 | case 'd': |
2214 | return 0177; | |
078e7b4a JB |
2215 | case 'e': |
2216 | return 033; | |
2217 | case 'f': | |
2218 | return '\f'; | |
2219 | case 'n': | |
2220 | return '\n'; | |
2221 | case 'r': | |
2222 | return '\r'; | |
2223 | case 't': | |
2224 | return '\t'; | |
2225 | case 'v': | |
2226 | return '\v'; | |
2227 | case '\n': | |
2228 | return -1; | |
e28552a4 | 2229 | case ' ': |
e7fc914b KH |
2230 | if (stringp) |
2231 | return -1; | |
2232 | return ' '; | |
078e7b4a JB |
2233 | |
2234 | case 'M': | |
2235 | c = READCHAR; | |
2236 | if (c != '-') | |
2237 | error ("Invalid escape character syntax"); | |
2238 | c = READCHAR; | |
2239 | if (c == '\\') | |
8792be66 | 2240 | c = read_escape (readcharfun, 0); |
7bd279cd | 2241 | return c | meta_modifier; |
f405a585 RS |
2242 | |
2243 | case 'S': | |
2244 | c = READCHAR; | |
2245 | if (c != '-') | |
2246 | error ("Invalid escape character syntax"); | |
2247 | c = READCHAR; | |
2248 | if (c == '\\') | |
8792be66 | 2249 | c = read_escape (readcharfun, 0); |
7bd279cd RS |
2250 | return c | shift_modifier; |
2251 | ||
2252 | case 'H': | |
2253 | c = READCHAR; | |
2254 | if (c != '-') | |
2255 | error ("Invalid escape character syntax"); | |
2256 | c = READCHAR; | |
2257 | if (c == '\\') | |
8792be66 | 2258 | c = read_escape (readcharfun, 0); |
7bd279cd RS |
2259 | return c | hyper_modifier; |
2260 | ||
2261 | case 'A': | |
2262 | c = READCHAR; | |
2263 | if (c != '-') | |
2264 | error ("Invalid escape character syntax"); | |
2265 | c = READCHAR; | |
2266 | if (c == '\\') | |
8792be66 | 2267 | c = read_escape (readcharfun, 0); |
7bd279cd RS |
2268 | return c | alt_modifier; |
2269 | ||
2270 | case 's': | |
2271 | c = READCHAR; | |
4d7528d0 | 2272 | if (stringp || c != '-') |
010b7eac RS |
2273 | { |
2274 | UNREAD (c); | |
2275 | return ' '; | |
2276 | } | |
7bd279cd RS |
2277 | c = READCHAR; |
2278 | if (c == '\\') | |
8792be66 | 2279 | c = read_escape (readcharfun, 0); |
7bd279cd | 2280 | return c | super_modifier; |
078e7b4a JB |
2281 | |
2282 | case 'C': | |
2283 | c = READCHAR; | |
2284 | if (c != '-') | |
2285 | error ("Invalid escape character syntax"); | |
2286 | case '^': | |
2287 | c = READCHAR; | |
2288 | if (c == '\\') | |
8792be66 | 2289 | c = read_escape (readcharfun, 0); |
164d590d KH |
2290 | if ((c & ~CHAR_MODIFIER_MASK) == '?') |
2291 | return 0177 | (c & CHAR_MODIFIER_MASK); | |
2292 | else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))) | |
2293 | return c | ctrl_modifier; | |
f405a585 RS |
2294 | /* ASCII control chars are made from letters (both cases), |
2295 | as well as the non-letters within 0100...0137. */ | |
2296 | else if ((c & 0137) >= 0101 && (c & 0137) <= 0132) | |
2297 | return (c & (037 | ~0177)); | |
2298 | else if ((c & 0177) >= 0100 && (c & 0177) <= 0137) | |
2299 | return (c & (037 | ~0177)); | |
078e7b4a | 2300 | else |
7bd279cd | 2301 | return c | ctrl_modifier; |
078e7b4a JB |
2302 | |
2303 | case '0': | |
2304 | case '1': | |
2305 | case '2': | |
2306 | case '3': | |
2307 | case '4': | |
2308 | case '5': | |
2309 | case '6': | |
2310 | case '7': | |
2311 | /* An octal escape, as in ANSI C. */ | |
2312 | { | |
2313 | register int i = c - '0'; | |
2314 | register int count = 0; | |
2315 | while (++count < 3) | |
2316 | { | |
2317 | if ((c = READCHAR) >= '0' && c <= '7') | |
2318 | { | |
2319 | i *= 8; | |
2320 | i += c - '0'; | |
2321 | } | |
2322 | else | |
2323 | { | |
2324 | UNREAD (c); | |
2325 | break; | |
2326 | } | |
2327 | } | |
177c0ea7 | 2328 | |
8f924df7 | 2329 | if (i >= 0x80 && i < 0x100) |
8792be66 | 2330 | i = BYTE8_TO_CHAR (i); |
078e7b4a JB |
2331 | return i; |
2332 | } | |
2333 | ||
2334 | case 'x': | |
2335 | /* A hex escape, as in ANSI C. */ | |
2336 | { | |
0324f3af | 2337 | unsigned int i = 0; |
1571601b | 2338 | int count = 0; |
078e7b4a JB |
2339 | while (1) |
2340 | { | |
2341 | c = READCHAR; | |
2342 | if (c >= '0' && c <= '9') | |
2343 | { | |
2344 | i *= 16; | |
2345 | i += c - '0'; | |
2346 | } | |
2347 | else if ((c >= 'a' && c <= 'f') | |
2348 | || (c >= 'A' && c <= 'F')) | |
2349 | { | |
2350 | i *= 16; | |
2351 | if (c >= 'a' && c <= 'f') | |
2352 | i += c - 'a' + 10; | |
2353 | else | |
2354 | i += c - 'A' + 10; | |
2355 | } | |
2356 | else | |
2357 | { | |
2358 | UNREAD (c); | |
2359 | break; | |
2360 | } | |
0324f3af PE |
2361 | /* Allow hex escapes as large as ?\xfffffff, because some |
2362 | packages use them to denote characters with modifiers. */ | |
2363 | if ((CHAR_META | (CHAR_META - 1)) < i) | |
39019e54 | 2364 | error ("Hex character out of range: \\x%x...", i); |
82cb60d3 | 2365 | count += count < 3; |
078e7b4a | 2366 | } |
f6f79b37 | 2367 | |
1571601b | 2368 | if (count < 3 && i >= 0x80) |
8792be66 | 2369 | return BYTE8_TO_CHAR (i); |
078e7b4a JB |
2370 | return i; |
2371 | } | |
2372 | ||
71b169b8 EZ |
2373 | case 'U': |
2374 | /* Post-Unicode-2.0: Up to eight hex chars. */ | |
2375 | unicode_hex_count = 8; | |
2376 | case 'u': | |
2377 | ||
9735b9ce | 2378 | /* A Unicode escape. We only permit them in strings and characters, |
71b169b8 EZ |
2379 | not arbitrarily in the source code, as in some other languages. */ |
2380 | { | |
a808f22d | 2381 | unsigned int i = 0; |
71b169b8 | 2382 | int count = 0; |
71b169b8 EZ |
2383 | |
2384 | while (++count <= unicode_hex_count) | |
2385 | { | |
2386 | c = READCHAR; | |
48def666 SM |
2387 | /* `isdigit' and `isalpha' may be locale-specific, which we don't |
2388 | want. */ | |
71b169b8 EZ |
2389 | if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); |
2390 | else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; | |
2391 | else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; | |
2392 | else | |
39019e54 | 2393 | error ("Non-hex digit used for Unicode escape"); |
71b169b8 | 2394 | } |
a808f22d KH |
2395 | if (i > 0x10FFFF) |
2396 | error ("Non-Unicode character: 0x%x", i); | |
7ea7f636 | 2397 | return i; |
71b169b8 EZ |
2398 | } |
2399 | ||
078e7b4a JB |
2400 | default: |
2401 | return c; | |
2402 | } | |
2403 | } | |
2404 | ||
a108c10b PE |
2405 | /* Return the digit that CHARACTER stands for in the given BASE. |
2406 | Return -1 if CHARACTER is out of range for BASE, | |
2407 | and -2 if CHARACTER is not valid for any supported BASE. */ | |
b0ab8123 | 2408 | static int |
a108c10b PE |
2409 | digit_to_number (int character, int base) |
2410 | { | |
2411 | int digit; | |
2412 | ||
2413 | if ('0' <= character && character <= '9') | |
2414 | digit = character - '0'; | |
2415 | else if ('a' <= character && character <= 'z') | |
2416 | digit = character - 'a' + 10; | |
2417 | else if ('A' <= character && character <= 'Z') | |
2418 | digit = character - 'A' + 10; | |
2419 | else | |
2420 | return -2; | |
2421 | ||
2422 | return digit < base ? digit : -1; | |
2423 | } | |
2424 | ||
bf5d1a17 GM |
2425 | /* Read an integer in radix RADIX using READCHARFUN to read |
2426 | characters. RADIX must be in the interval [2..36]; if it isn't, a | |
2427 | read error is signaled . Value is the integer read. Signals an | |
2428 | error if encountering invalid read syntax or if RADIX is out of | |
2429 | range. */ | |
2430 | ||
2431 | static Lisp_Object | |
8b9ac8b4 | 2432 | read_integer (Lisp_Object readcharfun, EMACS_INT radix) |
bf5d1a17 | 2433 | { |
8b9ac8b4 PE |
2434 | /* Room for sign, leading 0, other digits, trailing null byte. |
2435 | Also, room for invalid syntax diagnostic. */ | |
2436 | char buf[max (1 + 1 + sizeof (uintmax_t) * CHAR_BIT + 1, | |
2437 | sizeof "integer, radix " + INT_STRLEN_BOUND (EMACS_INT))]; | |
a108c10b PE |
2438 | |
2439 | int valid = -1; /* 1 if valid, 0 if not, -1 if incomplete. */ | |
bf5d1a17 GM |
2440 | |
2441 | if (radix < 2 || radix > 36) | |
a108c10b | 2442 | valid = 0; |
bf5d1a17 GM |
2443 | else |
2444 | { | |
a108c10b PE |
2445 | char *p = buf; |
2446 | int c, digit; | |
bf5d1a17 GM |
2447 | |
2448 | c = READCHAR; | |
a108c10b | 2449 | if (c == '-' || c == '+') |
bf5d1a17 | 2450 | { |
a108c10b | 2451 | *p++ = c; |
bf5d1a17 | 2452 | c = READCHAR; |
bf5d1a17 | 2453 | } |
177c0ea7 | 2454 | |
a108c10b | 2455 | if (c == '0') |
bf5d1a17 | 2456 | { |
a108c10b PE |
2457 | *p++ = c; |
2458 | valid = 1; | |
bf5d1a17 | 2459 | |
a108c10b PE |
2460 | /* Ignore redundant leading zeros, so the buffer doesn't |
2461 | fill up with them. */ | |
2462 | do | |
2463 | c = READCHAR; | |
2464 | while (c == '0'); | |
2465 | } | |
2466 | ||
908589fd | 2467 | while ((digit = digit_to_number (c, radix)) >= -1) |
a108c10b PE |
2468 | { |
2469 | if (digit == -1) | |
2470 | valid = 0; | |
2471 | if (valid < 0) | |
2472 | valid = 1; | |
2473 | ||
2474 | if (p < buf + sizeof buf - 1) | |
2475 | *p++ = c; | |
2476 | else | |
2477 | valid = 0; | |
bf5d1a17 | 2478 | |
bf5d1a17 GM |
2479 | c = READCHAR; |
2480 | } | |
a108c10b | 2481 | |
0a6a104b | 2482 | UNREAD (c); |
a108c10b | 2483 | *p = '\0'; |
bf5d1a17 GM |
2484 | } |
2485 | ||
a108c10b | 2486 | if (! valid) |
bf5d1a17 | 2487 | { |
8b9ac8b4 | 2488 | sprintf (buf, "integer, radix %"pI"d", radix); |
e4d29b33 | 2489 | invalid_syntax (buf); |
bf5d1a17 GM |
2490 | } |
2491 | ||
a108c10b | 2492 | return string_to_number (buf, radix, 0); |
bf5d1a17 GM |
2493 | } |
2494 | ||
2495 | ||
6428369f KH |
2496 | /* If the next token is ')' or ']' or '.', we store that character |
2497 | in *PCH and the return value is not interesting. Else, we store | |
17634846 RS |
2498 | zero in *PCH and we read and return one lisp object. |
2499 | ||
7cded46f | 2500 | FIRST_IN_LIST is true if this is the first element of a list. */ |
17634846 | 2501 | |
078e7b4a | 2502 | static Lisp_Object |
7cded46f | 2503 | read1 (Lisp_Object readcharfun, int *pch, bool first_in_list) |
078e7b4a | 2504 | { |
fce31d69 PE |
2505 | int c; |
2506 | bool uninterned_symbol = 0; | |
2507 | bool multibyte; | |
4ad679f9 | 2508 | |
6428369f | 2509 | *pch = 0; |
078e7b4a JB |
2510 | |
2511 | retry: | |
2512 | ||
1202434b | 2513 | c = READCHAR_REPORT_MULTIBYTE (&multibyte); |
9c97398c GM |
2514 | if (c < 0) |
2515 | end_of_file_error (); | |
078e7b4a JB |
2516 | |
2517 | switch (c) | |
2518 | { | |
2519 | case '(': | |
2520 | return read_list (0, readcharfun); | |
2521 | ||
2522 | case '[': | |
c15cfd1f | 2523 | return read_vector (readcharfun, 0); |
078e7b4a JB |
2524 | |
2525 | case ')': | |
2526 | case ']': | |
078e7b4a | 2527 | { |
6428369f KH |
2528 | *pch = c; |
2529 | return Qnil; | |
078e7b4a JB |
2530 | } |
2531 | ||
2532 | case '#': | |
200f684e | 2533 | c = READCHAR; |
f19a0f5b TZ |
2534 | if (c == 's') |
2535 | { | |
2536 | c = READCHAR; | |
2537 | if (c == '(') | |
2538 | { | |
2539 | /* Accept extended format for hashtables (extensible to | |
2540 | other types), e.g. | |
48def666 | 2541 | #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */ |
f19a0f5b TZ |
2542 | Lisp_Object tmp = read_list (0, readcharfun); |
2543 | Lisp_Object head = CAR_SAFE (tmp); | |
2544 | Lisp_Object data = Qnil; | |
2545 | Lisp_Object val = Qnil; | |
2546 | /* The size is 2 * number of allowed keywords to | |
48def666 | 2547 | make-hash-table. */ |
9735b9ce | 2548 | Lisp_Object params[10]; |
f19a0f5b TZ |
2549 | Lisp_Object ht; |
2550 | Lisp_Object key = Qnil; | |
2551 | int param_count = 0; | |
9735b9ce | 2552 | |
f19a0f5b TZ |
2553 | if (!EQ (head, Qhash_table)) |
2554 | error ("Invalid extended read marker at head of #s list " | |
2555 | "(only hash-table allowed)"); | |
9735b9ce | 2556 | |
f19a0f5b TZ |
2557 | tmp = CDR_SAFE (tmp); |
2558 | ||
48def666 | 2559 | /* This is repetitive but fast and simple. */ |
f19a0f5b | 2560 | params[param_count] = QCsize; |
48def666 | 2561 | params[param_count + 1] = Fplist_get (tmp, Qsize); |
5721b4ed AS |
2562 | if (!NILP (params[param_count + 1])) |
2563 | param_count += 2; | |
f19a0f5b TZ |
2564 | |
2565 | params[param_count] = QCtest; | |
48def666 | 2566 | params[param_count + 1] = Fplist_get (tmp, Qtest); |
5721b4ed AS |
2567 | if (!NILP (params[param_count + 1])) |
2568 | param_count += 2; | |
f19a0f5b TZ |
2569 | |
2570 | params[param_count] = QCweakness; | |
48def666 | 2571 | params[param_count + 1] = Fplist_get (tmp, Qweakness); |
5721b4ed AS |
2572 | if (!NILP (params[param_count + 1])) |
2573 | param_count += 2; | |
f19a0f5b TZ |
2574 | |
2575 | params[param_count] = QCrehash_size; | |
48def666 | 2576 | params[param_count + 1] = Fplist_get (tmp, Qrehash_size); |
5721b4ed AS |
2577 | if (!NILP (params[param_count + 1])) |
2578 | param_count += 2; | |
f19a0f5b TZ |
2579 | |
2580 | params[param_count] = QCrehash_threshold; | |
48def666 | 2581 | params[param_count + 1] = Fplist_get (tmp, Qrehash_threshold); |
5721b4ed AS |
2582 | if (!NILP (params[param_count + 1])) |
2583 | param_count += 2; | |
f19a0f5b | 2584 | |
48def666 | 2585 | /* This is the hashtable data. */ |
f19a0f5b TZ |
2586 | data = Fplist_get (tmp, Qdata); |
2587 | ||
48def666 | 2588 | /* Now use params to make a new hashtable and fill it. */ |
f19a0f5b | 2589 | ht = Fmake_hash_table (param_count, params); |
9735b9ce | 2590 | |
f19a0f5b TZ |
2591 | while (CONSP (data)) |
2592 | { | |
2593 | key = XCAR (data); | |
2594 | data = XCDR (data); | |
2595 | if (!CONSP (data)) | |
2596 | error ("Odd number of elements in hashtable data"); | |
2597 | val = XCAR (data); | |
2598 | data = XCDR (data); | |
2599 | Fputhash (key, val, ht); | |
2600 | } | |
9735b9ce | 2601 | |
f19a0f5b TZ |
2602 | return ht; |
2603 | } | |
5721b4ed | 2604 | UNREAD (c); |
e4d29b33 | 2605 | invalid_syntax ("#"); |
f19a0f5b | 2606 | } |
c2390933 RS |
2607 | if (c == '^') |
2608 | { | |
2609 | c = READCHAR; | |
2610 | if (c == '[') | |
2611 | { | |
2612 | Lisp_Object tmp; | |
c15cfd1f | 2613 | tmp = read_vector (readcharfun, 0); |
77b37c05 | 2614 | if (ASIZE (tmp) < CHAR_TABLE_STANDARD_SLOTS) |
c2390933 | 2615 | error ("Invalid size char-table"); |
985773c9 | 2616 | XSETPVECTYPE (XVECTOR (tmp), PVEC_CHAR_TABLE); |
c2390933 RS |
2617 | return tmp; |
2618 | } | |
3701b5de KH |
2619 | else if (c == '^') |
2620 | { | |
2621 | c = READCHAR; | |
2622 | if (c == '[') | |
2623 | { | |
2624 | Lisp_Object tmp; | |
d311d28c PE |
2625 | int depth; |
2626 | ptrdiff_t size; | |
8f924df7 | 2627 | |
c15cfd1f | 2628 | tmp = read_vector (readcharfun, 0); |
6efdadfd PE |
2629 | size = ASIZE (tmp); |
2630 | if (size == 0) | |
2631 | error ("Invalid size char-table"); | |
d311d28c | 2632 | if (! RANGED_INTEGERP (1, AREF (tmp, 0), 3)) |
1571601b KH |
2633 | error ("Invalid depth in char-table"); |
2634 | depth = XINT (AREF (tmp, 0)); | |
6efdadfd | 2635 | if (chartab_size[depth] != size - 2) |
3701b5de | 2636 | error ("Invalid size char-table"); |
985773c9 | 2637 | XSETPVECTYPE (XVECTOR (tmp), PVEC_SUB_CHAR_TABLE); |
3701b5de KH |
2638 | return tmp; |
2639 | } | |
1761305f | 2640 | invalid_syntax ("#^" "^"); |
3701b5de | 2641 | } |
e4d29b33 | 2642 | invalid_syntax ("#^"); |
c2390933 RS |
2643 | } |
2644 | if (c == '&') | |
2645 | { | |
2646 | Lisp_Object length; | |
2647 | length = read1 (readcharfun, pch, first_in_list); | |
2648 | c = READCHAR; | |
2649 | if (c == '"') | |
2650 | { | |
2651 | Lisp_Object tmp, val; | |
2cf00efc | 2652 | EMACS_INT size_in_chars = bool_vector_bytes (XFASTINT (length)); |
df5b4930 | 2653 | unsigned char *data; |
c2390933 RS |
2654 | |
2655 | UNREAD (c); | |
2656 | tmp = read1 (readcharfun, pch, first_in_list); | |
8792be66 | 2657 | if (STRING_MULTIBYTE (tmp) |
8f924df7 | 2658 | || (size_in_chars != SCHARS (tmp) |
8792be66 KH |
2659 | /* We used to print 1 char too many |
2660 | when the number of bits was a multiple of 8. | |
2661 | Accept such input in case it came from an old | |
2662 | version. */ | |
2663 | && ! (XFASTINT (length) | |
327719ee | 2664 | == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR))) |
e4d29b33 | 2665 | invalid_syntax ("#&..."); |
177c0ea7 | 2666 | |
2cf00efc | 2667 | val = make_uninit_bool_vector (XFASTINT (length)); |
df5b4930 PE |
2668 | data = bool_vector_uchar_data (val); |
2669 | memcpy (data, SDATA (tmp), size_in_chars); | |
67d3b149 | 2670 | /* Clear the extraneous bits in the last byte. */ |
d1ca81d9 | 2671 | if (XINT (length) != size_in_chars * BOOL_VECTOR_BITS_PER_CHAR) |
df5b4930 | 2672 | data[size_in_chars - 1] |
d1ca81d9 | 2673 | &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1; |
c2390933 RS |
2674 | return val; |
2675 | } | |
e4d29b33 | 2676 | invalid_syntax ("#&..."); |
c2390933 | 2677 | } |
200f684e | 2678 | if (c == '[') |
876c194c SM |
2679 | { |
2680 | /* Accept compiled functions at read-time so that we don't have to | |
2681 | build them using function calls. */ | |
2682 | Lisp_Object tmp; | |
56a0e352 | 2683 | struct Lisp_Vector *vec; |
876c194c | 2684 | tmp = read_vector (readcharfun, 1); |
56a0e352 PE |
2685 | vec = XVECTOR (tmp); |
2686 | if (vec->header.size == 0) | |
ba355de0 BR |
2687 | invalid_syntax ("Empty byte-code object"); |
2688 | make_byte_code (vec); | |
3017f87f | 2689 | return tmp; |
876c194c | 2690 | } |
748ef62f RS |
2691 | if (c == '(') |
2692 | { | |
2693 | Lisp_Object tmp; | |
2694 | struct gcpro gcpro1; | |
e28552a4 | 2695 | int ch; |
748ef62f RS |
2696 | |
2697 | /* Read the string itself. */ | |
17634846 | 2698 | tmp = read1 (readcharfun, &ch, 0); |
6428369f | 2699 | if (ch != 0 || !STRINGP (tmp)) |
e4d29b33 | 2700 | invalid_syntax ("#"); |
748ef62f RS |
2701 | GCPRO1 (tmp); |
2702 | /* Read the intervals and their properties. */ | |
2703 | while (1) | |
2704 | { | |
2705 | Lisp_Object beg, end, plist; | |
2706 | ||
17634846 | 2707 | beg = read1 (readcharfun, &ch, 0); |
7ee3bd7b | 2708 | end = plist = Qnil; |
6428369f KH |
2709 | if (ch == ')') |
2710 | break; | |
2711 | if (ch == 0) | |
17634846 | 2712 | end = read1 (readcharfun, &ch, 0); |
6428369f | 2713 | if (ch == 0) |
17634846 | 2714 | plist = read1 (readcharfun, &ch, 0); |
6428369f | 2715 | if (ch) |
e4d29b33 | 2716 | invalid_syntax ("Invalid string property list"); |
748ef62f RS |
2717 | Fset_text_properties (beg, end, plist, tmp); |
2718 | } | |
2719 | UNGCPRO; | |
2720 | return tmp; | |
2721 | } | |
177c0ea7 | 2722 | |
75a65c7e | 2723 | /* #@NUMBER is used to skip NUMBER following bytes. |
20ea2964 RS |
2724 | That's used in .elc files to skip over doc strings |
2725 | and function definitions. */ | |
2726 | if (c == '@') | |
2727 | { | |
bfbbd7e7 | 2728 | enum { extra = 100 }; |
759fd763 | 2729 | ptrdiff_t i, nskip = 0, digits = 0; |
20ea2964 RS |
2730 | |
2731 | /* Read a decimal integer. */ | |
2732 | while ((c = READCHAR) >= 0 | |
2733 | && c >= '0' && c <= '9') | |
2734 | { | |
bfbbd7e7 PE |
2735 | if ((STRING_BYTES_BOUND - extra) / 10 <= nskip) |
2736 | string_overflow (); | |
759fd763 | 2737 | digits++; |
20ea2964 RS |
2738 | nskip *= 10; |
2739 | nskip += c - '0'; | |
759fd763 SM |
2740 | if (digits == 2 && nskip == 0) |
2741 | { /* We've just seen #@00, which means "skip to end". */ | |
2742 | skip_dyn_eof (readcharfun); | |
2743 | return Qnil; | |
2744 | } | |
20ea2964 | 2745 | } |
75a65c7e SM |
2746 | if (nskip > 0) |
2747 | /* We can't use UNREAD here, because in the code below we side-step | |
2748 | READCHAR. Instead, assume the first char after #@NNN occupies | |
2749 | a single byte, which is the case normally since it's just | |
2750 | a space. */ | |
2751 | nskip--; | |
2752 | else | |
2753 | UNREAD (c); | |
7216e43b | 2754 | |
8792be66 | 2755 | if (load_force_doc_strings |
d2e24f92 | 2756 | && (FROM_FILE_P (readcharfun))) |
b2a30870 RS |
2757 | { |
2758 | /* If we are supposed to force doc strings into core right now, | |
2759 | record the last string that we skipped, | |
2760 | and record where in the file it comes from. */ | |
c15cfd1f RS |
2761 | |
2762 | /* But first exchange saved_doc_string | |
2763 | with prev_saved_doc_string, so we save two strings. */ | |
2764 | { | |
2765 | char *temp = saved_doc_string; | |
bfbbd7e7 | 2766 | ptrdiff_t temp_size = saved_doc_string_size; |
68c45bf0 | 2767 | file_offset temp_pos = saved_doc_string_position; |
bfbbd7e7 | 2768 | ptrdiff_t temp_len = saved_doc_string_length; |
c15cfd1f RS |
2769 | |
2770 | saved_doc_string = prev_saved_doc_string; | |
2771 | saved_doc_string_size = prev_saved_doc_string_size; | |
2772 | saved_doc_string_position = prev_saved_doc_string_position; | |
2773 | saved_doc_string_length = prev_saved_doc_string_length; | |
2774 | ||
2775 | prev_saved_doc_string = temp; | |
2776 | prev_saved_doc_string_size = temp_size; | |
2777 | prev_saved_doc_string_position = temp_pos; | |
2778 | prev_saved_doc_string_length = temp_len; | |
2779 | } | |
2780 | ||
b2a30870 RS |
2781 | if (saved_doc_string_size == 0) |
2782 | { | |
c1ade6f7 | 2783 | saved_doc_string = xmalloc_atomic (nskip + extra); |
bfbbd7e7 | 2784 | saved_doc_string_size = nskip + extra; |
b2a30870 RS |
2785 | } |
2786 | if (nskip > saved_doc_string_size) | |
2787 | { | |
38182d90 | 2788 | saved_doc_string = xrealloc (saved_doc_string, nskip + extra); |
37d0112b | 2789 | saved_doc_string_size = nskip + extra; |
b2a30870 RS |
2790 | } |
2791 | ||
68c45bf0 | 2792 | saved_doc_string_position = file_tell (instream); |
b2a30870 RS |
2793 | |
2794 | /* Copy that many characters into saved_doc_string. */ | |
75a65c7e | 2795 | block_input (); |
b2a30870 | 2796 | for (i = 0; i < nskip && c >= 0; i++) |
75a65c7e SM |
2797 | saved_doc_string[i] = c = getc (instream); |
2798 | unblock_input (); | |
b2a30870 RS |
2799 | |
2800 | saved_doc_string_length = i; | |
2801 | } | |
2802 | else | |
75a65c7e SM |
2803 | /* Skip that many bytes. */ |
2804 | skip_dyn_bytes (readcharfun, nskip); | |
d49f0c1a | 2805 | |
20ea2964 RS |
2806 | goto retry; |
2807 | } | |
e2518d02 RS |
2808 | if (c == '!') |
2809 | { | |
2810 | /* #! appears at the beginning of an executable file. | |
2811 | Skip the first line. */ | |
225c7a07 | 2812 | while (c != '\n' && c >= 0) |
e2518d02 RS |
2813 | c = READCHAR; |
2814 | goto retry; | |
2815 | } | |
20ea2964 RS |
2816 | if (c == '$') |
2817 | return Vload_file_name; | |
2b6cae0c | 2818 | if (c == '\'') |
6c6f1994 | 2819 | return list2 (Qfunction, read0 (readcharfun)); |
4ad679f9 EN |
2820 | /* #:foo is the uninterned symbol named foo. */ |
2821 | if (c == ':') | |
2822 | { | |
2823 | uninterned_symbol = 1; | |
2824 | c = READCHAR; | |
52968808 | 2825 | if (!(c > 040 |
ed497dd4 | 2826 | && c != 0xa0 /* NBSP */ |
52968808 | 2827 | && (c >= 0200 |
0a6a104b | 2828 | || strchr ("\"';()[]#`,", c) == NULL))) |
52968808 AS |
2829 | { |
2830 | /* No symbol character follows, this is the empty | |
2831 | symbol. */ | |
0a6a104b | 2832 | UNREAD (c); |
4a7edc24 | 2833 | return Fmake_symbol (empty_unibyte_string); |
52968808 AS |
2834 | } |
2835 | goto read_symbol; | |
4ad679f9 | 2836 | } |
9a79b20c AS |
2837 | /* ## is the empty symbol. */ |
2838 | if (c == '#') | |
4a7edc24 | 2839 | return Fintern (empty_unibyte_string, Qnil); |
4ad679f9 EN |
2840 | /* Reader forms that can reuse previously read objects. */ |
2841 | if (c >= '0' && c <= '9') | |
2842 | { | |
8b9ac8b4 | 2843 | EMACS_INT n = 0; |
4ad679f9 | 2844 | Lisp_Object tem; |
2b6cae0c | 2845 | |
4ad679f9 EN |
2846 | /* Read a non-negative integer. */ |
2847 | while (c >= '0' && c <= '9') | |
2848 | { | |
7216e43b PE |
2849 | if (MOST_POSITIVE_FIXNUM / 10 < n |
2850 | || MOST_POSITIVE_FIXNUM < n * 10 + c - '0') | |
8b9ac8b4 PE |
2851 | n = MOST_POSITIVE_FIXNUM + 1; |
2852 | else | |
2853 | n = n * 10 + c - '0'; | |
4ad679f9 EN |
2854 | c = READCHAR; |
2855 | } | |
8b9ac8b4 PE |
2856 | |
2857 | if (n <= MOST_POSITIVE_FIXNUM) | |
4ad679f9 | 2858 | { |
8b9ac8b4 PE |
2859 | if (c == 'r' || c == 'R') |
2860 | return read_integer (readcharfun, n); | |
9e062b6c | 2861 | |
8b9ac8b4 PE |
2862 | if (! NILP (Vread_circle)) |
2863 | { | |
2864 | /* #n=object returns object, but associates it with | |
2865 | n for #n#. */ | |
2866 | if (c == '=') | |
2867 | { | |
48def666 | 2868 | /* Make a placeholder for #n# to use temporarily. */ |
8b9ac8b4 PE |
2869 | Lisp_Object placeholder; |
2870 | Lisp_Object cell; | |
9e062b6c | 2871 | |
8b9ac8b4 PE |
2872 | placeholder = Fcons (Qnil, Qnil); |
2873 | cell = Fcons (make_number (n), placeholder); | |
2874 | read_objects = Fcons (cell, read_objects); | |
9e062b6c | 2875 | |
48def666 | 2876 | /* Read the object itself. */ |
8b9ac8b4 | 2877 | tem = read0 (readcharfun); |
9e062b6c | 2878 | |
48def666 | 2879 | /* Now put it everywhere the placeholder was... */ |
8b9ac8b4 | 2880 | substitute_object_in_subtree (tem, placeholder); |
177c0ea7 | 2881 | |
8b9ac8b4 PE |
2882 | /* ...and #n# will use the real value from now on. */ |
2883 | Fsetcdr (cell, tem); | |
177c0ea7 | 2884 | |
8b9ac8b4 PE |
2885 | return tem; |
2886 | } | |
2887 | ||
2888 | /* #n# returns a previously read object. */ | |
2889 | if (c == '#') | |
2890 | { | |
2891 | tem = Fassq (make_number (n), read_objects); | |
2892 | if (CONSP (tem)) | |
2893 | return XCDR (tem); | |
2894 | } | |
2895 | } | |
2896 | } | |
4ad679f9 EN |
2897 | /* Fall through to error message. */ |
2898 | } | |
bf5d1a17 GM |
2899 | else if (c == 'x' || c == 'X') |
2900 | return read_integer (readcharfun, 16); | |
2901 | else if (c == 'o' || c == 'O') | |
2902 | return read_integer (readcharfun, 8); | |
2903 | else if (c == 'b' || c == 'B') | |
2904 | return read_integer (readcharfun, 2); | |
20ea2964 | 2905 | |
200f684e | 2906 | UNREAD (c); |
e4d29b33 | 2907 | invalid_syntax ("#"); |
078e7b4a JB |
2908 | |
2909 | case ';': | |
2910 | while ((c = READCHAR) >= 0 && c != '\n'); | |
2911 | goto retry; | |
2912 | ||
2913 | case '\'': | |
6c6f1994 | 2914 | return list2 (Qquote, read0 (readcharfun)); |
078e7b4a | 2915 | |
17634846 | 2916 | case '`': |
9a39b306 TO |
2917 | { |
2918 | int next_char = READCHAR; | |
2919 | UNREAD (next_char); | |
2920 | /* Transition from old-style to new-style: | |
2921 | If we see "(`" it used to mean old-style, which usually works | |
2922 | fine because ` should almost never appear in such a position | |
2923 | for new-style. But occasionally we need "(`" to mean new | |
2924 | style, so we try to distinguish the two by the fact that we | |
2925 | can either write "( `foo" or "(` foo", where the first | |
2926 | intends to use new-style whereas the second intends to use | |
2927 | old-style. For Emacs-25, we should completely remove this | |
2928 | first_in_list exception (old-style can still be obtained via | |
2929 | "(\`" anyway). */ | |
bba3e508 | 2930 | if (!new_backquote_flag && first_in_list && next_char == ' ') |
9a39b306 TO |
2931 | { |
2932 | Vold_style_backquotes = Qt; | |
2933 | goto default_label; | |
2934 | } | |
2935 | else | |
2936 | { | |
2937 | Lisp_Object value; | |
7cded46f | 2938 | bool saved_new_backquote_flag = new_backquote_flag; |
17634846 | 2939 | |
7cded46f | 2940 | new_backquote_flag = 1; |
9a39b306 | 2941 | value = read0 (readcharfun); |
7cded46f | 2942 | new_backquote_flag = saved_new_backquote_flag; |
17634846 | 2943 | |
6c6f1994 | 2944 | return list2 (Qbackquote, value); |
9a39b306 TO |
2945 | } |
2946 | } | |
17634846 | 2947 | case ',': |
bba3e508 SM |
2948 | { |
2949 | int next_char = READCHAR; | |
2950 | UNREAD (next_char); | |
2951 | /* Transition from old-style to new-style: | |
2952 | It used to be impossible to have a new-style , other than within | |
2953 | a new-style `. This is sufficient when ` and , are used in the | |
2954 | normal way, but ` and , can also appear in args to macros that | |
2955 | will not interpret them in the usual way, in which case , may be | |
2956 | used without any ` anywhere near. | |
2957 | So we now use the same heuristic as for backquote: old-style | |
2958 | unquotes are only recognized when first on a list, and when | |
2959 | followed by a space. | |
333f9019 | 2960 | Because it's more difficult to peek 2 chars ahead, a new-style |
bba3e508 SM |
2961 | ,@ can still not be used outside of a `, unless it's in the middle |
2962 | of a list. */ | |
2963 | if (new_backquote_flag | |
2964 | || !first_in_list | |
2965 | || (next_char != ' ' && next_char != '@')) | |
2966 | { | |
2967 | Lisp_Object comma_type = Qnil; | |
2968 | Lisp_Object value; | |
2969 | int ch = READCHAR; | |
17634846 | 2970 | |
bba3e508 SM |
2971 | if (ch == '@') |
2972 | comma_type = Qcomma_at; | |
2973 | else if (ch == '.') | |
2974 | comma_type = Qcomma_dot; | |
2975 | else | |
2976 | { | |
2977 | if (ch >= 0) UNREAD (ch); | |
2978 | comma_type = Qcomma; | |
2979 | } | |
17634846 | 2980 | |
bba3e508 | 2981 | value = read0 (readcharfun); |
6c6f1994 | 2982 | return list2 (comma_type, value); |
bba3e508 SM |
2983 | } |
2984 | else | |
2985 | { | |
2986 | Vold_style_backquotes = Qt; | |
2987 | goto default_label; | |
2988 | } | |
2989 | } | |
078e7b4a JB |
2990 | case '?': |
2991 | { | |
8792be66 | 2992 | int modifiers; |
df9c2be7 | 2993 | int next_char; |
7cded46f | 2994 | bool ok; |
f6f79b37 | 2995 | |
078e7b4a | 2996 | c = READCHAR; |
9c97398c GM |
2997 | if (c < 0) |
2998 | end_of_file_error (); | |
078e7b4a | 2999 | |
b9284371 KS |
3000 | /* Accept `single space' syntax like (list ? x) where the |
3001 | whitespace character is SPC or TAB. | |
3002 | Other literal whitespace like NL, CR, and FF are not accepted, | |
3003 | as there are well-established escape sequences for these. */ | |
3004 | if (c == ' ' || c == '\t') | |
3005 | return make_number (c); | |
3006 | ||
078e7b4a | 3007 | if (c == '\\') |
8792be66 KH |
3008 | c = read_escape (readcharfun, 0); |
3009 | modifiers = c & CHAR_MODIFIER_MASK; | |
3010 | c &= ~CHAR_MODIFIER_MASK; | |
3011 | if (CHAR_BYTE8_P (c)) | |
3012 | c = CHAR_TO_BYTE8 (c); | |
3013 | c |= modifiers; | |
078e7b4a | 3014 | |
df9c2be7 | 3015 | next_char = READCHAR; |
bba3e508 SM |
3016 | ok = (next_char <= 040 |
3017 | || (next_char < 0200 | |
0a6a104b | 3018 | && strchr ("\"';()[]#?`,.", next_char) != NULL)); |
df9c2be7 | 3019 | UNREAD (next_char); |
336d4a9c KS |
3020 | if (ok) |
3021 | return make_number (c); | |
37cd4238 | 3022 | |
e4d29b33 | 3023 | invalid_syntax ("?"); |
078e7b4a JB |
3024 | } |
3025 | ||
00a9a935 | 3026 | case '"': |
078e7b4a | 3027 | { |
a742d646 GM |
3028 | char *p = read_buffer; |
3029 | char *end = read_buffer + read_buffer_size; | |
7cded46f PE |
3030 | int ch; |
3031 | /* True if we saw an escape sequence specifying | |
1571601b | 3032 | a multibyte character. */ |
7cded46f PE |
3033 | bool force_multibyte = 0; |
3034 | /* True if we saw an escape sequence specifying | |
e7fc914b | 3035 | a single-byte character. */ |
7cded46f PE |
3036 | bool force_singlebyte = 0; |
3037 | bool cancel = 0; | |
82cb60d3 | 3038 | ptrdiff_t nchars = 0; |
078e7b4a | 3039 | |
0902fe45 PE |
3040 | while ((ch = READCHAR) >= 0 |
3041 | && ch != '\"') | |
078e7b4a | 3042 | { |
449fea39 | 3043 | if (end - p < MAX_MULTIBYTE_LENGTH) |
078e7b4a | 3044 | { |
82cb60d3 | 3045 | ptrdiff_t offset = p - read_buffer; |
7216e43b | 3046 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) |
20270765 | 3047 | memory_full (SIZE_MAX); |
38182d90 | 3048 | read_buffer = xrealloc (read_buffer, read_buffer_size * 2); |
37d0112b | 3049 | read_buffer_size *= 2; |
5d65df0d | 3050 | p = read_buffer + offset; |
078e7b4a JB |
3051 | end = read_buffer + read_buffer_size; |
3052 | } | |
bed23cb2 | 3053 | |
0902fe45 | 3054 | if (ch == '\\') |
03e88613 | 3055 | { |
1571601b | 3056 | int modifiers; |
f6f79b37 | 3057 | |
0902fe45 | 3058 | ch = read_escape (readcharfun, 1); |
bed23cb2 | 3059 | |
48def666 | 3060 | /* CH is -1 if \ newline has just been seen. */ |
0902fe45 | 3061 | if (ch == -1) |
03e88613 | 3062 | { |
bed23cb2 RS |
3063 | if (p == read_buffer) |
3064 | cancel = 1; | |
03e88613 RS |
3065 | continue; |
3066 | } | |
bed23cb2 | 3067 | |
0902fe45 PE |
3068 | modifiers = ch & CHAR_MODIFIER_MASK; |
3069 | ch = ch & ~CHAR_MODIFIER_MASK; | |
1571601b | 3070 | |
0902fe45 | 3071 | if (CHAR_BYTE8_P (ch)) |
e7fc914b | 3072 | force_singlebyte = 1; |
0902fe45 | 3073 | else if (! ASCII_CHAR_P (ch)) |
f6f79b37 | 3074 | force_multibyte = 1; |
48def666 | 3075 | else /* I.e. ASCII_CHAR_P (ch). */ |
1571601b KH |
3076 | { |
3077 | /* Allow `\C- ' and `\C-?'. */ | |
3078 | if (modifiers == CHAR_CTL) | |
3079 | { | |
0902fe45 PE |
3080 | if (ch == ' ') |
3081 | ch = 0, modifiers = 0; | |
3082 | else if (ch == '?') | |
3083 | ch = 127, modifiers = 0; | |
1571601b KH |
3084 | } |
3085 | if (modifiers & CHAR_SHIFT) | |
3086 | { | |
3087 | /* Shift modifier is valid only with [A-Za-z]. */ | |
0902fe45 | 3088 | if (ch >= 'A' && ch <= 'Z') |
1571601b | 3089 | modifiers &= ~CHAR_SHIFT; |
0902fe45 PE |
3090 | else if (ch >= 'a' && ch <= 'z') |
3091 | ch -= ('a' - 'A'), modifiers &= ~CHAR_SHIFT; | |
1571601b KH |
3092 | } |
3093 | ||
3094 | if (modifiers & CHAR_META) | |
3095 | { | |
3096 | /* Move the meta bit to the right place for a | |
3097 | string. */ | |
3098 | modifiers &= ~CHAR_META; | |
0902fe45 | 3099 | ch = BYTE8_TO_CHAR (ch | 0x80); |
1571601b KH |
3100 | force_singlebyte = 1; |
3101 | } | |
3102 | } | |
5150eeec | 3103 | |
1571601b KH |
3104 | /* Any modifiers remaining are invalid. */ |
3105 | if (modifiers) | |
3106 | error ("Invalid modifier in string"); | |
0902fe45 | 3107 | p += CHAR_STRING (ch, (unsigned char *) p); |
078e7b4a | 3108 | } |
8792be66 | 3109 | else |
5150eeec | 3110 | { |
0902fe45 PE |
3111 | p += CHAR_STRING (ch, (unsigned char *) p); |
3112 | if (CHAR_BYTE8_P (ch)) | |
988f7a0c | 3113 | force_singlebyte = 1; |
0902fe45 | 3114 | else if (! ASCII_CHAR_P (ch)) |
988f7a0c | 3115 | force_multibyte = 1; |
f943104a | 3116 | } |
5150eeec | 3117 | nchars++; |
078e7b4a | 3118 | } |
5150eeec | 3119 | |
0902fe45 | 3120 | if (ch < 0) |
9c97398c | 3121 | end_of_file_error (); |
078e7b4a | 3122 | |
4cfd81f6 | 3123 | if (! force_multibyte && force_singlebyte) |
a742d646 | 3124 | { |
4cfd81f6 PE |
3125 | /* READ_BUFFER contains raw 8-bit bytes and no multibyte |
3126 | forms. Convert it to unibyte. */ | |
4a25e32a PE |
3127 | nchars = str_as_unibyte ((unsigned char *) read_buffer, |
3128 | p - read_buffer); | |
1571601b | 3129 | p = read_buffer + nchars; |
a742d646 | 3130 | } |
e7fc914b | 3131 | |
491f16a2 | 3132 | return make_specified_string (read_buffer, nchars, p - read_buffer, |
1571601b KH |
3133 | (force_multibyte |
3134 | || (p - read_buffer != nchars))); | |
078e7b4a JB |
3135 | } |
3136 | ||
109d300c JB |
3137 | case '.': |
3138 | { | |
109d300c JB |
3139 | int next_char = READCHAR; |
3140 | UNREAD (next_char); | |
3141 | ||
035eec48 | 3142 | if (next_char <= 040 |
e613ea97 | 3143 | || (next_char < 0200 |
0a6a104b | 3144 | && strchr ("\"';([#?`,", next_char) != NULL)) |
109d300c | 3145 | { |
6428369f KH |
3146 | *pch = c; |
3147 | return Qnil; | |
109d300c JB |
3148 | } |
3149 | ||
3150 | /* Otherwise, we fall through! Note that the atom-reading loop | |
3151 | below will now loop at least once, assuring that we will not | |
3152 | try to UNREAD two characters in a row. */ | |
3153 | } | |
078e7b4a | 3154 | default: |
17634846 | 3155 | default_label: |
88852d45 | 3156 | if (c <= 040) goto retry; |
ed497dd4 | 3157 | if (c == 0xa0) /* NBSP */ |
adef3de7 | 3158 | goto retry; |
52968808 AS |
3159 | |
3160 | read_symbol: | |
078e7b4a | 3161 | { |
38404229 | 3162 | char *p = read_buffer; |
7cded46f | 3163 | bool quoted = 0; |
46cfea45 | 3164 | EMACS_INT start_position = readchar_count - 1; |
078e7b4a JB |
3165 | |
3166 | { | |
38404229 | 3167 | char *end = read_buffer + read_buffer_size; |
078e7b4a | 3168 | |
ef1b0ba7 | 3169 | do |
078e7b4a | 3170 | { |
449fea39 | 3171 | if (end - p < MAX_MULTIBYTE_LENGTH) |
078e7b4a | 3172 | { |
82cb60d3 | 3173 | ptrdiff_t offset = p - read_buffer; |
7216e43b | 3174 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) |
20270765 | 3175 | memory_full (SIZE_MAX); |
38182d90 | 3176 | read_buffer = xrealloc (read_buffer, read_buffer_size * 2); |
37d0112b | 3177 | read_buffer_size *= 2; |
5d65df0d | 3178 | p = read_buffer + offset; |
078e7b4a JB |
3179 | end = read_buffer + read_buffer_size; |
3180 | } | |
177c0ea7 | 3181 | |
078e7b4a | 3182 | if (c == '\\') |
481c6336 RS |
3183 | { |
3184 | c = READCHAR; | |
4ab11c09 GM |
3185 | if (c == -1) |
3186 | end_of_file_error (); | |
481c6336 RS |
3187 | quoted = 1; |
3188 | } | |
6f7f43d5 | 3189 | |
1202434b | 3190 | if (multibyte) |
4a25e32a | 3191 | p += CHAR_STRING (c, (unsigned char *) p); |
1202434b KH |
3192 | else |
3193 | *p++ = c; | |
078e7b4a | 3194 | c = READCHAR; |
0a6a104b AS |
3195 | } |
3196 | while (c > 040 | |
ed497dd4 | 3197 | && c != 0xa0 /* NBSP */ |
0a6a104b AS |
3198 | && (c >= 0200 |
3199 | || strchr ("\"';()[]#`,", c) == NULL)); | |
078e7b4a JB |
3200 | |
3201 | if (p == end) | |
3202 | { | |
82cb60d3 | 3203 | ptrdiff_t offset = p - read_buffer; |
7216e43b | 3204 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) |
20270765 | 3205 | memory_full (SIZE_MAX); |
38182d90 | 3206 | read_buffer = xrealloc (read_buffer, read_buffer_size * 2); |
37d0112b | 3207 | read_buffer_size *= 2; |
5d65df0d GM |
3208 | p = read_buffer + offset; |
3209 | end = read_buffer + read_buffer_size; | |
078e7b4a JB |
3210 | } |
3211 | *p = 0; | |
0a6a104b | 3212 | UNREAD (c); |
078e7b4a JB |
3213 | } |
3214 | ||
4ad679f9 | 3215 | if (!quoted && !uninterned_symbol) |
481c6336 | 3216 | { |
452f4150 PE |
3217 | Lisp_Object result = string_to_number (read_buffer, 10, 0); |
3218 | if (! NILP (result)) | |
8b9587d7 | 3219 | return result; |
481c6336 | 3220 | } |
abb13b09 | 3221 | { |
e93abe3d | 3222 | Lisp_Object name, result; |
d311d28c PE |
3223 | ptrdiff_t nbytes = p - read_buffer; |
3224 | ptrdiff_t nchars | |
4a25e32a PE |
3225 | = (multibyte |
3226 | ? multibyte_chars_in_text ((unsigned char *) read_buffer, | |
3227 | nbytes) | |
e93abe3d KH |
3228 | : nbytes); |
3229 | ||
61b108cc SM |
3230 | name = ((uninterned_symbol && ! NILP (Vpurify_flag) |
3231 | ? make_pure_string : make_specified_string) | |
3232 | (read_buffer, nchars, nbytes, multibyte)); | |
e93abe3d KH |
3233 | result = (uninterned_symbol ? Fmake_symbol (name) |
3234 | : Fintern (name, Qnil)); | |
1202434b | 3235 | |
abb13b09 CW |
3236 | if (EQ (Vread_with_symbol_positions, Qt) |
3237 | || EQ (Vread_with_symbol_positions, readcharfun)) | |
61b108cc SM |
3238 | Vread_symbol_positions_list |
3239 | = Fcons (Fcons (result, make_number (start_position)), | |
3240 | Vread_symbol_positions_list); | |
abb13b09 CW |
3241 | return result; |
3242 | } | |
078e7b4a JB |
3243 | } |
3244 | } | |
3245 | } | |
3246 | \f | |
9e062b6c | 3247 | |
48def666 | 3248 | /* List of nodes we've seen during substitute_object_in_subtree. */ |
9e062b6c RS |
3249 | static Lisp_Object seen_list; |
3250 | ||
3251 | static void | |
971de7fb | 3252 | substitute_object_in_subtree (Lisp_Object object, Lisp_Object placeholder) |
9e062b6c RS |
3253 | { |
3254 | Lisp_Object check_object; | |
3255 | ||
48def666 | 3256 | /* We haven't seen any objects when we start. */ |
9e062b6c RS |
3257 | seen_list = Qnil; |
3258 | ||
48def666 | 3259 | /* Make all the substitutions. */ |
9e062b6c RS |
3260 | check_object |
3261 | = substitute_object_recurse (object, placeholder, object); | |
177c0ea7 | 3262 | |
48def666 | 3263 | /* Clear seen_list because we're done with it. */ |
9e062b6c RS |
3264 | seen_list = Qnil; |
3265 | ||
3266 | /* The returned object here is expected to always eq the | |
48def666 | 3267 | original. */ |
9e062b6c RS |
3268 | if (!EQ (check_object, object)) |
3269 | error ("Unexpected mutation error in reader"); | |
3270 | } | |
3271 | ||
48def666 | 3272 | /* Feval doesn't get called from here, so no gc protection is needed. */ |
7a3d90dc SM |
3273 | #define SUBSTITUTE(get_val, set_val) \ |
3274 | do { \ | |
3275 | Lisp_Object old_value = get_val; \ | |
3276 | Lisp_Object true_value \ | |
3277 | = substitute_object_recurse (object, placeholder, \ | |
3278 | old_value); \ | |
3279 | \ | |
3280 | if (!EQ (old_value, true_value)) \ | |
3281 | { \ | |
3282 | set_val; \ | |
3283 | } \ | |
3284 | } while (0) | |
9e062b6c RS |
3285 | |
3286 | static Lisp_Object | |
971de7fb | 3287 | substitute_object_recurse (Lisp_Object object, Lisp_Object placeholder, Lisp_Object subtree) |
9e062b6c | 3288 | { |
48def666 | 3289 | /* If we find the placeholder, return the target object. */ |
9e062b6c RS |
3290 | if (EQ (placeholder, subtree)) |
3291 | return object; | |
3292 | ||
48def666 | 3293 | /* If we've been to this node before, don't explore it again. */ |
9e062b6c RS |
3294 | if (!EQ (Qnil, Fmemq (subtree, seen_list))) |
3295 | return subtree; | |
3296 | ||
3297 | /* If this node can be the entry point to a cycle, remember that | |
3298 | we've seen it. It can only be such an entry point if it was made | |
3299 | by #n=, which means that we can find it as a value in | |
3300 | read_objects. */ | |
3301 | if (!EQ (Qnil, Frassq (subtree, read_objects))) | |
3302 | seen_list = Fcons (subtree, seen_list); | |
177c0ea7 | 3303 | |
9e062b6c RS |
3304 | /* Recurse according to subtree's type. |
3305 | Every branch must return a Lisp_Object. */ | |
2b8f856a | 3306 | if (VECTORLIKEP (subtree)) |
9e062b6c | 3307 | { |
2b8f856a BT |
3308 | ptrdiff_t i, length = 0; |
3309 | if (BOOL_VECTOR_P (subtree)) | |
3310 | return subtree; /* No sub-objects anyway. */ | |
3311 | else if (CHAR_TABLE_P (subtree) || SUB_CHAR_TABLE_P (subtree) | |
3312 | || COMPILEDP (subtree) || HASH_TABLE_P (subtree)) | |
3313 | length = ASIZE (subtree) & PSEUDOVECTOR_SIZE_MASK; | |
3314 | else if (VECTORP (subtree)) | |
3315 | length = ASIZE (subtree); | |
3316 | else | |
3317 | /* An unknown pseudovector may contain non-Lisp fields, so we | |
3318 | can't just blindly traverse all its fields. We used to call | |
3319 | `Flength' which signaled `sequencep', so I just preserved this | |
3320 | behavior. */ | |
3321 | wrong_type_argument (Qsequencep, subtree); | |
3322 | ||
3323 | for (i = 0; i < length; i++) | |
3324 | SUBSTITUTE (AREF (subtree, i), | |
3325 | ASET (subtree, i, true_value)); | |
3326 | return subtree; | |
3327 | } | |
3328 | else if (CONSP (subtree)) | |
3329 | { | |
3330 | SUBSTITUTE (XCAR (subtree), | |
3331 | XSETCAR (subtree, true_value)); | |
3332 | SUBSTITUTE (XCDR (subtree), | |
3333 | XSETCDR (subtree, true_value)); | |
3334 | return subtree; | |
3335 | } | |
3336 | else if (STRINGP (subtree)) | |
3337 | { | |
3338 | /* Check for text properties in each interval. | |
3339 | substitute_in_interval contains part of the logic. */ | |
177c0ea7 | 3340 | |
2b8f856a BT |
3341 | INTERVAL root_interval = string_intervals (subtree); |
3342 | Lisp_Object arg = Fcons (object, placeholder); | |
9e062b6c | 3343 | |
2b8f856a BT |
3344 | traverse_intervals_noorder (root_interval, |
3345 | &substitute_in_interval, arg); | |
9e062b6c | 3346 | |
9e062b6c RS |
3347 | return subtree; |
3348 | } | |
2b8f856a BT |
3349 | else |
3350 | /* Other types don't recurse any further. */ | |
3351 | return subtree; | |
9e062b6c RS |
3352 | } |
3353 | ||
3354 | /* Helper function for substitute_object_recurse. */ | |
3355 | static void | |
971de7fb | 3356 | substitute_in_interval (INTERVAL interval, Lisp_Object arg) |
9e062b6c RS |
3357 | { |
3358 | Lisp_Object object = Fcar (arg); | |
3359 | Lisp_Object placeholder = Fcdr (arg); | |
3360 | ||
0c94c8d6 | 3361 | SUBSTITUTE (interval->plist, set_interval_plist (interval, true_value)); |
9e062b6c RS |
3362 | } |
3363 | ||
3364 | \f | |
078e7b4a JB |
3365 | #define LEAD_INT 1 |
3366 | #define DOT_CHAR 2 | |
3367 | #define TRAIL_INT 4 | |
452f4150 | 3368 | #define E_EXP 16 |
078e7b4a | 3369 | |
8b9587d7 | 3370 | |
452f4150 PE |
3371 | /* Convert STRING to a number, assuming base BASE. Return a fixnum if CP has |
3372 | integer syntax and fits in a fixnum, else return the nearest float if CP has | |
3373 | either floating point or integer syntax and BASE is 10, else return nil. If | |
7cded46f | 3374 | IGNORE_TRAILING, consider just the longest prefix of CP that has |
452f4150 PE |
3375 | valid floating point syntax. Signal an overflow if BASE is not 10 and the |
3376 | number has integer syntax but does not fit. */ | |
8b9587d7 PE |
3377 | |
3378 | Lisp_Object | |
7cded46f | 3379 | string_to_number (char const *string, int base, bool ignore_trailing) |
078e7b4a | 3380 | { |
a8fe7202 | 3381 | int state; |
452f4150 PE |
3382 | char const *cp = string; |
3383 | int leading_digit; | |
7cded46f | 3384 | bool float_syntax = 0; |
452f4150 | 3385 | double value = 0; |
d8578e58 | 3386 | |
8b9587d7 PE |
3387 | /* Compute NaN and infinities using a variable, to cope with compilers that |
3388 | think they are smarter than we are. */ | |
3389 | double zero = 0; | |
3390 | ||
3391 | /* Negate the value ourselves. This treats 0, NaNs, and infinity properly on | |
3392 | IEEE floating point hosts, and works around a formerly-common bug where | |
3393 | atof ("-0.0") drops the sign. */ | |
7cded46f | 3394 | bool negative = *cp == '-'; |
8b9587d7 | 3395 | |
7cded46f | 3396 | bool signedp = negative || *cp == '+'; |
452f4150 | 3397 | cp += signedp; |
8b9587d7 | 3398 | |
078e7b4a | 3399 | state = 0; |
078e7b4a | 3400 | |
452f4150 | 3401 | leading_digit = digit_to_number (*cp, base); |
908589fd | 3402 | if (leading_digit >= 0) |
078e7b4a JB |
3403 | { |
3404 | state |= LEAD_INT; | |
452f4150 PE |
3405 | do |
3406 | ++cp; | |
908589fd | 3407 | while (digit_to_number (*cp, base) >= 0); |
078e7b4a JB |
3408 | } |
3409 | if (*cp == '.') | |
3410 | { | |
3411 | state |= DOT_CHAR; | |
3412 | cp++; | |
3413 | } | |
078e7b4a | 3414 | |
452f4150 | 3415 | if (base == 10) |
eb659c41 | 3416 | { |
452f4150 PE |
3417 | if ('0' <= *cp && *cp <= '9') |
3418 | { | |
3419 | state |= TRAIL_INT; | |
3420 | do | |
3421 | cp++; | |
3422 | while ('0' <= *cp && *cp <= '9'); | |
3423 | } | |
3424 | if (*cp == 'e' || *cp == 'E') | |
3425 | { | |
3426 | char const *ecp = cp; | |
3427 | cp++; | |
3428 | if (*cp == '+' || *cp == '-') | |
3429 | cp++; | |
3430 | if ('0' <= *cp && *cp <= '9') | |
3431 | { | |
3432 | state |= E_EXP; | |
3433 | do | |
3434 | cp++; | |
3435 | while ('0' <= *cp && *cp <= '9'); | |
3436 | } | |
3437 | else if (cp[-1] == '+' | |
3438 | && cp[0] == 'I' && cp[1] == 'N' && cp[2] == 'F') | |
3439 | { | |
3440 | state |= E_EXP; | |
3441 | cp += 3; | |
3442 | value = 1.0 / zero; | |
3443 | } | |
3444 | else if (cp[-1] == '+' | |
3445 | && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N') | |
3446 | { | |
3447 | state |= E_EXP; | |
3448 | cp += 3; | |
3449 | value = zero / zero; | |
3450 | ||
3451 | /* If that made a "negative" NaN, negate it. */ | |
3452 | { | |
3453 | int i; | |
3454 | union { double d; char c[sizeof (double)]; } | |
3455 | u_data, u_minus_zero; | |
3456 | u_data.d = value; | |
3457 | u_minus_zero.d = -0.0; | |
3458 | for (i = 0; i < sizeof (double); i++) | |
3459 | if (u_data.c[i] & u_minus_zero.c[i]) | |
3460 | { | |
3461 | value = -value; | |
3462 | break; | |
3463 | } | |
3464 | } | |
3465 | /* Now VALUE is a positive NaN. */ | |
3466 | } | |
3467 | else | |
3468 | cp = ecp; | |
3469 | } | |
3470 | ||
3471 | float_syntax = ((state & (DOT_CHAR|TRAIL_INT)) == (DOT_CHAR|TRAIL_INT) | |
3472 | || state == (LEAD_INT|E_EXP)); | |
eb659c41 | 3473 | } |
8b9587d7 | 3474 | |
452f4150 PE |
3475 | /* Return nil if the number uses invalid syntax. If IGNORE_TRAILING, accept |
3476 | any prefix that matches. Otherwise, the entire string must match. */ | |
3477 | if (! (ignore_trailing | |
3478 | ? ((state & LEAD_INT) != 0 || float_syntax) | |
3479 | : (!*cp && ((state & ~DOT_CHAR) == LEAD_INT || float_syntax)))) | |
3480 | return Qnil; | |
8b9587d7 | 3481 | |
d78050d6 PE |
3482 | /* If the number uses integer and not float syntax, and is in C-language |
3483 | range, use its value, preferably as a fixnum. */ | |
908589fd | 3484 | if (leading_digit >= 0 && ! float_syntax) |
452f4150 | 3485 | { |
d78050d6 PE |
3486 | uintmax_t n; |
3487 | ||
3488 | /* Fast special case for single-digit integers. This also avoids a | |
7cded46f | 3489 | glitch when BASE is 16 and IGNORE_TRAILING, because in that |
d78050d6 PE |
3490 | case some versions of strtoumax accept numbers like "0x1" that Emacs |
3491 | does not allow. */ | |
3492 | if (digit_to_number (string[signedp + 1], base) < 0) | |
3493 | return make_number (negative ? -leading_digit : leading_digit); | |
3494 | ||
3495 | errno = 0; | |
3496 | n = strtoumax (string + signedp, NULL, base); | |
3497 | if (errno == ERANGE) | |
452f4150 | 3498 | { |
d78050d6 PE |
3499 | /* Unfortunately there's no simple and accurate way to convert |
3500 | non-base-10 numbers that are out of C-language range. */ | |
3501 | if (base != 10) | |
f14ed477 | 3502 | xsignal1 (Qoverflow_error, build_string (string)); |
452f4150 | 3503 | } |
d78050d6 PE |
3504 | else if (n <= (negative ? -MOST_NEGATIVE_FIXNUM : MOST_POSITIVE_FIXNUM)) |
3505 | { | |
3506 | EMACS_INT signed_n = n; | |
3507 | return make_number (negative ? -signed_n : signed_n); | |
3508 | } | |
3509 | else | |
3510 | value = n; | |
452f4150 | 3511 | } |
8b9587d7 | 3512 | |
452f4150 PE |
3513 | /* Either the number uses float syntax, or it does not fit into a fixnum. |
3514 | Convert it from string to floating point, unless the value is already | |
d78050d6 PE |
3515 | known because it is an infinity, a NAN, or its absolute value fits in |
3516 | uintmax_t. */ | |
8b9587d7 | 3517 | if (! value) |
452f4150 PE |
3518 | value = atof (string + signedp); |
3519 | ||
d78050d6 | 3520 | return make_float (negative ? -value : value); |
078e7b4a | 3521 | } |
cc94f3b2 | 3522 | |
078e7b4a JB |
3523 | \f |
3524 | static Lisp_Object | |
7cded46f | 3525 | read_vector (Lisp_Object readcharfun, bool bytecodeflag) |
078e7b4a | 3526 | { |
82cb60d3 | 3527 | ptrdiff_t i, size; |
7cded46f PE |
3528 | Lisp_Object *ptr; |
3529 | Lisp_Object tem, item, vector; | |
078e7b4a JB |
3530 | Lisp_Object len; |
3531 | ||
3532 | tem = read_list (1, readcharfun); | |
3533 | len = Flength (tem); | |
48def666 | 3534 | vector = Fmake_vector (len, Qnil); |
078e7b4a | 3535 | |
77b37c05 | 3536 | size = ASIZE (vector); |
91f2d272 | 3537 | ptr = XVECTOR (vector)->contents; |
078e7b4a JB |
3538 | for (i = 0; i < size; i++) |
3539 | { | |
c15cfd1f RS |
3540 | item = Fcar (tem); |
3541 | /* If `load-force-doc-strings' is t when reading a lazily-loaded | |
3542 | bytecode object, the docstring containing the bytecode and | |
3543 | constants values must be treated as unibyte and passed to | |
3544 | Fread, to get the actual bytecode string and constants vector. */ | |
876c194c | 3545 | if (bytecodeflag && load_force_doc_strings) |
c15cfd1f RS |
3546 | { |
3547 | if (i == COMPILED_BYTECODE) | |
3548 | { | |
3549 | if (!STRINGP (item)) | |
6fa2b890 | 3550 | error ("Invalid byte code"); |
c15cfd1f RS |
3551 | |
3552 | /* Delay handling the bytecode slot until we know whether | |
3553 | it is lazily-loaded (we can tell by whether the | |
3554 | constants slot is nil). */ | |
086ca913 | 3555 | ASET (vector, COMPILED_CONSTANTS, item); |
c15cfd1f RS |
3556 | item = Qnil; |
3557 | } | |
3558 | else if (i == COMPILED_CONSTANTS) | |
3559 | { | |
3560 | Lisp_Object bytestr = ptr[COMPILED_CONSTANTS]; | |
3561 | ||
3562 | if (NILP (item)) | |
3563 | { | |
3564 | /* Coerce string to unibyte (like string-as-unibyte, | |
3565 | but without generating extra garbage and | |
3566 | guaranteeing no change in the contents). */ | |
bee91904 | 3567 | STRING_SET_CHARS (bytestr, SBYTES (bytestr)); |
d5db4077 | 3568 | STRING_SET_UNIBYTE (bytestr); |
c15cfd1f | 3569 | |
8792be66 | 3570 | item = Fread (Fcons (bytestr, readcharfun)); |
c15cfd1f | 3571 | if (!CONSP (item)) |
6fa2b890 | 3572 | error ("Invalid byte code"); |
c15cfd1f | 3573 | |
c1d497be KR |
3574 | bytestr = XCAR (item); |
3575 | item = XCDR (item); | |
c15cfd1f RS |
3576 | } |
3577 | ||
3578 | /* Now handle the bytecode slot. */ | |
086ca913 | 3579 | ASET (vector, COMPILED_BYTECODE, bytestr); |
c15cfd1f | 3580 | } |
8792be66 KH |
3581 | else if (i == COMPILED_DOC_STRING |
3582 | && STRINGP (item) | |
3583 | && ! STRING_MULTIBYTE (item)) | |
3584 | { | |
3585 | if (EQ (readcharfun, Qget_emacs_mule_file_char)) | |
3586 | item = Fdecode_coding_string (item, Qemacs_mule, Qnil, Qnil); | |
3587 | else | |
3588 | item = Fstring_as_multibyte (item); | |
3589 | } | |
c15cfd1f | 3590 | } |
086ca913 | 3591 | ASET (vector, i, item); |
078e7b4a | 3592 | tem = Fcdr (tem); |
078e7b4a JB |
3593 | } |
3594 | return vector; | |
3595 | } | |
177c0ea7 | 3596 | |
f224e500 | 3597 | /* FLAG means check for ']' to terminate rather than ')' and '.'. */ |
078e7b4a JB |
3598 | |
3599 | static Lisp_Object | |
7cded46f | 3600 | read_list (bool flag, Lisp_Object readcharfun) |
078e7b4a | 3601 | { |
078e7b4a | 3602 | Lisp_Object val, tail; |
7cded46f | 3603 | Lisp_Object elt, tem; |
078e7b4a | 3604 | struct gcpro gcpro1, gcpro2; |
821d417e | 3605 | /* 0 is the normal case. |
b2a30870 | 3606 | 1 means this list is a doc reference; replace it with the number 0. |
177c0ea7 | 3607 | 2 means this list is a doc reference; replace it with the doc string. */ |
821d417e | 3608 | int doc_reference = 0; |
078e7b4a | 3609 | |
17634846 | 3610 | /* Initialize this to 1 if we are reading a list. */ |
7cded46f | 3611 | bool first_in_list = flag <= 0; |
17634846 | 3612 | |
078e7b4a JB |
3613 | val = Qnil; |
3614 | tail = Qnil; | |
3615 | ||
3616 | while (1) | |
3617 | { | |
e28552a4 | 3618 | int ch; |
078e7b4a | 3619 | GCPRO2 (val, tail); |
17634846 | 3620 | elt = read1 (readcharfun, &ch, first_in_list); |
078e7b4a | 3621 | UNGCPRO; |
20ea2964 | 3622 | |
17634846 RS |
3623 | first_in_list = 0; |
3624 | ||
821d417e | 3625 | /* While building, if the list starts with #$, treat it specially. */ |
20ea2964 | 3626 | if (EQ (elt, Vload_file_name) |
d49f0c1a | 3627 | && ! NILP (elt) |
821d417e RS |
3628 | && !NILP (Vpurify_flag)) |
3629 | { | |
3630 | if (NILP (Vdoc_file_name)) | |
3631 | /* We have not yet called Snarf-documentation, so assume | |
6e911150 | 3632 | this file is described in the DOC file |
821d417e RS |
3633 | and Snarf-documentation will fill in the right value later. |
3634 | For now, replace the whole list with 0. */ | |
3635 | doc_reference = 1; | |
3636 | else | |
3637 | /* We have already called Snarf-documentation, so make a relative | |
3638 | file name for this file, so it can be found properly | |
3639 | in the installed Lisp directory. | |
3640 | We don't use Fexpand_file_name because that would make | |
3641 | the directory absolute now. */ | |
3642 | elt = concat2 (build_string ("../lisp/"), | |
61b108cc | 3643 | Ffile_name_nondirectory (elt)); |
821d417e | 3644 | } |
b2a30870 | 3645 | else if (EQ (elt, Vload_file_name) |
d49f0c1a | 3646 | && ! NILP (elt) |
b2a30870 RS |
3647 | && load_force_doc_strings) |
3648 | doc_reference = 2; | |
20ea2964 | 3649 | |
6428369f | 3650 | if (ch) |
078e7b4a JB |
3651 | { |
3652 | if (flag > 0) | |
3653 | { | |
6428369f | 3654 | if (ch == ']') |
078e7b4a | 3655 | return val; |
e4d29b33 | 3656 | invalid_syntax (") or . in a vector"); |
078e7b4a | 3657 | } |
6428369f | 3658 | if (ch == ')') |
078e7b4a | 3659 | return val; |
6428369f | 3660 | if (ch == '.') |
078e7b4a JB |
3661 | { |
3662 | GCPRO2 (val, tail); | |
265a9e55 | 3663 | if (!NILP (tail)) |
f5df591a | 3664 | XSETCDR (tail, read0 (readcharfun)); |
078e7b4a JB |
3665 | else |
3666 | val = read0 (readcharfun); | |
17634846 | 3667 | read1 (readcharfun, &ch, 0); |
078e7b4a | 3668 | UNGCPRO; |
6428369f | 3669 | if (ch == ')') |
821d417e RS |
3670 | { |
3671 | if (doc_reference == 1) | |
3672 | return make_number (0); | |
d2e24f92 | 3673 | if (doc_reference == 2 && INTEGERP (XCDR (val))) |
b2a30870 | 3674 | { |
d2e24f92 SM |
3675 | char *saved = NULL; |
3676 | file_offset saved_position; | |
b2a30870 | 3677 | /* Get a doc string from the file we are loading. |
8792be66 KH |
3678 | If it's in saved_doc_string, get it from there. |
3679 | ||
3680 | Here, we don't know if the string is a | |
3681 | bytecode string or a doc string. As a | |
3682 | bytecode string must be unibyte, we always | |
3683 | return a unibyte string. If it is actually a | |
3684 | doc string, caller must make it | |
3685 | multibyte. */ | |
8f924df7 | 3686 | |
c15cfd1f | 3687 | /* Position is negative for user variables. */ |
71376d4b | 3688 | EMACS_INT pos = eabs (XINT (XCDR (val))); |
b2a30870 RS |
3689 | if (pos >= saved_doc_string_position |
3690 | && pos < (saved_doc_string_position | |
3691 | + saved_doc_string_length)) | |
3692 | { | |
d2e24f92 SM |
3693 | saved = saved_doc_string; |
3694 | saved_position = saved_doc_string_position; | |
b2a30870 | 3695 | } |
c15cfd1f RS |
3696 | /* Look in prev_saved_doc_string the same way. */ |
3697 | else if (pos >= prev_saved_doc_string_position | |
3698 | && pos < (prev_saved_doc_string_position | |
3699 | + prev_saved_doc_string_length)) | |
3700 | { | |
d2e24f92 SM |
3701 | saved = prev_saved_doc_string; |
3702 | saved_position = prev_saved_doc_string_position; | |
3703 | } | |
3704 | if (saved) | |
3705 | { | |
3706 | ptrdiff_t start = pos - saved_position; | |
82cb60d3 | 3707 | ptrdiff_t from, to; |
c15cfd1f RS |
3708 | |
3709 | /* Process quoting with ^A, | |
3710 | and find the end of the string, | |
3711 | which is marked with ^_ (037). */ | |
3712 | for (from = start, to = start; | |
d2e24f92 | 3713 | saved[from] != 037;) |
c15cfd1f | 3714 | { |
d2e24f92 | 3715 | int c = saved[from++]; |
c15cfd1f RS |
3716 | if (c == 1) |
3717 | { | |
d2e24f92 SM |
3718 | c = saved[from++]; |
3719 | saved[to++] = (c == 1 ? c | |
3720 | : c == '0' ? 0 | |
3721 | : c == '_' ? 037 | |
3722 | : c); | |
c15cfd1f RS |
3723 | } |
3724 | else | |
d2e24f92 | 3725 | saved[to++] = c; |
c15cfd1f RS |
3726 | } |
3727 | ||
d2e24f92 | 3728 | return make_unibyte_string (saved + start, |
8792be66 | 3729 | to - start); |
c15cfd1f | 3730 | } |
b2a30870 | 3731 | else |
8792be66 | 3732 | return get_doc_string (val, 1, 0); |
b2a30870 RS |
3733 | } |
3734 | ||
821d417e RS |
3735 | return val; |
3736 | } | |
e4d29b33 | 3737 | invalid_syntax (". in wrong context"); |
078e7b4a | 3738 | } |
e4d29b33 | 3739 | invalid_syntax ("] in a list"); |
078e7b4a | 3740 | } |
6c6f1994 | 3741 | tem = list1 (elt); |
265a9e55 | 3742 | if (!NILP (tail)) |
f5df591a | 3743 | XSETCDR (tail, tem); |
078e7b4a JB |
3744 | else |
3745 | val = tem; | |
3746 | tail = tem; | |
078e7b4a JB |
3747 | } |
3748 | } | |
3749 | \f | |
1e3890d1 | 3750 | static Lisp_Object initial_obarray; |
078e7b4a | 3751 | |
d23d13c0 BT |
3752 | Lisp_Object |
3753 | obhash (Lisp_Object obarray) | |
3754 | { | |
3755 | Lisp_Object tem = scm_hashq_get_handle (obarrays, obarray); | |
3756 | if (SCM_UNLIKELY (scm_is_false (tem))) | |
3757 | tem = scm_hashq_create_handle_x (obarrays, obarray, | |
3758 | scm_make_obarray ()); | |
3759 | return scm_cdr (tem); | |
3760 | } | |
d007f5c8 | 3761 | |
d007f5c8 RS |
3762 | /* Get an error if OBARRAY is not an obarray. |
3763 | If it is one, return it. */ | |
3764 | ||
078e7b4a | 3765 | Lisp_Object |
971de7fb | 3766 | check_obarray (Lisp_Object obarray) |
078e7b4a | 3767 | { |
77b37c05 | 3768 | if (!VECTORP (obarray) || ASIZE (obarray) == 0) |
078e7b4a JB |
3769 | { |
3770 | /* If Vobarray is now invalid, force it to be valid. */ | |
3771 | if (EQ (Vobarray, obarray)) Vobarray = initial_obarray; | |
8878319c | 3772 | wrong_type_argument (Qvectorp, obarray); |
078e7b4a JB |
3773 | } |
3774 | return obarray; | |
3775 | } | |
3776 | ||
d007f5c8 RS |
3777 | /* Intern the C string STR: return a symbol with that name, |
3778 | interned in the current obarray. */ | |
078e7b4a JB |
3779 | |
3780 | Lisp_Object | |
e8df9267 | 3781 | intern_1 (const char *str, ptrdiff_t len) |
078e7b4a | 3782 | { |
3250348f | 3783 | return Fintern (make_string (str, len), Qnil); |
078e7b4a | 3784 | } |
4ad679f9 | 3785 | |
5e2327cf | 3786 | Lisp_Object |
e8df9267 | 3787 | intern_c_string_1 (const char *str, ptrdiff_t len) |
5e2327cf | 3788 | { |
3250348f BT |
3789 | return Fintern (make_pure_c_string (str, len), Qnil); |
3790 | } | |
3791 | \f | |
3792 | DEFUN ("find-symbol", Ffind_symbol, Sfind_symbol, 1, 2, 0, | |
3793 | doc: /* find-symbol */) | |
3794 | (Lisp_Object string, Lisp_Object obarray) | |
3795 | { | |
3796 | Lisp_Object tem, sstring, found; | |
5e2327cf | 3797 | |
3250348f BT |
3798 | obarray = check_obarray (NILP (obarray) ? Vobarray : obarray); |
3799 | CHECK_STRING (string); | |
5e2327cf | 3800 | |
3250348f BT |
3801 | sstring = scm_from_utf8_stringn (SSDATA (string), SBYTES (string)); |
3802 | tem = scm_find_symbol (sstring, obhash (obarray)); | |
d1c3da7b | 3803 | if (scm_is_true (tem)) |
3250348f BT |
3804 | { |
3805 | if (EQ (tem, Qnil_)) | |
3806 | tem = Qnil; | |
3807 | else if (EQ (tem, Qt_)) | |
3808 | tem = Qt; | |
3809 | return scm_values (scm_list_2 (tem, Qt)); | |
3810 | } | |
3811 | else | |
3812 | return scm_values (scm_list_2 (Qnil, Qnil)); | |
5e2327cf | 3813 | } |
3250348f | 3814 | |
a7ca3326 | 3815 | DEFUN ("intern", Fintern, Sintern, 1, 2, 0, |
5de38842 PJ |
3816 | doc: /* Return the canonical symbol whose name is STRING. |
3817 | If there is none, one is created by this function and returned. | |
3818 | A second optional argument specifies the obarray to use; | |
3819 | it defaults to the value of `obarray'. */) | |
5842a27b | 3820 | (Lisp_Object string, Lisp_Object obarray) |
078e7b4a JB |
3821 | { |
3822 | register Lisp_Object tem, sym, *ptr; | |
3823 | ||
265a9e55 | 3824 | if (NILP (obarray)) obarray = Vobarray; |
078e7b4a JB |
3825 | obarray = check_obarray (obarray); |
3826 | ||
b7826503 | 3827 | CHECK_STRING (string); |
078e7b4a | 3828 | |
3250348f BT |
3829 | tem = Ffind_symbol (string, obarray); |
3830 | if (! NILP (scm_c_value_ref (tem, 1))) | |
3831 | return scm_c_value_ref (tem, 0); | |
d23d13c0 BT |
3832 | |
3833 | sym = scm_intern (scm_from_utf8_stringn (SSDATA (string), | |
3834 | SBYTES (string)), | |
3835 | obhash (obarray)); | |
44c6c019 | 3836 | |
d5db4077 | 3837 | if ((SREF (string, 0) == ':') |
a458d45d | 3838 | && EQ (obarray, initial_obarray)) |
44c6c019 | 3839 | { |
844e0de1 BT |
3840 | SET_SYMBOL_CONSTANT (XSYMBOL (sym), 1); |
3841 | SET_SYMBOL_REDIRECT (XSYMBOL (sym), SYMBOL_PLAINVAL); | |
ce5b453a | 3842 | SET_SYMBOL_VAL (XSYMBOL (sym), sym); |
44c6c019 | 3843 | } |
a0549832 | 3844 | |
3250348f | 3845 | return sym; |
078e7b4a JB |
3846 | } |
3847 | ||
a7ca3326 | 3848 | DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0, |
5de38842 PJ |
3849 | doc: /* Return the canonical symbol named NAME, or nil if none exists. |
3850 | NAME may be a string or a symbol. If it is a symbol, that exact | |
3851 | symbol is searched for. | |
3852 | A second optional argument specifies the obarray to use; | |
3853 | it defaults to the value of `obarray'. */) | |
5842a27b | 3854 | (Lisp_Object name, Lisp_Object obarray) |
078e7b4a | 3855 | { |
3250348f | 3856 | register Lisp_Object tem, string, mv, found; |
078e7b4a | 3857 | |
3250348f BT |
3858 | string = SYMBOLP (name) ? SYMBOL_NAME (name) : name; |
3859 | mv = Ffind_symbol (string, obarray); | |
3860 | tem = scm_c_value_ref (mv, 0); | |
3861 | found = scm_c_value_ref (mv, 1); | |
078e7b4a | 3862 | |
3250348f | 3863 | if (NILP (found) || (SYMBOLP (name) && !EQ (name, tem))) |
b55048d4 GM |
3864 | return Qnil; |
3865 | else | |
078e7b4a | 3866 | return tem; |
078e7b4a | 3867 | } |
d007f5c8 | 3868 | \f |
a7ca3326 | 3869 | DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0, |
5de38842 PJ |
3870 | doc: /* Delete the symbol named NAME, if any, from OBARRAY. |
3871 | The value is t if a symbol was found and deleted, nil otherwise. | |
3872 | NAME may be a string or a symbol. If it is a symbol, that symbol | |
3873 | is deleted, if it belongs to OBARRAY--no other symbol is deleted. | |
0e46275b JB |
3874 | OBARRAY, if nil, defaults to the value of the variable `obarray'. |
3875 | usage: (unintern NAME OBARRAY) */) | |
5842a27b | 3876 | (Lisp_Object name, Lisp_Object obarray) |
d007f5c8 | 3877 | { |
d23d13c0 BT |
3878 | Lisp_Object string; |
3879 | Lisp_Object tem; | |
d007f5c8 | 3880 | |
d23d13c0 BT |
3881 | if (NILP (obarray)) |
3882 | obarray = Vobarray; | |
d007f5c8 RS |
3883 | obarray = check_obarray (obarray); |
3884 | ||
3885 | if (SYMBOLP (name)) | |
d007f5c8 | 3886 | { |
d23d13c0 BT |
3887 | if (! EQ (name, |
3888 | scm_find_symbol (scm_symbol_to_string (name), | |
3889 | obhash (obarray)))) | |
3890 | return Qnil; | |
3891 | string = SYMBOL_NAME (name); | |
b2a30870 | 3892 | } |
d007f5c8 RS |
3893 | else |
3894 | { | |
d23d13c0 BT |
3895 | CHECK_STRING (name); |
3896 | string = name; | |
3897 | ||
d007f5c8 RS |
3898 | } |
3899 | ||
d23d13c0 | 3900 | return (scm_is_true (scm_unintern (name, obhash (obarray))) ? Qt : Qnil); |
d007f5c8 RS |
3901 | } |
3902 | \f | |
078e7b4a | 3903 | void |
971de7fb | 3904 | map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Object arg) |
078e7b4a | 3905 | { |
d23d13c0 BT |
3906 | Lisp_Object proc (Lisp_Object sym) |
3907 | { | |
3908 | Lisp_Object tem = Ffind_symbol (SYMBOL_NAME (sym), obarray); | |
3909 | if (scm_is_true (scm_c_value_ref (tem, 1)) | |
3910 | && EQ (sym, scm_c_value_ref (tem, 0))) | |
3911 | fn (sym, arg); | |
3912 | return SCM_UNSPECIFIED; | |
3913 | } | |
b7826503 | 3914 | CHECK_VECTOR (obarray); |
d23d13c0 BT |
3915 | scm_obarray_for_each (scm_c_make_gsubr ("proc", 1, 0, 0, proc), |
3916 | obhash (obarray)); | |
078e7b4a JB |
3917 | } |
3918 | ||
7d383292 | 3919 | static void |
971de7fb | 3920 | mapatoms_1 (Lisp_Object sym, Lisp_Object function) |
078e7b4a JB |
3921 | { |
3922 | call1 (function, sym); | |
3923 | } | |
3924 | ||
3925 | DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0, | |
5de38842 PJ |
3926 | doc: /* Call FUNCTION on every symbol in OBARRAY. |
3927 | OBARRAY defaults to the value of `obarray'. */) | |
5842a27b | 3928 | (Lisp_Object function, Lisp_Object obarray) |
078e7b4a | 3929 | { |
265a9e55 | 3930 | if (NILP (obarray)) obarray = Vobarray; |
078e7b4a JB |
3931 | obarray = check_obarray (obarray); |
3932 | ||
3933 | map_obarray (obarray, mapatoms_1, function); | |
3934 | return Qnil; | |
3935 | } | |
3936 | ||
5e88a39e | 3937 | #define OBARRAY_SIZE 1511 |
078e7b4a JB |
3938 | |
3939 | void | |
971de7fb | 3940 | init_obarray (void) |
078e7b4a JB |
3941 | { |
3942 | Lisp_Object oblength; | |
37d0112b | 3943 | ptrdiff_t size = 100 + MAX_MULTIBYTE_LENGTH; |
078e7b4a | 3944 | |
baf69866 | 3945 | XSETFASTINT (oblength, OBARRAY_SIZE); |
078e7b4a | 3946 | |
078e7b4a JB |
3947 | Vobarray = Fmake_vector (oblength, make_number (0)); |
3948 | initial_obarray = Vobarray; | |
3949 | staticpro (&initial_obarray); | |
078e7b4a | 3950 | |
d23d13c0 BT |
3951 | obarrays = scm_make_hash_table (SCM_UNDEFINED); |
3952 | scm_hashq_set_x (obarrays, Vobarray, SCM_UNDEFINED); | |
3953 | ||
73880000 BT |
3954 | Qnil = SCM_ELISP_NIL; |
3955 | Qt = SCM_BOOL_T; | |
3956 | ||
3957 | Qnil_ = intern_c_string ("nil"); | |
3958 | SET_SYMBOL_VAL (XSYMBOL (Qnil_), Qnil); | |
844e0de1 BT |
3959 | SET_SYMBOL_CONSTANT (XSYMBOL (Qnil_), 1); |
3960 | SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (Qnil_), 1); | |
ce5b453a | 3961 | |
73880000 BT |
3962 | Qt_ = intern_c_string ("t"); |
3963 | SET_SYMBOL_VAL (XSYMBOL (Qt_), Qt); | |
844e0de1 BT |
3964 | SET_SYMBOL_CONSTANT (XSYMBOL (Qt_), 1); |
3965 | SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (Qt_), 1); | |
73880000 | 3966 | |
d1c3da7b | 3967 | Qunbound = scm_c_public_ref ("language elisp runtime", "unbound"); |
ce5b453a | 3968 | SET_SYMBOL_VAL (XSYMBOL (Qunbound), Qunbound); |
078e7b4a JB |
3969 | |
3970 | /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */ | |
3971 | Vpurify_flag = Qt; | |
3972 | ||
cd3520a4 | 3973 | DEFSYM (Qvariable_documentation, "variable-documentation"); |
078e7b4a | 3974 | |
c1ade6f7 | 3975 | read_buffer = xmalloc_atomic (size); |
37d0112b | 3976 | read_buffer_size = size; |
078e7b4a JB |
3977 | } |
3978 | \f | |
3979 | void | |
62947569 | 3980 | defsubr (const char *lname, scm_t_subr gsubr_fn, short min_args, short max_args, const char *intspec) |
078e7b4a | 3981 | { |
62947569 BT |
3982 | Lisp_Object sym = intern_c_string (lname); |
3983 | Lisp_Object fn; | |
3984 | switch (max_args) | |
3985 | { | |
3986 | case MANY: | |
3987 | fn = scm_c_make_gsubr (lname, 0, 0, 1, gsubr_fn); | |
3988 | break; | |
3989 | case UNEVALLED: | |
3990 | fn = Fcons (Qspecial_operator, | |
3991 | scm_c_make_gsubr (lname, 0, 0, 1, gsubr_fn)); | |
3992 | break; | |
3993 | default: | |
3994 | fn = scm_c_make_gsubr (lname, min_args, max_args - min_args, 0, gsubr_fn); | |
3995 | break; | |
3996 | } | |
3997 | set_symbol_function (sym, fn); | |
3998 | if (intspec) | |
3999 | { | |
4000 | Lisp_Object tem = ((*intspec != '(') | |
4001 | ? build_string (intspec) | |
4002 | : Fcar (Fread_from_string (build_string (intspec), | |
4003 | Qnil, Qnil))); | |
4004 | scm_set_procedure_property_x (fn, Qinteractive_form, tem); | |
4005 | } | |
078e7b4a JB |
4006 | } |
4007 | ||
039c6cc3 | 4008 | /* Define an "integer variable"; a symbol whose value is forwarded to a |
82cb60d3 | 4009 | C variable of type EMACS_INT. Sample call (with "xx" to fool make-docfile): |
039c6cc3 | 4010 | DEFxxVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */ |
078e7b4a | 4011 | void |
ce5b453a SM |
4012 | defvar_int (struct Lisp_Intfwd *i_fwd, |
4013 | const char *namestring, EMACS_INT *address) | |
078e7b4a | 4014 | { |
ce5b453a | 4015 | Lisp_Object sym; |
5e2327cf | 4016 | sym = intern_c_string (namestring); |
ce5b453a SM |
4017 | i_fwd->type = Lisp_Fwd_Int; |
4018 | i_fwd->intvar = address; | |
844e0de1 BT |
4019 | SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (sym), 1); |
4020 | SET_SYMBOL_REDIRECT (XSYMBOL (sym), SYMBOL_FORWARDED); | |
ce5b453a | 4021 | SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)i_fwd); |
078e7b4a JB |
4022 | } |
4023 | ||
f0529b5b | 4024 | /* Similar but define a variable whose value is t if address contains 1, |
0f011df0 | 4025 | nil if address contains 0. */ |
078e7b4a | 4026 | void |
ce5b453a | 4027 | defvar_bool (struct Lisp_Boolfwd *b_fwd, |
f5d9e83a | 4028 | const char *namestring, bool *address) |
078e7b4a | 4029 | { |
ce5b453a | 4030 | Lisp_Object sym; |
5e2327cf | 4031 | sym = intern_c_string (namestring); |
ce5b453a SM |
4032 | b_fwd->type = Lisp_Fwd_Bool; |
4033 | b_fwd->boolvar = address; | |
844e0de1 BT |
4034 | SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (sym), 1); |
4035 | SET_SYMBOL_REDIRECT (XSYMBOL (sym), SYMBOL_FORWARDED); | |
ce5b453a | 4036 | SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)b_fwd); |
1ffcc3b1 | 4037 | Vbyte_boolean_vars = Fcons (sym, Vbyte_boolean_vars); |
078e7b4a JB |
4038 | } |
4039 | ||
1a0f90f7 KH |
4040 | /* Similar but define a variable whose value is the Lisp Object stored |
4041 | at address. Two versions: with and without gc-marking of the C | |
4042 | variable. The nopro version is used when that variable will be | |
4043 | gc-marked for some other reason, since marking the same slot twice | |
4044 | can cause trouble with strings. */ | |
078e7b4a | 4045 | void |
ce5b453a SM |
4046 | defvar_lisp_nopro (struct Lisp_Objfwd *o_fwd, |
4047 | const char *namestring, Lisp_Object *address) | |
078e7b4a | 4048 | { |
ce5b453a | 4049 | Lisp_Object sym; |
5e2327cf | 4050 | sym = intern_c_string (namestring); |
ce5b453a SM |
4051 | o_fwd->type = Lisp_Fwd_Obj; |
4052 | o_fwd->objvar = address; | |
844e0de1 BT |
4053 | SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (sym), 1); |
4054 | SET_SYMBOL_REDIRECT (XSYMBOL (sym), SYMBOL_FORWARDED); | |
ce5b453a | 4055 | SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)o_fwd); |
078e7b4a JB |
4056 | } |
4057 | ||
078e7b4a | 4058 | void |
ce5b453a SM |
4059 | defvar_lisp (struct Lisp_Objfwd *o_fwd, |
4060 | const char *namestring, Lisp_Object *address) | |
078e7b4a | 4061 | { |
ce5b453a | 4062 | defvar_lisp_nopro (o_fwd, namestring, address); |
1a0f90f7 | 4063 | staticpro (address); |
078e7b4a JB |
4064 | } |
4065 | ||
950c215d | 4066 | /* Similar but define a variable whose value is the Lisp Object stored |
4ac38690 | 4067 | at a particular offset in the current kboard object. */ |
950c215d KH |
4068 | |
4069 | void | |
ce5b453a SM |
4070 | defvar_kboard (struct Lisp_Kboard_Objfwd *ko_fwd, |
4071 | const char *namestring, int offset) | |
950c215d | 4072 | { |
ce5b453a | 4073 | Lisp_Object sym; |
5e2327cf | 4074 | sym = intern_c_string (namestring); |
ce5b453a SM |
4075 | ko_fwd->type = Lisp_Fwd_Kboard_Obj; |
4076 | ko_fwd->offset = offset; | |
844e0de1 BT |
4077 | SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (sym), 1); |
4078 | SET_SYMBOL_REDIRECT (XSYMBOL (sym), SYMBOL_FORWARDED); | |
ce5b453a | 4079 | SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)ko_fwd); |
950c215d | 4080 | } |
078e7b4a | 4081 | \f |
17e0445b | 4082 | /* Check that the elements of lpath exist. */ |
929e7845 | 4083 | |
b3350bf9 | 4084 | static void |
17e0445b | 4085 | load_path_check (Lisp_Object lpath) |
929e7845 GM |
4086 | { |
4087 | Lisp_Object path_tail; | |
4088 | ||
4089 | /* The only elements that might not exist are those from | |
4090 | PATH_LOADSEARCH, EMACSLOADPATH. Anything else is only added if | |
4091 | it exists. */ | |
17e0445b | 4092 | for (path_tail = lpath; !NILP (path_tail); path_tail = XCDR (path_tail)) |
929e7845 GM |
4093 | { |
4094 | Lisp_Object dirfile; | |
4095 | dirfile = Fcar (path_tail); | |
4096 | if (STRINGP (dirfile)) | |
4097 | { | |
4098 | dirfile = Fdirectory_file_name (dirfile); | |
73dcdb9f PE |
4099 | if (! file_accessible_directory_p (SSDATA (dirfile))) |
4100 | dir_warning ("Lisp directory", XCAR (path_tail)); | |
929e7845 GM |
4101 | } |
4102 | } | |
4103 | } | |
4104 | ||
17e0445b GM |
4105 | /* Return the default load-path, to be used if EMACSLOADPATH is unset. |
4106 | This does not include the standard site-lisp directories | |
4107 | under the installation prefix (i.e., PATH_SITELOADSEARCH), | |
4108 | but it does (unless no_site_lisp is set) include site-lisp | |
4109 | directories in the source/build directories if those exist and we | |
4110 | are running uninstalled. | |
4111 | ||
4112 | Uses the following logic: | |
4113 | If CANNOT_DUMP: Use PATH_LOADSEARCH. | |
929e7845 GM |
4114 | The remainder is what happens when dumping works: |
4115 | If purify-flag (ie dumping) just use PATH_DUMPLOADSEARCH. | |
17e0445b | 4116 | Otherwise use PATH_LOADSEARCH. |
929e7845 | 4117 | |
06a4f110 GM |
4118 | If !initialized, then just return PATH_DUMPLOADSEARCH. |
4119 | If initialized: | |
929e7845 GM |
4120 | If Vinstallation_directory is not nil (ie, running uninstalled): |
4121 | If installation-dir/lisp exists and not already a member, | |
4122 | we must be running uninstalled. Reset the load-path | |
4123 | to just installation-dir/lisp. (The default PATH_LOADSEARCH | |
4124 | refers to the eventual installation directories. Since we | |
4125 | are not yet installed, we should not use them, even if they exist.) | |
06a4f110 GM |
4126 | If installation-dir/lisp does not exist, just add |
4127 | PATH_DUMPLOADSEARCH at the end instead. | |
929e7845 GM |
4128 | Add installation-dir/site-lisp (if !no_site_lisp, and exists |
4129 | and not already a member) at the front. | |
4130 | If installation-dir != source-dir (ie running an uninstalled, | |
4131 | out-of-tree build) AND install-dir/src/Makefile exists BUT | |
4132 | install-dir/src/Makefile.in does NOT exist (this is a sanity | |
cb6c95a3 | 4133 | check), then repeat the above steps for source-dir/lisp, site-lisp. */ |
4aaf6b61 PE |
4134 | |
4135 | static Lisp_Object | |
dc7909c4 | 4136 | load_path_default (void) |
078e7b4a | 4137 | { |
17e0445b | 4138 | Lisp_Object lpath = Qnil; |
8ea90aa3 | 4139 | const char *normal; |
ca26824c | 4140 | |
46947372 | 4141 | #ifdef CANNOT_DUMP |
9e059e3f GM |
4142 | #ifdef HAVE_NS |
4143 | const char *loadpath = ns_load_path (); | |
4144 | #endif | |
4145 | ||
46947372 | 4146 | normal = PATH_LOADSEARCH; |
9e059e3f | 4147 | #ifdef HAVE_NS |
17e0445b | 4148 | lpath = decode_env_path (0, loadpath ? loadpath : normal, 0); |
9e059e3f | 4149 | #else |
17e0445b | 4150 | lpath = decode_env_path (0, normal, 0); |
9e059e3f | 4151 | #endif |
929e7845 | 4152 | |
76151e2c | 4153 | #else /* !CANNOT_DUMP */ |
17e0445b GM |
4154 | |
4155 | normal = NILP (Vpurify_flag) ? PATH_LOADSEARCH : PATH_DUMPLOADSEARCH; | |
279499f0 | 4156 | |
4746118a JB |
4157 | if (initialized) |
4158 | { | |
9e059e3f | 4159 | #ifdef HAVE_NS |
06a4f110 GM |
4160 | const char *loadpath = ns_load_path (); |
4161 | lpath = decode_env_path (0, loadpath ? loadpath : normal, 0); | |
9e059e3f | 4162 | #else |
06a4f110 | 4163 | lpath = decode_env_path (0, normal, 0); |
9e059e3f | 4164 | #endif |
06a4f110 GM |
4165 | if (!NILP (Vinstallation_directory)) |
4166 | { | |
4167 | Lisp_Object tem, tem1; | |
4168 | ||
4169 | /* Add to the path the lisp subdir of the installation | |
4170 | dir, if it is accessible. Note: in out-of-tree builds, | |
4171 | this directory is empty save for Makefile. */ | |
4172 | tem = Fexpand_file_name (build_string ("lisp"), | |
4173 | Vinstallation_directory); | |
4174 | tem1 = Ffile_accessible_directory_p (tem); | |
4175 | if (!NILP (tem1)) | |
4176 | { | |
4177 | if (NILP (Fmember (tem, lpath))) | |
4178 | { | |
4179 | /* We are running uninstalled. The default load-path | |
4180 | points to the eventual installed lisp directories. | |
4181 | We should not use those now, even if they exist, | |
4182 | so start over from a clean slate. */ | |
4183 | lpath = list1 (tem); | |
4184 | } | |
4185 | } | |
4186 | else | |
4187 | /* That dir doesn't exist, so add the build-time | |
4188 | Lisp dirs instead. */ | |
17e0445b | 4189 | { |
06a4f110 GM |
4190 | Lisp_Object dump_path = |
4191 | decode_env_path (0, PATH_DUMPLOADSEARCH, 0); | |
4192 | lpath = nconc2 (lpath, dump_path); | |
4193 | } | |
ca26824c | 4194 | |
06a4f110 GM |
4195 | /* Add site-lisp under the installation dir, if it exists. */ |
4196 | if (!no_site_lisp) | |
4197 | { | |
4198 | tem = Fexpand_file_name (build_string ("site-lisp"), | |
ca26824c | 4199 | Vinstallation_directory); |
73dcdb9f | 4200 | tem1 = Ffile_accessible_directory_p (tem); |
ca26824c GM |
4201 | if (!NILP (tem1)) |
4202 | { | |
17e0445b | 4203 | if (NILP (Fmember (tem, lpath))) |
06a4f110 | 4204 | lpath = Fcons (tem, lpath); |
ca26824c | 4205 | } |
06a4f110 | 4206 | } |
ca26824c | 4207 | |
06a4f110 GM |
4208 | /* If Emacs was not built in the source directory, |
4209 | and it is run from where it was built, add to load-path | |
4210 | the lisp and site-lisp dirs under that directory. */ | |
ca26824c | 4211 | |
06a4f110 GM |
4212 | if (NILP (Fequal (Vinstallation_directory, Vsource_directory))) |
4213 | { | |
4214 | Lisp_Object tem2; | |
4215 | ||
4216 | tem = Fexpand_file_name (build_string ("src/Makefile"), | |
4217 | Vinstallation_directory); | |
4218 | tem1 = Ffile_exists_p (tem); | |
ca26824c | 4219 | |
06a4f110 GM |
4220 | /* Don't be fooled if they moved the entire source tree |
4221 | AFTER dumping Emacs. If the build directory is indeed | |
4222 | different from the source dir, src/Makefile.in and | |
4223 | src/Makefile will not be found together. */ | |
4224 | tem = Fexpand_file_name (build_string ("src/Makefile.in"), | |
4225 | Vinstallation_directory); | |
4226 | tem2 = Ffile_exists_p (tem); | |
4227 | if (!NILP (tem1) && NILP (tem2)) | |
ca26824c | 4228 | { |
06a4f110 GM |
4229 | tem = Fexpand_file_name (build_string ("lisp"), |
4230 | Vsource_directory); | |
ca26824c | 4231 | |
06a4f110 GM |
4232 | if (NILP (Fmember (tem, lpath))) |
4233 | lpath = Fcons (tem, lpath); | |
ca26824c | 4234 | |
06a4f110 GM |
4235 | if (!no_site_lisp) |
4236 | { | |
4237 | tem = Fexpand_file_name (build_string ("site-lisp"), | |
4238 | Vsource_directory); | |
4239 | tem1 = Ffile_accessible_directory_p (tem); | |
4240 | if (!NILP (tem1)) | |
ca26824c | 4241 | { |
06a4f110 GM |
4242 | if (NILP (Fmember (tem, lpath))) |
4243 | lpath = Fcons (tem, lpath); | |
ca26824c GM |
4244 | } |
4245 | } | |
06a4f110 GM |
4246 | } |
4247 | } /* Vinstallation_directory != Vsource_directory */ | |
929e7845 | 4248 | |
06a4f110 | 4249 | } /* if Vinstallation_directory */ |
4746118a | 4250 | } |
9d8d07e5 | 4251 | else /* !initialized */ |
11938f10 | 4252 | { |
929e7845 GM |
4253 | /* NORMAL refers to PATH_DUMPLOADSEARCH, ie the lisp dir in the |
4254 | source directory. We used to add ../lisp (ie the lisp dir in | |
06a4f110 GM |
4255 | the build directory) at the front here, but that should not |
4256 | be necessary, since in out of tree builds lisp/ is empty, save | |
929e7845 | 4257 | for Makefile. */ |
17e0445b | 4258 | lpath = decode_env_path (0, normal, 0); |
11938f10 | 4259 | } |
17e0445b GM |
4260 | #endif /* !CANNOT_DUMP */ |
4261 | ||
4262 | return lpath; | |
4263 | } | |
4264 | ||
4265 | void | |
4266 | init_lread (void) | |
4267 | { | |
4268 | /* First, set Vload_path. */ | |
4269 | ||
8fb8c4f3 PE |
4270 | /* Ignore EMACSLOADPATH when dumping. */ |
4271 | #ifdef CANNOT_DUMP | |
4272 | bool use_loadpath = true; | |
4273 | #else | |
f952002e | 4274 | bool use_loadpath = NILP (Vpurify_flag); |
8fb8c4f3 PE |
4275 | #endif |
4276 | ||
4277 | if (use_loadpath && egetenv ("EMACSLOADPATH")) | |
17e0445b | 4278 | { |
06a4f110 | 4279 | Vload_path = decode_env_path ("EMACSLOADPATH", 0, 1); |
17e0445b GM |
4280 | |
4281 | /* Check (non-nil) user-supplied elements. */ | |
06a4f110 | 4282 | load_path_check (Vload_path); |
17e0445b | 4283 | |
310294a3 GM |
4284 | /* If no nils in the environment variable, use as-is. |
4285 | Otherwise, replace any nils with the default. */ | |
06a4f110 | 4286 | if (! NILP (Fmemq (Qnil, Vload_path))) |
17e0445b | 4287 | { |
06a4f110 GM |
4288 | Lisp_Object elem, elpath = Vload_path; |
4289 | Lisp_Object default_lpath = load_path_default (); | |
17e0445b GM |
4290 | |
4291 | /* Check defaults, before adding site-lisp. */ | |
4292 | load_path_check (default_lpath); | |
4293 | ||
4294 | /* Add the site-lisp directories to the front of the default. */ | |
4295 | if (!no_site_lisp) | |
4296 | { | |
4297 | Lisp_Object sitelisp; | |
4298 | sitelisp = decode_env_path (0, PATH_SITELOADSEARCH, 0); | |
4299 | if (! NILP (sitelisp)) | |
4300 | default_lpath = nconc2 (sitelisp, default_lpath); | |
4301 | } | |
4302 | ||
4303 | Vload_path = Qnil; | |
4304 | ||
4305 | /* Replace nils from EMACSLOADPATH by default. */ | |
310294a3 | 4306 | while (CONSP (elpath)) |
17e0445b GM |
4307 | { |
4308 | Lisp_Object arg[2]; | |
310294a3 GM |
4309 | elem = XCAR (elpath); |
4310 | elpath = XCDR (elpath); | |
17e0445b GM |
4311 | arg[0] = Vload_path; |
4312 | arg[1] = NILP (elem) ? default_lpath : Fcons (elem, Qnil); | |
4313 | Vload_path = Fappend (2, arg); | |
4314 | } | |
4315 | } /* Fmemq (Qnil, Vload_path) */ | |
4316 | } | |
f952002e | 4317 | else |
17e0445b | 4318 | { |
06a4f110 | 4319 | Vload_path = load_path_default (); |
17e0445b GM |
4320 | |
4321 | /* Check before adding site-lisp directories. | |
4322 | The install should have created them, but they are not | |
4323 | required, so no need to warn if they are absent. | |
4324 | Or we might be running before installation. */ | |
4325 | load_path_check (Vload_path); | |
4326 | ||
06a4f110 GM |
4327 | /* Add the site-lisp directories at the front. */ |
4328 | if (initialized && !no_site_lisp) | |
17e0445b GM |
4329 | { |
4330 | Lisp_Object sitelisp; | |
4331 | sitelisp = decode_env_path (0, PATH_SITELOADSEARCH, 0); | |
4332 | if (! NILP (sitelisp)) Vload_path = nconc2 (sitelisp, Vload_path); | |
4333 | } | |
f952002e | 4334 | } |
279499f0 | 4335 | |
279499f0 JB |
4336 | Vvalues = Qnil; |
4337 | ||
078e7b4a | 4338 | load_in_progress = 0; |
4e53f562 | 4339 | Vload_file_name = Qnil; |
8f6b0411 | 4340 | Vstandard_input = Qt; |
f74b0705 | 4341 | Vloads_in_progress = Qnil; |
078e7b4a JB |
4342 | } |
4343 | ||
73dcdb9f PE |
4344 | /* Print a warning that directory intended for use USE and with name |
4345 | DIRNAME cannot be accessed. On entry, errno should correspond to | |
4346 | the access failure. Print the warning on stderr and put it in | |
4347 | *Messages*. */ | |
85496b8c | 4348 | |
d5b28a9d | 4349 | void |
73dcdb9f | 4350 | dir_warning (char const *use, Lisp_Object dirname) |
85496b8c | 4351 | { |
73dcdb9f PE |
4352 | static char const format[] = "Warning: %s `%s': %s\n"; |
4353 | int access_errno = errno; | |
4354 | fprintf (stderr, format, use, SSDATA (dirname), strerror (access_errno)); | |
0df02bf3 | 4355 | |
48def666 | 4356 | /* Don't log the warning before we've initialized!! */ |
9b69357e | 4357 | if (initialized) |
0df02bf3 | 4358 | { |
73dcdb9f | 4359 | char const *diagnostic = emacs_strerror (access_errno); |
0df02bf3 | 4360 | USE_SAFE_ALLOCA; |
73dcdb9f PE |
4361 | char *buffer = SAFE_ALLOCA (sizeof format - 3 * (sizeof "%s" - 1) |
4362 | + strlen (use) + SBYTES (dirname) | |
4363 | + strlen (diagnostic)); | |
4364 | ptrdiff_t message_len = esprintf (buffer, format, use, SSDATA (dirname), | |
4365 | diagnostic); | |
0df02bf3 PE |
4366 | message_dolog (buffer, message_len, 0, STRING_MULTIBYTE (dirname)); |
4367 | SAFE_FREE (); | |
4368 | } | |
85496b8c RS |
4369 | } |
4370 | ||
078e7b4a | 4371 | void |
971de7fb | 4372 | syms_of_lread (void) |
078e7b4a | 4373 | { |
fe6aa7a1 | 4374 | #include "lread.x" |
078e7b4a | 4375 | |
29208e82 | 4376 | DEFVAR_LISP ("obarray", Vobarray, |
5de38842 PJ |
4377 | doc: /* Symbol table for use by `intern' and `read'. |
4378 | It is a vector whose length ought to be prime for best results. | |
4379 | The vector's contents don't make sense if examined from Lisp programs; | |
4380 | to find all the symbols in an obarray, use `mapatoms'. */); | |
078e7b4a | 4381 | |
29208e82 | 4382 | DEFVAR_LISP ("values", Vvalues, |
5de38842 | 4383 | doc: /* List of values of all expressions which were read, evaluated and printed. |
513749ee | 4384 | Order is reverse chronological. */); |
844e0de1 | 4385 | SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (intern ("values")), 0); |
078e7b4a | 4386 | |
29208e82 | 4387 | DEFVAR_LISP ("standard-input", Vstandard_input, |
5de38842 PJ |
4388 | doc: /* Stream for read to get input from. |
4389 | See documentation of `read' for possible values. */); | |
078e7b4a JB |
4390 | Vstandard_input = Qt; |
4391 | ||
29208e82 | 4392 | DEFVAR_LISP ("read-with-symbol-positions", Vread_with_symbol_positions, |
abb13b09 CW |
4393 | doc: /* If non-nil, add position of read symbols to `read-symbol-positions-list'. |
4394 | ||
4395 | If this variable is a buffer, then only forms read from that buffer | |
4396 | will be added to `read-symbol-positions-list'. | |
4397 | If this variable is t, then all read forms will be added. | |
4398 | The effect of all other values other than nil are not currently | |
4399 | defined, although they may be in the future. | |
4400 | ||
4401 | The positions are relative to the last call to `read' or | |
4402 | `read-from-string'. It is probably a bad idea to set this variable at | |
513749ee | 4403 | the toplevel; bind it instead. */); |
abb13b09 CW |
4404 | Vread_with_symbol_positions = Qnil; |
4405 | ||
29208e82 | 4406 | DEFVAR_LISP ("read-symbol-positions-list", Vread_symbol_positions_list, |
d6567030 | 4407 | doc: /* A list mapping read symbols to their positions. |
abb13b09 CW |
4408 | This variable is modified during calls to `read' or |
4409 | `read-from-string', but only when `read-with-symbol-positions' is | |
4410 | non-nil. | |
4411 | ||
4412 | Each element of the list looks like (SYMBOL . CHAR-POSITION), where | |
d6567030 | 4413 | CHAR-POSITION is an integer giving the offset of that occurrence of the |
abb13b09 CW |
4414 | symbol from the position where `read' or `read-from-string' started. |
4415 | ||
4416 | Note that a symbol will appear multiple times in this list, if it was | |
4417 | read multiple times. The list is in the same order as the symbols | |
513749ee | 4418 | were read in. */); |
177c0ea7 | 4419 | Vread_symbol_positions_list = Qnil; |
abb13b09 | 4420 | |
29208e82 | 4421 | DEFVAR_LISP ("read-circle", Vread_circle, |
91f68422 CY |
4422 | doc: /* Non-nil means read recursive structures using #N= and #N# syntax. */); |
4423 | Vread_circle = Qt; | |
4424 | ||
29208e82 | 4425 | DEFVAR_LISP ("load-path", Vload_path, |
fb7ada5f | 4426 | doc: /* List of directories to search for files to load. |
17e0445b GM |
4427 | Each element is a string (directory name) or nil (meaning `default-directory'). |
4428 | Initialized during startup as described in Info node `(elisp)Library Search'. */); | |
078e7b4a | 4429 | |
29208e82 | 4430 | DEFVAR_LISP ("load-suffixes", Vload_suffixes, |
971a4293 LT |
4431 | doc: /* List of suffixes for (compiled or source) Emacs Lisp files. |
4432 | This list should not include the empty string. | |
4433 | `load' and related functions try to append these suffixes, in order, | |
4434 | to the specified file name if a Lisp suffix is allowed or required. */); | |
6c6f1994 PE |
4435 | Vload_suffixes = list2 (build_pure_c_string (".elc"), |
4436 | build_pure_c_string (".el")); | |
29208e82 | 4437 | DEFVAR_LISP ("load-file-rep-suffixes", Vload_file_rep_suffixes, |
971a4293 LT |
4438 | doc: /* List of suffixes that indicate representations of \ |
4439 | the same file. | |
4440 | This list should normally start with the empty string. | |
4441 | ||
4442 | Enabling Auto Compression mode appends the suffixes in | |
4443 | `jka-compr-load-suffixes' to this list and disabling Auto Compression | |
4444 | mode removes them again. `load' and related functions use this list to | |
4445 | determine whether they should look for compressed versions of a file | |
4446 | and, if so, which suffixes they should try to append to the file name | |
4447 | in order to do so. However, if you want to customize which suffixes | |
4448 | the loading functions recognize as compression suffixes, you should | |
4449 | customize `jka-compr-load-suffixes' rather than the present variable. */); | |
6c6f1994 | 4450 | Vload_file_rep_suffixes = list1 (empty_unibyte_string); |
e61b9b87 | 4451 | |
29208e82 | 4452 | DEFVAR_BOOL ("load-in-progress", load_in_progress, |
e0f24100 | 4453 | doc: /* Non-nil if inside of `load'. */); |
cd3520a4 | 4454 | DEFSYM (Qload_in_progress, "load-in-progress"); |
078e7b4a | 4455 | |
29208e82 | 4456 | DEFVAR_LISP ("after-load-alist", Vafter_load_alist, |
de0503df SM |
4457 | doc: /* An alist of functions to be evalled when particular files are loaded. |
4458 | Each element looks like (REGEXP-OR-FEATURE FUNCS...). | |
6bb6da3e AM |
4459 | |
4460 | REGEXP-OR-FEATURE is either a regular expression to match file names, or | |
4461 | a symbol \(a feature name). | |
4462 | ||
4463 | When `load' is run and the file-name argument matches an element's | |
4464 | REGEXP-OR-FEATURE, or when `provide' is run and provides the symbol | |
de0503df | 4465 | REGEXP-OR-FEATURE, the FUNCS in the element are called. |
6bb6da3e AM |
4466 | |
4467 | An error in FORMS does not undo the load, but does prevent execution of | |
4468 | the rest of the FORMS. */); | |
078e7b4a JB |
4469 | Vafter_load_alist = Qnil; |
4470 | ||
29208e82 | 4471 | DEFVAR_LISP ("load-history", Vload_history, |
4801c5fa CY |
4472 | doc: /* Alist mapping loaded file names to symbols and features. |
4473 | Each alist element should be a list (FILE-NAME ENTRIES...), where | |
4474 | FILE-NAME is the name of a file that has been loaded into Emacs. | |
4475 | The file name is absolute and true (i.e. it doesn't contain symlinks). | |
4476 | As an exception, one of the alist elements may have FILE-NAME nil, | |
4477 | for symbols and features not associated with any file. | |
4478 | ||
4479 | The remaining ENTRIES in the alist element describe the functions and | |
4480 | variables defined in that file, the features provided, and the | |
4481 | features required. Each entry has the form `(provide . FEATURE)', | |
4482 | `(require . FEATURE)', `(defun . FUNCTION)', `(autoload . SYMBOL)', | |
69bb1ef7 LMI |
4483 | `(defface . SYMBOL)', or `(t . SYMBOL)'. Entries like `(t . SYMBOL)' |
4484 | may precede a `(defun . FUNCTION)' entry, and means that SYMBOL was an | |
4485 | autoload before this file redefined it as a function. In addition, | |
4486 | entries may also be single symbols, which means that SYMBOL was | |
4487 | defined by `defvar' or `defconst'. | |
0fc213e9 | 4488 | |
b502a9a1 RS |
4489 | During preloading, the file name recorded is relative to the main Lisp |
4490 | directory. These file names are converted to absolute at startup. */); | |
ae321d28 RS |
4491 | Vload_history = Qnil; |
4492 | ||
29208e82 | 4493 | DEFVAR_LISP ("load-file-name", Vload_file_name, |
5de38842 | 4494 | doc: /* Full name of file being loaded by `load'. */); |
20ea2964 RS |
4495 | Vload_file_name = Qnil; |
4496 | ||
29208e82 | 4497 | DEFVAR_LISP ("user-init-file", Vuser_init_file, |
5de38842 | 4498 | doc: /* File name, including directory, of user's initialization file. |
0a25a201 RS |
4499 | If the file loaded had extension `.elc', and the corresponding source file |
4500 | exists, this variable contains the name of source file, suitable for use | |
099de390 JB |
4501 | by functions like `custom-save-all' which edit the init file. |
4502 | While Emacs loads and evaluates the init file, value is the real name | |
4503 | of the file, regardless of whether or not it has the `.elc' extension. */); | |
4116ab9f KH |
4504 | Vuser_init_file = Qnil; |
4505 | ||
29208e82 | 4506 | DEFVAR_LISP ("current-load-list", Vcurrent_load_list, |
5de38842 | 4507 | doc: /* Used for internal purposes by `load'. */); |
ae321d28 RS |
4508 | Vcurrent_load_list = Qnil; |
4509 | ||
29208e82 | 4510 | DEFVAR_LISP ("load-read-function", Vload_read_function, |
5de38842 PJ |
4511 | doc: /* Function used by `load' and `eval-region' for reading expressions. |
4512 | The default is nil, which means use the function `read'. */); | |
84a15045 RS |
4513 | Vload_read_function = Qnil; |
4514 | ||
29208e82 | 4515 | DEFVAR_LISP ("load-source-file-function", Vload_source_file_function, |
76b92fee CS |
4516 | doc: /* Function called in `load' to load an Emacs Lisp source file. |
4517 | The value should be a function for doing code conversion before | |
4518 | reading a source file. It can also be nil, in which case loading is | |
4519 | done without any code conversion. | |
4520 | ||
4521 | If the value is a function, it is called with four arguments, | |
4522 | FULLNAME, FILE, NOERROR, NOMESSAGE. FULLNAME is the absolute name of | |
4523 | the file to load, FILE is the non-absolute name (for messages etc.), | |
4524 | and NOERROR and NOMESSAGE are the corresponding arguments passed to | |
4525 | `load'. The function should return t if the file was loaded. */); | |
fe0e03f3 KH |
4526 | Vload_source_file_function = Qnil; |
4527 | ||
29208e82 | 4528 | DEFVAR_BOOL ("load-force-doc-strings", load_force_doc_strings, |
5de38842 PJ |
4529 | doc: /* Non-nil means `load' should force-load all dynamic doc strings. |
4530 | This is useful when the file being loaded is a temporary copy. */); | |
b2a30870 RS |
4531 | load_force_doc_strings = 0; |
4532 | ||
29208e82 | 4533 | DEFVAR_BOOL ("load-convert-to-unibyte", load_convert_to_unibyte, |
5de38842 PJ |
4534 | doc: /* Non-nil means `read' converts strings to unibyte whenever possible. |
4535 | This is normally bound by `load' and `eval-buffer' to control `read', | |
4536 | and is not meant for users to change. */); | |
94e554db RS |
4537 | load_convert_to_unibyte = 0; |
4538 | ||
29208e82 | 4539 | DEFVAR_LISP ("source-directory", Vsource_directory, |
5de38842 PJ |
4540 | doc: /* Directory in which Emacs sources were found when Emacs was built. |
4541 | You cannot count on them to still be there! */); | |
a90ba1e2 KH |
4542 | Vsource_directory |
4543 | = Fexpand_file_name (build_string ("../"), | |
17e0445b | 4544 | Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH, 0))); |
a90ba1e2 | 4545 | |
29208e82 | 4546 | DEFVAR_LISP ("preloaded-file-list", Vpreloaded_file_list, |
5de38842 | 4547 | doc: /* List of files that were preloaded (when dumping Emacs). */); |
4b104c41 RS |
4548 | Vpreloaded_file_list = Qnil; |
4549 | ||
29208e82 | 4550 | DEFVAR_LISP ("byte-boolean-vars", Vbyte_boolean_vars, |
5de38842 | 4551 | doc: /* List of all DEFVAR_BOOL variables, used by the byte code optimizer. */); |
1ffcc3b1 DL |
4552 | Vbyte_boolean_vars = Qnil; |
4553 | ||
29208e82 | 4554 | DEFVAR_BOOL ("load-dangerous-libraries", load_dangerous_libraries, |
5de38842 PJ |
4555 | doc: /* Non-nil means load dangerous compiled Lisp files. |
4556 | Some versions of XEmacs use different byte codes than Emacs. These | |
4557 | incompatible byte codes can make Emacs crash when it tries to execute | |
4558 | them. */); | |
da84f340 GM |
4559 | load_dangerous_libraries = 0; |
4560 | ||
29208e82 | 4561 | DEFVAR_BOOL ("force-load-messages", force_load_messages, |
beb0b7f9 EZ |
4562 | doc: /* Non-nil means force printing messages when loading Lisp files. |
4563 | This overrides the value of the NOMESSAGE argument to `load'. */); | |
4564 | force_load_messages = 0; | |
4565 | ||
29208e82 | 4566 | DEFVAR_LISP ("bytecomp-version-regexp", Vbytecomp_version_regexp, |
5de38842 PJ |
4567 | doc: /* Regular expression matching safe to load compiled Lisp files. |
4568 | When Emacs loads a compiled Lisp file, it reads the first 512 bytes | |
4569 | from the file, and matches them against this regular expression. | |
4570 | When the regular expression matches, the file is considered to be safe | |
4571 | to load. See also `load-dangerous-libraries'. */); | |
bb970e67 | 4572 | Vbytecomp_version_regexp |
2a0213a6 | 4573 | = build_pure_c_string ("^;;;.\\(in Emacs version\\|bytecomp version FSF\\)"); |
da84f340 | 4574 | |
14ae4239 | 4575 | DEFSYM (Qlexical_binding, "lexical-binding"); |
8f1d2ef6 | 4576 | DEFVAR_LISP ("lexical-binding", Vlexical_binding, |
f41628b2 LMI |
4577 | doc: /* Whether to use lexical binding when evaluating code. |
4578 | Non-nil means that the code in the current buffer should be evaluated | |
4579 | with lexical binding. | |
1d698799 | 4580 | This variable is automatically set from the file variables of an |
48da7392 GM |
4581 | interpreted Lisp file read using `load'. Unlike other file local |
4582 | variables, this must be set in the first line of a file. */); | |
14ae4239 | 4583 | Vlexical_binding = Qnil; |
b9598260 SM |
4584 | Fmake_variable_buffer_local (Qlexical_binding); |
4585 | ||
29208e82 | 4586 | DEFVAR_LISP ("eval-buffer-list", Veval_buffer_list, |
3f39f996 RS |
4587 | doc: /* List of buffers being read from by calls to `eval-buffer' and `eval-region'. */); |
4588 | Veval_buffer_list = Qnil; | |
4589 | ||
29208e82 | 4590 | DEFVAR_LISP ("old-style-backquotes", Vold_style_backquotes, |
5aa273b0 SM |
4591 | doc: /* Set to non-nil when `read' encounters an old-style backquote. */); |
4592 | Vold_style_backquotes = Qnil; | |
cd3520a4 | 4593 | DEFSYM (Qold_style_backquotes, "old-style-backquotes"); |
5aa273b0 | 4594 | |
1f41ee56 GM |
4595 | DEFVAR_BOOL ("load-prefer-newer", load_prefer_newer, |
4596 | doc: /* Non-nil means `load' prefers the newest version of a file. | |
4597 | This applies when a filename suffix is not explicitly specified and | |
4598 | `load' is trying various possible suffixes (see `load-suffixes' and | |
4599 | `load-file-rep-suffixes'). Normally, it stops at the first file | |
2dc383bc XF |
4600 | that exists unless you explicitly specify one or the other. If this |
4601 | option is non-nil, it checks all suffixes and uses whichever file is | |
4602 | newest. | |
1f41ee56 GM |
4603 | Note that if you customize this, obviously it will not affect files |
4604 | that are loaded before your customizations are read! */); | |
c16fbf67 | 4605 | load_prefer_newer = 1; |
1f41ee56 | 4606 | |
a90ba1e2 KH |
4607 | /* Vsource_directory was initialized in init_lread. */ |
4608 | ||
cd3520a4 JB |
4609 | DEFSYM (Qcurrent_load_list, "current-load-list"); |
4610 | DEFSYM (Qstandard_input, "standard-input"); | |
4611 | DEFSYM (Qread_char, "read-char"); | |
4612 | DEFSYM (Qget_file_char, "get-file-char"); | |
4613 | DEFSYM (Qget_emacs_mule_file_char, "get-emacs-mule-file-char"); | |
4614 | DEFSYM (Qload_force_doc_strings, "load-force-doc-strings"); | |
4615 | ||
4616 | DEFSYM (Qbackquote, "`"); | |
4617 | DEFSYM (Qcomma, ","); | |
4618 | DEFSYM (Qcomma_at, ",@"); | |
4619 | DEFSYM (Qcomma_dot, ",."); | |
4620 | ||
4621 | DEFSYM (Qinhibit_file_name_operation, "inhibit-file-name-operation"); | |
4622 | DEFSYM (Qascii_character, "ascii-character"); | |
4623 | DEFSYM (Qfunction, "function"); | |
4624 | DEFSYM (Qload, "load"); | |
4625 | DEFSYM (Qload_file_name, "load-file-name"); | |
4626 | DEFSYM (Qeval_buffer_list, "eval-buffer-list"); | |
4627 | DEFSYM (Qfile_truename, "file-truename"); | |
4628 | DEFSYM (Qdir_ok, "dir-ok"); | |
4629 | DEFSYM (Qdo_after_load_evaluation, "do-after-load-evaluation"); | |
6bb6da3e | 4630 | |
4ad679f9 EN |
4631 | staticpro (&read_objects); |
4632 | read_objects = Qnil; | |
9e062b6c | 4633 | staticpro (&seen_list); |
f153db13 | 4634 | seen_list = Qnil; |
177c0ea7 | 4635 | |
7ee3bd7b GM |
4636 | Vloads_in_progress = Qnil; |
4637 | staticpro (&Vloads_in_progress); | |
f19a0f5b | 4638 | |
cd3520a4 JB |
4639 | DEFSYM (Qhash_table, "hash-table"); |
4640 | DEFSYM (Qdata, "data"); | |
4641 | DEFSYM (Qtest, "test"); | |
4642 | DEFSYM (Qsize, "size"); | |
4643 | DEFSYM (Qweakness, "weakness"); | |
4644 | DEFSYM (Qrehash_size, "rehash-size"); | |
4645 | DEFSYM (Qrehash_threshold, "rehash-threshold"); | |
078e7b4a | 4646 | } |