Mercurial > hg > xemacs-beta
annotate src/lread.c @ 4517:5e8f6469169f
Fix up initial condition for skip-chars test.
author | Stephen J. Turnbull <stephen@xemacs.org> |
---|---|
date | Sat, 27 Sep 2008 16:34:40 +0900 |
parents | 7869173584fc |
children | 1e3cf11fa27d |
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 } | |
4483
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1858 |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1859 if (count == 3) |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1860 { |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1861 c = readchar (readcharfun); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1862 if ((c >= '0' && c <= '9') || |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1863 (c >= 'a' && c <= 'f') || |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1864 (c >= 'A' && c <= 'F')) |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1865 { |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1866 Lisp_Object args[2]; |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1867 |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1868 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1869 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1870 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1871 |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1872 args[0] = build_string ("?\\x%x"); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1873 args[1] = make_int (i); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1874 syntax_error ("Overlong hex character escape", |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1875 Fformat (2, args)); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1876 } |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1877 unreadchar (readcharfun, c); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1878 } |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1879 |
428 | 1880 return i; |
1881 } | |
3367 | 1882 case 'U': |
1883 /* Post-Unicode-2.0: Up to eight hex chars */ | |
3543 | 1884 return read_unicode_escape(readcharfun, 8); |
3367 | 1885 case 'u': |
3543 | 1886 /* Unicode-2.0 and before; four hex chars. */ |
1887 return read_unicode_escape(readcharfun, 4); | |
428 | 1888 |
1889 default: | |
1890 return c; | |
1891 } | |
1892 } | |
1893 | |
1894 | |
1895 | |
1896 /* read symbol-constituent stuff into `Vread_buffer_stream'. */ | |
1897 static Bytecount | |
867 | 1898 read_atom_0 (Lisp_Object readcharfun, Ichar firstchar, int *saw_a_backslash) |
428 | 1899 { |
1900 /* This function can GC */ | |
867 | 1901 Ichar c = ((firstchar) >= 0 ? firstchar : readchar (readcharfun)); |
428 | 1902 Lstream_rewind (XLSTREAM (Vread_buffer_stream)); |
1903 | |
1904 *saw_a_backslash = 0; | |
1905 | |
1906 while (c > 040 /* #### - comma should be here as should backquote */ | |
1907 && !(c == '\"' || c == '\'' || c == ';' | |
1908 || c == '(' || c == ')' | |
1909 || c == '[' || c == ']' || c == '#' | |
1910 )) | |
1911 { | |
1912 if (c == '\\') | |
1913 { | |
1914 c = readchar (readcharfun); | |
1915 if (c < 0) | |
563 | 1916 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1917 *saw_a_backslash = 1; |
1918 } | |
867 | 1919 Lstream_put_ichar (XLSTREAM (Vread_buffer_stream), c); |
428 | 1920 QUIT; |
1921 c = readchar (readcharfun); | |
1922 } | |
1923 | |
1924 if (c >= 0) | |
1925 unreadchar (readcharfun, c); | |
1926 /* blasted terminating 0 */ | |
867 | 1927 Lstream_put_ichar (XLSTREAM (Vread_buffer_stream), 0); |
428 | 1928 Lstream_flush (XLSTREAM (Vread_buffer_stream)); |
1929 | |
1930 return Lstream_byte_count (XLSTREAM (Vread_buffer_stream)) - 1; | |
1931 } | |
1932 | |
867 | 1933 static Lisp_Object parse_integer (const Ibyte *buf, Bytecount len, int base); |
428 | 1934 |
1935 static Lisp_Object | |
1936 read_atom (Lisp_Object readcharfun, | |
867 | 1937 Ichar firstchar, |
428 | 1938 int uninterned_symbol) |
1939 { | |
1940 /* This function can GC */ | |
1941 int saw_a_backslash; | |
1942 Bytecount len = read_atom_0 (readcharfun, firstchar, &saw_a_backslash); | |
1943 char *read_ptr = (char *) | |
1944 resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)); | |
1945 | |
1946 /* Is it an integer? */ | |
1947 if (! (saw_a_backslash || uninterned_symbol)) | |
1948 { | |
1949 /* If a token had any backslashes in it, it is disqualified from | |
1950 being an integer or a float. This means that 123\456 is a | |
1951 symbol, as is \123 (which is the way (intern "123") prints). | |
1952 Also, if token was preceded by #:, it's always a symbol. | |
1953 */ | |
1954 char *p = read_ptr + len; | |
1955 char *p1 = read_ptr; | |
1956 | |
1957 if (*p1 == '+' || *p1 == '-') p1++; | |
1958 if (p1 != p) | |
1959 { | |
1960 int c; | |
1961 | |
1962 while (p1 != p && (c = *p1) >= '0' && c <= '9') | |
1963 p1++; | |
1964 /* Integers can have trailing decimal points. */ | |
1965 if (p1 > read_ptr && p1 < p && *p1 == '.') | |
1966 p1++; | |
1967 if (p1 == p) | |
1968 { | |
1969 /* It is an integer. */ | |
1970 if (p1[-1] == '.') | |
1971 p1[-1] = '\0'; | |
1972 #if 0 | |
1973 { | |
1974 int number = 0; | |
1975 if (sizeof (int) == sizeof (EMACS_INT)) | |
1976 number = atoi (read_buffer); | |
1977 else if (sizeof (long) == sizeof (EMACS_INT)) | |
1978 number = atol (read_buffer); | |
1979 else | |
2500 | 1980 ABORT (); |
428 | 1981 return make_int (number); |
1982 } | |
1983 #else | |
867 | 1984 return parse_integer ((Ibyte *) read_ptr, len, 10); |
428 | 1985 #endif |
1986 } | |
1987 } | |
1983 | 1988 #ifdef HAVE_RATIO |
1989 if (isratio_string (read_ptr)) | |
1990 { | |
2013 | 1991 /* GMP ratio_set_string has no effect with initial + sign */ |
2010 | 1992 if (*read_ptr == '+') |
1993 read_ptr++; | |
1983 | 1994 ratio_set_string (scratch_ratio, read_ptr, 0); |
1995 ratio_canonicalize (scratch_ratio); | |
1996 return Fcanonicalize_number (make_ratio_rt (scratch_ratio)); | |
1997 } | |
1998 #endif | |
428 | 1999 if (isfloat_string (read_ptr)) |
2000 return make_float (atof (read_ptr)); | |
2001 } | |
2002 | |
2003 { | |
2004 Lisp_Object sym; | |
2005 if (uninterned_symbol) | |
867 | 2006 sym = Fmake_symbol ( make_string ((Ibyte *) read_ptr, len)); |
428 | 2007 else |
2008 { | |
867 | 2009 Lisp_Object name = make_string ((Ibyte *) read_ptr, len); |
428 | 2010 sym = Fintern (name, Qnil); |
2011 } | |
2012 return sym; | |
2013 } | |
2014 } | |
2015 | |
2016 | |
2017 static Lisp_Object | |
867 | 2018 parse_integer (const Ibyte *buf, Bytecount len, int base) |
428 | 2019 { |
867 | 2020 const Ibyte *lim = buf + len; |
2021 const Ibyte *p = buf; | |
428 | 2022 EMACS_UINT num = 0; |
2023 int negativland = 0; | |
2024 | |
2025 if (*p == '-') | |
2026 { | |
2027 negativland = 1; | |
2028 p++; | |
2029 } | |
2030 else if (*p == '+') | |
2031 { | |
2032 p++; | |
2033 } | |
2034 | |
2035 if (p == lim) | |
2036 goto loser; | |
2037 | |
2038 for (; (p < lim) && (*p != '\0'); p++) | |
2039 { | |
2040 int c = *p; | |
2041 EMACS_UINT onum; | |
2042 | |
2043 if (isdigit (c)) | |
2044 c = c - '0'; | |
2045 else if (isupper (c)) | |
2046 c = c - 'A' + 10; | |
2047 else if (islower (c)) | |
2048 c = c - 'a' + 10; | |
2049 else | |
2050 goto loser; | |
2051 | |
2052 if (c < 0 || c >= base) | |
2053 goto loser; | |
2054 | |
2055 onum = num; | |
2056 num = num * base + c; | |
2057 if (num < onum) | |
2058 goto overflow; | |
2059 } | |
2060 | |
2061 { | |
2062 EMACS_INT int_result = negativland ? - (EMACS_INT) num : (EMACS_INT) num; | |
2063 Lisp_Object result = make_int (int_result); | |
2064 if (num && ((XINT (result) < 0) != negativland)) | |
2065 goto overflow; | |
2066 if (XINT (result) != int_result) | |
2067 goto overflow; | |
2068 return result; | |
2069 } | |
2070 overflow: | |
1983 | 2071 #ifdef HAVE_BIGNUM |
2072 { | |
4329
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4268
diff
changeset
|
2073 bignum_set_string (scratch_bignum, (const char *) buf, base); |
1983 | 2074 return make_bignum_bg (scratch_bignum); |
2075 } | |
2076 #else | |
428 | 2077 return Fsignal (Qinvalid_read_syntax, |
771 | 2078 list3 (build_msg_string |
428 | 2079 ("Integer constant overflow in reader"), |
2080 make_string (buf, len), | |
2081 make_int (base))); | |
1983 | 2082 #endif /* HAVE_BIGNUM */ |
428 | 2083 loser: |
2084 return Fsignal (Qinvalid_read_syntax, | |
771 | 2085 list3 (build_msg_string |
428 | 2086 ("Invalid integer constant in reader"), |
2087 make_string (buf, len), | |
2088 make_int (base))); | |
2089 } | |
2090 | |
2091 | |
2092 static Lisp_Object | |
2093 read_integer (Lisp_Object readcharfun, int base) | |
2094 { | |
2095 /* This function can GC */ | |
2096 int saw_a_backslash; | |
2097 Bytecount len = read_atom_0 (readcharfun, -1, &saw_a_backslash); | |
2098 return (parse_integer | |
2099 (resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)), | |
2100 ((saw_a_backslash) | |
2101 ? 0 /* make parse_integer signal error */ | |
2102 : len), | |
2103 base)); | |
2104 } | |
2105 | |
2106 static Lisp_Object | |
2107 read_bit_vector (Lisp_Object readcharfun) | |
2108 { | |
2109 unsigned_char_dynarr *dyn = Dynarr_new (unsigned_char); | |
440 | 2110 Lisp_Object val; |
428 | 2111 |
2112 while (1) | |
2113 { | |
444 | 2114 unsigned char bit; |
867 | 2115 Ichar c = readchar (readcharfun); |
444 | 2116 if (c == '0') |
2117 bit = 0; | |
2118 else if (c == '1') | |
2119 bit = 1; | |
2120 else | |
2121 { | |
2122 if (c >= 0) | |
2123 unreadchar (readcharfun, c); | |
2124 break; | |
2125 } | |
2126 Dynarr_add (dyn, bit); | |
428 | 2127 } |
2128 | |
440 | 2129 val = make_bit_vector_from_byte_vector (Dynarr_atp (dyn, 0), |
2130 Dynarr_length (dyn)); | |
2131 Dynarr_free (dyn); | |
2132 | |
2133 return val; | |
428 | 2134 } |
2135 | |
2136 | |
2137 | |
2138 /* structures */ | |
2139 | |
2140 struct structure_type * | |
2141 define_structure_type (Lisp_Object type, | |
2142 int (*validate) (Lisp_Object data, | |
578 | 2143 Error_Behavior errb), |
428 | 2144 Lisp_Object (*instantiate) (Lisp_Object data)) |
2145 { | |
2146 struct structure_type st; | |
2147 | |
2148 st.type = type; | |
2149 st.keywords = Dynarr_new (structure_keyword_entry); | |
2150 st.validate = validate; | |
2151 st.instantiate = instantiate; | |
2152 Dynarr_add (the_structure_type_dynarr, st); | |
2153 | |
2154 return Dynarr_atp (the_structure_type_dynarr, | |
2155 Dynarr_length (the_structure_type_dynarr) - 1); | |
2156 } | |
2157 | |
2158 void | |
2159 define_structure_type_keyword (struct structure_type *st, Lisp_Object keyword, | |
2160 int (*validate) (Lisp_Object keyword, | |
2161 Lisp_Object value, | |
578 | 2162 Error_Behavior errb)) |
428 | 2163 { |
2164 struct structure_keyword_entry en; | |
2165 | |
2166 en.keyword = keyword; | |
2167 en.validate = validate; | |
2168 Dynarr_add (st->keywords, en); | |
2169 } | |
2170 | |
2171 static struct structure_type * | |
2172 recognized_structure_type (Lisp_Object type) | |
2173 { | |
2174 int i; | |
2175 | |
2176 for (i = 0; i < Dynarr_length (the_structure_type_dynarr); i++) | |
2177 { | |
2178 struct structure_type *st = Dynarr_atp (the_structure_type_dynarr, i); | |
2179 if (EQ (st->type, type)) | |
2180 return st; | |
2181 } | |
2182 | |
2183 return 0; | |
2184 } | |
2185 | |
2186 static Lisp_Object | |
2187 read_structure (Lisp_Object readcharfun) | |
2188 { | |
867 | 2189 Ichar c = readchar (readcharfun); |
428 | 2190 Lisp_Object list = Qnil; |
2191 Lisp_Object orig_list = Qnil; | |
2192 Lisp_Object already_seen = Qnil; | |
2193 int keyword_count; | |
2194 struct structure_type *st; | |
2195 struct gcpro gcpro1, gcpro2; | |
2196 | |
2197 GCPRO2 (orig_list, already_seen); | |
2198 if (c != '(') | |
442 | 2199 RETURN_UNGCPRO (continuable_read_syntax_error ("#s not followed by paren")); |
428 | 2200 list = read_list (readcharfun, ')', 0, 0); |
2201 orig_list = list; | |
2202 { | |
2203 int len = XINT (Flength (list)); | |
2204 if (len == 0) | |
442 | 2205 RETURN_UNGCPRO (continuable_read_syntax_error |
428 | 2206 ("structure type not specified")); |
2207 if (!(len & 1)) | |
2208 RETURN_UNGCPRO | |
442 | 2209 (continuable_read_syntax_error |
428 | 2210 ("structures must have alternating keyword/value pairs")); |
2211 } | |
2212 | |
2213 st = recognized_structure_type (XCAR (list)); | |
2214 if (!st) | |
2215 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2216 list2 (build_msg_string |
428 | 2217 ("unrecognized structure type"), |
2218 XCAR (list)))); | |
2219 | |
2220 list = Fcdr (list); | |
2221 keyword_count = Dynarr_length (st->keywords); | |
2222 while (!NILP (list)) | |
2223 { | |
2224 Lisp_Object keyword, value; | |
2225 int i; | |
2226 struct structure_keyword_entry *en = NULL; | |
2227 | |
2228 keyword = Fcar (list); | |
2229 list = Fcdr (list); | |
2230 value = Fcar (list); | |
2231 list = Fcdr (list); | |
2232 | |
2233 if (!NILP (memq_no_quit (keyword, already_seen))) | |
2234 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2235 list2 (build_msg_string |
428 | 2236 ("structure keyword already seen"), |
2237 keyword))); | |
2238 | |
2239 for (i = 0; i < keyword_count; i++) | |
2240 { | |
2241 en = Dynarr_atp (st->keywords, i); | |
2242 if (EQ (keyword, en->keyword)) | |
2243 break; | |
2244 } | |
2245 | |
2246 if (i == keyword_count) | |
2247 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2248 list2 (build_msg_string |
428 | 2249 ("unrecognized structure keyword"), |
2250 keyword))); | |
2251 | |
2252 if (en->validate && ! (en->validate) (keyword, value, ERROR_ME)) | |
2253 RETURN_UNGCPRO | |
2254 (Fsignal (Qinvalid_read_syntax, | |
771 | 2255 list3 (build_msg_string |
428 | 2256 ("invalid value for structure keyword"), |
2257 keyword, value))); | |
2258 | |
2259 already_seen = Fcons (keyword, already_seen); | |
2260 } | |
2261 | |
2262 if (st->validate && ! (st->validate) (orig_list, ERROR_ME)) | |
2263 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2264 list2 (build_msg_string |
428 | 2265 ("invalid structure initializer"), |
2266 orig_list))); | |
2267 | |
2268 RETURN_UNGCPRO ((st->instantiate) (XCDR (orig_list))); | |
2269 } | |
2270 | |
2271 | |
2272 static Lisp_Object read_compiled_function (Lisp_Object readcharfun, | |
2273 int terminator); | |
2274 static Lisp_Object read_vector (Lisp_Object readcharfun, int terminator); | |
2275 | |
2276 /* Get the next character; filter out whitespace and comments */ | |
2277 | |
867 | 2278 static Ichar |
428 | 2279 reader_nextchar (Lisp_Object readcharfun) |
2280 { | |
2281 /* This function can GC */ | |
867 | 2282 Ichar c; |
428 | 2283 |
2284 retry: | |
2285 QUIT; | |
2286 c = readchar (readcharfun); | |
2287 if (c < 0) | |
563 | 2288 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 2289 |
2290 switch (c) | |
2291 { | |
2292 default: | |
2293 { | |
2294 /* Ignore whitespace and control characters */ | |
2295 if (c <= 040) | |
2296 goto retry; | |
2297 return c; | |
2298 } | |
2299 | |
2300 case ';': | |
2301 { | |
2302 /* Comment */ | |
2303 while ((c = readchar (readcharfun)) >= 0 && c != '\n') | |
2304 QUIT; | |
2305 goto retry; | |
2306 } | |
2307 } | |
2308 } | |
2309 | |
2310 #if 0 | |
2311 static Lisp_Object | |
2312 list2_pure (int pure, Lisp_Object a, Lisp_Object b) | |
2313 { | |
2314 return pure ? pure_cons (a, pure_cons (b, Qnil)) : list2 (a, b); | |
2315 } | |
2316 #endif | |
2317 | |
3543 | 2318 static Lisp_Object |
2319 read_string (Lisp_Object readcharfun, Ichar delim, int raw, | |
2320 int honor_unicode) | |
2321 { | |
2322 #ifdef I18N3 | |
2323 /* #### If the input stream is translating, then the string | |
2324 should be marked as translatable by setting its | |
2325 `string-translatable' property to t. .el and .elc files | |
2326 normally are translating input streams. See Fgettext() | |
2327 and print_internal(). */ | |
2328 #endif | |
2329 Ichar c; | |
2330 int cancel = 0; | |
2331 | |
2332 Lstream_rewind(XLSTREAM(Vread_buffer_stream)); | |
2333 while ((c = readchar(readcharfun)) >= 0 && c != delim) | |
2334 { | |
2335 if (c == '\\') | |
2336 { | |
2337 if (raw) | |
2338 { | |
2339 c = readchar(readcharfun); | |
2340 if (honor_unicode && ('u' == c || 'U' == c)) | |
2341 { | |
2342 c = read_unicode_escape(readcharfun, | |
2343 'U' == c ? 8 : 4); | |
2344 } | |
2345 else | |
2346 { | |
2347 /* For raw strings, insert the | |
2348 backslash and the next char, */ | |
2349 Lstream_put_ichar(XLSTREAM | |
2350 (Vread_buffer_stream), | |
2351 '\\'); | |
2352 } | |
2353 } | |
2354 else | |
2355 /* otherwise, backslash escapes the next char. */ | |
2356 c = read_escape(readcharfun); | |
2357 } | |
2358 /* c is -1 if \ newline has just been seen */ | |
2359 if (c == -1) | |
2360 { | |
2361 if (Lstream_byte_count | |
2362 (XLSTREAM(Vread_buffer_stream)) == | |
2363 0) | |
2364 cancel = 1; | |
2365 } | |
2366 else | |
2367 Lstream_put_ichar(XLSTREAM | |
2368 (Vread_buffer_stream), | |
2369 c); | |
2370 QUIT; | |
2371 } | |
2372 if (c < 0) | |
2373 return Fsignal(Qend_of_file, | |
2374 list1(READCHARFUN_MAYBE(readcharfun))); | |
2375 | |
2376 /* If purifying, and string starts with \ newline, | |
2377 return zero instead. This is for doc strings | |
2378 that we are really going to find in lib-src/DOC.nn.nn */ | |
2379 if (purify_flag && NILP(Vinternal_doc_file_name) | |
2380 && cancel) | |
2381 return Qzero; | |
2382 | |
2383 Lstream_flush(XLSTREAM(Vread_buffer_stream)); | |
2384 return make_string(resizing_buffer_stream_ptr | |
2385 (XLSTREAM(Vread_buffer_stream)), | |
2386 Lstream_byte_count(XLSTREAM(Vread_buffer_stream))); | |
2387 } | |
2388 | |
2389 static Lisp_Object | |
2390 read_raw_string (Lisp_Object readcharfun) | |
2391 { | |
2392 Ichar c; | |
2393 Ichar permit_unicode = 0; | |
2394 | |
2395 do { | |
2396 c = reader_nextchar(readcharfun); | |
2397 switch (c) { | |
2398 /* #r:engine"my sexy raw string" -- raw string w/ flags*/ | |
2399 /* case ':': */ | |
2400 /* #ru"Hi there\u20AC \U000020AC" -- raw string, honouring Unicode. */ | |
2401 case 'u': | |
2402 case 'U': | |
2403 permit_unicode = c; | |
2404 continue; | |
2405 | |
2406 /* #r"my raw string" -- raw string */ | |
2407 case '\"': | |
2408 return read_string(readcharfun, '\"', 1, permit_unicode); | |
2409 /* invalid syntax */ | |
2410 default: | |
2411 { | |
2412 if (permit_unicode) | |
2413 { | |
2414 unreadchar(readcharfun, permit_unicode); | |
2415 } | |
2416 unreadchar(readcharfun, c); | |
2417 return Fsignal(Qinvalid_read_syntax, | |
2418 list1(build_string | |
2419 ("unrecognized raw string syntax"))); | |
2420 } | |
2421 } | |
2422 } while (1); | |
2423 } | |
2424 | |
428 | 2425 /* Read the next Lisp object from the stream READCHARFUN and return it. |
2426 If the return value is a cons whose car is Qunbound, then read1() | |
2427 encountered a misplaced token (e.g. a right bracket, right paren, | |
2428 or dot followed by a non-number). To filter this stuff out, | |
2429 use read0(). */ | |
2430 | |
2431 static Lisp_Object | |
2432 read1 (Lisp_Object readcharfun) | |
2433 { | |
867 | 2434 Ichar c; |
428 | 2435 |
2436 retry: | |
2437 c = reader_nextchar (readcharfun); | |
2438 | |
2439 switch (c) | |
2440 { | |
2441 case '(': | |
2442 { | |
2443 #ifdef LISP_BACKQUOTES /* old backquote compatibility in lisp reader */ | |
2444 /* if this is disabled, then other code in eval.c must be enabled */ | |
867 | 2445 Ichar ch = reader_nextchar (readcharfun); |
428 | 2446 switch (ch) |
2447 { | |
2448 case '`': | |
2449 { | |
2450 Lisp_Object tem; | |
853 | 2451 int speccount = internal_bind_int (&old_backquote_flag, |
2452 1 + old_backquote_flag); | |
428 | 2453 tem = read0 (readcharfun); |
771 | 2454 unbind_to (speccount); |
428 | 2455 ch = reader_nextchar (readcharfun); |
2456 if (ch != ')') | |
2457 { | |
2458 unreadchar (readcharfun, ch); | |
2459 return Fsignal (Qinvalid_read_syntax, | |
771 | 2460 list1 (build_msg_string |
428 | 2461 ("Weird old-backquote syntax"))); |
2462 } | |
2463 return list2 (Qbacktick, tem); | |
2464 } | |
2465 case ',': | |
2466 { | |
2467 if (old_backquote_flag) | |
2468 { | |
2469 Lisp_Object tem, comma_type; | |
2470 ch = readchar (readcharfun); | |
2471 if (ch == '@') | |
2472 comma_type = Qcomma_at; | |
2473 else | |
2474 { | |
2475 if (ch >= 0) | |
2476 unreadchar (readcharfun, ch); | |
2477 comma_type = Qcomma; | |
2478 } | |
2479 tem = read0 (readcharfun); | |
2480 ch = reader_nextchar (readcharfun); | |
2481 if (ch != ')') | |
2482 { | |
2483 unreadchar (readcharfun, ch); | |
2484 return Fsignal (Qinvalid_read_syntax, | |
771 | 2485 list1 (build_msg_string |
428 | 2486 ("Weird old-backquote syntax"))); |
2487 } | |
2488 return list2 (comma_type, tem); | |
2489 } | |
2490 else | |
2491 { | |
2492 unreadchar (readcharfun, ch); | |
2493 #if 0 | |
2494 return Fsignal (Qinvalid_read_syntax, | |
771 | 2495 list1 (build_msg_string ("Comma outside of backquote"))); |
428 | 2496 #else |
2497 /* #### - yuck....but this is reverse compatible. */ | |
2498 /* mostly this is required by edebug, which does its own | |
2499 annotated reading. We need to have an annotated_read | |
2500 function that records (with markers) the buffer | |
2501 positions of the elements that make up lists, then that | |
2502 can be used in edebug and bytecomp and the check above | |
2503 can go back in. --Stig */ | |
2504 break; | |
2505 #endif | |
2506 } | |
2507 } | |
2508 default: | |
2509 unreadchar (readcharfun, ch); | |
2510 } /* switch(ch) */ | |
2511 #endif /* old backquote crap... */ | |
2512 return read_list (readcharfun, ')', 1, 1); | |
2513 } | |
2514 case '[': | |
2515 return read_vector (readcharfun, ']'); | |
2516 | |
2517 case ')': | |
2518 case ']': | |
2519 /* #### - huh? these don't do what they seem... */ | |
2520 return noseeum_cons (Qunbound, make_char (c)); | |
2521 case '.': | |
2522 { | |
2523 /* If a period is followed by a number, then we should read it | |
2524 as a floating point number. Otherwise, it denotes a dotted | |
2525 pair. | |
2526 */ | |
2527 c = readchar (readcharfun); | |
2528 unreadchar (readcharfun, c); | |
2529 | |
867 | 2530 /* Can't use isdigit on Ichars */ |
428 | 2531 if (c < '0' || c > '9') |
2532 return noseeum_cons (Qunbound, make_char ('.')); | |
2533 | |
2534 /* Note that read_atom will loop | |
2535 at least once, assuring that we will not try to UNREAD | |
2536 two characters in a row. | |
2537 (I think this doesn't matter anymore because there should | |
2538 be no more danger in unreading multiple characters) */ | |
2539 return read_atom (readcharfun, '.', 0); | |
2540 } | |
2541 | |
2542 case '#': | |
2543 { | |
2544 c = readchar (readcharfun); | |
2545 switch (c) | |
2546 { | |
2547 #if 0 /* FSFmacs silly char-table syntax */ | |
2548 case '^': | |
2549 #endif | |
2550 #if 0 /* FSFmacs silly bool-vector syntax */ | |
2551 case '&': | |
2552 #endif | |
2553 /* "#["-- byte-code constant syntax */ | |
2554 /* purecons #[...] syntax */ | |
2555 case '[': return read_compiled_function (readcharfun, ']' | |
2556 /*, purify_flag */ ); | |
2557 /* "#:"-- gensym syntax */ | |
2558 case ':': return read_atom (readcharfun, -1, 1); | |
2559 /* #'x => (function x) */ | |
2560 case '\'': return list2 (Qfunction, read0 (readcharfun)); | |
2561 #if 0 | |
2562 /* RMS uses this syntax for fat-strings. | |
2563 If we use it for vectors, then obscure bugs happen. | |
2564 */ | |
2565 /* "#(" -- Scheme/CL vector syntax */ | |
2566 case '(': return read_vector (readcharfun, ')'); | |
2567 #endif | |
2568 #if 0 /* FSFmacs */ | |
2569 case '(': | |
2570 { | |
2571 Lisp_Object tmp; | |
2572 struct gcpro gcpro1; | |
2573 | |
2574 /* Read the string itself. */ | |
2575 tmp = read1 (readcharfun); | |
2576 if (!STRINGP (tmp)) | |
2577 { | |
2578 if (CONSP (tmp) && UNBOUNDP (XCAR (tmp))) | |
853 | 2579 free_cons (tmp); |
428 | 2580 return Fsignal (Qinvalid_read_syntax, |
2581 list1 (build_string ("#"))); | |
2582 } | |
2583 GCPRO1 (tmp); | |
2584 /* Read the intervals and their properties. */ | |
2585 while (1) | |
2586 { | |
2587 Lisp_Object beg, end, plist; | |
867 | 2588 Ichar ch; |
428 | 2589 int invalid = 0; |
2590 | |
2591 beg = read1 (readcharfun); | |
2592 if (CONSP (beg) && UNBOUNDP (XCAR (beg))) | |
2593 { | |
2594 ch = XCHAR (XCDR (beg)); | |
853 | 2595 free_cons (beg); |
428 | 2596 if (ch == ')') |
2597 break; | |
2598 else | |
2599 invalid = 1; | |
2600 } | |
2601 if (!invalid) | |
2602 { | |
2603 end = read1 (readcharfun); | |
2604 if (CONSP (end) && UNBOUNDP (XCAR (end))) | |
2605 { | |
853 | 2606 free_cons (end); |
428 | 2607 invalid = 1; |
2608 } | |
2609 } | |
2610 if (!invalid) | |
2611 { | |
2612 plist = read1 (readcharfun); | |
2613 if (CONSP (plist) && UNBOUNDP (XCAR (plist))) | |
2614 { | |
853 | 2615 free_cons (plist); |
428 | 2616 invalid = 1; |
2617 } | |
2618 } | |
2619 if (invalid) | |
2620 RETURN_UNGCPRO | |
2621 (Fsignal (Qinvalid_read_syntax, | |
2622 list2 | |
771 | 2623 (build_msg_string ("invalid string property list"), |
428 | 2624 XCDR (plist)))); |
2625 Fset_text_properties (beg, end, plist, tmp); | |
2626 } | |
2627 UNGCPRO; | |
2628 return tmp; | |
2629 } | |
2630 #endif /* 0 */ | |
2631 case '@': | |
2632 { | |
2633 /* #@NUMBER is used to skip NUMBER following characters. | |
2634 That's used in .elc files to skip over doc strings | |
2635 and function definitions. */ | |
2636 int i, nskip = 0; | |
2637 | |
2638 /* Read a decimal integer. */ | |
2639 while ((c = readchar (readcharfun)) >= 0 | |
2640 && c >= '0' && c <= '9') | |
2641 nskip = (10 * nskip) + (c - '0'); | |
2642 if (c >= 0) | |
2643 unreadchar (readcharfun, c); | |
2644 | |
2645 /* FSF has code here that maybe caches the skipped | |
2646 string. See above for why this is totally | |
2647 losing. We handle this differently. */ | |
2648 | |
2649 /* Skip that many characters. */ | |
2650 for (i = 0; i < nskip && c >= 0; i++) | |
2651 c = readchar (readcharfun); | |
2652 | |
2653 goto retry; | |
2654 } | |
2655 case '$': return Vload_file_name_internal; | |
2656 /* bit vectors */ | |
2657 case '*': return read_bit_vector (readcharfun); | |
2658 /* #o10 => 8 -- octal constant syntax */ | |
2659 case 'o': return read_integer (readcharfun, 8); | |
2660 /* #xdead => 57005 -- hex constant syntax */ | |
2661 case 'x': return read_integer (readcharfun, 16); | |
2662 /* #b010 => 2 -- binary constant syntax */ | |
2663 case 'b': return read_integer (readcharfun, 2); | |
3543 | 2664 /* #r"raw\stringt" -- raw string syntax */ |
2665 case 'r': return read_raw_string(readcharfun); | |
428 | 2666 /* #s(foobar key1 val1 key2 val2) -- structure syntax */ |
2667 case 's': return read_structure (readcharfun); | |
2668 case '<': | |
2669 { | |
2670 unreadchar (readcharfun, c); | |
2671 return Fsignal (Qinvalid_read_syntax, | |
771 | 2672 list1 (build_msg_string ("Cannot read unreadable object"))); |
428 | 2673 } |
2674 #ifdef FEATUREP_SYNTAX | |
2675 case '+': | |
2676 case '-': | |
2677 { | |
456 | 2678 Lisp_Object feature_exp, obj, tem; |
428 | 2679 struct gcpro gcpro1, gcpro2; |
2680 | |
456 | 2681 feature_exp = read0(readcharfun); |
428 | 2682 obj = read0(readcharfun); |
2683 | |
2684 /* the call to `featurep' may GC. */ | |
456 | 2685 GCPRO2 (feature_exp, obj); |
2686 tem = call1 (Qfeaturep, feature_exp); | |
428 | 2687 UNGCPRO; |
2688 | |
2689 if (c == '+' && NILP(tem)) goto retry; | |
2690 if (c == '-' && !NILP(tem)) goto retry; | |
2691 return obj; | |
2692 } | |
2693 #endif | |
2694 case '0': case '1': case '2': case '3': case '4': | |
2695 case '5': case '6': case '7': case '8': case '9': | |
2696 /* Reader forms that can reuse previously read objects. */ | |
2697 { | |
2698 int n = 0; | |
2699 Lisp_Object found; | |
2700 | |
2701 /* Using read_integer() here is impossible, because it | |
2702 chokes on `='. Using parse_integer() is too hard. | |
2703 So we simply read it in, and ignore overflows, which | |
2704 is safe. */ | |
2705 while (c >= '0' && c <= '9') | |
2706 { | |
2707 n *= 10; | |
2708 n += c - '0'; | |
2709 c = readchar (readcharfun); | |
2710 } | |
2711 found = assq_no_quit (make_int (n), Vread_objects); | |
2712 if (c == '=') | |
2713 { | |
2714 /* #n=object returns object, but associates it with | |
2715 n for #n#. */ | |
2716 Lisp_Object obj; | |
2717 if (CONSP (found)) | |
2718 return Fsignal (Qinvalid_read_syntax, | |
771 | 2719 list2 (build_msg_string |
428 | 2720 ("Multiply defined symbol label"), |
2721 make_int (n))); | |
2722 obj = read0 (readcharfun); | |
2723 Vread_objects = Fcons (Fcons (make_int (n), obj), | |
2724 Vread_objects); | |
2725 return obj; | |
2726 } | |
2727 else if (c == '#') | |
2728 { | |
2729 /* #n# returns a previously read object. */ | |
2730 if (CONSP (found)) | |
2731 return XCDR (found); | |
2732 else | |
2733 return Fsignal (Qinvalid_read_syntax, | |
771 | 2734 list2 (build_msg_string |
428 | 2735 ("Undefined symbol label"), |
2736 make_int (n))); | |
2737 } | |
2738 return Fsignal (Qinvalid_read_syntax, | |
2739 list1 (build_string ("#"))); | |
2740 } | |
2741 default: | |
2742 { | |
2743 unreadchar (readcharfun, c); | |
2744 return Fsignal (Qinvalid_read_syntax, | |
2745 list1 (build_string ("#"))); | |
2746 } | |
2747 } | |
2748 } | |
2749 | |
2750 /* Quote */ | |
2751 case '\'': return list2 (Qquote, read0 (readcharfun)); | |
2752 | |
2753 #ifdef LISP_BACKQUOTES | |
2754 case '`': | |
2755 { | |
2756 Lisp_Object tem; | |
853 | 2757 int speccount = internal_bind_int (&new_backquote_flag, |
2758 1 + new_backquote_flag); | |
428 | 2759 tem = read0 (readcharfun); |
771 | 2760 unbind_to (speccount); |
428 | 2761 return list2 (Qbackquote, tem); |
2762 } | |
2763 | |
2764 case ',': | |
2765 { | |
2766 if (new_backquote_flag) | |
2767 { | |
2768 Lisp_Object comma_type = Qnil; | |
2769 int ch = readchar (readcharfun); | |
2770 | |
2771 if (ch == '@') | |
2772 comma_type = Qcomma_at; | |
2773 else if (ch == '.') | |
2774 comma_type = Qcomma_dot; | |
2775 else | |
2776 { | |
2777 if (ch >= 0) | |
2778 unreadchar (readcharfun, ch); | |
2779 comma_type = Qcomma; | |
2780 } | |
2781 return list2 (comma_type, read0 (readcharfun)); | |
2782 } | |
2783 else | |
2784 { | |
2785 /* YUCK. 99.999% backwards compatibility. The Right | |
2786 Thing(tm) is to signal an error here, because it's | |
2787 really invalid read syntax. Instead, this permits | |
2788 commas to begin symbols (unless they're inside | |
2789 backquotes). If an error is signalled here in the | |
2790 future, then commas should be invalid read syntax | |
2791 outside of backquotes anywhere they're found (i.e. | |
2792 they must be quoted in symbols) -- Stig */ | |
2793 return read_atom (readcharfun, c, 0); | |
2794 } | |
2795 } | |
2796 #endif | |
2797 | |
2798 case '?': | |
2799 { | |
2800 /* Evil GNU Emacs "character" (ie integer) syntax */ | |
2801 c = readchar (readcharfun); | |
2802 if (c < 0) | |
2803 return Fsignal (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun))); | |
2804 | |
2805 if (c == '\\') | |
2806 c = read_escape (readcharfun); | |
4439 | 2807 if (c < 0) |
2808 return Fsignal (Qinvalid_read_syntax, list1 (READCHARFUN_MAYBE (readcharfun))); | |
428 | 2809 return make_char (c); |
2810 } | |
2811 | |
2812 case '\"': | |
3543 | 2813 /* String */ |
2814 return read_string(readcharfun, '\"', 0, 1); | |
428 | 2815 |
2816 default: | |
2817 { | |
2818 /* Ignore whitespace and control characters */ | |
2819 if (c <= 040) | |
2820 goto retry; | |
2821 return read_atom (readcharfun, c, 0); | |
2822 } | |
2823 } | |
2824 } | |
2825 | |
2826 | |
2827 | |
2828 #define LEAD_INT 1 | |
2829 #define DOT_CHAR 2 | |
2830 #define TRAIL_INT 4 | |
2831 #define E_CHAR 8 | |
2832 #define EXP_INT 16 | |
2833 | |
2834 int | |
442 | 2835 isfloat_string (const char *cp) |
428 | 2836 { |
2837 int state = 0; | |
867 | 2838 const Ibyte *ucp = (const Ibyte *) cp; |
428 | 2839 |
2840 if (*ucp == '+' || *ucp == '-') | |
2841 ucp++; | |
2842 | |
2843 if (*ucp >= '0' && *ucp <= '9') | |
2844 { | |
2845 state |= LEAD_INT; | |
2846 while (*ucp >= '0' && *ucp <= '9') | |
2847 ucp++; | |
2848 } | |
2849 if (*ucp == '.') | |
2850 { | |
2851 state |= DOT_CHAR; | |
2852 ucp++; | |
2853 } | |
2854 if (*ucp >= '0' && *ucp <= '9') | |
2855 { | |
2856 state |= TRAIL_INT; | |
2857 while (*ucp >= '0' && *ucp <= '9') | |
2858 ucp++; | |
2859 } | |
2860 if (*ucp == 'e' || *ucp == 'E') | |
2861 { | |
2862 state |= E_CHAR; | |
2863 ucp++; | |
2864 if ((*ucp == '+') || (*ucp == '-')) | |
2865 ucp++; | |
2866 } | |
2867 | |
2868 if (*ucp >= '0' && *ucp <= '9') | |
2869 { | |
2870 state |= EXP_INT; | |
2871 while (*ucp >= '0' && *ucp <= '9') | |
2872 ucp++; | |
2873 } | |
2874 return (((*ucp == 0) || (*ucp == ' ') || (*ucp == '\t') || (*ucp == '\n') | |
2875 || (*ucp == '\r') || (*ucp == '\f')) | |
2876 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT) | |
2877 || state == (DOT_CHAR|TRAIL_INT) | |
2878 || state == (LEAD_INT|E_CHAR|EXP_INT) | |
2879 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT) | |
2880 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT))); | |
2881 } | |
1983 | 2882 |
2883 #ifdef HAVE_RATIO | |
2884 int | |
2885 isratio_string (const char *cp) | |
2886 { | |
2010 | 2887 /* Possible minus/plus sign */ |
2888 if (*cp == '-' || *cp == '+') | |
1983 | 2889 cp++; |
2890 | |
2891 /* Numerator */ | |
2892 if (*cp < '0' || *cp > '9') | |
2893 return 0; | |
2894 | |
2895 do { | |
2896 cp++; | |
2897 } while (*cp >= '0' && *cp <= '9'); | |
2898 | |
2899 /* Slash */ | |
2900 if (*cp++ != '/') | |
2901 return 0; | |
2902 | |
2903 /* Denominator */ | |
2904 if (*cp < '0' || *cp > '9') | |
2905 return 0; | |
2906 | |
2907 do { | |
2908 cp++; | |
2909 } while (*cp >= '0' && *cp <= '9'); | |
2910 | |
2911 return *cp == '\0' || *cp == ' ' || *cp =='\t' || *cp == '\n' || | |
2912 *cp == '\r' || *cp == '\f'; | |
2913 } | |
2914 #endif | |
428 | 2915 |
2916 static void * | |
2917 sequence_reader (Lisp_Object readcharfun, | |
867 | 2918 Ichar terminator, |
428 | 2919 void *state, |
2920 void * (*conser) (Lisp_Object readcharfun, | |
2921 void *state, Charcount len)) | |
2922 { | |
2923 Charcount len; | |
2924 | |
2925 for (len = 0; ; len++) | |
2926 { | |
867 | 2927 Ichar ch; |
428 | 2928 |
2929 QUIT; | |
2930 ch = reader_nextchar (readcharfun); | |
2931 | |
2932 if (ch == terminator) | |
2933 return state; | |
2934 else | |
2935 unreadchar (readcharfun, ch); | |
2936 #ifdef FEATUREP_SYNTAX | |
2937 if (ch == ']') | |
442 | 2938 read_syntax_error ("\"]\" in a list"); |
428 | 2939 else if (ch == ')') |
442 | 2940 read_syntax_error ("\")\" in a vector"); |
428 | 2941 #endif |
2942 state = ((conser) (readcharfun, state, len)); | |
2943 } | |
2944 } | |
2945 | |
2946 | |
2947 struct read_list_state | |
2948 { | |
2949 Lisp_Object head; | |
2950 Lisp_Object tail; | |
2951 int length; | |
2952 int allow_dotted_lists; | |
867 | 2953 Ichar terminator; |
428 | 2954 }; |
2955 | |
2956 static void * | |
2286 | 2957 read_list_conser (Lisp_Object readcharfun, void *state, Charcount UNUSED (len)) |
428 | 2958 { |
2959 struct read_list_state *s = (struct read_list_state *) state; | |
2960 Lisp_Object elt; | |
2961 | |
2962 elt = read1 (readcharfun); | |
2963 | |
2964 if (CONSP (elt) && UNBOUNDP (XCAR (elt))) | |
2965 { | |
2966 Lisp_Object tem = elt; | |
867 | 2967 Ichar ch; |
428 | 2968 |
2969 elt = XCDR (elt); | |
853 | 2970 free_cons (tem); |
428 | 2971 tem = Qnil; |
2972 ch = XCHAR (elt); | |
2973 #ifdef FEATUREP_SYNTAX | |
2974 if (ch == s->terminator) /* deal with #+, #- reader macros */ | |
2975 { | |
2976 unreadchar (readcharfun, s->terminator); | |
2977 goto done; | |
2978 } | |
2979 else if (ch == ']') | |
442 | 2980 read_syntax_error ("']' in a list"); |
428 | 2981 else if (ch == ')') |
442 | 2982 read_syntax_error ("')' in a vector"); |
428 | 2983 else |
2984 #endif | |
2985 if (ch != '.') | |
563 | 2986 signal_error (Qinternal_error, "BUG! Internal reader error", elt); |
428 | 2987 else if (!s->allow_dotted_lists) |
442 | 2988 read_syntax_error ("\".\" in a vector"); |
428 | 2989 else |
2990 { | |
2991 if (!NILP (s->tail)) | |
2992 XCDR (s->tail) = read0 (readcharfun); | |
2993 else | |
2994 s->head = read0 (readcharfun); | |
2995 elt = read1 (readcharfun); | |
2996 if (CONSP (elt) && UNBOUNDP (XCAR (elt))) | |
2997 { | |
2998 ch = XCHAR (XCDR (elt)); | |
853 | 2999 free_cons (elt); |
428 | 3000 if (ch == s->terminator) |
3001 { | |
3002 unreadchar (readcharfun, s->terminator); | |
3003 goto done; | |
3004 } | |
3005 } | |
442 | 3006 read_syntax_error (". in wrong context"); |
428 | 3007 } |
3008 } | |
3009 | |
3010 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
3011 if (s->length == 1 && s->allow_dotted_lists && EQ (XCAR (s->head), Qfset)) | |
3012 { | |
3013 if (CONSP (elt) && EQ (XCAR (elt), Qquote) && CONSP (XCDR (elt))) | |
3014 Vcurrent_compiled_function_annotation = XCAR (XCDR (elt)); | |
3015 else | |
3016 Vcurrent_compiled_function_annotation = elt; | |
3017 } | |
3018 #endif | |
3019 | |
3020 elt = Fcons (elt, Qnil); | |
3021 if (!NILP (s->tail)) | |
3022 XCDR (s->tail) = elt; | |
3023 else | |
3024 s->head = elt; | |
3025 s->tail = elt; | |
3026 done: | |
3027 s->length++; | |
3028 return s; | |
3029 } | |
3030 | |
3031 | |
814 | 3032 /* allow_dotted_lists means that something like (foo bar . baz) |
3033 is acceptable. If -1, means check for starting with defun | |
3034 and make structure pure. (not implemented, probably for very | |
3035 good reasons) | |
3036 | |
3037 If check_for_doc_references, look for (#$ . INT) doc references | |
3038 in the list and record if load_force_doc_strings is non-zero. | |
3039 (Such doc references will be destroyed during the loadup phase | |
3040 by replacing with Qzero, because Snarf-documentation will fill | |
3041 them in again.) | |
3042 | |
3043 WARNING: If you set this, you sure as hell better not call | |
3044 free_list() on the returned list here. | |
3045 */ | |
428 | 3046 |
3047 static Lisp_Object | |
3048 read_list (Lisp_Object readcharfun, | |
867 | 3049 Ichar terminator, |
428 | 3050 int allow_dotted_lists, |
3051 int check_for_doc_references) | |
3052 { | |
3053 struct read_list_state s; | |
3054 struct gcpro gcpro1, gcpro2; | |
3055 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
3056 Lisp_Object old_compiled_function_annotation = | |
3057 Vcurrent_compiled_function_annotation; | |
3058 #endif | |
3059 | |
3060 s.head = Qnil; | |
3061 s.tail = Qnil; | |
3062 s.length = 0; | |
3063 s.allow_dotted_lists = allow_dotted_lists; | |
3064 s.terminator = terminator; | |
3065 GCPRO2 (s.head, s.tail); | |
3066 | |
3067 sequence_reader (readcharfun, terminator, &s, read_list_conser); | |
3068 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
3069 Vcurrent_compiled_function_annotation = old_compiled_function_annotation; | |
3070 #endif | |
3071 | |
3072 if ((purify_flag || load_force_doc_strings) && check_for_doc_references) | |
3073 { | |
3074 /* check now for any doc string references and record them | |
3075 for later. */ | |
3076 Lisp_Object tail; | |
3077 | |
3078 /* We might be dealing with an imperfect list so don't | |
3079 use LIST_LOOP */ | |
3080 for (tail = s.head; CONSP (tail); tail = XCDR (tail)) | |
3081 { | |
3082 Lisp_Object holding_cons = Qnil; | |
3083 | |
3084 { | |
3085 Lisp_Object elem = XCAR (tail); | |
3086 /* elem might be (#$ . INT) ... */ | |
3087 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal)) | |
3088 holding_cons = tail; | |
3089 /* or it might be (quote (#$ . INT)) i.e. | |
3090 (quote . ((#$ . INT) . nil)) in the case of | |
3091 `autoload' (autoload evaluates its arguments, while | |
3092 `defvar', `defun', etc. don't). */ | |
3093 if (CONSP (elem) && EQ (XCAR (elem), Qquote) | |
3094 && CONSP (XCDR (elem))) | |
3095 { | |
3096 elem = XCAR (XCDR (elem)); | |
3097 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal)) | |
3098 holding_cons = XCDR (XCAR (tail)); | |
3099 } | |
3100 } | |
3101 | |
3102 if (CONSP (holding_cons)) | |
3103 { | |
3104 if (purify_flag) | |
3105 { | |
3106 if (NILP (Vinternal_doc_file_name)) | |
3107 /* We have not yet called Snarf-documentation, so | |
3108 assume this file is described in the DOC file | |
3109 and Snarf-documentation will fill in the right | |
3110 value later. For now, replace the whole list | |
3111 with 0. */ | |
3112 XCAR (holding_cons) = Qzero; | |
3113 else | |
3114 /* We have already called Snarf-documentation, so | |
3115 make a relative file name for this file, so it | |
3116 can be found properly in the installed Lisp | |
3117 directory. We don't use Fexpand_file_name | |
3118 because that would make the directory absolute | |
3119 now. */ | |
3120 XCAR (XCAR (holding_cons)) = | |
3121 concat2 (build_string ("../lisp/"), | |
3122 Ffile_name_nondirectory | |
3123 (Vload_file_name_internal)); | |
3124 } | |
3125 else | |
3126 /* Not pure. Just add to Vload_force_doc_string_list, | |
3127 and the string will be filled in properly in | |
3128 load_force_doc_string_unwind(). */ | |
3129 Vload_force_doc_string_list = | |
3130 /* We pass the cons that holds the (#$ . INT) so we | |
3131 can modify it in-place. */ | |
3132 Fcons (holding_cons, Vload_force_doc_string_list); | |
3133 } | |
3134 } | |
3135 } | |
3136 | |
3137 UNGCPRO; | |
3138 return s.head; | |
3139 } | |
3140 | |
3141 static Lisp_Object | |
3142 read_vector (Lisp_Object readcharfun, | |
867 | 3143 Ichar terminator) |
428 | 3144 { |
3145 Lisp_Object tem; | |
3146 Lisp_Object *p; | |
3147 int len; | |
3148 int i; | |
3149 struct read_list_state s; | |
3150 struct gcpro gcpro1, gcpro2; | |
3151 | |
3152 s.head = Qnil; | |
3153 s.tail = Qnil; | |
3154 s.length = 0; | |
3155 s.allow_dotted_lists = 0; | |
3156 GCPRO2 (s.head, s.tail); | |
3157 | |
3158 sequence_reader (readcharfun, terminator, &s, read_list_conser); | |
3159 | |
3160 UNGCPRO; | |
3161 tem = s.head; | |
3162 len = XINT (Flength (tem)); | |
3163 | |
814 | 3164 s.head = make_vector (len, Qnil); |
428 | 3165 |
3166 for (i = 0, p = &(XVECTOR_DATA (s.head)[0]); | |
3167 i < len; | |
3168 i++, p++) | |
3169 { | |
853 | 3170 Lisp_Object otem = tem; |
428 | 3171 tem = Fcar (tem); |
3172 *p = tem; | |
853 | 3173 tem = XCDR (otem); |
428 | 3174 free_cons (otem); |
3175 } | |
3176 return s.head; | |
3177 } | |
3178 | |
3179 static Lisp_Object | |
867 | 3180 read_compiled_function (Lisp_Object readcharfun, Ichar terminator) |
428 | 3181 { |
3182 /* Accept compiled functions at read-time so that we don't | |
3183 have to build them at load-time. */ | |
3184 Lisp_Object stuff; | |
3185 Lisp_Object make_byte_code_args[COMPILED_DOMAIN + 1]; | |
3186 struct gcpro gcpro1; | |
3187 int len; | |
3188 int iii; | |
3189 int saw_a_doc_ref = 0; | |
3190 | |
3191 /* Note: we tell read_list not to search for doc references | |
3192 because we need to handle the "doc reference" for the | |
3193 instructions and constants differently. */ | |
3194 stuff = read_list (readcharfun, terminator, 0, 0); | |
3195 len = XINT (Flength (stuff)); | |
3196 if (len < COMPILED_STACK_DEPTH + 1 || len > COMPILED_DOMAIN + 1) | |
3197 return | |
442 | 3198 continuable_read_syntax_error ("#[...] used with wrong number of elements"); |
428 | 3199 |
3200 for (iii = 0; CONSP (stuff); iii++) | |
3201 { | |
853 | 3202 Lisp_Object victim = stuff; |
428 | 3203 make_byte_code_args[iii] = Fcar (stuff); |
3204 if ((purify_flag || load_force_doc_strings) | |
3205 && CONSP (make_byte_code_args[iii]) | |
3206 && EQ (XCAR (make_byte_code_args[iii]), Vload_file_name_internal)) | |
3207 { | |
3208 if (purify_flag && iii == COMPILED_DOC_STRING) | |
3209 { | |
3210 /* same as in read_list(). */ | |
3211 if (NILP (Vinternal_doc_file_name)) | |
3212 make_byte_code_args[iii] = Qzero; | |
3213 else | |
3214 XCAR (make_byte_code_args[iii]) = | |
3215 concat2 (build_string ("../lisp/"), | |
3216 Ffile_name_nondirectory | |
3217 (Vload_file_name_internal)); | |
3218 } | |
3219 else | |
3220 saw_a_doc_ref = 1; | |
3221 } | |
3222 stuff = Fcdr (stuff); | |
3223 free_cons (victim); | |
3224 } | |
3225 GCPRO1 (make_byte_code_args[0]); | |
3226 gcpro1.nvars = len; | |
3227 | |
3228 /* v18 or v19 bytecode file. Need to Ebolify. */ | |
3229 if (load_byte_code_version < 20 && VECTORP (make_byte_code_args[2])) | |
3230 ebolify_bytecode_constants (make_byte_code_args[2]); | |
3231 | |
3232 /* make-byte-code looks at purify_flag, which should have the same | |
3233 * value as our "read-pure" argument */ | |
3234 stuff = Fmake_byte_code (len, make_byte_code_args); | |
3235 XCOMPILED_FUNCTION (stuff)->flags.ebolified = (load_byte_code_version < 20); | |
3236 if (saw_a_doc_ref) | |
3237 Vload_force_doc_string_list = Fcons (stuff, Vload_force_doc_string_list); | |
3238 UNGCPRO; | |
3239 return stuff; | |
3240 } | |
3241 | |
3242 | |
3243 | |
3244 void | |
3245 init_lread (void) | |
3246 { | |
3247 Vvalues = Qnil; | |
3248 | |
3249 load_in_progress = 0; | |
3250 | |
3251 Vload_descriptor_list = Qnil; | |
3252 | |
3253 /* kludge: locate-file does not work for a null load-path, even if | |
3254 the file name is absolute. */ | |
3255 | |
3256 Vload_path = Fcons (build_string (""), Qnil); | |
3257 | |
3258 /* This used to get initialized in init_lread because all streams | |
3259 got closed when dumping occurs. This is no longer true -- | |
3260 Vread_buffer_stream is a resizing output stream, and there is no | |
3261 reason to close it at dump-time. | |
3262 | |
3263 Vread_buffer_stream is set to Qnil in vars_of_lread, and this | |
3264 will initialize it only once, at dump-time. */ | |
3265 if (NILP (Vread_buffer_stream)) | |
3266 Vread_buffer_stream = make_resizing_buffer_output_stream (); | |
3267 | |
3268 Vload_force_doc_string_list = Qnil; | |
3269 } | |
3270 | |
3271 void | |
3272 syms_of_lread (void) | |
3273 { | |
3274 DEFSUBR (Fread); | |
3275 DEFSUBR (Fread_from_string); | |
3276 DEFSUBR (Fload_internal); | |
3277 DEFSUBR (Flocate_file); | |
3278 DEFSUBR (Flocate_file_clear_hashing); | |
3279 DEFSUBR (Feval_buffer); | |
3280 DEFSUBR (Feval_region); | |
3281 | |
563 | 3282 DEFSYMBOL (Qstandard_input); |
3283 DEFSYMBOL (Qread_char); | |
3284 DEFSYMBOL (Qload); | |
1292 | 3285 DEFSYMBOL (Qload_internal); |
563 | 3286 DEFSYMBOL (Qfset); |
428 | 3287 |
3288 #ifdef LISP_BACKQUOTES | |
563 | 3289 DEFSYMBOL (Qbackquote); |
428 | 3290 defsymbol (&Qbacktick, "`"); |
3291 defsymbol (&Qcomma, ","); | |
3292 defsymbol (&Qcomma_at, ",@"); | |
3293 defsymbol (&Qcomma_dot, ",."); | |
3294 #endif | |
3295 | |
563 | 3296 DEFSYMBOL (Qexists); |
3297 DEFSYMBOL (Qreadable); | |
3298 DEFSYMBOL (Qwritable); | |
3299 DEFSYMBOL (Qexecutable); | |
428 | 3300 } |
3301 | |
3302 void | |
3303 structure_type_create (void) | |
3304 { | |
3305 the_structure_type_dynarr = Dynarr_new (structure_type); | |
3306 } | |
3307 | |
3308 void | |
3309 reinit_vars_of_lread (void) | |
3310 { | |
3311 Vread_buffer_stream = Qnil; | |
3312 staticpro_nodump (&Vread_buffer_stream); | |
3313 } | |
3314 | |
3315 void | |
3316 vars_of_lread (void) | |
3317 { | |
3318 DEFVAR_LISP ("values", &Vvalues /* | |
3319 List of values of all expressions which were read, evaluated and printed. | |
3320 Order is reverse chronological. | |
3321 */ ); | |
3322 | |
3323 DEFVAR_LISP ("standard-input", &Vstandard_input /* | |
3324 Stream for read to get input from. | |
3325 See documentation of `read' for possible values. | |
3326 */ ); | |
3327 Vstandard_input = Qt; | |
3328 | |
3329 DEFVAR_LISP ("load-path", &Vload_path /* | |
3330 *List of directories to search for files to load. | |
3331 Each element is a string (directory name) or nil (try default directory). | |
3332 | |
3333 Note that the elements of this list *may not* begin with "~", so you must | |
3334 call `expand-file-name' on them before adding them to this list. | |
3335 | |
3336 Initialized based on EMACSLOADPATH environment variable, if any, | |
3337 otherwise to default specified in by file `paths.h' when XEmacs was built. | |
3338 If there were no paths specified in `paths.h', then XEmacs chooses a default | |
3339 value for this variable by looking around in the file-system near the | |
3340 directory in which the XEmacs executable resides. | |
3341 */ ); | |
3342 Vload_path = Qnil; | |
3343 | |
3344 /* xxxDEFVAR_LISP ("dump-load-path", &Vdump_load_path, | |
3345 "*Location of lisp files to be used when dumping ONLY."); */ | |
3346 | |
3347 DEFVAR_BOOL ("load-in-progress", &load_in_progress /* | |
3348 Non-nil iff inside of `load'. | |
3349 */ ); | |
3350 | |
2548 | 3351 DEFVAR_LISP ("load-suppress-alist", &Vload_suppress_alist /* |
3352 An alist of expressions controlling whether particular files can be loaded. | |
3353 Each element looks like (FILENAME EXPR). | |
3354 FILENAME should be a full pathname, but without the .el suffix. | |
3355 When `load' is run and is about to load the specified file, it evaluates | |
3356 the form to determine if the file can be loaded. | |
3357 This variable is normally initialized automatically. | |
3358 */ ); | |
3359 Vload_suppress_alist = Qnil; | |
3360 | |
428 | 3361 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist /* |
3362 An alist of expressions to be evalled when particular files are loaded. | |
3363 Each element looks like (FILENAME FORMS...). | |
3364 When `load' is run and the file-name argument is FILENAME, | |
3365 the FORMS in the corresponding element are executed at the end of loading. | |
3366 | |
3367 FILENAME must match exactly! Normally FILENAME is the name of a library, | |
3368 with no directory specified, since that is how `load' is normally called. | |
3369 An error in FORMS does not undo the load, | |
3370 but does prevent execution of the rest of the FORMS. | |
3371 */ ); | |
3372 Vafter_load_alist = Qnil; | |
3373 | |
3374 DEFVAR_BOOL ("load-warn-when-source-newer", &load_warn_when_source_newer /* | |
3375 *Whether `load' should check whether the source is newer than the binary. | |
3376 If this variable is true, then when a `.elc' file is being loaded and the | |
3377 corresponding `.el' is newer, a warning message will be printed. | |
3378 */ ); | |
1261 | 3379 load_warn_when_source_newer = 1; |
428 | 3380 |
3381 DEFVAR_BOOL ("load-warn-when-source-only", &load_warn_when_source_only /* | |
3382 *Whether `load' should warn when loading a `.el' file instead of an `.elc'. | |
3383 If this variable is true, then when `load' is called with a filename without | |
3384 an extension, and the `.elc' version doesn't exist but the `.el' version does, | |
3385 then a message will be printed. If an explicit extension is passed to `load', | |
3386 no warning will be printed. | |
3387 */ ); | |
3388 load_warn_when_source_only = 0; | |
3389 | |
3390 DEFVAR_BOOL ("load-ignore-elc-files", &load_ignore_elc_files /* | |
3391 *Whether `load' should ignore `.elc' files when a suffix is not given. | |
3392 This is normally used only to bootstrap the `.elc' files when building XEmacs. | |
3393 */ ); | |
3394 load_ignore_elc_files = 0; | |
3395 | |
1123 | 3396 DEFVAR_BOOL ("load-ignore-out-of-date-elc-files", |
3397 &load_ignore_out_of_date_elc_files /* | |
3398 *Whether `load' should ignore out-of-date `.elc' files when no suffix is given. | |
3399 This is normally used when compiling packages of elisp files that may have | |
3400 complex dependencies. Ignoring all elc files with `load-ignore-elc-files' | |
3401 would also be safe, but much slower. | |
3402 */ ); | |
3403 load_ignore_out_of_date_elc_files = 0; | |
3404 | |
3405 DEFVAR_BOOL ("load-always-display-messages", | |
3406 &load_always_display_messages /* | |
3407 *Whether `load' should always display loading messages. | |
3408 If this is true, every file loaded will be shown, regardless of the setting | |
3409 of the NOMESSAGE parameter, and even when files are loaded indirectly, e.g. | |
2857 | 3410 due to `require'. |
1123 | 3411 */ ); |
3412 load_always_display_messages = 0; | |
3413 | |
3414 DEFVAR_BOOL ("load-show-full-path-in-messages", | |
3415 &load_show_full_path_in_messages /* | |
3416 *Whether `load' should show the full path in all loading messages. | |
3417 */ ); | |
3418 load_show_full_path_in_messages = 0; | |
3419 | |
428 | 3420 #ifdef LOADHIST |
3421 DEFVAR_LISP ("load-history", &Vload_history /* | |
3422 Alist mapping source file names to symbols and features. | |
3423 Each alist element is a list that starts with a file name, | |
3424 except for one element (optional) that starts with nil and describes | |
3425 definitions evaluated from buffers not visiting files. | |
3426 The remaining elements of each list are symbols defined as functions | |
3427 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'. | |
3428 */ ); | |
3429 Vload_history = Qnil; | |
3430 | |
3431 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list /* | |
3432 Used for internal purposes by `load'. | |
3433 */ ); | |
3434 Vcurrent_load_list = Qnil; | |
3435 #endif | |
3436 | |
3437 DEFVAR_LISP ("load-file-name", &Vload_file_name /* | |
3438 Full name of file being loaded by `load'. | |
3439 */ ); | |
3440 Vload_file_name = Qnil; | |
3441 | |
3442 DEFVAR_LISP ("load-read-function", &Vload_read_function /* | |
3443 Function used by `load' and `eval-region' for reading expressions. | |
3444 The default is nil, which means use the function `read'. | |
3445 */ ); | |
3446 Vload_read_function = Qnil; | |
3447 | |
3448 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings /* | |
3449 Non-nil means `load' should force-load all dynamic doc strings. | |
3450 This is useful when the file being loaded is a temporary copy. | |
3451 */ ); | |
3452 load_force_doc_strings = 0; | |
3453 | |
3454 /* See read_escape(). */ | |
3455 #if 0 | |
3456 /* Used to be named `puke-on-fsf-keys' */ | |
3457 DEFVAR_BOOL ("fail-on-bucky-bit-character-escapes", | |
3458 &fail_on_bucky_bit_character_escapes /* | |
3459 Whether `read' should signal an error when it encounters unsupported | |
3460 character escape syntaxes or just read them incorrectly. | |
3461 */ ); | |
3462 fail_on_bucky_bit_character_escapes = 0; | |
3463 #endif | |
3464 | |
3465 /* This must be initialized in init_lread otherwise it may start out | |
3466 with values saved when the image is dumped. */ | |
3467 staticpro (&Vload_descriptor_list); | |
3468 | |
3469 /* Initialized in init_lread. */ | |
3470 staticpro (&Vload_force_doc_string_list); | |
3471 | |
3472 Vload_file_name_internal = Qnil; | |
3473 staticpro (&Vload_file_name_internal); | |
3474 | |
3475 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
3476 Vcurrent_compiled_function_annotation = Qnil; | |
3477 staticpro (&Vcurrent_compiled_function_annotation); | |
3478 #endif | |
3479 | |
3480 /* So that early-early stuff will work */ | |
1292 | 3481 Ffset (Qload, Qload_internal); |
428 | 3482 |
3483 #ifdef FEATUREP_SYNTAX | |
563 | 3484 DEFSYMBOL (Qfeaturep); |
771 | 3485 Fprovide (intern ("xemacs")); |
428 | 3486 #ifdef INFODOCK |
771 | 3487 Fprovide (intern ("infodock")); |
428 | 3488 #endif /* INFODOCK */ |
3489 #endif /* FEATUREP_SYNTAX */ | |
3490 | |
3491 #ifdef LISP_BACKQUOTES | |
3492 old_backquote_flag = new_backquote_flag = 0; | |
3493 #endif | |
3494 | |
3495 #ifdef I18N3 | |
3496 Vfile_domain = Qnil; | |
3497 #endif | |
3498 | |
3499 Vread_objects = Qnil; | |
3500 staticpro (&Vread_objects); | |
3501 | |
3502 Vlocate_file_hash_table = make_lisp_hash_table (200, | |
3503 HASH_TABLE_NON_WEAK, | |
3504 HASH_TABLE_EQUAL); | |
3505 staticpro (&Vlocate_file_hash_table); | |
3506 #ifdef DEBUG_XEMACS | |
3507 symbol_value (XSYMBOL (intern ("Vlocate-file-hash-table"))) | |
3508 = Vlocate_file_hash_table; | |
3509 #endif | |
3510 } |