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