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