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