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