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