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