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