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
|
272
|
71 int fail_on_bucky_bit_character_escapes;
|
0
|
72
|
140
|
73 /* This symbol is also used in fns.c */
|
|
74 #define FEATUREP_SYNTAX
|
|
75
|
|
76 #ifdef FEATUREP_SYNTAX
|
209
|
77 Lisp_Object Qfeaturep;
|
140
|
78 #endif
|
|
79
|
0
|
80 /* non-zero if inside `load' */
|
|
81 int load_in_progress;
|
|
82
|
|
83 /* Whether Fload_internal() should check whether the .el is newer
|
|
84 when loading .elc */
|
|
85 int load_warn_when_source_newer;
|
|
86 /* Whether Fload_internal() should check whether the .elc doesn't exist */
|
|
87 int load_warn_when_source_only;
|
|
88 /* Whether Fload_internal() should ignore .elc files when no suffix is given */
|
|
89 int load_ignore_elc_files;
|
|
90
|
|
91 /* Directory in which the sources were found. */
|
|
92 Lisp_Object Vsource_directory;
|
|
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))
|
|
796 message_append (" (%d)", purespace_usage() - pure_usage);
|
|
797 else
|
80
|
798 message ("Loading %s ...done (%d)", XSTRING_DATA (file),
|
16
|
799 purespace_usage() - pure_usage);
|
0
|
800 }
|
251
|
801 /*#endif / * DEBUG_XEMACS */
|
0
|
802
|
16
|
803 if (!noninteractive)
|
|
804 PRINT_LOADING_MESSAGE ("done");
|
173
|
805
|
0
|
806 UNGCPRO;
|
|
807 return Qt;
|
|
808 }
|
|
809
|
|
810
|
|
811 #if 0 /* FSFmacs */
|
|
812 /* not used */
|
|
813 static int
|
|
814 complete_filename_p (Lisp_Object pathname)
|
|
815 {
|
16
|
816 REGISTER unsigned char *s = XSTRING_DATA (pathname);
|
0
|
817 return (IS_DIRECTORY_SEP (s[0])
|
16
|
818 || (XSTRING_LENGTH (pathname) > 2
|
0
|
819 && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2]))
|
|
820 #ifdef ALTOS
|
|
821 || *s == '@'
|
|
822 #endif
|
|
823 );
|
|
824 }
|
|
825 #endif /* 0 */
|
|
826
|
20
|
827 DEFUN ("locate-file", Flocate_file, 2, 4, 0, /*
|
0
|
828 Search for FILENAME through PATH-LIST, expanded by one of the optional
|
185
|
829 SUFFIXES (string of suffixes separated by ":"s), checking for access
|
0
|
830 MODE (0|1|2|4 = exists|executable|writeable|readable), default readable.
|
|
831
|
|
832 `locate-file' keeps hash tables of the directories it searches through,
|
|
833 in order to speed things up. It tries valiantly to not get confused in
|
|
834 the face of a changing and unpredictable environment, but can occasionally
|
|
835 get tripped up. In this case, you will have to call
|
|
836 `locate-file-clear-hashing' to get it back on track. See that function
|
|
837 for details.
|
20
|
838 */
|
|
839 (filename, path_list, suffixes, mode))
|
0
|
840 {
|
|
841 /* This function can GC */
|
|
842 Lisp_Object tp;
|
|
843
|
|
844 CHECK_STRING (filename);
|
|
845 if (!NILP (suffixes))
|
272
|
846 CHECK_STRING (suffixes);
|
|
847 if (!NILP (mode))
|
|
848 CHECK_NATNUM (mode);
|
|
849
|
173
|
850 locate_file (path_list, filename,
|
0
|
851 ((NILP (suffixes)) ? "" :
|
16
|
852 (char *) (XSTRING_DATA (suffixes))),
|
0
|
853 &tp, (NILP (mode) ? R_OK : XINT (mode)));
|
|
854 return tp;
|
|
855 }
|
|
856
|
|
857 /* recalculate the hash table for the given string */
|
|
858
|
|
859 static Lisp_Object
|
|
860 locate_file_refresh_hashing (Lisp_Object str)
|
|
861 {
|
|
862 Lisp_Object hash =
|
16
|
863 make_directory_hash_table ((char *) XSTRING_DATA (str));
|
0
|
864 Fput (str, Qlocate_file_hash_table, hash);
|
|
865 return hash;
|
|
866 }
|
|
867
|
|
868 /* find the hash table for the given string, recalculating if necessary */
|
|
869
|
|
870 static Lisp_Object
|
|
871 locate_file_find_directory_hash_table (Lisp_Object str)
|
|
872 {
|
|
873 Lisp_Object hash = Fget (str, Qlocate_file_hash_table, Qnil);
|
|
874 if (NILP (Fhashtablep (hash)))
|
|
875 return locate_file_refresh_hashing (str);
|
|
876 return hash;
|
|
877 }
|
|
878
|
|
879 /* look for STR in PATH, optionally adding suffixes in SUFFIX */
|
|
880
|
|
881 static int
|
|
882 locate_file_in_directory (Lisp_Object path, Lisp_Object str,
|
|
883 CONST char *suffix, Lisp_Object *storeptr,
|
|
884 int mode)
|
|
885 {
|
|
886 /* This function can GC */
|
|
887 int fd;
|
|
888 int fn_size = 100;
|
|
889 char buf[100];
|
|
890 char *fn = buf;
|
|
891 int want_size;
|
|
892 struct stat st;
|
|
893 Lisp_Object filename = Qnil;
|
|
894 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
895 CONST char *nsuffix;
|
|
896
|
|
897 GCPRO3 (path, str, filename);
|
|
898
|
|
899 filename = Fexpand_file_name (str, path);
|
|
900 if (NILP (filename) || NILP (Ffile_name_absolute_p (filename)))
|
|
901 /* If there are non-absolute elts in PATH (eg ".") */
|
|
902 /* Of course, this could conceivably lose if luser sets
|
|
903 default-directory to be something non-absolute ... */
|
|
904 {
|
|
905 if (NILP (filename))
|
|
906 /* NIL means current dirctory */
|
|
907 filename = current_buffer->directory;
|
|
908 else
|
|
909 filename = Fexpand_file_name (filename,
|
|
910 current_buffer->directory);
|
|
911 if (NILP (Ffile_name_absolute_p (filename)))
|
|
912 {
|
|
913 /* Give up on this path element! */
|
|
914 UNGCPRO;
|
|
915 return -1;
|
|
916 }
|
|
917 }
|
|
918 /* Calculate maximum size of any filename made from
|
|
919 this path element/specified file name and any possible suffix. */
|
16
|
920 want_size = strlen (suffix) + XSTRING_LENGTH (filename) + 1;
|
0
|
921 if (fn_size < want_size)
|
|
922 fn = (char *) alloca (fn_size = 100 + want_size);
|
173
|
923
|
0
|
924 nsuffix = suffix;
|
173
|
925
|
0
|
926 /* Loop over suffixes. */
|
|
927 while (1)
|
|
928 {
|
|
929 char *esuffix = (char *) strchr (nsuffix, ':');
|
|
930 int lsuffix = ((esuffix) ? (esuffix - nsuffix) : strlen (nsuffix));
|
173
|
931
|
0
|
932 /* Concatenate path element/specified name with the suffix. */
|
173
|
933 strncpy (fn, (char *) XSTRING_DATA (filename),
|
16
|
934 XSTRING_LENGTH (filename));
|
|
935 fn[XSTRING_LENGTH (filename)] = 0;
|
0
|
936 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
|
|
937 strncat (fn, nsuffix, lsuffix);
|
173
|
938
|
0
|
939 /* Ignore file if it's a directory. */
|
|
940 if (stat (fn, &st) >= 0
|
|
941 && (st.st_mode & S_IFMT) != S_IFDIR)
|
|
942 {
|
|
943 /* Check that we can access or open it. */
|
|
944 if (mode >= 0)
|
|
945 fd = access (fn, mode);
|
|
946 else
|
251
|
947 fd = open (fn, O_RDONLY | OPEN_BINARY, 0);
|
173
|
948
|
0
|
949 if (fd >= 0)
|
|
950 {
|
|
951 /* We succeeded; return this descriptor and filename. */
|
|
952 if (storeptr)
|
|
953 *storeptr = build_string (fn);
|
|
954 UNGCPRO;
|
173
|
955
|
265
|
956 #ifndef WINDOWSNT
|
0
|
957 /* If we actually opened the file, set close-on-exec flag
|
|
958 on the new descriptor so that subprocesses can't whack
|
|
959 at it. */
|
|
960 if (mode < 0)
|
|
961 (void) fcntl (fd, F_SETFD, FD_CLOEXEC);
|
118
|
962 #endif
|
173
|
963
|
0
|
964 return fd;
|
|
965 }
|
|
966 }
|
173
|
967
|
0
|
968 /* Advance to next suffix. */
|
|
969 if (esuffix == 0)
|
|
970 break;
|
|
971 nsuffix += lsuffix + 1;
|
|
972 }
|
173
|
973
|
0
|
974 UNGCPRO;
|
|
975 return -1;
|
|
976 }
|
|
977
|
|
978 /* do the same as locate_file() but don't use any hash tables. */
|
|
979
|
|
980 static int
|
|
981 locate_file_without_hash (Lisp_Object path, Lisp_Object str,
|
|
982 CONST char *suffix, Lisp_Object *storeptr,
|
|
983 int mode)
|
|
984 {
|
|
985 /* This function can GC */
|
|
986 int absolute;
|
|
987 struct gcpro gcpro1;
|
|
988
|
|
989 /* is this necessary? */
|
|
990 GCPRO1 (path);
|
|
991
|
|
992 absolute = !NILP (Ffile_name_absolute_p (str));
|
|
993
|
|
994 for (; !NILP (path); path = Fcdr (path))
|
|
995 {
|
|
996 int val = locate_file_in_directory (Fcar (path), str, suffix,
|
|
997 storeptr, mode);
|
|
998 if (val >= 0)
|
|
999 {
|
|
1000 UNGCPRO;
|
|
1001 return val;
|
|
1002 }
|
|
1003 if (absolute)
|
|
1004 break;
|
|
1005 }
|
173
|
1006
|
0
|
1007 UNGCPRO;
|
|
1008 return -1;
|
|
1009 }
|
|
1010
|
|
1011 /* Construct a list of all files to search for. */
|
|
1012
|
|
1013 static Lisp_Object
|
|
1014 locate_file_construct_suffixed_files (Lisp_Object str, CONST char *suffix)
|
|
1015 {
|
|
1016 int want_size;
|
|
1017 int fn_size = 100;
|
|
1018 char buf[100];
|
|
1019 char *fn = buf;
|
|
1020 CONST char *nsuffix;
|
|
1021 Lisp_Object suffixtab = Qnil;
|
173
|
1022
|
0
|
1023 /* Calculate maximum size of any filename made from
|
|
1024 this path element/specified file name and any possible suffix. */
|
16
|
1025 want_size = strlen (suffix) + XSTRING_LENGTH (str) + 1;
|
0
|
1026 if (fn_size < want_size)
|
|
1027 fn = (char *) alloca (fn_size = 100 + want_size);
|
173
|
1028
|
0
|
1029 nsuffix = suffix;
|
173
|
1030
|
0
|
1031 while (1)
|
|
1032 {
|
|
1033 char *esuffix = (char *) strchr (nsuffix, ':');
|
|
1034 int lsuffix = ((esuffix) ? (esuffix - nsuffix) : strlen (nsuffix));
|
173
|
1035
|
0
|
1036 /* Concatenate path element/specified name with the suffix. */
|
16
|
1037 strncpy (fn, (char *) XSTRING_DATA (str), XSTRING_LENGTH (str));
|
|
1038 fn[XSTRING_LENGTH (str)] = 0;
|
0
|
1039 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
|
|
1040 strncat (fn, nsuffix, lsuffix);
|
173
|
1041
|
0
|
1042 suffixtab = Fcons (build_string (fn), suffixtab);
|
|
1043 /* Advance to next suffix. */
|
|
1044 if (esuffix == 0)
|
|
1045 break;
|
|
1046 nsuffix += lsuffix + 1;
|
|
1047 }
|
|
1048 return Fnreverse (suffixtab);
|
|
1049 }
|
|
1050
|
272
|
1051 DEFUN ("locate-file-clear-hashing", Flocate_file_clear_hashing, 1, 1, 0, /*
|
|
1052 Clear the hash records for the specified list of directories.
|
|
1053 `locate-file' uses a hashing scheme to speed lookup, and will correctly
|
|
1054 track the following environmental changes:
|
|
1055
|
|
1056 -- changes of any sort to the list of directories to be searched.
|
|
1057 -- addition and deletion of non-shadowing files (see below) from the
|
|
1058 directories in the list.
|
|
1059 -- byte-compilation of a .el file into a .elc file.
|
|
1060
|
|
1061 `locate-file' will primarily get confused if you add a file that shadows
|
|
1062 \(i.e. has the same name as) another file further down in the directory list.
|
|
1063 In this case, you must call `locate-file-clear-hashing'.
|
|
1064 */
|
|
1065 (path))
|
|
1066 {
|
|
1067 Lisp_Object pathtail;
|
|
1068
|
|
1069 for (pathtail = path; !NILP (pathtail); pathtail = Fcdr (pathtail))
|
|
1070 {
|
|
1071 Lisp_Object pathel = Fcar (pathtail);
|
|
1072 if (!purified (pathel))
|
|
1073 Fput (pathel, Qlocate_file_hash_table, Qnil);
|
|
1074 }
|
|
1075 return Qnil;
|
|
1076 }
|
|
1077
|
0
|
1078 /* Search for a file whose name is STR, looking in directories
|
|
1079 in the Lisp list PATH, and trying suffixes from SUFFIX.
|
|
1080 SUFFIX is a string containing possible suffixes separated by colons.
|
|
1081 On success, returns a file descriptor. On failure, returns -1.
|
|
1082
|
|
1083 MODE nonnegative means don't open the files,
|
|
1084 just look for one for which access(file,MODE) succeeds. In this case,
|
|
1085 returns 1 on success.
|
|
1086
|
|
1087 If STOREPTR is nonzero, it points to a slot where the name of
|
|
1088 the file actually found should be stored as a Lisp string.
|
|
1089 Nil is stored there on failure.
|
|
1090
|
|
1091 Called openp() in FSFmacs. */
|
|
1092
|
|
1093 int
|
|
1094 locate_file (Lisp_Object path, Lisp_Object str, CONST char *suffix,
|
|
1095 Lisp_Object *storeptr, int mode)
|
|
1096 {
|
|
1097 /* This function can GC */
|
|
1098 Lisp_Object suffixtab = Qnil;
|
|
1099 Lisp_Object pathtail;
|
|
1100 int val;
|
|
1101 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1102
|
|
1103 if (storeptr)
|
|
1104 *storeptr = Qnil;
|
|
1105
|
|
1106 /* if this filename has directory components, it's too complicated
|
|
1107 to try and use the hash tables. */
|
|
1108 if (!NILP (Ffile_name_directory (str)))
|
|
1109 return locate_file_without_hash (path, str, suffix, storeptr,
|
|
1110 mode);
|
|
1111
|
|
1112 /* Is it really necessary to gcpro path and str? It shouldn't be
|
|
1113 unless some caller has fucked up. */
|
|
1114 GCPRO3 (path, str, suffixtab);
|
|
1115
|
|
1116 suffixtab = locate_file_construct_suffixed_files (str, suffix);
|
|
1117
|
|
1118 for (pathtail = path; !NILP (pathtail); pathtail = Fcdr (pathtail))
|
|
1119 {
|
|
1120 Lisp_Object pathel = Fcar (pathtail);
|
|
1121 Lisp_Object hashtab;
|
|
1122 Lisp_Object tail;
|
|
1123 int found;
|
|
1124
|
|
1125 /* If this path element is relative, we have to look by hand.
|
|
1126 Can't set string property in a pure string. */
|
|
1127 if (NILP (pathel) || NILP (Ffile_name_absolute_p (pathel)) ||
|
|
1128 purified (pathel))
|
|
1129 {
|
|
1130 val = locate_file_in_directory (pathel, str, suffix, storeptr,
|
|
1131 mode);
|
|
1132 if (val >= 0)
|
|
1133 {
|
|
1134 UNGCPRO;
|
|
1135 return val;
|
|
1136 }
|
|
1137 continue;
|
|
1138 }
|
|
1139
|
|
1140 hashtab = locate_file_find_directory_hash_table (pathel);
|
|
1141
|
|
1142 /* Loop over suffixes. */
|
195
|
1143 for (tail = suffixtab, found = 0; !found && CONSP (tail);
|
|
1144 tail = XCDR (tail))
|
0
|
1145 {
|
195
|
1146 if (!NILP (Fgethash (XCAR (tail), hashtab, Qnil)))
|
0
|
1147 found = 1;
|
|
1148 }
|
|
1149
|
|
1150 if (found)
|
|
1151 {
|
|
1152 /* This is a likely candidate. Look by hand in this directory
|
|
1153 so we don't get thrown off if someone byte-compiles a file. */
|
|
1154 val = locate_file_in_directory (pathel, str, suffix, storeptr,
|
|
1155 mode);
|
|
1156 if (val >= 0)
|
|
1157 {
|
|
1158 UNGCPRO;
|
|
1159 return val;
|
|
1160 }
|
|
1161
|
|
1162 /* Hmm ... the file isn't actually there. (Or possibly it's
|
|
1163 a directory ...) So refresh our hashing. */
|
|
1164 locate_file_refresh_hashing (pathel);
|
|
1165 }
|
|
1166 }
|
|
1167
|
|
1168 /* File is probably not there, but check the hard way just in case. */
|
|
1169 val = locate_file_without_hash (path, str, suffix, storeptr,
|
|
1170 mode);
|
|
1171 if (val >= 0)
|
|
1172 {
|
|
1173 /* Sneaky user added a file without telling us. */
|
|
1174 Flocate_file_clear_hashing (path);
|
|
1175 }
|
|
1176
|
|
1177 UNGCPRO;
|
|
1178 return val;
|
|
1179 }
|
|
1180
|
|
1181
|
|
1182 #ifdef LOADHIST
|
|
1183
|
|
1184 /* Merge the list we've accumulated of globals from the current input source
|
|
1185 into the load_history variable. The details depend on whether
|
|
1186 the source has an associated file name or not. */
|
|
1187
|
|
1188 static void
|
|
1189 build_load_history (int loading, Lisp_Object source)
|
|
1190 {
|
|
1191 REGISTER Lisp_Object tail, prev, newelt;
|
|
1192 REGISTER Lisp_Object tem, tem2;
|
|
1193 int foundit;
|
|
1194
|
233
|
1195 #if !defined(LOADHIST_DUMPED)
|
0
|
1196 /* Don't bother recording anything for preloaded files. */
|
|
1197 if (purify_flag)
|
|
1198 return;
|
233
|
1199 #endif
|
0
|
1200
|
|
1201 tail = Vload_history;
|
|
1202 prev = Qnil;
|
|
1203 foundit = 0;
|
|
1204 while (!NILP (tail))
|
|
1205 {
|
|
1206 tem = Fcar (tail);
|
|
1207
|
|
1208 /* Find the feature's previous assoc list... */
|
195
|
1209 if (internal_equal (source, Fcar (tem), 0))
|
0
|
1210 {
|
|
1211 foundit = 1;
|
|
1212
|
|
1213 /* If we're loading, remove it. */
|
|
1214 if (loading)
|
173
|
1215 {
|
0
|
1216 if (NILP (prev))
|
|
1217 Vload_history = Fcdr (tail);
|
|
1218 else
|
|
1219 Fsetcdr (prev, Fcdr (tail));
|
|
1220 }
|
|
1221
|
|
1222 /* Otherwise, cons on new symbols that are not already members. */
|
|
1223 else
|
|
1224 {
|
|
1225 tem2 = Vcurrent_load_list;
|
|
1226
|
|
1227 while (CONSP (tem2))
|
|
1228 {
|
195
|
1229 newelt = XCAR (tem2);
|
0
|
1230
|
|
1231 if (NILP (Fmemq (newelt, tem)))
|
|
1232 Fsetcar (tail, Fcons (Fcar (tem),
|
|
1233 Fcons (newelt, Fcdr (tem))));
|
|
1234
|
195
|
1235 tem2 = XCDR (tem2);
|
0
|
1236 QUIT;
|
|
1237 }
|
|
1238 }
|
|
1239 }
|
|
1240 else
|
|
1241 prev = tail;
|
|
1242 tail = Fcdr (tail);
|
|
1243 QUIT;
|
|
1244 }
|
|
1245
|
|
1246 /* If we're loading, cons the new assoc onto the front of load-history,
|
|
1247 the most-recently-loaded position. Also do this if we didn't find
|
|
1248 an existing member for the current source. */
|
|
1249 if (loading || !foundit)
|
|
1250 Vload_history = Fcons (Fnreverse (Vcurrent_load_list),
|
|
1251 Vload_history);
|
|
1252 }
|
|
1253
|
|
1254 #else /* !LOADHIST */
|
|
1255 #define build_load_history(x,y)
|
|
1256 #endif /* !LOADHIST */
|
|
1257
|
|
1258
|
|
1259 #if 0 /* FSFmacs defun hack */
|
|
1260 Lisp_Object
|
|
1261 unreadpure (void) /* Used as unwind-protect function in readevalloop */
|
|
1262 {
|
|
1263 read_pure = 0;
|
|
1264 return Qnil;
|
|
1265 }
|
|
1266 #endif /* 0 */
|
|
1267
|
|
1268 static void
|
173
|
1269 readevalloop (Lisp_Object readcharfun,
|
0
|
1270 Lisp_Object sourcename,
|
|
1271 Lisp_Object (*evalfun) (Lisp_Object),
|
|
1272 int printflag)
|
|
1273 {
|
|
1274 /* This function can GC */
|
|
1275 REGISTER Emchar c;
|
|
1276 REGISTER Lisp_Object val;
|
|
1277 int speccount = specpdl_depth ();
|
|
1278 struct gcpro gcpro1;
|
|
1279 struct buffer *b = 0;
|
|
1280
|
|
1281 if (BUFFERP (readcharfun))
|
|
1282 b = XBUFFER (readcharfun);
|
|
1283 else if (MARKERP (readcharfun))
|
|
1284 b = XMARKER (readcharfun)->buffer;
|
|
1285
|
267
|
1286 /* Don't do this. It is not necessary, and it needlessly exposes
|
|
1287 READCHARFUN (which can be a stream) to Lisp. --hniksic */
|
|
1288 /*specbind (Qstandard_input, readcharfun);*/
|
|
1289
|
0
|
1290 specbind (Qcurrent_load_list, Qnil);
|
|
1291
|
|
1292 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1293 Vcurrent_compiled_function_annotation = Qnil;
|
|
1294 #endif
|
|
1295 GCPRO1 (sourcename);
|
|
1296
|
|
1297 LOADHIST_ATTACH (sourcename);
|
|
1298
|
|
1299 while (1)
|
|
1300 {
|
|
1301 QUIT;
|
|
1302
|
|
1303 if (b != 0 && !BUFFER_LIVE_P (b))
|
|
1304 error ("Reading from killed buffer");
|
|
1305
|
|
1306 c = readchar (readcharfun);
|
|
1307 if (c == ';')
|
|
1308 {
|
|
1309 /* Skip comment */
|
|
1310 while ((c = readchar (readcharfun)) != '\n' && c != -1)
|
|
1311 QUIT;
|
|
1312 continue;
|
|
1313 }
|
|
1314 if (c < 0)
|
|
1315 break;
|
|
1316
|
|
1317 /* Ignore whitespace here, so we can detect eof. */
|
|
1318 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r')
|
|
1319 continue;
|
|
1320
|
|
1321 #if 0 /* FSFmacs defun hack */
|
|
1322 if (purify_flag && c == '(')
|
|
1323 {
|
|
1324 int count1 = specpdl_depth ();
|
|
1325 record_unwind_protect (unreadpure, Qnil);
|
|
1326 val = read_list (readcharfun, ')', -1, 1);
|
|
1327 unbind_to (count1, Qnil);
|
|
1328 }
|
|
1329 else
|
|
1330 #else /* No "defun hack" -- Emacs 19 uses read-time syntax for bytecodes */
|
|
1331 {
|
|
1332 unreadchar (readcharfun, c);
|
245
|
1333 read_objects = Qnil;
|
0
|
1334 if (NILP (Vload_read_function))
|
|
1335 val = read0 (readcharfun);
|
|
1336 else
|
|
1337 val = call1 (Vload_read_function, readcharfun);
|
|
1338 }
|
|
1339 #endif
|
|
1340 val = (*evalfun) (val);
|
|
1341 if (printflag)
|
|
1342 {
|
|
1343 Vvalues = Fcons (val, Vvalues);
|
|
1344 if (EQ (Vstandard_output, Qt))
|
|
1345 Fprin1 (val, Qnil);
|
|
1346 else
|
|
1347 Fprint (val, Qnil);
|
|
1348 }
|
|
1349 }
|
|
1350
|
|
1351 build_load_history (LSTREAMP (readcharfun) ||
|
|
1352 /* This looks weird, but it's what's in FSFmacs */
|
|
1353 (b ? BUF_NARROWED (b) : BUF_NARROWED (current_buffer)),
|
|
1354 sourcename);
|
|
1355 UNGCPRO;
|
|
1356
|
|
1357 unbind_to (speccount, Qnil);
|
|
1358 }
|
|
1359
|
20
|
1360 DEFUN ("eval-buffer", Feval_buffer, 0, 2, "bBuffer: ", /*
|
0
|
1361 Execute BUFFER as Lisp code.
|
|
1362 Programs can pass two arguments, BUFFER and PRINTFLAG.
|
|
1363 BUFFER is the buffer to evaluate (nil means use current buffer).
|
|
1364 PRINTFLAG controls printing of output:
|
|
1365 nil means discard it; anything else is stream for print.
|
|
1366
|
|
1367 If there is no error, point does not move. If there is an error,
|
|
1368 point remains at the end of the last character read from the buffer.
|
|
1369 Execute BUFFER as Lisp code.
|
20
|
1370 */
|
|
1371 (bufname, printflag))
|
0
|
1372 {
|
|
1373 /* This function can GC */
|
|
1374 int speccount = specpdl_depth ();
|
|
1375 Lisp_Object tem, buf;
|
|
1376
|
|
1377 if (NILP (bufname))
|
|
1378 buf = Fcurrent_buffer ();
|
|
1379 else
|
|
1380 buf = Fget_buffer (bufname);
|
|
1381 if (NILP (buf))
|
|
1382 error ("No such buffer.");
|
|
1383
|
|
1384 if (NILP (printflag))
|
|
1385 tem = Qsymbolp; /* #### #@[]*&$#*[& SI:NULL-STREAM */
|
|
1386 else
|
|
1387 tem = printflag;
|
|
1388 specbind (Qstandard_output, tem);
|
|
1389 record_unwind_protect (save_excursion_restore, save_excursion_save ());
|
|
1390 BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
|
|
1391 readevalloop (buf, XBUFFER (buf)->filename, Feval,
|
|
1392 !NILP (printflag));
|
|
1393
|
|
1394 return unbind_to (speccount, Qnil);
|
|
1395 }
|
|
1396
|
|
1397 #if 0
|
149
|
1398 xxDEFUN ("eval-current-buffer", Feval_current_buffer, 0, 1, "", /*
|
0
|
1399 Execute the current buffer as Lisp code.
|
|
1400 Programs can pass argument PRINTFLAG which controls printing of output:
|
|
1401 nil means discard it; anything else is stream for print.
|
|
1402
|
|
1403 If there is no error, point does not move. If there is an error,
|
|
1404 point remains at the end of the last character read from the buffer.
|
149
|
1405 */
|
|
1406 (printflag))
|
0
|
1407 {
|
|
1408 code omitted;
|
|
1409 }
|
149
|
1410 #endif /* 0 */
|
0
|
1411
|
20
|
1412 DEFUN ("eval-region", Feval_region, 2, 3, "r", /*
|
0
|
1413 Execute the region as Lisp code.
|
|
1414 When called from programs, expects two arguments,
|
|
1415 giving starting and ending indices in the current buffer
|
|
1416 of the text to be executed.
|
|
1417 Programs can pass third argument PRINTFLAG which controls output:
|
|
1418 nil means discard it; anything else is stream for printing it.
|
|
1419
|
|
1420 If there is no error, point does not move. If there is an error,
|
|
1421 point remains at the end of the last character read from the buffer.
|
|
1422
|
|
1423 Note: Before evaling the region, this function narrows the buffer to it.
|
|
1424 If the code being eval'd should happen to trigger a redisplay you may
|
|
1425 see some text temporarily disappear because of this.
|
20
|
1426 */
|
|
1427 (b, e, printflag))
|
0
|
1428 {
|
|
1429 /* This function can GC */
|
|
1430 int speccount = specpdl_depth ();
|
|
1431 Lisp_Object tem;
|
|
1432 Lisp_Object cbuf = Fcurrent_buffer ();
|
|
1433
|
|
1434 if (NILP (printflag))
|
|
1435 tem = Qsymbolp; /* #### #@[]*&$#*[& SI:NULL-STREAM */
|
|
1436 else
|
|
1437 tem = printflag;
|
|
1438 specbind (Qstandard_output, tem);
|
|
1439
|
|
1440 if (NILP (printflag))
|
|
1441 record_unwind_protect (save_excursion_restore, save_excursion_save ());
|
|
1442 record_unwind_protect (save_restriction_restore, save_restriction_save ());
|
|
1443
|
|
1444 /* This both uses b and checks its type. */
|
|
1445 Fgoto_char (b, cbuf);
|
|
1446 Fnarrow_to_region (make_int (BUF_BEGV (current_buffer)), e, cbuf);
|
|
1447 readevalloop (cbuf, XBUFFER (cbuf)->filename, Feval,
|
|
1448 !NILP (printflag));
|
|
1449
|
|
1450 return unbind_to (speccount, Qnil);
|
|
1451 }
|
|
1452
|
20
|
1453 DEFUN ("read", Fread, 0, 1, 0, /*
|
0
|
1454 Read one Lisp expression as text from STREAM, return as Lisp object.
|
|
1455 If STREAM is nil, use the value of `standard-input' (which see).
|
|
1456 STREAM or the value of `standard-input' may be:
|
|
1457 a buffer (read from point and advance it)
|
|
1458 a marker (read from where it points and advance it)
|
|
1459 a function (call it with no arguments for each character,
|
|
1460 call it with a char as argument to push a char back)
|
|
1461 a string (takes text from string, starting at the beginning)
|
|
1462 t (read text line using minibuffer and use it).
|
20
|
1463 */
|
|
1464 (stream))
|
0
|
1465 {
|
|
1466 if (NILP (stream))
|
|
1467 stream = Vstandard_input;
|
|
1468 if (EQ (stream, Qt))
|
|
1469 stream = Qread_char;
|
|
1470
|
245
|
1471 read_objects = Qnil;
|
|
1472
|
0
|
1473 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1474 Vcurrent_compiled_function_annotation = Qnil;
|
|
1475 #endif
|
|
1476 if (EQ (stream, Qread_char))
|
|
1477 {
|
173
|
1478 Lisp_Object val = call1 (Qread_from_minibuffer,
|
0
|
1479 build_translated_string ("Lisp expression: "));
|
173
|
1480 return Fcar (Fread_from_string (val, Qnil, Qnil));
|
0
|
1481 }
|
|
1482
|
|
1483 if (STRINGP (stream))
|
|
1484 return Fcar (Fread_from_string (stream, Qnil, Qnil));
|
|
1485
|
|
1486 return read0 (stream);
|
|
1487 }
|
|
1488
|
20
|
1489 DEFUN ("read-from-string", Fread_from_string, 1, 3, 0, /*
|
0
|
1490 Read one Lisp expression which is represented as text by STRING.
|
|
1491 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
|
|
1492 START and END optionally delimit a substring of STRING from which to read;
|
|
1493 they default to 0 and (length STRING) respectively.
|
20
|
1494 */
|
|
1495 (string, start, end))
|
0
|
1496 {
|
|
1497 Bytecount startval, endval;
|
|
1498 Lisp_Object tem;
|
|
1499 Lisp_Object lispstream = Qnil;
|
|
1500 struct gcpro gcpro1;
|
|
1501
|
|
1502 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1503 Vcurrent_compiled_function_annotation = Qnil;
|
|
1504 #endif
|
|
1505 GCPRO1 (lispstream);
|
|
1506 CHECK_STRING (string);
|
|
1507 get_string_range_byte (string, start, end, &startval, &endval,
|
|
1508 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
1509 lispstream = make_lisp_string_input_stream (string, startval,
|
|
1510 endval - startval);
|
|
1511
|
245
|
1512 read_objects = Qnil;
|
|
1513
|
0
|
1514 tem = read0 (lispstream);
|
|
1515 /* Yeah, it's ugly. Gonna make something of it?
|
|
1516 At least our reader is reentrant ... */
|
|
1517 tem =
|
|
1518 (Fcons (tem, make_int
|
|
1519 (bytecount_to_charcount
|
16
|
1520 (XSTRING_DATA (string),
|
0
|
1521 startval + Lstream_byte_count (XLSTREAM (lispstream))))));
|
|
1522 Lstream_delete (XLSTREAM (lispstream));
|
|
1523 UNGCPRO;
|
|
1524 return tem;
|
|
1525 }
|
|
1526
|
|
1527
|
|
1528 #ifdef LISP_BACKQUOTES
|
|
1529
|
|
1530 static Lisp_Object
|
|
1531 backquote_unwind (Lisp_Object ptr)
|
|
1532 { /* used as unwind-protect function in read0() */
|
|
1533 int *counter = (int *) get_opaque_ptr (ptr);
|
|
1534 if (--*counter < 0)
|
173
|
1535 *counter = 0;
|
0
|
1536 free_opaque_ptr (ptr);
|
|
1537 return Qnil;
|
|
1538 }
|
|
1539
|
173
|
1540 #endif
|
0
|
1541
|
|
1542 /* Use this for recursive reads, in contexts where internal tokens
|
|
1543 are not allowed. See also read1(). */
|
|
1544 static Lisp_Object
|
|
1545 read0 (Lisp_Object readcharfun)
|
|
1546 {
|
|
1547 Lisp_Object val;
|
|
1548
|
|
1549 val = read1 (readcharfun);
|
|
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
|
280
|
1596 #ifndef MULE
|
0
|
1597 #define FSF_KEYS
|
280
|
1598 #endif
|
0
|
1599 #ifdef FSF_KEYS
|
|
1600
|
|
1601 #define alt_modifier (0x040000)
|
|
1602 #define super_modifier (0x080000)
|
|
1603 #define hyper_modifier (0x100000)
|
|
1604 #define shift_modifier (0x200000)
|
|
1605 /* fsf uses a different modifiers for meta and control. Possibly
|
173
|
1606 byte_compiled code will still work fsfmacs, though... --Stig
|
0
|
1607
|
|
1608 #define ctl_modifier (0x400000)
|
173
|
1609 #define meta_modifier (0x800000)
|
0
|
1610 */
|
267
|
1611 #define FSF_LOSSAGE(mask) \
|
272
|
1612 if (fail_on_bucky_bit_character_escapes || \
|
|
1613 ((c = readchar (readcharfun)) != '-')) \
|
267
|
1614 error ("Invalid escape character syntax"); \
|
|
1615 c = readchar (readcharfun); \
|
|
1616 if (c < 0) \
|
|
1617 signal_error (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun))); \
|
|
1618 if (c == '\\') \
|
|
1619 c = read_escape (readcharfun); \
|
0
|
1620 return c | mask
|
|
1621
|
|
1622 case 'S': FSF_LOSSAGE (shift_modifier);
|
|
1623 case 'H': FSF_LOSSAGE (hyper_modifier);
|
|
1624 case 'A': FSF_LOSSAGE (alt_modifier);
|
|
1625 case 's': FSF_LOSSAGE (super_modifier);
|
|
1626 #undef alt_modifier
|
|
1627 #undef super_modifier
|
|
1628 #undef hyper_modifier
|
|
1629 #undef shift_modifier
|
|
1630 #undef FSF_LOSSAGE
|
|
1631
|
|
1632 #endif /* FSF_KEYS */
|
|
1633
|
|
1634 case 'C':
|
|
1635 c = readchar (readcharfun);
|
267
|
1636 if (c < 0)
|
|
1637 signal_error (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun)));
|
0
|
1638 if (c != '-')
|
|
1639 error ("Invalid escape character syntax");
|
|
1640 case '^':
|
|
1641 c = readchar (readcharfun);
|
267
|
1642 if (c < 0)
|
|
1643 signal_error (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun)));
|
0
|
1644 if (c == '\\')
|
|
1645 c = read_escape (readcharfun);
|
|
1646 /* FSFmacs junk for non-ASCII controls.
|
|
1647 Not used here. */
|
|
1648 if (c == '?')
|
|
1649 return 0177;
|
|
1650 else
|
173
|
1651 return c & (0200 | 037);
|
|
1652
|
0
|
1653 case '0':
|
|
1654 case '1':
|
|
1655 case '2':
|
|
1656 case '3':
|
|
1657 case '4':
|
|
1658 case '5':
|
|
1659 case '6':
|
|
1660 case '7':
|
|
1661 /* An octal escape, as in ANSI C. */
|
|
1662 {
|
|
1663 REGISTER Emchar i = c - '0';
|
|
1664 REGISTER int count = 0;
|
|
1665 while (++count < 3)
|
|
1666 {
|
|
1667 if ((c = readchar (readcharfun)) >= '0' && c <= '7')
|
|
1668 i = (i << 3) + (c - '0');
|
|
1669 else
|
|
1670 {
|
|
1671 unreadchar (readcharfun, c);
|
|
1672 break;
|
|
1673 }
|
|
1674 }
|
|
1675 return i;
|
|
1676 }
|
|
1677
|
|
1678 case 'x':
|
|
1679 /* A hex escape, as in ANSI C. */
|
|
1680 {
|
|
1681 REGISTER Emchar i = 0;
|
|
1682 while (1)
|
|
1683 {
|
|
1684 c = readchar (readcharfun);
|
|
1685 /* Remember, can't use isdigit(), isalpha() etc. on Emchars */
|
|
1686 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0');
|
|
1687 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10;
|
|
1688 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10;
|
|
1689 else
|
|
1690 {
|
|
1691 unreadchar (readcharfun, c);
|
|
1692 break;
|
|
1693 }
|
|
1694 }
|
|
1695 return i;
|
|
1696 }
|
|
1697
|
70
|
1698 #ifdef MULE
|
|
1699 /* #### need some way of reading an extended character with
|
|
1700 an escape sequence. */
|
|
1701 #endif
|
16
|
1702
|
0
|
1703 default:
|
|
1704 return c;
|
|
1705 }
|
|
1706 }
|
|
1707
|
|
1708
|
|
1709
|
|
1710 /* read symbol-constituent stuff into `Vread_buffer_stream'. */
|
|
1711 static Bytecount
|
|
1712 read_atom_0 (Lisp_Object readcharfun, Emchar firstchar, int *saw_a_backslash)
|
|
1713 {
|
|
1714 /* This function can GC */
|
|
1715 Emchar c = ((firstchar) >= 0 ? firstchar : readchar (readcharfun));
|
|
1716 Lstream_rewind (XLSTREAM (Vread_buffer_stream));
|
|
1717
|
|
1718 *saw_a_backslash = 0;
|
|
1719
|
|
1720 while (c > 040 /* #### - comma should be here as should backquote */
|
|
1721 && !(c == '\"' || c == '\'' || c == ';'
|
|
1722 || c == '(' || c == ')'
|
|
1723 #ifndef LISP_FLOAT_TYPE
|
|
1724 /* If we have floating-point support, then we need
|
|
1725 to allow <digits><dot><digits>. */
|
|
1726 || c =='.'
|
|
1727 #endif /* not LISP_FLOAT_TYPE */
|
|
1728 || c == '[' || c == ']' || c == '#'
|
|
1729 ))
|
|
1730 {
|
|
1731 if (c == '\\')
|
|
1732 {
|
|
1733 c = readchar (readcharfun);
|
267
|
1734 if (c < 0)
|
|
1735 signal_error (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun)));
|
0
|
1736 *saw_a_backslash = 1;
|
|
1737 }
|
|
1738 Lstream_put_emchar (XLSTREAM (Vread_buffer_stream), c);
|
|
1739 QUIT;
|
|
1740 c = readchar (readcharfun);
|
|
1741 }
|
|
1742
|
|
1743 if (c >= 0)
|
|
1744 unreadchar (readcharfun, c);
|
|
1745 /* blasted terminating 0 */
|
|
1746 Lstream_put_emchar (XLSTREAM (Vread_buffer_stream), 0);
|
|
1747 Lstream_flush (XLSTREAM (Vread_buffer_stream));
|
|
1748
|
173
|
1749 return Lstream_byte_count (XLSTREAM (Vread_buffer_stream)) - 1;
|
0
|
1750 }
|
|
1751
|
|
1752 static Lisp_Object parse_integer (CONST Bufbyte *buf, Bytecount len, int base);
|
|
1753
|
|
1754 static Lisp_Object
|
|
1755 read_atom (Lisp_Object readcharfun,
|
|
1756 Emchar firstchar,
|
|
1757 int uninterned_symbol)
|
|
1758 {
|
|
1759 /* This function can GC */
|
|
1760 int saw_a_backslash;
|
|
1761 Bytecount len = read_atom_0 (readcharfun, firstchar, &saw_a_backslash);
|
|
1762 char *read_ptr = (char *)
|
|
1763 resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream));
|
|
1764
|
|
1765 /* Is it an integer? */
|
|
1766 if (! (saw_a_backslash || uninterned_symbol))
|
|
1767 {
|
|
1768 /* If a token had any backslashes in it, it is disqualified from
|
|
1769 being an integer or a float. This means that 123\456 is a
|
|
1770 symbol, as is \123 (which is the way (intern "123") prints).
|
110
|
1771 Also, if token was preceded by #:, it's always a symbol.
|
0
|
1772 */
|
|
1773 char *p = read_ptr + len;
|
|
1774 char *p1 = read_ptr;
|
|
1775
|
|
1776 if (*p1 == '+' || *p1 == '-') p1++;
|
|
1777 if (p1 != p)
|
|
1778 {
|
|
1779 int c;
|
|
1780
|
|
1781 while (p1 != p && (c = *p1) >= '0' && c <= '9')
|
|
1782 p1++;
|
|
1783 #ifdef LISP_FLOAT_TYPE
|
|
1784 /* Integers can have trailing decimal points. */
|
|
1785 if (p1 > read_ptr && p1 < p && *p1 == '.')
|
|
1786 p1++;
|
|
1787 #endif
|
|
1788 if (p1 == p)
|
|
1789 {
|
|
1790 /* It is an integer. */
|
|
1791 #ifdef LISP_FLOAT_TYPE
|
|
1792 if (p1[-1] == '.')
|
|
1793 p1[-1] = '\0';
|
|
1794 #endif
|
|
1795 #if 0
|
|
1796 {
|
|
1797 int number = 0;
|
|
1798 if (sizeof (int) == sizeof (EMACS_INT))
|
|
1799 number = atoi (read_buffer);
|
|
1800 else if (sizeof (long) == sizeof (EMACS_INT))
|
|
1801 number = atol (read_buffer);
|
|
1802 else
|
|
1803 abort ();
|
173
|
1804 return make_int (number);
|
0
|
1805 }
|
|
1806 #else
|
173
|
1807 return parse_integer ((Bufbyte *) read_ptr, len, 10);
|
0
|
1808 #endif
|
|
1809 }
|
|
1810 }
|
|
1811 #ifdef LISP_FLOAT_TYPE
|
|
1812 if (isfloat_string (read_ptr))
|
|
1813 return make_float (atof (read_ptr));
|
|
1814 #endif
|
|
1815 }
|
|
1816
|
|
1817 {
|
|
1818 Lisp_Object sym;
|
|
1819 if (uninterned_symbol)
|
173
|
1820 sym = (Fmake_symbol ((purify_flag)
|
0
|
1821 ? make_pure_pname ((Bufbyte *) read_ptr, len, 0)
|
|
1822 : make_string ((Bufbyte *) read_ptr, len)));
|
|
1823 else
|
|
1824 {
|
|
1825 /* intern will purecopy pname if necessary */
|
|
1826 Lisp_Object name = make_string ((Bufbyte *) read_ptr, len);
|
|
1827 sym = Fintern (name, Qnil);
|
267
|
1828
|
|
1829 if (SYMBOL_IS_KEYWORD (sym))
|
|
1830 {
|
|
1831 /* the LISP way is to put keywords in their own package,
|
|
1832 but we don't have packages, so we do something simpler.
|
|
1833 Someday, maybe we'll have packages and then this will
|
|
1834 be reworked. --Stig. */
|
|
1835 XSYMBOL (sym)->value = sym;
|
|
1836 }
|
0
|
1837 }
|
173
|
1838 return sym;
|
0
|
1839 }
|
|
1840 }
|
|
1841
|
|
1842
|
|
1843 static Lisp_Object
|
|
1844 parse_integer (CONST Bufbyte *buf, Bytecount len, int base)
|
|
1845 {
|
|
1846 CONST Bufbyte *lim = buf + len;
|
|
1847 CONST Bufbyte *p = buf;
|
272
|
1848 EMACS_UINT num = 0;
|
0
|
1849 int negativland = 0;
|
|
1850
|
|
1851 if (*p == '-')
|
|
1852 {
|
|
1853 negativland = 1;
|
|
1854 p++;
|
|
1855 }
|
|
1856 else if (*p == '+')
|
|
1857 {
|
|
1858 p++;
|
|
1859 }
|
|
1860
|
|
1861 if (p == lim)
|
|
1862 goto loser;
|
|
1863
|
142
|
1864 for (; (p < lim) && (*p != '\0'); p++)
|
0
|
1865 {
|
|
1866 int c = *p;
|
272
|
1867 EMACS_UINT onum;
|
0
|
1868
|
|
1869 if (isdigit (c))
|
|
1870 c = c - '0';
|
|
1871 else if (isupper (c))
|
|
1872 c = c - 'A' + 10;
|
|
1873 else if (islower (c))
|
|
1874 c = c - 'a' + 10;
|
|
1875 else
|
|
1876 goto loser;
|
173
|
1877
|
0
|
1878 if (c < 0 || c >= base)
|
|
1879 goto loser;
|
|
1880
|
|
1881 onum = num;
|
|
1882 num = num * base + c;
|
|
1883 if (num < onum)
|
|
1884 goto overflow;
|
|
1885 }
|
|
1886
|
|
1887 {
|
272
|
1888 EMACS_INT int_result = negativland ? -num : num;
|
265
|
1889 Lisp_Object result = make_int (int_result);
|
0
|
1890 if (num && ((XINT (result) < 0) != negativland))
|
|
1891 goto overflow;
|
265
|
1892 if (XINT (result) != int_result)
|
0
|
1893 goto overflow;
|
173
|
1894 return result;
|
0
|
1895 }
|
|
1896 overflow:
|
173
|
1897 return Fsignal (Qinvalid_read_syntax,
|
0
|
1898 list3 (build_translated_string
|
|
1899 ("Integer constant overflow in reader"),
|
|
1900 make_string (buf, len),
|
|
1901 make_int (base)));
|
|
1902 loser:
|
173
|
1903 return Fsignal (Qinvalid_read_syntax,
|
0
|
1904 list3 (build_translated_string
|
|
1905 ("Invalid integer constant in reader"),
|
|
1906 make_string (buf, len),
|
|
1907 make_int (base)));
|
|
1908 }
|
|
1909
|
|
1910
|
|
1911 static Lisp_Object
|
|
1912 read_integer (Lisp_Object readcharfun, int base)
|
|
1913 {
|
|
1914 /* This function can GC */
|
|
1915 int saw_a_backslash;
|
|
1916 Bytecount len = read_atom_0 (readcharfun, -1, &saw_a_backslash);
|
|
1917 return (parse_integer
|
|
1918 (resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)),
|
|
1919 ((saw_a_backslash)
|
|
1920 ? 0 /* make parse_integer signal error */
|
|
1921 : len),
|
|
1922 base));
|
|
1923 }
|
|
1924
|
|
1925 static Lisp_Object
|
|
1926 read_bit_vector (Lisp_Object readcharfun)
|
|
1927 {
|
185
|
1928 unsigned_char_dynarr *dyn = Dynarr_new (unsigned_char);
|
0
|
1929 Emchar c;
|
|
1930
|
|
1931 while (1)
|
|
1932 {
|
|
1933 c = readchar (readcharfun);
|
|
1934 if (c != '0' && c != '1')
|
|
1935 break;
|
|
1936 Dynarr_add (dyn, (unsigned char) (c - '0'));
|
|
1937 }
|
|
1938
|
|
1939 if (c >= 0)
|
|
1940 unreadchar (readcharfun, c);
|
|
1941
|
|
1942 return make_bit_vector_from_byte_vector (Dynarr_atp (dyn, 0),
|
|
1943 Dynarr_length (dyn));
|
|
1944 }
|
|
1945
|
|
1946
|
|
1947
|
|
1948 /* structures */
|
|
1949
|
|
1950 struct structure_type *
|
|
1951 define_structure_type (Lisp_Object type,
|
|
1952 int (*validate) (Lisp_Object data,
|
|
1953 Error_behavior errb),
|
|
1954 Lisp_Object (*instantiate) (Lisp_Object data))
|
|
1955 {
|
|
1956 struct structure_type st;
|
|
1957
|
|
1958 st.type = type;
|
185
|
1959 st.keywords = Dynarr_new (structure_keyword_entry);
|
0
|
1960 st.validate = validate;
|
|
1961 st.instantiate = instantiate;
|
|
1962 Dynarr_add (the_structure_type_dynarr, st);
|
|
1963
|
|
1964 return Dynarr_atp (the_structure_type_dynarr,
|
|
1965 Dynarr_length (the_structure_type_dynarr) - 1);
|
|
1966 }
|
|
1967
|
|
1968 void
|
|
1969 define_structure_type_keyword (struct structure_type *st, Lisp_Object keyword,
|
|
1970 int (*validate) (Lisp_Object keyword,
|
|
1971 Lisp_Object value,
|
|
1972 Error_behavior errb))
|
|
1973 {
|
|
1974 struct structure_keyword_entry en;
|
|
1975
|
|
1976 en.keyword = keyword;
|
|
1977 en.validate = validate;
|
|
1978 Dynarr_add (st->keywords, en);
|
|
1979 }
|
|
1980
|
|
1981 static struct structure_type *
|
|
1982 recognized_structure_type (Lisp_Object type)
|
|
1983 {
|
|
1984 int i;
|
|
1985
|
|
1986 for (i = 0; i < Dynarr_length (the_structure_type_dynarr); i++)
|
|
1987 {
|
|
1988 struct structure_type *st = Dynarr_atp (the_structure_type_dynarr, i);
|
|
1989 if (EQ (st->type, type))
|
|
1990 return st;
|
|
1991 }
|
|
1992
|
|
1993 return 0;
|
|
1994 }
|
|
1995
|
|
1996 static Lisp_Object
|
|
1997 read_structure (Lisp_Object readcharfun)
|
|
1998 {
|
|
1999 Emchar c = readchar (readcharfun);
|
|
2000 Lisp_Object list = Qnil;
|
|
2001 Lisp_Object orig_list = Qnil;
|
|
2002 Lisp_Object already_seen = Qnil;
|
173
|
2003 int keyword_count;
|
0
|
2004 struct structure_type *st;
|
|
2005 struct gcpro gcpro1, gcpro2;
|
|
2006
|
|
2007 GCPRO2 (orig_list, already_seen);
|
|
2008 if (c != '(')
|
|
2009 RETURN_UNGCPRO (continuable_syntax_error ("#s not followed by paren"));
|
|
2010 list = read_list (readcharfun, ')', 0, 0);
|
|
2011 orig_list = list;
|
|
2012 {
|
|
2013 int len = XINT (Flength (list));
|
|
2014 if (len == 0)
|
|
2015 RETURN_UNGCPRO (continuable_syntax_error
|
|
2016 ("structure type not specified"));
|
|
2017 if (!(len & 1))
|
|
2018 RETURN_UNGCPRO
|
|
2019 (continuable_syntax_error
|
|
2020 ("structures must have alternating keyword/value pairs"));
|
|
2021 }
|
173
|
2022
|
0
|
2023 st = recognized_structure_type (XCAR (list));
|
|
2024 if (!st)
|
173
|
2025 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax,
|
|
2026 list2 (build_translated_string
|
|
2027 ("unrecognized structure type"),
|
|
2028 XCAR (list))));
|
0
|
2029
|
|
2030 list = Fcdr (list);
|
173
|
2031 keyword_count = Dynarr_length (st->keywords);
|
0
|
2032 while (!NILP (list))
|
|
2033 {
|
|
2034 Lisp_Object keyword, value;
|
|
2035 int i;
|
173
|
2036 struct structure_keyword_entry *en = NULL;
|
|
2037
|
0
|
2038 keyword = Fcar (list);
|
|
2039 list = Fcdr (list);
|
|
2040 value = Fcar (list);
|
|
2041 list = Fcdr (list);
|
173
|
2042
|
0
|
2043 if (!NILP (memq_no_quit (keyword, already_seen)))
|
173
|
2044 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax,
|
|
2045 list2 (build_translated_string
|
|
2046 ("structure keyword already seen"),
|
|
2047 keyword)));
|
|
2048
|
|
2049 for (i = 0; i < keyword_count; i++)
|
0
|
2050 {
|
|
2051 en = Dynarr_atp (st->keywords, i);
|
|
2052 if (EQ (keyword, en->keyword))
|
|
2053 break;
|
|
2054 }
|
|
2055
|
173
|
2056 if (i == keyword_count)
|
0
|
2057 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax,
|
|
2058 list2 (build_translated_string
|
|
2059 ("unrecognized structure keyword"),
|
|
2060 keyword)));
|
|
2061
|
|
2062 if (en->validate && ! (en->validate) (keyword, value, ERROR_ME))
|
|
2063 RETURN_UNGCPRO
|
|
2064 (Fsignal (Qinvalid_read_syntax,
|
|
2065 list3 (build_translated_string
|
|
2066 ("invalid value for structure keyword"),
|
|
2067 keyword, value)));
|
|
2068
|
|
2069 already_seen = Fcons (keyword, already_seen);
|
|
2070 }
|
|
2071
|
|
2072 if (st->validate && ! (st->validate) (orig_list, ERROR_ME))
|
173
|
2073 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax,
|
|
2074 list2 (build_translated_string
|
|
2075 ("invalid structure initializer"),
|
|
2076 orig_list)));
|
0
|
2077
|
|
2078 RETURN_UNGCPRO ((st->instantiate) (XCDR (orig_list)));
|
173
|
2079 }
|
0
|
2080
|
|
2081
|
|
2082 static Lisp_Object read_compiled_function (Lisp_Object readcharfun,
|
|
2083 int terminator);
|
|
2084 static Lisp_Object read_vector (Lisp_Object readcharfun, int terminator);
|
|
2085
|
|
2086 /* Get the next character; filter out whitespace and comments */
|
|
2087
|
|
2088 static Emchar
|
|
2089 reader_nextchar (Lisp_Object readcharfun)
|
|
2090 {
|
|
2091 /* This function can GC */
|
|
2092 Emchar c;
|
|
2093
|
|
2094 retry:
|
|
2095 QUIT;
|
|
2096 c = readchar (readcharfun);
|
|
2097 if (c < 0)
|
265
|
2098 signal_error (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun)));
|
0
|
2099
|
|
2100 switch (c)
|
|
2101 {
|
|
2102 default:
|
|
2103 {
|
|
2104 /* Ignore whitespace and control characters */
|
|
2105 if (c <= 040)
|
|
2106 goto retry;
|
173
|
2107 return c;
|
0
|
2108 }
|
|
2109
|
|
2110 case ';':
|
|
2111 {
|
|
2112 /* Comment */
|
|
2113 while ((c = readchar (readcharfun)) >= 0 && c != '\n')
|
|
2114 QUIT;
|
|
2115 goto retry;
|
|
2116 }
|
|
2117 }
|
|
2118 }
|
|
2119
|
|
2120 #if 0
|
|
2121 static Lisp_Object
|
|
2122 list2_pure (int pure, Lisp_Object a, Lisp_Object b)
|
|
2123 {
|
173
|
2124 return pure ? pure_cons (a, pure_cons (b, Qnil)) : list2 (a, b);
|
0
|
2125 }
|
|
2126 #endif
|
|
2127
|
|
2128 /* Read the next Lisp object from the stream READCHARFUN and return it.
|
|
2129 If the return value is a cons whose car is Qunbound, then read1()
|
|
2130 encountered a misplaced token (e.g. a right bracket, right paren,
|
|
2131 or dot followed by a non-number). To filter this stuff out,
|
|
2132 use read0(). */
|
173
|
2133
|
0
|
2134 static Lisp_Object
|
|
2135 read1 (Lisp_Object readcharfun)
|
|
2136 {
|
|
2137 Emchar c;
|
|
2138
|
|
2139 retry:
|
|
2140 c = reader_nextchar (readcharfun);
|
|
2141
|
|
2142 switch (c)
|
|
2143 {
|
|
2144 case '(':
|
|
2145 {
|
|
2146 #ifdef LISP_BACKQUOTES /* old backquote compatibility in lisp reader */
|
|
2147 /* if this is disabled, then other code in eval.c must be enabled */
|
|
2148 Emchar ch = reader_nextchar (readcharfun);
|
|
2149 switch (ch)
|
|
2150 {
|
|
2151 case '`':
|
|
2152 {
|
|
2153 Lisp_Object tem;
|
|
2154 int speccount = specpdl_depth ();
|
|
2155 ++old_backquote_flag;
|
|
2156 record_unwind_protect (backquote_unwind,
|
|
2157 make_opaque_ptr (&old_backquote_flag));
|
|
2158 tem = read0 (readcharfun);
|
|
2159 unbind_to (speccount, Qnil);
|
|
2160 ch = reader_nextchar (readcharfun);
|
|
2161 if (ch != ')')
|
|
2162 {
|
|
2163 unreadchar (readcharfun, ch);
|
|
2164 return Fsignal (Qinvalid_read_syntax,
|
|
2165 list1 (build_string
|
|
2166 ("Weird old-backquote syntax")));
|
|
2167 }
|
|
2168 return list2 (Qbacktick, tem);
|
|
2169 }
|
|
2170 case ',':
|
|
2171 {
|
|
2172 if (old_backquote_flag)
|
|
2173 {
|
|
2174 Lisp_Object tem, comma_type;
|
|
2175 ch = readchar (readcharfun);
|
|
2176 if (ch == '@')
|
|
2177 comma_type = Qcomma_at;
|
|
2178 else
|
|
2179 {
|
|
2180 if (ch >= 0)
|
|
2181 unreadchar (readcharfun, ch);
|
|
2182 comma_type = Qcomma;
|
|
2183 }
|
|
2184 tem = read0 (readcharfun);
|
|
2185 ch = reader_nextchar (readcharfun);
|
|
2186 if (ch != ')')
|
|
2187 {
|
|
2188 unreadchar (readcharfun, ch);
|
|
2189 return Fsignal (Qinvalid_read_syntax,
|
|
2190 list1 (build_string
|
|
2191 ("Weird old-backquote syntax")));
|
|
2192 }
|
|
2193 return list2 (comma_type, tem);
|
|
2194 }
|
|
2195 else
|
|
2196 {
|
|
2197 unreadchar (readcharfun, ch);
|
|
2198 #if 0
|
|
2199 return Fsignal (Qinvalid_read_syntax,
|
|
2200 list1 (build_string ("Comma outside of backquote")));
|
|
2201 #else
|
|
2202 /* #### - yuck....but this is reverse compatible. */
|
272
|
2203 /* mostly this is required by edebug, which does its own
|
0
|
2204 annotated reading. We need to have an annotated_read
|
|
2205 function that records (with markers) the buffer
|
|
2206 positions of the elements that make up lists, then that
|
|
2207 can be used in edebug and bytecomp and the check above
|
|
2208 can go back in. --Stig */
|
|
2209 break;
|
|
2210 #endif
|
|
2211 }
|
|
2212 }
|
|
2213 default:
|
|
2214 unreadchar (readcharfun, ch);
|
|
2215 } /* switch(ch) */
|
|
2216 #endif /* old backquote crap... */
|
|
2217 return read_list (readcharfun, ')', 1, 1);
|
|
2218 }
|
|
2219 case '[':
|
173
|
2220 return read_vector (readcharfun, ']');
|
0
|
2221
|
|
2222 case ')':
|
|
2223 case ']':
|
|
2224 /* #### - huh? these don't do what they seem... */
|
173
|
2225 return noseeum_cons (Qunbound, make_char (c));
|
0
|
2226 case '.':
|
|
2227 {
|
|
2228 #ifdef LISP_FLOAT_TYPE
|
|
2229 /* If a period is followed by a number, then we should read it
|
|
2230 as a floating point number. Otherwise, it denotes a dotted
|
|
2231 pair.
|
|
2232 */
|
|
2233 c = readchar (readcharfun);
|
|
2234 unreadchar (readcharfun, c);
|
|
2235
|
|
2236 /* Can't use isdigit on Emchars */
|
|
2237 if (c < '0' || c > '9')
|
173
|
2238 return noseeum_cons (Qunbound, make_char ('.'));
|
0
|
2239
|
|
2240 /* Note that read_atom will loop
|
|
2241 at least once, assuring that we will not try to UNREAD
|
|
2242 two characters in a row.
|
|
2243 (I think this doesn't matter anymore because there should
|
|
2244 be no more danger in unreading multiple characters) */
|
173
|
2245 return read_atom (readcharfun, '.', 0);
|
0
|
2246
|
|
2247 #else /* ! LISP_FLOAT_TYPE */
|
173
|
2248 return noseeum_cons (Qunbound, make_char ('.'));
|
0
|
2249 #endif /* ! LISP_FLOAT_TYPE */
|
|
2250 }
|
|
2251
|
|
2252 case '#':
|
|
2253 {
|
|
2254 c = readchar (readcharfun);
|
|
2255 switch (c)
|
|
2256 {
|
|
2257 #if 0 /* FSFmacs silly char-table syntax */
|
|
2258 case '^':
|
|
2259 #endif
|
|
2260 #if 0 /* FSFmacs silly bool-vector syntax */
|
|
2261 case '&':
|
|
2262 #endif
|
|
2263 /* "#["-- byte-code constant syntax */
|
|
2264 /* purecons #[...] syntax */
|
173
|
2265 case '[': return read_compiled_function (readcharfun, ']'
|
|
2266 /*, purify_flag */ );
|
267
|
2267 /* "#:"-- gensym syntax */
|
173
|
2268 case ':': return read_atom (readcharfun, -1, 1);
|
0
|
2269 /* #'x => (function x) */
|
173
|
2270 case '\'': return list2 (Qfunction, read0 (readcharfun));
|
0
|
2271 #if 0
|
|
2272 /* RMS uses this syntax for fat-strings.
|
|
2273 If we use it for vectors, then obscure bugs happen.
|
|
2274 */
|
|
2275 /* "#(" -- Scheme/CL vector syntax */
|
173
|
2276 case '(': return read_vector (readcharfun, ')');
|
0
|
2277 #endif
|
|
2278 #if 0 /* FSFmacs */
|
|
2279 case '(':
|
|
2280 {
|
|
2281 Lisp_Object tmp;
|
|
2282 struct gcpro gcpro1;
|
|
2283
|
|
2284 /* Read the string itself. */
|
|
2285 tmp = read1 (readcharfun);
|
|
2286 if (!STRINGP (tmp))
|
|
2287 {
|
|
2288 if (CONSP (tmp) && UNBOUNDP (XCAR (tmp)))
|
|
2289 free_cons (XCONS (tmp));
|
173
|
2290 return Fsignal (Qinvalid_read_syntax,
|
|
2291 list1 (build_string ("#")));
|
0
|
2292 }
|
|
2293 GCPRO1 (tmp);
|
|
2294 /* Read the intervals and their properties. */
|
|
2295 while (1)
|
|
2296 {
|
|
2297 Lisp_Object beg, end, plist;
|
|
2298 Emchar ch;
|
|
2299 int invalid = 0;
|
173
|
2300
|
0
|
2301 beg = read1 (readcharfun);
|
|
2302 if (CONSP (beg) && UNBOUNDP (XCAR (beg)))
|
|
2303 {
|
|
2304 ch = XCHAR (XCDR (beg));
|
|
2305 free_cons (XCONS (beg));
|
|
2306 if (ch == ')')
|
|
2307 break;
|
|
2308 else
|
|
2309 invalid = 1;
|
|
2310 }
|
|
2311 if (!invalid)
|
|
2312 {
|
|
2313 end = read1 (readcharfun);
|
|
2314 if (CONSP (end) && UNBOUNDP (XCAR (end)))
|
|
2315 {
|
|
2316 free_cons (XCONS (end));
|
|
2317 invalid = 1;
|
|
2318 }
|
|
2319 }
|
|
2320 if (!invalid)
|
|
2321 {
|
|
2322 plist = read1 (readcharfun);
|
|
2323 if (CONSP (plist) && UNBOUNDP (XCAR (plist)))
|
|
2324 {
|
|
2325 free_cons (XCONS (plist));
|
|
2326 invalid = 1;
|
|
2327 }
|
|
2328 }
|
|
2329 if (invalid)
|
|
2330 RETURN_UNGCPRO
|
|
2331 (Fsignal (Qinvalid_read_syntax,
|
|
2332 list2
|
|
2333 (build_string ("invalid string property list"),
|
|
2334 XCDR (plist))));
|
|
2335 Fset_text_properties (beg, end, plist, tmp);
|
|
2336 }
|
|
2337 UNGCPRO;
|
|
2338 return tmp;
|
|
2339 }
|
|
2340 #endif /* 0 */
|
|
2341 case '@':
|
|
2342 {
|
|
2343 /* #@NUMBER is used to skip NUMBER following characters.
|
|
2344 That's used in .elc files to skip over doc strings
|
|
2345 and function definitions. */
|
|
2346 int i, nskip = 0;
|
|
2347
|
|
2348 /* Read a decimal integer. */
|
|
2349 while ((c = readchar (readcharfun)) >= 0
|
|
2350 && c >= '0' && c <= '9')
|
|
2351 nskip = (10 * nskip) + (c - '0');
|
|
2352 if (c >= 0)
|
|
2353 unreadchar (readcharfun, c);
|
|
2354
|
|
2355 /* FSF has code here that maybe caches the skipped
|
|
2356 string. See above for why this is totally
|
|
2357 losing. We handle this differently. */
|
|
2358
|
|
2359 /* Skip that many characters. */
|
|
2360 for (i = 0; i < nskip && c >= 0; i++)
|
|
2361 c = readchar (readcharfun);
|
|
2362
|
|
2363 goto retry;
|
|
2364 }
|
|
2365 case '$': return Vload_file_name_internal;
|
|
2366 /* bit vectors */
|
173
|
2367 case '*': return read_bit_vector (readcharfun);
|
0
|
2368 /* #o10 => 8 -- octal constant syntax */
|
173
|
2369 case 'o': return read_integer (readcharfun, 8);
|
0
|
2370 /* #xdead => 57005 -- hex constant syntax */
|
173
|
2371 case 'x': return read_integer (readcharfun, 16);
|
0
|
2372 /* #b010 => 2 -- binary constant syntax */
|
173
|
2373 case 'b': return read_integer (readcharfun, 2);
|
0
|
2374 /* #s(foobar key1 val1 key2 val2) -- structure syntax */
|
173
|
2375 case 's': return read_structure (readcharfun);
|
0
|
2376 case '<':
|
|
2377 {
|
|
2378 unreadchar (readcharfun, c);
|
|
2379 return Fsignal (Qinvalid_read_syntax,
|
|
2380 list1 (build_string ("Cannot read unreadable object")));
|
|
2381 }
|
140
|
2382 #ifdef FEATUREP_SYNTAX
|
|
2383 case '+':
|
|
2384 case '-':
|
|
2385 {
|
|
2386 Lisp_Object fexp, obj, tem;
|
|
2387 struct gcpro gcpro1, gcpro2;
|
|
2388
|
|
2389 fexp = read0(readcharfun);
|
|
2390 obj = read0(readcharfun);
|
|
2391
|
|
2392 /* the call to `featurep' may GC. */
|
|
2393 GCPRO2(fexp, obj);
|
|
2394 tem = call1(Qfeaturep, fexp);
|
|
2395 UNGCPRO;
|
|
2396
|
|
2397 if (c == '+' && NILP(tem)) goto retry;
|
|
2398 if (c == '-' && !NILP(tem)) goto retry;
|
|
2399 return obj;
|
|
2400 }
|
|
2401 #endif
|
245
|
2402 case '0': case '1': case '2': case '3': case '4':
|
|
2403 case '5': case '6': case '7': case '8': case '9':
|
|
2404 /* Reader forms that can reuse previously read objects. */
|
|
2405 {
|
|
2406 int n = 0;
|
|
2407 Lisp_Object found;
|
|
2408
|
|
2409 /* Using read_integer() here is impossible, because it
|
|
2410 chokes on `='. Using parse_integer() is too hard.
|
|
2411 So we simply read it in, and ignore overflows, which
|
|
2412 is safe. */
|
|
2413 while (c >= '0' && c <= '9')
|
|
2414 {
|
|
2415 n *= 10;
|
|
2416 n += c - '0';
|
|
2417 c = readchar (readcharfun);
|
|
2418 }
|
|
2419 found = assq_no_quit (make_int (n), read_objects);
|
|
2420 if (c == '=')
|
|
2421 {
|
|
2422 /* #n=object returns object, but associates it with
|
|
2423 n for #n#. */
|
|
2424 Lisp_Object obj;
|
|
2425 if (CONSP (found))
|
|
2426 return Fsignal (Qinvalid_read_syntax,
|
|
2427 list2 (build_translated_string
|
|
2428 ("Multiply defined symbol label"),
|
|
2429 make_int (n)));
|
|
2430 obj = read0 (readcharfun);
|
|
2431 read_objects = Fcons (Fcons (make_int (n), obj), read_objects);
|
|
2432 return obj;
|
|
2433 }
|
|
2434 else if (c == '#')
|
|
2435 {
|
|
2436 /* #n# returns a previously read object. */
|
|
2437 if (CONSP (found))
|
|
2438 return XCDR (found);
|
|
2439 else
|
|
2440 return Fsignal (Qinvalid_read_syntax,
|
|
2441 list2 (build_translated_string
|
|
2442 ("Undefined symbol label"),
|
|
2443 make_int (n)));
|
|
2444 }
|
|
2445 return Fsignal (Qinvalid_read_syntax,
|
|
2446 list1 (build_string ("#")));
|
|
2447 }
|
0
|
2448 default:
|
|
2449 {
|
|
2450 unreadchar (readcharfun, c);
|
|
2451 return Fsignal (Qinvalid_read_syntax,
|
|
2452 list1 (build_string ("#")));
|
|
2453 }
|
|
2454 }
|
|
2455 }
|
|
2456
|
|
2457 /* Quote */
|
|
2458 case '\'': return list2 (Qquote, read0 (readcharfun));
|
|
2459
|
|
2460 #ifdef LISP_BACKQUOTES
|
|
2461 case '`':
|
|
2462 {
|
|
2463 Lisp_Object tem;
|
|
2464 int speccount = specpdl_depth ();
|
|
2465 ++new_backquote_flag;
|
|
2466 record_unwind_protect (backquote_unwind,
|
|
2467 make_opaque_ptr (&new_backquote_flag));
|
|
2468 tem = read0 (readcharfun);
|
|
2469 unbind_to (speccount, Qnil);
|
|
2470 return list2 (Qbackquote, tem);
|
|
2471 }
|
|
2472
|
|
2473 case ',':
|
|
2474 {
|
|
2475 if (new_backquote_flag)
|
|
2476 {
|
|
2477 Lisp_Object comma_type = Qnil;
|
|
2478 int ch = readchar (readcharfun);
|
|
2479
|
|
2480 if (ch == '@')
|
|
2481 comma_type = Qcomma_at;
|
|
2482 else if (ch == '.')
|
|
2483 comma_type = Qcomma_dot;
|
|
2484 else
|
|
2485 {
|
|
2486 if (ch >= 0)
|
|
2487 unreadchar (readcharfun, ch);
|
|
2488 comma_type = Qcomma;
|
|
2489 }
|
|
2490 return list2 (comma_type, read0 (readcharfun));
|
|
2491 }
|
|
2492 else
|
|
2493 {
|
|
2494 /* YUCK. 99.999% backwards compatibility. The Right
|
|
2495 Thing(tm) is to signal an error here, because it's
|
|
2496 really invalid read syntax. Instead, this permits
|
|
2497 commas to begin symbols (unless they're inside
|
|
2498 backquotes). If an error is signalled here in the
|
|
2499 future, then commas should be invalid read syntax
|
|
2500 outside of backquotes anywhere they're found (i.e.
|
|
2501 they must be quoted in symbols) -- Stig */
|
173
|
2502 return read_atom (readcharfun, c, 0);
|
0
|
2503 }
|
|
2504 }
|
|
2505 #endif
|
|
2506
|
|
2507 case '?':
|
|
2508 {
|
|
2509 /* Evil GNU Emacs "character" (ie integer) syntax */
|
|
2510 c = readchar (readcharfun);
|
|
2511 if (c < 0)
|
265
|
2512 return Fsignal (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun)));
|
0
|
2513
|
|
2514 if (c == '\\')
|
|
2515 c = read_escape (readcharfun);
|
173
|
2516 return make_char (c);
|
0
|
2517 }
|
|
2518
|
|
2519 case '\"':
|
|
2520 {
|
|
2521 /* String */
|
|
2522 #ifdef I18N3
|
|
2523 /* #### If the input stream is translating, then the string
|
|
2524 should be marked as translatable by setting its
|
|
2525 `string-translatable' property to t. .el and .elc files
|
|
2526 normally are translating input streams. See Fgettext()
|
|
2527 and print_internal(). */
|
|
2528 #endif
|
|
2529 int cancel = 0;
|
|
2530
|
|
2531 Lstream_rewind (XLSTREAM (Vread_buffer_stream));
|
|
2532 while ((c = readchar (readcharfun)) >= 0
|
|
2533 && c != '\"')
|
|
2534 {
|
|
2535 if (c == '\\')
|
|
2536 c = read_escape (readcharfun);
|
|
2537 /* c is -1 if \ newline has just been seen */
|
|
2538 if (c == -1)
|
|
2539 {
|
|
2540 if (Lstream_byte_count (XLSTREAM (Vread_buffer_stream)) == 0)
|
|
2541 cancel = 1;
|
|
2542 }
|
|
2543 else
|
|
2544 Lstream_put_emchar (XLSTREAM (Vread_buffer_stream), c);
|
|
2545 QUIT;
|
|
2546 }
|
|
2547 if (c < 0)
|
265
|
2548 return Fsignal (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun)));
|
0
|
2549
|
|
2550 /* If purifying, and string starts with \ newline,
|
|
2551 return zero instead. This is for doc strings
|
|
2552 that we are really going to find in lib-src/DOC.nn.nn */
|
272
|
2553 if (purify_flag && NILP (Vinternal_doc_file_name) && cancel)
|
173
|
2554 return Qzero;
|
0
|
2555
|
|
2556 Lstream_flush (XLSTREAM (Vread_buffer_stream));
|
|
2557 #if 0 /* FSFmacs defun hack */
|
|
2558 if (read_pure)
|
|
2559 return
|
|
2560 make_pure_string
|
|
2561 (resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)),
|
|
2562 Lstream_byte_count (XLSTREAM (Vread_buffer_stream)));
|
|
2563 else
|
|
2564 #endif
|
|
2565 return
|
|
2566 make_string
|
|
2567 (resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)),
|
|
2568 Lstream_byte_count (XLSTREAM (Vread_buffer_stream)));
|
|
2569 }
|
|
2570
|
|
2571 default:
|
|
2572 {
|
|
2573 /* Ignore whitespace and control characters */
|
|
2574 if (c <= 040)
|
|
2575 goto retry;
|
173
|
2576 return read_atom (readcharfun, c, 0);
|
0
|
2577 }
|
|
2578 }
|
|
2579 }
|
|
2580
|
|
2581
|
|
2582
|
|
2583 #ifdef LISP_FLOAT_TYPE
|
|
2584
|
|
2585 #define LEAD_INT 1
|
|
2586 #define DOT_CHAR 2
|
|
2587 #define TRAIL_INT 4
|
|
2588 #define E_CHAR 8
|
|
2589 #define EXP_INT 16
|
|
2590
|
|
2591 int
|
|
2592 isfloat_string (CONST char *cp)
|
|
2593 {
|
|
2594 int state = 0;
|
|
2595 CONST Bufbyte *ucp = (CONST Bufbyte *) cp;
|
173
|
2596
|
0
|
2597 if (*ucp == '+' || *ucp == '-')
|
|
2598 ucp++;
|
|
2599
|
|
2600 if (*ucp >= '0' && *ucp <= '9')
|
|
2601 {
|
|
2602 state |= LEAD_INT;
|
|
2603 while (*ucp >= '0' && *ucp <= '9')
|
|
2604 ucp++;
|
|
2605 }
|
|
2606 if (*ucp == '.')
|
|
2607 {
|
|
2608 state |= DOT_CHAR;
|
|
2609 ucp++;
|
|
2610 }
|
|
2611 if (*ucp >= '0' && *ucp <= '9')
|
|
2612 {
|
|
2613 state |= TRAIL_INT;
|
|
2614 while (*ucp >= '0' && *ucp <= '9')
|
|
2615 ucp++;
|
|
2616 }
|
|
2617 if (*ucp == 'e' || *ucp == 'E')
|
|
2618 {
|
|
2619 state |= E_CHAR;
|
|
2620 ucp++;
|
|
2621 if ((*ucp == '+') || (*ucp == '-'))
|
|
2622 ucp++;
|
|
2623 }
|
|
2624
|
|
2625 if (*ucp >= '0' && *ucp <= '9')
|
|
2626 {
|
|
2627 state |= EXP_INT;
|
|
2628 while (*ucp >= '0' && *ucp <= '9')
|
|
2629 ucp++;
|
|
2630 }
|
|
2631 return (((*ucp == 0) || (*ucp == ' ') || (*ucp == '\t') || (*ucp == '\n')
|
|
2632 || (*ucp == '\r') || (*ucp == '\f'))
|
|
2633 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
|
|
2634 || state == (DOT_CHAR|TRAIL_INT)
|
|
2635 || state == (LEAD_INT|E_CHAR|EXP_INT)
|
|
2636 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)
|
|
2637 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)));
|
|
2638 }
|
|
2639 #endif /* LISP_FLOAT_TYPE */
|
|
2640
|
|
2641 static void *
|
|
2642 sequence_reader (Lisp_Object readcharfun,
|
|
2643 Emchar terminator,
|
|
2644 void *state,
|
|
2645 void * (*conser) (Lisp_Object readcharfun,
|
|
2646 void *state, Charcount len))
|
|
2647 {
|
|
2648 Charcount len;
|
|
2649
|
|
2650 for (len = 0; ; len++)
|
|
2651 {
|
|
2652 Emchar ch;
|
|
2653
|
|
2654 QUIT;
|
|
2655 ch = reader_nextchar (readcharfun);
|
|
2656
|
|
2657 if (ch == terminator)
|
173
|
2658 return state;
|
0
|
2659 else
|
|
2660 unreadchar (readcharfun, ch);
|
140
|
2661 #ifdef FEATUREP_SYNTAX
|
0
|
2662 if (ch == ']')
|
|
2663 syntax_error ("\"]\" in a list");
|
|
2664 else if (ch == ')')
|
|
2665 syntax_error ("\")\" in a vector");
|
140
|
2666 #endif
|
0
|
2667 state = ((conser) (readcharfun, state, len));
|
|
2668 }
|
|
2669 }
|
|
2670
|
|
2671
|
173
|
2672 struct read_list_state
|
0
|
2673 {
|
|
2674 Lisp_Object head;
|
|
2675 Lisp_Object tail;
|
|
2676 int length;
|
|
2677 int allow_dotted_lists;
|
|
2678 Emchar terminator;
|
|
2679 };
|
|
2680
|
|
2681 static void *
|
|
2682 read_list_conser (Lisp_Object readcharfun, void *state, Charcount len)
|
|
2683 {
|
185
|
2684 struct read_list_state *s = (struct read_list_state *) state;
|
0
|
2685 Lisp_Object elt;
|
|
2686
|
|
2687 elt = read1 (readcharfun);
|
|
2688
|
|
2689 if (CONSP (elt) && UNBOUNDP (XCAR (elt)))
|
|
2690 {
|
|
2691 Lisp_Object tem = elt;
|
|
2692 Emchar ch;
|
173
|
2693
|
0
|
2694 elt = XCDR (elt);
|
|
2695 free_cons (XCONS (tem));
|
|
2696 tem = Qnil;
|
|
2697 ch = XCHAR (elt);
|
140
|
2698 #ifdef FEATUREP_SYNTAX
|
|
2699 if (ch == s->terminator) /* deal with #+, #- reader macros */
|
|
2700 {
|
|
2701 unreadchar (readcharfun, s->terminator);
|
|
2702 goto done;
|
|
2703 }
|
|
2704 else if (ch == ']')
|
|
2705 syntax_error ("']' in a list");
|
|
2706 else if (ch == ')')
|
|
2707 syntax_error ("')' in a vector");
|
|
2708 else
|
|
2709 #endif
|
0
|
2710 if (ch != '.')
|
|
2711 signal_simple_error ("BUG! Internal reader error", elt);
|
|
2712 else if (!s->allow_dotted_lists)
|
|
2713 syntax_error ("\".\" in a vector");
|
|
2714 else
|
|
2715 {
|
|
2716 if (!NILP (s->tail))
|
|
2717 XCDR (s->tail) = read0 (readcharfun);
|
|
2718 else
|
|
2719 s->head = read0 (readcharfun);
|
|
2720 elt = read1 (readcharfun);
|
|
2721 if (CONSP (elt) && UNBOUNDP (XCAR (elt)))
|
|
2722 {
|
|
2723 ch = XCHAR (XCDR (elt));
|
|
2724 free_cons (XCONS (elt));
|
|
2725 if (ch == s->terminator)
|
|
2726 {
|
|
2727 unreadchar (readcharfun, s->terminator);
|
|
2728 goto done;
|
|
2729 }
|
|
2730 }
|
|
2731 syntax_error (". in wrong context");
|
|
2732 }
|
|
2733 }
|
|
2734
|
|
2735 #if 0 /* FSFmacs defun hack, or something ... */
|
|
2736 if (NILP (tail) && defun_hack && EQ (elt, Qdefun) && !read_pure)
|
|
2737 {
|
|
2738 record_unwind_protect (unreadpure, Qzero);
|
|
2739 read_pure = 1;
|
|
2740 }
|
|
2741 #endif
|
|
2742
|
|
2743 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
2744 if (s->length == 1 && s->allow_dotted_lists && EQ (XCAR (s->head), Qfset))
|
|
2745 {
|
|
2746 if (CONSP (elt) && EQ (XCAR (elt), Qquote) && CONSP (XCDR (elt)))
|
|
2747 Vcurrent_compiled_function_annotation = XCAR (XCDR (elt));
|
|
2748 else
|
|
2749 Vcurrent_compiled_function_annotation = elt;
|
|
2750 }
|
|
2751 #endif
|
|
2752
|
|
2753 elt = Fcons (elt, Qnil);
|
|
2754 if (!NILP (s->tail))
|
|
2755 XCDR (s->tail) = elt;
|
|
2756 else
|
|
2757 s->head = elt;
|
|
2758 s->tail = elt;
|
|
2759 done:
|
|
2760 s->length++;
|
173
|
2761 return s;
|
0
|
2762 }
|
|
2763
|
|
2764
|
|
2765 #if 0 /* FSFmacs defun hack */
|
|
2766 /* -1 for allow_dotted_lists means allow_dotted_lists and check
|
|
2767 for starting with defun and make structure pure. */
|
|
2768 #endif
|
|
2769
|
|
2770 static Lisp_Object
|
|
2771 read_list (Lisp_Object readcharfun,
|
|
2772 Emchar terminator,
|
|
2773 int allow_dotted_lists,
|
|
2774 int check_for_doc_references)
|
|
2775 {
|
|
2776 struct read_list_state s;
|
|
2777 struct gcpro gcpro1, gcpro2;
|
|
2778 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
2779 Lisp_Object old_compiled_function_annotation =
|
|
2780 Vcurrent_compiled_function_annotation;
|
|
2781 #endif
|
|
2782
|
|
2783 s.head = Qnil;
|
|
2784 s.tail = Qnil;
|
|
2785 s.length = 0;
|
|
2786 s.allow_dotted_lists = allow_dotted_lists;
|
|
2787 s.terminator = terminator;
|
|
2788 GCPRO2 (s.head, s.tail);
|
|
2789
|
181
|
2790 sequence_reader (readcharfun, terminator, &s, read_list_conser);
|
0
|
2791 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
2792 Vcurrent_compiled_function_annotation = old_compiled_function_annotation;
|
|
2793 #endif
|
|
2794
|
|
2795 if ((purify_flag || load_force_doc_strings) && check_for_doc_references)
|
|
2796 {
|
|
2797 /* check now for any doc string references and record them
|
|
2798 for later. */
|
|
2799 Lisp_Object tail;
|
|
2800
|
|
2801 /* We might be dealing with an imperfect list so don't
|
|
2802 use LIST_LOOP */
|
|
2803 for (tail = s.head; CONSP (tail); tail = XCDR (tail))
|
|
2804 {
|
|
2805 Lisp_Object holding_cons = Qnil;
|
|
2806
|
|
2807 {
|
|
2808 Lisp_Object elem = XCAR (tail);
|
|
2809 /* elem might be (#$ . INT) ... */
|
|
2810 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal))
|
|
2811 holding_cons = tail;
|
|
2812 /* or it might be (quote (#$ . INT)) i.e.
|
|
2813 (quote . ((#$ . INT) . nil)) in the case of
|
|
2814 `autoload' (autoload evaluates its arguments, while
|
|
2815 `defvar', `defun', etc. don't). */
|
|
2816 if (CONSP (elem) && EQ (XCAR (elem), Qquote)
|
|
2817 && CONSP (XCDR (elem)))
|
|
2818 {
|
|
2819 elem = XCAR (XCDR (elem));
|
|
2820 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal))
|
|
2821 holding_cons = XCDR (XCAR (tail));
|
|
2822 }
|
|
2823 }
|
|
2824
|
|
2825 if (CONSP (holding_cons))
|
|
2826 {
|
|
2827 if (purify_flag)
|
|
2828 {
|
272
|
2829 if (NILP (Vinternal_doc_file_name))
|
0
|
2830 /* We have not yet called Snarf-documentation, so
|
80
|
2831 assume this file is described in the DOC file
|
|
2832 and Snarf-documentation will fill in the right
|
|
2833 value later. For now, replace the whole list
|
|
2834 with 0. */
|
0
|
2835 XCAR (holding_cons) = Qzero;
|
|
2836 else
|
|
2837 /* We have already called Snarf-documentation, so
|
|
2838 make a relative file name for this file, so it
|
|
2839 can be found properly in the installed Lisp
|
|
2840 directory. We don't use Fexpand_file_name
|
|
2841 because that would make the directory absolute
|
|
2842 now. */
|
|
2843 XCAR (XCAR (holding_cons)) =
|
|
2844 concat2 (build_string ("../lisp/"),
|
|
2845 Ffile_name_nondirectory
|
|
2846 (Vload_file_name_internal));
|
|
2847 }
|
|
2848 else
|
|
2849 /* Not pure. Just add to Vload_force_doc_string_list,
|
|
2850 and the string will be filled in properly in
|
|
2851 load_force_doc_string_unwind(). */
|
|
2852 Vload_force_doc_string_list =
|
|
2853 /* We pass the cons that holds the (#$ . INT) so we
|
|
2854 can modify it in-place. */
|
|
2855 Fcons (holding_cons, Vload_force_doc_string_list);
|
|
2856 }
|
|
2857 }
|
|
2858 }
|
173
|
2859
|
0
|
2860 UNGCPRO;
|
173
|
2861 return s.head;
|
0
|
2862 }
|
|
2863
|
|
2864 static Lisp_Object
|
|
2865 read_vector (Lisp_Object readcharfun,
|
|
2866 Emchar terminator)
|
|
2867 {
|
|
2868 Lisp_Object tem;
|
|
2869 Lisp_Object *p;
|
|
2870 int len;
|
|
2871 int i;
|
|
2872 struct read_list_state s;
|
|
2873 struct gcpro gcpro1, gcpro2;
|
|
2874
|
|
2875 s.head = Qnil;
|
|
2876 s.tail = Qnil;
|
|
2877 s.length = 0;
|
|
2878 s.allow_dotted_lists = 0;
|
|
2879 GCPRO2 (s.head, s.tail);
|
173
|
2880
|
181
|
2881 sequence_reader (readcharfun, terminator, &s, read_list_conser);
|
185
|
2882
|
0
|
2883 UNGCPRO;
|
|
2884 tem = s.head;
|
|
2885 len = XINT (Flength (tem));
|
|
2886
|
|
2887 #if 0 /* FSFmacs defun hack */
|
|
2888 if (read_pure)
|
|
2889 s.head = make_pure_vector (len, Qnil);
|
|
2890 else
|
|
2891 #endif
|
|
2892 s.head = make_vector (len, Qnil);
|
|
2893
|
173
|
2894 for (i = 0, p = &(XVECTOR_DATA (s.head)[0]);
|
0
|
2895 i < len;
|
|
2896 i++, p++)
|
|
2897 {
|
|
2898 struct Lisp_Cons *otem = XCONS (tem);
|
|
2899 #if 0 /* FSFmacs defun hack */
|
|
2900 if (read_pure)
|
|
2901 tem = Fpurecopy (Fcar (tem));
|
|
2902 else
|
|
2903 #endif
|
|
2904 tem = Fcar (tem);
|
|
2905 *p = tem;
|
|
2906 tem = otem->cdr;
|
|
2907 free_cons (otem);
|
|
2908 }
|
173
|
2909 return s.head;
|
0
|
2910 }
|
|
2911
|
|
2912 static Lisp_Object
|
|
2913 read_compiled_function (Lisp_Object readcharfun, Emchar terminator)
|
|
2914 {
|
173
|
2915 /* Accept compiled functions at read-time so that we don't
|
0
|
2916 have to build them at load-time. */
|
|
2917 Lisp_Object stuff;
|
|
2918 Lisp_Object make_byte_code_args[COMPILED_DOMAIN + 1];
|
|
2919 struct gcpro gcpro1;
|
|
2920 int len;
|
|
2921 int iii;
|
|
2922 int saw_a_doc_ref = 0;
|
|
2923
|
|
2924 /* Note: we tell read_list not to search for doc references
|
|
2925 because we need to handle the "doc reference" for the
|
|
2926 instructions and constants differently. */
|
|
2927 stuff = read_list (readcharfun, terminator, 0, 0);
|
|
2928 len = XINT (Flength (stuff));
|
|
2929 if (len < COMPILED_STACK_DEPTH + 1 || len > COMPILED_DOMAIN + 1)
|
|
2930 return
|
|
2931 continuable_syntax_error ("#[...] used with wrong number of elements");
|
|
2932
|
|
2933 for (iii = 0; CONSP (stuff); iii++)
|
|
2934 {
|
|
2935 struct Lisp_Cons *victim = XCONS (stuff);
|
|
2936 make_byte_code_args[iii] = Fcar (stuff);
|
|
2937 if ((purify_flag || load_force_doc_strings)
|
|
2938 && CONSP (make_byte_code_args[iii])
|
|
2939 && EQ (XCAR (make_byte_code_args[iii]), Vload_file_name_internal))
|
|
2940 {
|
|
2941 if (purify_flag && iii == COMPILED_DOC_STRING)
|
|
2942 {
|
|
2943 /* same as in read_list(). */
|
272
|
2944 if (NILP (Vinternal_doc_file_name))
|
0
|
2945 make_byte_code_args[iii] = Qzero;
|
|
2946 else
|
|
2947 XCAR (make_byte_code_args[iii]) =
|
|
2948 concat2 (build_string ("../lisp/"),
|
|
2949 Ffile_name_nondirectory
|
|
2950 (Vload_file_name_internal));
|
|
2951 }
|
|
2952 else
|
|
2953 saw_a_doc_ref = 1;
|
|
2954 }
|
|
2955 stuff = Fcdr (stuff);
|
|
2956 free_cons (victim);
|
|
2957 }
|
|
2958 GCPRO1 (make_byte_code_args[0]);
|
|
2959 gcpro1.nvars = len;
|
|
2960
|
70
|
2961 /* v18 or v19 bytecode file. Need to Ebolify. */
|
|
2962 if (load_byte_code_version < 20 && VECTORP (make_byte_code_args[2]))
|
|
2963 ebolify_bytecode_constants (make_byte_code_args[2]);
|
|
2964
|
0
|
2965 /* make-byte-code looks at purify_flag, which should have the same
|
|
2966 * value as our "read-pure" argument */
|
|
2967 stuff = Fmake_byte_code (len, make_byte_code_args);
|
70
|
2968 XCOMPILED_FUNCTION (stuff)->flags.ebolified = (load_byte_code_version < 20);
|
0
|
2969 if (saw_a_doc_ref)
|
|
2970 Vload_force_doc_string_list = Fcons (stuff, Vload_force_doc_string_list);
|
|
2971 UNGCPRO;
|
|
2972 return stuff;
|
|
2973 }
|
|
2974
|
|
2975
|
|
2976
|
|
2977 void
|
|
2978 init_lread (void)
|
|
2979 {
|
|
2980 Vvalues = Qnil;
|
|
2981
|
|
2982 load_in_progress = 0;
|
267
|
2983
|
0
|
2984 Vload_descriptor_list = Qnil;
|
|
2985
|
267
|
2986 /* kludge: locate-file does not work for a null load-path, even if
|
|
2987 the file name is absolute. */
|
|
2988
|
|
2989 Vload_path = Fcons (build_string (""), Qnil);
|
|
2990
|
231
|
2991 /* This used to get initialized in init_lread because all streams
|
|
2992 got closed when dumping occurs. This is no longer true --
|
|
2993 Vread_buffer_stream is a resizing output stream, and there is no
|
|
2994 reason to close it at dump-time.
|
|
2995
|
|
2996 Vread_buffer_stream is set to Qnil in vars_of_lread, and this
|
|
2997 will initialize it only once, at dump-time. */
|
|
2998 if (NILP (Vread_buffer_stream))
|
|
2999 Vread_buffer_stream = make_resizing_buffer_output_stream ();
|
0
|
3000
|
|
3001 Vload_force_doc_string_list = Qnil;
|
|
3002 }
|
|
3003
|
|
3004 void
|
|
3005 syms_of_lread (void)
|
|
3006 {
|
20
|
3007 DEFSUBR (Fread);
|
|
3008 DEFSUBR (Fread_from_string);
|
|
3009 DEFSUBR (Fload_internal);
|
|
3010 DEFSUBR (Flocate_file);
|
|
3011 DEFSUBR (Flocate_file_clear_hashing);
|
|
3012 DEFSUBR (Feval_buffer);
|
|
3013 DEFSUBR (Feval_region);
|
0
|
3014
|
|
3015 defsymbol (&Qstandard_input, "standard-input");
|
|
3016 defsymbol (&Qread_char, "read-char");
|
|
3017 defsymbol (&Qcurrent_load_list, "current-load-list");
|
|
3018 defsymbol (&Qload, "load");
|
|
3019 defsymbol (&Qload_file_name, "load-file-name");
|
|
3020 defsymbol (&Qlocate_file_hash_table, "locate-file-hash-table");
|
|
3021 defsymbol (&Qfset, "fset");
|
|
3022
|
|
3023 #ifdef LISP_BACKQUOTES
|
|
3024 defsymbol (&Qbackquote, "backquote");
|
|
3025 defsymbol (&Qbacktick, "`");
|
|
3026 defsymbol (&Qcomma, ",");
|
|
3027 defsymbol (&Qcomma_at, ",@");
|
|
3028 defsymbol (&Qcomma_dot, ",.");
|
|
3029 #endif
|
|
3030 }
|
|
3031
|
|
3032 void
|
|
3033 structure_type_create (void)
|
|
3034 {
|
185
|
3035 the_structure_type_dynarr = Dynarr_new (structure_type);
|
0
|
3036 }
|
|
3037
|
|
3038 void
|
|
3039 vars_of_lread (void)
|
|
3040 {
|
|
3041 DEFVAR_LISP ("values", &Vvalues /*
|
|
3042 List of values of all expressions which were read, evaluated and printed.
|
|
3043 Order is reverse chronological.
|
|
3044 */ );
|
|
3045
|
|
3046 DEFVAR_LISP ("standard-input", &Vstandard_input /*
|
|
3047 Stream for read to get input from.
|
|
3048 See documentation of `read' for possible values.
|
|
3049 */ );
|
|
3050 Vstandard_input = Qt;
|
|
3051
|
|
3052 DEFVAR_LISP ("load-path", &Vload_path /*
|
|
3053 *List of directories to search for files to load.
|
|
3054 Each element is a string (directory name) or nil (try default directory).
|
|
3055
|
185
|
3056 Note that the elements of this list *may not* begin with "~", so you must
|
0
|
3057 call `expand-file-name' on them before adding them to this list.
|
|
3058
|
|
3059 Initialized based on EMACSLOADPATH environment variable, if any,
|
|
3060 otherwise to default specified in by file `paths.h' when XEmacs was built.
|
|
3061 If there were no paths specified in `paths.h', then XEmacs chooses a default
|
|
3062 value for this variable by looking around in the file-system near the
|
|
3063 directory in which the XEmacs executable resides.
|
|
3064 */ );
|
267
|
3065 Vload_path = Qnil;
|
0
|
3066
|
|
3067 /* xxxDEFVAR_LISP ("dump-load-path", &Vdump_load_path,
|
|
3068 "*Location of lisp files to be used when dumping ONLY."); */
|
|
3069
|
|
3070 DEFVAR_BOOL ("load-in-progress", &load_in_progress /*
|
|
3071 Non-nil iff inside of `load'.
|
|
3072 */ );
|
|
3073
|
|
3074 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist /*
|
|
3075 An alist of expressions to be evalled when particular files are loaded.
|
|
3076 Each element looks like (FILENAME FORMS...).
|
|
3077 When `load' is run and the file-name argument is FILENAME,
|
|
3078 the FORMS in the corresponding element are executed at the end of loading.
|
|
3079
|
|
3080 FILENAME must match exactly! Normally FILENAME is the name of a library,
|
|
3081 with no directory specified, since that is how `load' is normally called.
|
|
3082 An error in FORMS does not undo the load,
|
|
3083 but does prevent execution of the rest of the FORMS.
|
|
3084 */ );
|
|
3085 Vafter_load_alist = Qnil;
|
|
3086
|
|
3087 DEFVAR_BOOL ("load-warn-when-source-newer", &load_warn_when_source_newer /*
|
|
3088 *Whether `load' should check whether the source is newer than the binary.
|
|
3089 If this variable is true, then when a `.elc' file is being loaded and the
|
|
3090 corresponding `.el' is newer, a warning message will be printed.
|
|
3091 */ );
|
|
3092 load_warn_when_source_newer = 0;
|
|
3093
|
|
3094 DEFVAR_BOOL ("load-warn-when-source-only", &load_warn_when_source_only /*
|
|
3095 *Whether `load' should warn when loading a `.el' file instead of an `.elc'.
|
|
3096 If this variable is true, then when `load' is called with a filename without
|
|
3097 an extension, and the `.elc' version doesn't exist but the `.el' version does,
|
|
3098 then a message will be printed. If an explicit extension is passed to `load',
|
|
3099 no warning will be printed.
|
|
3100 */ );
|
|
3101 load_warn_when_source_only = 0;
|
|
3102
|
|
3103 DEFVAR_BOOL ("load-ignore-elc-files", &load_ignore_elc_files /*
|
|
3104 *Whether `load' should ignore `.elc' files when a suffix is not given.
|
|
3105 This is normally used only to bootstrap the `.elc' files when building XEmacs.
|
|
3106 */ );
|
|
3107 load_ignore_elc_files = 0;
|
|
3108
|
|
3109 #ifdef LOADHIST
|
|
3110 DEFVAR_LISP ("load-history", &Vload_history /*
|
|
3111 Alist mapping source file names to symbols and features.
|
|
3112 Each alist element is a list that starts with a file name,
|
|
3113 except for one element (optional) that starts with nil and describes
|
|
3114 definitions evaluated from buffers not visiting files.
|
|
3115 The remaining elements of each list are symbols defined as functions
|
|
3116 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.
|
|
3117 */ );
|
|
3118 Vload_history = Qnil;
|
|
3119
|
|
3120 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list /*
|
|
3121 Used for internal purposes by `load'.
|
|
3122 */ );
|
|
3123 Vcurrent_load_list = Qnil;
|
|
3124 #endif
|
|
3125
|
|
3126 DEFVAR_LISP ("load-file-name", &Vload_file_name /*
|
|
3127 Full name of file being loaded by `load'.
|
|
3128 */ );
|
|
3129 Vload_file_name = Qnil;
|
|
3130
|
|
3131 DEFVAR_LISP ("load-read-function", &Vload_read_function /*
|
|
3132 "Function used by `load' and `eval-region' for reading expressions.
|
|
3133 The default is nil, which means use the function `read'.
|
|
3134 */ );
|
|
3135 Vload_read_function = Qnil;
|
|
3136
|
|
3137 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings /*
|
|
3138 Non-nil means `load' should force-load all dynamic doc strings.
|
|
3139 This is useful when the file being loaded is a temporary copy.
|
|
3140 */ );
|
|
3141 load_force_doc_strings = 0;
|
|
3142
|
|
3143 DEFVAR_LISP ("source-directory", &Vsource_directory /*
|
|
3144 Directory in which XEmacs sources were found when XEmacs was built.
|
|
3145 You cannot count on them to still be there!
|
|
3146 */ );
|
|
3147 Vsource_directory = Qnil;
|
|
3148
|
272
|
3149 /* Used to be named `puke-on-fsf-keys' */
|
|
3150 DEFVAR_BOOL ("fail-on-bucky-bit-character-escapes",
|
|
3151 &fail_on_bucky_bit_character_escapes /*
|
0
|
3152 Whether `read' should signal an error when it encounters unsupported
|
|
3153 character escape syntaxes or just read them incorrectly.
|
|
3154 */ );
|
272
|
3155 fail_on_bucky_bit_character_escapes = 0;
|
0
|
3156
|
|
3157 /* This must be initialized in init_lread otherwise it may start out
|
|
3158 with values saved when the image is dumped. */
|
|
3159 staticpro (&Vload_descriptor_list);
|
|
3160
|
231
|
3161 Vread_buffer_stream = Qnil;
|
0
|
3162 staticpro (&Vread_buffer_stream);
|
|
3163
|
|
3164 /* Initialized in init_lread. */
|
|
3165 staticpro (&Vload_force_doc_string_list);
|
|
3166
|
|
3167 Vload_file_name_internal = Qnil;
|
|
3168 staticpro (&Vload_file_name_internal);
|
|
3169
|
|
3170 Vload_file_name_internal_the_purecopy = Qnil;
|
|
3171 staticpro (&Vload_file_name_internal_the_purecopy);
|
|
3172
|
|
3173 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
3174 Vcurrent_compiled_function_annotation = Qnil;
|
|
3175 staticpro (&Vcurrent_compiled_function_annotation);
|
|
3176 #endif
|
|
3177
|
|
3178 /* So that early-early stuff will work */
|
|
3179 Ffset (Qload, intern ("load-internal"));
|
|
3180
|
140
|
3181 #ifdef FEATUREP_SYNTAX
|
207
|
3182 defsymbol (&Qfeaturep, "featurep");
|
140
|
3183 Fprovide(intern("xemacs"));
|
155
|
3184 #ifdef INFODOCK
|
|
3185 Fprovide(intern("infodock"));
|
231
|
3186 #endif /* INFODOCK */
|
|
3187 #endif /* FEATUREP_SYNTAX */
|
140
|
3188
|
0
|
3189 #ifdef LISP_BACKQUOTES
|
|
3190 old_backquote_flag = new_backquote_flag = 0;
|
|
3191 #endif
|
185
|
3192
|
0
|
3193 #ifdef I18N3
|
|
3194 Vfile_domain = Qnil;
|
|
3195 #endif
|
245
|
3196
|
|
3197 read_objects = Qnil;
|
|
3198 staticpro (&read_objects);
|
0
|
3199 }
|