Mercurial > hg > xemacs-beta
annotate src/lread.c @ 4454:1f0aa40cafe0
Small improvements in disp-table.el, mule/cyril-util.el.
2008-05-11 Aidan Kehoe <kehoea@parhasard.net>
* disp-table.el (make-display-table):
[...] Also, I previously said #xFF when I meant
?\xFF; correct this.
* mule/cyril-util.el (standard-display-cyrillic-translit):
Make the selection of the default language more sensible; change
the API a little to make a sensible default Cyrillic language
available, checking current-language-environment.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 11 May 2008 12:03:07 +0200 |
parents | ac6231e0c1df |
children | 7869173584fc |
rev | line source |
---|---|
428 | 1 /* Lisp parsing and input streams. |
2 Copyright (C) 1985-1989, 1992-1995 Free Software Foundation, Inc. | |
3 Copyright (C) 1995 Tinker Systems. | |
1261 | 4 Copyright (C) 1996, 2001, 2002, 2003 Ben Wing. |
428 | 5 |
6 This file is part of XEmacs. | |
7 | |
8 XEmacs is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
10 Free Software Foundation; either version 2, or (at your option) any | |
11 later version. | |
12 | |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with XEmacs; see the file COPYING. If not, write to | |
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 Boston, MA 02111-1307, USA. */ | |
22 | |
23 /* Synched up with: Mule 2.0, FSF 19.30. */ | |
24 | |
25 /* This file has been Mule-ized. */ | |
26 | |
27 #include <config.h> | |
28 #include "lisp.h" | |
29 | |
30 #include "buffer.h" | |
31 #include "bytecode.h" | |
32 #include "elhash.h" | |
1292 | 33 #include "file-coding.h" |
428 | 34 #include "lstream.h" |
35 #include "opaque.h" | |
1292 | 36 #include "profile.h" |
3439 | 37 #include "charset.h" /* For Funicode_to_char. */ |
428 | 38 |
39 #include "sysfile.h" | |
40 #include "sysfloat.h" | |
771 | 41 #ifdef WIN32_NATIVE |
42 #include "syswindows.h" | |
43 #endif | |
428 | 44 |
45 Lisp_Object Qread_char, Qstandard_input; | |
46 Lisp_Object Qvariable_documentation; | |
47 #define LISP_BACKQUOTES | |
48 #ifdef LISP_BACKQUOTES | |
49 /* | |
50 Nonzero means inside a new-style backquote | |
51 with no surrounding parentheses. | |
52 Fread initializes this to zero, so we need not specbind it | |
53 or worry about what happens to it when there is an error. | |
54 | |
55 XEmacs: | |
56 Nested backquotes are perfectly legal and fail utterly with | |
57 this silliness. */ | |
58 static int new_backquote_flag, old_backquote_flag; | |
59 Lisp_Object Qbackquote, Qbacktick, Qcomma, Qcomma_at, Qcomma_dot; | |
60 #endif | |
61 Lisp_Object Qvariable_domain; /* I18N3 */ | |
62 Lisp_Object Vvalues, Vstandard_input, Vafter_load_alist; | |
2548 | 63 Lisp_Object Vload_suppress_alist; |
64 Lisp_Object Qload, Qload_internal, Qfset; | |
428 | 65 |
66 /* Hash-table that maps directory names to hashes of their contents. */ | |
67 static Lisp_Object Vlocate_file_hash_table; | |
68 | |
69 Lisp_Object Qexists, Qreadable, Qwritable, Qexecutable; | |
70 | |
71 /* See read_escape() for an explanation of this. */ | |
72 #if 0 | |
73 int fail_on_bucky_bit_character_escapes; | |
74 #endif | |
75 | |
76 /* This symbol is also used in fns.c */ | |
77 #define FEATUREP_SYNTAX | |
78 | |
79 #ifdef FEATUREP_SYNTAX | |
80 Lisp_Object Qfeaturep; | |
81 #endif | |
82 | |
83 /* non-zero if inside `load' */ | |
84 int load_in_progress; | |
85 | |
86 /* Whether Fload_internal() should check whether the .el is newer | |
87 when loading .elc */ | |
88 int load_warn_when_source_newer; | |
89 /* Whether Fload_internal() should check whether the .elc doesn't exist */ | |
90 int load_warn_when_source_only; | |
91 /* Whether Fload_internal() should ignore .elc files when no suffix is given */ | |
92 int load_ignore_elc_files; | |
1123 | 93 /* Whether Fload_internal() should ignore out-of-date .elc files when no |
94 suffix is given */ | |
95 int load_ignore_out_of_date_elc_files; | |
96 /* Always display messages showing when a file is loaded, regardless of | |
97 whether the flag to `load' tries to suppress them. */ | |
98 int load_always_display_messages; | |
99 /* Show the full path in loading messages. */ | |
100 int load_show_full_path_in_messages; | |
428 | 101 |
102 /* Search path for files to be loaded. */ | |
103 Lisp_Object Vload_path; | |
104 | |
105 /* Search path for files when dumping. */ | |
106 /* Lisp_Object Vdump_load_path; */ | |
107 | |
108 /* This is the user-visible association list that maps features to | |
109 lists of defs in their load files. */ | |
110 Lisp_Object Vload_history; | |
111 | |
112 /* This is used to build the load history. */ | |
113 Lisp_Object Vcurrent_load_list; | |
114 | |
115 /* Name of file actually being read by `load'. */ | |
116 Lisp_Object Vload_file_name; | |
117 | |
118 /* Same as Vload_file_name but not Lisp-accessible. This ensures that | |
119 our #$ checks are reliable. */ | |
120 Lisp_Object Vload_file_name_internal; | |
121 | |
122 /* Function to use for reading, in `load' and friends. */ | |
123 Lisp_Object Vload_read_function; | |
124 | |
125 /* The association list of objects read with the #n=object form. | |
126 Each member of the list has the form (n . object), and is used to | |
127 look up the object for the corresponding #n# construct. | |
128 It must be set to nil before all top-level calls to read0. */ | |
129 Lisp_Object Vread_objects; | |
130 | |
131 /* Nonzero means load should forcibly load all dynamic doc strings. */ | |
132 /* Note that this always happens (with some special behavior) when | |
133 purify_flag is set. */ | |
134 static int load_force_doc_strings; | |
135 | |
136 /* List of descriptors now open for Fload_internal. */ | |
137 static Lisp_Object Vload_descriptor_list; | |
138 | |
139 /* In order to implement "load_force_doc_strings", we keep | |
140 a list of all the compiled-function objects and such | |
141 that we have created in the process of loading this file. | |
142 See the rant below. | |
143 | |
144 We specbind this just like Vload_file_name, so there's no | |
145 problems with recursive loading. */ | |
146 static Lisp_Object Vload_force_doc_string_list; | |
147 | |
148 /* A resizing-buffer stream used to temporarily hold data while reading */ | |
149 static Lisp_Object Vread_buffer_stream; | |
150 | |
151 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
152 Lisp_Object Vcurrent_compiled_function_annotation; | |
153 #endif | |
154 | |
155 static int load_byte_code_version; | |
156 | |
157 /* An array describing all known built-in structure types */ | |
158 static structure_type_dynarr *the_structure_type_dynarr; | |
159 | |
160 #if 0 /* FSF stuff */ | |
161 /* For use within read-from-string (this reader is non-reentrant!!) */ | |
162 static int read_from_string_index; | |
163 static int read_from_string_limit; | |
164 #endif | |
165 | |
166 #if 0 /* More FSF implementation kludges. */ | |
167 /* In order to implement load-force-doc-string, FSF saves the | |
168 #@-quoted string when it's seen, and goes back and retrieves | |
169 it later. | |
170 | |
171 This approach is not only kludgy, but it in general won't work | |
172 correctly because there's no stack of remembered #@-quoted-strings | |
173 and those strings don't generally appear in the file in the same | |
174 order as their #$ references. (Yes, that is amazingly stupid too. | |
175 | |
176 It would be trivially easy to always encode the #@ string | |
177 [which is a comment, anyway] in the middle of the (#$ . INT) cons | |
178 reference. That way, it would be really easy to implement | |
179 load-force-doc-string in a non-kludgy way by just retrieving the | |
180 string immediately, because it's delivered on a silver platter.) | |
181 | |
182 And finally, this stupid approach doesn't work under Mule, or | |
183 under MS-DOS or Windows NT, or under VMS, or any other place | |
184 where you either can't do an ftell() or don't get back a byte | |
185 count. | |
186 | |
187 Oh, and one more lossage in this approach: If you attempt to | |
188 dump any ELC files that were compiled with `byte-compile-dynamic' | |
189 (as opposed to just `byte-compile-dynamic-docstring'), you | |
190 get hosed. FMH! (as the illustrious JWZ was prone to utter) | |
191 | |
192 The approach we use is clean, solves all of these problems, and is | |
193 probably easier to implement anyway. We just save a list of all | |
194 the containing objects that have (#$ . INT) conses in them (this | |
195 will only be compiled-function objects and lists), and when the | |
196 file is finished loading, we go through and fill in all the | |
814 | 197 doc strings at once. --ben */ |
428 | 198 |
199 /* This contains the last string skipped with #@. */ | |
200 static char *saved_doc_string; | |
201 /* Length of buffer allocated in saved_doc_string. */ | |
202 static int saved_doc_string_size; | |
203 /* Length of actual data in saved_doc_string. */ | |
204 static int saved_doc_string_length; | |
205 /* This is the file position that string came from. */ | |
206 static int saved_doc_string_position; | |
207 #endif | |
208 | |
1123 | 209 static int locate_file_open_or_access_file (Ibyte *fn, int access_mode); |
428 | 210 EXFUN (Fread_from_string, 3); |
211 | |
212 /* When errors are signaled, the actual readcharfun should not be used | |
213 as an argument if it is an lstream, so that lstreams don't escape | |
214 to the Lisp level. */ | |
1261 | 215 #define READCHARFUN_MAYBE(x) (LSTREAMP (x) \ |
216 ? (build_msg_string ("internal input stream")) \ | |
428 | 217 : (x)) |
218 | |
219 | |
2268 | 220 static DECLARE_DOESNT_RETURN (read_syntax_error (const char *)); |
221 | |
428 | 222 static DOESNT_RETURN |
442 | 223 read_syntax_error (const char *string) |
428 | 224 { |
563 | 225 signal_error (Qinvalid_read_syntax, string, Qunbound); |
428 | 226 } |
227 | |
228 static Lisp_Object | |
442 | 229 continuable_read_syntax_error (const char *string) |
428 | 230 { |
563 | 231 return signal_continuable_error (Qinvalid_read_syntax, string, Qunbound); |
428 | 232 } |
233 | |
234 | |
235 /* Handle unreading and rereading of characters. */ | |
867 | 236 static Ichar |
428 | 237 readchar (Lisp_Object readcharfun) |
238 { | |
239 /* This function can GC */ | |
240 | |
241 if (BUFFERP (readcharfun)) | |
242 { | |
867 | 243 Ichar c; |
428 | 244 struct buffer *b = XBUFFER (readcharfun); |
245 | |
246 if (!BUFFER_LIVE_P (b)) | |
563 | 247 invalid_operation ("Reading from killed buffer", Qunbound); |
428 | 248 |
249 if (BUF_PT (b) >= BUF_ZV (b)) | |
250 return -1; | |
251 c = BUF_FETCH_CHAR (b, BUF_PT (b)); | |
252 BUF_SET_PT (b, BUF_PT (b) + 1); | |
253 | |
254 return c; | |
255 } | |
256 else if (LSTREAMP (readcharfun)) | |
257 { | |
867 | 258 Ichar c = Lstream_get_ichar (XLSTREAM (readcharfun)); |
428 | 259 #ifdef DEBUG_XEMACS /* testing Mule */ |
260 static int testing_mule = 0; /* Change via debugger */ | |
444 | 261 if (testing_mule) |
262 { | |
263 if (c >= 0x20 && c <= 0x7E) stderr_out ("%c", c); | |
264 else if (c == '\n') stderr_out ("\\n\n"); | |
265 else stderr_out ("\\%o ", c); | |
266 } | |
267 #endif /* testing Mule */ | |
428 | 268 return c; |
269 } | |
270 else if (MARKERP (readcharfun)) | |
271 { | |
867 | 272 Ichar c; |
665 | 273 Charbpos mpos = marker_position (readcharfun); |
428 | 274 struct buffer *inbuffer = XMARKER (readcharfun)->buffer; |
275 | |
276 if (mpos >= BUF_ZV (inbuffer)) | |
277 return -1; | |
278 c = BUF_FETCH_CHAR (inbuffer, mpos); | |
279 set_marker_position (readcharfun, mpos + 1); | |
280 return c; | |
281 } | |
282 else | |
283 { | |
284 Lisp_Object tem = call0 (readcharfun); | |
285 | |
286 if (!CHAR_OR_CHAR_INTP (tem)) | |
287 return -1; | |
288 return XCHAR_OR_CHAR_INT (tem); | |
289 } | |
290 } | |
291 | |
292 /* Unread the character C in the way appropriate for the stream READCHARFUN. | |
293 If the stream is a user function, call it with the char as argument. */ | |
294 | |
295 static void | |
867 | 296 unreadchar (Lisp_Object readcharfun, Ichar c) |
428 | 297 { |
298 if (c == -1) | |
299 /* Don't back up the pointer if we're unreading the end-of-input mark, | |
300 since readchar didn't advance it when we read it. */ | |
301 ; | |
302 else if (BUFFERP (readcharfun)) | |
303 BUF_SET_PT (XBUFFER (readcharfun), BUF_PT (XBUFFER (readcharfun)) - 1); | |
304 else if (LSTREAMP (readcharfun)) | |
305 { | |
867 | 306 Lstream_unget_ichar (XLSTREAM (readcharfun), c); |
428 | 307 #ifdef DEBUG_XEMACS /* testing Mule */ |
308 { | |
309 static int testing_mule = 0; /* Set this using debugger */ | |
310 if (testing_mule) | |
311 fprintf (stderr, | |
312 (c >= 0x20 && c <= 0x7E) ? "UU%c" : | |
313 ((c == '\n') ? "UU\\n\n" : "UU\\%o"), c); | |
314 } | |
315 #endif | |
316 } | |
317 else if (MARKERP (readcharfun)) | |
318 set_marker_position (readcharfun, marker_position (readcharfun) - 1); | |
319 else | |
320 call1 (readcharfun, make_char (c)); | |
321 } | |
322 | |
323 static Lisp_Object read0 (Lisp_Object readcharfun); | |
324 static Lisp_Object read1 (Lisp_Object readcharfun); | |
325 static Lisp_Object read_list (Lisp_Object readcharfun, | |
867 | 326 Ichar terminator, |
428 | 327 int allow_dotted_lists, |
328 int check_for_doc_references); | |
329 | |
330 static void readevalloop (Lisp_Object readcharfun, | |
331 Lisp_Object sourcefile, | |
332 Lisp_Object (*evalfun) (Lisp_Object), | |
333 int printflag); | |
334 | |
335 static Lisp_Object | |
336 load_unwind (Lisp_Object stream) /* used as unwind-protect function in load */ | |
337 { | |
338 Lstream_close (XLSTREAM (stream)); | |
339 return Qnil; | |
340 } | |
341 | |
2548 | 342 /* Check if NONRELOC/RELOC (an absolute filename) is suppressed according |
343 to load-suppress-alist. */ | |
344 static int | |
345 check_if_suppressed (Ibyte *nonreloc, Lisp_Object reloc) | |
346 { | |
347 Bytecount len; | |
348 | |
349 if (!NILP (reloc)) | |
350 { | |
351 nonreloc = XSTRING_DATA (reloc); | |
352 len = XSTRING_LENGTH (reloc); | |
353 } | |
354 else | |
355 len = qxestrlen (nonreloc); | |
356 | |
357 if (len >= 4 && !qxestrcmp_ascii (nonreloc + len - 4, ".elc")) | |
358 len -= 4; | |
359 else if (len >= 3 && !qxestrcmp_ascii (nonreloc + len - 3, ".el")) | |
360 len -= 3; | |
361 | |
2567 | 362 { |
363 EXTERNAL_LIST_LOOP_2 (acons, Vload_suppress_alist) | |
364 { | |
365 if (CONSP (acons) && STRINGP (XCAR (acons))) | |
366 { | |
367 Lisp_Object name = XCAR (acons); | |
368 if (XSTRING_LENGTH (name) == len && | |
369 !memcmp (XSTRING_DATA (name), nonreloc, len)) | |
370 { | |
371 struct gcpro gcpro1; | |
372 Lisp_Object val; | |
373 | |
374 GCPRO1 (reloc); | |
375 val = Feval (XCDR (acons)); | |
376 UNGCPRO; | |
377 | |
378 if (!NILP (val)) | |
379 return 1; | |
380 } | |
381 } | |
382 } | |
383 } | |
2548 | 384 |
385 return 0; | |
386 } | |
387 | |
428 | 388 /* The plague is coming. |
389 | |
390 Ring around the rosy, pocket full of posy, | |
391 Ashes ashes, they all fall down. | |
392 */ | |
393 void | |
394 ebolify_bytecode_constants (Lisp_Object vector) | |
395 { | |
396 int len = XVECTOR_LENGTH (vector); | |
397 int i; | |
398 | |
399 for (i = 0; i < len; i++) | |
400 { | |
401 Lisp_Object el = XVECTOR_DATA (vector)[i]; | |
402 | |
403 /* We don't check for `eq', `equal', and the others that have | |
404 bytecode opcodes. This might lose if someone passes #'eq or | |
405 something to `funcall', but who would really do that? As | |
406 they say in law, we've made a "good-faith effort" to | |
407 unfuckify ourselves. And doing it this way avoids screwing | |
408 up args to `make-hash-table' and such. As it is, we have to | |
409 add an extra Ebola check in decode_weak_list_type(). --ben */ | |
410 if (EQ (el, Qassoc)) el = Qold_assoc; | |
411 else if (EQ (el, Qdelq)) el = Qold_delq; | |
412 #if 0 | |
413 /* I think this is a bad idea because it will probably mess | |
414 with keymap code. */ | |
415 else if (EQ (el, Qdelete)) el = Qold_delete; | |
416 #endif | |
417 else if (EQ (el, Qrassq)) el = Qold_rassq; | |
418 else if (EQ (el, Qrassoc)) el = Qold_rassoc; | |
419 | |
420 XVECTOR_DATA (vector)[i] = el; | |
421 } | |
422 } | |
423 | |
424 static Lisp_Object | |
558 | 425 pas_de_holgazan_ici (int fd, Lisp_Object victim) |
428 | 426 { |
427 Lisp_Object tem; | |
428 EMACS_INT pos; | |
429 | |
430 if (!INTP (XCDR (victim))) | |
563 | 431 invalid_byte_code ("Bogus doc string reference", victim); |
428 | 432 pos = XINT (XCDR (victim)); |
433 if (pos < 0) | |
434 pos = -pos; /* kludge to mark a user variable */ | |
814 | 435 tem = unparesseuxify_doc_string (fd, pos, 0, Vload_file_name_internal, 0); |
428 | 436 if (!STRINGP (tem)) |
563 | 437 signal_error_1 (Qinvalid_byte_code, tem); |
428 | 438 return tem; |
439 } | |
440 | |
441 static Lisp_Object | |
442 load_force_doc_string_unwind (Lisp_Object oldlist) | |
443 { | |
444 struct gcpro gcpro1; | |
445 Lisp_Object list = Vload_force_doc_string_list; | |
446 Lisp_Object tail; | |
447 int fd = XINT (XCAR (Vload_descriptor_list)); | |
448 | |
449 GCPRO1 (list); | |
450 /* restore the old value first just in case an error occurs. */ | |
451 Vload_force_doc_string_list = oldlist; | |
452 | |
453 LIST_LOOP (tail, list) | |
454 { | |
455 Lisp_Object john = Fcar (tail); | |
456 if (CONSP (john)) | |
457 { | |
458 assert (CONSP (XCAR (john))); | |
459 assert (!purify_flag); /* should have been handled in read_list() */ | |
558 | 460 XCAR (john) = pas_de_holgazan_ici (fd, XCAR (john)); |
428 | 461 } |
462 else | |
463 { | |
464 Lisp_Object doc; | |
465 | |
466 assert (COMPILED_FUNCTIONP (john)); | |
467 if (CONSP (XCOMPILED_FUNCTION (john)->instructions)) | |
468 { | |
469 struct gcpro ngcpro1; | |
558 | 470 Lisp_Object juan = (pas_de_holgazan_ici |
814 | 471 (fd, |
472 XCOMPILED_FUNCTION (john)->instructions)); | |
428 | 473 Lisp_Object ivan; |
474 | |
475 NGCPRO1 (juan); | |
476 ivan = Fread (juan); | |
477 if (!CONSP (ivan)) | |
563 | 478 invalid_byte_code ("invalid lazy-loaded byte code", ivan); |
428 | 479 XCOMPILED_FUNCTION (john)->instructions = XCAR (ivan); |
480 /* v18 or v19 bytecode file. Need to Ebolify. */ | |
481 if (XCOMPILED_FUNCTION (john)->flags.ebolified | |
482 && VECTORP (XCDR (ivan))) | |
483 ebolify_bytecode_constants (XCDR (ivan)); | |
484 XCOMPILED_FUNCTION (john)->constants = XCDR (ivan); | |
485 NUNGCPRO; | |
486 } | |
487 doc = compiled_function_documentation (XCOMPILED_FUNCTION (john)); | |
488 if (CONSP (doc)) | |
489 { | |
490 assert (!purify_flag); /* should have been handled in | |
491 read_compiled_function() */ | |
558 | 492 doc = pas_de_holgazan_ici (fd, doc); |
428 | 493 set_compiled_function_documentation (XCOMPILED_FUNCTION (john), |
494 doc); | |
495 } | |
496 } | |
497 } | |
498 | |
499 if (!NILP (list)) | |
500 free_list (list); | |
501 | |
502 UNGCPRO; | |
503 return Qnil; | |
504 } | |
505 | |
506 /* Close all descriptors in use for Fload_internal. | |
507 This is used when starting a subprocess. */ | |
508 | |
509 void | |
510 close_load_descs (void) | |
511 { | |
512 Lisp_Object tail; | |
513 LIST_LOOP (tail, Vload_descriptor_list) | |
771 | 514 retry_close (XINT (XCAR (tail))); |
428 | 515 } |
516 | |
517 #ifdef I18N3 | |
518 Lisp_Object Vfile_domain; | |
519 #endif /* I18N3 */ | |
520 | |
521 DEFUN ("load-internal", Fload_internal, 1, 6, 0, /* | |
522 Execute a file of Lisp code named FILE; no coding-system frobbing. | |
523 This function is identical to `load' except for the handling of the | |
524 CODESYS and USED-CODESYS arguments under XEmacs/Mule. (When Mule | |
525 support is not present, both functions are identical and ignore the | |
526 CODESYS and USED-CODESYS arguments.) | |
527 | |
528 If support for Mule exists in this Emacs, the file is decoded | |
529 according to CODESYS; if omitted, no conversion happens. If | |
530 USED-CODESYS is non-nil, it should be a symbol, and the actual coding | |
531 system that was used for the decoding is stored into it. It will in | |
532 general be different from CODESYS if CODESYS specifies automatic | |
533 encoding detection or end-of-line detection. | |
534 */ | |
444 | 535 (file, noerror, nomessage, nosuffix, codesys, used_codesys)) |
428 | 536 { |
537 /* This function can GC */ | |
538 int fd = -1; | |
539 int speccount = specpdl_depth (); | |
540 int source_only = 0; | |
1123 | 541 /* NEWER and OLDER are filenames w/o directory, used in loading messages |
542 to e.g. warn of newer .el files when the .elc is being loaded. */ | |
428 | 543 Lisp_Object newer = Qnil; |
1123 | 544 Lisp_Object older = Qnil; |
428 | 545 Lisp_Object handler = Qnil; |
546 Lisp_Object found = Qnil; | |
1292 | 547 Lisp_Object retval; |
1123 | 548 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
428 | 549 int reading_elc = 0; |
780 | 550 int from_require = EQ (nomessage, Qrequire); |
1261 | 551 int message_p = NILP (nomessage) || load_always_display_messages; |
428 | 552 struct stat s1, s2; |
1261 | 553 Ibyte *spaces = alloca_ibytes (load_in_progress * 2 + 10); |
554 int i; | |
1292 | 555 PROFILE_DECLARE (); |
428 | 556 |
1266 | 557 GCPRO4 (file, newer, older, found); |
428 | 558 CHECK_STRING (file); |
559 | |
1292 | 560 PROFILE_RECORD_ENTERING_SECTION (Qload_internal); |
561 | |
428 | 562 /* If file name is magic, call the handler. */ |
563 handler = Ffind_file_name_handler (file, Qload); | |
564 if (!NILP (handler)) | |
1292 | 565 { |
566 retval = call5 (handler, Qload, file, noerror, nomessage, nosuffix); | |
567 goto done; | |
568 } | |
428 | 569 |
570 /* Do this after the handler to avoid | |
571 the need to gcpro noerror, nomessage and nosuffix. | |
572 (Below here, we care only whether they are nil or not.) */ | |
573 file = Fsubstitute_in_file_name (file); | |
574 if (!NILP (used_codesys)) | |
575 CHECK_SYMBOL (used_codesys); | |
576 | |
1261 | 577 if (noninteractive) |
578 { | |
579 for (i = 0; i < load_in_progress * 2; i++) | |
580 spaces[i] = ' '; | |
581 spaces[i] = '\0'; | |
582 } | |
583 else | |
584 spaces[0] = '\0'; | |
585 | |
428 | 586 /* Avoid weird lossage with null string as arg, |
587 since it would try to load a directory as a Lisp file. | |
588 Unix truly sucks. */ | |
589 if (XSTRING_LENGTH (file) > 0) | |
590 { | |
867 | 591 Ibyte *foundstr; |
428 | 592 int foundlen; |
593 | |
594 fd = locate_file (Vload_path, file, | |
595 ((!NILP (nosuffix)) ? Qnil : | |
596 build_string (load_ignore_elc_files ? ".el:" : | |
597 ".elc:.el:")), | |
598 &found, | |
599 -1); | |
600 | |
601 if (fd < 0) | |
602 { | |
444 | 603 if (NILP (noerror)) |
563 | 604 signal_error (Qfile_error, "Cannot open load file", file); |
428 | 605 else |
606 { | |
1292 | 607 retval = Qnil; |
608 goto done; | |
428 | 609 } |
610 } | |
611 | |
2367 | 612 foundstr = alloca_ibytes (XSTRING_LENGTH (found) + 1); |
771 | 613 qxestrcpy (foundstr, XSTRING_DATA (found)); |
614 foundlen = qxestrlen (foundstr); | |
428 | 615 |
616 /* The omniscient JWZ thinks this is worthless, but I beg to | |
617 differ. --ben */ | |
618 if (load_ignore_elc_files) | |
1123 | 619 newer = Ffile_name_nondirectory (found); |
620 else if ((load_warn_when_source_newer || | |
621 load_ignore_out_of_date_elc_files) && | |
428 | 622 !memcmp (".elc", foundstr + foundlen - 4, 4)) |
623 { | |
771 | 624 if (! qxe_fstat (fd, &s1)) /* can't fail, right? */ |
428 | 625 { |
626 int result; | |
627 /* temporarily hack the 'c' off the end of the filename */ | |
628 foundstr[foundlen - 1] = '\0'; | |
771 | 629 result = qxe_stat (foundstr, &s2); |
428 | 630 if (result >= 0 && |
631 (unsigned) s1.st_mtime < (unsigned) s2.st_mtime) | |
1123 | 632 { |
633 /* .elc exists and is out-of-date wrt .el */ | |
634 Lisp_Object el_name = make_string (foundstr, foundlen - 1); | |
635 struct gcpro nngcpro1; | |
636 NNGCPRO1 (el_name); | |
637 newer = Ffile_name_nondirectory (el_name); | |
638 if (load_ignore_out_of_date_elc_files) | |
639 { | |
640 int newfd = | |
641 locate_file_open_or_access_file | |
642 (XSTRING_DATA (el_name), -1); | |
643 | |
644 if (newfd >= 0) | |
645 { | |
646 older = Ffile_name_nondirectory (found); | |
647 found = el_name; | |
648 retry_close (fd); | |
649 fd = newfd; | |
650 } | |
651 } | |
652 NNUNGCPRO; | |
653 } | |
428 | 654 /* put the 'c' back on (kludge-o-rama) */ |
655 foundstr[foundlen - 1] = 'c'; | |
656 } | |
657 } | |
658 else if (load_warn_when_source_only && | |
659 /* `found' ends in ".el" */ | |
660 !memcmp (".el", foundstr + foundlen - 3, 3) && | |
661 /* `file' does not end in ".el" */ | |
662 memcmp (".el", | |
663 XSTRING_DATA (file) + XSTRING_LENGTH (file) - 3, | |
664 3)) | |
1123 | 665 source_only = 1; |
428 | 666 |
667 if (!memcmp (".elc", foundstr + foundlen - 4, 4)) | |
668 reading_elc = 1; | |
669 } | |
670 | |
1123 | 671 #define PRINT_LOADING_MESSAGE_1(loading, done) \ |
672 do { \ | |
673 if (load_ignore_elc_files) \ | |
674 { \ | |
675 if (message_p) \ | |
1261 | 676 message (loading done, spaces, \ |
1123 | 677 XSTRING_DATA (load_show_full_path_in_messages ? \ |
678 found : newer)); \ | |
679 } \ | |
680 else if (!NILP (older)) \ | |
681 { \ | |
682 assert (load_ignore_out_of_date_elc_files); \ | |
1261 | 683 message (loading done " (file %s is out-of-date)", spaces, \ |
1123 | 684 XSTRING_DATA (load_show_full_path_in_messages ? \ |
685 found : newer), \ | |
686 XSTRING_DATA (older)); \ | |
687 } \ | |
688 else if (!NILP (newer)) \ | |
1261 | 689 message (loading done " (file %s is newer)", spaces, \ |
1123 | 690 XSTRING_DATA (load_show_full_path_in_messages ? \ |
691 found : file), \ | |
692 XSTRING_DATA (newer)); \ | |
693 else if (source_only) \ | |
1261 | 694 message (loading done " (file %s.elc does not exist)", spaces, \ |
1123 | 695 XSTRING_DATA (load_show_full_path_in_messages ? \ |
696 found : file), \ | |
697 XSTRING_DATA (Ffile_name_nondirectory (file))); \ | |
698 else if (message_p) \ | |
1261 | 699 message (loading done, spaces, \ |
1123 | 700 XSTRING_DATA (load_show_full_path_in_messages ? \ |
701 found : file)); \ | |
428 | 702 } while (0) |
703 | |
1261 | 704 #define PRINT_LOADING_MESSAGE(done) \ |
705 do { \ | |
706 if (from_require) \ | |
707 PRINT_LOADING_MESSAGE_1 ("%sRequiring %s...", done); \ | |
708 else \ | |
709 PRINT_LOADING_MESSAGE_1 ("%sLoading %s...", done); \ | |
780 | 710 } while (0) |
711 | |
428 | 712 PRINT_LOADING_MESSAGE (""); |
713 | |
714 { | |
715 /* Lisp_Object's must be malloc'ed, not stack-allocated */ | |
716 Lisp_Object lispstream = Qnil; | |
442 | 717 const int block_size = 8192; |
428 | 718 struct gcpro ngcpro1; |
719 | |
720 NGCPRO1 (lispstream); | |
721 lispstream = make_filedesc_input_stream (fd, 0, -1, LSTR_CLOSING); | |
722 /* 64K is used for normal files; 8K should be OK here because Lisp | |
723 files aren't really all that big. */ | |
724 Lstream_set_buffering (XLSTREAM (lispstream), LSTREAM_BLOCKN_BUFFERED, | |
725 block_size); | |
771 | 726 lispstream = make_coding_input_stream |
727 (XLSTREAM (lispstream), get_coding_system_for_text_file (codesys, 1), | |
800 | 728 CODING_DECODE, 0); |
428 | 729 Lstream_set_buffering (XLSTREAM (lispstream), LSTREAM_BLOCKN_BUFFERED, |
730 block_size); | |
731 /* NOTE: Order of these is very important. Don't rearrange them. */ | |
853 | 732 internal_bind_int (&load_in_progress, 1 + load_in_progress); |
428 | 733 record_unwind_protect (load_unwind, lispstream); |
853 | 734 internal_bind_lisp_object (&Vload_descriptor_list, |
735 Fcons (make_int (fd), Vload_descriptor_list)); | |
736 internal_bind_lisp_object (&Vload_file_name_internal, found); | |
737 /* this is not a simple internal_bind. */ | |
428 | 738 record_unwind_protect (load_force_doc_string_unwind, |
739 Vload_force_doc_string_list); | |
853 | 740 Vload_force_doc_string_list = Qnil; |
2548 | 741 internal_bind_lisp_object (&Vload_file_name, found); |
428 | 742 #ifdef I18N3 |
853 | 743 /* set it to nil; a call to #'domain will set it. */ |
744 internal_bind_lisp_object (&Vfile_domain, Qnil); | |
428 | 745 #endif |
746 | |
4448
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
747 /* Is there a #!? If so, read it, and unread ;!. |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
748 |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
749 GNU implement this by treating any #! anywhere in the source text as |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
750 commenting out the whole line. */ |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
751 { |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
752 char shebangp[2]; |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
753 int num_read; |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
754 |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
755 num_read = Lstream_read (XLSTREAM (lispstream), shebangp, |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
756 sizeof(shebangp)); |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
757 if (sizeof(shebangp) == num_read |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
758 && 0 == strncmp("#!", shebangp, sizeof(shebangp))) |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
759 { |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
760 shebangp[0] = ';'; |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
761 } |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
762 |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
763 Lstream_unread (XLSTREAM (lispstream), shebangp, num_read); |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
764 } |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
765 |
428 | 766 /* Now determine what sort of ELC file we're reading in. */ |
853 | 767 internal_bind_int (&load_byte_code_version, load_byte_code_version); |
428 | 768 if (reading_elc) |
769 { | |
770 char elc_header[8]; | |
771 int num_read; | |
772 | |
773 num_read = Lstream_read (XLSTREAM (lispstream), elc_header, 8); | |
774 if (num_read < 8 | |
775 || strncmp (elc_header, ";ELC", 4)) | |
776 { | |
777 /* Huh? Probably not a valid ELC file. */ | |
778 load_byte_code_version = 100; /* no Ebolification needed */ | |
779 Lstream_unread (XLSTREAM (lispstream), elc_header, num_read); | |
780 } | |
781 else | |
782 load_byte_code_version = elc_header[4]; | |
783 } | |
784 else | |
785 load_byte_code_version = 100; /* no Ebolification needed */ | |
786 | |
787 readevalloop (lispstream, file, Feval, 0); | |
788 if (!NILP (used_codesys)) | |
789 Fset (used_codesys, | |
790 XCODING_SYSTEM_NAME | |
771 | 791 (coding_stream_detected_coding_system (XLSTREAM (lispstream)))); |
792 unbind_to (speccount); | |
428 | 793 |
794 NUNGCPRO; | |
795 } | |
796 | |
797 { | |
798 Lisp_Object tem; | |
799 /* #### Disgusting kludge */ | |
800 /* Run any load-hooks for this file. */ | |
801 /* #### An even more disgusting kludge. There is horrible code */ | |
802 /* that is relying on the fact that dumped lisp files are found */ | |
803 /* via `load-path' search. */ | |
804 Lisp_Object name = file; | |
805 | |
1123 | 806 if (!NILP (Ffile_name_absolute_p (file))) |
807 name = Ffile_name_nondirectory (file); | |
428 | 808 |
1261 | 809 tem = Fassoc (name, Vafter_load_alist); |
428 | 810 if (!NILP (tem)) |
811 { | |
812 struct gcpro ngcpro1; | |
813 | |
814 NGCPRO1 (tem); | |
815 /* Use eval so that errors give a semi-meaningful backtrace. --Stig */ | |
816 tem = Fcons (Qprogn, Fcdr (tem)); | |
817 Feval (tem); | |
818 NUNGCPRO; | |
819 } | |
820 } | |
821 | |
822 if (!noninteractive) | |
823 PRINT_LOADING_MESSAGE ("done"); | |
824 | |
1292 | 825 retval = Qt; |
826 done: | |
827 PROFILE_RECORD_EXITING_SECTION (Qload_internal); | |
428 | 828 UNGCPRO; |
1292 | 829 return retval; |
428 | 830 } |
831 | |
832 | |
833 /* ------------------------------- */ | |
834 /* locate_file */ | |
835 /* ------------------------------- */ | |
836 | |
837 static int | |
838 decode_mode_1 (Lisp_Object mode) | |
839 { | |
840 if (EQ (mode, Qexists)) | |
841 return F_OK; | |
842 else if (EQ (mode, Qexecutable)) | |
843 return X_OK; | |
844 else if (EQ (mode, Qwritable)) | |
845 return W_OK; | |
846 else if (EQ (mode, Qreadable)) | |
847 return R_OK; | |
848 else if (INTP (mode)) | |
849 { | |
850 check_int_range (XINT (mode), 0, 7); | |
851 return XINT (mode); | |
852 } | |
853 else | |
563 | 854 invalid_argument ("Invalid value", mode); |
428 | 855 return 0; /* unreached */ |
856 } | |
857 | |
858 static int | |
859 decode_mode (Lisp_Object mode) | |
860 { | |
861 if (NILP (mode)) | |
862 return R_OK; | |
863 else if (CONSP (mode)) | |
864 { | |
865 int mask = 0; | |
2367 | 866 EXTERNAL_LIST_LOOP_2 (elt, mode) |
867 mask |= decode_mode_1 (elt); | |
428 | 868 return mask; |
869 } | |
870 else | |
871 return decode_mode_1 (mode); | |
872 } | |
873 | |
874 DEFUN ("locate-file", Flocate_file, 2, 4, 0, /* | |
875 Search for FILENAME through PATH-LIST. | |
876 | |
877 If SUFFIXES is non-nil, it should be a list of suffixes to append to | |
878 file name when searching. | |
879 | |
880 If MODE is non-nil, it should be a symbol or a list of symbol representing | |
881 requirements. Allowed symbols are `exists', `executable', `writable', and | |
882 `readable'. If MODE is nil, it defaults to `readable'. | |
883 | |
2548 | 884 Filenames are checked against `load-suppress-alist' to determine if they |
885 should be ignored. | |
886 | |
428 | 887 `locate-file' keeps hash tables of the directories it searches through, |
888 in order to speed things up. It tries valiantly to not get confused in | |
889 the face of a changing and unpredictable environment, but can occasionally | |
890 get tripped up. In this case, you will have to call | |
891 `locate-file-clear-hashing' to get it back on track. See that function | |
892 for details. | |
893 */ | |
894 (filename, path_list, suffixes, mode)) | |
895 { | |
896 /* This function can GC */ | |
897 Lisp_Object tp; | |
898 | |
899 CHECK_STRING (filename); | |
900 | |
901 if (LISTP (suffixes)) | |
902 { | |
2367 | 903 EXTERNAL_LIST_LOOP_2 (elt, suffixes) |
904 CHECK_STRING (elt); | |
428 | 905 } |
906 else | |
907 CHECK_STRING (suffixes); | |
908 | |
909 locate_file (path_list, filename, suffixes, &tp, decode_mode (mode)); | |
910 return tp; | |
911 } | |
912 | |
913 /* Recalculate the hash table for the given string. DIRECTORY should | |
914 better have been through Fexpand_file_name() by now. */ | |
915 | |
916 static Lisp_Object | |
917 locate_file_refresh_hashing (Lisp_Object directory) | |
918 { | |
919 Lisp_Object hash = | |
771 | 920 make_directory_hash_table (XSTRING_DATA (directory)); |
428 | 921 |
922 if (!NILP (hash)) | |
923 Fputhash (directory, hash, Vlocate_file_hash_table); | |
924 return hash; | |
925 } | |
926 | |
927 /* find the hash table for the given directory, recalculating if necessary */ | |
928 | |
929 static Lisp_Object | |
930 locate_file_find_directory_hash_table (Lisp_Object directory) | |
931 { | |
932 Lisp_Object hash = Fgethash (directory, Vlocate_file_hash_table, Qnil); | |
933 if (NILP (hash)) | |
934 return locate_file_refresh_hashing (directory); | |
935 else | |
936 return hash; | |
937 } | |
938 | |
939 /* The SUFFIXES argument in any of the locate_file* functions can be | |
940 nil, a list, or a string (for backward compatibility), with the | |
941 following semantics: | |
942 | |
943 a) nil - no suffix, just search for file name intact | |
944 (semantically different from "empty suffix list", which | |
945 would be meaningless.) | |
946 b) list - list of suffixes to append to file name. Each of these | |
947 must be a string. | |
948 c) string - colon-separated suffixes to append to file name (backward | |
949 compatibility). | |
950 | |
951 All of this got hairy, so I decided to use a mapper. Calling a | |
952 function for each suffix shouldn't slow things down, since | |
953 locate_file is rarely called with enough suffixes for funcalls to | |
954 make any difference. */ | |
955 | |
956 /* Map FUN over SUFFIXES, as described above. FUN will be called with a | |
957 char * containing the current file name, and ARG. Mapping stops when | |
958 FUN returns non-zero. */ | |
959 static void | |
960 locate_file_map_suffixes (Lisp_Object filename, Lisp_Object suffixes, | |
867 | 961 int (*fun) (Ibyte *, void *), |
428 | 962 void *arg) |
963 { | |
964 /* This function can GC */ | |
867 | 965 Ibyte *fn; |
428 | 966 int fn_len, max; |
967 | |
968 /* Calculate maximum size of any filename made from | |
969 this path element/specified file name and any possible suffix. */ | |
970 if (CONSP (suffixes)) | |
971 { | |
972 /* We must traverse the list, so why not do it right. */ | |
973 Lisp_Object tail; | |
974 max = 0; | |
975 LIST_LOOP (tail, suffixes) | |
976 { | |
977 if (XSTRING_LENGTH (XCAR (tail)) > max) | |
978 max = XSTRING_LENGTH (XCAR (tail)); | |
979 } | |
980 } | |
981 else if (NILP (suffixes)) | |
982 max = 0; | |
983 else | |
984 /* Just take the easy way out */ | |
985 max = XSTRING_LENGTH (suffixes); | |
986 | |
987 fn_len = XSTRING_LENGTH (filename); | |
2367 | 988 fn = alloca_ibytes (max + fn_len + 1); |
771 | 989 memcpy (fn, XSTRING_DATA (filename), fn_len); |
428 | 990 |
991 /* Loop over suffixes. */ | |
992 if (!STRINGP (suffixes)) | |
993 { | |
994 if (NILP (suffixes)) | |
995 { | |
996 /* Case a) discussed in the comment above. */ | |
997 fn[fn_len] = 0; | |
998 if ((*fun) (fn, arg)) | |
999 return; | |
1000 } | |
1001 else | |
1002 { | |
1003 /* Case b) */ | |
1004 Lisp_Object tail; | |
1005 LIST_LOOP (tail, suffixes) | |
1006 { | |
1007 memcpy (fn + fn_len, XSTRING_DATA (XCAR (tail)), | |
1008 XSTRING_LENGTH (XCAR (tail))); | |
1009 fn[fn_len + XSTRING_LENGTH (XCAR (tail))] = 0; | |
1010 if ((*fun) (fn, arg)) | |
1011 return; | |
1012 } | |
1013 } | |
1014 } | |
1015 else | |
1016 { | |
1017 /* Case c) */ | |
867 | 1018 const Ibyte *nsuffix = XSTRING_DATA (suffixes); |
428 | 1019 |
1020 while (1) | |
1021 { | |
867 | 1022 Ibyte *esuffix = qxestrchr (nsuffix, ':'); |
771 | 1023 Bytecount lsuffix = esuffix ? esuffix - nsuffix : |
1024 qxestrlen (nsuffix); | |
428 | 1025 |
1026 /* Concatenate path element/specified name with the suffix. */ | |
771 | 1027 qxestrncpy (fn + fn_len, nsuffix, lsuffix); |
428 | 1028 fn[fn_len + lsuffix] = 0; |
1029 | |
1030 if ((*fun) (fn, arg)) | |
1031 return; | |
1032 | |
1033 /* Advance to next suffix. */ | |
1034 if (esuffix == 0) | |
1035 break; | |
1036 nsuffix += lsuffix + 1; | |
1037 } | |
1038 } | |
1039 } | |
1040 | |
771 | 1041 struct locate_file_in_directory_mapper_closure |
1042 { | |
428 | 1043 int fd; |
1044 Lisp_Object *storeptr; | |
1045 int mode; | |
1046 }; | |
1047 | |
1123 | 1048 /* open() or access() a file to be returned by locate_file(). if |
1049 ACCESS_MODE >= 0, do an access() with that mode, else open(). Does | |
1050 various magic, e.g. opening the file read-only and binary and setting | |
1051 the close-on-exec flag on the file. */ | |
1052 | |
1053 static int | |
1054 locate_file_open_or_access_file (Ibyte *fn, int access_mode) | |
1055 { | |
1056 int val; | |
1057 | |
1058 /* Check that we can access or open it. */ | |
1059 if (access_mode >= 0) | |
1060 val = qxe_access (fn, access_mode); | |
1061 else | |
1062 { | |
1063 val = qxe_open (fn, O_RDONLY | OPEN_BINARY, 0); | |
1064 | |
1065 #ifndef WIN32_NATIVE | |
1066 if (val >= 0) | |
1067 /* If we actually opened the file, set close-on-exec flag | |
1068 on the new descriptor so that subprocesses can't whack | |
1069 at it. */ | |
1070 (void) fcntl (val, F_SETFD, FD_CLOEXEC); | |
1071 #endif | |
1072 } | |
1073 | |
1074 return val; | |
1075 } | |
1076 | |
428 | 1077 static int |
867 | 1078 locate_file_in_directory_mapper (Ibyte *fn, void *arg) |
428 | 1079 { |
1080 struct locate_file_in_directory_mapper_closure *closure = | |
771 | 1081 (struct locate_file_in_directory_mapper_closure *) arg; |
428 | 1082 struct stat st; |
1083 | |
1084 /* Ignore file if it's a directory. */ | |
771 | 1085 if (qxe_stat (fn, &st) >= 0 |
428 | 1086 && (st.st_mode & S_IFMT) != S_IFDIR) |
1087 { | |
1088 /* Check that we can access or open it. */ | |
1123 | 1089 closure->fd = locate_file_open_or_access_file (fn, closure->mode); |
428 | 1090 |
1091 if (closure->fd >= 0) | |
1092 { | |
2548 | 1093 if (!check_if_suppressed (fn, Qnil)) |
1094 { | |
1095 /* We succeeded; return this descriptor and filename. */ | |
1096 if (closure->storeptr) | |
1097 *closure->storeptr = build_intstring (fn); | |
1098 | |
1099 return 1; | |
1100 } | |
428 | 1101 } |
1102 } | |
1103 /* Keep mapping. */ | |
1104 return 0; | |
1105 } | |
1106 | |
1107 | |
1108 /* look for STR in PATH, optionally adding SUFFIXES. DIRECTORY need | |
1109 not have been expanded. */ | |
1110 | |
1111 static int | |
1112 locate_file_in_directory (Lisp_Object directory, Lisp_Object str, | |
1113 Lisp_Object suffixes, Lisp_Object *storeptr, | |
1114 int mode) | |
1115 { | |
1116 /* This function can GC */ | |
1117 struct locate_file_in_directory_mapper_closure closure; | |
1118 Lisp_Object filename = Qnil; | |
1119 struct gcpro gcpro1, gcpro2, gcpro3; | |
1120 | |
1121 GCPRO3 (directory, str, filename); | |
1122 | |
1123 filename = Fexpand_file_name (str, directory); | |
1124 if (NILP (filename) || NILP (Ffile_name_absolute_p (filename))) | |
1125 /* If there are non-absolute elts in PATH (eg ".") */ | |
1126 /* Of course, this could conceivably lose if luser sets | |
1127 default-directory to be something non-absolute ... */ | |
1128 { | |
1129 if (NILP (filename)) | |
1130 /* NIL means current directory */ | |
1131 filename = current_buffer->directory; | |
1132 else | |
1133 filename = Fexpand_file_name (filename, | |
1134 current_buffer->directory); | |
1135 if (NILP (Ffile_name_absolute_p (filename))) | |
1136 { | |
1137 /* Give up on this directory! */ | |
1138 UNGCPRO; | |
1139 return -1; | |
1140 } | |
1141 } | |
1142 | |
1143 closure.fd = -1; | |
1144 closure.storeptr = storeptr; | |
1145 closure.mode = mode; | |
1146 | |
771 | 1147 locate_file_map_suffixes (filename, suffixes, |
1148 locate_file_in_directory_mapper, | |
428 | 1149 &closure); |
1150 | |
1151 UNGCPRO; | |
1152 return closure.fd; | |
1153 } | |
1154 | |
1155 /* do the same as locate_file() but don't use any hash tables. */ | |
1156 | |
1157 static int | |
1158 locate_file_without_hash (Lisp_Object path, Lisp_Object str, | |
1159 Lisp_Object suffixes, Lisp_Object *storeptr, | |
1160 int mode) | |
1161 { | |
1162 /* This function can GC */ | |
1163 int absolute = !NILP (Ffile_name_absolute_p (str)); | |
1164 | |
2367 | 1165 EXTERNAL_LIST_LOOP_2 (elt, path) |
428 | 1166 { |
2367 | 1167 int val = locate_file_in_directory (elt, str, suffixes, storeptr, |
428 | 1168 mode); |
1169 if (val >= 0) | |
1170 return val; | |
1171 if (absolute) | |
1172 break; | |
1173 } | |
1174 return -1; | |
1175 } | |
1176 | |
1177 static int | |
867 | 1178 locate_file_construct_suffixed_files_mapper (Ibyte *fn, void *arg) |
428 | 1179 { |
771 | 1180 Lisp_Object *tail = (Lisp_Object *) arg; |
1181 *tail = Fcons (build_intstring (fn), *tail); | |
428 | 1182 return 0; |
1183 } | |
1184 | |
1185 /* Construct a list of all files to search for. | |
1186 It makes sense to have this despite locate_file_map_suffixes() | |
1187 because we need Lisp strings to access the hash-table, and it would | |
1188 be inefficient to create them on the fly, again and again for each | |
1189 path component. See locate_file(). */ | |
1190 | |
1191 static Lisp_Object | |
1192 locate_file_construct_suffixed_files (Lisp_Object filename, | |
1193 Lisp_Object suffixes) | |
1194 { | |
1195 Lisp_Object tail = Qnil; | |
1196 struct gcpro gcpro1; | |
1197 GCPRO1 (tail); | |
1198 | |
1199 locate_file_map_suffixes (filename, suffixes, | |
1200 locate_file_construct_suffixed_files_mapper, | |
1201 &tail); | |
1202 | |
1203 UNGCPRO; | |
1204 return Fnreverse (tail); | |
1205 } | |
1206 | |
1207 DEFUN ("locate-file-clear-hashing", Flocate_file_clear_hashing, 1, 1, 0, /* | |
1208 Clear the hash records for the specified list of directories. | |
1209 `locate-file' uses a hashing scheme to speed lookup, and will correctly | |
1210 track the following environmental changes: | |
1211 | |
1212 -- changes of any sort to the list of directories to be searched. | |
1213 -- addition and deletion of non-shadowing files (see below) from the | |
1214 directories in the list. | |
1215 -- byte-compilation of a .el file into a .elc file. | |
1216 | |
1217 `locate-file' will primarily get confused if you add a file that shadows | |
1218 \(i.e. has the same name as) another file further down in the directory list. | |
1219 In this case, you must call `locate-file-clear-hashing'. | |
1220 | |
1221 If PATH is t, it means to fully clear all the accumulated hashes. This | |
1222 can be used if the internal tables grow too large, or when dumping. | |
1223 */ | |
1224 (path)) | |
1225 { | |
1226 if (EQ (path, Qt)) | |
1227 Fclrhash (Vlocate_file_hash_table); | |
1228 else | |
1229 { | |
2367 | 1230 EXTERNAL_LIST_LOOP_2 (elt, path) |
428 | 1231 { |
2367 | 1232 Lisp_Object pathel = Fexpand_file_name (elt, Qnil); |
428 | 1233 Fremhash (pathel, Vlocate_file_hash_table); |
1234 } | |
1235 } | |
1236 return Qnil; | |
1237 } | |
1238 | |
1239 /* Search for a file whose name is STR, looking in directories | |
1240 in the Lisp list PATH, and trying suffixes from SUFFIXES. | |
1241 SUFFIXES is a list of possible suffixes, or (for backward | |
1242 compatibility) a string containing possible suffixes separated by | |
1243 colons. | |
1244 On success, returns a file descriptor. On failure, returns -1. | |
1245 | |
1246 MODE nonnegative means don't open the files, | |
1247 just look for one for which access(file,MODE) succeeds. In this case, | |
951 | 1248 returns a nonnegative value on success. On failure, returns -1. |
428 | 1249 |
2548 | 1250 If STOREPTR is non-nil, it points to a slot where the name of |
428 | 1251 the file actually found should be stored as a Lisp string. |
1252 Nil is stored there on failure. | |
1253 | |
1254 Called openp() in FSFmacs. */ | |
1255 | |
1256 int | |
1257 locate_file (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, | |
1258 Lisp_Object *storeptr, int mode) | |
1259 { | |
1260 /* This function can GC */ | |
1261 Lisp_Object suffixtab = Qnil; | |
2367 | 1262 Lisp_Object pathel_expanded; |
428 | 1263 int val; |
1264 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
1265 | |
1266 if (storeptr) | |
1267 *storeptr = Qnil; | |
1268 | |
1269 /* Is it really necessary to gcpro path and str? It shouldn't be | |
1270 unless some caller has fucked up. There are known instances that | |
1271 call us with build_string("foo:bar") as SUFFIXES, though. */ | |
1272 GCPRO4 (path, str, suffixes, suffixtab); | |
1273 | |
1274 /* if this filename has directory components, it's too complicated | |
1275 to try and use the hash tables. */ | |
1276 if (!NILP (Ffile_name_directory (str))) | |
1277 { | |
1278 val = locate_file_without_hash (path, str, suffixes, storeptr, mode); | |
1279 UNGCPRO; | |
1280 return val; | |
1281 } | |
1282 | |
1283 suffixtab = locate_file_construct_suffixed_files (str, suffixes); | |
1284 | |
2367 | 1285 { |
1286 EXTERNAL_LIST_LOOP_2 (pathel, path) | |
1287 { | |
1288 Lisp_Object hash_table; | |
1289 int found = 0; | |
1290 | |
1291 /* If this path element is relative, we have to look by hand. */ | |
1292 if (NILP (pathel) || NILP (Ffile_name_absolute_p (pathel))) | |
1293 { | |
1294 val = locate_file_in_directory (pathel, str, suffixes, storeptr, | |
1295 mode); | |
1296 if (val >= 0) | |
428 | 1297 { |
2367 | 1298 UNGCPRO; |
1299 return val; | |
428 | 1300 } |
2367 | 1301 continue; |
1302 } | |
1303 | |
1304 pathel_expanded = Fexpand_file_name (pathel, Qnil); | |
1305 hash_table = locate_file_find_directory_hash_table (pathel_expanded); | |
1306 | |
1307 if (!NILP (hash_table)) | |
1308 { | |
1309 /* Loop over suffixes. */ | |
1310 LIST_LOOP_2 (elt, suffixtab) | |
1311 if (!NILP (Fgethash (elt, hash_table, Qnil))) | |
1312 { | |
1313 found = 1; | |
1314 break; | |
1315 } | |
1316 } | |
1317 | |
1318 if (found) | |
1319 { | |
1320 /* This is a likely candidate. Look by hand in this directory | |
1321 so we don't get thrown off if someone byte-compiles a file. */ | |
1322 val = locate_file_in_directory (pathel, str, suffixes, storeptr, | |
1323 mode); | |
1324 if (val >= 0) | |
1325 { | |
1326 UNGCPRO; | |
1327 return val; | |
1328 } | |
1329 | |
1330 /* Hmm ... the file isn't actually there. (Or possibly it's | |
1331 a directory ...) So refresh our hashing. */ | |
1332 locate_file_refresh_hashing (pathel_expanded); | |
1333 } | |
1334 } | |
428 | 1335 } |
1336 | |
1337 /* File is probably not there, but check the hard way just in case. */ | |
1338 val = locate_file_without_hash (path, str, suffixes, storeptr, mode); | |
1339 if (val >= 0) | |
1340 { | |
1341 /* Sneaky user added a file without telling us. */ | |
1342 Flocate_file_clear_hashing (path); | |
1343 } | |
1344 | |
1345 UNGCPRO; | |
1346 return val; | |
1347 } | |
1348 | |
1349 | |
1350 #ifdef LOADHIST | |
1351 | |
1352 /* Merge the list we've accumulated of globals from the current input source | |
1353 into the load_history variable. The details depend on whether | |
1354 the source has an associated file name or not. */ | |
1355 | |
1356 static void | |
1357 build_load_history (int loading, Lisp_Object source) | |
1358 { | |
1359 REGISTER Lisp_Object tail, prev, newelt; | |
1360 REGISTER Lisp_Object tem, tem2; | |
1361 int foundit; | |
1362 | |
1363 #if !defined(LOADHIST_DUMPED) | |
1364 /* Don't bother recording anything for preloaded files. */ | |
1365 if (purify_flag) | |
1366 return; | |
1367 #endif | |
1368 | |
1369 tail = Vload_history; | |
1370 prev = Qnil; | |
1371 foundit = 0; | |
1372 while (!NILP (tail)) | |
1373 { | |
1374 tem = Fcar (tail); | |
1375 | |
1376 /* Find the feature's previous assoc list... */ | |
1377 if (internal_equal (source, Fcar (tem), 0)) | |
1378 { | |
1379 foundit = 1; | |
1380 | |
1381 /* If we're loading, remove it. */ | |
1382 if (loading) | |
1383 { | |
1384 if (NILP (prev)) | |
1385 Vload_history = Fcdr (tail); | |
1386 else | |
1387 Fsetcdr (prev, Fcdr (tail)); | |
1388 } | |
1389 | |
1390 /* Otherwise, cons on new symbols that are not already members. */ | |
1391 else | |
1392 { | |
1393 tem2 = Vcurrent_load_list; | |
1394 | |
1395 while (CONSP (tem2)) | |
1396 { | |
1397 newelt = XCAR (tem2); | |
1398 | |
1399 if (NILP (Fmemq (newelt, tem))) | |
1400 Fsetcar (tail, Fcons (Fcar (tem), | |
1401 Fcons (newelt, Fcdr (tem)))); | |
1402 | |
1403 tem2 = XCDR (tem2); | |
1404 QUIT; | |
1405 } | |
1406 } | |
1407 } | |
1408 else | |
1409 prev = tail; | |
1410 tail = Fcdr (tail); | |
1411 QUIT; | |
1412 } | |
1413 | |
1414 /* If we're loading, cons the new assoc onto the front of load-history, | |
1415 the most-recently-loaded position. Also do this if we didn't find | |
1416 an existing member for the current source. */ | |
1417 if (loading || !foundit) | |
1418 Vload_history = Fcons (Fnreverse (Vcurrent_load_list), | |
1419 Vload_history); | |
1420 } | |
1421 | |
1422 #else /* !LOADHIST */ | |
1423 #define build_load_history(x,y) | |
1424 #endif /* !LOADHIST */ | |
1425 | |
1426 | |
1427 static void | |
1428 readevalloop (Lisp_Object readcharfun, | |
1429 Lisp_Object sourcename, | |
1430 Lisp_Object (*evalfun) (Lisp_Object), | |
1431 int printflag) | |
1432 { | |
1433 /* This function can GC */ | |
867 | 1434 REGISTER Ichar c; |
1849 | 1435 Lisp_Object val = Qnil; |
428 | 1436 int speccount = specpdl_depth (); |
1437 struct gcpro gcpro1, gcpro2; | |
1438 struct buffer *b = 0; | |
1439 | |
1440 if (BUFFERP (readcharfun)) | |
1441 b = XBUFFER (readcharfun); | |
1442 else if (MARKERP (readcharfun)) | |
1443 b = XMARKER (readcharfun)->buffer; | |
1444 | |
1445 /* Don't do this. It is not necessary, and it needlessly exposes | |
1446 READCHARFUN (which can be a stream) to Lisp. --hniksic */ | |
1447 /*specbind (Qstandard_input, readcharfun);*/ | |
1448 | |
2548 | 1449 internal_bind_lisp_object (&Vcurrent_load_list, Qnil); |
428 | 1450 |
1451 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
1452 Vcurrent_compiled_function_annotation = Qnil; | |
1453 #endif | |
1454 GCPRO2 (val, sourcename); | |
1455 | |
1456 LOADHIST_ATTACH (sourcename); | |
1457 | |
1458 while (1) | |
1459 { | |
1460 QUIT; | |
1461 | |
1462 if (b != 0 && !BUFFER_LIVE_P (b)) | |
563 | 1463 invalid_operation ("Reading from killed buffer", Qunbound); |
428 | 1464 |
1465 c = readchar (readcharfun); | |
1466 if (c == ';') | |
1467 { | |
1468 /* Skip comment */ | |
1469 while ((c = readchar (readcharfun)) != '\n' && c != -1) | |
1470 QUIT; | |
1471 continue; | |
1472 } | |
1473 if (c < 0) | |
1474 break; | |
1475 | |
1476 /* Ignore whitespace here, so we can detect eof. */ | |
1477 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r') | |
1478 continue; | |
1479 | |
814 | 1480 unreadchar (readcharfun, c); |
1481 Vread_objects = Qnil; | |
1482 if (NILP (Vload_read_function)) | |
1483 val = read0 (readcharfun); | |
428 | 1484 else |
814 | 1485 val = call1 (Vload_read_function, readcharfun); |
428 | 1486 val = (*evalfun) (val); |
1487 if (printflag) | |
1488 { | |
1489 Vvalues = Fcons (val, Vvalues); | |
1490 if (EQ (Vstandard_output, Qt)) | |
1491 Fprin1 (val, Qnil); | |
1492 else | |
1493 Fprint (val, Qnil); | |
1494 } | |
1495 } | |
1496 | |
1497 build_load_history (LSTREAMP (readcharfun) || | |
1498 /* This looks weird, but it's what's in FSFmacs */ | |
1499 (b ? BUF_NARROWED (b) : BUF_NARROWED (current_buffer)), | |
1500 sourcename); | |
1501 UNGCPRO; | |
1502 | |
771 | 1503 unbind_to (speccount); |
428 | 1504 } |
1505 | |
1506 DEFUN ("eval-buffer", Feval_buffer, 0, 2, "bBuffer: ", /* | |
1507 Execute BUFFER as Lisp code. | |
1508 Programs can pass two arguments, BUFFER and PRINTFLAG. | |
1509 BUFFER is the buffer to evaluate (nil means use current buffer). | |
1510 PRINTFLAG controls printing of output: | |
444 | 1511 nil means discard it; anything else is a stream for printing. |
428 | 1512 |
1513 If there is no error, point does not move. If there is an error, | |
1514 point remains at the end of the last character read from the buffer. | |
1515 */ | |
444 | 1516 (buffer, printflag)) |
428 | 1517 { |
1518 /* This function can GC */ | |
1519 int speccount = specpdl_depth (); | |
1520 Lisp_Object tem, buf; | |
1521 | |
444 | 1522 if (NILP (buffer)) |
428 | 1523 buf = Fcurrent_buffer (); |
1524 else | |
444 | 1525 buf = Fget_buffer (buffer); |
428 | 1526 if (NILP (buf)) |
563 | 1527 invalid_argument ("No such buffer", Qunbound); |
428 | 1528 |
1529 if (NILP (printflag)) | |
1530 tem = Qsymbolp; /* #### #@[]*&$#*[& SI:NULL-STREAM */ | |
1531 else | |
1532 tem = printflag; | |
1533 specbind (Qstandard_output, tem); | |
1534 record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
1535 BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); | |
1536 readevalloop (buf, XBUFFER (buf)->filename, Feval, | |
1537 !NILP (printflag)); | |
1538 | |
771 | 1539 return unbind_to (speccount); |
428 | 1540 } |
1541 | |
1542 #if 0 | |
826 | 1543 DEFUN ("eval-current-buffer", Feval_current_buffer, 0, 1, "", /* |
428 | 1544 Execute the current buffer as Lisp code. |
1545 Programs can pass argument PRINTFLAG which controls printing of output: | |
1546 nil means discard it; anything else is stream for print. | |
1547 | |
1548 If there is no error, point does not move. If there is an error, | |
1549 point remains at the end of the last character read from the buffer. | |
1550 */ | |
1551 (printflag)) | |
1552 { | |
1553 code omitted; | |
1554 } | |
1555 #endif /* 0 */ | |
1556 | |
1557 DEFUN ("eval-region", Feval_region, 2, 3, "r", /* | |
1558 Execute the region as Lisp code. | |
444 | 1559 When called from programs, expects two arguments START and END |
428 | 1560 giving starting and ending indices in the current buffer |
1561 of the text to be executed. | |
444 | 1562 Programs can pass third optional argument STREAM which controls output: |
428 | 1563 nil means discard it; anything else is stream for printing it. |
1564 | |
1565 If there is no error, point does not move. If there is an error, | |
1566 point remains at the end of the last character read from the buffer. | |
1567 | |
1568 Note: Before evaling the region, this function narrows the buffer to it. | |
1569 If the code being eval'd should happen to trigger a redisplay you may | |
1570 see some text temporarily disappear because of this. | |
1571 */ | |
444 | 1572 (start, end, stream)) |
428 | 1573 { |
1574 /* This function can GC */ | |
1575 int speccount = specpdl_depth (); | |
1576 Lisp_Object tem; | |
1577 Lisp_Object cbuf = Fcurrent_buffer (); | |
1578 | |
444 | 1579 if (NILP (stream)) |
428 | 1580 tem = Qsymbolp; /* #### #@[]*&$#*[& SI:NULL-STREAM */ |
1581 else | |
444 | 1582 tem = stream; |
428 | 1583 specbind (Qstandard_output, tem); |
1584 | |
444 | 1585 if (NILP (stream)) |
428 | 1586 record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
844 | 1587 record_unwind_protect (save_restriction_restore, |
1588 save_restriction_save (current_buffer)); | |
428 | 1589 |
444 | 1590 /* This both uses start and checks its type. */ |
1591 Fgoto_char (start, cbuf); | |
1592 Fnarrow_to_region (make_int (BUF_BEGV (current_buffer)), end, cbuf); | |
428 | 1593 readevalloop (cbuf, XBUFFER (cbuf)->filename, Feval, |
444 | 1594 !NILP (stream)); |
428 | 1595 |
771 | 1596 return unbind_to (speccount); |
428 | 1597 } |
1598 | |
1599 DEFUN ("read", Fread, 0, 1, 0, /* | |
1600 Read one Lisp expression as text from STREAM, return as Lisp object. | |
1601 If STREAM is nil, use the value of `standard-input' (which see). | |
1602 STREAM or the value of `standard-input' may be: | |
1603 a buffer (read from point and advance it) | |
1604 a marker (read from where it points and advance it) | |
1605 a function (call it with no arguments for each character, | |
1606 call it with a char as argument to push a char back) | |
1607 a string (takes text from string, starting at the beginning) | |
1608 t (read text line using minibuffer and use it). | |
1609 */ | |
1610 (stream)) | |
1611 { | |
1612 if (NILP (stream)) | |
1613 stream = Vstandard_input; | |
1614 if (EQ (stream, Qt)) | |
1615 stream = Qread_char; | |
1616 | |
1617 Vread_objects = Qnil; | |
1618 | |
1619 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
1620 Vcurrent_compiled_function_annotation = Qnil; | |
1621 #endif | |
1622 if (EQ (stream, Qread_char)) | |
1623 { | |
1624 Lisp_Object val = call1 (Qread_from_minibuffer, | |
771 | 1625 build_msg_string ("Lisp expression: ")); |
428 | 1626 return Fcar (Fread_from_string (val, Qnil, Qnil)); |
1627 } | |
1628 | |
1629 if (STRINGP (stream)) | |
1630 return Fcar (Fread_from_string (stream, Qnil, Qnil)); | |
1631 | |
1632 return read0 (stream); | |
1633 } | |
1634 | |
1635 DEFUN ("read-from-string", Fread_from_string, 1, 3, 0, /* | |
1636 Read one Lisp expression which is represented as text by STRING. | |
1637 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX). | |
1638 START and END optionally delimit a substring of STRING from which to read; | |
1639 they default to 0 and (length STRING) respectively. | |
1640 */ | |
1641 (string, start, end)) | |
1642 { | |
1643 Bytecount startval, endval; | |
1644 Lisp_Object tem; | |
1645 Lisp_Object lispstream = Qnil; | |
1646 struct gcpro gcpro1; | |
1647 | |
1648 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
1649 Vcurrent_compiled_function_annotation = Qnil; | |
1650 #endif | |
1651 GCPRO1 (lispstream); | |
1652 CHECK_STRING (string); | |
1653 get_string_range_byte (string, start, end, &startval, &endval, | |
1654 GB_HISTORICAL_STRING_BEHAVIOR); | |
1655 lispstream = make_lisp_string_input_stream (string, startval, | |
1656 endval - startval); | |
1657 | |
1658 Vread_objects = Qnil; | |
1659 | |
1660 tem = read0 (lispstream); | |
1661 /* Yeah, it's ugly. Gonna make something of it? | |
1662 At least our reader is reentrant ... */ | |
1663 tem = | |
1664 (Fcons (tem, make_int | |
793 | 1665 (string_index_byte_to_char |
771 | 1666 (string, |
428 | 1667 startval + Lstream_byte_count (XLSTREAM (lispstream)))))); |
1668 Lstream_delete (XLSTREAM (lispstream)); | |
1669 UNGCPRO; | |
1670 return tem; | |
1671 } | |
1672 | |
1673 | |
1674 | |
1675 /* Use this for recursive reads, in contexts where internal tokens | |
1676 are not allowed. See also read1(). */ | |
1677 static Lisp_Object | |
1678 read0 (Lisp_Object readcharfun) | |
1679 { | |
1680 Lisp_Object val = read1 (readcharfun); | |
1681 | |
1682 if (CONSP (val) && UNBOUNDP (XCAR (val))) | |
1683 { | |
867 | 1684 Ichar c = XCHAR (XCDR (val)); |
853 | 1685 free_cons (val); |
428 | 1686 return Fsignal (Qinvalid_read_syntax, |
1687 list1 (Fchar_to_string (make_char (c)))); | |
1688 } | |
1689 | |
1690 return val; | |
1691 } | |
3543 | 1692 |
1693 /* A Unicode escape, as in C# (though we only permit them in strings | |
1694 and characters, not arbitrarily in the source code.) */ | |
1695 static Ichar | |
1696 read_unicode_escape (Lisp_Object readcharfun, int unicode_hex_count) | |
1697 { | |
1698 REGISTER Ichar i = 0, c; | |
1699 REGISTER int count = 0; | |
1700 Lisp_Object lisp_char; | |
1701 while (++count <= unicode_hex_count) | |
1702 { | |
1703 c = readchar (readcharfun); | |
1704 /* Remember, can't use isdigit(), isalpha() etc. on Ichars */ | |
1705 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); | |
1706 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; | |
1707 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; | |
1708 else | |
1709 { | |
1710 syntax_error ("Non-hex digit used for Unicode escape", | |
1711 make_char (c)); | |
1712 break; | |
1713 } | |
1714 } | |
1715 | |
4268 | 1716 if (i >= 0x110000 || i < 0) |
4096 | 1717 { |
1718 syntax_error ("Not a Unicode code point", make_int(i)); | |
1719 } | |
1720 | |
3543 | 1721 lisp_char = Funicode_to_char(make_int(i), Qnil); |
1722 | |
1723 if (EQ(Qnil, lisp_char)) | |
1724 { | |
4096 | 1725 /* Will happen on non-Mule. Silent corruption is what happens |
1726 elsewhere, and we used to do that to be consistent, but GNU error, | |
1727 so people writing portable code need to be able to handle that, and | |
1728 given a choice I prefer that behaviour. | |
1729 | |
1730 An undesirable aspect to this error is that the code point is shown | |
1731 as a decimal integer, which is mostly unreadable. */ | |
1732 syntax_error ("Unsupported Unicode code point", make_int(i)); | |
3543 | 1733 } |
4096 | 1734 |
1735 return XCHAR(lisp_char); | |
3543 | 1736 } |
1737 | |
428 | 1738 |
867 | 1739 static Ichar |
428 | 1740 read_escape (Lisp_Object readcharfun) |
1741 { | |
1742 /* This function can GC */ | |
867 | 1743 Ichar c = readchar (readcharfun); |
428 | 1744 |
1745 if (c < 0) | |
563 | 1746 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1747 |
1748 switch (c) | |
1749 { | |
1750 case 'a': return '\007'; | |
1751 case 'b': return '\b'; | |
1752 case 'd': return 0177; | |
1753 case 'e': return 033; | |
1754 case 'f': return '\f'; | |
1755 case 'n': return '\n'; | |
1756 case 'r': return '\r'; | |
1757 case 't': return '\t'; | |
1758 case 'v': return '\v'; | |
1759 case '\n': return -1; | |
1760 | |
1761 case 'M': | |
1762 c = readchar (readcharfun); | |
1763 if (c < 0) | |
563 | 1764 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1765 if (c != '-') |
563 | 1766 syntax_error ("Invalid escape character syntax", Qunbound); |
428 | 1767 c = readchar (readcharfun); |
1768 if (c < 0) | |
563 | 1769 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1770 if (c == '\\') |
1771 c = read_escape (readcharfun); | |
1772 return c | 0200; | |
1773 | |
1774 /* Originally, FSF_KEYS provided a degree of FSF Emacs | |
1775 compatibility by defining character "modifiers" alt, super, | |
1776 hyper and shift to infest the characters (i.e. integers). | |
1777 | |
1778 However, this doesn't cut it for XEmacs 20, which | |
1779 distinguishes characters from integers. Without Mule, ?\H-a | |
1780 simply returns ?a because every character is clipped into | |
1781 0-255. Under Mule it is much worse -- ?\H-a with FSF_KEYS | |
1782 produces an illegal character, and moves us to crash-land. | |
1783 | |
1784 For these reasons, FSF_KEYS hack is useless and without hope | |
1785 of ever working under XEmacs 20. */ | |
1786 #ifdef FSF_KEYS | |
831 | 1787 /* Deleted */ |
1788 #endif | |
428 | 1789 |
1790 case 'C': | |
1791 c = readchar (readcharfun); | |
1792 if (c < 0) | |
563 | 1793 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1794 if (c != '-') |
563 | 1795 syntax_error ("Invalid escape character syntax", Qunbound); |
428 | 1796 case '^': |
1797 c = readchar (readcharfun); | |
1798 if (c < 0) | |
563 | 1799 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1800 if (c == '\\') |
1801 c = read_escape (readcharfun); | |
1802 /* FSFmacs junk for non-ASCII controls. | |
1803 Not used here. */ | |
1804 if (c == '?') | |
1805 return 0177; | |
1806 else | |
1807 return c & (0200 | 037); | |
1808 | |
1809 case '0': | |
1810 case '1': | |
1811 case '2': | |
1812 case '3': | |
1813 case '4': | |
1814 case '5': | |
1815 case '6': | |
1816 case '7': | |
1817 /* An octal escape, as in ANSI C. */ | |
1818 { | |
867 | 1819 REGISTER Ichar i = c - '0'; |
428 | 1820 REGISTER int count = 0; |
1821 while (++count < 3) | |
1822 { | |
1823 if ((c = readchar (readcharfun)) >= '0' && c <= '7') | |
1824 i = (i << 3) + (c - '0'); | |
1825 else | |
1826 { | |
1827 unreadchar (readcharfun, c); | |
1828 break; | |
1829 } | |
1830 } | |
831 | 1831 if (i >= 0400) |
3367 | 1832 syntax_error ("Non-ISO-8859-1 character specified with octal escape", |
831 | 1833 make_int (i)); |
428 | 1834 return i; |
1835 } | |
1836 | |
1837 case 'x': | |
1838 /* A hex escape, as in ANSI C, except that we only allow latin-1 | |
1839 characters to be read this way. What is "\x4e03" supposed to | |
1840 mean, anyways, if the internal representation is hidden? | |
1841 This is also consistent with the treatment of octal escapes. */ | |
1842 { | |
867 | 1843 REGISTER Ichar i = 0; |
428 | 1844 REGISTER int count = 0; |
1845 while (++count <= 2) | |
1846 { | |
1847 c = readchar (readcharfun); | |
867 | 1848 /* Remember, can't use isdigit(), isalpha() etc. on Ichars */ |
428 | 1849 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); |
1850 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; | |
1851 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; | |
1852 else | |
1853 { | |
1854 unreadchar (readcharfun, c); | |
1855 break; | |
1856 } | |
1857 } | |
1858 return i; | |
1859 } | |
3367 | 1860 case 'U': |
1861 /* Post-Unicode-2.0: Up to eight hex chars */ | |
3543 | 1862 return read_unicode_escape(readcharfun, 8); |
3367 | 1863 case 'u': |
3543 | 1864 /* Unicode-2.0 and before; four hex chars. */ |
1865 return read_unicode_escape(readcharfun, 4); | |
428 | 1866 |
1867 default: | |
1868 return c; | |
1869 } | |
1870 } | |
1871 | |
1872 | |
1873 | |
1874 /* read symbol-constituent stuff into `Vread_buffer_stream'. */ | |
1875 static Bytecount | |
867 | 1876 read_atom_0 (Lisp_Object readcharfun, Ichar firstchar, int *saw_a_backslash) |
428 | 1877 { |
1878 /* This function can GC */ | |
867 | 1879 Ichar c = ((firstchar) >= 0 ? firstchar : readchar (readcharfun)); |
428 | 1880 Lstream_rewind (XLSTREAM (Vread_buffer_stream)); |
1881 | |
1882 *saw_a_backslash = 0; | |
1883 | |
1884 while (c > 040 /* #### - comma should be here as should backquote */ | |
1885 && !(c == '\"' || c == '\'' || c == ';' | |
1886 || c == '(' || c == ')' | |
1887 || c == '[' || c == ']' || c == '#' | |
1888 )) | |
1889 { | |
1890 if (c == '\\') | |
1891 { | |
1892 c = readchar (readcharfun); | |
1893 if (c < 0) | |
563 | 1894 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1895 *saw_a_backslash = 1; |
1896 } | |
867 | 1897 Lstream_put_ichar (XLSTREAM (Vread_buffer_stream), c); |
428 | 1898 QUIT; |
1899 c = readchar (readcharfun); | |
1900 } | |
1901 | |
1902 if (c >= 0) | |
1903 unreadchar (readcharfun, c); | |
1904 /* blasted terminating 0 */ | |
867 | 1905 Lstream_put_ichar (XLSTREAM (Vread_buffer_stream), 0); |
428 | 1906 Lstream_flush (XLSTREAM (Vread_buffer_stream)); |
1907 | |
1908 return Lstream_byte_count (XLSTREAM (Vread_buffer_stream)) - 1; | |
1909 } | |
1910 | |
867 | 1911 static Lisp_Object parse_integer (const Ibyte *buf, Bytecount len, int base); |
428 | 1912 |
1913 static Lisp_Object | |
1914 read_atom (Lisp_Object readcharfun, | |
867 | 1915 Ichar firstchar, |
428 | 1916 int uninterned_symbol) |
1917 { | |
1918 /* This function can GC */ | |
1919 int saw_a_backslash; | |
1920 Bytecount len = read_atom_0 (readcharfun, firstchar, &saw_a_backslash); | |
1921 char *read_ptr = (char *) | |
1922 resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)); | |
1923 | |
1924 /* Is it an integer? */ | |
1925 if (! (saw_a_backslash || uninterned_symbol)) | |
1926 { | |
1927 /* If a token had any backslashes in it, it is disqualified from | |
1928 being an integer or a float. This means that 123\456 is a | |
1929 symbol, as is \123 (which is the way (intern "123") prints). | |
1930 Also, if token was preceded by #:, it's always a symbol. | |
1931 */ | |
1932 char *p = read_ptr + len; | |
1933 char *p1 = read_ptr; | |
1934 | |
1935 if (*p1 == '+' || *p1 == '-') p1++; | |
1936 if (p1 != p) | |
1937 { | |
1938 int c; | |
1939 | |
1940 while (p1 != p && (c = *p1) >= '0' && c <= '9') | |
1941 p1++; | |
1942 /* Integers can have trailing decimal points. */ | |
1943 if (p1 > read_ptr && p1 < p && *p1 == '.') | |
1944 p1++; | |
1945 if (p1 == p) | |
1946 { | |
1947 /* It is an integer. */ | |
1948 if (p1[-1] == '.') | |
1949 p1[-1] = '\0'; | |
1950 #if 0 | |
1951 { | |
1952 int number = 0; | |
1953 if (sizeof (int) == sizeof (EMACS_INT)) | |
1954 number = atoi (read_buffer); | |
1955 else if (sizeof (long) == sizeof (EMACS_INT)) | |
1956 number = atol (read_buffer); | |
1957 else | |
2500 | 1958 ABORT (); |
428 | 1959 return make_int (number); |
1960 } | |
1961 #else | |
867 | 1962 return parse_integer ((Ibyte *) read_ptr, len, 10); |
428 | 1963 #endif |
1964 } | |
1965 } | |
1983 | 1966 #ifdef HAVE_RATIO |
1967 if (isratio_string (read_ptr)) | |
1968 { | |
2013 | 1969 /* GMP ratio_set_string has no effect with initial + sign */ |
2010 | 1970 if (*read_ptr == '+') |
1971 read_ptr++; | |
1983 | 1972 ratio_set_string (scratch_ratio, read_ptr, 0); |
1973 ratio_canonicalize (scratch_ratio); | |
1974 return Fcanonicalize_number (make_ratio_rt (scratch_ratio)); | |
1975 } | |
1976 #endif | |
428 | 1977 if (isfloat_string (read_ptr)) |
1978 return make_float (atof (read_ptr)); | |
1979 } | |
1980 | |
1981 { | |
1982 Lisp_Object sym; | |
1983 if (uninterned_symbol) | |
867 | 1984 sym = Fmake_symbol ( make_string ((Ibyte *) read_ptr, len)); |
428 | 1985 else |
1986 { | |
867 | 1987 Lisp_Object name = make_string ((Ibyte *) read_ptr, len); |
428 | 1988 sym = Fintern (name, Qnil); |
1989 } | |
1990 return sym; | |
1991 } | |
1992 } | |
1993 | |
1994 | |
1995 static Lisp_Object | |
867 | 1996 parse_integer (const Ibyte *buf, Bytecount len, int base) |
428 | 1997 { |
867 | 1998 const Ibyte *lim = buf + len; |
1999 const Ibyte *p = buf; | |
428 | 2000 EMACS_UINT num = 0; |
2001 int negativland = 0; | |
2002 | |
2003 if (*p == '-') | |
2004 { | |
2005 negativland = 1; | |
2006 p++; | |
2007 } | |
2008 else if (*p == '+') | |
2009 { | |
2010 p++; | |
2011 } | |
2012 | |
2013 if (p == lim) | |
2014 goto loser; | |
2015 | |
2016 for (; (p < lim) && (*p != '\0'); p++) | |
2017 { | |
2018 int c = *p; | |
2019 EMACS_UINT onum; | |
2020 | |
2021 if (isdigit (c)) | |
2022 c = c - '0'; | |
2023 else if (isupper (c)) | |
2024 c = c - 'A' + 10; | |
2025 else if (islower (c)) | |
2026 c = c - 'a' + 10; | |
2027 else | |
2028 goto loser; | |
2029 | |
2030 if (c < 0 || c >= base) | |
2031 goto loser; | |
2032 | |
2033 onum = num; | |
2034 num = num * base + c; | |
2035 if (num < onum) | |
2036 goto overflow; | |
2037 } | |
2038 | |
2039 { | |
2040 EMACS_INT int_result = negativland ? - (EMACS_INT) num : (EMACS_INT) num; | |
2041 Lisp_Object result = make_int (int_result); | |
2042 if (num && ((XINT (result) < 0) != negativland)) | |
2043 goto overflow; | |
2044 if (XINT (result) != int_result) | |
2045 goto overflow; | |
2046 return result; | |
2047 } | |
2048 overflow: | |
1983 | 2049 #ifdef HAVE_BIGNUM |
2050 { | |
4329
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4268
diff
changeset
|
2051 bignum_set_string (scratch_bignum, (const char *) buf, base); |
1983 | 2052 return make_bignum_bg (scratch_bignum); |
2053 } | |
2054 #else | |
428 | 2055 return Fsignal (Qinvalid_read_syntax, |
771 | 2056 list3 (build_msg_string |
428 | 2057 ("Integer constant overflow in reader"), |
2058 make_string (buf, len), | |
2059 make_int (base))); | |
1983 | 2060 #endif /* HAVE_BIGNUM */ |
428 | 2061 loser: |
2062 return Fsignal (Qinvalid_read_syntax, | |
771 | 2063 list3 (build_msg_string |
428 | 2064 ("Invalid integer constant in reader"), |
2065 make_string (buf, len), | |
2066 make_int (base))); | |
2067 } | |
2068 | |
2069 | |
2070 static Lisp_Object | |
2071 read_integer (Lisp_Object readcharfun, int base) | |
2072 { | |
2073 /* This function can GC */ | |
2074 int saw_a_backslash; | |
2075 Bytecount len = read_atom_0 (readcharfun, -1, &saw_a_backslash); | |
2076 return (parse_integer | |
2077 (resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)), | |
2078 ((saw_a_backslash) | |
2079 ? 0 /* make parse_integer signal error */ | |
2080 : len), | |
2081 base)); | |
2082 } | |
2083 | |
2084 static Lisp_Object | |
2085 read_bit_vector (Lisp_Object readcharfun) | |
2086 { | |
2087 unsigned_char_dynarr *dyn = Dynarr_new (unsigned_char); | |
440 | 2088 Lisp_Object val; |
428 | 2089 |
2090 while (1) | |
2091 { | |
444 | 2092 unsigned char bit; |
867 | 2093 Ichar c = readchar (readcharfun); |
444 | 2094 if (c == '0') |
2095 bit = 0; | |
2096 else if (c == '1') | |
2097 bit = 1; | |
2098 else | |
2099 { | |
2100 if (c >= 0) | |
2101 unreadchar (readcharfun, c); | |
2102 break; | |
2103 } | |
2104 Dynarr_add (dyn, bit); | |
428 | 2105 } |
2106 | |
440 | 2107 val = make_bit_vector_from_byte_vector (Dynarr_atp (dyn, 0), |
2108 Dynarr_length (dyn)); | |
2109 Dynarr_free (dyn); | |
2110 | |
2111 return val; | |
428 | 2112 } |
2113 | |
2114 | |
2115 | |
2116 /* structures */ | |
2117 | |
2118 struct structure_type * | |
2119 define_structure_type (Lisp_Object type, | |
2120 int (*validate) (Lisp_Object data, | |
578 | 2121 Error_Behavior errb), |
428 | 2122 Lisp_Object (*instantiate) (Lisp_Object data)) |
2123 { | |
2124 struct structure_type st; | |
2125 | |
2126 st.type = type; | |
2127 st.keywords = Dynarr_new (structure_keyword_entry); | |
2128 st.validate = validate; | |
2129 st.instantiate = instantiate; | |
2130 Dynarr_add (the_structure_type_dynarr, st); | |
2131 | |
2132 return Dynarr_atp (the_structure_type_dynarr, | |
2133 Dynarr_length (the_structure_type_dynarr) - 1); | |
2134 } | |
2135 | |
2136 void | |
2137 define_structure_type_keyword (struct structure_type *st, Lisp_Object keyword, | |
2138 int (*validate) (Lisp_Object keyword, | |
2139 Lisp_Object value, | |
578 | 2140 Error_Behavior errb)) |
428 | 2141 { |
2142 struct structure_keyword_entry en; | |
2143 | |
2144 en.keyword = keyword; | |
2145 en.validate = validate; | |
2146 Dynarr_add (st->keywords, en); | |
2147 } | |
2148 | |
2149 static struct structure_type * | |
2150 recognized_structure_type (Lisp_Object type) | |
2151 { | |
2152 int i; | |
2153 | |
2154 for (i = 0; i < Dynarr_length (the_structure_type_dynarr); i++) | |
2155 { | |
2156 struct structure_type *st = Dynarr_atp (the_structure_type_dynarr, i); | |
2157 if (EQ (st->type, type)) | |
2158 return st; | |
2159 } | |
2160 | |
2161 return 0; | |
2162 } | |
2163 | |
2164 static Lisp_Object | |
2165 read_structure (Lisp_Object readcharfun) | |
2166 { | |
867 | 2167 Ichar c = readchar (readcharfun); |
428 | 2168 Lisp_Object list = Qnil; |
2169 Lisp_Object orig_list = Qnil; | |
2170 Lisp_Object already_seen = Qnil; | |
2171 int keyword_count; | |
2172 struct structure_type *st; | |
2173 struct gcpro gcpro1, gcpro2; | |
2174 | |
2175 GCPRO2 (orig_list, already_seen); | |
2176 if (c != '(') | |
442 | 2177 RETURN_UNGCPRO (continuable_read_syntax_error ("#s not followed by paren")); |
428 | 2178 list = read_list (readcharfun, ')', 0, 0); |
2179 orig_list = list; | |
2180 { | |
2181 int len = XINT (Flength (list)); | |
2182 if (len == 0) | |
442 | 2183 RETURN_UNGCPRO (continuable_read_syntax_error |
428 | 2184 ("structure type not specified")); |
2185 if (!(len & 1)) | |
2186 RETURN_UNGCPRO | |
442 | 2187 (continuable_read_syntax_error |
428 | 2188 ("structures must have alternating keyword/value pairs")); |
2189 } | |
2190 | |
2191 st = recognized_structure_type (XCAR (list)); | |
2192 if (!st) | |
2193 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2194 list2 (build_msg_string |
428 | 2195 ("unrecognized structure type"), |
2196 XCAR (list)))); | |
2197 | |
2198 list = Fcdr (list); | |
2199 keyword_count = Dynarr_length (st->keywords); | |
2200 while (!NILP (list)) | |
2201 { | |
2202 Lisp_Object keyword, value; | |
2203 int i; | |
2204 struct structure_keyword_entry *en = NULL; | |
2205 | |
2206 keyword = Fcar (list); | |
2207 list = Fcdr (list); | |
2208 value = Fcar (list); | |
2209 list = Fcdr (list); | |
2210 | |
2211 if (!NILP (memq_no_quit (keyword, already_seen))) | |
2212 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2213 list2 (build_msg_string |
428 | 2214 ("structure keyword already seen"), |
2215 keyword))); | |
2216 | |
2217 for (i = 0; i < keyword_count; i++) | |
2218 { | |
2219 en = Dynarr_atp (st->keywords, i); | |
2220 if (EQ (keyword, en->keyword)) | |
2221 break; | |
2222 } | |
2223 | |
2224 if (i == keyword_count) | |
2225 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2226 list2 (build_msg_string |
428 | 2227 ("unrecognized structure keyword"), |
2228 keyword))); | |
2229 | |
2230 if (en->validate && ! (en->validate) (keyword, value, ERROR_ME)) | |
2231 RETURN_UNGCPRO | |
2232 (Fsignal (Qinvalid_read_syntax, | |
771 | 2233 list3 (build_msg_string |
428 | 2234 ("invalid value for structure keyword"), |
2235 keyword, value))); | |
2236 | |
2237 already_seen = Fcons (keyword, already_seen); | |
2238 } | |
2239 | |
2240 if (st->validate && ! (st->validate) (orig_list, ERROR_ME)) | |
2241 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2242 list2 (build_msg_string |
428 | 2243 ("invalid structure initializer"), |
2244 orig_list))); | |
2245 | |
2246 RETURN_UNGCPRO ((st->instantiate) (XCDR (orig_list))); | |
2247 } | |
2248 | |
2249 | |
2250 static Lisp_Object read_compiled_function (Lisp_Object readcharfun, | |
2251 int terminator); | |
2252 static Lisp_Object read_vector (Lisp_Object readcharfun, int terminator); | |
2253 | |
2254 /* Get the next character; filter out whitespace and comments */ | |
2255 | |
867 | 2256 static Ichar |
428 | 2257 reader_nextchar (Lisp_Object readcharfun) |
2258 { | |
2259 /* This function can GC */ | |
867 | 2260 Ichar c; |
428 | 2261 |
2262 retry: | |
2263 QUIT; | |
2264 c = readchar (readcharfun); | |
2265 if (c < 0) | |
563 | 2266 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 2267 |
2268 switch (c) | |
2269 { | |
2270 default: | |
2271 { | |
2272 /* Ignore whitespace and control characters */ | |
2273 if (c <= 040) | |
2274 goto retry; | |
2275 return c; | |
2276 } | |
2277 | |
2278 case ';': | |
2279 { | |
2280 /* Comment */ | |
2281 while ((c = readchar (readcharfun)) >= 0 && c != '\n') | |
2282 QUIT; | |
2283 goto retry; | |
2284 } | |
2285 } | |
2286 } | |
2287 | |
2288 #if 0 | |
2289 static Lisp_Object | |
2290 list2_pure (int pure, Lisp_Object a, Lisp_Object b) | |
2291 { | |
2292 return pure ? pure_cons (a, pure_cons (b, Qnil)) : list2 (a, b); | |
2293 } | |
2294 #endif | |
2295 | |
3543 | 2296 static Lisp_Object |
2297 read_string (Lisp_Object readcharfun, Ichar delim, int raw, | |
2298 int honor_unicode) | |
2299 { | |
2300 #ifdef I18N3 | |
2301 /* #### If the input stream is translating, then the string | |
2302 should be marked as translatable by setting its | |
2303 `string-translatable' property to t. .el and .elc files | |
2304 normally are translating input streams. See Fgettext() | |
2305 and print_internal(). */ | |
2306 #endif | |
2307 Ichar c; | |
2308 int cancel = 0; | |
2309 | |
2310 Lstream_rewind(XLSTREAM(Vread_buffer_stream)); | |
2311 while ((c = readchar(readcharfun)) >= 0 && c != delim) | |
2312 { | |
2313 if (c == '\\') | |
2314 { | |
2315 if (raw) | |
2316 { | |
2317 c = readchar(readcharfun); | |
2318 if (honor_unicode && ('u' == c || 'U' == c)) | |
2319 { | |
2320 c = read_unicode_escape(readcharfun, | |
2321 'U' == c ? 8 : 4); | |
2322 } | |
2323 else | |
2324 { | |
2325 /* For raw strings, insert the | |
2326 backslash and the next char, */ | |
2327 Lstream_put_ichar(XLSTREAM | |
2328 (Vread_buffer_stream), | |
2329 '\\'); | |
2330 } | |
2331 } | |
2332 else | |
2333 /* otherwise, backslash escapes the next char. */ | |
2334 c = read_escape(readcharfun); | |
2335 } | |
2336 /* c is -1 if \ newline has just been seen */ | |
2337 if (c == -1) | |
2338 { | |
2339 if (Lstream_byte_count | |
2340 (XLSTREAM(Vread_buffer_stream)) == | |
2341 0) | |
2342 cancel = 1; | |
2343 } | |
2344 else | |
2345 Lstream_put_ichar(XLSTREAM | |
2346 (Vread_buffer_stream), | |
2347 c); | |
2348 QUIT; | |
2349 } | |
2350 if (c < 0) | |
2351 return Fsignal(Qend_of_file, | |
2352 list1(READCHARFUN_MAYBE(readcharfun))); | |
2353 | |
2354 /* If purifying, and string starts with \ newline, | |
2355 return zero instead. This is for doc strings | |
2356 that we are really going to find in lib-src/DOC.nn.nn */ | |
2357 if (purify_flag && NILP(Vinternal_doc_file_name) | |
2358 && cancel) | |
2359 return Qzero; | |
2360 | |
2361 Lstream_flush(XLSTREAM(Vread_buffer_stream)); | |
2362 return make_string(resizing_buffer_stream_ptr | |
2363 (XLSTREAM(Vread_buffer_stream)), | |
2364 Lstream_byte_count(XLSTREAM(Vread_buffer_stream))); | |
2365 } | |
2366 | |
2367 static Lisp_Object | |
2368 read_raw_string (Lisp_Object readcharfun) | |
2369 { | |
2370 Ichar c; | |
2371 Ichar permit_unicode = 0; | |
2372 | |
2373 do { | |
2374 c = reader_nextchar(readcharfun); | |
2375 switch (c) { | |
2376 /* #r:engine"my sexy raw string" -- raw string w/ flags*/ | |
2377 /* case ':': */ | |
2378 /* #ru"Hi there\u20AC \U000020AC" -- raw string, honouring Unicode. */ | |
2379 case 'u': | |
2380 case 'U': | |
2381 permit_unicode = c; | |
2382 continue; | |
2383 | |
2384 /* #r"my raw string" -- raw string */ | |
2385 case '\"': | |
2386 return read_string(readcharfun, '\"', 1, permit_unicode); | |
2387 /* invalid syntax */ | |
2388 default: | |
2389 { | |
2390 if (permit_unicode) | |
2391 { | |
2392 unreadchar(readcharfun, permit_unicode); | |
2393 } | |
2394 unreadchar(readcharfun, c); | |
2395 return Fsignal(Qinvalid_read_syntax, | |
2396 list1(build_string | |
2397 ("unrecognized raw string syntax"))); | |
2398 } | |
2399 } | |
2400 } while (1); | |
2401 } | |
2402 | |
428 | 2403 /* Read the next Lisp object from the stream READCHARFUN and return it. |
2404 If the return value is a cons whose car is Qunbound, then read1() | |
2405 encountered a misplaced token (e.g. a right bracket, right paren, | |
2406 or dot followed by a non-number). To filter this stuff out, | |
2407 use read0(). */ | |
2408 | |
2409 static Lisp_Object | |
2410 read1 (Lisp_Object readcharfun) | |
2411 { | |
867 | 2412 Ichar c; |
428 | 2413 |
2414 retry: | |
2415 c = reader_nextchar (readcharfun); | |
2416 | |
2417 switch (c) | |
2418 { | |
2419 case '(': | |
2420 { | |
2421 #ifdef LISP_BACKQUOTES /* old backquote compatibility in lisp reader */ | |
2422 /* if this is disabled, then other code in eval.c must be enabled */ | |
867 | 2423 Ichar ch = reader_nextchar (readcharfun); |
428 | 2424 switch (ch) |
2425 { | |
2426 case '`': | |
2427 { | |
2428 Lisp_Object tem; | |
853 | 2429 int speccount = internal_bind_int (&old_backquote_flag, |
2430 1 + old_backquote_flag); | |
428 | 2431 tem = read0 (readcharfun); |
771 | 2432 unbind_to (speccount); |
428 | 2433 ch = reader_nextchar (readcharfun); |
2434 if (ch != ')') | |
2435 { | |
2436 unreadchar (readcharfun, ch); | |
2437 return Fsignal (Qinvalid_read_syntax, | |
771 | 2438 list1 (build_msg_string |
428 | 2439 ("Weird old-backquote syntax"))); |
2440 } | |
2441 return list2 (Qbacktick, tem); | |
2442 } | |
2443 case ',': | |
2444 { | |
2445 if (old_backquote_flag) | |
2446 { | |
2447 Lisp_Object tem, comma_type; | |
2448 ch = readchar (readcharfun); | |
2449 if (ch == '@') | |
2450 comma_type = Qcomma_at; | |
2451 else | |
2452 { | |
2453 if (ch >= 0) | |
2454 unreadchar (readcharfun, ch); | |
2455 comma_type = Qcomma; | |
2456 } | |
2457 tem = read0 (readcharfun); | |
2458 ch = reader_nextchar (readcharfun); | |
2459 if (ch != ')') | |
2460 { | |
2461 unreadchar (readcharfun, ch); | |
2462 return Fsignal (Qinvalid_read_syntax, | |
771 | 2463 list1 (build_msg_string |
428 | 2464 ("Weird old-backquote syntax"))); |
2465 } | |
2466 return list2 (comma_type, tem); | |
2467 } | |
2468 else | |
2469 { | |
2470 unreadchar (readcharfun, ch); | |
2471 #if 0 | |
2472 return Fsignal (Qinvalid_read_syntax, | |
771 | 2473 list1 (build_msg_string ("Comma outside of backquote"))); |
428 | 2474 #else |
2475 /* #### - yuck....but this is reverse compatible. */ | |
2476 /* mostly this is required by edebug, which does its own | |
2477 annotated reading. We need to have an annotated_read | |
2478 function that records (with markers) the buffer | |
2479 positions of the elements that make up lists, then that | |
2480 can be used in edebug and bytecomp and the check above | |
2481 can go back in. --Stig */ | |
2482 break; | |
2483 #endif | |
2484 } | |
2485 } | |
2486 default: | |
2487 unreadchar (readcharfun, ch); | |
2488 } /* switch(ch) */ | |
2489 #endif /* old backquote crap... */ | |
2490 return read_list (readcharfun, ')', 1, 1); | |
2491 } | |
2492 case '[': | |
2493 return read_vector (readcharfun, ']'); | |
2494 | |
2495 case ')': | |
2496 case ']': | |
2497 /* #### - huh? these don't do what they seem... */ | |
2498 return noseeum_cons (Qunbound, make_char (c)); | |
2499 case '.': | |
2500 { | |
2501 /* If a period is followed by a number, then we should read it | |
2502 as a floating point number. Otherwise, it denotes a dotted | |
2503 pair. | |
2504 */ | |
2505 c = readchar (readcharfun); | |
2506 unreadchar (readcharfun, c); | |
2507 | |
867 | 2508 /* Can't use isdigit on Ichars */ |
428 | 2509 if (c < '0' || c > '9') |
2510 return noseeum_cons (Qunbound, make_char ('.')); | |
2511 | |
2512 /* Note that read_atom will loop | |
2513 at least once, assuring that we will not try to UNREAD | |
2514 two characters in a row. | |
2515 (I think this doesn't matter anymore because there should | |
2516 be no more danger in unreading multiple characters) */ | |
2517 return read_atom (readcharfun, '.', 0); | |
2518 } | |
2519 | |
2520 case '#': | |
2521 { | |
2522 c = readchar (readcharfun); | |
2523 switch (c) | |
2524 { | |
2525 #if 0 /* FSFmacs silly char-table syntax */ | |
2526 case '^': | |
2527 #endif | |
2528 #if 0 /* FSFmacs silly bool-vector syntax */ | |
2529 case '&': | |
2530 #endif | |
2531 /* "#["-- byte-code constant syntax */ | |
2532 /* purecons #[...] syntax */ | |
2533 case '[': return read_compiled_function (readcharfun, ']' | |
2534 /*, purify_flag */ ); | |
2535 /* "#:"-- gensym syntax */ | |
2536 case ':': return read_atom (readcharfun, -1, 1); | |
2537 /* #'x => (function x) */ | |
2538 case '\'': return list2 (Qfunction, read0 (readcharfun)); | |
2539 #if 0 | |
2540 /* RMS uses this syntax for fat-strings. | |
2541 If we use it for vectors, then obscure bugs happen. | |
2542 */ | |
2543 /* "#(" -- Scheme/CL vector syntax */ | |
2544 case '(': return read_vector (readcharfun, ')'); | |
2545 #endif | |
2546 #if 0 /* FSFmacs */ | |
2547 case '(': | |
2548 { | |
2549 Lisp_Object tmp; | |
2550 struct gcpro gcpro1; | |
2551 | |
2552 /* Read the string itself. */ | |
2553 tmp = read1 (readcharfun); | |
2554 if (!STRINGP (tmp)) | |
2555 { | |
2556 if (CONSP (tmp) && UNBOUNDP (XCAR (tmp))) | |
853 | 2557 free_cons (tmp); |
428 | 2558 return Fsignal (Qinvalid_read_syntax, |
2559 list1 (build_string ("#"))); | |
2560 } | |
2561 GCPRO1 (tmp); | |
2562 /* Read the intervals and their properties. */ | |
2563 while (1) | |
2564 { | |
2565 Lisp_Object beg, end, plist; | |
867 | 2566 Ichar ch; |
428 | 2567 int invalid = 0; |
2568 | |
2569 beg = read1 (readcharfun); | |
2570 if (CONSP (beg) && UNBOUNDP (XCAR (beg))) | |
2571 { | |
2572 ch = XCHAR (XCDR (beg)); | |
853 | 2573 free_cons (beg); |
428 | 2574 if (ch == ')') |
2575 break; | |
2576 else | |
2577 invalid = 1; | |
2578 } | |
2579 if (!invalid) | |
2580 { | |
2581 end = read1 (readcharfun); | |
2582 if (CONSP (end) && UNBOUNDP (XCAR (end))) | |
2583 { | |
853 | 2584 free_cons (end); |
428 | 2585 invalid = 1; |
2586 } | |
2587 } | |
2588 if (!invalid) | |
2589 { | |
2590 plist = read1 (readcharfun); | |
2591 if (CONSP (plist) && UNBOUNDP (XCAR (plist))) | |
2592 { | |
853 | 2593 free_cons (plist); |
428 | 2594 invalid = 1; |
2595 } | |
2596 } | |
2597 if (invalid) | |
2598 RETURN_UNGCPRO | |
2599 (Fsignal (Qinvalid_read_syntax, | |
2600 list2 | |
771 | 2601 (build_msg_string ("invalid string property list"), |
428 | 2602 XCDR (plist)))); |
2603 Fset_text_properties (beg, end, plist, tmp); | |
2604 } | |
2605 UNGCPRO; | |
2606 return tmp; | |
2607 } | |
2608 #endif /* 0 */ | |
2609 case '@': | |
2610 { | |
2611 /* #@NUMBER is used to skip NUMBER following characters. | |
2612 That's used in .elc files to skip over doc strings | |
2613 and function definitions. */ | |
2614 int i, nskip = 0; | |
2615 | |
2616 /* Read a decimal integer. */ | |
2617 while ((c = readchar (readcharfun)) >= 0 | |
2618 && c >= '0' && c <= '9') | |
2619 nskip = (10 * nskip) + (c - '0'); | |
2620 if (c >= 0) | |
2621 unreadchar (readcharfun, c); | |
2622 | |
2623 /* FSF has code here that maybe caches the skipped | |
2624 string. See above for why this is totally | |
2625 losing. We handle this differently. */ | |
2626 | |
2627 /* Skip that many characters. */ | |
2628 for (i = 0; i < nskip && c >= 0; i++) | |
2629 c = readchar (readcharfun); | |
2630 | |
2631 goto retry; | |
2632 } | |
2633 case '$': return Vload_file_name_internal; | |
2634 /* bit vectors */ | |
2635 case '*': return read_bit_vector (readcharfun); | |
2636 /* #o10 => 8 -- octal constant syntax */ | |
2637 case 'o': return read_integer (readcharfun, 8); | |
2638 /* #xdead => 57005 -- hex constant syntax */ | |
2639 case 'x': return read_integer (readcharfun, 16); | |
2640 /* #b010 => 2 -- binary constant syntax */ | |
2641 case 'b': return read_integer (readcharfun, 2); | |
3543 | 2642 /* #r"raw\stringt" -- raw string syntax */ |
2643 case 'r': return read_raw_string(readcharfun); | |
428 | 2644 /* #s(foobar key1 val1 key2 val2) -- structure syntax */ |
2645 case 's': return read_structure (readcharfun); | |
2646 case '<': | |
2647 { | |
2648 unreadchar (readcharfun, c); | |
2649 return Fsignal (Qinvalid_read_syntax, | |
771 | 2650 list1 (build_msg_string ("Cannot read unreadable object"))); |
428 | 2651 } |
2652 #ifdef FEATUREP_SYNTAX | |
2653 case '+': | |
2654 case '-': | |
2655 { | |
456 | 2656 Lisp_Object feature_exp, obj, tem; |
428 | 2657 struct gcpro gcpro1, gcpro2; |
2658 | |
456 | 2659 feature_exp = read0(readcharfun); |
428 | 2660 obj = read0(readcharfun); |
2661 | |
2662 /* the call to `featurep' may GC. */ | |
456 | 2663 GCPRO2 (feature_exp, obj); |
2664 tem = call1 (Qfeaturep, feature_exp); | |
428 | 2665 UNGCPRO; |
2666 | |
2667 if (c == '+' && NILP(tem)) goto retry; | |
2668 if (c == '-' && !NILP(tem)) goto retry; | |
2669 return obj; | |
2670 } | |
2671 #endif | |
2672 case '0': case '1': case '2': case '3': case '4': | |
2673 case '5': case '6': case '7': case '8': case '9': | |
2674 /* Reader forms that can reuse previously read objects. */ | |
2675 { | |
2676 int n = 0; | |
2677 Lisp_Object found; | |
2678 | |
2679 /* Using read_integer() here is impossible, because it | |
2680 chokes on `='. Using parse_integer() is too hard. | |
2681 So we simply read it in, and ignore overflows, which | |
2682 is safe. */ | |
2683 while (c >= '0' && c <= '9') | |
2684 { | |
2685 n *= 10; | |
2686 n += c - '0'; | |
2687 c = readchar (readcharfun); | |
2688 } | |
2689 found = assq_no_quit (make_int (n), Vread_objects); | |
2690 if (c == '=') | |
2691 { | |
2692 /* #n=object returns object, but associates it with | |
2693 n for #n#. */ | |
2694 Lisp_Object obj; | |
2695 if (CONSP (found)) | |
2696 return Fsignal (Qinvalid_read_syntax, | |
771 | 2697 list2 (build_msg_string |
428 | 2698 ("Multiply defined symbol label"), |
2699 make_int (n))); | |
2700 obj = read0 (readcharfun); | |
2701 Vread_objects = Fcons (Fcons (make_int (n), obj), | |
2702 Vread_objects); | |
2703 return obj; | |
2704 } | |
2705 else if (c == '#') | |
2706 { | |
2707 /* #n# returns a previously read object. */ | |
2708 if (CONSP (found)) | |
2709 return XCDR (found); | |
2710 else | |
2711 return Fsignal (Qinvalid_read_syntax, | |
771 | 2712 list2 (build_msg_string |
428 | 2713 ("Undefined symbol label"), |
2714 make_int (n))); | |
2715 } | |
2716 return Fsignal (Qinvalid_read_syntax, | |
2717 list1 (build_string ("#"))); | |
2718 } | |
2719 default: | |
2720 { | |
2721 unreadchar (readcharfun, c); | |
2722 return Fsignal (Qinvalid_read_syntax, | |
2723 list1 (build_string ("#"))); | |
2724 } | |
2725 } | |
2726 } | |
2727 | |
2728 /* Quote */ | |
2729 case '\'': return list2 (Qquote, read0 (readcharfun)); | |
2730 | |
2731 #ifdef LISP_BACKQUOTES | |
2732 case '`': | |
2733 { | |
2734 Lisp_Object tem; | |
853 | 2735 int speccount = internal_bind_int (&new_backquote_flag, |
2736 1 + new_backquote_flag); | |
428 | 2737 tem = read0 (readcharfun); |
771 | 2738 unbind_to (speccount); |
428 | 2739 return list2 (Qbackquote, tem); |
2740 } | |
2741 | |
2742 case ',': | |
2743 { | |
2744 if (new_backquote_flag) | |
2745 { | |
2746 Lisp_Object comma_type = Qnil; | |
2747 int ch = readchar (readcharfun); | |
2748 | |
2749 if (ch == '@') | |
2750 comma_type = Qcomma_at; | |
2751 else if (ch == '.') | |
2752 comma_type = Qcomma_dot; | |
2753 else | |
2754 { | |
2755 if (ch >= 0) | |
2756 unreadchar (readcharfun, ch); | |
2757 comma_type = Qcomma; | |
2758 } | |
2759 return list2 (comma_type, read0 (readcharfun)); | |
2760 } | |
2761 else | |
2762 { | |
2763 /* YUCK. 99.999% backwards compatibility. The Right | |
2764 Thing(tm) is to signal an error here, because it's | |
2765 really invalid read syntax. Instead, this permits | |
2766 commas to begin symbols (unless they're inside | |
2767 backquotes). If an error is signalled here in the | |
2768 future, then commas should be invalid read syntax | |
2769 outside of backquotes anywhere they're found (i.e. | |
2770 they must be quoted in symbols) -- Stig */ | |
2771 return read_atom (readcharfun, c, 0); | |
2772 } | |
2773 } | |
2774 #endif | |
2775 | |
2776 case '?': | |
2777 { | |
2778 /* Evil GNU Emacs "character" (ie integer) syntax */ | |
2779 c = readchar (readcharfun); | |
2780 if (c < 0) | |
2781 return Fsignal (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun))); | |
2782 | |
2783 if (c == '\\') | |
2784 c = read_escape (readcharfun); | |
4439 | 2785 if (c < 0) |
2786 return Fsignal (Qinvalid_read_syntax, list1 (READCHARFUN_MAYBE (readcharfun))); | |
428 | 2787 return make_char (c); |
2788 } | |
2789 | |
2790 case '\"': | |
3543 | 2791 /* String */ |
2792 return read_string(readcharfun, '\"', 0, 1); | |
428 | 2793 |
2794 default: | |
2795 { | |
2796 /* Ignore whitespace and control characters */ | |
2797 if (c <= 040) | |
2798 goto retry; | |
2799 return read_atom (readcharfun, c, 0); | |
2800 } | |
2801 } | |
2802 } | |
2803 | |
2804 | |
2805 | |
2806 #define LEAD_INT 1 | |
2807 #define DOT_CHAR 2 | |
2808 #define TRAIL_INT 4 | |
2809 #define E_CHAR 8 | |
2810 #define EXP_INT 16 | |
2811 | |
2812 int | |
442 | 2813 isfloat_string (const char *cp) |
428 | 2814 { |
2815 int state = 0; | |
867 | 2816 const Ibyte *ucp = (const Ibyte *) cp; |
428 | 2817 |
2818 if (*ucp == '+' || *ucp == '-') | |
2819 ucp++; | |
2820 | |
2821 if (*ucp >= '0' && *ucp <= '9') | |
2822 { | |
2823 state |= LEAD_INT; | |
2824 while (*ucp >= '0' && *ucp <= '9') | |
2825 ucp++; | |
2826 } | |
2827 if (*ucp == '.') | |
2828 { | |
2829 state |= DOT_CHAR; | |
2830 ucp++; | |
2831 } | |
2832 if (*ucp >= '0' && *ucp <= '9') | |
2833 { | |
2834 state |= TRAIL_INT; | |
2835 while (*ucp >= '0' && *ucp <= '9') | |
2836 ucp++; | |
2837 } | |
2838 if (*ucp == 'e' || *ucp == 'E') | |
2839 { | |
2840 state |= E_CHAR; | |
2841 ucp++; | |
2842 if ((*ucp == '+') || (*ucp == '-')) | |
2843 ucp++; | |
2844 } | |
2845 | |
2846 if (*ucp >= '0' && *ucp <= '9') | |
2847 { | |
2848 state |= EXP_INT; | |
2849 while (*ucp >= '0' && *ucp <= '9') | |
2850 ucp++; | |
2851 } | |
2852 return (((*ucp == 0) || (*ucp == ' ') || (*ucp == '\t') || (*ucp == '\n') | |
2853 || (*ucp == '\r') || (*ucp == '\f')) | |
2854 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT) | |
2855 || state == (DOT_CHAR|TRAIL_INT) | |
2856 || state == (LEAD_INT|E_CHAR|EXP_INT) | |
2857 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT) | |
2858 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT))); | |
2859 } | |
1983 | 2860 |
2861 #ifdef HAVE_RATIO | |
2862 int | |
2863 isratio_string (const char *cp) | |
2864 { | |
2010 | 2865 /* Possible minus/plus sign */ |
2866 if (*cp == '-' || *cp == '+') | |
1983 | 2867 cp++; |
2868 | |
2869 /* Numerator */ | |
2870 if (*cp < '0' || *cp > '9') | |
2871 return 0; | |
2872 | |
2873 do { | |
2874 cp++; | |
2875 } while (*cp >= '0' && *cp <= '9'); | |
2876 | |
2877 /* Slash */ | |
2878 if (*cp++ != '/') | |
2879 return 0; | |
2880 | |
2881 /* Denominator */ | |
2882 if (*cp < '0' || *cp > '9') | |
2883 return 0; | |
2884 | |
2885 do { | |
2886 cp++; | |
2887 } while (*cp >= '0' && *cp <= '9'); | |
2888 | |
2889 return *cp == '\0' || *cp == ' ' || *cp =='\t' || *cp == '\n' || | |
2890 *cp == '\r' || *cp == '\f'; | |
2891 } | |
2892 #endif | |
428 | 2893 |
2894 static void * | |
2895 sequence_reader (Lisp_Object readcharfun, | |
867 | 2896 Ichar terminator, |
428 | 2897 void *state, |
2898 void * (*conser) (Lisp_Object readcharfun, | |
2899 void *state, Charcount len)) | |
2900 { | |
2901 Charcount len; | |
2902 | |
2903 for (len = 0; ; len++) | |
2904 { | |
867 | 2905 Ichar ch; |
428 | 2906 |
2907 QUIT; | |
2908 ch = reader_nextchar (readcharfun); | |
2909 | |
2910 if (ch == terminator) | |
2911 return state; | |
2912 else | |
2913 unreadchar (readcharfun, ch); | |
2914 #ifdef FEATUREP_SYNTAX | |
2915 if (ch == ']') | |
442 | 2916 read_syntax_error ("\"]\" in a list"); |
428 | 2917 else if (ch == ')') |
442 | 2918 read_syntax_error ("\")\" in a vector"); |
428 | 2919 #endif |
2920 state = ((conser) (readcharfun, state, len)); | |
2921 } | |
2922 } | |
2923 | |
2924 | |
2925 struct read_list_state | |
2926 { | |
2927 Lisp_Object head; | |
2928 Lisp_Object tail; | |
2929 int length; | |
2930 int allow_dotted_lists; | |
867 | 2931 Ichar terminator; |
428 | 2932 }; |
2933 | |
2934 static void * | |
2286 | 2935 read_list_conser (Lisp_Object readcharfun, void *state, Charcount UNUSED (len)) |
428 | 2936 { |
2937 struct read_list_state *s = (struct read_list_state *) state; | |
2938 Lisp_Object elt; | |
2939 | |
2940 elt = read1 (readcharfun); | |
2941 | |
2942 if (CONSP (elt) && UNBOUNDP (XCAR (elt))) | |
2943 { | |
2944 Lisp_Object tem = elt; | |
867 | 2945 Ichar ch; |
428 | 2946 |
2947 elt = XCDR (elt); | |
853 | 2948 free_cons (tem); |
428 | 2949 tem = Qnil; |
2950 ch = XCHAR (elt); | |
2951 #ifdef FEATUREP_SYNTAX | |
2952 if (ch == s->terminator) /* deal with #+, #- reader macros */ | |
2953 { | |
2954 unreadchar (readcharfun, s->terminator); | |
2955 goto done; | |
2956 } | |
2957 else if (ch == ']') | |
442 | 2958 read_syntax_error ("']' in a list"); |
428 | 2959 else if (ch == ')') |
442 | 2960 read_syntax_error ("')' in a vector"); |
428 | 2961 else |
2962 #endif | |
2963 if (ch != '.') | |
563 | 2964 signal_error (Qinternal_error, "BUG! Internal reader error", elt); |
428 | 2965 else if (!s->allow_dotted_lists) |
442 | 2966 read_syntax_error ("\".\" in a vector"); |
428 | 2967 else |
2968 { | |
2969 if (!NILP (s->tail)) | |
2970 XCDR (s->tail) = read0 (readcharfun); | |
2971 else | |
2972 s->head = read0 (readcharfun); | |
2973 elt = read1 (readcharfun); | |
2974 if (CONSP (elt) && UNBOUNDP (XCAR (elt))) | |
2975 { | |
2976 ch = XCHAR (XCDR (elt)); | |
853 | 2977 free_cons (elt); |
428 | 2978 if (ch == s->terminator) |
2979 { | |
2980 unreadchar (readcharfun, s->terminator); | |
2981 goto done; | |
2982 } | |
2983 } | |
442 | 2984 read_syntax_error (". in wrong context"); |
428 | 2985 } |
2986 } | |
2987 | |
2988 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
2989 if (s->length == 1 && s->allow_dotted_lists && EQ (XCAR (s->head), Qfset)) | |
2990 { | |
2991 if (CONSP (elt) && EQ (XCAR (elt), Qquote) && CONSP (XCDR (elt))) | |
2992 Vcurrent_compiled_function_annotation = XCAR (XCDR (elt)); | |
2993 else | |
2994 Vcurrent_compiled_function_annotation = elt; | |
2995 } | |
2996 #endif | |
2997 | |
2998 elt = Fcons (elt, Qnil); | |
2999 if (!NILP (s->tail)) | |
3000 XCDR (s->tail) = elt; | |
3001 else | |
3002 s->head = elt; | |
3003 s->tail = elt; | |
3004 done: | |
3005 s->length++; | |
3006 return s; | |
3007 } | |
3008 | |
3009 | |
814 | 3010 /* allow_dotted_lists means that something like (foo bar . baz) |
3011 is acceptable. If -1, means check for starting with defun | |
3012 and make structure pure. (not implemented, probably for very | |
3013 good reasons) | |
3014 | |
3015 If check_for_doc_references, look for (#$ . INT) doc references | |
3016 in the list and record if load_force_doc_strings is non-zero. | |
3017 (Such doc references will be destroyed during the loadup phase | |
3018 by replacing with Qzero, because Snarf-documentation will fill | |
3019 them in again.) | |
3020 | |
3021 WARNING: If you set this, you sure as hell better not call | |
3022 free_list() on the returned list here. | |
3023 */ | |
428 | 3024 |
3025 static Lisp_Object | |
3026 read_list (Lisp_Object readcharfun, | |
867 | 3027 Ichar terminator, |
428 | 3028 int allow_dotted_lists, |
3029 int check_for_doc_references) | |
3030 { | |
3031 struct read_list_state s; | |
3032 struct gcpro gcpro1, gcpro2; | |
3033 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
3034 Lisp_Object old_compiled_function_annotation = | |
3035 Vcurrent_compiled_function_annotation; | |
3036 #endif | |
3037 | |
3038 s.head = Qnil; | |
3039 s.tail = Qnil; | |
3040 s.length = 0; | |
3041 s.allow_dotted_lists = allow_dotted_lists; | |
3042 s.terminator = terminator; | |
3043 GCPRO2 (s.head, s.tail); | |
3044 | |
3045 sequence_reader (readcharfun, terminator, &s, read_list_conser); | |
3046 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
3047 Vcurrent_compiled_function_annotation = old_compiled_function_annotation; | |
3048 #endif | |
3049 | |
3050 if ((purify_flag || load_force_doc_strings) && check_for_doc_references) | |
3051 { | |
3052 /* check now for any doc string references and record them | |
3053 for later. */ | |
3054 Lisp_Object tail; | |
3055 | |
3056 /* We might be dealing with an imperfect list so don't | |
3057 use LIST_LOOP */ | |
3058 for (tail = s.head; CONSP (tail); tail = XCDR (tail)) | |
3059 { | |
3060 Lisp_Object holding_cons = Qnil; | |
3061 | |
3062 { | |
3063 Lisp_Object elem = XCAR (tail); | |
3064 /* elem might be (#$ . INT) ... */ | |
3065 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal)) | |
3066 holding_cons = tail; | |
3067 /* or it might be (quote (#$ . INT)) i.e. | |
3068 (quote . ((#$ . INT) . nil)) in the case of | |
3069 `autoload' (autoload evaluates its arguments, while | |
3070 `defvar', `defun', etc. don't). */ | |
3071 if (CONSP (elem) && EQ (XCAR (elem), Qquote) | |
3072 && CONSP (XCDR (elem))) | |
3073 { | |
3074 elem = XCAR (XCDR (elem)); | |
3075 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal)) | |
3076 holding_cons = XCDR (XCAR (tail)); | |
3077 } | |
3078 } | |
3079 | |
3080 if (CONSP (holding_cons)) | |
3081 { | |
3082 if (purify_flag) | |
3083 { | |
3084 if (NILP (Vinternal_doc_file_name)) | |
3085 /* We have not yet called Snarf-documentation, so | |
3086 assume this file is described in the DOC file | |
3087 and Snarf-documentation will fill in the right | |
3088 value later. For now, replace the whole list | |
3089 with 0. */ | |
3090 XCAR (holding_cons) = Qzero; | |
3091 else | |
3092 /* We have already called Snarf-documentation, so | |
3093 make a relative file name for this file, so it | |
3094 can be found properly in the installed Lisp | |
3095 directory. We don't use Fexpand_file_name | |
3096 because that would make the directory absolute | |
3097 now. */ | |
3098 XCAR (XCAR (holding_cons)) = | |
3099 concat2 (build_string ("../lisp/"), | |
3100 Ffile_name_nondirectory | |
3101 (Vload_file_name_internal)); | |
3102 } | |
3103 else | |
3104 /* Not pure. Just add to Vload_force_doc_string_list, | |
3105 and the string will be filled in properly in | |
3106 load_force_doc_string_unwind(). */ | |
3107 Vload_force_doc_string_list = | |
3108 /* We pass the cons that holds the (#$ . INT) so we | |
3109 can modify it in-place. */ | |
3110 Fcons (holding_cons, Vload_force_doc_string_list); | |
3111 } | |
3112 } | |
3113 } | |
3114 | |
3115 UNGCPRO; | |
3116 return s.head; | |
3117 } | |
3118 | |
3119 static Lisp_Object | |
3120 read_vector (Lisp_Object readcharfun, | |
867 | 3121 Ichar terminator) |
428 | 3122 { |
3123 Lisp_Object tem; | |
3124 Lisp_Object *p; | |
3125 int len; | |
3126 int i; | |
3127 struct read_list_state s; | |
3128 struct gcpro gcpro1, gcpro2; | |
3129 | |
3130 s.head = Qnil; | |
3131 s.tail = Qnil; | |
3132 s.length = 0; | |
3133 s.allow_dotted_lists = 0; | |
3134 GCPRO2 (s.head, s.tail); | |
3135 | |
3136 sequence_reader (readcharfun, terminator, &s, read_list_conser); | |
3137 | |
3138 UNGCPRO; | |
3139 tem = s.head; | |
3140 len = XINT (Flength (tem)); | |
3141 | |
814 | 3142 s.head = make_vector (len, Qnil); |
428 | 3143 |
3144 for (i = 0, p = &(XVECTOR_DATA (s.head)[0]); | |
3145 i < len; | |
3146 i++, p++) | |
3147 { | |
853 | 3148 Lisp_Object otem = tem; |
428 | 3149 tem = Fcar (tem); |
3150 *p = tem; | |
853 | 3151 tem = XCDR (otem); |
428 | 3152 free_cons (otem); |
3153 } | |
3154 return s.head; | |
3155 } | |
3156 | |
3157 static Lisp_Object | |
867 | 3158 read_compiled_function (Lisp_Object readcharfun, Ichar terminator) |
428 | 3159 { |
3160 /* Accept compiled functions at read-time so that we don't | |
3161 have to build them at load-time. */ | |
3162 Lisp_Object stuff; | |
3163 Lisp_Object make_byte_code_args[COMPILED_DOMAIN + 1]; | |
3164 struct gcpro gcpro1; | |
3165 int len; | |
3166 int iii; | |
3167 int saw_a_doc_ref = 0; | |
3168 | |
3169 /* Note: we tell read_list not to search for doc references | |
3170 because we need to handle the "doc reference" for the | |
3171 instructions and constants differently. */ | |
3172 stuff = read_list (readcharfun, terminator, 0, 0); | |
3173 len = XINT (Flength (stuff)); | |
3174 if (len < COMPILED_STACK_DEPTH + 1 || len > COMPILED_DOMAIN + 1) | |
3175 return | |
442 | 3176 continuable_read_syntax_error ("#[...] used with wrong number of elements"); |
428 | 3177 |
3178 for (iii = 0; CONSP (stuff); iii++) | |
3179 { | |
853 | 3180 Lisp_Object victim = stuff; |
428 | 3181 make_byte_code_args[iii] = Fcar (stuff); |
3182 if ((purify_flag || load_force_doc_strings) | |
3183 && CONSP (make_byte_code_args[iii]) | |
3184 && EQ (XCAR (make_byte_code_args[iii]), Vload_file_name_internal)) | |
3185 { | |
3186 if (purify_flag && iii == COMPILED_DOC_STRING) | |
3187 { | |
3188 /* same as in read_list(). */ | |
3189 if (NILP (Vinternal_doc_file_name)) | |
3190 make_byte_code_args[iii] = Qzero; | |
3191 else | |
3192 XCAR (make_byte_code_args[iii]) = | |
3193 concat2 (build_string ("../lisp/"), | |
3194 Ffile_name_nondirectory | |
3195 (Vload_file_name_internal)); | |
3196 } | |
3197 else | |
3198 saw_a_doc_ref = 1; | |
3199 } | |
3200 stuff = Fcdr (stuff); | |
3201 free_cons (victim); | |
3202 } | |
3203 GCPRO1 (make_byte_code_args[0]); | |
3204 gcpro1.nvars = len; | |
3205 | |
3206 /* v18 or v19 bytecode file. Need to Ebolify. */ | |
3207 if (load_byte_code_version < 20 && VECTORP (make_byte_code_args[2])) | |
3208 ebolify_bytecode_constants (make_byte_code_args[2]); | |
3209 | |
3210 /* make-byte-code looks at purify_flag, which should have the same | |
3211 * value as our "read-pure" argument */ | |
3212 stuff = Fmake_byte_code (len, make_byte_code_args); | |
3213 XCOMPILED_FUNCTION (stuff)->flags.ebolified = (load_byte_code_version < 20); | |
3214 if (saw_a_doc_ref) | |
3215 Vload_force_doc_string_list = Fcons (stuff, Vload_force_doc_string_list); | |
3216 UNGCPRO; | |
3217 return stuff; | |
3218 } | |
3219 | |
3220 | |
3221 | |
3222 void | |
3223 init_lread (void) | |
3224 { | |
3225 Vvalues = Qnil; | |
3226 | |
3227 load_in_progress = 0; | |
3228 | |
3229 Vload_descriptor_list = Qnil; | |
3230 | |
3231 /* kludge: locate-file does not work for a null load-path, even if | |
3232 the file name is absolute. */ | |
3233 | |
3234 Vload_path = Fcons (build_string (""), Qnil); | |
3235 | |
3236 /* This used to get initialized in init_lread because all streams | |
3237 got closed when dumping occurs. This is no longer true -- | |
3238 Vread_buffer_stream is a resizing output stream, and there is no | |
3239 reason to close it at dump-time. | |
3240 | |
3241 Vread_buffer_stream is set to Qnil in vars_of_lread, and this | |
3242 will initialize it only once, at dump-time. */ | |
3243 if (NILP (Vread_buffer_stream)) | |
3244 Vread_buffer_stream = make_resizing_buffer_output_stream (); | |
3245 | |
3246 Vload_force_doc_string_list = Qnil; | |
3247 } | |
3248 | |
3249 void | |
3250 syms_of_lread (void) | |
3251 { | |
3252 DEFSUBR (Fread); | |
3253 DEFSUBR (Fread_from_string); | |
3254 DEFSUBR (Fload_internal); | |
3255 DEFSUBR (Flocate_file); | |
3256 DEFSUBR (Flocate_file_clear_hashing); | |
3257 DEFSUBR (Feval_buffer); | |
3258 DEFSUBR (Feval_region); | |
3259 | |
563 | 3260 DEFSYMBOL (Qstandard_input); |
3261 DEFSYMBOL (Qread_char); | |
3262 DEFSYMBOL (Qload); | |
1292 | 3263 DEFSYMBOL (Qload_internal); |
563 | 3264 DEFSYMBOL (Qfset); |
428 | 3265 |
3266 #ifdef LISP_BACKQUOTES | |
563 | 3267 DEFSYMBOL (Qbackquote); |
428 | 3268 defsymbol (&Qbacktick, "`"); |
3269 defsymbol (&Qcomma, ","); | |
3270 defsymbol (&Qcomma_at, ",@"); | |
3271 defsymbol (&Qcomma_dot, ",."); | |
3272 #endif | |
3273 | |
563 | 3274 DEFSYMBOL (Qexists); |
3275 DEFSYMBOL (Qreadable); | |
3276 DEFSYMBOL (Qwritable); | |
3277 DEFSYMBOL (Qexecutable); | |
428 | 3278 } |
3279 | |
3280 void | |
3281 structure_type_create (void) | |
3282 { | |
3283 the_structure_type_dynarr = Dynarr_new (structure_type); | |
3284 } | |
3285 | |
3286 void | |
3287 reinit_vars_of_lread (void) | |
3288 { | |
3289 Vread_buffer_stream = Qnil; | |
3290 staticpro_nodump (&Vread_buffer_stream); | |
3291 } | |
3292 | |
3293 void | |
3294 vars_of_lread (void) | |
3295 { | |
3296 DEFVAR_LISP ("values", &Vvalues /* | |
3297 List of values of all expressions which were read, evaluated and printed. | |
3298 Order is reverse chronological. | |
3299 */ ); | |
3300 | |
3301 DEFVAR_LISP ("standard-input", &Vstandard_input /* | |
3302 Stream for read to get input from. | |
3303 See documentation of `read' for possible values. | |
3304 */ ); | |
3305 Vstandard_input = Qt; | |
3306 | |
3307 DEFVAR_LISP ("load-path", &Vload_path /* | |
3308 *List of directories to search for files to load. | |
3309 Each element is a string (directory name) or nil (try default directory). | |
3310 | |
3311 Note that the elements of this list *may not* begin with "~", so you must | |
3312 call `expand-file-name' on them before adding them to this list. | |
3313 | |
3314 Initialized based on EMACSLOADPATH environment variable, if any, | |
3315 otherwise to default specified in by file `paths.h' when XEmacs was built. | |
3316 If there were no paths specified in `paths.h', then XEmacs chooses a default | |
3317 value for this variable by looking around in the file-system near the | |
3318 directory in which the XEmacs executable resides. | |
3319 */ ); | |
3320 Vload_path = Qnil; | |
3321 | |
3322 /* xxxDEFVAR_LISP ("dump-load-path", &Vdump_load_path, | |
3323 "*Location of lisp files to be used when dumping ONLY."); */ | |
3324 | |
3325 DEFVAR_BOOL ("load-in-progress", &load_in_progress /* | |
3326 Non-nil iff inside of `load'. | |
3327 */ ); | |
3328 | |
2548 | 3329 DEFVAR_LISP ("load-suppress-alist", &Vload_suppress_alist /* |
3330 An alist of expressions controlling whether particular files can be loaded. | |
3331 Each element looks like (FILENAME EXPR). | |
3332 FILENAME should be a full pathname, but without the .el suffix. | |
3333 When `load' is run and is about to load the specified file, it evaluates | |
3334 the form to determine if the file can be loaded. | |
3335 This variable is normally initialized automatically. | |
3336 */ ); | |
3337 Vload_suppress_alist = Qnil; | |
3338 | |
428 | 3339 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist /* |
3340 An alist of expressions to be evalled when particular files are loaded. | |
3341 Each element looks like (FILENAME FORMS...). | |
3342 When `load' is run and the file-name argument is FILENAME, | |
3343 the FORMS in the corresponding element are executed at the end of loading. | |
3344 | |
3345 FILENAME must match exactly! Normally FILENAME is the name of a library, | |
3346 with no directory specified, since that is how `load' is normally called. | |
3347 An error in FORMS does not undo the load, | |
3348 but does prevent execution of the rest of the FORMS. | |
3349 */ ); | |
3350 Vafter_load_alist = Qnil; | |
3351 | |
3352 DEFVAR_BOOL ("load-warn-when-source-newer", &load_warn_when_source_newer /* | |
3353 *Whether `load' should check whether the source is newer than the binary. | |
3354 If this variable is true, then when a `.elc' file is being loaded and the | |
3355 corresponding `.el' is newer, a warning message will be printed. | |
3356 */ ); | |
1261 | 3357 load_warn_when_source_newer = 1; |
428 | 3358 |
3359 DEFVAR_BOOL ("load-warn-when-source-only", &load_warn_when_source_only /* | |
3360 *Whether `load' should warn when loading a `.el' file instead of an `.elc'. | |
3361 If this variable is true, then when `load' is called with a filename without | |
3362 an extension, and the `.elc' version doesn't exist but the `.el' version does, | |
3363 then a message will be printed. If an explicit extension is passed to `load', | |
3364 no warning will be printed. | |
3365 */ ); | |
3366 load_warn_when_source_only = 0; | |
3367 | |
3368 DEFVAR_BOOL ("load-ignore-elc-files", &load_ignore_elc_files /* | |
3369 *Whether `load' should ignore `.elc' files when a suffix is not given. | |
3370 This is normally used only to bootstrap the `.elc' files when building XEmacs. | |
3371 */ ); | |
3372 load_ignore_elc_files = 0; | |
3373 | |
1123 | 3374 DEFVAR_BOOL ("load-ignore-out-of-date-elc-files", |
3375 &load_ignore_out_of_date_elc_files /* | |
3376 *Whether `load' should ignore out-of-date `.elc' files when no suffix is given. | |
3377 This is normally used when compiling packages of elisp files that may have | |
3378 complex dependencies. Ignoring all elc files with `load-ignore-elc-files' | |
3379 would also be safe, but much slower. | |
3380 */ ); | |
3381 load_ignore_out_of_date_elc_files = 0; | |
3382 | |
3383 DEFVAR_BOOL ("load-always-display-messages", | |
3384 &load_always_display_messages /* | |
3385 *Whether `load' should always display loading messages. | |
3386 If this is true, every file loaded will be shown, regardless of the setting | |
3387 of the NOMESSAGE parameter, and even when files are loaded indirectly, e.g. | |
2857 | 3388 due to `require'. |
1123 | 3389 */ ); |
3390 load_always_display_messages = 0; | |
3391 | |
3392 DEFVAR_BOOL ("load-show-full-path-in-messages", | |
3393 &load_show_full_path_in_messages /* | |
3394 *Whether `load' should show the full path in all loading messages. | |
3395 */ ); | |
3396 load_show_full_path_in_messages = 0; | |
3397 | |
428 | 3398 #ifdef LOADHIST |
3399 DEFVAR_LISP ("load-history", &Vload_history /* | |
3400 Alist mapping source file names to symbols and features. | |
3401 Each alist element is a list that starts with a file name, | |
3402 except for one element (optional) that starts with nil and describes | |
3403 definitions evaluated from buffers not visiting files. | |
3404 The remaining elements of each list are symbols defined as functions | |
3405 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'. | |
3406 */ ); | |
3407 Vload_history = Qnil; | |
3408 | |
3409 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list /* | |
3410 Used for internal purposes by `load'. | |
3411 */ ); | |
3412 Vcurrent_load_list = Qnil; | |
3413 #endif | |
3414 | |
3415 DEFVAR_LISP ("load-file-name", &Vload_file_name /* | |
3416 Full name of file being loaded by `load'. | |
3417 */ ); | |
3418 Vload_file_name = Qnil; | |
3419 | |
3420 DEFVAR_LISP ("load-read-function", &Vload_read_function /* | |
3421 Function used by `load' and `eval-region' for reading expressions. | |
3422 The default is nil, which means use the function `read'. | |
3423 */ ); | |
3424 Vload_read_function = Qnil; | |
3425 | |
3426 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings /* | |
3427 Non-nil means `load' should force-load all dynamic doc strings. | |
3428 This is useful when the file being loaded is a temporary copy. | |
3429 */ ); | |
3430 load_force_doc_strings = 0; | |
3431 | |
3432 /* See read_escape(). */ | |
3433 #if 0 | |
3434 /* Used to be named `puke-on-fsf-keys' */ | |
3435 DEFVAR_BOOL ("fail-on-bucky-bit-character-escapes", | |
3436 &fail_on_bucky_bit_character_escapes /* | |
3437 Whether `read' should signal an error when it encounters unsupported | |
3438 character escape syntaxes or just read them incorrectly. | |
3439 */ ); | |
3440 fail_on_bucky_bit_character_escapes = 0; | |
3441 #endif | |
3442 | |
3443 /* This must be initialized in init_lread otherwise it may start out | |
3444 with values saved when the image is dumped. */ | |
3445 staticpro (&Vload_descriptor_list); | |
3446 | |
3447 /* Initialized in init_lread. */ | |
3448 staticpro (&Vload_force_doc_string_list); | |
3449 | |
3450 Vload_file_name_internal = Qnil; | |
3451 staticpro (&Vload_file_name_internal); | |
3452 | |
3453 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
3454 Vcurrent_compiled_function_annotation = Qnil; | |
3455 staticpro (&Vcurrent_compiled_function_annotation); | |
3456 #endif | |
3457 | |
3458 /* So that early-early stuff will work */ | |
1292 | 3459 Ffset (Qload, Qload_internal); |
428 | 3460 |
3461 #ifdef FEATUREP_SYNTAX | |
563 | 3462 DEFSYMBOL (Qfeaturep); |
771 | 3463 Fprovide (intern ("xemacs")); |
428 | 3464 #ifdef INFODOCK |
771 | 3465 Fprovide (intern ("infodock")); |
428 | 3466 #endif /* INFODOCK */ |
3467 #endif /* FEATUREP_SYNTAX */ | |
3468 | |
3469 #ifdef LISP_BACKQUOTES | |
3470 old_backquote_flag = new_backquote_flag = 0; | |
3471 #endif | |
3472 | |
3473 #ifdef I18N3 | |
3474 Vfile_domain = Qnil; | |
3475 #endif | |
3476 | |
3477 Vread_objects = Qnil; | |
3478 staticpro (&Vread_objects); | |
3479 | |
3480 Vlocate_file_hash_table = make_lisp_hash_table (200, | |
3481 HASH_TABLE_NON_WEAK, | |
3482 HASH_TABLE_EQUAL); | |
3483 staticpro (&Vlocate_file_hash_table); | |
3484 #ifdef DEBUG_XEMACS | |
3485 symbol_value (XSYMBOL (intern ("Vlocate-file-hash-table"))) | |
3486 = Vlocate_file_hash_table; | |
3487 #endif | |
3488 } |