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