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