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