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
|
|
1467 xxDEFUN ("eval-current-buffer", Feval_current_buffer, 0, 1, "", /*
|
|
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 ());
|
|
1511 record_unwind_protect (save_restriction_restore, save_restriction_save ());
|
|
1512
|
444
|
1513 /* This both uses start and checks its type. */
|
|
1514 Fgoto_char (start, cbuf);
|
|
1515 Fnarrow_to_region (make_int (BUF_BEGV (current_buffer)), end, cbuf);
|
428
|
1516 readevalloop (cbuf, XBUFFER (cbuf)->filename, Feval,
|
444
|
1517 !NILP (stream));
|
428
|
1518
|
771
|
1519 return unbind_to (speccount);
|
428
|
1520 }
|
|
1521
|
|
1522 DEFUN ("read", Fread, 0, 1, 0, /*
|
|
1523 Read one Lisp expression as text from STREAM, return as Lisp object.
|
|
1524 If STREAM is nil, use the value of `standard-input' (which see).
|
|
1525 STREAM or the value of `standard-input' may be:
|
|
1526 a buffer (read from point and advance it)
|
|
1527 a marker (read from where it points and advance it)
|
|
1528 a function (call it with no arguments for each character,
|
|
1529 call it with a char as argument to push a char back)
|
|
1530 a string (takes text from string, starting at the beginning)
|
|
1531 t (read text line using minibuffer and use it).
|
|
1532 */
|
|
1533 (stream))
|
|
1534 {
|
|
1535 if (NILP (stream))
|
|
1536 stream = Vstandard_input;
|
|
1537 if (EQ (stream, Qt))
|
|
1538 stream = Qread_char;
|
|
1539
|
|
1540 Vread_objects = Qnil;
|
|
1541
|
|
1542 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1543 Vcurrent_compiled_function_annotation = Qnil;
|
|
1544 #endif
|
|
1545 if (EQ (stream, Qread_char))
|
|
1546 {
|
|
1547 Lisp_Object val = call1 (Qread_from_minibuffer,
|
771
|
1548 build_msg_string ("Lisp expression: "));
|
428
|
1549 return Fcar (Fread_from_string (val, Qnil, Qnil));
|
|
1550 }
|
|
1551
|
|
1552 if (STRINGP (stream))
|
|
1553 return Fcar (Fread_from_string (stream, Qnil, Qnil));
|
|
1554
|
|
1555 return read0 (stream);
|
|
1556 }
|
|
1557
|
|
1558 DEFUN ("read-from-string", Fread_from_string, 1, 3, 0, /*
|
|
1559 Read one Lisp expression which is represented as text by STRING.
|
|
1560 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
|
|
1561 START and END optionally delimit a substring of STRING from which to read;
|
|
1562 they default to 0 and (length STRING) respectively.
|
|
1563 */
|
|
1564 (string, start, end))
|
|
1565 {
|
|
1566 Bytecount startval, endval;
|
|
1567 Lisp_Object tem;
|
|
1568 Lisp_Object lispstream = Qnil;
|
|
1569 struct gcpro gcpro1;
|
|
1570
|
|
1571 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1572 Vcurrent_compiled_function_annotation = Qnil;
|
|
1573 #endif
|
|
1574 GCPRO1 (lispstream);
|
|
1575 CHECK_STRING (string);
|
|
1576 get_string_range_byte (string, start, end, &startval, &endval,
|
|
1577 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
1578 lispstream = make_lisp_string_input_stream (string, startval,
|
|
1579 endval - startval);
|
|
1580
|
|
1581 Vread_objects = Qnil;
|
|
1582
|
|
1583 tem = read0 (lispstream);
|
|
1584 /* Yeah, it's ugly. Gonna make something of it?
|
|
1585 At least our reader is reentrant ... */
|
|
1586 tem =
|
|
1587 (Fcons (tem, make_int
|
793
|
1588 (string_index_byte_to_char
|
771
|
1589 (string,
|
428
|
1590 startval + Lstream_byte_count (XLSTREAM (lispstream))))));
|
|
1591 Lstream_delete (XLSTREAM (lispstream));
|
|
1592 UNGCPRO;
|
|
1593 return tem;
|
|
1594 }
|
|
1595
|
|
1596
|
|
1597 #ifdef LISP_BACKQUOTES
|
|
1598
|
|
1599 static Lisp_Object
|
|
1600 backquote_unwind (Lisp_Object ptr)
|
|
1601 { /* used as unwind-protect function in read0() */
|
|
1602 int *counter = (int *) get_opaque_ptr (ptr);
|
|
1603 if (--*counter < 0)
|
|
1604 *counter = 0;
|
|
1605 free_opaque_ptr (ptr);
|
|
1606 return Qnil;
|
|
1607 }
|
|
1608
|
|
1609 #endif
|
|
1610
|
|
1611 /* Use this for recursive reads, in contexts where internal tokens
|
|
1612 are not allowed. See also read1(). */
|
|
1613 static Lisp_Object
|
|
1614 read0 (Lisp_Object readcharfun)
|
|
1615 {
|
|
1616 Lisp_Object val = read1 (readcharfun);
|
|
1617
|
|
1618 if (CONSP (val) && UNBOUNDP (XCAR (val)))
|
|
1619 {
|
|
1620 Emchar c = XCHAR (XCDR (val));
|
|
1621 free_cons (XCONS (val));
|
|
1622 return Fsignal (Qinvalid_read_syntax,
|
|
1623 list1 (Fchar_to_string (make_char (c))));
|
|
1624 }
|
|
1625
|
|
1626 return val;
|
|
1627 }
|
|
1628
|
|
1629 static Emchar
|
|
1630 read_escape (Lisp_Object readcharfun)
|
|
1631 {
|
|
1632 /* This function can GC */
|
|
1633 Emchar c = readchar (readcharfun);
|
|
1634
|
|
1635 if (c < 0)
|
563
|
1636 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun));
|
428
|
1637
|
|
1638 switch (c)
|
|
1639 {
|
|
1640 case 'a': return '\007';
|
|
1641 case 'b': return '\b';
|
|
1642 case 'd': return 0177;
|
|
1643 case 'e': return 033;
|
|
1644 case 'f': return '\f';
|
|
1645 case 'n': return '\n';
|
|
1646 case 'r': return '\r';
|
|
1647 case 't': return '\t';
|
|
1648 case 'v': return '\v';
|
|
1649 case '\n': return -1;
|
|
1650
|
|
1651 case 'M':
|
|
1652 c = readchar (readcharfun);
|
|
1653 if (c < 0)
|
563
|
1654 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun));
|
428
|
1655 if (c != '-')
|
563
|
1656 syntax_error ("Invalid escape character syntax", Qunbound);
|
428
|
1657 c = readchar (readcharfun);
|
|
1658 if (c < 0)
|
563
|
1659 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun));
|
428
|
1660 if (c == '\\')
|
|
1661 c = read_escape (readcharfun);
|
|
1662 return c | 0200;
|
|
1663
|
|
1664 /* Originally, FSF_KEYS provided a degree of FSF Emacs
|
|
1665 compatibility by defining character "modifiers" alt, super,
|
|
1666 hyper and shift to infest the characters (i.e. integers).
|
|
1667
|
|
1668 However, this doesn't cut it for XEmacs 20, which
|
|
1669 distinguishes characters from integers. Without Mule, ?\H-a
|
|
1670 simply returns ?a because every character is clipped into
|
|
1671 0-255. Under Mule it is much worse -- ?\H-a with FSF_KEYS
|
|
1672 produces an illegal character, and moves us to crash-land.
|
|
1673
|
|
1674 For these reasons, FSF_KEYS hack is useless and without hope
|
|
1675 of ever working under XEmacs 20. */
|
|
1676 #undef FSF_KEYS
|
|
1677
|
|
1678 #ifdef FSF_KEYS
|
|
1679 #define alt_modifier (0x040000)
|
|
1680 #define super_modifier (0x080000)
|
|
1681 #define hyper_modifier (0x100000)
|
|
1682 #define shift_modifier (0x200000)
|
|
1683 /* fsf uses a different modifiers for meta and control. Possibly
|
|
1684 byte_compiled code will still work fsfmacs, though... --Stig
|
|
1685
|
|
1686 #define ctl_modifier (0x400000)
|
|
1687 #define meta_modifier (0x800000)
|
|
1688 */
|
563
|
1689 #define FSF_LOSSAGE(mask) \
|
|
1690 if (fail_on_bucky_bit_character_escapes || \
|
|
1691 ((c = readchar (readcharfun)) != '-')) \
|
|
1692 syntax_error ("Invalid escape character syntax", Qunbound); \
|
|
1693 c = readchar (readcharfun); \
|
|
1694 if (c < 0) \
|
|
1695 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); \
|
|
1696 if (c == '\\') \
|
|
1697 c = read_escape (readcharfun); \
|
428
|
1698 return c | mask
|
|
1699
|
|
1700 case 'S': FSF_LOSSAGE (shift_modifier);
|
|
1701 case 'H': FSF_LOSSAGE (hyper_modifier);
|
|
1702 case 'A': FSF_LOSSAGE (alt_modifier);
|
|
1703 case 's': FSF_LOSSAGE (super_modifier);
|
|
1704 #undef alt_modifier
|
|
1705 #undef super_modifier
|
|
1706 #undef hyper_modifier
|
|
1707 #undef shift_modifier
|
|
1708 #undef FSF_LOSSAGE
|
|
1709
|
|
1710 #endif /* FSF_KEYS */
|
|
1711
|
|
1712 case 'C':
|
|
1713 c = readchar (readcharfun);
|
|
1714 if (c < 0)
|
563
|
1715 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun));
|
428
|
1716 if (c != '-')
|
563
|
1717 syntax_error ("Invalid escape character syntax", Qunbound);
|
428
|
1718 case '^':
|
|
1719 c = readchar (readcharfun);
|
|
1720 if (c < 0)
|
563
|
1721 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun));
|
428
|
1722 if (c == '\\')
|
|
1723 c = read_escape (readcharfun);
|
|
1724 /* FSFmacs junk for non-ASCII controls.
|
|
1725 Not used here. */
|
|
1726 if (c == '?')
|
|
1727 return 0177;
|
|
1728 else
|
|
1729 return c & (0200 | 037);
|
|
1730
|
|
1731 case '0':
|
|
1732 case '1':
|
|
1733 case '2':
|
|
1734 case '3':
|
|
1735 case '4':
|
|
1736 case '5':
|
|
1737 case '6':
|
|
1738 case '7':
|
|
1739 /* An octal escape, as in ANSI C. */
|
|
1740 {
|
|
1741 REGISTER Emchar i = c - '0';
|
|
1742 REGISTER int count = 0;
|
|
1743 while (++count < 3)
|
|
1744 {
|
|
1745 if ((c = readchar (readcharfun)) >= '0' && c <= '7')
|
|
1746 i = (i << 3) + (c - '0');
|
|
1747 else
|
|
1748 {
|
|
1749 unreadchar (readcharfun, c);
|
|
1750 break;
|
|
1751 }
|
|
1752 }
|
|
1753 return i;
|
|
1754 }
|
|
1755
|
|
1756 case 'x':
|
|
1757 /* A hex escape, as in ANSI C, except that we only allow latin-1
|
|
1758 characters to be read this way. What is "\x4e03" supposed to
|
|
1759 mean, anyways, if the internal representation is hidden?
|
|
1760 This is also consistent with the treatment of octal escapes. */
|
|
1761 {
|
|
1762 REGISTER Emchar i = 0;
|
|
1763 REGISTER int count = 0;
|
|
1764 while (++count <= 2)
|
|
1765 {
|
|
1766 c = readchar (readcharfun);
|
|
1767 /* Remember, can't use isdigit(), isalpha() etc. on Emchars */
|
|
1768 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0');
|
|
1769 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10;
|
|
1770 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10;
|
|
1771 else
|
|
1772 {
|
|
1773 unreadchar (readcharfun, c);
|
|
1774 break;
|
|
1775 }
|
|
1776 }
|
|
1777 return i;
|
|
1778 }
|
|
1779
|
|
1780 #ifdef MULE
|
|
1781 /* #### need some way of reading an extended character with
|
|
1782 an escape sequence. */
|
|
1783 #endif
|
|
1784
|
|
1785 default:
|
|
1786 return c;
|
|
1787 }
|
|
1788 }
|
|
1789
|
|
1790
|
|
1791
|
|
1792 /* read symbol-constituent stuff into `Vread_buffer_stream'. */
|
|
1793 static Bytecount
|
|
1794 read_atom_0 (Lisp_Object readcharfun, Emchar firstchar, int *saw_a_backslash)
|
|
1795 {
|
|
1796 /* This function can GC */
|
|
1797 Emchar c = ((firstchar) >= 0 ? firstchar : readchar (readcharfun));
|
|
1798 Lstream_rewind (XLSTREAM (Vread_buffer_stream));
|
|
1799
|
|
1800 *saw_a_backslash = 0;
|
|
1801
|
|
1802 while (c > 040 /* #### - comma should be here as should backquote */
|
|
1803 && !(c == '\"' || c == '\'' || c == ';'
|
|
1804 || c == '(' || c == ')'
|
|
1805 #ifndef LISP_FLOAT_TYPE
|
|
1806 /* If we have floating-point support, then we need
|
|
1807 to allow <digits><dot><digits>. */
|
|
1808 || c =='.'
|
|
1809 #endif /* not LISP_FLOAT_TYPE */
|
|
1810 || c == '[' || c == ']' || c == '#'
|
|
1811 ))
|
|
1812 {
|
|
1813 if (c == '\\')
|
|
1814 {
|
|
1815 c = readchar (readcharfun);
|
|
1816 if (c < 0)
|
563
|
1817 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun));
|
428
|
1818 *saw_a_backslash = 1;
|
|
1819 }
|
|
1820 Lstream_put_emchar (XLSTREAM (Vread_buffer_stream), c);
|
|
1821 QUIT;
|
|
1822 c = readchar (readcharfun);
|
|
1823 }
|
|
1824
|
|
1825 if (c >= 0)
|
|
1826 unreadchar (readcharfun, c);
|
|
1827 /* blasted terminating 0 */
|
|
1828 Lstream_put_emchar (XLSTREAM (Vread_buffer_stream), 0);
|
|
1829 Lstream_flush (XLSTREAM (Vread_buffer_stream));
|
|
1830
|
|
1831 return Lstream_byte_count (XLSTREAM (Vread_buffer_stream)) - 1;
|
|
1832 }
|
|
1833
|
665
|
1834 static Lisp_Object parse_integer (const Intbyte *buf, Bytecount len, int base);
|
428
|
1835
|
|
1836 static Lisp_Object
|
|
1837 read_atom (Lisp_Object readcharfun,
|
|
1838 Emchar firstchar,
|
|
1839 int uninterned_symbol)
|
|
1840 {
|
|
1841 /* This function can GC */
|
|
1842 int saw_a_backslash;
|
|
1843 Bytecount len = read_atom_0 (readcharfun, firstchar, &saw_a_backslash);
|
|
1844 char *read_ptr = (char *)
|
|
1845 resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream));
|
|
1846
|
|
1847 /* Is it an integer? */
|
|
1848 if (! (saw_a_backslash || uninterned_symbol))
|
|
1849 {
|
|
1850 /* If a token had any backslashes in it, it is disqualified from
|
|
1851 being an integer or a float. This means that 123\456 is a
|
|
1852 symbol, as is \123 (which is the way (intern "123") prints).
|
|
1853 Also, if token was preceded by #:, it's always a symbol.
|
|
1854 */
|
|
1855 char *p = read_ptr + len;
|
|
1856 char *p1 = read_ptr;
|
|
1857
|
|
1858 if (*p1 == '+' || *p1 == '-') p1++;
|
|
1859 if (p1 != p)
|
|
1860 {
|
|
1861 int c;
|
|
1862
|
|
1863 while (p1 != p && (c = *p1) >= '0' && c <= '9')
|
|
1864 p1++;
|
|
1865 #ifdef LISP_FLOAT_TYPE
|
|
1866 /* Integers can have trailing decimal points. */
|
|
1867 if (p1 > read_ptr && p1 < p && *p1 == '.')
|
|
1868 p1++;
|
|
1869 #endif
|
|
1870 if (p1 == p)
|
|
1871 {
|
|
1872 /* It is an integer. */
|
|
1873 #ifdef LISP_FLOAT_TYPE
|
|
1874 if (p1[-1] == '.')
|
|
1875 p1[-1] = '\0';
|
|
1876 #endif
|
|
1877 #if 0
|
|
1878 {
|
|
1879 int number = 0;
|
|
1880 if (sizeof (int) == sizeof (EMACS_INT))
|
|
1881 number = atoi (read_buffer);
|
|
1882 else if (sizeof (long) == sizeof (EMACS_INT))
|
|
1883 number = atol (read_buffer);
|
|
1884 else
|
|
1885 abort ();
|
|
1886 return make_int (number);
|
|
1887 }
|
|
1888 #else
|
665
|
1889 return parse_integer ((Intbyte *) read_ptr, len, 10);
|
428
|
1890 #endif
|
|
1891 }
|
|
1892 }
|
|
1893 #ifdef LISP_FLOAT_TYPE
|
|
1894 if (isfloat_string (read_ptr))
|
|
1895 return make_float (atof (read_ptr));
|
|
1896 #endif
|
|
1897 }
|
|
1898
|
|
1899 {
|
|
1900 Lisp_Object sym;
|
|
1901 if (uninterned_symbol)
|
665
|
1902 sym = Fmake_symbol ( make_string ((Intbyte *) read_ptr, len));
|
428
|
1903 else
|
|
1904 {
|
665
|
1905 Lisp_Object name = make_string ((Intbyte *) read_ptr, len);
|
428
|
1906 sym = Fintern (name, Qnil);
|
|
1907 }
|
|
1908 return sym;
|
|
1909 }
|
|
1910 }
|
|
1911
|
|
1912
|
|
1913 static Lisp_Object
|
665
|
1914 parse_integer (const Intbyte *buf, Bytecount len, int base)
|
428
|
1915 {
|
665
|
1916 const Intbyte *lim = buf + len;
|
|
1917 const Intbyte *p = buf;
|
428
|
1918 EMACS_UINT num = 0;
|
|
1919 int negativland = 0;
|
|
1920
|
|
1921 if (*p == '-')
|
|
1922 {
|
|
1923 negativland = 1;
|
|
1924 p++;
|
|
1925 }
|
|
1926 else if (*p == '+')
|
|
1927 {
|
|
1928 p++;
|
|
1929 }
|
|
1930
|
|
1931 if (p == lim)
|
|
1932 goto loser;
|
|
1933
|
|
1934 for (; (p < lim) && (*p != '\0'); p++)
|
|
1935 {
|
|
1936 int c = *p;
|
|
1937 EMACS_UINT onum;
|
|
1938
|
|
1939 if (isdigit (c))
|
|
1940 c = c - '0';
|
|
1941 else if (isupper (c))
|
|
1942 c = c - 'A' + 10;
|
|
1943 else if (islower (c))
|
|
1944 c = c - 'a' + 10;
|
|
1945 else
|
|
1946 goto loser;
|
|
1947
|
|
1948 if (c < 0 || c >= base)
|
|
1949 goto loser;
|
|
1950
|
|
1951 onum = num;
|
|
1952 num = num * base + c;
|
|
1953 if (num < onum)
|
|
1954 goto overflow;
|
|
1955 }
|
|
1956
|
|
1957 {
|
|
1958 EMACS_INT int_result = negativland ? - (EMACS_INT) num : (EMACS_INT) num;
|
|
1959 Lisp_Object result = make_int (int_result);
|
|
1960 if (num && ((XINT (result) < 0) != negativland))
|
|
1961 goto overflow;
|
|
1962 if (XINT (result) != int_result)
|
|
1963 goto overflow;
|
|
1964 return result;
|
|
1965 }
|
|
1966 overflow:
|
|
1967 return Fsignal (Qinvalid_read_syntax,
|
771
|
1968 list3 (build_msg_string
|
428
|
1969 ("Integer constant overflow in reader"),
|
|
1970 make_string (buf, len),
|
|
1971 make_int (base)));
|
|
1972 loser:
|
|
1973 return Fsignal (Qinvalid_read_syntax,
|
771
|
1974 list3 (build_msg_string
|
428
|
1975 ("Invalid integer constant in reader"),
|
|
1976 make_string (buf, len),
|
|
1977 make_int (base)));
|
|
1978 }
|
|
1979
|
|
1980
|
|
1981 static Lisp_Object
|
|
1982 read_integer (Lisp_Object readcharfun, int base)
|
|
1983 {
|
|
1984 /* This function can GC */
|
|
1985 int saw_a_backslash;
|
|
1986 Bytecount len = read_atom_0 (readcharfun, -1, &saw_a_backslash);
|
|
1987 return (parse_integer
|
|
1988 (resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)),
|
|
1989 ((saw_a_backslash)
|
|
1990 ? 0 /* make parse_integer signal error */
|
|
1991 : len),
|
|
1992 base));
|
|
1993 }
|
|
1994
|
|
1995 static Lisp_Object
|
|
1996 read_bit_vector (Lisp_Object readcharfun)
|
|
1997 {
|
|
1998 unsigned_char_dynarr *dyn = Dynarr_new (unsigned_char);
|
440
|
1999 Lisp_Object val;
|
428
|
2000
|
|
2001 while (1)
|
|
2002 {
|
444
|
2003 unsigned char bit;
|
|
2004 Emchar c = readchar (readcharfun);
|
|
2005 if (c == '0')
|
|
2006 bit = 0;
|
|
2007 else if (c == '1')
|
|
2008 bit = 1;
|
|
2009 else
|
|
2010 {
|
|
2011 if (c >= 0)
|
|
2012 unreadchar (readcharfun, c);
|
|
2013 break;
|
|
2014 }
|
|
2015 Dynarr_add (dyn, bit);
|
428
|
2016 }
|
|
2017
|
440
|
2018 val = make_bit_vector_from_byte_vector (Dynarr_atp (dyn, 0),
|
|
2019 Dynarr_length (dyn));
|
|
2020 Dynarr_free (dyn);
|
|
2021
|
|
2022 return val;
|
428
|
2023 }
|
|
2024
|
|
2025
|
|
2026
|
|
2027 /* structures */
|
|
2028
|
|
2029 struct structure_type *
|
|
2030 define_structure_type (Lisp_Object type,
|
|
2031 int (*validate) (Lisp_Object data,
|
578
|
2032 Error_Behavior errb),
|
428
|
2033 Lisp_Object (*instantiate) (Lisp_Object data))
|
|
2034 {
|
|
2035 struct structure_type st;
|
|
2036
|
|
2037 st.type = type;
|
|
2038 st.keywords = Dynarr_new (structure_keyword_entry);
|
|
2039 st.validate = validate;
|
|
2040 st.instantiate = instantiate;
|
|
2041 Dynarr_add (the_structure_type_dynarr, st);
|
|
2042
|
|
2043 return Dynarr_atp (the_structure_type_dynarr,
|
|
2044 Dynarr_length (the_structure_type_dynarr) - 1);
|
|
2045 }
|
|
2046
|
|
2047 void
|
|
2048 define_structure_type_keyword (struct structure_type *st, Lisp_Object keyword,
|
|
2049 int (*validate) (Lisp_Object keyword,
|
|
2050 Lisp_Object value,
|
578
|
2051 Error_Behavior errb))
|
428
|
2052 {
|
|
2053 struct structure_keyword_entry en;
|
|
2054
|
|
2055 en.keyword = keyword;
|
|
2056 en.validate = validate;
|
|
2057 Dynarr_add (st->keywords, en);
|
|
2058 }
|
|
2059
|
|
2060 static struct structure_type *
|
|
2061 recognized_structure_type (Lisp_Object type)
|
|
2062 {
|
|
2063 int i;
|
|
2064
|
|
2065 for (i = 0; i < Dynarr_length (the_structure_type_dynarr); i++)
|
|
2066 {
|
|
2067 struct structure_type *st = Dynarr_atp (the_structure_type_dynarr, i);
|
|
2068 if (EQ (st->type, type))
|
|
2069 return st;
|
|
2070 }
|
|
2071
|
|
2072 return 0;
|
|
2073 }
|
|
2074
|
|
2075 static Lisp_Object
|
|
2076 read_structure (Lisp_Object readcharfun)
|
|
2077 {
|
|
2078 Emchar c = readchar (readcharfun);
|
|
2079 Lisp_Object list = Qnil;
|
|
2080 Lisp_Object orig_list = Qnil;
|
|
2081 Lisp_Object already_seen = Qnil;
|
|
2082 int keyword_count;
|
|
2083 struct structure_type *st;
|
|
2084 struct gcpro gcpro1, gcpro2;
|
|
2085
|
|
2086 GCPRO2 (orig_list, already_seen);
|
|
2087 if (c != '(')
|
442
|
2088 RETURN_UNGCPRO (continuable_read_syntax_error ("#s not followed by paren"));
|
428
|
2089 list = read_list (readcharfun, ')', 0, 0);
|
|
2090 orig_list = list;
|
|
2091 {
|
|
2092 int len = XINT (Flength (list));
|
|
2093 if (len == 0)
|
442
|
2094 RETURN_UNGCPRO (continuable_read_syntax_error
|
428
|
2095 ("structure type not specified"));
|
|
2096 if (!(len & 1))
|
|
2097 RETURN_UNGCPRO
|
442
|
2098 (continuable_read_syntax_error
|
428
|
2099 ("structures must have alternating keyword/value pairs"));
|
|
2100 }
|
|
2101
|
|
2102 st = recognized_structure_type (XCAR (list));
|
|
2103 if (!st)
|
|
2104 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax,
|
771
|
2105 list2 (build_msg_string
|
428
|
2106 ("unrecognized structure type"),
|
|
2107 XCAR (list))));
|
|
2108
|
|
2109 list = Fcdr (list);
|
|
2110 keyword_count = Dynarr_length (st->keywords);
|
|
2111 while (!NILP (list))
|
|
2112 {
|
|
2113 Lisp_Object keyword, value;
|
|
2114 int i;
|
|
2115 struct structure_keyword_entry *en = NULL;
|
|
2116
|
|
2117 keyword = Fcar (list);
|
|
2118 list = Fcdr (list);
|
|
2119 value = Fcar (list);
|
|
2120 list = Fcdr (list);
|
|
2121
|
|
2122 if (!NILP (memq_no_quit (keyword, already_seen)))
|
|
2123 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax,
|
771
|
2124 list2 (build_msg_string
|
428
|
2125 ("structure keyword already seen"),
|
|
2126 keyword)));
|
|
2127
|
|
2128 for (i = 0; i < keyword_count; i++)
|
|
2129 {
|
|
2130 en = Dynarr_atp (st->keywords, i);
|
|
2131 if (EQ (keyword, en->keyword))
|
|
2132 break;
|
|
2133 }
|
|
2134
|
|
2135 if (i == keyword_count)
|
|
2136 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax,
|
771
|
2137 list2 (build_msg_string
|
428
|
2138 ("unrecognized structure keyword"),
|
|
2139 keyword)));
|
|
2140
|
|
2141 if (en->validate && ! (en->validate) (keyword, value, ERROR_ME))
|
|
2142 RETURN_UNGCPRO
|
|
2143 (Fsignal (Qinvalid_read_syntax,
|
771
|
2144 list3 (build_msg_string
|
428
|
2145 ("invalid value for structure keyword"),
|
|
2146 keyword, value)));
|
|
2147
|
|
2148 already_seen = Fcons (keyword, already_seen);
|
|
2149 }
|
|
2150
|
|
2151 if (st->validate && ! (st->validate) (orig_list, ERROR_ME))
|
|
2152 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax,
|
771
|
2153 list2 (build_msg_string
|
428
|
2154 ("invalid structure initializer"),
|
|
2155 orig_list)));
|
|
2156
|
|
2157 RETURN_UNGCPRO ((st->instantiate) (XCDR (orig_list)));
|
|
2158 }
|
|
2159
|
|
2160
|
|
2161 static Lisp_Object read_compiled_function (Lisp_Object readcharfun,
|
|
2162 int terminator);
|
|
2163 static Lisp_Object read_vector (Lisp_Object readcharfun, int terminator);
|
|
2164
|
|
2165 /* Get the next character; filter out whitespace and comments */
|
|
2166
|
|
2167 static Emchar
|
|
2168 reader_nextchar (Lisp_Object readcharfun)
|
|
2169 {
|
|
2170 /* This function can GC */
|
|
2171 Emchar c;
|
|
2172
|
|
2173 retry:
|
|
2174 QUIT;
|
|
2175 c = readchar (readcharfun);
|
|
2176 if (c < 0)
|
563
|
2177 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun));
|
428
|
2178
|
|
2179 switch (c)
|
|
2180 {
|
|
2181 default:
|
|
2182 {
|
|
2183 /* Ignore whitespace and control characters */
|
|
2184 if (c <= 040)
|
|
2185 goto retry;
|
|
2186 return c;
|
|
2187 }
|
|
2188
|
|
2189 case ';':
|
|
2190 {
|
|
2191 /* Comment */
|
|
2192 while ((c = readchar (readcharfun)) >= 0 && c != '\n')
|
|
2193 QUIT;
|
|
2194 goto retry;
|
|
2195 }
|
|
2196 }
|
|
2197 }
|
|
2198
|
|
2199 #if 0
|
|
2200 static Lisp_Object
|
|
2201 list2_pure (int pure, Lisp_Object a, Lisp_Object b)
|
|
2202 {
|
|
2203 return pure ? pure_cons (a, pure_cons (b, Qnil)) : list2 (a, b);
|
|
2204 }
|
|
2205 #endif
|
|
2206
|
|
2207 /* Read the next Lisp object from the stream READCHARFUN and return it.
|
|
2208 If the return value is a cons whose car is Qunbound, then read1()
|
|
2209 encountered a misplaced token (e.g. a right bracket, right paren,
|
|
2210 or dot followed by a non-number). To filter this stuff out,
|
|
2211 use read0(). */
|
|
2212
|
|
2213 static Lisp_Object
|
|
2214 read1 (Lisp_Object readcharfun)
|
|
2215 {
|
|
2216 Emchar c;
|
|
2217
|
|
2218 retry:
|
|
2219 c = reader_nextchar (readcharfun);
|
|
2220
|
|
2221 switch (c)
|
|
2222 {
|
|
2223 case '(':
|
|
2224 {
|
|
2225 #ifdef LISP_BACKQUOTES /* old backquote compatibility in lisp reader */
|
|
2226 /* if this is disabled, then other code in eval.c must be enabled */
|
|
2227 Emchar ch = reader_nextchar (readcharfun);
|
|
2228 switch (ch)
|
|
2229 {
|
|
2230 case '`':
|
|
2231 {
|
|
2232 Lisp_Object tem;
|
|
2233 int speccount = specpdl_depth ();
|
|
2234 ++old_backquote_flag;
|
|
2235 record_unwind_protect (backquote_unwind,
|
|
2236 make_opaque_ptr (&old_backquote_flag));
|
|
2237 tem = read0 (readcharfun);
|
771
|
2238 unbind_to (speccount);
|
428
|
2239 ch = reader_nextchar (readcharfun);
|
|
2240 if (ch != ')')
|
|
2241 {
|
|
2242 unreadchar (readcharfun, ch);
|
|
2243 return Fsignal (Qinvalid_read_syntax,
|
771
|
2244 list1 (build_msg_string
|
428
|
2245 ("Weird old-backquote syntax")));
|
|
2246 }
|
|
2247 return list2 (Qbacktick, tem);
|
|
2248 }
|
|
2249 case ',':
|
|
2250 {
|
|
2251 if (old_backquote_flag)
|
|
2252 {
|
|
2253 Lisp_Object tem, comma_type;
|
|
2254 ch = readchar (readcharfun);
|
|
2255 if (ch == '@')
|
|
2256 comma_type = Qcomma_at;
|
|
2257 else
|
|
2258 {
|
|
2259 if (ch >= 0)
|
|
2260 unreadchar (readcharfun, ch);
|
|
2261 comma_type = Qcomma;
|
|
2262 }
|
|
2263 tem = read0 (readcharfun);
|
|
2264 ch = reader_nextchar (readcharfun);
|
|
2265 if (ch != ')')
|
|
2266 {
|
|
2267 unreadchar (readcharfun, ch);
|
|
2268 return Fsignal (Qinvalid_read_syntax,
|
771
|
2269 list1 (build_msg_string
|
428
|
2270 ("Weird old-backquote syntax")));
|
|
2271 }
|
|
2272 return list2 (comma_type, tem);
|
|
2273 }
|
|
2274 else
|
|
2275 {
|
|
2276 unreadchar (readcharfun, ch);
|
|
2277 #if 0
|
|
2278 return Fsignal (Qinvalid_read_syntax,
|
771
|
2279 list1 (build_msg_string ("Comma outside of backquote")));
|
428
|
2280 #else
|
|
2281 /* #### - yuck....but this is reverse compatible. */
|
|
2282 /* mostly this is required by edebug, which does its own
|
|
2283 annotated reading. We need to have an annotated_read
|
|
2284 function that records (with markers) the buffer
|
|
2285 positions of the elements that make up lists, then that
|
|
2286 can be used in edebug and bytecomp and the check above
|
|
2287 can go back in. --Stig */
|
|
2288 break;
|
|
2289 #endif
|
|
2290 }
|
|
2291 }
|
|
2292 default:
|
|
2293 unreadchar (readcharfun, ch);
|
|
2294 } /* switch(ch) */
|
|
2295 #endif /* old backquote crap... */
|
|
2296 return read_list (readcharfun, ')', 1, 1);
|
|
2297 }
|
|
2298 case '[':
|
|
2299 return read_vector (readcharfun, ']');
|
|
2300
|
|
2301 case ')':
|
|
2302 case ']':
|
|
2303 /* #### - huh? these don't do what they seem... */
|
|
2304 return noseeum_cons (Qunbound, make_char (c));
|
|
2305 case '.':
|
|
2306 {
|
|
2307 #ifdef LISP_FLOAT_TYPE
|
|
2308 /* If a period is followed by a number, then we should read it
|
|
2309 as a floating point number. Otherwise, it denotes a dotted
|
|
2310 pair.
|
|
2311 */
|
|
2312 c = readchar (readcharfun);
|
|
2313 unreadchar (readcharfun, c);
|
|
2314
|
|
2315 /* Can't use isdigit on Emchars */
|
|
2316 if (c < '0' || c > '9')
|
|
2317 return noseeum_cons (Qunbound, make_char ('.'));
|
|
2318
|
|
2319 /* Note that read_atom will loop
|
|
2320 at least once, assuring that we will not try to UNREAD
|
|
2321 two characters in a row.
|
|
2322 (I think this doesn't matter anymore because there should
|
|
2323 be no more danger in unreading multiple characters) */
|
|
2324 return read_atom (readcharfun, '.', 0);
|
|
2325
|
|
2326 #else /* ! LISP_FLOAT_TYPE */
|
|
2327 return noseeum_cons (Qunbound, make_char ('.'));
|
|
2328 #endif /* ! LISP_FLOAT_TYPE */
|
|
2329 }
|
|
2330
|
|
2331 case '#':
|
|
2332 {
|
|
2333 c = readchar (readcharfun);
|
|
2334 switch (c)
|
|
2335 {
|
|
2336 #if 0 /* FSFmacs silly char-table syntax */
|
|
2337 case '^':
|
|
2338 #endif
|
|
2339 #if 0 /* FSFmacs silly bool-vector syntax */
|
|
2340 case '&':
|
|
2341 #endif
|
|
2342 /* "#["-- byte-code constant syntax */
|
|
2343 /* purecons #[...] syntax */
|
|
2344 case '[': return read_compiled_function (readcharfun, ']'
|
|
2345 /*, purify_flag */ );
|
|
2346 /* "#:"-- gensym syntax */
|
|
2347 case ':': return read_atom (readcharfun, -1, 1);
|
|
2348 /* #'x => (function x) */
|
|
2349 case '\'': return list2 (Qfunction, read0 (readcharfun));
|
|
2350 #if 0
|
|
2351 /* RMS uses this syntax for fat-strings.
|
|
2352 If we use it for vectors, then obscure bugs happen.
|
|
2353 */
|
|
2354 /* "#(" -- Scheme/CL vector syntax */
|
|
2355 case '(': return read_vector (readcharfun, ')');
|
|
2356 #endif
|
|
2357 #if 0 /* FSFmacs */
|
|
2358 case '(':
|
|
2359 {
|
|
2360 Lisp_Object tmp;
|
|
2361 struct gcpro gcpro1;
|
|
2362
|
|
2363 /* Read the string itself. */
|
|
2364 tmp = read1 (readcharfun);
|
|
2365 if (!STRINGP (tmp))
|
|
2366 {
|
|
2367 if (CONSP (tmp) && UNBOUNDP (XCAR (tmp)))
|
|
2368 free_cons (XCONS (tmp));
|
|
2369 return Fsignal (Qinvalid_read_syntax,
|
|
2370 list1 (build_string ("#")));
|
|
2371 }
|
|
2372 GCPRO1 (tmp);
|
|
2373 /* Read the intervals and their properties. */
|
|
2374 while (1)
|
|
2375 {
|
|
2376 Lisp_Object beg, end, plist;
|
|
2377 Emchar ch;
|
|
2378 int invalid = 0;
|
|
2379
|
|
2380 beg = read1 (readcharfun);
|
|
2381 if (CONSP (beg) && UNBOUNDP (XCAR (beg)))
|
|
2382 {
|
|
2383 ch = XCHAR (XCDR (beg));
|
|
2384 free_cons (XCONS (beg));
|
|
2385 if (ch == ')')
|
|
2386 break;
|
|
2387 else
|
|
2388 invalid = 1;
|
|
2389 }
|
|
2390 if (!invalid)
|
|
2391 {
|
|
2392 end = read1 (readcharfun);
|
|
2393 if (CONSP (end) && UNBOUNDP (XCAR (end)))
|
|
2394 {
|
|
2395 free_cons (XCONS (end));
|
|
2396 invalid = 1;
|
|
2397 }
|
|
2398 }
|
|
2399 if (!invalid)
|
|
2400 {
|
|
2401 plist = read1 (readcharfun);
|
|
2402 if (CONSP (plist) && UNBOUNDP (XCAR (plist)))
|
|
2403 {
|
|
2404 free_cons (XCONS (plist));
|
|
2405 invalid = 1;
|
|
2406 }
|
|
2407 }
|
|
2408 if (invalid)
|
|
2409 RETURN_UNGCPRO
|
|
2410 (Fsignal (Qinvalid_read_syntax,
|
|
2411 list2
|
771
|
2412 (build_msg_string ("invalid string property list"),
|
428
|
2413 XCDR (plist))));
|
|
2414 Fset_text_properties (beg, end, plist, tmp);
|
|
2415 }
|
|
2416 UNGCPRO;
|
|
2417 return tmp;
|
|
2418 }
|
|
2419 #endif /* 0 */
|
|
2420 case '@':
|
|
2421 {
|
|
2422 /* #@NUMBER is used to skip NUMBER following characters.
|
|
2423 That's used in .elc files to skip over doc strings
|
|
2424 and function definitions. */
|
|
2425 int i, nskip = 0;
|
|
2426
|
|
2427 /* Read a decimal integer. */
|
|
2428 while ((c = readchar (readcharfun)) >= 0
|
|
2429 && c >= '0' && c <= '9')
|
|
2430 nskip = (10 * nskip) + (c - '0');
|
|
2431 if (c >= 0)
|
|
2432 unreadchar (readcharfun, c);
|
|
2433
|
|
2434 /* FSF has code here that maybe caches the skipped
|
|
2435 string. See above for why this is totally
|
|
2436 losing. We handle this differently. */
|
|
2437
|
|
2438 /* Skip that many characters. */
|
|
2439 for (i = 0; i < nskip && c >= 0; i++)
|
|
2440 c = readchar (readcharfun);
|
|
2441
|
|
2442 goto retry;
|
|
2443 }
|
|
2444 case '$': return Vload_file_name_internal;
|
|
2445 /* bit vectors */
|
|
2446 case '*': return read_bit_vector (readcharfun);
|
|
2447 /* #o10 => 8 -- octal constant syntax */
|
|
2448 case 'o': return read_integer (readcharfun, 8);
|
|
2449 /* #xdead => 57005 -- hex constant syntax */
|
|
2450 case 'x': return read_integer (readcharfun, 16);
|
|
2451 /* #b010 => 2 -- binary constant syntax */
|
|
2452 case 'b': return read_integer (readcharfun, 2);
|
|
2453 /* #s(foobar key1 val1 key2 val2) -- structure syntax */
|
|
2454 case 's': return read_structure (readcharfun);
|
|
2455 case '<':
|
|
2456 {
|
|
2457 unreadchar (readcharfun, c);
|
|
2458 return Fsignal (Qinvalid_read_syntax,
|
771
|
2459 list1 (build_msg_string ("Cannot read unreadable object")));
|
428
|
2460 }
|
|
2461 #ifdef FEATUREP_SYNTAX
|
|
2462 case '+':
|
|
2463 case '-':
|
|
2464 {
|
456
|
2465 Lisp_Object feature_exp, obj, tem;
|
428
|
2466 struct gcpro gcpro1, gcpro2;
|
|
2467
|
456
|
2468 feature_exp = read0(readcharfun);
|
428
|
2469 obj = read0(readcharfun);
|
|
2470
|
|
2471 /* the call to `featurep' may GC. */
|
456
|
2472 GCPRO2 (feature_exp, obj);
|
|
2473 tem = call1 (Qfeaturep, feature_exp);
|
428
|
2474 UNGCPRO;
|
|
2475
|
|
2476 if (c == '+' && NILP(tem)) goto retry;
|
|
2477 if (c == '-' && !NILP(tem)) goto retry;
|
|
2478 return obj;
|
|
2479 }
|
|
2480 #endif
|
|
2481 case '0': case '1': case '2': case '3': case '4':
|
|
2482 case '5': case '6': case '7': case '8': case '9':
|
|
2483 /* Reader forms that can reuse previously read objects. */
|
|
2484 {
|
|
2485 int n = 0;
|
|
2486 Lisp_Object found;
|
|
2487
|
|
2488 /* Using read_integer() here is impossible, because it
|
|
2489 chokes on `='. Using parse_integer() is too hard.
|
|
2490 So we simply read it in, and ignore overflows, which
|
|
2491 is safe. */
|
|
2492 while (c >= '0' && c <= '9')
|
|
2493 {
|
|
2494 n *= 10;
|
|
2495 n += c - '0';
|
|
2496 c = readchar (readcharfun);
|
|
2497 }
|
|
2498 found = assq_no_quit (make_int (n), Vread_objects);
|
|
2499 if (c == '=')
|
|
2500 {
|
|
2501 /* #n=object returns object, but associates it with
|
|
2502 n for #n#. */
|
|
2503 Lisp_Object obj;
|
|
2504 if (CONSP (found))
|
|
2505 return Fsignal (Qinvalid_read_syntax,
|
771
|
2506 list2 (build_msg_string
|
428
|
2507 ("Multiply defined symbol label"),
|
|
2508 make_int (n)));
|
|
2509 obj = read0 (readcharfun);
|
|
2510 Vread_objects = Fcons (Fcons (make_int (n), obj),
|
|
2511 Vread_objects);
|
|
2512 return obj;
|
|
2513 }
|
|
2514 else if (c == '#')
|
|
2515 {
|
|
2516 /* #n# returns a previously read object. */
|
|
2517 if (CONSP (found))
|
|
2518 return XCDR (found);
|
|
2519 else
|
|
2520 return Fsignal (Qinvalid_read_syntax,
|
771
|
2521 list2 (build_msg_string
|
428
|
2522 ("Undefined symbol label"),
|
|
2523 make_int (n)));
|
|
2524 }
|
|
2525 return Fsignal (Qinvalid_read_syntax,
|
|
2526 list1 (build_string ("#")));
|
|
2527 }
|
|
2528 default:
|
|
2529 {
|
|
2530 unreadchar (readcharfun, c);
|
|
2531 return Fsignal (Qinvalid_read_syntax,
|
|
2532 list1 (build_string ("#")));
|
|
2533 }
|
|
2534 }
|
|
2535 }
|
|
2536
|
|
2537 /* Quote */
|
|
2538 case '\'': return list2 (Qquote, read0 (readcharfun));
|
|
2539
|
|
2540 #ifdef LISP_BACKQUOTES
|
|
2541 case '`':
|
|
2542 {
|
|
2543 Lisp_Object tem;
|
|
2544 int speccount = specpdl_depth ();
|
|
2545 ++new_backquote_flag;
|
|
2546 record_unwind_protect (backquote_unwind,
|
|
2547 make_opaque_ptr (&new_backquote_flag));
|
|
2548 tem = read0 (readcharfun);
|
771
|
2549 unbind_to (speccount);
|
428
|
2550 return list2 (Qbackquote, tem);
|
|
2551 }
|
|
2552
|
|
2553 case ',':
|
|
2554 {
|
|
2555 if (new_backquote_flag)
|
|
2556 {
|
|
2557 Lisp_Object comma_type = Qnil;
|
|
2558 int ch = readchar (readcharfun);
|
|
2559
|
|
2560 if (ch == '@')
|
|
2561 comma_type = Qcomma_at;
|
|
2562 else if (ch == '.')
|
|
2563 comma_type = Qcomma_dot;
|
|
2564 else
|
|
2565 {
|
|
2566 if (ch >= 0)
|
|
2567 unreadchar (readcharfun, ch);
|
|
2568 comma_type = Qcomma;
|
|
2569 }
|
|
2570 return list2 (comma_type, read0 (readcharfun));
|
|
2571 }
|
|
2572 else
|
|
2573 {
|
|
2574 /* YUCK. 99.999% backwards compatibility. The Right
|
|
2575 Thing(tm) is to signal an error here, because it's
|
|
2576 really invalid read syntax. Instead, this permits
|
|
2577 commas to begin symbols (unless they're inside
|
|
2578 backquotes). If an error is signalled here in the
|
|
2579 future, then commas should be invalid read syntax
|
|
2580 outside of backquotes anywhere they're found (i.e.
|
|
2581 they must be quoted in symbols) -- Stig */
|
|
2582 return read_atom (readcharfun, c, 0);
|
|
2583 }
|
|
2584 }
|
|
2585 #endif
|
|
2586
|
|
2587 case '?':
|
|
2588 {
|
|
2589 /* Evil GNU Emacs "character" (ie integer) syntax */
|
|
2590 c = readchar (readcharfun);
|
|
2591 if (c < 0)
|
|
2592 return Fsignal (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun)));
|
|
2593
|
|
2594 if (c == '\\')
|
|
2595 c = read_escape (readcharfun);
|
|
2596 return make_char (c);
|
|
2597 }
|
|
2598
|
|
2599 case '\"':
|
|
2600 {
|
|
2601 /* String */
|
|
2602 #ifdef I18N3
|
|
2603 /* #### If the input stream is translating, then the string
|
|
2604 should be marked as translatable by setting its
|
|
2605 `string-translatable' property to t. .el and .elc files
|
|
2606 normally are translating input streams. See Fgettext()
|
|
2607 and print_internal(). */
|
|
2608 #endif
|
|
2609 int cancel = 0;
|
|
2610
|
|
2611 Lstream_rewind (XLSTREAM (Vread_buffer_stream));
|
|
2612 while ((c = readchar (readcharfun)) >= 0
|
|
2613 && c != '\"')
|
|
2614 {
|
|
2615 if (c == '\\')
|
|
2616 c = read_escape (readcharfun);
|
|
2617 /* c is -1 if \ newline has just been seen */
|
|
2618 if (c == -1)
|
|
2619 {
|
|
2620 if (Lstream_byte_count (XLSTREAM (Vread_buffer_stream)) == 0)
|
|
2621 cancel = 1;
|
|
2622 }
|
|
2623 else
|
|
2624 Lstream_put_emchar (XLSTREAM (Vread_buffer_stream), c);
|
|
2625 QUIT;
|
|
2626 }
|
|
2627 if (c < 0)
|
|
2628 return Fsignal (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun)));
|
|
2629
|
|
2630 /* If purifying, and string starts with \ newline,
|
|
2631 return zero instead. This is for doc strings
|
|
2632 that we are really going to find in lib-src/DOC.nn.nn */
|
|
2633 if (purify_flag && NILP (Vinternal_doc_file_name) && cancel)
|
|
2634 return Qzero;
|
|
2635
|
|
2636 Lstream_flush (XLSTREAM (Vread_buffer_stream));
|
|
2637 return
|
|
2638 make_string
|
|
2639 (resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)),
|
|
2640 Lstream_byte_count (XLSTREAM (Vread_buffer_stream)));
|
|
2641 }
|
|
2642
|
|
2643 default:
|
|
2644 {
|
|
2645 /* Ignore whitespace and control characters */
|
|
2646 if (c <= 040)
|
|
2647 goto retry;
|
|
2648 return read_atom (readcharfun, c, 0);
|
|
2649 }
|
|
2650 }
|
|
2651 }
|
|
2652
|
|
2653
|
|
2654
|
|
2655 #ifdef LISP_FLOAT_TYPE
|
|
2656
|
|
2657 #define LEAD_INT 1
|
|
2658 #define DOT_CHAR 2
|
|
2659 #define TRAIL_INT 4
|
|
2660 #define E_CHAR 8
|
|
2661 #define EXP_INT 16
|
|
2662
|
|
2663 int
|
442
|
2664 isfloat_string (const char *cp)
|
428
|
2665 {
|
|
2666 int state = 0;
|
665
|
2667 const Intbyte *ucp = (const Intbyte *) cp;
|
428
|
2668
|
|
2669 if (*ucp == '+' || *ucp == '-')
|
|
2670 ucp++;
|
|
2671
|
|
2672 if (*ucp >= '0' && *ucp <= '9')
|
|
2673 {
|
|
2674 state |= LEAD_INT;
|
|
2675 while (*ucp >= '0' && *ucp <= '9')
|
|
2676 ucp++;
|
|
2677 }
|
|
2678 if (*ucp == '.')
|
|
2679 {
|
|
2680 state |= DOT_CHAR;
|
|
2681 ucp++;
|
|
2682 }
|
|
2683 if (*ucp >= '0' && *ucp <= '9')
|
|
2684 {
|
|
2685 state |= TRAIL_INT;
|
|
2686 while (*ucp >= '0' && *ucp <= '9')
|
|
2687 ucp++;
|
|
2688 }
|
|
2689 if (*ucp == 'e' || *ucp == 'E')
|
|
2690 {
|
|
2691 state |= E_CHAR;
|
|
2692 ucp++;
|
|
2693 if ((*ucp == '+') || (*ucp == '-'))
|
|
2694 ucp++;
|
|
2695 }
|
|
2696
|
|
2697 if (*ucp >= '0' && *ucp <= '9')
|
|
2698 {
|
|
2699 state |= EXP_INT;
|
|
2700 while (*ucp >= '0' && *ucp <= '9')
|
|
2701 ucp++;
|
|
2702 }
|
|
2703 return (((*ucp == 0) || (*ucp == ' ') || (*ucp == '\t') || (*ucp == '\n')
|
|
2704 || (*ucp == '\r') || (*ucp == '\f'))
|
|
2705 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
|
|
2706 || state == (DOT_CHAR|TRAIL_INT)
|
|
2707 || state == (LEAD_INT|E_CHAR|EXP_INT)
|
|
2708 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)
|
|
2709 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)));
|
|
2710 }
|
|
2711 #endif /* LISP_FLOAT_TYPE */
|
|
2712
|
|
2713 static void *
|
|
2714 sequence_reader (Lisp_Object readcharfun,
|
|
2715 Emchar terminator,
|
|
2716 void *state,
|
|
2717 void * (*conser) (Lisp_Object readcharfun,
|
|
2718 void *state, Charcount len))
|
|
2719 {
|
|
2720 Charcount len;
|
|
2721
|
|
2722 for (len = 0; ; len++)
|
|
2723 {
|
|
2724 Emchar ch;
|
|
2725
|
|
2726 QUIT;
|
|
2727 ch = reader_nextchar (readcharfun);
|
|
2728
|
|
2729 if (ch == terminator)
|
|
2730 return state;
|
|
2731 else
|
|
2732 unreadchar (readcharfun, ch);
|
|
2733 #ifdef FEATUREP_SYNTAX
|
|
2734 if (ch == ']')
|
442
|
2735 read_syntax_error ("\"]\" in a list");
|
428
|
2736 else if (ch == ')')
|
442
|
2737 read_syntax_error ("\")\" in a vector");
|
428
|
2738 #endif
|
|
2739 state = ((conser) (readcharfun, state, len));
|
|
2740 }
|
|
2741 }
|
|
2742
|
|
2743
|
|
2744 struct read_list_state
|
|
2745 {
|
|
2746 Lisp_Object head;
|
|
2747 Lisp_Object tail;
|
|
2748 int length;
|
|
2749 int allow_dotted_lists;
|
|
2750 Emchar terminator;
|
|
2751 };
|
|
2752
|
|
2753 static void *
|
|
2754 read_list_conser (Lisp_Object readcharfun, void *state, Charcount len)
|
|
2755 {
|
|
2756 struct read_list_state *s = (struct read_list_state *) state;
|
|
2757 Lisp_Object elt;
|
|
2758
|
|
2759 elt = read1 (readcharfun);
|
|
2760
|
|
2761 if (CONSP (elt) && UNBOUNDP (XCAR (elt)))
|
|
2762 {
|
|
2763 Lisp_Object tem = elt;
|
|
2764 Emchar ch;
|
|
2765
|
|
2766 elt = XCDR (elt);
|
|
2767 free_cons (XCONS (tem));
|
|
2768 tem = Qnil;
|
|
2769 ch = XCHAR (elt);
|
|
2770 #ifdef FEATUREP_SYNTAX
|
|
2771 if (ch == s->terminator) /* deal with #+, #- reader macros */
|
|
2772 {
|
|
2773 unreadchar (readcharfun, s->terminator);
|
|
2774 goto done;
|
|
2775 }
|
|
2776 else if (ch == ']')
|
442
|
2777 read_syntax_error ("']' in a list");
|
428
|
2778 else if (ch == ')')
|
442
|
2779 read_syntax_error ("')' in a vector");
|
428
|
2780 else
|
|
2781 #endif
|
|
2782 if (ch != '.')
|
563
|
2783 signal_error (Qinternal_error, "BUG! Internal reader error", elt);
|
428
|
2784 else if (!s->allow_dotted_lists)
|
442
|
2785 read_syntax_error ("\".\" in a vector");
|
428
|
2786 else
|
|
2787 {
|
|
2788 if (!NILP (s->tail))
|
|
2789 XCDR (s->tail) = read0 (readcharfun);
|
|
2790 else
|
|
2791 s->head = read0 (readcharfun);
|
|
2792 elt = read1 (readcharfun);
|
|
2793 if (CONSP (elt) && UNBOUNDP (XCAR (elt)))
|
|
2794 {
|
|
2795 ch = XCHAR (XCDR (elt));
|
|
2796 free_cons (XCONS (elt));
|
|
2797 if (ch == s->terminator)
|
|
2798 {
|
|
2799 unreadchar (readcharfun, s->terminator);
|
|
2800 goto done;
|
|
2801 }
|
|
2802 }
|
442
|
2803 read_syntax_error (". in wrong context");
|
428
|
2804 }
|
|
2805 }
|
|
2806
|
|
2807 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
2808 if (s->length == 1 && s->allow_dotted_lists && EQ (XCAR (s->head), Qfset))
|
|
2809 {
|
|
2810 if (CONSP (elt) && EQ (XCAR (elt), Qquote) && CONSP (XCDR (elt)))
|
|
2811 Vcurrent_compiled_function_annotation = XCAR (XCDR (elt));
|
|
2812 else
|
|
2813 Vcurrent_compiled_function_annotation = elt;
|
|
2814 }
|
|
2815 #endif
|
|
2816
|
|
2817 elt = Fcons (elt, Qnil);
|
|
2818 if (!NILP (s->tail))
|
|
2819 XCDR (s->tail) = elt;
|
|
2820 else
|
|
2821 s->head = elt;
|
|
2822 s->tail = elt;
|
|
2823 done:
|
|
2824 s->length++;
|
|
2825 return s;
|
|
2826 }
|
|
2827
|
|
2828
|
814
|
2829 /* allow_dotted_lists means that something like (foo bar . baz)
|
|
2830 is acceptable. If -1, means check for starting with defun
|
|
2831 and make structure pure. (not implemented, probably for very
|
|
2832 good reasons)
|
|
2833
|
|
2834 If check_for_doc_references, look for (#$ . INT) doc references
|
|
2835 in the list and record if load_force_doc_strings is non-zero.
|
|
2836 (Such doc references will be destroyed during the loadup phase
|
|
2837 by replacing with Qzero, because Snarf-documentation will fill
|
|
2838 them in again.)
|
|
2839
|
|
2840 WARNING: If you set this, you sure as hell better not call
|
|
2841 free_list() on the returned list here.
|
|
2842 */
|
428
|
2843
|
|
2844 static Lisp_Object
|
|
2845 read_list (Lisp_Object readcharfun,
|
|
2846 Emchar terminator,
|
|
2847 int allow_dotted_lists,
|
|
2848 int check_for_doc_references)
|
|
2849 {
|
|
2850 struct read_list_state s;
|
|
2851 struct gcpro gcpro1, gcpro2;
|
|
2852 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
2853 Lisp_Object old_compiled_function_annotation =
|
|
2854 Vcurrent_compiled_function_annotation;
|
|
2855 #endif
|
|
2856
|
|
2857 s.head = Qnil;
|
|
2858 s.tail = Qnil;
|
|
2859 s.length = 0;
|
|
2860 s.allow_dotted_lists = allow_dotted_lists;
|
|
2861 s.terminator = terminator;
|
|
2862 GCPRO2 (s.head, s.tail);
|
|
2863
|
|
2864 sequence_reader (readcharfun, terminator, &s, read_list_conser);
|
|
2865 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
2866 Vcurrent_compiled_function_annotation = old_compiled_function_annotation;
|
|
2867 #endif
|
|
2868
|
|
2869 if ((purify_flag || load_force_doc_strings) && check_for_doc_references)
|
|
2870 {
|
|
2871 /* check now for any doc string references and record them
|
|
2872 for later. */
|
|
2873 Lisp_Object tail;
|
|
2874
|
|
2875 /* We might be dealing with an imperfect list so don't
|
|
2876 use LIST_LOOP */
|
|
2877 for (tail = s.head; CONSP (tail); tail = XCDR (tail))
|
|
2878 {
|
|
2879 Lisp_Object holding_cons = Qnil;
|
|
2880
|
|
2881 {
|
|
2882 Lisp_Object elem = XCAR (tail);
|
|
2883 /* elem might be (#$ . INT) ... */
|
|
2884 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal))
|
|
2885 holding_cons = tail;
|
|
2886 /* or it might be (quote (#$ . INT)) i.e.
|
|
2887 (quote . ((#$ . INT) . nil)) in the case of
|
|
2888 `autoload' (autoload evaluates its arguments, while
|
|
2889 `defvar', `defun', etc. don't). */
|
|
2890 if (CONSP (elem) && EQ (XCAR (elem), Qquote)
|
|
2891 && CONSP (XCDR (elem)))
|
|
2892 {
|
|
2893 elem = XCAR (XCDR (elem));
|
|
2894 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal))
|
|
2895 holding_cons = XCDR (XCAR (tail));
|
|
2896 }
|
|
2897 }
|
|
2898
|
|
2899 if (CONSP (holding_cons))
|
|
2900 {
|
|
2901 if (purify_flag)
|
|
2902 {
|
|
2903 if (NILP (Vinternal_doc_file_name))
|
|
2904 /* We have not yet called Snarf-documentation, so
|
|
2905 assume this file is described in the DOC file
|
|
2906 and Snarf-documentation will fill in the right
|
|
2907 value later. For now, replace the whole list
|
|
2908 with 0. */
|
|
2909 XCAR (holding_cons) = Qzero;
|
|
2910 else
|
|
2911 /* We have already called Snarf-documentation, so
|
|
2912 make a relative file name for this file, so it
|
|
2913 can be found properly in the installed Lisp
|
|
2914 directory. We don't use Fexpand_file_name
|
|
2915 because that would make the directory absolute
|
|
2916 now. */
|
|
2917 XCAR (XCAR (holding_cons)) =
|
|
2918 concat2 (build_string ("../lisp/"),
|
|
2919 Ffile_name_nondirectory
|
|
2920 (Vload_file_name_internal));
|
|
2921 }
|
|
2922 else
|
|
2923 /* Not pure. Just add to Vload_force_doc_string_list,
|
|
2924 and the string will be filled in properly in
|
|
2925 load_force_doc_string_unwind(). */
|
|
2926 Vload_force_doc_string_list =
|
|
2927 /* We pass the cons that holds the (#$ . INT) so we
|
|
2928 can modify it in-place. */
|
|
2929 Fcons (holding_cons, Vload_force_doc_string_list);
|
|
2930 }
|
|
2931 }
|
|
2932 }
|
|
2933
|
|
2934 UNGCPRO;
|
|
2935 return s.head;
|
|
2936 }
|
|
2937
|
|
2938 static Lisp_Object
|
|
2939 read_vector (Lisp_Object readcharfun,
|
|
2940 Emchar terminator)
|
|
2941 {
|
|
2942 Lisp_Object tem;
|
|
2943 Lisp_Object *p;
|
|
2944 int len;
|
|
2945 int i;
|
|
2946 struct read_list_state s;
|
|
2947 struct gcpro gcpro1, gcpro2;
|
|
2948
|
|
2949 s.head = Qnil;
|
|
2950 s.tail = Qnil;
|
|
2951 s.length = 0;
|
|
2952 s.allow_dotted_lists = 0;
|
|
2953 GCPRO2 (s.head, s.tail);
|
|
2954
|
|
2955 sequence_reader (readcharfun, terminator, &s, read_list_conser);
|
|
2956
|
|
2957 UNGCPRO;
|
|
2958 tem = s.head;
|
|
2959 len = XINT (Flength (tem));
|
|
2960
|
814
|
2961 s.head = make_vector (len, Qnil);
|
428
|
2962
|
|
2963 for (i = 0, p = &(XVECTOR_DATA (s.head)[0]);
|
|
2964 i < len;
|
|
2965 i++, p++)
|
|
2966 {
|
440
|
2967 Lisp_Cons *otem = XCONS (tem);
|
428
|
2968 tem = Fcar (tem);
|
|
2969 *p = tem;
|
|
2970 tem = otem->cdr;
|
|
2971 free_cons (otem);
|
|
2972 }
|
|
2973 return s.head;
|
|
2974 }
|
|
2975
|
|
2976 static Lisp_Object
|
|
2977 read_compiled_function (Lisp_Object readcharfun, Emchar terminator)
|
|
2978 {
|
|
2979 /* Accept compiled functions at read-time so that we don't
|
|
2980 have to build them at load-time. */
|
|
2981 Lisp_Object stuff;
|
|
2982 Lisp_Object make_byte_code_args[COMPILED_DOMAIN + 1];
|
|
2983 struct gcpro gcpro1;
|
|
2984 int len;
|
|
2985 int iii;
|
|
2986 int saw_a_doc_ref = 0;
|
|
2987
|
|
2988 /* Note: we tell read_list not to search for doc references
|
|
2989 because we need to handle the "doc reference" for the
|
|
2990 instructions and constants differently. */
|
|
2991 stuff = read_list (readcharfun, terminator, 0, 0);
|
|
2992 len = XINT (Flength (stuff));
|
|
2993 if (len < COMPILED_STACK_DEPTH + 1 || len > COMPILED_DOMAIN + 1)
|
|
2994 return
|
442
|
2995 continuable_read_syntax_error ("#[...] used with wrong number of elements");
|
428
|
2996
|
|
2997 for (iii = 0; CONSP (stuff); iii++)
|
|
2998 {
|
440
|
2999 Lisp_Cons *victim = XCONS (stuff);
|
428
|
3000 make_byte_code_args[iii] = Fcar (stuff);
|
|
3001 if ((purify_flag || load_force_doc_strings)
|
|
3002 && CONSP (make_byte_code_args[iii])
|
|
3003 && EQ (XCAR (make_byte_code_args[iii]), Vload_file_name_internal))
|
|
3004 {
|
|
3005 if (purify_flag && iii == COMPILED_DOC_STRING)
|
|
3006 {
|
|
3007 /* same as in read_list(). */
|
|
3008 if (NILP (Vinternal_doc_file_name))
|
|
3009 make_byte_code_args[iii] = Qzero;
|
|
3010 else
|
|
3011 XCAR (make_byte_code_args[iii]) =
|
|
3012 concat2 (build_string ("../lisp/"),
|
|
3013 Ffile_name_nondirectory
|
|
3014 (Vload_file_name_internal));
|
|
3015 }
|
|
3016 else
|
|
3017 saw_a_doc_ref = 1;
|
|
3018 }
|
|
3019 stuff = Fcdr (stuff);
|
|
3020 free_cons (victim);
|
|
3021 }
|
|
3022 GCPRO1 (make_byte_code_args[0]);
|
|
3023 gcpro1.nvars = len;
|
|
3024
|
|
3025 /* v18 or v19 bytecode file. Need to Ebolify. */
|
|
3026 if (load_byte_code_version < 20 && VECTORP (make_byte_code_args[2]))
|
|
3027 ebolify_bytecode_constants (make_byte_code_args[2]);
|
|
3028
|
|
3029 /* make-byte-code looks at purify_flag, which should have the same
|
|
3030 * value as our "read-pure" argument */
|
|
3031 stuff = Fmake_byte_code (len, make_byte_code_args);
|
|
3032 XCOMPILED_FUNCTION (stuff)->flags.ebolified = (load_byte_code_version < 20);
|
|
3033 if (saw_a_doc_ref)
|
|
3034 Vload_force_doc_string_list = Fcons (stuff, Vload_force_doc_string_list);
|
|
3035 UNGCPRO;
|
|
3036 return stuff;
|
|
3037 }
|
|
3038
|
|
3039
|
|
3040
|
|
3041 void
|
|
3042 init_lread (void)
|
|
3043 {
|
|
3044 Vvalues = Qnil;
|
|
3045
|
|
3046 load_in_progress = 0;
|
|
3047
|
|
3048 Vload_descriptor_list = Qnil;
|
|
3049
|
|
3050 /* kludge: locate-file does not work for a null load-path, even if
|
|
3051 the file name is absolute. */
|
|
3052
|
|
3053 Vload_path = Fcons (build_string (""), Qnil);
|
|
3054
|
|
3055 /* This used to get initialized in init_lread because all streams
|
|
3056 got closed when dumping occurs. This is no longer true --
|
|
3057 Vread_buffer_stream is a resizing output stream, and there is no
|
|
3058 reason to close it at dump-time.
|
|
3059
|
|
3060 Vread_buffer_stream is set to Qnil in vars_of_lread, and this
|
|
3061 will initialize it only once, at dump-time. */
|
|
3062 if (NILP (Vread_buffer_stream))
|
|
3063 Vread_buffer_stream = make_resizing_buffer_output_stream ();
|
|
3064
|
|
3065 Vload_force_doc_string_list = Qnil;
|
|
3066 }
|
|
3067
|
|
3068 void
|
|
3069 syms_of_lread (void)
|
|
3070 {
|
|
3071 DEFSUBR (Fread);
|
|
3072 DEFSUBR (Fread_from_string);
|
|
3073 DEFSUBR (Fload_internal);
|
|
3074 DEFSUBR (Flocate_file);
|
|
3075 DEFSUBR (Flocate_file_clear_hashing);
|
|
3076 DEFSUBR (Feval_buffer);
|
|
3077 DEFSUBR (Feval_region);
|
|
3078
|
563
|
3079 DEFSYMBOL (Qstandard_input);
|
|
3080 DEFSYMBOL (Qread_char);
|
|
3081 DEFSYMBOL (Qcurrent_load_list);
|
|
3082 DEFSYMBOL (Qload);
|
|
3083 DEFSYMBOL (Qload_file_name);
|
|
3084 DEFSYMBOL (Qfset);
|
428
|
3085
|
|
3086 #ifdef LISP_BACKQUOTES
|
563
|
3087 DEFSYMBOL (Qbackquote);
|
428
|
3088 defsymbol (&Qbacktick, "`");
|
|
3089 defsymbol (&Qcomma, ",");
|
|
3090 defsymbol (&Qcomma_at, ",@");
|
|
3091 defsymbol (&Qcomma_dot, ",.");
|
|
3092 #endif
|
|
3093
|
563
|
3094 DEFSYMBOL (Qexists);
|
|
3095 DEFSYMBOL (Qreadable);
|
|
3096 DEFSYMBOL (Qwritable);
|
|
3097 DEFSYMBOL (Qexecutable);
|
428
|
3098 }
|
|
3099
|
|
3100 void
|
|
3101 structure_type_create (void)
|
|
3102 {
|
|
3103 the_structure_type_dynarr = Dynarr_new (structure_type);
|
|
3104 }
|
|
3105
|
|
3106 void
|
|
3107 reinit_vars_of_lread (void)
|
|
3108 {
|
|
3109 Vread_buffer_stream = Qnil;
|
|
3110 staticpro_nodump (&Vread_buffer_stream);
|
|
3111 }
|
|
3112
|
|
3113 void
|
|
3114 vars_of_lread (void)
|
|
3115 {
|
|
3116 reinit_vars_of_lread ();
|
|
3117
|
|
3118 DEFVAR_LISP ("values", &Vvalues /*
|
|
3119 List of values of all expressions which were read, evaluated and printed.
|
|
3120 Order is reverse chronological.
|
|
3121 */ );
|
|
3122
|
|
3123 DEFVAR_LISP ("standard-input", &Vstandard_input /*
|
|
3124 Stream for read to get input from.
|
|
3125 See documentation of `read' for possible values.
|
|
3126 */ );
|
|
3127 Vstandard_input = Qt;
|
|
3128
|
|
3129 DEFVAR_LISP ("load-path", &Vload_path /*
|
|
3130 *List of directories to search for files to load.
|
|
3131 Each element is a string (directory name) or nil (try default directory).
|
|
3132
|
|
3133 Note that the elements of this list *may not* begin with "~", so you must
|
|
3134 call `expand-file-name' on them before adding them to this list.
|
|
3135
|
|
3136 Initialized based on EMACSLOADPATH environment variable, if any,
|
|
3137 otherwise to default specified in by file `paths.h' when XEmacs was built.
|
|
3138 If there were no paths specified in `paths.h', then XEmacs chooses a default
|
|
3139 value for this variable by looking around in the file-system near the
|
|
3140 directory in which the XEmacs executable resides.
|
|
3141 */ );
|
|
3142 Vload_path = Qnil;
|
|
3143
|
|
3144 /* xxxDEFVAR_LISP ("dump-load-path", &Vdump_load_path,
|
|
3145 "*Location of lisp files to be used when dumping ONLY."); */
|
|
3146
|
|
3147 DEFVAR_BOOL ("load-in-progress", &load_in_progress /*
|
|
3148 Non-nil iff inside of `load'.
|
|
3149 */ );
|
|
3150
|
|
3151 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist /*
|
|
3152 An alist of expressions to be evalled when particular files are loaded.
|
|
3153 Each element looks like (FILENAME FORMS...).
|
|
3154 When `load' is run and the file-name argument is FILENAME,
|
|
3155 the FORMS in the corresponding element are executed at the end of loading.
|
|
3156
|
|
3157 FILENAME must match exactly! Normally FILENAME is the name of a library,
|
|
3158 with no directory specified, since that is how `load' is normally called.
|
|
3159 An error in FORMS does not undo the load,
|
|
3160 but does prevent execution of the rest of the FORMS.
|
|
3161 */ );
|
|
3162 Vafter_load_alist = Qnil;
|
|
3163
|
|
3164 DEFVAR_BOOL ("load-warn-when-source-newer", &load_warn_when_source_newer /*
|
|
3165 *Whether `load' should check whether the source is newer than the binary.
|
|
3166 If this variable is true, then when a `.elc' file is being loaded and the
|
|
3167 corresponding `.el' is newer, a warning message will be printed.
|
|
3168 */ );
|
|
3169 load_warn_when_source_newer = 0;
|
|
3170
|
|
3171 DEFVAR_BOOL ("load-warn-when-source-only", &load_warn_when_source_only /*
|
|
3172 *Whether `load' should warn when loading a `.el' file instead of an `.elc'.
|
|
3173 If this variable is true, then when `load' is called with a filename without
|
|
3174 an extension, and the `.elc' version doesn't exist but the `.el' version does,
|
|
3175 then a message will be printed. If an explicit extension is passed to `load',
|
|
3176 no warning will be printed.
|
|
3177 */ );
|
|
3178 load_warn_when_source_only = 0;
|
|
3179
|
|
3180 DEFVAR_BOOL ("load-ignore-elc-files", &load_ignore_elc_files /*
|
|
3181 *Whether `load' should ignore `.elc' files when a suffix is not given.
|
|
3182 This is normally used only to bootstrap the `.elc' files when building XEmacs.
|
|
3183 */ );
|
|
3184 load_ignore_elc_files = 0;
|
|
3185
|
|
3186 #ifdef LOADHIST
|
|
3187 DEFVAR_LISP ("load-history", &Vload_history /*
|
|
3188 Alist mapping source file names to symbols and features.
|
|
3189 Each alist element is a list that starts with a file name,
|
|
3190 except for one element (optional) that starts with nil and describes
|
|
3191 definitions evaluated from buffers not visiting files.
|
|
3192 The remaining elements of each list are symbols defined as functions
|
|
3193 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.
|
|
3194 */ );
|
|
3195 Vload_history = Qnil;
|
|
3196
|
|
3197 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list /*
|
|
3198 Used for internal purposes by `load'.
|
|
3199 */ );
|
|
3200 Vcurrent_load_list = Qnil;
|
|
3201 #endif
|
|
3202
|
|
3203 DEFVAR_LISP ("load-file-name", &Vload_file_name /*
|
|
3204 Full name of file being loaded by `load'.
|
|
3205 */ );
|
|
3206 Vload_file_name = Qnil;
|
|
3207
|
|
3208 DEFVAR_LISP ("load-read-function", &Vload_read_function /*
|
|
3209 Function used by `load' and `eval-region' for reading expressions.
|
|
3210 The default is nil, which means use the function `read'.
|
|
3211 */ );
|
|
3212 Vload_read_function = Qnil;
|
|
3213
|
|
3214 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings /*
|
|
3215 Non-nil means `load' should force-load all dynamic doc strings.
|
|
3216 This is useful when the file being loaded is a temporary copy.
|
|
3217 */ );
|
|
3218 load_force_doc_strings = 0;
|
|
3219
|
|
3220 /* See read_escape(). */
|
|
3221 #if 0
|
|
3222 /* Used to be named `puke-on-fsf-keys' */
|
|
3223 DEFVAR_BOOL ("fail-on-bucky-bit-character-escapes",
|
|
3224 &fail_on_bucky_bit_character_escapes /*
|
|
3225 Whether `read' should signal an error when it encounters unsupported
|
|
3226 character escape syntaxes or just read them incorrectly.
|
|
3227 */ );
|
|
3228 fail_on_bucky_bit_character_escapes = 0;
|
|
3229 #endif
|
|
3230
|
|
3231 /* This must be initialized in init_lread otherwise it may start out
|
|
3232 with values saved when the image is dumped. */
|
|
3233 staticpro (&Vload_descriptor_list);
|
|
3234
|
|
3235 /* Initialized in init_lread. */
|
|
3236 staticpro (&Vload_force_doc_string_list);
|
|
3237
|
|
3238 Vload_file_name_internal = Qnil;
|
|
3239 staticpro (&Vload_file_name_internal);
|
|
3240
|
|
3241 Vload_file_name_internal_the_purecopy = Qnil;
|
|
3242 staticpro (&Vload_file_name_internal_the_purecopy);
|
|
3243
|
|
3244 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
3245 Vcurrent_compiled_function_annotation = Qnil;
|
|
3246 staticpro (&Vcurrent_compiled_function_annotation);
|
|
3247 #endif
|
|
3248
|
|
3249 /* So that early-early stuff will work */
|
|
3250 Ffset (Qload, intern ("load-internal"));
|
|
3251
|
|
3252 #ifdef FEATUREP_SYNTAX
|
563
|
3253 DEFSYMBOL (Qfeaturep);
|
771
|
3254 Fprovide (intern ("xemacs"));
|
428
|
3255 #ifdef INFODOCK
|
771
|
3256 Fprovide (intern ("infodock"));
|
428
|
3257 #endif /* INFODOCK */
|
|
3258 #endif /* FEATUREP_SYNTAX */
|
|
3259
|
|
3260 #ifdef LISP_BACKQUOTES
|
|
3261 old_backquote_flag = new_backquote_flag = 0;
|
|
3262 #endif
|
|
3263
|
|
3264 #ifdef I18N3
|
|
3265 Vfile_domain = Qnil;
|
|
3266 #endif
|
|
3267
|
|
3268 Vread_objects = Qnil;
|
|
3269 staticpro (&Vread_objects);
|
|
3270
|
|
3271 Vlocate_file_hash_table = make_lisp_hash_table (200,
|
|
3272 HASH_TABLE_NON_WEAK,
|
|
3273 HASH_TABLE_EQUAL);
|
|
3274 staticpro (&Vlocate_file_hash_table);
|
|
3275 #ifdef DEBUG_XEMACS
|
|
3276 symbol_value (XSYMBOL (intern ("Vlocate-file-hash-table")))
|
|
3277 = Vlocate_file_hash_table;
|
|
3278 #endif
|
|
3279 }
|