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