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