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