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