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
|
|
1212 /* Don't bother recording anything for preloaded files. */
|
|
1213 if (purify_flag)
|
|
1214 return;
|
|
1215
|
|
1216 tail = Vload_history;
|
|
1217 prev = Qnil;
|
|
1218 foundit = 0;
|
|
1219 while (!NILP (tail))
|
|
1220 {
|
|
1221 tem = Fcar (tail);
|
|
1222
|
|
1223 /* Find the feature's previous assoc list... */
|
195
|
1224 if (internal_equal (source, Fcar (tem), 0))
|
0
|
1225 {
|
|
1226 foundit = 1;
|
|
1227
|
|
1228 /* If we're loading, remove it. */
|
|
1229 if (loading)
|
173
|
1230 {
|
0
|
1231 if (NILP (prev))
|
|
1232 Vload_history = Fcdr (tail);
|
|
1233 else
|
|
1234 Fsetcdr (prev, Fcdr (tail));
|
|
1235 }
|
|
1236
|
|
1237 /* Otherwise, cons on new symbols that are not already members. */
|
|
1238 else
|
|
1239 {
|
|
1240 tem2 = Vcurrent_load_list;
|
|
1241
|
|
1242 while (CONSP (tem2))
|
|
1243 {
|
195
|
1244 newelt = XCAR (tem2);
|
0
|
1245
|
|
1246 if (NILP (Fmemq (newelt, tem)))
|
|
1247 Fsetcar (tail, Fcons (Fcar (tem),
|
|
1248 Fcons (newelt, Fcdr (tem))));
|
|
1249
|
195
|
1250 tem2 = XCDR (tem2);
|
0
|
1251 QUIT;
|
|
1252 }
|
|
1253 }
|
|
1254 }
|
|
1255 else
|
|
1256 prev = tail;
|
|
1257 tail = Fcdr (tail);
|
|
1258 QUIT;
|
|
1259 }
|
|
1260
|
|
1261 /* If we're loading, cons the new assoc onto the front of load-history,
|
|
1262 the most-recently-loaded position. Also do this if we didn't find
|
|
1263 an existing member for the current source. */
|
|
1264 if (loading || !foundit)
|
|
1265 Vload_history = Fcons (Fnreverse (Vcurrent_load_list),
|
|
1266 Vload_history);
|
|
1267 }
|
|
1268
|
|
1269 #else /* !LOADHIST */
|
|
1270 #define build_load_history(x,y)
|
|
1271 #endif /* !LOADHIST */
|
|
1272
|
|
1273
|
|
1274 #if 0 /* FSFmacs defun hack */
|
|
1275 Lisp_Object
|
|
1276 unreadpure (void) /* Used as unwind-protect function in readevalloop */
|
|
1277 {
|
|
1278 read_pure = 0;
|
|
1279 return Qnil;
|
|
1280 }
|
|
1281 #endif /* 0 */
|
|
1282
|
|
1283 static void
|
173
|
1284 readevalloop (Lisp_Object readcharfun,
|
0
|
1285 Lisp_Object sourcename,
|
|
1286 Lisp_Object (*evalfun) (Lisp_Object),
|
|
1287 int printflag)
|
|
1288 {
|
|
1289 /* This function can GC */
|
|
1290 REGISTER Emchar c;
|
|
1291 REGISTER Lisp_Object val;
|
|
1292 int speccount = specpdl_depth ();
|
|
1293 struct gcpro gcpro1;
|
|
1294 struct buffer *b = 0;
|
|
1295
|
|
1296 if (BUFFERP (readcharfun))
|
|
1297 b = XBUFFER (readcharfun);
|
|
1298 else if (MARKERP (readcharfun))
|
|
1299 b = XMARKER (readcharfun)->buffer;
|
|
1300
|
|
1301 specbind (Qstandard_input, readcharfun);
|
|
1302 specbind (Qcurrent_load_list, Qnil);
|
|
1303
|
|
1304 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1305 Vcurrent_compiled_function_annotation = Qnil;
|
|
1306 #endif
|
|
1307 GCPRO1 (sourcename);
|
|
1308
|
|
1309 LOADHIST_ATTACH (sourcename);
|
|
1310
|
|
1311 while (1)
|
|
1312 {
|
|
1313 QUIT;
|
|
1314
|
|
1315 if (b != 0 && !BUFFER_LIVE_P (b))
|
|
1316 error ("Reading from killed buffer");
|
|
1317
|
|
1318 c = readchar (readcharfun);
|
|
1319 if (c == ';')
|
|
1320 {
|
|
1321 /* Skip comment */
|
|
1322 while ((c = readchar (readcharfun)) != '\n' && c != -1)
|
|
1323 QUIT;
|
|
1324 continue;
|
|
1325 }
|
|
1326 if (c < 0)
|
|
1327 break;
|
|
1328
|
|
1329 /* Ignore whitespace here, so we can detect eof. */
|
|
1330 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r')
|
|
1331 continue;
|
|
1332
|
|
1333 #if 0 /* FSFmacs defun hack */
|
|
1334 if (purify_flag && c == '(')
|
|
1335 {
|
|
1336 int count1 = specpdl_depth ();
|
|
1337 record_unwind_protect (unreadpure, Qnil);
|
|
1338 val = read_list (readcharfun, ')', -1, 1);
|
|
1339 unbind_to (count1, Qnil);
|
|
1340 }
|
|
1341 else
|
|
1342 #else /* No "defun hack" -- Emacs 19 uses read-time syntax for bytecodes */
|
|
1343 {
|
|
1344 unreadchar (readcharfun, c);
|
|
1345 if (NILP (Vload_read_function))
|
|
1346 val = read0 (readcharfun);
|
|
1347 else
|
|
1348 val = call1 (Vload_read_function, readcharfun);
|
|
1349 }
|
|
1350 #endif
|
|
1351 val = (*evalfun) (val);
|
|
1352 if (printflag)
|
|
1353 {
|
|
1354 Vvalues = Fcons (val, Vvalues);
|
|
1355 if (EQ (Vstandard_output, Qt))
|
|
1356 Fprin1 (val, Qnil);
|
|
1357 else
|
|
1358 Fprint (val, Qnil);
|
|
1359 }
|
|
1360 }
|
|
1361
|
|
1362 build_load_history (LSTREAMP (readcharfun) ||
|
|
1363 /* This looks weird, but it's what's in FSFmacs */
|
|
1364 (b ? BUF_NARROWED (b) : BUF_NARROWED (current_buffer)),
|
|
1365 sourcename);
|
|
1366 UNGCPRO;
|
|
1367
|
|
1368 unbind_to (speccount, Qnil);
|
|
1369 }
|
|
1370
|
|
1371 #ifndef standalone
|
|
1372
|
20
|
1373 DEFUN ("eval-buffer", Feval_buffer, 0, 2, "bBuffer: ", /*
|
0
|
1374 Execute BUFFER as Lisp code.
|
|
1375 Programs can pass two arguments, BUFFER and PRINTFLAG.
|
|
1376 BUFFER is the buffer to evaluate (nil means use current buffer).
|
|
1377 PRINTFLAG controls printing of output:
|
|
1378 nil means discard it; anything else is stream for print.
|
|
1379
|
|
1380 If there is no error, point does not move. If there is an error,
|
|
1381 point remains at the end of the last character read from the buffer.
|
|
1382 Execute BUFFER as Lisp code.
|
20
|
1383 */
|
|
1384 (bufname, printflag))
|
0
|
1385 {
|
|
1386 /* This function can GC */
|
|
1387 int speccount = specpdl_depth ();
|
|
1388 Lisp_Object tem, buf;
|
|
1389
|
|
1390 if (NILP (bufname))
|
|
1391 buf = Fcurrent_buffer ();
|
|
1392 else
|
|
1393 buf = Fget_buffer (bufname);
|
|
1394 if (NILP (buf))
|
|
1395 error ("No such buffer.");
|
|
1396
|
|
1397 if (NILP (printflag))
|
|
1398 tem = Qsymbolp; /* #### #@[]*&$#*[& SI:NULL-STREAM */
|
|
1399 else
|
|
1400 tem = printflag;
|
|
1401 specbind (Qstandard_output, tem);
|
|
1402 record_unwind_protect (save_excursion_restore, save_excursion_save ());
|
|
1403 BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
|
|
1404 readevalloop (buf, XBUFFER (buf)->filename, Feval,
|
|
1405 !NILP (printflag));
|
|
1406
|
|
1407 return unbind_to (speccount, Qnil);
|
|
1408 }
|
|
1409
|
|
1410 #if 0
|
149
|
1411 xxDEFUN ("eval-current-buffer", Feval_current_buffer, 0, 1, "", /*
|
0
|
1412 Execute the current buffer as Lisp code.
|
|
1413 Programs can pass argument PRINTFLAG which controls printing of output:
|
|
1414 nil means discard it; anything else is stream for print.
|
|
1415
|
|
1416 If there is no error, point does not move. If there is an error,
|
|
1417 point remains at the end of the last character read from the buffer.
|
149
|
1418 */
|
|
1419 (printflag))
|
0
|
1420 {
|
|
1421 code omitted;
|
|
1422 }
|
149
|
1423 #endif /* 0 */
|
0
|
1424
|
20
|
1425 DEFUN ("eval-region", Feval_region, 2, 3, "r", /*
|
0
|
1426 Execute the region as Lisp code.
|
|
1427 When called from programs, expects two arguments,
|
|
1428 giving starting and ending indices in the current buffer
|
|
1429 of the text to be executed.
|
|
1430 Programs can pass third argument PRINTFLAG which controls output:
|
|
1431 nil means discard it; anything else is stream for printing it.
|
|
1432
|
|
1433 If there is no error, point does not move. If there is an error,
|
|
1434 point remains at the end of the last character read from the buffer.
|
|
1435
|
|
1436 Note: Before evaling the region, this function narrows the buffer to it.
|
|
1437 If the code being eval'd should happen to trigger a redisplay you may
|
|
1438 see some text temporarily disappear because of this.
|
20
|
1439 */
|
|
1440 (b, e, printflag))
|
0
|
1441 {
|
|
1442 /* This function can GC */
|
|
1443 int speccount = specpdl_depth ();
|
|
1444 Lisp_Object tem;
|
|
1445 Lisp_Object cbuf = Fcurrent_buffer ();
|
|
1446
|
|
1447 if (NILP (printflag))
|
|
1448 tem = Qsymbolp; /* #### #@[]*&$#*[& SI:NULL-STREAM */
|
|
1449 else
|
|
1450 tem = printflag;
|
|
1451 specbind (Qstandard_output, tem);
|
|
1452
|
|
1453 if (NILP (printflag))
|
|
1454 record_unwind_protect (save_excursion_restore, save_excursion_save ());
|
|
1455 record_unwind_protect (save_restriction_restore, save_restriction_save ());
|
|
1456
|
|
1457 /* This both uses b and checks its type. */
|
|
1458 Fgoto_char (b, cbuf);
|
|
1459 Fnarrow_to_region (make_int (BUF_BEGV (current_buffer)), e, cbuf);
|
|
1460 readevalloop (cbuf, XBUFFER (cbuf)->filename, Feval,
|
|
1461 !NILP (printflag));
|
|
1462
|
|
1463 return unbind_to (speccount, Qnil);
|
|
1464 }
|
|
1465
|
|
1466 #endif /* standalone */
|
|
1467
|
20
|
1468 DEFUN ("read", Fread, 0, 1, 0, /*
|
0
|
1469 Read one Lisp expression as text from STREAM, return as Lisp object.
|
|
1470 If STREAM is nil, use the value of `standard-input' (which see).
|
|
1471 STREAM or the value of `standard-input' may be:
|
|
1472 a buffer (read from point and advance it)
|
|
1473 a marker (read from where it points and advance it)
|
|
1474 a function (call it with no arguments for each character,
|
|
1475 call it with a char as argument to push a char back)
|
|
1476 a string (takes text from string, starting at the beginning)
|
|
1477 t (read text line using minibuffer and use it).
|
20
|
1478 */
|
|
1479 (stream))
|
0
|
1480 {
|
|
1481 if (NILP (stream))
|
|
1482 stream = Vstandard_input;
|
|
1483 if (EQ (stream, Qt))
|
|
1484 stream = Qread_char;
|
|
1485
|
|
1486 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1487 Vcurrent_compiled_function_annotation = Qnil;
|
|
1488 #endif
|
|
1489 #ifndef standalone
|
|
1490 if (EQ (stream, Qread_char))
|
|
1491 {
|
173
|
1492 Lisp_Object val = call1 (Qread_from_minibuffer,
|
0
|
1493 build_translated_string ("Lisp expression: "));
|
173
|
1494 return Fcar (Fread_from_string (val, Qnil, Qnil));
|
0
|
1495 }
|
|
1496 #endif
|
|
1497
|
|
1498 if (STRINGP (stream))
|
|
1499 return Fcar (Fread_from_string (stream, Qnil, Qnil));
|
|
1500
|
|
1501 return read0 (stream);
|
|
1502 }
|
|
1503
|
20
|
1504 DEFUN ("read-from-string", Fread_from_string, 1, 3, 0, /*
|
0
|
1505 Read one Lisp expression which is represented as text by STRING.
|
|
1506 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
|
|
1507 START and END optionally delimit a substring of STRING from which to read;
|
|
1508 they default to 0 and (length STRING) respectively.
|
20
|
1509 */
|
|
1510 (string, start, end))
|
0
|
1511 {
|
|
1512 Bytecount startval, endval;
|
|
1513 Lisp_Object tem;
|
|
1514 Lisp_Object lispstream = Qnil;
|
|
1515 struct gcpro gcpro1;
|
|
1516
|
|
1517 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1518 Vcurrent_compiled_function_annotation = Qnil;
|
|
1519 #endif
|
|
1520 GCPRO1 (lispstream);
|
|
1521 CHECK_STRING (string);
|
|
1522 get_string_range_byte (string, start, end, &startval, &endval,
|
|
1523 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
1524 lispstream = make_lisp_string_input_stream (string, startval,
|
|
1525 endval - startval);
|
|
1526
|
|
1527 tem = read0 (lispstream);
|
|
1528 /* Yeah, it's ugly. Gonna make something of it?
|
|
1529 At least our reader is reentrant ... */
|
|
1530 tem =
|
|
1531 (Fcons (tem, make_int
|
|
1532 (bytecount_to_charcount
|
16
|
1533 (XSTRING_DATA (string),
|
0
|
1534 startval + Lstream_byte_count (XLSTREAM (lispstream))))));
|
|
1535 Lstream_delete (XLSTREAM (lispstream));
|
|
1536 UNGCPRO;
|
|
1537 return tem;
|
|
1538 }
|
|
1539
|
|
1540
|
|
1541 #ifdef LISP_BACKQUOTES
|
|
1542
|
|
1543 static Lisp_Object
|
|
1544 backquote_unwind (Lisp_Object ptr)
|
|
1545 { /* used as unwind-protect function in read0() */
|
|
1546 int *counter = (int *) get_opaque_ptr (ptr);
|
|
1547 if (--*counter < 0)
|
173
|
1548 *counter = 0;
|
0
|
1549 free_opaque_ptr (ptr);
|
|
1550 return Qnil;
|
|
1551 }
|
|
1552
|
173
|
1553 #endif
|
0
|
1554
|
|
1555 /* Use this for recursive reads, in contexts where internal tokens
|
|
1556 are not allowed. See also read1(). */
|
|
1557 static Lisp_Object
|
|
1558 read0 (Lisp_Object readcharfun)
|
|
1559 {
|
|
1560 Lisp_Object val;
|
|
1561
|
|
1562 val = read1 (readcharfun);
|
|
1563 if (CONSP (val) && UNBOUNDP (XCAR (val)))
|
|
1564 {
|
|
1565 Emchar c = XCHAR (XCDR (val));
|
|
1566 free_cons (XCONS (val));
|
|
1567 return Fsignal (Qinvalid_read_syntax,
|
|
1568 list1 (Fchar_to_string (make_char (c))));
|
|
1569 }
|
|
1570
|
|
1571 return val;
|
|
1572 }
|
|
1573
|
|
1574 static Emchar
|
|
1575 read_escape (Lisp_Object readcharfun)
|
|
1576 {
|
|
1577 /* This function can GC */
|
|
1578 Emchar c = readchar (readcharfun);
|
|
1579 switch (c)
|
|
1580 {
|
|
1581 case 'a': return '\007';
|
|
1582 case 'b': return '\b';
|
|
1583 case 'd': return 0177;
|
|
1584 case 'e': return 033;
|
|
1585 case 'f': return '\f';
|
|
1586 case 'n': return '\n';
|
|
1587 case 'r': return '\r';
|
|
1588 case 't': return '\t';
|
|
1589 case 'v': return '\v';
|
|
1590 case '\n': return -1;
|
|
1591
|
|
1592 case 'M':
|
|
1593 c = readchar (readcharfun);
|
|
1594 if (c != '-')
|
|
1595 error ("Invalid escape character syntax");
|
|
1596 c = readchar (readcharfun);
|
|
1597 if (c == '\\')
|
|
1598 c = read_escape (readcharfun);
|
|
1599 return c | 0200;
|
|
1600
|
|
1601 #define FSF_KEYS
|
|
1602 #ifdef FSF_KEYS
|
|
1603
|
|
1604 #define alt_modifier (0x040000)
|
|
1605 #define super_modifier (0x080000)
|
|
1606 #define hyper_modifier (0x100000)
|
|
1607 #define shift_modifier (0x200000)
|
|
1608 /* fsf uses a different modifiers for meta and control. Possibly
|
173
|
1609 byte_compiled code will still work fsfmacs, though... --Stig
|
0
|
1610
|
|
1611 #define ctl_modifier (0x400000)
|
173
|
1612 #define meta_modifier (0x800000)
|
0
|
1613 */
|
|
1614 #define FSF_LOSSAGE(mask) \
|
|
1615 if (puke_on_fsf_keys || ((c = readchar (readcharfun)) != '-')) \
|
|
1616 error ("Invalid escape character syntax"); \
|
|
1617 if ((c = readchar (readcharfun)) == '\\') \
|
|
1618 c = read_escape (readcharfun); \
|
|
1619 return c | mask
|
|
1620
|
|
1621 case 'S': FSF_LOSSAGE (shift_modifier);
|
|
1622 case 'H': FSF_LOSSAGE (hyper_modifier);
|
|
1623 case 'A': FSF_LOSSAGE (alt_modifier);
|
|
1624 case 's': FSF_LOSSAGE (super_modifier);
|
|
1625 #undef alt_modifier
|
|
1626 #undef super_modifier
|
|
1627 #undef hyper_modifier
|
|
1628 #undef shift_modifier
|
|
1629 #undef FSF_LOSSAGE
|
|
1630
|
|
1631 #endif /* FSF_KEYS */
|
|
1632
|
|
1633 case 'C':
|
|
1634 c = readchar (readcharfun);
|
|
1635 if (c != '-')
|
|
1636 error ("Invalid escape character syntax");
|
|
1637 case '^':
|
|
1638 c = readchar (readcharfun);
|
|
1639 if (c == '\\')
|
|
1640 c = read_escape (readcharfun);
|
|
1641 /* FSFmacs junk for non-ASCII controls.
|
|
1642 Not used here. */
|
|
1643 if (c == '?')
|
|
1644 return 0177;
|
|
1645 else
|
173
|
1646 return c & (0200 | 037);
|
|
1647
|
0
|
1648 case '0':
|
|
1649 case '1':
|
|
1650 case '2':
|
|
1651 case '3':
|
|
1652 case '4':
|
|
1653 case '5':
|
|
1654 case '6':
|
|
1655 case '7':
|
|
1656 /* An octal escape, as in ANSI C. */
|
|
1657 {
|
|
1658 REGISTER Emchar i = c - '0';
|
|
1659 REGISTER int count = 0;
|
|
1660 while (++count < 3)
|
|
1661 {
|
|
1662 if ((c = readchar (readcharfun)) >= '0' && c <= '7')
|
|
1663 i = (i << 3) + (c - '0');
|
|
1664 else
|
|
1665 {
|
|
1666 unreadchar (readcharfun, c);
|
|
1667 break;
|
|
1668 }
|
|
1669 }
|
|
1670 return i;
|
|
1671 }
|
|
1672
|
|
1673 case 'x':
|
|
1674 /* A hex escape, as in ANSI C. */
|
|
1675 {
|
|
1676 REGISTER Emchar i = 0;
|
|
1677 while (1)
|
|
1678 {
|
|
1679 c = readchar (readcharfun);
|
|
1680 /* Remember, can't use isdigit(), isalpha() etc. on Emchars */
|
|
1681 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0');
|
|
1682 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10;
|
|
1683 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10;
|
|
1684 else
|
|
1685 {
|
|
1686 unreadchar (readcharfun, c);
|
|
1687 break;
|
|
1688 }
|
|
1689 }
|
|
1690 return i;
|
|
1691 }
|
|
1692
|
70
|
1693 #ifdef MULE
|
|
1694 /* #### need some way of reading an extended character with
|
|
1695 an escape sequence. */
|
|
1696 #endif
|
16
|
1697
|
0
|
1698 default:
|
|
1699 return c;
|
|
1700 }
|
|
1701 }
|
|
1702
|
|
1703
|
|
1704
|
|
1705 /* read symbol-constituent stuff into `Vread_buffer_stream'. */
|
|
1706 static Bytecount
|
|
1707 read_atom_0 (Lisp_Object readcharfun, Emchar firstchar, int *saw_a_backslash)
|
|
1708 {
|
|
1709 /* This function can GC */
|
|
1710 Emchar c = ((firstchar) >= 0 ? firstchar : readchar (readcharfun));
|
|
1711 Lstream_rewind (XLSTREAM (Vread_buffer_stream));
|
|
1712
|
|
1713 *saw_a_backslash = 0;
|
|
1714
|
|
1715 while (c > 040 /* #### - comma should be here as should backquote */
|
|
1716 && !(c == '\"' || c == '\'' || c == ';'
|
|
1717 || c == '(' || c == ')'
|
|
1718 #ifndef LISP_FLOAT_TYPE
|
|
1719 /* If we have floating-point support, then we need
|
|
1720 to allow <digits><dot><digits>. */
|
|
1721 || c =='.'
|
|
1722 #endif /* not LISP_FLOAT_TYPE */
|
|
1723 || c == '[' || c == ']' || c == '#'
|
|
1724 ))
|
|
1725 {
|
|
1726 if (c == '\\')
|
|
1727 {
|
|
1728 c = readchar (readcharfun);
|
|
1729 *saw_a_backslash = 1;
|
|
1730 }
|
|
1731 Lstream_put_emchar (XLSTREAM (Vread_buffer_stream), c);
|
|
1732 QUIT;
|
|
1733 c = readchar (readcharfun);
|
|
1734 }
|
|
1735
|
|
1736 if (c >= 0)
|
|
1737 unreadchar (readcharfun, c);
|
|
1738 /* blasted terminating 0 */
|
|
1739 Lstream_put_emchar (XLSTREAM (Vread_buffer_stream), 0);
|
|
1740 Lstream_flush (XLSTREAM (Vread_buffer_stream));
|
|
1741
|
173
|
1742 return Lstream_byte_count (XLSTREAM (Vread_buffer_stream)) - 1;
|
0
|
1743 }
|
|
1744
|
|
1745 static Lisp_Object parse_integer (CONST Bufbyte *buf, Bytecount len, int base);
|
|
1746
|
|
1747 static Lisp_Object
|
|
1748 read_atom (Lisp_Object readcharfun,
|
|
1749 Emchar firstchar,
|
|
1750 int uninterned_symbol)
|
|
1751 {
|
|
1752 /* This function can GC */
|
|
1753 int saw_a_backslash;
|
|
1754 Bytecount len = read_atom_0 (readcharfun, firstchar, &saw_a_backslash);
|
|
1755 char *read_ptr = (char *)
|
|
1756 resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream));
|
|
1757
|
|
1758 /* Is it an integer? */
|
|
1759 if (! (saw_a_backslash || uninterned_symbol))
|
|
1760 {
|
|
1761 /* If a token had any backslashes in it, it is disqualified from
|
|
1762 being an integer or a float. This means that 123\456 is a
|
|
1763 symbol, as is \123 (which is the way (intern "123") prints).
|
110
|
1764 Also, if token was preceded by #:, it's always a symbol.
|
0
|
1765 */
|
|
1766 char *p = read_ptr + len;
|
|
1767 char *p1 = read_ptr;
|
|
1768
|
|
1769 if (*p1 == '+' || *p1 == '-') p1++;
|
|
1770 if (p1 != p)
|
|
1771 {
|
|
1772 int c;
|
|
1773
|
|
1774 while (p1 != p && (c = *p1) >= '0' && c <= '9')
|
|
1775 p1++;
|
|
1776 #ifdef LISP_FLOAT_TYPE
|
|
1777 /* Integers can have trailing decimal points. */
|
|
1778 if (p1 > read_ptr && p1 < p && *p1 == '.')
|
|
1779 p1++;
|
|
1780 #endif
|
|
1781 if (p1 == p)
|
|
1782 {
|
|
1783 /* It is an integer. */
|
|
1784 #ifdef LISP_FLOAT_TYPE
|
|
1785 if (p1[-1] == '.')
|
|
1786 p1[-1] = '\0';
|
|
1787 #endif
|
|
1788 #if 0
|
|
1789 {
|
|
1790 int number = 0;
|
|
1791 if (sizeof (int) == sizeof (EMACS_INT))
|
|
1792 number = atoi (read_buffer);
|
|
1793 else if (sizeof (long) == sizeof (EMACS_INT))
|
|
1794 number = atol (read_buffer);
|
|
1795 else
|
|
1796 abort ();
|
173
|
1797 return make_int (number);
|
0
|
1798 }
|
|
1799 #else
|
173
|
1800 return parse_integer ((Bufbyte *) read_ptr, len, 10);
|
0
|
1801 #endif
|
|
1802 }
|
|
1803 }
|
|
1804 #ifdef LISP_FLOAT_TYPE
|
|
1805 if (isfloat_string (read_ptr))
|
|
1806 return make_float (atof (read_ptr));
|
|
1807 #endif
|
|
1808 }
|
|
1809
|
|
1810 {
|
|
1811 Lisp_Object sym;
|
|
1812 if (uninterned_symbol)
|
173
|
1813 sym = (Fmake_symbol ((purify_flag)
|
0
|
1814 ? make_pure_pname ((Bufbyte *) read_ptr, len, 0)
|
|
1815 : make_string ((Bufbyte *) read_ptr, len)));
|
|
1816 else
|
|
1817 {
|
|
1818 /* intern will purecopy pname if necessary */
|
|
1819 Lisp_Object name = make_string ((Bufbyte *) read_ptr, len);
|
|
1820 sym = Fintern (name, Qnil);
|
|
1821 }
|
|
1822 if (SYMBOL_IS_KEYWORD (sym))
|
|
1823 {
|
|
1824 /* the LISP way is to put keywords in their own package, but we don't
|
|
1825 have packages, so we do something simpler. Someday, maybe we'll
|
|
1826 have packages and then this will be reworked. --Stig. */
|
|
1827 XSYMBOL (sym)->value = sym;
|
|
1828 }
|
173
|
1829 return sym;
|
0
|
1830 }
|
|
1831 }
|
|
1832
|
|
1833
|
|
1834 static Lisp_Object
|
|
1835 parse_integer (CONST Bufbyte *buf, Bytecount len, int base)
|
|
1836 {
|
|
1837 CONST Bufbyte *lim = buf + len;
|
|
1838 CONST Bufbyte *p = buf;
|
|
1839 unsigned EMACS_INT num = 0;
|
|
1840 int negativland = 0;
|
|
1841
|
|
1842 if (*p == '-')
|
|
1843 {
|
|
1844 negativland = 1;
|
|
1845 p++;
|
|
1846 }
|
|
1847 else if (*p == '+')
|
|
1848 {
|
|
1849 p++;
|
|
1850 }
|
|
1851
|
|
1852 if (p == lim)
|
|
1853 goto loser;
|
|
1854
|
142
|
1855 for (; (p < lim) && (*p != '\0'); p++)
|
0
|
1856 {
|
|
1857 int c = *p;
|
|
1858 unsigned EMACS_INT onum;
|
|
1859
|
|
1860 if (isdigit (c))
|
|
1861 c = c - '0';
|
|
1862 else if (isupper (c))
|
|
1863 c = c - 'A' + 10;
|
|
1864 else if (islower (c))
|
|
1865 c = c - 'a' + 10;
|
|
1866 else
|
|
1867 goto loser;
|
173
|
1868
|
0
|
1869 if (c < 0 || c >= base)
|
|
1870 goto loser;
|
|
1871
|
|
1872 onum = num;
|
|
1873 num = num * base + c;
|
|
1874 if (num < onum)
|
|
1875 goto overflow;
|
|
1876 }
|
|
1877
|
|
1878 {
|
|
1879 Lisp_Object result = make_int ((negativland) ? -num : num);
|
|
1880 if (num && ((XINT (result) < 0) != negativland))
|
|
1881 goto overflow;
|
|
1882 if (XINT (result) != ((negativland) ? -num : num))
|
|
1883 goto overflow;
|
173
|
1884 return result;
|
0
|
1885 }
|
|
1886 overflow:
|
173
|
1887 return Fsignal (Qinvalid_read_syntax,
|
0
|
1888 list3 (build_translated_string
|
|
1889 ("Integer constant overflow in reader"),
|
|
1890 make_string (buf, len),
|
|
1891 make_int (base)));
|
|
1892 loser:
|
173
|
1893 return Fsignal (Qinvalid_read_syntax,
|
0
|
1894 list3 (build_translated_string
|
|
1895 ("Invalid integer constant in reader"),
|
|
1896 make_string (buf, len),
|
|
1897 make_int (base)));
|
|
1898 }
|
|
1899
|
|
1900
|
|
1901 static Lisp_Object
|
|
1902 read_integer (Lisp_Object readcharfun, int base)
|
|
1903 {
|
|
1904 /* This function can GC */
|
|
1905 int saw_a_backslash;
|
|
1906 Bytecount len = read_atom_0 (readcharfun, -1, &saw_a_backslash);
|
|
1907 return (parse_integer
|
|
1908 (resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)),
|
|
1909 ((saw_a_backslash)
|
|
1910 ? 0 /* make parse_integer signal error */
|
|
1911 : len),
|
|
1912 base));
|
|
1913 }
|
|
1914
|
|
1915 static Lisp_Object
|
|
1916 read_bit_vector (Lisp_Object readcharfun)
|
|
1917 {
|
185
|
1918 unsigned_char_dynarr *dyn = Dynarr_new (unsigned_char);
|
0
|
1919 Emchar c;
|
|
1920
|
|
1921 while (1)
|
|
1922 {
|
|
1923 c = readchar (readcharfun);
|
|
1924 if (c != '0' && c != '1')
|
|
1925 break;
|
|
1926 Dynarr_add (dyn, (unsigned char) (c - '0'));
|
|
1927 }
|
|
1928
|
|
1929 if (c >= 0)
|
|
1930 unreadchar (readcharfun, c);
|
|
1931
|
|
1932 return make_bit_vector_from_byte_vector (Dynarr_atp (dyn, 0),
|
|
1933 Dynarr_length (dyn));
|
|
1934 }
|
|
1935
|
|
1936
|
|
1937
|
|
1938 /* structures */
|
|
1939
|
|
1940 struct structure_type *
|
|
1941 define_structure_type (Lisp_Object type,
|
|
1942 int (*validate) (Lisp_Object data,
|
|
1943 Error_behavior errb),
|
|
1944 Lisp_Object (*instantiate) (Lisp_Object data))
|
|
1945 {
|
|
1946 struct structure_type st;
|
|
1947
|
|
1948 st.type = type;
|
185
|
1949 st.keywords = Dynarr_new (structure_keyword_entry);
|
0
|
1950 st.validate = validate;
|
|
1951 st.instantiate = instantiate;
|
|
1952 Dynarr_add (the_structure_type_dynarr, st);
|
|
1953
|
|
1954 return Dynarr_atp (the_structure_type_dynarr,
|
|
1955 Dynarr_length (the_structure_type_dynarr) - 1);
|
|
1956 }
|
|
1957
|
|
1958 void
|
|
1959 define_structure_type_keyword (struct structure_type *st, Lisp_Object keyword,
|
|
1960 int (*validate) (Lisp_Object keyword,
|
|
1961 Lisp_Object value,
|
|
1962 Error_behavior errb))
|
|
1963 {
|
|
1964 struct structure_keyword_entry en;
|
|
1965
|
|
1966 en.keyword = keyword;
|
|
1967 en.validate = validate;
|
|
1968 Dynarr_add (st->keywords, en);
|
|
1969 }
|
|
1970
|
|
1971 static struct structure_type *
|
|
1972 recognized_structure_type (Lisp_Object type)
|
|
1973 {
|
|
1974 int i;
|
|
1975
|
|
1976 for (i = 0; i < Dynarr_length (the_structure_type_dynarr); i++)
|
|
1977 {
|
|
1978 struct structure_type *st = Dynarr_atp (the_structure_type_dynarr, i);
|
|
1979 if (EQ (st->type, type))
|
|
1980 return st;
|
|
1981 }
|
|
1982
|
|
1983 return 0;
|
|
1984 }
|
|
1985
|
|
1986 static Lisp_Object
|
|
1987 read_structure (Lisp_Object readcharfun)
|
|
1988 {
|
|
1989 Emchar c = readchar (readcharfun);
|
|
1990 Lisp_Object list = Qnil;
|
|
1991 Lisp_Object orig_list = Qnil;
|
|
1992 Lisp_Object already_seen = Qnil;
|
173
|
1993 int keyword_count;
|
0
|
1994 struct structure_type *st;
|
|
1995 struct gcpro gcpro1, gcpro2;
|
|
1996
|
|
1997 GCPRO2 (orig_list, already_seen);
|
|
1998 if (c != '(')
|
|
1999 RETURN_UNGCPRO (continuable_syntax_error ("#s not followed by paren"));
|
|
2000 list = read_list (readcharfun, ')', 0, 0);
|
|
2001 orig_list = list;
|
|
2002 {
|
|
2003 int len = XINT (Flength (list));
|
|
2004 if (len == 0)
|
|
2005 RETURN_UNGCPRO (continuable_syntax_error
|
|
2006 ("structure type not specified"));
|
|
2007 if (!(len & 1))
|
|
2008 RETURN_UNGCPRO
|
|
2009 (continuable_syntax_error
|
|
2010 ("structures must have alternating keyword/value pairs"));
|
|
2011 }
|
173
|
2012
|
0
|
2013 st = recognized_structure_type (XCAR (list));
|
|
2014 if (!st)
|
173
|
2015 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax,
|
|
2016 list2 (build_translated_string
|
|
2017 ("unrecognized structure type"),
|
|
2018 XCAR (list))));
|
0
|
2019
|
|
2020 list = Fcdr (list);
|
173
|
2021 keyword_count = Dynarr_length (st->keywords);
|
0
|
2022 while (!NILP (list))
|
|
2023 {
|
|
2024 Lisp_Object keyword, value;
|
|
2025 int i;
|
173
|
2026 struct structure_keyword_entry *en = NULL;
|
|
2027
|
0
|
2028 keyword = Fcar (list);
|
|
2029 list = Fcdr (list);
|
|
2030 value = Fcar (list);
|
|
2031 list = Fcdr (list);
|
173
|
2032
|
0
|
2033 if (!NILP (memq_no_quit (keyword, already_seen)))
|
173
|
2034 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax,
|
|
2035 list2 (build_translated_string
|
|
2036 ("structure keyword already seen"),
|
|
2037 keyword)));
|
|
2038
|
|
2039 for (i = 0; i < keyword_count; i++)
|
0
|
2040 {
|
|
2041 en = Dynarr_atp (st->keywords, i);
|
|
2042 if (EQ (keyword, en->keyword))
|
|
2043 break;
|
|
2044 }
|
|
2045
|
173
|
2046 if (i == keyword_count)
|
0
|
2047 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax,
|
|
2048 list2 (build_translated_string
|
|
2049 ("unrecognized structure keyword"),
|
|
2050 keyword)));
|
|
2051
|
|
2052 if (en->validate && ! (en->validate) (keyword, value, ERROR_ME))
|
|
2053 RETURN_UNGCPRO
|
|
2054 (Fsignal (Qinvalid_read_syntax,
|
|
2055 list3 (build_translated_string
|
|
2056 ("invalid value for structure keyword"),
|
|
2057 keyword, value)));
|
|
2058
|
|
2059 already_seen = Fcons (keyword, already_seen);
|
|
2060 }
|
|
2061
|
|
2062 if (st->validate && ! (st->validate) (orig_list, ERROR_ME))
|
173
|
2063 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax,
|
|
2064 list2 (build_translated_string
|
|
2065 ("invalid structure initializer"),
|
|
2066 orig_list)));
|
0
|
2067
|
|
2068 RETURN_UNGCPRO ((st->instantiate) (XCDR (orig_list)));
|
173
|
2069 }
|
0
|
2070
|
|
2071
|
|
2072 static Lisp_Object read_compiled_function (Lisp_Object readcharfun,
|
|
2073 int terminator);
|
|
2074 static Lisp_Object read_vector (Lisp_Object readcharfun, int terminator);
|
|
2075
|
|
2076 /* Get the next character; filter out whitespace and comments */
|
|
2077
|
|
2078 static Emchar
|
|
2079 reader_nextchar (Lisp_Object readcharfun)
|
|
2080 {
|
|
2081 /* This function can GC */
|
|
2082 Emchar c;
|
|
2083
|
|
2084 retry:
|
|
2085 QUIT;
|
|
2086 c = readchar (readcharfun);
|
|
2087 if (c < 0)
|
|
2088 {
|
|
2089 if (LSTREAMP (readcharfun))
|
|
2090 signal_error (Qend_of_file,
|
|
2091 list1 (build_string ("internal input stream")));
|
|
2092 else
|
|
2093 signal_error (Qend_of_file, list1 (readcharfun));
|
|
2094 }
|
|
2095
|
|
2096 switch (c)
|
|
2097 {
|
|
2098 default:
|
|
2099 {
|
|
2100 /* Ignore whitespace and control characters */
|
|
2101 if (c <= 040)
|
|
2102 goto retry;
|
173
|
2103 return c;
|
0
|
2104 }
|
|
2105
|
|
2106 case ';':
|
|
2107 {
|
|
2108 /* Comment */
|
|
2109 while ((c = readchar (readcharfun)) >= 0 && c != '\n')
|
|
2110 QUIT;
|
|
2111 goto retry;
|
|
2112 }
|
|
2113 }
|
|
2114 }
|
|
2115
|
|
2116 #if 0
|
|
2117 static Lisp_Object
|
|
2118 list2_pure (int pure, Lisp_Object a, Lisp_Object b)
|
|
2119 {
|
173
|
2120 return pure ? pure_cons (a, pure_cons (b, Qnil)) : list2 (a, b);
|
0
|
2121 }
|
|
2122 #endif
|
|
2123
|
|
2124 /* Read the next Lisp object from the stream READCHARFUN and return it.
|
|
2125 If the return value is a cons whose car is Qunbound, then read1()
|
|
2126 encountered a misplaced token (e.g. a right bracket, right paren,
|
|
2127 or dot followed by a non-number). To filter this stuff out,
|
|
2128 use read0(). */
|
173
|
2129
|
0
|
2130 static Lisp_Object
|
|
2131 read1 (Lisp_Object readcharfun)
|
|
2132 {
|
|
2133 Emchar c;
|
|
2134
|
|
2135 retry:
|
|
2136 c = reader_nextchar (readcharfun);
|
|
2137
|
|
2138 switch (c)
|
|
2139 {
|
|
2140 case '(':
|
|
2141 {
|
|
2142 #ifdef LISP_BACKQUOTES /* old backquote compatibility in lisp reader */
|
|
2143 /* if this is disabled, then other code in eval.c must be enabled */
|
|
2144 Emchar ch = reader_nextchar (readcharfun);
|
|
2145 switch (ch)
|
|
2146 {
|
|
2147 case '`':
|
|
2148 {
|
|
2149 Lisp_Object tem;
|
|
2150 int speccount = specpdl_depth ();
|
|
2151 ++old_backquote_flag;
|
|
2152 record_unwind_protect (backquote_unwind,
|
|
2153 make_opaque_ptr (&old_backquote_flag));
|
|
2154 tem = read0 (readcharfun);
|
|
2155 unbind_to (speccount, Qnil);
|
|
2156 ch = reader_nextchar (readcharfun);
|
|
2157 if (ch != ')')
|
|
2158 {
|
|
2159 unreadchar (readcharfun, ch);
|
|
2160 return Fsignal (Qinvalid_read_syntax,
|
|
2161 list1 (build_string
|
|
2162 ("Weird old-backquote syntax")));
|
|
2163 }
|
|
2164 return list2 (Qbacktick, tem);
|
|
2165 }
|
|
2166 case ',':
|
|
2167 {
|
|
2168 if (old_backquote_flag)
|
|
2169 {
|
|
2170 Lisp_Object tem, comma_type;
|
|
2171 ch = readchar (readcharfun);
|
|
2172 if (ch == '@')
|
|
2173 comma_type = Qcomma_at;
|
|
2174 else
|
|
2175 {
|
|
2176 if (ch >= 0)
|
|
2177 unreadchar (readcharfun, ch);
|
|
2178 comma_type = Qcomma;
|
|
2179 }
|
|
2180 tem = read0 (readcharfun);
|
|
2181 ch = reader_nextchar (readcharfun);
|
|
2182 if (ch != ')')
|
|
2183 {
|
|
2184 unreadchar (readcharfun, ch);
|
|
2185 return Fsignal (Qinvalid_read_syntax,
|
|
2186 list1 (build_string
|
|
2187 ("Weird old-backquote syntax")));
|
|
2188 }
|
|
2189 return list2 (comma_type, tem);
|
|
2190 }
|
|
2191 else
|
|
2192 {
|
|
2193 unreadchar (readcharfun, ch);
|
|
2194 #if 0
|
|
2195 return Fsignal (Qinvalid_read_syntax,
|
|
2196 list1 (build_string ("Comma outside of backquote")));
|
|
2197 #else
|
|
2198 /* #### - yuck....but this is reverse compatible. */
|
|
2199 /* mostly this is required by edebug, which does it's own
|
|
2200 annotated reading. We need to have an annotated_read
|
|
2201 function that records (with markers) the buffer
|
|
2202 positions of the elements that make up lists, then that
|
|
2203 can be used in edebug and bytecomp and the check above
|
|
2204 can go back in. --Stig */
|
|
2205 break;
|
|
2206 #endif
|
|
2207 }
|
|
2208 }
|
|
2209 default:
|
|
2210 unreadchar (readcharfun, ch);
|
|
2211 } /* switch(ch) */
|
|
2212 #endif /* old backquote crap... */
|
|
2213 return read_list (readcharfun, ')', 1, 1);
|
|
2214 }
|
|
2215 case '[':
|
173
|
2216 return read_vector (readcharfun, ']');
|
0
|
2217
|
|
2218 case ')':
|
|
2219 case ']':
|
|
2220 /* #### - huh? these don't do what they seem... */
|
173
|
2221 return noseeum_cons (Qunbound, make_char (c));
|
0
|
2222 case '.':
|
|
2223 {
|
|
2224 #ifdef LISP_FLOAT_TYPE
|
|
2225 /* If a period is followed by a number, then we should read it
|
|
2226 as a floating point number. Otherwise, it denotes a dotted
|
|
2227 pair.
|
|
2228 */
|
|
2229 c = readchar (readcharfun);
|
|
2230 unreadchar (readcharfun, c);
|
|
2231
|
|
2232 /* Can't use isdigit on Emchars */
|
|
2233 if (c < '0' || c > '9')
|
173
|
2234 return noseeum_cons (Qunbound, make_char ('.'));
|
0
|
2235
|
|
2236 /* Note that read_atom will loop
|
|
2237 at least once, assuring that we will not try to UNREAD
|
|
2238 two characters in a row.
|
|
2239 (I think this doesn't matter anymore because there should
|
|
2240 be no more danger in unreading multiple characters) */
|
173
|
2241 return read_atom (readcharfun, '.', 0);
|
0
|
2242
|
|
2243 #else /* ! LISP_FLOAT_TYPE */
|
173
|
2244 return noseeum_cons (Qunbound, make_char ('.'));
|
0
|
2245 #endif /* ! LISP_FLOAT_TYPE */
|
|
2246 }
|
|
2247
|
|
2248 case '#':
|
|
2249 {
|
|
2250 c = readchar (readcharfun);
|
|
2251 switch (c)
|
|
2252 {
|
|
2253 #if 0 /* FSFmacs silly char-table syntax */
|
|
2254 case '^':
|
|
2255 #endif
|
|
2256 #if 0 /* FSFmacs silly bool-vector syntax */
|
|
2257 case '&':
|
|
2258 #endif
|
|
2259 /* "#["-- byte-code constant syntax */
|
|
2260 /* purecons #[...] syntax */
|
173
|
2261 case '[': return read_compiled_function (readcharfun, ']'
|
|
2262 /*, purify_flag */ );
|
0
|
2263 /* "#:"-- quasi-implemented gensym syntax */
|
173
|
2264 case ':': return read_atom (readcharfun, -1, 1);
|
0
|
2265 /* #'x => (function x) */
|
173
|
2266 case '\'': return list2 (Qfunction, read0 (readcharfun));
|
0
|
2267 #if 0
|
|
2268 /* RMS uses this syntax for fat-strings.
|
|
2269 If we use it for vectors, then obscure bugs happen.
|
|
2270 */
|
|
2271 /* "#(" -- Scheme/CL vector syntax */
|
173
|
2272 case '(': return read_vector (readcharfun, ')');
|
0
|
2273 #endif
|
|
2274 #if 0 /* FSFmacs */
|
|
2275 case '(':
|
|
2276 {
|
|
2277 Lisp_Object tmp;
|
|
2278 struct gcpro gcpro1;
|
|
2279
|
|
2280 /* Read the string itself. */
|
|
2281 tmp = read1 (readcharfun);
|
|
2282 if (!STRINGP (tmp))
|
|
2283 {
|
|
2284 if (CONSP (tmp) && UNBOUNDP (XCAR (tmp)))
|
|
2285 free_cons (XCONS (tmp));
|
173
|
2286 return Fsignal (Qinvalid_read_syntax,
|
|
2287 list1 (build_string ("#")));
|
0
|
2288 }
|
|
2289 GCPRO1 (tmp);
|
|
2290 /* Read the intervals and their properties. */
|
|
2291 while (1)
|
|
2292 {
|
|
2293 Lisp_Object beg, end, plist;
|
|
2294 Emchar ch;
|
|
2295 int invalid = 0;
|
173
|
2296
|
0
|
2297 beg = read1 (readcharfun);
|
|
2298 if (CONSP (beg) && UNBOUNDP (XCAR (beg)))
|
|
2299 {
|
|
2300 ch = XCHAR (XCDR (beg));
|
|
2301 free_cons (XCONS (beg));
|
|
2302 if (ch == ')')
|
|
2303 break;
|
|
2304 else
|
|
2305 invalid = 1;
|
|
2306 }
|
|
2307 if (!invalid)
|
|
2308 {
|
|
2309 end = read1 (readcharfun);
|
|
2310 if (CONSP (end) && UNBOUNDP (XCAR (end)))
|
|
2311 {
|
|
2312 free_cons (XCONS (end));
|
|
2313 invalid = 1;
|
|
2314 }
|
|
2315 }
|
|
2316 if (!invalid)
|
|
2317 {
|
|
2318 plist = read1 (readcharfun);
|
|
2319 if (CONSP (plist) && UNBOUNDP (XCAR (plist)))
|
|
2320 {
|
|
2321 free_cons (XCONS (plist));
|
|
2322 invalid = 1;
|
|
2323 }
|
|
2324 }
|
|
2325 if (invalid)
|
|
2326 RETURN_UNGCPRO
|
|
2327 (Fsignal (Qinvalid_read_syntax,
|
|
2328 list2
|
|
2329 (build_string ("invalid string property list"),
|
|
2330 XCDR (plist))));
|
|
2331 Fset_text_properties (beg, end, plist, tmp);
|
|
2332 }
|
|
2333 UNGCPRO;
|
|
2334 return tmp;
|
|
2335 }
|
|
2336 #endif /* 0 */
|
|
2337 case '@':
|
|
2338 {
|
|
2339 /* #@NUMBER is used to skip NUMBER following characters.
|
|
2340 That's used in .elc files to skip over doc strings
|
|
2341 and function definitions. */
|
|
2342 int i, nskip = 0;
|
|
2343
|
|
2344 /* Read a decimal integer. */
|
|
2345 while ((c = readchar (readcharfun)) >= 0
|
|
2346 && c >= '0' && c <= '9')
|
|
2347 nskip = (10 * nskip) + (c - '0');
|
|
2348 if (c >= 0)
|
|
2349 unreadchar (readcharfun, c);
|
|
2350
|
|
2351 /* FSF has code here that maybe caches the skipped
|
|
2352 string. See above for why this is totally
|
|
2353 losing. We handle this differently. */
|
|
2354
|
|
2355 /* Skip that many characters. */
|
|
2356 for (i = 0; i < nskip && c >= 0; i++)
|
|
2357 c = readchar (readcharfun);
|
|
2358
|
|
2359 goto retry;
|
|
2360 }
|
|
2361 case '$': return Vload_file_name_internal;
|
|
2362 /* bit vectors */
|
173
|
2363 case '*': return read_bit_vector (readcharfun);
|
0
|
2364 /* #o10 => 8 -- octal constant syntax */
|
173
|
2365 case 'o': return read_integer (readcharfun, 8);
|
0
|
2366 /* #xdead => 57005 -- hex constant syntax */
|
173
|
2367 case 'x': return read_integer (readcharfun, 16);
|
0
|
2368 /* #b010 => 2 -- binary constant syntax */
|
173
|
2369 case 'b': return read_integer (readcharfun, 2);
|
0
|
2370 /* #s(foobar key1 val1 key2 val2) -- structure syntax */
|
173
|
2371 case 's': return read_structure (readcharfun);
|
0
|
2372 case '<':
|
|
2373 {
|
|
2374 unreadchar (readcharfun, c);
|
|
2375 return Fsignal (Qinvalid_read_syntax,
|
|
2376 list1 (build_string ("Cannot read unreadable object")));
|
|
2377 }
|
140
|
2378 #ifdef FEATUREP_SYNTAX
|
|
2379 case '+':
|
|
2380 case '-':
|
|
2381 {
|
|
2382 Lisp_Object fexp, obj, tem;
|
|
2383 struct gcpro gcpro1, gcpro2;
|
|
2384
|
|
2385 fexp = read0(readcharfun);
|
|
2386 obj = read0(readcharfun);
|
|
2387
|
|
2388 /* the call to `featurep' may GC. */
|
|
2389 GCPRO2(fexp, obj);
|
|
2390 tem = call1(Qfeaturep, fexp);
|
|
2391 UNGCPRO;
|
|
2392
|
|
2393 if (c == '+' && NILP(tem)) goto retry;
|
|
2394 if (c == '-' && !NILP(tem)) goto retry;
|
|
2395 return obj;
|
|
2396 }
|
|
2397 #endif
|
0
|
2398 default:
|
|
2399 {
|
|
2400 unreadchar (readcharfun, c);
|
|
2401 return Fsignal (Qinvalid_read_syntax,
|
|
2402 list1 (build_string ("#")));
|
|
2403 }
|
|
2404 }
|
|
2405 }
|
|
2406
|
|
2407 /* Quote */
|
|
2408 case '\'': return list2 (Qquote, read0 (readcharfun));
|
|
2409
|
|
2410 #ifdef LISP_BACKQUOTES
|
|
2411 case '`':
|
|
2412 {
|
|
2413 Lisp_Object tem;
|
|
2414 int speccount = specpdl_depth ();
|
|
2415 ++new_backquote_flag;
|
|
2416 record_unwind_protect (backquote_unwind,
|
|
2417 make_opaque_ptr (&new_backquote_flag));
|
|
2418 tem = read0 (readcharfun);
|
|
2419 unbind_to (speccount, Qnil);
|
|
2420 return list2 (Qbackquote, tem);
|
|
2421 }
|
|
2422
|
|
2423 case ',':
|
|
2424 {
|
|
2425 if (new_backquote_flag)
|
|
2426 {
|
|
2427 Lisp_Object comma_type = Qnil;
|
|
2428 int ch = readchar (readcharfun);
|
|
2429
|
|
2430 if (ch == '@')
|
|
2431 comma_type = Qcomma_at;
|
|
2432 else if (ch == '.')
|
|
2433 comma_type = Qcomma_dot;
|
|
2434 else
|
|
2435 {
|
|
2436 if (ch >= 0)
|
|
2437 unreadchar (readcharfun, ch);
|
|
2438 comma_type = Qcomma;
|
|
2439 }
|
|
2440 return list2 (comma_type, read0 (readcharfun));
|
|
2441 }
|
|
2442 else
|
|
2443 {
|
|
2444 /* YUCK. 99.999% backwards compatibility. The Right
|
|
2445 Thing(tm) is to signal an error here, because it's
|
|
2446 really invalid read syntax. Instead, this permits
|
|
2447 commas to begin symbols (unless they're inside
|
|
2448 backquotes). If an error is signalled here in the
|
|
2449 future, then commas should be invalid read syntax
|
|
2450 outside of backquotes anywhere they're found (i.e.
|
|
2451 they must be quoted in symbols) -- Stig */
|
173
|
2452 return read_atom (readcharfun, c, 0);
|
0
|
2453 }
|
|
2454 }
|
|
2455 #endif
|
|
2456
|
|
2457 case '?':
|
|
2458 {
|
|
2459 /* Evil GNU Emacs "character" (ie integer) syntax */
|
|
2460 c = readchar (readcharfun);
|
|
2461 if (c < 0)
|
|
2462 return Fsignal (Qend_of_file, list1 (readcharfun));
|
|
2463
|
|
2464 if (c == '\\')
|
|
2465 c = read_escape (readcharfun);
|
173
|
2466 return make_char (c);
|
0
|
2467 }
|
|
2468
|
|
2469 case '\"':
|
|
2470 {
|
|
2471 /* String */
|
|
2472 #ifdef I18N3
|
|
2473 /* #### If the input stream is translating, then the string
|
|
2474 should be marked as translatable by setting its
|
|
2475 `string-translatable' property to t. .el and .elc files
|
|
2476 normally are translating input streams. See Fgettext()
|
|
2477 and print_internal(). */
|
|
2478 #endif
|
|
2479 int cancel = 0;
|
|
2480
|
|
2481 Lstream_rewind (XLSTREAM (Vread_buffer_stream));
|
|
2482 while ((c = readchar (readcharfun)) >= 0
|
|
2483 && c != '\"')
|
|
2484 {
|
|
2485 if (c == '\\')
|
|
2486 c = read_escape (readcharfun);
|
|
2487 /* c is -1 if \ newline has just been seen */
|
|
2488 if (c == -1)
|
|
2489 {
|
|
2490 if (Lstream_byte_count (XLSTREAM (Vread_buffer_stream)) == 0)
|
|
2491 cancel = 1;
|
|
2492 }
|
|
2493 else
|
|
2494 Lstream_put_emchar (XLSTREAM (Vread_buffer_stream), c);
|
|
2495 QUIT;
|
|
2496 }
|
|
2497 if (c < 0)
|
|
2498 return Fsignal (Qend_of_file, list1 (readcharfun));
|
|
2499
|
|
2500 /* If purifying, and string starts with \ newline,
|
|
2501 return zero instead. This is for doc strings
|
|
2502 that we are really going to find in lib-src/DOC.nn.nn */
|
|
2503 if (purify_flag && NILP (Vdoc_file_name) && cancel)
|
173
|
2504 return Qzero;
|
0
|
2505
|
|
2506 Lstream_flush (XLSTREAM (Vread_buffer_stream));
|
|
2507 #if 0 /* FSFmacs defun hack */
|
|
2508 if (read_pure)
|
|
2509 return
|
|
2510 make_pure_string
|
|
2511 (resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)),
|
|
2512 Lstream_byte_count (XLSTREAM (Vread_buffer_stream)));
|
|
2513 else
|
|
2514 #endif
|
|
2515 return
|
|
2516 make_string
|
|
2517 (resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)),
|
|
2518 Lstream_byte_count (XLSTREAM (Vread_buffer_stream)));
|
|
2519 }
|
|
2520
|
|
2521 default:
|
|
2522 {
|
|
2523 /* Ignore whitespace and control characters */
|
|
2524 if (c <= 040)
|
|
2525 goto retry;
|
173
|
2526 return read_atom (readcharfun, c, 0);
|
0
|
2527 }
|
|
2528 }
|
|
2529 }
|
|
2530
|
|
2531
|
|
2532
|
|
2533 #ifdef LISP_FLOAT_TYPE
|
|
2534
|
|
2535 #define LEAD_INT 1
|
|
2536 #define DOT_CHAR 2
|
|
2537 #define TRAIL_INT 4
|
|
2538 #define E_CHAR 8
|
|
2539 #define EXP_INT 16
|
|
2540
|
|
2541 int
|
|
2542 isfloat_string (CONST char *cp)
|
|
2543 {
|
|
2544 int state = 0;
|
|
2545 CONST Bufbyte *ucp = (CONST Bufbyte *) cp;
|
173
|
2546
|
0
|
2547 if (*ucp == '+' || *ucp == '-')
|
|
2548 ucp++;
|
|
2549
|
|
2550 if (*ucp >= '0' && *ucp <= '9')
|
|
2551 {
|
|
2552 state |= LEAD_INT;
|
|
2553 while (*ucp >= '0' && *ucp <= '9')
|
|
2554 ucp++;
|
|
2555 }
|
|
2556 if (*ucp == '.')
|
|
2557 {
|
|
2558 state |= DOT_CHAR;
|
|
2559 ucp++;
|
|
2560 }
|
|
2561 if (*ucp >= '0' && *ucp <= '9')
|
|
2562 {
|
|
2563 state |= TRAIL_INT;
|
|
2564 while (*ucp >= '0' && *ucp <= '9')
|
|
2565 ucp++;
|
|
2566 }
|
|
2567 if (*ucp == 'e' || *ucp == 'E')
|
|
2568 {
|
|
2569 state |= E_CHAR;
|
|
2570 ucp++;
|
|
2571 if ((*ucp == '+') || (*ucp == '-'))
|
|
2572 ucp++;
|
|
2573 }
|
|
2574
|
|
2575 if (*ucp >= '0' && *ucp <= '9')
|
|
2576 {
|
|
2577 state |= EXP_INT;
|
|
2578 while (*ucp >= '0' && *ucp <= '9')
|
|
2579 ucp++;
|
|
2580 }
|
|
2581 return (((*ucp == 0) || (*ucp == ' ') || (*ucp == '\t') || (*ucp == '\n')
|
|
2582 || (*ucp == '\r') || (*ucp == '\f'))
|
|
2583 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
|
|
2584 || state == (DOT_CHAR|TRAIL_INT)
|
|
2585 || state == (LEAD_INT|E_CHAR|EXP_INT)
|
|
2586 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)
|
|
2587 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)));
|
|
2588 }
|
|
2589 #endif /* LISP_FLOAT_TYPE */
|
|
2590
|
|
2591 static void *
|
|
2592 sequence_reader (Lisp_Object readcharfun,
|
|
2593 Emchar terminator,
|
|
2594 void *state,
|
|
2595 void * (*conser) (Lisp_Object readcharfun,
|
|
2596 void *state, Charcount len))
|
|
2597 {
|
|
2598 Charcount len;
|
|
2599
|
|
2600 for (len = 0; ; len++)
|
|
2601 {
|
|
2602 Emchar ch;
|
|
2603
|
|
2604 QUIT;
|
|
2605 ch = reader_nextchar (readcharfun);
|
|
2606
|
|
2607 if (ch == terminator)
|
173
|
2608 return state;
|
0
|
2609 else
|
|
2610 unreadchar (readcharfun, ch);
|
140
|
2611 #ifdef FEATUREP_SYNTAX
|
0
|
2612 if (ch == ']')
|
|
2613 syntax_error ("\"]\" in a list");
|
|
2614 else if (ch == ')')
|
|
2615 syntax_error ("\")\" in a vector");
|
140
|
2616 #endif
|
0
|
2617 state = ((conser) (readcharfun, state, len));
|
|
2618 }
|
|
2619 }
|
|
2620
|
|
2621
|
173
|
2622 struct read_list_state
|
0
|
2623 {
|
|
2624 Lisp_Object head;
|
|
2625 Lisp_Object tail;
|
|
2626 int length;
|
|
2627 int allow_dotted_lists;
|
|
2628 Emchar terminator;
|
|
2629 };
|
|
2630
|
|
2631 static void *
|
|
2632 read_list_conser (Lisp_Object readcharfun, void *state, Charcount len)
|
|
2633 {
|
185
|
2634 struct read_list_state *s = (struct read_list_state *) state;
|
0
|
2635 Lisp_Object elt;
|
|
2636
|
|
2637 elt = read1 (readcharfun);
|
|
2638
|
|
2639 if (CONSP (elt) && UNBOUNDP (XCAR (elt)))
|
|
2640 {
|
|
2641 Lisp_Object tem = elt;
|
|
2642 Emchar ch;
|
173
|
2643
|
0
|
2644 elt = XCDR (elt);
|
|
2645 free_cons (XCONS (tem));
|
|
2646 tem = Qnil;
|
|
2647 ch = XCHAR (elt);
|
140
|
2648 #ifdef FEATUREP_SYNTAX
|
|
2649 if (ch == s->terminator) /* deal with #+, #- reader macros */
|
|
2650 {
|
|
2651 unreadchar (readcharfun, s->terminator);
|
|
2652 goto done;
|
|
2653 }
|
|
2654 else if (ch == ']')
|
|
2655 syntax_error ("']' in a list");
|
|
2656 else if (ch == ')')
|
|
2657 syntax_error ("')' in a vector");
|
|
2658 else
|
|
2659 #endif
|
0
|
2660 if (ch != '.')
|
|
2661 signal_simple_error ("BUG! Internal reader error", elt);
|
|
2662 else if (!s->allow_dotted_lists)
|
|
2663 syntax_error ("\".\" in a vector");
|
|
2664 else
|
|
2665 {
|
|
2666 if (!NILP (s->tail))
|
|
2667 XCDR (s->tail) = read0 (readcharfun);
|
|
2668 else
|
|
2669 s->head = read0 (readcharfun);
|
|
2670 elt = read1 (readcharfun);
|
|
2671 if (CONSP (elt) && UNBOUNDP (XCAR (elt)))
|
|
2672 {
|
|
2673 ch = XCHAR (XCDR (elt));
|
|
2674 free_cons (XCONS (elt));
|
|
2675 if (ch == s->terminator)
|
|
2676 {
|
|
2677 unreadchar (readcharfun, s->terminator);
|
|
2678 goto done;
|
|
2679 }
|
|
2680 }
|
|
2681 syntax_error (". in wrong context");
|
|
2682 }
|
|
2683 }
|
|
2684
|
|
2685 #if 0 /* FSFmacs defun hack, or something ... */
|
|
2686 if (NILP (tail) && defun_hack && EQ (elt, Qdefun) && !read_pure)
|
|
2687 {
|
|
2688 record_unwind_protect (unreadpure, Qzero);
|
|
2689 read_pure = 1;
|
|
2690 }
|
|
2691 #endif
|
|
2692
|
|
2693 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
2694 if (s->length == 1 && s->allow_dotted_lists && EQ (XCAR (s->head), Qfset))
|
|
2695 {
|
|
2696 if (CONSP (elt) && EQ (XCAR (elt), Qquote) && CONSP (XCDR (elt)))
|
|
2697 Vcurrent_compiled_function_annotation = XCAR (XCDR (elt));
|
|
2698 else
|
|
2699 Vcurrent_compiled_function_annotation = elt;
|
|
2700 }
|
|
2701 #endif
|
|
2702
|
|
2703 elt = Fcons (elt, Qnil);
|
|
2704 if (!NILP (s->tail))
|
|
2705 XCDR (s->tail) = elt;
|
|
2706 else
|
|
2707 s->head = elt;
|
|
2708 s->tail = elt;
|
|
2709 done:
|
|
2710 s->length++;
|
173
|
2711 return s;
|
0
|
2712 }
|
|
2713
|
|
2714
|
|
2715 #if 0 /* FSFmacs defun hack */
|
|
2716 /* -1 for allow_dotted_lists means allow_dotted_lists and check
|
|
2717 for starting with defun and make structure pure. */
|
|
2718 #endif
|
|
2719
|
|
2720 static Lisp_Object
|
|
2721 read_list (Lisp_Object readcharfun,
|
|
2722 Emchar terminator,
|
|
2723 int allow_dotted_lists,
|
|
2724 int check_for_doc_references)
|
|
2725 {
|
|
2726 struct read_list_state s;
|
|
2727 struct gcpro gcpro1, gcpro2;
|
|
2728 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
2729 Lisp_Object old_compiled_function_annotation =
|
|
2730 Vcurrent_compiled_function_annotation;
|
|
2731 #endif
|
|
2732
|
|
2733 s.head = Qnil;
|
|
2734 s.tail = Qnil;
|
|
2735 s.length = 0;
|
|
2736 s.allow_dotted_lists = allow_dotted_lists;
|
|
2737 s.terminator = terminator;
|
|
2738 GCPRO2 (s.head, s.tail);
|
|
2739
|
181
|
2740 sequence_reader (readcharfun, terminator, &s, read_list_conser);
|
0
|
2741 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
2742 Vcurrent_compiled_function_annotation = old_compiled_function_annotation;
|
|
2743 #endif
|
|
2744
|
|
2745 if ((purify_flag || load_force_doc_strings) && check_for_doc_references)
|
|
2746 {
|
|
2747 /* check now for any doc string references and record them
|
|
2748 for later. */
|
|
2749 Lisp_Object tail;
|
|
2750
|
|
2751 /* We might be dealing with an imperfect list so don't
|
|
2752 use LIST_LOOP */
|
|
2753 for (tail = s.head; CONSP (tail); tail = XCDR (tail))
|
|
2754 {
|
|
2755 Lisp_Object holding_cons = Qnil;
|
|
2756
|
|
2757 {
|
|
2758 Lisp_Object elem = XCAR (tail);
|
|
2759 /* elem might be (#$ . INT) ... */
|
|
2760 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal))
|
|
2761 holding_cons = tail;
|
|
2762 /* or it might be (quote (#$ . INT)) i.e.
|
|
2763 (quote . ((#$ . INT) . nil)) in the case of
|
|
2764 `autoload' (autoload evaluates its arguments, while
|
|
2765 `defvar', `defun', etc. don't). */
|
|
2766 if (CONSP (elem) && EQ (XCAR (elem), Qquote)
|
|
2767 && CONSP (XCDR (elem)))
|
|
2768 {
|
|
2769 elem = XCAR (XCDR (elem));
|
|
2770 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal))
|
|
2771 holding_cons = XCDR (XCAR (tail));
|
|
2772 }
|
|
2773 }
|
|
2774
|
|
2775 if (CONSP (holding_cons))
|
|
2776 {
|
|
2777 if (purify_flag)
|
|
2778 {
|
|
2779 if (NILP (Vdoc_file_name))
|
|
2780 /* We have not yet called Snarf-documentation, so
|
80
|
2781 assume this file is described in the DOC file
|
|
2782 and Snarf-documentation will fill in the right
|
|
2783 value later. For now, replace the whole list
|
|
2784 with 0. */
|
0
|
2785 XCAR (holding_cons) = Qzero;
|
|
2786 else
|
|
2787 /* We have already called Snarf-documentation, so
|
|
2788 make a relative file name for this file, so it
|
|
2789 can be found properly in the installed Lisp
|
|
2790 directory. We don't use Fexpand_file_name
|
|
2791 because that would make the directory absolute
|
|
2792 now. */
|
|
2793 XCAR (XCAR (holding_cons)) =
|
|
2794 concat2 (build_string ("../lisp/"),
|
|
2795 Ffile_name_nondirectory
|
|
2796 (Vload_file_name_internal));
|
|
2797 }
|
|
2798 else
|
|
2799 /* Not pure. Just add to Vload_force_doc_string_list,
|
|
2800 and the string will be filled in properly in
|
|
2801 load_force_doc_string_unwind(). */
|
|
2802 Vload_force_doc_string_list =
|
|
2803 /* We pass the cons that holds the (#$ . INT) so we
|
|
2804 can modify it in-place. */
|
|
2805 Fcons (holding_cons, Vload_force_doc_string_list);
|
|
2806 }
|
|
2807 }
|
|
2808 }
|
173
|
2809
|
0
|
2810 UNGCPRO;
|
173
|
2811 return s.head;
|
0
|
2812 }
|
|
2813
|
|
2814 static Lisp_Object
|
|
2815 read_vector (Lisp_Object readcharfun,
|
|
2816 Emchar terminator)
|
|
2817 {
|
|
2818 Lisp_Object tem;
|
|
2819 Lisp_Object *p;
|
|
2820 int len;
|
|
2821 int i;
|
|
2822 struct read_list_state s;
|
|
2823 struct gcpro gcpro1, gcpro2;
|
|
2824
|
|
2825 s.head = Qnil;
|
|
2826 s.tail = Qnil;
|
|
2827 s.length = 0;
|
|
2828 s.allow_dotted_lists = 0;
|
|
2829 GCPRO2 (s.head, s.tail);
|
173
|
2830
|
181
|
2831 sequence_reader (readcharfun, terminator, &s, read_list_conser);
|
185
|
2832
|
0
|
2833 UNGCPRO;
|
|
2834 tem = s.head;
|
|
2835 len = XINT (Flength (tem));
|
|
2836
|
|
2837 #if 0 /* FSFmacs defun hack */
|
|
2838 if (read_pure)
|
|
2839 s.head = make_pure_vector (len, Qnil);
|
|
2840 else
|
|
2841 #endif
|
|
2842 s.head = make_vector (len, Qnil);
|
|
2843
|
173
|
2844 for (i = 0, p = &(XVECTOR_DATA (s.head)[0]);
|
0
|
2845 i < len;
|
|
2846 i++, p++)
|
|
2847 {
|
|
2848 struct Lisp_Cons *otem = XCONS (tem);
|
|
2849 #if 0 /* FSFmacs defun hack */
|
|
2850 if (read_pure)
|
|
2851 tem = Fpurecopy (Fcar (tem));
|
|
2852 else
|
|
2853 #endif
|
|
2854 tem = Fcar (tem);
|
|
2855 *p = tem;
|
|
2856 tem = otem->cdr;
|
|
2857 free_cons (otem);
|
|
2858 }
|
173
|
2859 return s.head;
|
0
|
2860 }
|
|
2861
|
|
2862 static Lisp_Object
|
|
2863 read_compiled_function (Lisp_Object readcharfun, Emchar terminator)
|
|
2864 {
|
173
|
2865 /* Accept compiled functions at read-time so that we don't
|
0
|
2866 have to build them at load-time. */
|
|
2867 Lisp_Object stuff;
|
|
2868 Lisp_Object make_byte_code_args[COMPILED_DOMAIN + 1];
|
|
2869 struct gcpro gcpro1;
|
|
2870 int len;
|
|
2871 int iii;
|
|
2872 int saw_a_doc_ref = 0;
|
|
2873
|
|
2874 /* Note: we tell read_list not to search for doc references
|
|
2875 because we need to handle the "doc reference" for the
|
|
2876 instructions and constants differently. */
|
|
2877 stuff = read_list (readcharfun, terminator, 0, 0);
|
|
2878 len = XINT (Flength (stuff));
|
|
2879 if (len < COMPILED_STACK_DEPTH + 1 || len > COMPILED_DOMAIN + 1)
|
|
2880 return
|
|
2881 continuable_syntax_error ("#[...] used with wrong number of elements");
|
|
2882
|
|
2883 for (iii = 0; CONSP (stuff); iii++)
|
|
2884 {
|
|
2885 struct Lisp_Cons *victim = XCONS (stuff);
|
|
2886 make_byte_code_args[iii] = Fcar (stuff);
|
|
2887 if ((purify_flag || load_force_doc_strings)
|
|
2888 && CONSP (make_byte_code_args[iii])
|
|
2889 && EQ (XCAR (make_byte_code_args[iii]), Vload_file_name_internal))
|
|
2890 {
|
|
2891 if (purify_flag && iii == COMPILED_DOC_STRING)
|
|
2892 {
|
|
2893 /* same as in read_list(). */
|
|
2894 if (NILP (Vdoc_file_name))
|
|
2895 make_byte_code_args[iii] = Qzero;
|
|
2896 else
|
|
2897 XCAR (make_byte_code_args[iii]) =
|
|
2898 concat2 (build_string ("../lisp/"),
|
|
2899 Ffile_name_nondirectory
|
|
2900 (Vload_file_name_internal));
|
|
2901 }
|
|
2902 else
|
|
2903 saw_a_doc_ref = 1;
|
|
2904 }
|
|
2905 stuff = Fcdr (stuff);
|
|
2906 free_cons (victim);
|
|
2907 }
|
|
2908 GCPRO1 (make_byte_code_args[0]);
|
|
2909 gcpro1.nvars = len;
|
|
2910
|
70
|
2911 /* v18 or v19 bytecode file. Need to Ebolify. */
|
|
2912 if (load_byte_code_version < 20 && VECTORP (make_byte_code_args[2]))
|
|
2913 ebolify_bytecode_constants (make_byte_code_args[2]);
|
|
2914
|
0
|
2915 /* make-byte-code looks at purify_flag, which should have the same
|
|
2916 * value as our "read-pure" argument */
|
|
2917 stuff = Fmake_byte_code (len, make_byte_code_args);
|
70
|
2918 XCOMPILED_FUNCTION (stuff)->flags.ebolified = (load_byte_code_version < 20);
|
0
|
2919 if (saw_a_doc_ref)
|
|
2920 Vload_force_doc_string_list = Fcons (stuff, Vload_force_doc_string_list);
|
|
2921 UNGCPRO;
|
|
2922 return stuff;
|
|
2923 }
|
|
2924
|
|
2925
|
|
2926
|
|
2927 void
|
|
2928 init_lread (void)
|
|
2929 {
|
|
2930 #ifdef PATH_LOADSEARCH
|
|
2931 CONST char *normal = PATH_LOADSEARCH;
|
|
2932
|
|
2933 /* Don't print this warning. If the hardcoded paths don't exist, then
|
|
2934 startup.el will try and deduce one. If it fails, it knows how to
|
|
2935 handle things. */
|
|
2936 #if 0
|
|
2937 #ifndef WINDOWSNT
|
173
|
2938 /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is
|
185
|
2939 almost never correct, thereby causing a warning to be printed out that
|
0
|
2940 confuses users. Since PATH_LOADSEARCH is always overriden by the
|
|
2941 EMACSLOADPATH environment variable below, disable the warning on NT. */
|
|
2942
|
|
2943 /* Warn if dirs in the *standard* path don't exist. */
|
|
2944 if (!turn_off_warning)
|
|
2945 {
|
|
2946 Lisp_Object normal_path = decode_env_path (0, normal);
|
|
2947 for (; !NILP (normal_path); normal_path = XCDR (normal_path))
|
|
2948 {
|
|
2949 Lisp_Object dirfile;
|
|
2950 dirfile = Fcar (normal_path);
|
|
2951 if (!NILP (dirfile))
|
|
2952 {
|
|
2953 dirfile = Fdirectory_file_name (dirfile);
|
16
|
2954 if (access ((char *) XSTRING_DATA (dirfile), 0) < 0)
|
0
|
2955 stdout_out ("Warning: lisp library (%s) does not exist.\n",
|
16
|
2956 XSTRING_DATA (Fcar (normal_path)));
|
0
|
2957 }
|
|
2958 }
|
|
2959 }
|
|
2960 #endif /* WINDOWSNT */
|
|
2961 #endif /* 0 */
|
|
2962 #else /* !PATH_LOADSEARCH */
|
|
2963 CONST char *normal = 0;
|
|
2964 #endif /* !PATH_LOADSEARCH */
|
|
2965 Vvalues = Qnil;
|
|
2966
|
|
2967 /* further frobbed by startup.el if nil. */
|
|
2968 Vload_path = decode_env_path ("EMACSLOADPATH", normal);
|
|
2969
|
|
2970 /* Vdump_load_path = Qnil; */
|
|
2971 #ifndef CANNOT_DUMP
|
|
2972 if (purify_flag && NILP (Vload_path))
|
|
2973 {
|
|
2974 /* loadup.el will frob this some more. */
|
|
2975 /* #### unix-specific */
|
209
|
2976 Vload_path = Fcons (build_string ("../lisp/"), Vload_path);
|
0
|
2977 }
|
|
2978 #endif /* not CANNOT_DUMP */
|
|
2979 load_in_progress = 0;
|
|
2980
|
|
2981 Vload_descriptor_list = Qnil;
|
|
2982
|
231
|
2983 /* This used to get initialized in init_lread because all streams
|
|
2984 got closed when dumping occurs. This is no longer true --
|
|
2985 Vread_buffer_stream is a resizing output stream, and there is no
|
|
2986 reason to close it at dump-time.
|
|
2987
|
|
2988 Vread_buffer_stream is set to Qnil in vars_of_lread, and this
|
|
2989 will initialize it only once, at dump-time. */
|
|
2990 if (NILP (Vread_buffer_stream))
|
|
2991 Vread_buffer_stream = make_resizing_buffer_output_stream ();
|
0
|
2992
|
|
2993 Vload_force_doc_string_list = Qnil;
|
|
2994 }
|
|
2995
|
|
2996 void
|
|
2997 syms_of_lread (void)
|
|
2998 {
|
20
|
2999 DEFSUBR (Fread);
|
|
3000 DEFSUBR (Fread_from_string);
|
|
3001 DEFSUBR (Fload_internal);
|
|
3002 DEFSUBR (Flocate_file);
|
|
3003 DEFSUBR (Flocate_file_clear_hashing);
|
|
3004 DEFSUBR (Feval_buffer);
|
|
3005 DEFSUBR (Feval_region);
|
0
|
3006 #ifdef standalone
|
20
|
3007 DEFSUBR (Fread_char);
|
0
|
3008 #endif
|
|
3009
|
|
3010 defsymbol (&Qstandard_input, "standard-input");
|
|
3011 defsymbol (&Qread_char, "read-char");
|
|
3012 defsymbol (&Qcurrent_load_list, "current-load-list");
|
|
3013 defsymbol (&Qload, "load");
|
|
3014 defsymbol (&Qload_file_name, "load-file-name");
|
|
3015 defsymbol (&Qlocate_file_hash_table, "locate-file-hash-table");
|
|
3016 defsymbol (&Qfset, "fset");
|
|
3017
|
|
3018 #ifdef LISP_BACKQUOTES
|
|
3019 defsymbol (&Qbackquote, "backquote");
|
|
3020 defsymbol (&Qbacktick, "`");
|
|
3021 defsymbol (&Qcomma, ",");
|
|
3022 defsymbol (&Qcomma_at, ",@");
|
|
3023 defsymbol (&Qcomma_dot, ",.");
|
|
3024 #endif
|
|
3025 }
|
|
3026
|
|
3027 void
|
|
3028 structure_type_create (void)
|
|
3029 {
|
185
|
3030 the_structure_type_dynarr = Dynarr_new (structure_type);
|
0
|
3031 }
|
|
3032
|
|
3033 void
|
|
3034 vars_of_lread (void)
|
|
3035 {
|
|
3036 DEFVAR_LISP ("values", &Vvalues /*
|
|
3037 List of values of all expressions which were read, evaluated and printed.
|
|
3038 Order is reverse chronological.
|
|
3039 */ );
|
|
3040
|
|
3041 DEFVAR_LISP ("standard-input", &Vstandard_input /*
|
|
3042 Stream for read to get input from.
|
|
3043 See documentation of `read' for possible values.
|
|
3044 */ );
|
|
3045 Vstandard_input = Qt;
|
|
3046
|
|
3047 DEFVAR_LISP ("load-path", &Vload_path /*
|
|
3048 *List of directories to search for files to load.
|
|
3049 Each element is a string (directory name) or nil (try default directory).
|
|
3050
|
185
|
3051 Note that the elements of this list *may not* begin with "~", so you must
|
0
|
3052 call `expand-file-name' on them before adding them to this list.
|
|
3053
|
|
3054 Initialized based on EMACSLOADPATH environment variable, if any,
|
|
3055 otherwise to default specified in by file `paths.h' when XEmacs was built.
|
|
3056 If there were no paths specified in `paths.h', then XEmacs chooses a default
|
|
3057 value for this variable by looking around in the file-system near the
|
|
3058 directory in which the XEmacs executable resides.
|
|
3059 */ );
|
|
3060
|
|
3061 /* xxxDEFVAR_LISP ("dump-load-path", &Vdump_load_path,
|
|
3062 "*Location of lisp files to be used when dumping ONLY."); */
|
|
3063
|
|
3064 DEFVAR_BOOL ("load-in-progress", &load_in_progress /*
|
|
3065 Non-nil iff inside of `load'.
|
|
3066 */ );
|
|
3067
|
|
3068 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist /*
|
|
3069 An alist of expressions to be evalled when particular files are loaded.
|
|
3070 Each element looks like (FILENAME FORMS...).
|
|
3071 When `load' is run and the file-name argument is FILENAME,
|
|
3072 the FORMS in the corresponding element are executed at the end of loading.
|
|
3073
|
|
3074 FILENAME must match exactly! Normally FILENAME is the name of a library,
|
|
3075 with no directory specified, since that is how `load' is normally called.
|
|
3076 An error in FORMS does not undo the load,
|
|
3077 but does prevent execution of the rest of the FORMS.
|
|
3078 */ );
|
|
3079 Vafter_load_alist = Qnil;
|
|
3080
|
|
3081 DEFVAR_BOOL ("load-warn-when-source-newer", &load_warn_when_source_newer /*
|
|
3082 *Whether `load' should check whether the source is newer than the binary.
|
|
3083 If this variable is true, then when a `.elc' file is being loaded and the
|
|
3084 corresponding `.el' is newer, a warning message will be printed.
|
|
3085 */ );
|
|
3086 load_warn_when_source_newer = 0;
|
|
3087
|
|
3088 DEFVAR_BOOL ("load-warn-when-source-only", &load_warn_when_source_only /*
|
|
3089 *Whether `load' should warn when loading a `.el' file instead of an `.elc'.
|
|
3090 If this variable is true, then when `load' is called with a filename without
|
|
3091 an extension, and the `.elc' version doesn't exist but the `.el' version does,
|
|
3092 then a message will be printed. If an explicit extension is passed to `load',
|
|
3093 no warning will be printed.
|
|
3094 */ );
|
|
3095 load_warn_when_source_only = 0;
|
|
3096
|
|
3097 DEFVAR_BOOL ("load-ignore-elc-files", &load_ignore_elc_files /*
|
|
3098 *Whether `load' should ignore `.elc' files when a suffix is not given.
|
|
3099 This is normally used only to bootstrap the `.elc' files when building XEmacs.
|
|
3100 */ );
|
|
3101 load_ignore_elc_files = 0;
|
|
3102
|
|
3103 #ifdef LOADHIST
|
|
3104 DEFVAR_LISP ("load-history", &Vload_history /*
|
|
3105 Alist mapping source file names to symbols and features.
|
|
3106 Each alist element is a list that starts with a file name,
|
|
3107 except for one element (optional) that starts with nil and describes
|
|
3108 definitions evaluated from buffers not visiting files.
|
|
3109 The remaining elements of each list are symbols defined as functions
|
|
3110 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.
|
|
3111 */ );
|
|
3112 Vload_history = Qnil;
|
|
3113
|
|
3114 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list /*
|
|
3115 Used for internal purposes by `load'.
|
|
3116 */ );
|
|
3117 Vcurrent_load_list = Qnil;
|
|
3118 #endif
|
|
3119
|
|
3120 DEFVAR_LISP ("load-file-name", &Vload_file_name /*
|
|
3121 Full name of file being loaded by `load'.
|
|
3122 */ );
|
|
3123 Vload_file_name = Qnil;
|
|
3124
|
|
3125 DEFVAR_LISP ("load-read-function", &Vload_read_function /*
|
|
3126 "Function used by `load' and `eval-region' for reading expressions.
|
|
3127 The default is nil, which means use the function `read'.
|
|
3128 */ );
|
|
3129 Vload_read_function = Qnil;
|
|
3130
|
|
3131 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings /*
|
|
3132 Non-nil means `load' should force-load all dynamic doc strings.
|
|
3133 This is useful when the file being loaded is a temporary copy.
|
|
3134 */ );
|
|
3135 load_force_doc_strings = 0;
|
|
3136
|
|
3137 DEFVAR_LISP ("source-directory", &Vsource_directory /*
|
|
3138 Directory in which XEmacs sources were found when XEmacs was built.
|
|
3139 You cannot count on them to still be there!
|
|
3140 */ );
|
|
3141 Vsource_directory = Qnil;
|
|
3142
|
|
3143 DEFVAR_BOOL ("fail-on-bucky-bit-character-escapes", &puke_on_fsf_keys /*
|
|
3144 Whether `read' should signal an error when it encounters unsupported
|
|
3145 character escape syntaxes or just read them incorrectly.
|
|
3146 */ );
|
|
3147 puke_on_fsf_keys = 0;
|
|
3148
|
|
3149 /* This must be initialized in init_lread otherwise it may start out
|
|
3150 with values saved when the image is dumped. */
|
|
3151 staticpro (&Vload_descriptor_list);
|
|
3152
|
231
|
3153 Vread_buffer_stream = Qnil;
|
0
|
3154 staticpro (&Vread_buffer_stream);
|
|
3155
|
|
3156 /* Initialized in init_lread. */
|
|
3157 staticpro (&Vload_force_doc_string_list);
|
|
3158
|
|
3159 Vload_file_name_internal = Qnil;
|
|
3160 staticpro (&Vload_file_name_internal);
|
|
3161
|
|
3162 Vload_file_name_internal_the_purecopy = Qnil;
|
|
3163 staticpro (&Vload_file_name_internal_the_purecopy);
|
|
3164
|
|
3165 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
3166 Vcurrent_compiled_function_annotation = Qnil;
|
|
3167 staticpro (&Vcurrent_compiled_function_annotation);
|
|
3168 #endif
|
|
3169
|
|
3170 /* So that early-early stuff will work */
|
|
3171 Ffset (Qload, intern ("load-internal"));
|
|
3172
|
140
|
3173 #ifdef FEATUREP_SYNTAX
|
207
|
3174 defsymbol (&Qfeaturep, "featurep");
|
140
|
3175 Fprovide(intern("xemacs"));
|
155
|
3176 #ifdef INFODOCK
|
|
3177 Fprovide(intern("infodock"));
|
231
|
3178 #endif /* INFODOCK */
|
|
3179 #endif /* FEATUREP_SYNTAX */
|
140
|
3180
|
0
|
3181 #ifdef LISP_BACKQUOTES
|
|
3182 old_backquote_flag = new_backquote_flag = 0;
|
|
3183 #endif
|
185
|
3184
|
0
|
3185 #ifdef I18N3
|
|
3186 Vfile_domain = Qnil;
|
|
3187 #endif
|
|
3188 }
|