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