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