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