Mercurial > hg > xemacs-beta
annotate src/lread.c @ 5197:ce8ffb95bbe3
finish up CHANGES-beta -- all changes thru Apr 9, 2010
-------------------- ChangeLog entries follow: --------------------
ChangeLog addition:
2010-04-09 Ben Wing <ben@xemacs.org>
* CHANGES-beta:
Update with my changes to the trunk since the release of 21.5.29
in 2009 up through April 9, 2010.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Fri, 09 Apr 2010 02:33:11 -0500 |
parents | 71ee43b8a74d |
children | cdca98f2d36f |
rev | line source |
---|---|
428 | 1 /* Lisp parsing and input streams. |
2 Copyright (C) 1985-1989, 1992-1995 Free Software Foundation, Inc. | |
3 Copyright (C) 1995 Tinker Systems. | |
4921
17362f371cc2
add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
4 Copyright (C) 1996, 2001, 2002, 2003, 2010 Ben Wing. |
428 | 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 #include "buffer.h" | |
31 #include "bytecode.h" | |
32 #include "elhash.h" | |
1292 | 33 #include "file-coding.h" |
428 | 34 #include "lstream.h" |
35 #include "opaque.h" | |
1292 | 36 #include "profile.h" |
3439 | 37 #include "charset.h" /* For Funicode_to_char. */ |
428 | 38 |
39 #include "sysfile.h" | |
40 #include "sysfloat.h" | |
771 | 41 #ifdef WIN32_NATIVE |
42 #include "syswindows.h" | |
43 #endif | |
428 | 44 |
45 Lisp_Object Qread_char, Qstandard_input; | |
46 Lisp_Object Qvariable_documentation; | |
47 #define LISP_BACKQUOTES | |
48 #ifdef LISP_BACKQUOTES | |
49 /* | |
50 Nonzero means inside a new-style backquote | |
51 with no surrounding parentheses. | |
52 Fread initializes this to zero, so we need not specbind it | |
53 or worry about what happens to it when there is an error. | |
54 | |
55 XEmacs: | |
56 Nested backquotes are perfectly legal and fail utterly with | |
57 this silliness. */ | |
58 static int new_backquote_flag, old_backquote_flag; | |
59 Lisp_Object Qbackquote, Qbacktick, Qcomma, Qcomma_at, Qcomma_dot; | |
60 #endif | |
61 Lisp_Object Qvariable_domain; /* I18N3 */ | |
62 Lisp_Object Vvalues, Vstandard_input, Vafter_load_alist; | |
2548 | 63 Lisp_Object Vload_suppress_alist; |
64 Lisp_Object Qload, Qload_internal, Qfset; | |
428 | 65 |
66 /* Hash-table that maps directory names to hashes of their contents. */ | |
67 static Lisp_Object Vlocate_file_hash_table; | |
68 | |
69 Lisp_Object Qexists, Qreadable, Qwritable, Qexecutable; | |
70 | |
71 /* See read_escape() for an explanation of this. */ | |
72 #if 0 | |
73 int fail_on_bucky_bit_character_escapes; | |
74 #endif | |
75 | |
76 /* This symbol is also used in fns.c */ | |
77 #define FEATUREP_SYNTAX | |
78 | |
79 #ifdef FEATUREP_SYNTAX | |
80 Lisp_Object Qfeaturep; | |
81 #endif | |
82 | |
83 /* non-zero if inside `load' */ | |
84 int load_in_progress; | |
85 | |
86 /* Whether Fload_internal() should check whether the .el is newer | |
87 when loading .elc */ | |
88 int load_warn_when_source_newer; | |
89 /* Whether Fload_internal() should check whether the .elc doesn't exist */ | |
90 int load_warn_when_source_only; | |
91 /* Whether Fload_internal() should ignore .elc files when no suffix is given */ | |
92 int load_ignore_elc_files; | |
1123 | 93 /* Whether Fload_internal() should ignore out-of-date .elc files when no |
94 suffix is given */ | |
95 int load_ignore_out_of_date_elc_files; | |
96 /* Always display messages showing when a file is loaded, regardless of | |
97 whether the flag to `load' tries to suppress them. */ | |
98 int load_always_display_messages; | |
99 /* Show the full path in loading messages. */ | |
100 int load_show_full_path_in_messages; | |
428 | 101 |
102 /* Search path for files to be loaded. */ | |
103 Lisp_Object Vload_path; | |
104 | |
105 /* Search path for files when dumping. */ | |
106 /* Lisp_Object Vdump_load_path; */ | |
107 | |
108 /* This is the user-visible association list that maps features to | |
109 lists of defs in their load files. */ | |
110 Lisp_Object Vload_history; | |
111 | |
112 /* This is used to build the load history. */ | |
113 Lisp_Object Vcurrent_load_list; | |
114 | |
115 /* Name of file actually being read by `load'. */ | |
116 Lisp_Object Vload_file_name; | |
117 | |
118 /* Same as Vload_file_name but not Lisp-accessible. This ensures that | |
119 our #$ checks are reliable. */ | |
120 Lisp_Object Vload_file_name_internal; | |
121 | |
122 /* Function to use for reading, in `load' and friends. */ | |
123 Lisp_Object Vload_read_function; | |
124 | |
125 /* The association list of objects read with the #n=object form. | |
126 Each member of the list has the form (n . object), and is used to | |
127 look up the object for the corresponding #n# construct. | |
128 It must be set to nil before all top-level calls to read0. */ | |
129 Lisp_Object Vread_objects; | |
130 | |
131 /* Nonzero means load should forcibly load all dynamic doc strings. */ | |
132 /* Note that this always happens (with some special behavior) when | |
133 purify_flag is set. */ | |
134 static int load_force_doc_strings; | |
135 | |
136 /* List of descriptors now open for Fload_internal. */ | |
137 static Lisp_Object Vload_descriptor_list; | |
138 | |
139 /* In order to implement "load_force_doc_strings", we keep | |
140 a list of all the compiled-function objects and such | |
141 that we have created in the process of loading this file. | |
142 See the rant below. | |
143 | |
144 We specbind this just like Vload_file_name, so there's no | |
145 problems with recursive loading. */ | |
146 static Lisp_Object Vload_force_doc_string_list; | |
147 | |
148 /* A resizing-buffer stream used to temporarily hold data while reading */ | |
149 static Lisp_Object Vread_buffer_stream; | |
150 | |
151 static int load_byte_code_version; | |
152 | |
153 /* An array describing all known built-in structure types */ | |
154 static structure_type_dynarr *the_structure_type_dynarr; | |
155 | |
156 #if 0 /* FSF stuff */ | |
157 /* For use within read-from-string (this reader is non-reentrant!!) */ | |
158 static int read_from_string_index; | |
159 static int read_from_string_limit; | |
160 #endif | |
161 | |
162 #if 0 /* More FSF implementation kludges. */ | |
163 /* In order to implement load-force-doc-string, FSF saves the | |
164 #@-quoted string when it's seen, and goes back and retrieves | |
165 it later. | |
166 | |
167 This approach is not only kludgy, but it in general won't work | |
168 correctly because there's no stack of remembered #@-quoted-strings | |
169 and those strings don't generally appear in the file in the same | |
170 order as their #$ references. (Yes, that is amazingly stupid too. | |
171 | |
172 It would be trivially easy to always encode the #@ string | |
173 [which is a comment, anyway] in the middle of the (#$ . INT) cons | |
174 reference. That way, it would be really easy to implement | |
175 load-force-doc-string in a non-kludgy way by just retrieving the | |
176 string immediately, because it's delivered on a silver platter.) | |
177 | |
178 And finally, this stupid approach doesn't work under Mule, or | |
179 under MS-DOS or Windows NT, or under VMS, or any other place | |
180 where you either can't do an ftell() or don't get back a byte | |
181 count. | |
182 | |
183 Oh, and one more lossage in this approach: If you attempt to | |
184 dump any ELC files that were compiled with `byte-compile-dynamic' | |
185 (as opposed to just `byte-compile-dynamic-docstring'), you | |
186 get hosed. FMH! (as the illustrious JWZ was prone to utter) | |
187 | |
188 The approach we use is clean, solves all of these problems, and is | |
189 probably easier to implement anyway. We just save a list of all | |
190 the containing objects that have (#$ . INT) conses in them (this | |
191 will only be compiled-function objects and lists), and when the | |
192 file is finished loading, we go through and fill in all the | |
814 | 193 doc strings at once. --ben */ |
428 | 194 |
195 /* This contains the last string skipped with #@. */ | |
196 static char *saved_doc_string; | |
197 /* Length of buffer allocated in saved_doc_string. */ | |
198 static int saved_doc_string_size; | |
199 /* Length of actual data in saved_doc_string. */ | |
200 static int saved_doc_string_length; | |
201 /* This is the file position that string came from. */ | |
202 static int saved_doc_string_position; | |
203 #endif | |
204 | |
1123 | 205 static int locate_file_open_or_access_file (Ibyte *fn, int access_mode); |
428 | 206 EXFUN (Fread_from_string, 3); |
207 | |
208 /* When errors are signaled, the actual readcharfun should not be used | |
209 as an argument if it is an lstream, so that lstreams don't escape | |
210 to the Lisp level. */ | |
1261 | 211 #define READCHARFUN_MAYBE(x) (LSTREAMP (x) \ |
212 ? (build_msg_string ("internal input stream")) \ | |
428 | 213 : (x)) |
214 | |
215 | |
2268 | 216 static DECLARE_DOESNT_RETURN (read_syntax_error (const char *)); |
217 | |
428 | 218 static DOESNT_RETURN |
442 | 219 read_syntax_error (const char *string) |
428 | 220 { |
563 | 221 signal_error (Qinvalid_read_syntax, string, Qunbound); |
428 | 222 } |
223 | |
224 static Lisp_Object | |
442 | 225 continuable_read_syntax_error (const char *string) |
428 | 226 { |
563 | 227 return signal_continuable_error (Qinvalid_read_syntax, string, Qunbound); |
428 | 228 } |
229 | |
230 | |
231 /* Handle unreading and rereading of characters. */ | |
867 | 232 static Ichar |
428 | 233 readchar (Lisp_Object readcharfun) |
234 { | |
235 /* This function can GC */ | |
236 | |
237 if (BUFFERP (readcharfun)) | |
238 { | |
867 | 239 Ichar c; |
428 | 240 struct buffer *b = XBUFFER (readcharfun); |
241 | |
242 if (!BUFFER_LIVE_P (b)) | |
563 | 243 invalid_operation ("Reading from killed buffer", Qunbound); |
428 | 244 |
245 if (BUF_PT (b) >= BUF_ZV (b)) | |
246 return -1; | |
247 c = BUF_FETCH_CHAR (b, BUF_PT (b)); | |
248 BUF_SET_PT (b, BUF_PT (b) + 1); | |
249 | |
250 return c; | |
251 } | |
252 else if (LSTREAMP (readcharfun)) | |
253 { | |
867 | 254 Ichar c = Lstream_get_ichar (XLSTREAM (readcharfun)); |
428 | 255 #ifdef DEBUG_XEMACS /* testing Mule */ |
256 static int testing_mule = 0; /* Change via debugger */ | |
444 | 257 if (testing_mule) |
258 { | |
259 if (c >= 0x20 && c <= 0x7E) stderr_out ("%c", c); | |
260 else if (c == '\n') stderr_out ("\\n\n"); | |
261 else stderr_out ("\\%o ", c); | |
262 } | |
263 #endif /* testing Mule */ | |
428 | 264 return c; |
265 } | |
266 else if (MARKERP (readcharfun)) | |
267 { | |
867 | 268 Ichar c; |
665 | 269 Charbpos mpos = marker_position (readcharfun); |
428 | 270 struct buffer *inbuffer = XMARKER (readcharfun)->buffer; |
271 | |
272 if (mpos >= BUF_ZV (inbuffer)) | |
273 return -1; | |
274 c = BUF_FETCH_CHAR (inbuffer, mpos); | |
275 set_marker_position (readcharfun, mpos + 1); | |
276 return c; | |
277 } | |
278 else | |
279 { | |
280 Lisp_Object tem = call0 (readcharfun); | |
281 | |
282 if (!CHAR_OR_CHAR_INTP (tem)) | |
283 return -1; | |
284 return XCHAR_OR_CHAR_INT (tem); | |
285 } | |
286 } | |
287 | |
288 /* Unread the character C in the way appropriate for the stream READCHARFUN. | |
289 If the stream is a user function, call it with the char as argument. */ | |
290 | |
291 static void | |
867 | 292 unreadchar (Lisp_Object readcharfun, Ichar c) |
428 | 293 { |
294 if (c == -1) | |
295 /* Don't back up the pointer if we're unreading the end-of-input mark, | |
296 since readchar didn't advance it when we read it. */ | |
297 ; | |
298 else if (BUFFERP (readcharfun)) | |
299 BUF_SET_PT (XBUFFER (readcharfun), BUF_PT (XBUFFER (readcharfun)) - 1); | |
300 else if (LSTREAMP (readcharfun)) | |
301 { | |
867 | 302 Lstream_unget_ichar (XLSTREAM (readcharfun), c); |
428 | 303 #ifdef DEBUG_XEMACS /* testing Mule */ |
304 { | |
305 static int testing_mule = 0; /* Set this using debugger */ | |
306 if (testing_mule) | |
307 fprintf (stderr, | |
308 (c >= 0x20 && c <= 0x7E) ? "UU%c" : | |
309 ((c == '\n') ? "UU\\n\n" : "UU\\%o"), c); | |
310 } | |
311 #endif | |
312 } | |
313 else if (MARKERP (readcharfun)) | |
314 set_marker_position (readcharfun, marker_position (readcharfun) - 1); | |
315 else | |
316 call1 (readcharfun, make_char (c)); | |
317 } | |
318 | |
319 static Lisp_Object read0 (Lisp_Object readcharfun); | |
320 static Lisp_Object read1 (Lisp_Object readcharfun); | |
321 static Lisp_Object read_list (Lisp_Object readcharfun, | |
867 | 322 Ichar terminator, |
428 | 323 int allow_dotted_lists, |
324 int check_for_doc_references); | |
325 | |
326 static void readevalloop (Lisp_Object readcharfun, | |
327 Lisp_Object sourcefile, | |
328 Lisp_Object (*evalfun) (Lisp_Object), | |
329 int printflag); | |
330 | |
331 static Lisp_Object | |
332 load_unwind (Lisp_Object stream) /* used as unwind-protect function in load */ | |
333 { | |
334 Lstream_close (XLSTREAM (stream)); | |
335 return Qnil; | |
336 } | |
337 | |
2548 | 338 /* Check if NONRELOC/RELOC (an absolute filename) is suppressed according |
339 to load-suppress-alist. */ | |
340 static int | |
341 check_if_suppressed (Ibyte *nonreloc, Lisp_Object reloc) | |
342 { | |
343 Bytecount len; | |
344 | |
345 if (!NILP (reloc)) | |
346 { | |
347 nonreloc = XSTRING_DATA (reloc); | |
348 len = XSTRING_LENGTH (reloc); | |
349 } | |
350 else | |
351 len = qxestrlen (nonreloc); | |
352 | |
353 if (len >= 4 && !qxestrcmp_ascii (nonreloc + len - 4, ".elc")) | |
354 len -= 4; | |
355 else if (len >= 3 && !qxestrcmp_ascii (nonreloc + len - 3, ".el")) | |
356 len -= 3; | |
357 | |
2567 | 358 { |
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
359 EXTERNAL_LIST_LOOP_2 (cons, Vload_suppress_alist) |
2567 | 360 { |
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
361 if (CONSP (cons) && STRINGP (XCAR (cons))) |
2567 | 362 { |
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
363 Lisp_Object name = XCAR (cons); |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
364 if (XSTRING_LENGTH (name) == len && |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
365 !memcmp (XSTRING_DATA (name), nonreloc, len)) |
2567 | 366 { |
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
367 struct gcpro gcpro1; |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
368 Lisp_Object val; |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
369 |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
370 GCPRO1 (reloc); |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
371 val = IGNORE_MULTIPLE_VALUES (Feval (XCDR (cons))); |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
372 UNGCPRO; |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
373 |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
374 if (!NILP (val)) |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
375 return 1; |
2567 | 376 } |
377 } | |
378 } | |
379 } | |
2548 | 380 |
381 return 0; | |
382 } | |
383 | |
428 | 384 /* The plague is coming. |
385 | |
386 Ring around the rosy, pocket full of posy, | |
387 Ashes ashes, they all fall down. | |
388 */ | |
389 void | |
390 ebolify_bytecode_constants (Lisp_Object vector) | |
391 { | |
392 int len = XVECTOR_LENGTH (vector); | |
393 int i; | |
394 | |
395 for (i = 0; i < len; i++) | |
396 { | |
397 Lisp_Object el = XVECTOR_DATA (vector)[i]; | |
398 | |
399 /* We don't check for `eq', `equal', and the others that have | |
400 bytecode opcodes. This might lose if someone passes #'eq or | |
401 something to `funcall', but who would really do that? As | |
402 they say in law, we've made a "good-faith effort" to | |
403 unfuckify ourselves. And doing it this way avoids screwing | |
404 up args to `make-hash-table' and such. As it is, we have to | |
405 add an extra Ebola check in decode_weak_list_type(). --ben */ | |
406 if (EQ (el, Qassoc)) el = Qold_assoc; | |
407 else if (EQ (el, Qdelq)) el = Qold_delq; | |
408 #if 0 | |
409 /* I think this is a bad idea because it will probably mess | |
410 with keymap code. */ | |
411 else if (EQ (el, Qdelete)) el = Qold_delete; | |
412 #endif | |
413 else if (EQ (el, Qrassq)) el = Qold_rassq; | |
414 else if (EQ (el, Qrassoc)) el = Qold_rassoc; | |
415 | |
416 XVECTOR_DATA (vector)[i] = el; | |
417 } | |
418 } | |
419 | |
420 static Lisp_Object | |
558 | 421 pas_de_holgazan_ici (int fd, Lisp_Object victim) |
428 | 422 { |
423 Lisp_Object tem; | |
424 EMACS_INT pos; | |
425 | |
426 if (!INTP (XCDR (victim))) | |
563 | 427 invalid_byte_code ("Bogus doc string reference", victim); |
428 | 428 pos = XINT (XCDR (victim)); |
429 if (pos < 0) | |
430 pos = -pos; /* kludge to mark a user variable */ | |
814 | 431 tem = unparesseuxify_doc_string (fd, pos, 0, Vload_file_name_internal, 0); |
428 | 432 if (!STRINGP (tem)) |
563 | 433 signal_error_1 (Qinvalid_byte_code, tem); |
428 | 434 return tem; |
435 } | |
436 | |
437 static Lisp_Object | |
438 load_force_doc_string_unwind (Lisp_Object oldlist) | |
439 { | |
440 struct gcpro gcpro1; | |
441 Lisp_Object list = Vload_force_doc_string_list; | |
442 Lisp_Object tail; | |
443 int fd = XINT (XCAR (Vload_descriptor_list)); | |
444 | |
445 GCPRO1 (list); | |
446 /* restore the old value first just in case an error occurs. */ | |
447 Vload_force_doc_string_list = oldlist; | |
448 | |
449 LIST_LOOP (tail, list) | |
450 { | |
451 Lisp_Object john = Fcar (tail); | |
452 if (CONSP (john)) | |
453 { | |
454 assert (CONSP (XCAR (john))); | |
455 assert (!purify_flag); /* should have been handled in read_list() */ | |
558 | 456 XCAR (john) = pas_de_holgazan_ici (fd, XCAR (john)); |
428 | 457 } |
458 else | |
459 { | |
460 Lisp_Object doc; | |
461 | |
462 assert (COMPILED_FUNCTIONP (john)); | |
463 if (CONSP (XCOMPILED_FUNCTION (john)->instructions)) | |
464 { | |
465 struct gcpro ngcpro1; | |
558 | 466 Lisp_Object juan = (pas_de_holgazan_ici |
814 | 467 (fd, |
468 XCOMPILED_FUNCTION (john)->instructions)); | |
428 | 469 Lisp_Object ivan; |
470 | |
471 NGCPRO1 (juan); | |
472 ivan = Fread (juan); | |
473 if (!CONSP (ivan)) | |
563 | 474 invalid_byte_code ("invalid lazy-loaded byte code", ivan); |
428 | 475 XCOMPILED_FUNCTION (john)->instructions = XCAR (ivan); |
476 /* v18 or v19 bytecode file. Need to Ebolify. */ | |
477 if (XCOMPILED_FUNCTION (john)->flags.ebolified | |
478 && VECTORP (XCDR (ivan))) | |
479 ebolify_bytecode_constants (XCDR (ivan)); | |
480 XCOMPILED_FUNCTION (john)->constants = XCDR (ivan); | |
481 NUNGCPRO; | |
482 } | |
483 doc = compiled_function_documentation (XCOMPILED_FUNCTION (john)); | |
484 if (CONSP (doc)) | |
485 { | |
486 assert (!purify_flag); /* should have been handled in | |
487 read_compiled_function() */ | |
558 | 488 doc = pas_de_holgazan_ici (fd, doc); |
428 | 489 set_compiled_function_documentation (XCOMPILED_FUNCTION (john), |
490 doc); | |
491 } | |
492 } | |
493 } | |
494 | |
495 if (!NILP (list)) | |
496 free_list (list); | |
497 | |
498 UNGCPRO; | |
499 return Qnil; | |
500 } | |
501 | |
502 /* Close all descriptors in use for Fload_internal. | |
503 This is used when starting a subprocess. */ | |
504 | |
505 void | |
506 close_load_descs (void) | |
507 { | |
508 Lisp_Object tail; | |
509 LIST_LOOP (tail, Vload_descriptor_list) | |
771 | 510 retry_close (XINT (XCAR (tail))); |
428 | 511 } |
512 | |
513 #ifdef I18N3 | |
514 Lisp_Object Vfile_domain; | |
515 #endif /* I18N3 */ | |
516 | |
517 DEFUN ("load-internal", Fload_internal, 1, 6, 0, /* | |
518 Execute a file of Lisp code named FILE; no coding-system frobbing. | |
519 This function is identical to `load' except for the handling of the | |
520 CODESYS and USED-CODESYS arguments under XEmacs/Mule. (When Mule | |
521 support is not present, both functions are identical and ignore the | |
522 CODESYS and USED-CODESYS arguments.) | |
523 | |
524 If support for Mule exists in this Emacs, the file is decoded | |
525 according to CODESYS; if omitted, no conversion happens. If | |
526 USED-CODESYS is non-nil, it should be a symbol, and the actual coding | |
527 system that was used for the decoding is stored into it. It will in | |
528 general be different from CODESYS if CODESYS specifies automatic | |
529 encoding detection or end-of-line detection. | |
530 */ | |
444 | 531 (file, noerror, nomessage, nosuffix, codesys, used_codesys)) |
428 | 532 { |
533 /* This function can GC */ | |
534 int fd = -1; | |
535 int speccount = specpdl_depth (); | |
536 int source_only = 0; | |
1123 | 537 /* NEWER and OLDER are filenames w/o directory, used in loading messages |
538 to e.g. warn of newer .el files when the .elc is being loaded. */ | |
428 | 539 Lisp_Object newer = Qnil; |
1123 | 540 Lisp_Object older = Qnil; |
428 | 541 Lisp_Object handler = Qnil; |
542 Lisp_Object found = Qnil; | |
1292 | 543 Lisp_Object retval; |
1123 | 544 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
428 | 545 int reading_elc = 0; |
780 | 546 int from_require = EQ (nomessage, Qrequire); |
1261 | 547 int message_p = NILP (nomessage) || load_always_display_messages; |
428 | 548 struct stat s1, s2; |
1261 | 549 Ibyte *spaces = alloca_ibytes (load_in_progress * 2 + 10); |
550 int i; | |
1292 | 551 PROFILE_DECLARE (); |
428 | 552 |
1266 | 553 GCPRO4 (file, newer, older, found); |
428 | 554 CHECK_STRING (file); |
555 | |
1292 | 556 PROFILE_RECORD_ENTERING_SECTION (Qload_internal); |
557 | |
428 | 558 /* If file name is magic, call the handler. */ |
559 handler = Ffind_file_name_handler (file, Qload); | |
560 if (!NILP (handler)) | |
1292 | 561 { |
562 retval = call5 (handler, Qload, file, noerror, nomessage, nosuffix); | |
563 goto done; | |
564 } | |
428 | 565 |
566 /* Do this after the handler to avoid | |
567 the need to gcpro noerror, nomessage and nosuffix. | |
568 (Below here, we care only whether they are nil or not.) */ | |
569 file = Fsubstitute_in_file_name (file); | |
570 if (!NILP (used_codesys)) | |
571 CHECK_SYMBOL (used_codesys); | |
572 | |
1261 | 573 if (noninteractive) |
574 { | |
575 for (i = 0; i < load_in_progress * 2; i++) | |
576 spaces[i] = ' '; | |
577 spaces[i] = '\0'; | |
578 } | |
579 else | |
580 spaces[0] = '\0'; | |
581 | |
428 | 582 /* Avoid weird lossage with null string as arg, |
583 since it would try to load a directory as a Lisp file. | |
584 Unix truly sucks. */ | |
585 if (XSTRING_LENGTH (file) > 0) | |
586 { | |
867 | 587 Ibyte *foundstr; |
428 | 588 int foundlen; |
589 | |
590 fd = locate_file (Vload_path, file, | |
591 ((!NILP (nosuffix)) ? Qnil : | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
592 build_ascstring (load_ignore_elc_files ? ".el:" : |
428 | 593 ".elc:.el:")), |
594 &found, | |
595 -1); | |
596 | |
597 if (fd < 0) | |
598 { | |
444 | 599 if (NILP (noerror)) |
563 | 600 signal_error (Qfile_error, "Cannot open load file", file); |
428 | 601 else |
602 { | |
1292 | 603 retval = Qnil; |
604 goto done; | |
428 | 605 } |
606 } | |
607 | |
2367 | 608 foundstr = alloca_ibytes (XSTRING_LENGTH (found) + 1); |
771 | 609 qxestrcpy (foundstr, XSTRING_DATA (found)); |
610 foundlen = qxestrlen (foundstr); | |
428 | 611 |
612 /* The omniscient JWZ thinks this is worthless, but I beg to | |
613 differ. --ben */ | |
614 if (load_ignore_elc_files) | |
1123 | 615 newer = Ffile_name_nondirectory (found); |
616 else if ((load_warn_when_source_newer || | |
617 load_ignore_out_of_date_elc_files) && | |
428 | 618 !memcmp (".elc", foundstr + foundlen - 4, 4)) |
619 { | |
771 | 620 if (! qxe_fstat (fd, &s1)) /* can't fail, right? */ |
428 | 621 { |
622 int result; | |
623 /* temporarily hack the 'c' off the end of the filename */ | |
624 foundstr[foundlen - 1] = '\0'; | |
771 | 625 result = qxe_stat (foundstr, &s2); |
428 | 626 if (result >= 0 && |
627 (unsigned) s1.st_mtime < (unsigned) s2.st_mtime) | |
1123 | 628 { |
629 /* .elc exists and is out-of-date wrt .el */ | |
630 Lisp_Object el_name = make_string (foundstr, foundlen - 1); | |
631 struct gcpro nngcpro1; | |
632 NNGCPRO1 (el_name); | |
633 newer = Ffile_name_nondirectory (el_name); | |
634 if (load_ignore_out_of_date_elc_files) | |
635 { | |
636 int newfd = | |
637 locate_file_open_or_access_file | |
638 (XSTRING_DATA (el_name), -1); | |
639 | |
640 if (newfd >= 0) | |
641 { | |
642 older = Ffile_name_nondirectory (found); | |
643 found = el_name; | |
644 retry_close (fd); | |
645 fd = newfd; | |
646 } | |
647 } | |
648 NNUNGCPRO; | |
649 } | |
428 | 650 /* put the 'c' back on (kludge-o-rama) */ |
651 foundstr[foundlen - 1] = 'c'; | |
652 } | |
653 } | |
654 else if (load_warn_when_source_only && | |
655 /* `found' ends in ".el" */ | |
656 !memcmp (".el", foundstr + foundlen - 3, 3) && | |
657 /* `file' does not end in ".el" */ | |
658 memcmp (".el", | |
659 XSTRING_DATA (file) + XSTRING_LENGTH (file) - 3, | |
660 3)) | |
1123 | 661 source_only = 1; |
428 | 662 |
663 if (!memcmp (".elc", foundstr + foundlen - 4, 4)) | |
664 reading_elc = 1; | |
665 } | |
666 | |
1123 | 667 #define PRINT_LOADING_MESSAGE_1(loading, done) \ |
668 do { \ | |
669 if (load_ignore_elc_files) \ | |
670 { \ | |
671 if (message_p) \ | |
1261 | 672 message (loading done, spaces, \ |
1123 | 673 XSTRING_DATA (load_show_full_path_in_messages ? \ |
674 found : newer)); \ | |
675 } \ | |
676 else if (!NILP (older)) \ | |
677 { \ | |
678 assert (load_ignore_out_of_date_elc_files); \ | |
1261 | 679 message (loading done " (file %s is out-of-date)", spaces, \ |
1123 | 680 XSTRING_DATA (load_show_full_path_in_messages ? \ |
681 found : newer), \ | |
682 XSTRING_DATA (older)); \ | |
683 } \ | |
684 else if (!NILP (newer)) \ | |
1261 | 685 message (loading done " (file %s is newer)", spaces, \ |
1123 | 686 XSTRING_DATA (load_show_full_path_in_messages ? \ |
687 found : file), \ | |
688 XSTRING_DATA (newer)); \ | |
689 else if (source_only) \ | |
1261 | 690 message (loading done " (file %s.elc does not exist)", spaces, \ |
1123 | 691 XSTRING_DATA (load_show_full_path_in_messages ? \ |
692 found : file), \ | |
693 XSTRING_DATA (Ffile_name_nondirectory (file))); \ | |
694 else if (message_p) \ | |
1261 | 695 message (loading done, spaces, \ |
1123 | 696 XSTRING_DATA (load_show_full_path_in_messages ? \ |
697 found : file)); \ | |
428 | 698 } while (0) |
699 | |
1261 | 700 #define PRINT_LOADING_MESSAGE(done) \ |
701 do { \ | |
702 if (from_require) \ | |
703 PRINT_LOADING_MESSAGE_1 ("%sRequiring %s...", done); \ | |
704 else \ | |
705 PRINT_LOADING_MESSAGE_1 ("%sLoading %s...", done); \ | |
780 | 706 } while (0) |
707 | |
428 | 708 PRINT_LOADING_MESSAGE (""); |
709 | |
4608
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
710 LISP_READONLY (found) = 1; |
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
711 |
428 | 712 { |
713 /* Lisp_Object's must be malloc'ed, not stack-allocated */ | |
714 Lisp_Object lispstream = Qnil; | |
442 | 715 const int block_size = 8192; |
428 | 716 struct gcpro ngcpro1; |
717 | |
718 NGCPRO1 (lispstream); | |
719 lispstream = make_filedesc_input_stream (fd, 0, -1, LSTR_CLOSING); | |
720 /* 64K is used for normal files; 8K should be OK here because Lisp | |
721 files aren't really all that big. */ | |
722 Lstream_set_buffering (XLSTREAM (lispstream), LSTREAM_BLOCKN_BUFFERED, | |
723 block_size); | |
771 | 724 lispstream = make_coding_input_stream |
725 (XLSTREAM (lispstream), get_coding_system_for_text_file (codesys, 1), | |
800 | 726 CODING_DECODE, 0); |
428 | 727 Lstream_set_buffering (XLSTREAM (lispstream), LSTREAM_BLOCKN_BUFFERED, |
728 block_size); | |
729 /* NOTE: Order of these is very important. Don't rearrange them. */ | |
853 | 730 internal_bind_int (&load_in_progress, 1 + load_in_progress); |
428 | 731 record_unwind_protect (load_unwind, lispstream); |
853 | 732 internal_bind_lisp_object (&Vload_descriptor_list, |
733 Fcons (make_int (fd), Vload_descriptor_list)); | |
734 internal_bind_lisp_object (&Vload_file_name_internal, found); | |
735 /* this is not a simple internal_bind. */ | |
428 | 736 record_unwind_protect (load_force_doc_string_unwind, |
737 Vload_force_doc_string_list); | |
853 | 738 Vload_force_doc_string_list = Qnil; |
4608
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
739 /* load-file-name is not read-only to Lisp. */ |
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
740 internal_bind_lisp_object (&Vload_file_name, Fcopy_sequence(found)); |
428 | 741 #ifdef I18N3 |
853 | 742 /* set it to nil; a call to #'domain will set it. */ |
743 internal_bind_lisp_object (&Vfile_domain, Qnil); | |
428 | 744 #endif |
745 | |
4448
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
746 /* Is there a #!? If so, read it, and unread ;!. |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
747 |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
748 GNU implement this by treating any #! anywhere in the source text as |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
749 commenting out the whole line. */ |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
750 { |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
751 char shebangp[2]; |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
752 int num_read; |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
753 |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
754 num_read = Lstream_read (XLSTREAM (lispstream), shebangp, |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
755 sizeof(shebangp)); |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
756 if (sizeof(shebangp) == num_read |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
757 && 0 == strncmp("#!", shebangp, sizeof(shebangp))) |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
758 { |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
759 shebangp[0] = ';'; |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
760 } |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
761 |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
762 Lstream_unread (XLSTREAM (lispstream), shebangp, num_read); |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
763 } |
fd8a9a4d81d9
Support #!, to allow XEmacs to be called as a script interpreter.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
764 |
428 | 765 /* Now determine what sort of ELC file we're reading in. */ |
853 | 766 internal_bind_int (&load_byte_code_version, load_byte_code_version); |
428 | 767 if (reading_elc) |
768 { | |
769 char elc_header[8]; | |
770 int num_read; | |
771 | |
772 num_read = Lstream_read (XLSTREAM (lispstream), elc_header, 8); | |
773 if (num_read < 8 | |
774 || strncmp (elc_header, ";ELC", 4)) | |
775 { | |
776 /* Huh? Probably not a valid ELC file. */ | |
777 load_byte_code_version = 100; /* no Ebolification needed */ | |
778 Lstream_unread (XLSTREAM (lispstream), elc_header, num_read); | |
779 } | |
780 else | |
781 load_byte_code_version = elc_header[4]; | |
782 } | |
783 else | |
784 load_byte_code_version = 100; /* no Ebolification needed */ | |
785 | |
786 readevalloop (lispstream, file, Feval, 0); | |
787 if (!NILP (used_codesys)) | |
788 Fset (used_codesys, | |
789 XCODING_SYSTEM_NAME | |
771 | 790 (coding_stream_detected_coding_system (XLSTREAM (lispstream)))); |
791 unbind_to (speccount); | |
428 | 792 |
793 NUNGCPRO; | |
794 } | |
795 | |
796 { | |
797 Lisp_Object tem; | |
798 /* #### Disgusting kludge */ | |
799 /* Run any load-hooks for this file. */ | |
800 /* #### An even more disgusting kludge. There is horrible code */ | |
801 /* that is relying on the fact that dumped lisp files are found */ | |
802 /* via `load-path' search. */ | |
803 Lisp_Object name = file; | |
804 | |
1123 | 805 if (!NILP (Ffile_name_absolute_p (file))) |
806 name = Ffile_name_nondirectory (file); | |
428 | 807 |
1261 | 808 tem = Fassoc (name, Vafter_load_alist); |
428 | 809 if (!NILP (tem)) |
810 { | |
811 struct gcpro ngcpro1; | |
812 | |
813 NGCPRO1 (tem); | |
814 /* Use eval so that errors give a semi-meaningful backtrace. --Stig */ | |
815 tem = Fcons (Qprogn, Fcdr (tem)); | |
816 Feval (tem); | |
817 NUNGCPRO; | |
818 } | |
819 } | |
820 | |
821 if (!noninteractive) | |
822 PRINT_LOADING_MESSAGE ("done"); | |
823 | |
1292 | 824 retval = Qt; |
825 done: | |
826 PROFILE_RECORD_EXITING_SECTION (Qload_internal); | |
428 | 827 UNGCPRO; |
1292 | 828 return retval; |
428 | 829 } |
830 | |
831 | |
832 /* ------------------------------- */ | |
833 /* locate_file */ | |
834 /* ------------------------------- */ | |
835 | |
836 static int | |
837 decode_mode_1 (Lisp_Object mode) | |
838 { | |
839 if (EQ (mode, Qexists)) | |
840 return F_OK; | |
841 else if (EQ (mode, Qexecutable)) | |
842 return X_OK; | |
843 else if (EQ (mode, Qwritable)) | |
844 return W_OK; | |
845 else if (EQ (mode, Qreadable)) | |
846 return R_OK; | |
847 else if (INTP (mode)) | |
848 { | |
849 check_int_range (XINT (mode), 0, 7); | |
850 return XINT (mode); | |
851 } | |
852 else | |
563 | 853 invalid_argument ("Invalid value", mode); |
428 | 854 return 0; /* unreached */ |
855 } | |
856 | |
857 static int | |
858 decode_mode (Lisp_Object mode) | |
859 { | |
860 if (NILP (mode)) | |
861 return R_OK; | |
862 else if (CONSP (mode)) | |
863 { | |
864 int mask = 0; | |
2367 | 865 EXTERNAL_LIST_LOOP_2 (elt, mode) |
866 mask |= decode_mode_1 (elt); | |
428 | 867 return mask; |
868 } | |
869 else | |
870 return decode_mode_1 (mode); | |
871 } | |
872 | |
873 DEFUN ("locate-file", Flocate_file, 2, 4, 0, /* | |
874 Search for FILENAME through PATH-LIST. | |
875 | |
876 If SUFFIXES is non-nil, it should be a list of suffixes to append to | |
877 file name when searching. | |
878 | |
879 If MODE is non-nil, it should be a symbol or a list of symbol representing | |
880 requirements. Allowed symbols are `exists', `executable', `writable', and | |
881 `readable'. If MODE is nil, it defaults to `readable'. | |
882 | |
2548 | 883 Filenames are checked against `load-suppress-alist' to determine if they |
884 should be ignored. | |
885 | |
428 | 886 `locate-file' keeps hash tables of the directories it searches through, |
887 in order to speed things up. It tries valiantly to not get confused in | |
888 the face of a changing and unpredictable environment, but can occasionally | |
889 get tripped up. In this case, you will have to call | |
890 `locate-file-clear-hashing' to get it back on track. See that function | |
891 for details. | |
892 */ | |
893 (filename, path_list, suffixes, mode)) | |
894 { | |
895 /* This function can GC */ | |
896 Lisp_Object tp; | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5139
diff
changeset
|
897 static int locate_file_called; |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5139
diff
changeset
|
898 |
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5139
diff
changeset
|
899 ++locate_file_called; |
428 | 900 |
901 CHECK_STRING (filename); | |
902 | |
903 if (LISTP (suffixes)) | |
904 { | |
2367 | 905 EXTERNAL_LIST_LOOP_2 (elt, suffixes) |
906 CHECK_STRING (elt); | |
428 | 907 } |
908 else | |
909 CHECK_STRING (suffixes); | |
910 | |
911 locate_file (path_list, filename, suffixes, &tp, decode_mode (mode)); | |
912 return tp; | |
913 } | |
914 | |
915 /* Recalculate the hash table for the given string. DIRECTORY should | |
916 better have been through Fexpand_file_name() by now. */ | |
917 | |
918 static Lisp_Object | |
919 locate_file_refresh_hashing (Lisp_Object directory) | |
920 { | |
921 Lisp_Object hash = | |
771 | 922 make_directory_hash_table (XSTRING_DATA (directory)); |
428 | 923 |
924 if (!NILP (hash)) | |
925 Fputhash (directory, hash, Vlocate_file_hash_table); | |
926 return hash; | |
927 } | |
928 | |
929 /* find the hash table for the given directory, recalculating if necessary */ | |
930 | |
931 static Lisp_Object | |
932 locate_file_find_directory_hash_table (Lisp_Object directory) | |
933 { | |
934 Lisp_Object hash = Fgethash (directory, Vlocate_file_hash_table, Qnil); | |
935 if (NILP (hash)) | |
936 return locate_file_refresh_hashing (directory); | |
937 else | |
938 return hash; | |
939 } | |
940 | |
941 /* The SUFFIXES argument in any of the locate_file* functions can be | |
942 nil, a list, or a string (for backward compatibility), with the | |
943 following semantics: | |
944 | |
945 a) nil - no suffix, just search for file name intact | |
946 (semantically different from "empty suffix list", which | |
947 would be meaningless.) | |
948 b) list - list of suffixes to append to file name. Each of these | |
949 must be a string. | |
950 c) string - colon-separated suffixes to append to file name (backward | |
951 compatibility). | |
952 | |
953 All of this got hairy, so I decided to use a mapper. Calling a | |
954 function for each suffix shouldn't slow things down, since | |
955 locate_file is rarely called with enough suffixes for funcalls to | |
956 make any difference. */ | |
957 | |
958 /* Map FUN over SUFFIXES, as described above. FUN will be called with a | |
959 char * containing the current file name, and ARG. Mapping stops when | |
960 FUN returns non-zero. */ | |
961 static void | |
962 locate_file_map_suffixes (Lisp_Object filename, Lisp_Object suffixes, | |
867 | 963 int (*fun) (Ibyte *, void *), |
428 | 964 void *arg) |
965 { | |
966 /* This function can GC */ | |
867 | 967 Ibyte *fn; |
428 | 968 int fn_len, max; |
969 | |
970 /* Calculate maximum size of any filename made from | |
971 this path element/specified file name and any possible suffix. */ | |
972 if (CONSP (suffixes)) | |
973 { | |
974 /* We must traverse the list, so why not do it right. */ | |
975 Lisp_Object tail; | |
976 max = 0; | |
977 LIST_LOOP (tail, suffixes) | |
978 { | |
979 if (XSTRING_LENGTH (XCAR (tail)) > max) | |
980 max = XSTRING_LENGTH (XCAR (tail)); | |
981 } | |
982 } | |
983 else if (NILP (suffixes)) | |
984 max = 0; | |
985 else | |
986 /* Just take the easy way out */ | |
987 max = XSTRING_LENGTH (suffixes); | |
988 | |
989 fn_len = XSTRING_LENGTH (filename); | |
2367 | 990 fn = alloca_ibytes (max + fn_len + 1); |
771 | 991 memcpy (fn, XSTRING_DATA (filename), fn_len); |
428 | 992 |
993 /* Loop over suffixes. */ | |
994 if (!STRINGP (suffixes)) | |
995 { | |
996 if (NILP (suffixes)) | |
997 { | |
998 /* Case a) discussed in the comment above. */ | |
999 fn[fn_len] = 0; | |
1000 if ((*fun) (fn, arg)) | |
1001 return; | |
1002 } | |
1003 else | |
1004 { | |
1005 /* Case b) */ | |
1006 Lisp_Object tail; | |
1007 LIST_LOOP (tail, suffixes) | |
1008 { | |
1009 memcpy (fn + fn_len, XSTRING_DATA (XCAR (tail)), | |
1010 XSTRING_LENGTH (XCAR (tail))); | |
1011 fn[fn_len + XSTRING_LENGTH (XCAR (tail))] = 0; | |
1012 if ((*fun) (fn, arg)) | |
1013 return; | |
1014 } | |
1015 } | |
1016 } | |
1017 else | |
1018 { | |
1019 /* Case c) */ | |
867 | 1020 const Ibyte *nsuffix = XSTRING_DATA (suffixes); |
428 | 1021 |
1022 while (1) | |
1023 { | |
867 | 1024 Ibyte *esuffix = qxestrchr (nsuffix, ':'); |
771 | 1025 Bytecount lsuffix = esuffix ? esuffix - nsuffix : |
1026 qxestrlen (nsuffix); | |
428 | 1027 |
1028 /* Concatenate path element/specified name with the suffix. */ | |
771 | 1029 qxestrncpy (fn + fn_len, nsuffix, lsuffix); |
428 | 1030 fn[fn_len + lsuffix] = 0; |
1031 | |
1032 if ((*fun) (fn, arg)) | |
1033 return; | |
1034 | |
1035 /* Advance to next suffix. */ | |
1036 if (esuffix == 0) | |
1037 break; | |
1038 nsuffix += lsuffix + 1; | |
1039 } | |
1040 } | |
1041 } | |
1042 | |
771 | 1043 struct locate_file_in_directory_mapper_closure |
1044 { | |
428 | 1045 int fd; |
1046 Lisp_Object *storeptr; | |
1047 int mode; | |
1048 }; | |
1049 | |
1123 | 1050 /* open() or access() a file to be returned by locate_file(). if |
1051 ACCESS_MODE >= 0, do an access() with that mode, else open(). Does | |
1052 various magic, e.g. opening the file read-only and binary and setting | |
1053 the close-on-exec flag on the file. */ | |
1054 | |
1055 static int | |
1056 locate_file_open_or_access_file (Ibyte *fn, int access_mode) | |
1057 { | |
1058 int val; | |
1059 | |
1060 /* Check that we can access or open it. */ | |
1061 if (access_mode >= 0) | |
1062 val = qxe_access (fn, access_mode); | |
1063 else | |
1064 { | |
1065 val = qxe_open (fn, O_RDONLY | OPEN_BINARY, 0); | |
1066 | |
1067 #ifndef WIN32_NATIVE | |
1068 if (val >= 0) | |
1069 /* If we actually opened the file, set close-on-exec flag | |
1070 on the new descriptor so that subprocesses can't whack | |
1071 at it. */ | |
1072 (void) fcntl (val, F_SETFD, FD_CLOEXEC); | |
1073 #endif | |
1074 } | |
1075 | |
1076 return val; | |
1077 } | |
1078 | |
428 | 1079 static int |
867 | 1080 locate_file_in_directory_mapper (Ibyte *fn, void *arg) |
428 | 1081 { |
1082 struct locate_file_in_directory_mapper_closure *closure = | |
771 | 1083 (struct locate_file_in_directory_mapper_closure *) arg; |
428 | 1084 struct stat st; |
1085 | |
1086 /* Ignore file if it's a directory. */ | |
771 | 1087 if (qxe_stat (fn, &st) >= 0 |
428 | 1088 && (st.st_mode & S_IFMT) != S_IFDIR) |
1089 { | |
1090 /* Check that we can access or open it. */ | |
1123 | 1091 closure->fd = locate_file_open_or_access_file (fn, closure->mode); |
428 | 1092 |
1093 if (closure->fd >= 0) | |
1094 { | |
2548 | 1095 if (!check_if_suppressed (fn, Qnil)) |
1096 { | |
1097 /* We succeeded; return this descriptor and filename. */ | |
1098 if (closure->storeptr) | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1099 *closure->storeptr = build_istring (fn); |
2548 | 1100 |
1101 return 1; | |
1102 } | |
428 | 1103 } |
1104 } | |
1105 /* Keep mapping. */ | |
1106 return 0; | |
1107 } | |
1108 | |
1109 | |
1110 /* look for STR in PATH, optionally adding SUFFIXES. DIRECTORY need | |
1111 not have been expanded. */ | |
1112 | |
1113 static int | |
1114 locate_file_in_directory (Lisp_Object directory, Lisp_Object str, | |
1115 Lisp_Object suffixes, Lisp_Object *storeptr, | |
1116 int mode) | |
1117 { | |
1118 /* This function can GC */ | |
1119 struct locate_file_in_directory_mapper_closure closure; | |
1120 Lisp_Object filename = Qnil; | |
1121 struct gcpro gcpro1, gcpro2, gcpro3; | |
1122 | |
1123 GCPRO3 (directory, str, filename); | |
1124 | |
1125 filename = Fexpand_file_name (str, directory); | |
1126 if (NILP (filename) || NILP (Ffile_name_absolute_p (filename))) | |
1127 /* If there are non-absolute elts in PATH (eg ".") */ | |
1128 /* Of course, this could conceivably lose if luser sets | |
1129 default-directory to be something non-absolute ... */ | |
1130 { | |
1131 if (NILP (filename)) | |
1132 /* NIL means current directory */ | |
1133 filename = current_buffer->directory; | |
1134 else | |
1135 filename = Fexpand_file_name (filename, | |
1136 current_buffer->directory); | |
1137 if (NILP (Ffile_name_absolute_p (filename))) | |
1138 { | |
1139 /* Give up on this directory! */ | |
1140 UNGCPRO; | |
1141 return -1; | |
1142 } | |
1143 } | |
1144 | |
1145 closure.fd = -1; | |
1146 closure.storeptr = storeptr; | |
1147 closure.mode = mode; | |
1148 | |
771 | 1149 locate_file_map_suffixes (filename, suffixes, |
1150 locate_file_in_directory_mapper, | |
428 | 1151 &closure); |
1152 | |
1153 UNGCPRO; | |
1154 return closure.fd; | |
1155 } | |
1156 | |
1157 /* do the same as locate_file() but don't use any hash tables. */ | |
1158 | |
1159 static int | |
1160 locate_file_without_hash (Lisp_Object path, Lisp_Object str, | |
1161 Lisp_Object suffixes, Lisp_Object *storeptr, | |
1162 int mode) | |
1163 { | |
1164 /* This function can GC */ | |
1165 int absolute = !NILP (Ffile_name_absolute_p (str)); | |
1166 | |
2367 | 1167 EXTERNAL_LIST_LOOP_2 (elt, path) |
428 | 1168 { |
2367 | 1169 int val = locate_file_in_directory (elt, str, suffixes, storeptr, |
428 | 1170 mode); |
1171 if (val >= 0) | |
1172 return val; | |
1173 if (absolute) | |
1174 break; | |
1175 } | |
1176 return -1; | |
1177 } | |
1178 | |
1179 static int | |
867 | 1180 locate_file_construct_suffixed_files_mapper (Ibyte *fn, void *arg) |
428 | 1181 { |
771 | 1182 Lisp_Object *tail = (Lisp_Object *) arg; |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1183 *tail = Fcons (build_istring (fn), *tail); |
428 | 1184 return 0; |
1185 } | |
1186 | |
1187 /* Construct a list of all files to search for. | |
1188 It makes sense to have this despite locate_file_map_suffixes() | |
1189 because we need Lisp strings to access the hash-table, and it would | |
1190 be inefficient to create them on the fly, again and again for each | |
1191 path component. See locate_file(). */ | |
1192 | |
1193 static Lisp_Object | |
1194 locate_file_construct_suffixed_files (Lisp_Object filename, | |
1195 Lisp_Object suffixes) | |
1196 { | |
1197 Lisp_Object tail = Qnil; | |
1198 struct gcpro gcpro1; | |
1199 GCPRO1 (tail); | |
1200 | |
1201 locate_file_map_suffixes (filename, suffixes, | |
1202 locate_file_construct_suffixed_files_mapper, | |
1203 &tail); | |
1204 | |
1205 UNGCPRO; | |
1206 return Fnreverse (tail); | |
1207 } | |
1208 | |
1209 DEFUN ("locate-file-clear-hashing", Flocate_file_clear_hashing, 1, 1, 0, /* | |
1210 Clear the hash records for the specified list of directories. | |
1211 `locate-file' uses a hashing scheme to speed lookup, and will correctly | |
1212 track the following environmental changes: | |
1213 | |
1214 -- changes of any sort to the list of directories to be searched. | |
1215 -- addition and deletion of non-shadowing files (see below) from the | |
1216 directories in the list. | |
1217 -- byte-compilation of a .el file into a .elc file. | |
1218 | |
1219 `locate-file' will primarily get confused if you add a file that shadows | |
1220 \(i.e. has the same name as) another file further down in the directory list. | |
1221 In this case, you must call `locate-file-clear-hashing'. | |
1222 | |
1223 If PATH is t, it means to fully clear all the accumulated hashes. This | |
1224 can be used if the internal tables grow too large, or when dumping. | |
1225 */ | |
1226 (path)) | |
1227 { | |
1228 if (EQ (path, Qt)) | |
1229 Fclrhash (Vlocate_file_hash_table); | |
1230 else | |
1231 { | |
2367 | 1232 EXTERNAL_LIST_LOOP_2 (elt, path) |
428 | 1233 { |
2367 | 1234 Lisp_Object pathel = Fexpand_file_name (elt, Qnil); |
428 | 1235 Fremhash (pathel, Vlocate_file_hash_table); |
1236 } | |
1237 } | |
1238 return Qnil; | |
1239 } | |
1240 | |
1241 /* Search for a file whose name is STR, looking in directories | |
1242 in the Lisp list PATH, and trying suffixes from SUFFIXES. | |
1243 SUFFIXES is a list of possible suffixes, or (for backward | |
1244 compatibility) a string containing possible suffixes separated by | |
1245 colons. | |
1246 On success, returns a file descriptor. On failure, returns -1. | |
1247 | |
1248 MODE nonnegative means don't open the files, | |
1249 just look for one for which access(file,MODE) succeeds. In this case, | |
951 | 1250 returns a nonnegative value on success. On failure, returns -1. |
428 | 1251 |
2548 | 1252 If STOREPTR is non-nil, it points to a slot where the name of |
428 | 1253 the file actually found should be stored as a Lisp string. |
1254 Nil is stored there on failure. | |
1255 | |
1256 Called openp() in FSFmacs. */ | |
1257 | |
1258 int | |
1259 locate_file (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, | |
1260 Lisp_Object *storeptr, int mode) | |
1261 { | |
1262 /* This function can GC */ | |
1263 Lisp_Object suffixtab = Qnil; | |
2367 | 1264 Lisp_Object pathel_expanded; |
428 | 1265 int val; |
1266 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
1267 | |
1268 if (storeptr) | |
1269 *storeptr = Qnil; | |
1270 | |
1271 /* Is it really necessary to gcpro path and str? It shouldn't be | |
1272 unless some caller has fucked up. There are known instances that | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
1273 call us with build_ascstring("foo:bar") as SUFFIXES, though. */ |
428 | 1274 GCPRO4 (path, str, suffixes, suffixtab); |
1275 | |
1276 /* if this filename has directory components, it's too complicated | |
1277 to try and use the hash tables. */ | |
1278 if (!NILP (Ffile_name_directory (str))) | |
1279 { | |
1280 val = locate_file_without_hash (path, str, suffixes, storeptr, mode); | |
1281 UNGCPRO; | |
1282 return val; | |
1283 } | |
1284 | |
1285 suffixtab = locate_file_construct_suffixed_files (str, suffixes); | |
1286 | |
2367 | 1287 { |
1288 EXTERNAL_LIST_LOOP_2 (pathel, path) | |
1289 { | |
1290 Lisp_Object hash_table; | |
1291 int found = 0; | |
1292 | |
1293 /* If this path element is relative, we have to look by hand. */ | |
1294 if (NILP (pathel) || NILP (Ffile_name_absolute_p (pathel))) | |
1295 { | |
1296 val = locate_file_in_directory (pathel, str, suffixes, storeptr, | |
1297 mode); | |
1298 if (val >= 0) | |
428 | 1299 { |
2367 | 1300 UNGCPRO; |
1301 return val; | |
428 | 1302 } |
2367 | 1303 continue; |
1304 } | |
1305 | |
1306 pathel_expanded = Fexpand_file_name (pathel, Qnil); | |
1307 hash_table = locate_file_find_directory_hash_table (pathel_expanded); | |
1308 | |
1309 if (!NILP (hash_table)) | |
1310 { | |
1311 /* Loop over suffixes. */ | |
1312 LIST_LOOP_2 (elt, suffixtab) | |
1313 if (!NILP (Fgethash (elt, hash_table, Qnil))) | |
1314 { | |
1315 found = 1; | |
1316 break; | |
1317 } | |
1318 } | |
1319 | |
1320 if (found) | |
1321 { | |
1322 /* This is a likely candidate. Look by hand in this directory | |
1323 so we don't get thrown off if someone byte-compiles a file. */ | |
1324 val = locate_file_in_directory (pathel, str, suffixes, storeptr, | |
1325 mode); | |
1326 if (val >= 0) | |
1327 { | |
1328 UNGCPRO; | |
1329 return val; | |
1330 } | |
1331 | |
1332 /* Hmm ... the file isn't actually there. (Or possibly it's | |
1333 a directory ...) So refresh our hashing. */ | |
1334 locate_file_refresh_hashing (pathel_expanded); | |
1335 } | |
1336 } | |
428 | 1337 } |
1338 | |
1339 /* File is probably not there, but check the hard way just in case. */ | |
1340 val = locate_file_without_hash (path, str, suffixes, storeptr, mode); | |
1341 if (val >= 0) | |
1342 { | |
1343 /* Sneaky user added a file without telling us. */ | |
1344 Flocate_file_clear_hashing (path); | |
1345 } | |
1346 | |
1347 UNGCPRO; | |
1348 return val; | |
1349 } | |
1350 | |
1351 | |
1352 #ifdef LOADHIST | |
1353 | |
1354 /* Merge the list we've accumulated of globals from the current input source | |
1355 into the load_history variable. The details depend on whether | |
1356 the source has an associated file name or not. */ | |
1357 | |
1358 static void | |
1359 build_load_history (int loading, Lisp_Object source) | |
1360 { | |
1361 REGISTER Lisp_Object tail, prev, newelt; | |
1362 REGISTER Lisp_Object tem, tem2; | |
1363 int foundit; | |
1364 | |
1365 #if !defined(LOADHIST_DUMPED) | |
1366 /* Don't bother recording anything for preloaded files. */ | |
1367 if (purify_flag) | |
1368 return; | |
1369 #endif | |
1370 | |
1371 tail = Vload_history; | |
1372 prev = Qnil; | |
1373 foundit = 0; | |
1374 while (!NILP (tail)) | |
1375 { | |
1376 tem = Fcar (tail); | |
1377 | |
1378 /* Find the feature's previous assoc list... */ | |
1379 if (internal_equal (source, Fcar (tem), 0)) | |
1380 { | |
1381 foundit = 1; | |
1382 | |
1383 /* If we're loading, remove it. */ | |
1384 if (loading) | |
1385 { | |
1386 if (NILP (prev)) | |
1387 Vload_history = Fcdr (tail); | |
1388 else | |
1389 Fsetcdr (prev, Fcdr (tail)); | |
1390 } | |
1391 | |
1392 /* Otherwise, cons on new symbols that are not already members. */ | |
1393 else | |
1394 { | |
1395 tem2 = Vcurrent_load_list; | |
1396 | |
1397 while (CONSP (tem2)) | |
1398 { | |
1399 newelt = XCAR (tem2); | |
1400 | |
1401 if (NILP (Fmemq (newelt, tem))) | |
1402 Fsetcar (tail, Fcons (Fcar (tem), | |
1403 Fcons (newelt, Fcdr (tem)))); | |
1404 | |
1405 tem2 = XCDR (tem2); | |
1406 QUIT; | |
1407 } | |
1408 } | |
1409 } | |
1410 else | |
1411 prev = tail; | |
1412 tail = Fcdr (tail); | |
1413 QUIT; | |
1414 } | |
1415 | |
1416 /* If we're loading, cons the new assoc onto the front of load-history, | |
1417 the most-recently-loaded position. Also do this if we didn't find | |
1418 an existing member for the current source. */ | |
1419 if (loading || !foundit) | |
1420 Vload_history = Fcons (Fnreverse (Vcurrent_load_list), | |
1421 Vload_history); | |
1422 } | |
1423 | |
1424 #else /* !LOADHIST */ | |
1425 #define build_load_history(x,y) | |
1426 #endif /* !LOADHIST */ | |
1427 | |
1428 | |
1429 static void | |
1430 readevalloop (Lisp_Object readcharfun, | |
1431 Lisp_Object sourcename, | |
1432 Lisp_Object (*evalfun) (Lisp_Object), | |
1433 int printflag) | |
1434 { | |
1435 /* This function can GC */ | |
867 | 1436 REGISTER Ichar c; |
1849 | 1437 Lisp_Object val = Qnil; |
428 | 1438 int speccount = specpdl_depth (); |
1439 struct gcpro gcpro1, gcpro2; | |
1440 struct buffer *b = 0; | |
1441 | |
1442 if (BUFFERP (readcharfun)) | |
1443 b = XBUFFER (readcharfun); | |
1444 else if (MARKERP (readcharfun)) | |
1445 b = XMARKER (readcharfun)->buffer; | |
1446 | |
1447 /* Don't do this. It is not necessary, and it needlessly exposes | |
1448 READCHARFUN (which can be a stream) to Lisp. --hniksic */ | |
1449 /*specbind (Qstandard_input, readcharfun);*/ | |
1450 | |
2548 | 1451 internal_bind_lisp_object (&Vcurrent_load_list, Qnil); |
428 | 1452 |
1453 GCPRO2 (val, sourcename); | |
1454 | |
1455 LOADHIST_ATTACH (sourcename); | |
1456 | |
1457 while (1) | |
1458 { | |
1459 QUIT; | |
1460 | |
1461 if (b != 0 && !BUFFER_LIVE_P (b)) | |
563 | 1462 invalid_operation ("Reading from killed buffer", Qunbound); |
428 | 1463 |
1464 c = readchar (readcharfun); | |
1465 if (c == ';') | |
1466 { | |
1467 /* Skip comment */ | |
1468 while ((c = readchar (readcharfun)) != '\n' && c != -1) | |
1469 QUIT; | |
1470 continue; | |
1471 } | |
1472 if (c < 0) | |
1473 break; | |
1474 | |
1475 /* Ignore whitespace here, so we can detect eof. */ | |
1476 if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r') | |
1477 continue; | |
1478 | |
814 | 1479 unreadchar (readcharfun, c); |
1480 Vread_objects = Qnil; | |
1481 if (NILP (Vload_read_function)) | |
1482 val = read0 (readcharfun); | |
428 | 1483 else |
814 | 1484 val = call1 (Vload_read_function, readcharfun); |
428 | 1485 val = (*evalfun) (val); |
1486 if (printflag) | |
1487 { | |
1488 Vvalues = Fcons (val, Vvalues); | |
1489 if (EQ (Vstandard_output, Qt)) | |
1490 Fprin1 (val, Qnil); | |
1491 else | |
1492 Fprint (val, Qnil); | |
1493 } | |
1494 } | |
1495 | |
1496 build_load_history (LSTREAMP (readcharfun) || | |
1497 /* This looks weird, but it's what's in FSFmacs */ | |
1498 (b ? BUF_NARROWED (b) : BUF_NARROWED (current_buffer)), | |
1499 sourcename); | |
1500 UNGCPRO; | |
1501 | |
771 | 1502 unbind_to (speccount); |
428 | 1503 } |
1504 | |
1505 DEFUN ("eval-buffer", Feval_buffer, 0, 2, "bBuffer: ", /* | |
1506 Execute BUFFER as Lisp code. | |
1507 Programs can pass two arguments, BUFFER and PRINTFLAG. | |
1508 BUFFER is the buffer to evaluate (nil means use current buffer). | |
1509 PRINTFLAG controls printing of output: | |
444 | 1510 nil means discard it; anything else is a stream for printing. |
428 | 1511 |
1512 If there is no error, point does not move. If there is an error, | |
1513 point remains at the end of the last character read from the buffer. | |
1514 */ | |
444 | 1515 (buffer, printflag)) |
428 | 1516 { |
1517 /* This function can GC */ | |
1518 int speccount = specpdl_depth (); | |
1519 Lisp_Object tem, buf; | |
1520 | |
444 | 1521 if (NILP (buffer)) |
428 | 1522 buf = Fcurrent_buffer (); |
1523 else | |
444 | 1524 buf = Fget_buffer (buffer); |
428 | 1525 if (NILP (buf)) |
563 | 1526 invalid_argument ("No such buffer", Qunbound); |
428 | 1527 |
1528 if (NILP (printflag)) | |
1529 tem = Qsymbolp; /* #### #@[]*&$#*[& SI:NULL-STREAM */ | |
1530 else | |
1531 tem = printflag; | |
1532 specbind (Qstandard_output, tem); | |
1533 record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
1534 BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); | |
1535 readevalloop (buf, XBUFFER (buf)->filename, Feval, | |
1536 !NILP (printflag)); | |
1537 | |
771 | 1538 return unbind_to (speccount); |
428 | 1539 } |
1540 | |
1541 #if 0 | |
826 | 1542 DEFUN ("eval-current-buffer", Feval_current_buffer, 0, 1, "", /* |
428 | 1543 Execute the current buffer as Lisp code. |
1544 Programs can pass argument PRINTFLAG which controls printing of output: | |
1545 nil means discard it; anything else is stream for print. | |
1546 | |
1547 If there is no error, point does not move. If there is an error, | |
1548 point remains at the end of the last character read from the buffer. | |
1549 */ | |
1550 (printflag)) | |
1551 { | |
1552 code omitted; | |
1553 } | |
1554 #endif /* 0 */ | |
1555 | |
1556 DEFUN ("eval-region", Feval_region, 2, 3, "r", /* | |
1557 Execute the region as Lisp code. | |
444 | 1558 When called from programs, expects two arguments START and END |
428 | 1559 giving starting and ending indices in the current buffer |
1560 of the text to be executed. | |
444 | 1561 Programs can pass third optional argument STREAM which controls output: |
428 | 1562 nil means discard it; anything else is stream for printing it. |
1563 | |
1564 If there is no error, point does not move. If there is an error, | |
1565 point remains at the end of the last character read from the buffer. | |
1566 | |
1567 Note: Before evaling the region, this function narrows the buffer to it. | |
1568 If the code being eval'd should happen to trigger a redisplay you may | |
1569 see some text temporarily disappear because of this. | |
1570 */ | |
444 | 1571 (start, end, stream)) |
428 | 1572 { |
1573 /* This function can GC */ | |
1574 int speccount = specpdl_depth (); | |
1575 Lisp_Object tem; | |
1576 Lisp_Object cbuf = Fcurrent_buffer (); | |
1577 | |
444 | 1578 if (NILP (stream)) |
428 | 1579 tem = Qsymbolp; /* #### #@[]*&$#*[& SI:NULL-STREAM */ |
1580 else | |
444 | 1581 tem = stream; |
428 | 1582 specbind (Qstandard_output, tem); |
1583 | |
444 | 1584 if (NILP (stream)) |
428 | 1585 record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
844 | 1586 record_unwind_protect (save_restriction_restore, |
1587 save_restriction_save (current_buffer)); | |
428 | 1588 |
444 | 1589 /* This both uses start and checks its type. */ |
1590 Fgoto_char (start, cbuf); | |
1591 Fnarrow_to_region (make_int (BUF_BEGV (current_buffer)), end, cbuf); | |
428 | 1592 readevalloop (cbuf, XBUFFER (cbuf)->filename, Feval, |
444 | 1593 !NILP (stream)); |
428 | 1594 |
771 | 1595 return unbind_to (speccount); |
428 | 1596 } |
1597 | |
1598 DEFUN ("read", Fread, 0, 1, 0, /* | |
1599 Read one Lisp expression as text from STREAM, return as Lisp object. | |
1600 If STREAM is nil, use the value of `standard-input' (which see). | |
1601 STREAM or the value of `standard-input' may be: | |
1602 a buffer (read from point and advance it) | |
1603 a marker (read from where it points and advance it) | |
1604 a function (call it with no arguments for each character, | |
1605 call it with a char as argument to push a char back) | |
1606 a string (takes text from string, starting at the beginning) | |
1607 t (read text line using minibuffer and use it). | |
1608 */ | |
1609 (stream)) | |
1610 { | |
1611 if (NILP (stream)) | |
1612 stream = Vstandard_input; | |
1613 if (EQ (stream, Qt)) | |
1614 stream = Qread_char; | |
1615 | |
1616 Vread_objects = Qnil; | |
1617 | |
1618 if (EQ (stream, Qread_char)) | |
1619 { | |
1620 Lisp_Object val = call1 (Qread_from_minibuffer, | |
771 | 1621 build_msg_string ("Lisp expression: ")); |
428 | 1622 return Fcar (Fread_from_string (val, Qnil, Qnil)); |
1623 } | |
1624 | |
1625 if (STRINGP (stream)) | |
1626 return Fcar (Fread_from_string (stream, Qnil, Qnil)); | |
1627 | |
1628 return read0 (stream); | |
1629 } | |
1630 | |
1631 DEFUN ("read-from-string", Fread_from_string, 1, 3, 0, /* | |
1632 Read one Lisp expression which is represented as text by STRING. | |
1633 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX). | |
1634 START and END optionally delimit a substring of STRING from which to read; | |
1635 they default to 0 and (length STRING) respectively. | |
1636 */ | |
1637 (string, start, end)) | |
1638 { | |
1639 Bytecount startval, endval; | |
1640 Lisp_Object tem; | |
1641 Lisp_Object lispstream = Qnil; | |
1642 struct gcpro gcpro1; | |
1643 | |
1644 GCPRO1 (lispstream); | |
1645 CHECK_STRING (string); | |
1646 get_string_range_byte (string, start, end, &startval, &endval, | |
1647 GB_HISTORICAL_STRING_BEHAVIOR); | |
1648 lispstream = make_lisp_string_input_stream (string, startval, | |
1649 endval - startval); | |
1650 | |
1651 Vread_objects = Qnil; | |
1652 | |
1653 tem = read0 (lispstream); | |
1654 /* Yeah, it's ugly. Gonna make something of it? | |
1655 At least our reader is reentrant ... */ | |
1656 tem = | |
1657 (Fcons (tem, make_int | |
793 | 1658 (string_index_byte_to_char |
771 | 1659 (string, |
428 | 1660 startval + Lstream_byte_count (XLSTREAM (lispstream)))))); |
1661 Lstream_delete (XLSTREAM (lispstream)); | |
1662 UNGCPRO; | |
1663 return tem; | |
1664 } | |
1665 | |
1666 | |
1667 | |
1668 /* Use this for recursive reads, in contexts where internal tokens | |
1669 are not allowed. See also read1(). */ | |
1670 static Lisp_Object | |
1671 read0 (Lisp_Object readcharfun) | |
1672 { | |
1673 Lisp_Object val = read1 (readcharfun); | |
1674 | |
1675 if (CONSP (val) && UNBOUNDP (XCAR (val))) | |
1676 { | |
867 | 1677 Ichar c = XCHAR (XCDR (val)); |
853 | 1678 free_cons (val); |
428 | 1679 return Fsignal (Qinvalid_read_syntax, |
1680 list1 (Fchar_to_string (make_char (c)))); | |
1681 } | |
1682 | |
1683 return val; | |
1684 } | |
3543 | 1685 |
1686 /* A Unicode escape, as in C# (though we only permit them in strings | |
1687 and characters, not arbitrarily in the source code.) */ | |
1688 static Ichar | |
1689 read_unicode_escape (Lisp_Object readcharfun, int unicode_hex_count) | |
1690 { | |
1691 REGISTER Ichar i = 0, c; | |
1692 REGISTER int count = 0; | |
1693 Lisp_Object lisp_char; | |
1694 while (++count <= unicode_hex_count) | |
1695 { | |
1696 c = readchar (readcharfun); | |
1697 /* Remember, can't use isdigit(), isalpha() etc. on Ichars */ | |
1698 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); | |
1699 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; | |
1700 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; | |
1701 else | |
1702 { | |
1703 syntax_error ("Non-hex digit used for Unicode escape", | |
1704 make_char (c)); | |
1705 break; | |
1706 } | |
1707 } | |
1708 | |
4268 | 1709 if (i >= 0x110000 || i < 0) |
4096 | 1710 { |
1711 syntax_error ("Not a Unicode code point", make_int(i)); | |
1712 } | |
1713 | |
3543 | 1714 lisp_char = Funicode_to_char(make_int(i), Qnil); |
1715 | |
1716 if (EQ(Qnil, lisp_char)) | |
1717 { | |
4096 | 1718 /* Will happen on non-Mule. Silent corruption is what happens |
1719 elsewhere, and we used to do that to be consistent, but GNU error, | |
1720 so people writing portable code need to be able to handle that, and | |
1721 given a choice I prefer that behaviour. | |
1722 | |
1723 An undesirable aspect to this error is that the code point is shown | |
1724 as a decimal integer, which is mostly unreadable. */ | |
1725 syntax_error ("Unsupported Unicode code point", make_int(i)); | |
3543 | 1726 } |
4096 | 1727 |
1728 return XCHAR(lisp_char); | |
3543 | 1729 } |
1730 | |
428 | 1731 |
867 | 1732 static Ichar |
428 | 1733 read_escape (Lisp_Object readcharfun) |
1734 { | |
1735 /* This function can GC */ | |
867 | 1736 Ichar c = readchar (readcharfun); |
428 | 1737 |
1738 if (c < 0) | |
563 | 1739 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1740 |
1741 switch (c) | |
1742 { | |
1743 case 'a': return '\007'; | |
1744 case 'b': return '\b'; | |
1745 case 'd': return 0177; | |
1746 case 'e': return 033; | |
1747 case 'f': return '\f'; | |
1748 case 'n': return '\n'; | |
1749 case 'r': return '\r'; | |
1750 case 't': return '\t'; | |
1751 case 'v': return '\v'; | |
1752 case '\n': return -1; | |
1753 | |
1754 case 'M': | |
1755 c = readchar (readcharfun); | |
1756 if (c < 0) | |
563 | 1757 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1758 if (c != '-') |
563 | 1759 syntax_error ("Invalid escape character syntax", Qunbound); |
428 | 1760 c = readchar (readcharfun); |
1761 if (c < 0) | |
563 | 1762 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1763 if (c == '\\') |
1764 c = read_escape (readcharfun); | |
1765 return c | 0200; | |
1766 | |
1767 /* Originally, FSF_KEYS provided a degree of FSF Emacs | |
1768 compatibility by defining character "modifiers" alt, super, | |
1769 hyper and shift to infest the characters (i.e. integers). | |
1770 | |
1771 However, this doesn't cut it for XEmacs 20, which | |
1772 distinguishes characters from integers. Without Mule, ?\H-a | |
1773 simply returns ?a because every character is clipped into | |
1774 0-255. Under Mule it is much worse -- ?\H-a with FSF_KEYS | |
1775 produces an illegal character, and moves us to crash-land. | |
1776 | |
1777 For these reasons, FSF_KEYS hack is useless and without hope | |
1778 of ever working under XEmacs 20. */ | |
1779 #ifdef FSF_KEYS | |
831 | 1780 /* Deleted */ |
1781 #endif | |
428 | 1782 |
1783 case 'C': | |
1784 c = readchar (readcharfun); | |
1785 if (c < 0) | |
563 | 1786 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1787 if (c != '-') |
563 | 1788 syntax_error ("Invalid escape character syntax", Qunbound); |
428 | 1789 case '^': |
1790 c = readchar (readcharfun); | |
1791 if (c < 0) | |
563 | 1792 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1793 if (c == '\\') |
1794 c = read_escape (readcharfun); | |
1795 /* FSFmacs junk for non-ASCII controls. | |
1796 Not used here. */ | |
1797 if (c == '?') | |
1798 return 0177; | |
1799 else | |
1800 return c & (0200 | 037); | |
1801 | |
1802 case '0': | |
1803 case '1': | |
1804 case '2': | |
1805 case '3': | |
1806 case '4': | |
1807 case '5': | |
1808 case '6': | |
1809 case '7': | |
1810 /* An octal escape, as in ANSI C. */ | |
1811 { | |
867 | 1812 REGISTER Ichar i = c - '0'; |
428 | 1813 REGISTER int count = 0; |
1814 while (++count < 3) | |
1815 { | |
1816 if ((c = readchar (readcharfun)) >= '0' && c <= '7') | |
1817 i = (i << 3) + (c - '0'); | |
1818 else | |
1819 { | |
1820 unreadchar (readcharfun, c); | |
1821 break; | |
1822 } | |
1823 } | |
831 | 1824 if (i >= 0400) |
3367 | 1825 syntax_error ("Non-ISO-8859-1 character specified with octal escape", |
831 | 1826 make_int (i)); |
428 | 1827 return i; |
1828 } | |
1829 | |
1830 case 'x': | |
1831 /* A hex escape, as in ANSI C, except that we only allow latin-1 | |
1832 characters to be read this way. What is "\x4e03" supposed to | |
1833 mean, anyways, if the internal representation is hidden? | |
1834 This is also consistent with the treatment of octal escapes. */ | |
1835 { | |
867 | 1836 REGISTER Ichar i = 0; |
428 | 1837 REGISTER int count = 0; |
1838 while (++count <= 2) | |
1839 { | |
1840 c = readchar (readcharfun); | |
867 | 1841 /* Remember, can't use isdigit(), isalpha() etc. on Ichars */ |
428 | 1842 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); |
1843 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; | |
1844 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; | |
1845 else | |
1846 { | |
1847 unreadchar (readcharfun, c); | |
1848 break; | |
1849 } | |
1850 } | |
4483
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1851 |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1852 if (count == 3) |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1853 { |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1854 c = readchar (readcharfun); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1855 if ((c >= '0' && c <= '9') || |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1856 (c >= 'a' && c <= 'f') || |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1857 (c >= 'A' && c <= 'F')) |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1858 { |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1859 Lisp_Object args[2]; |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1860 |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1861 if (c >= '0' && c <= '9') i = (i << 4) + (c - '0'); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1862 else if (c >= 'a' && c <= 'f') i = (i << 4) + (c - 'a') + 10; |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1863 else if (c >= 'A' && c <= 'F') i = (i << 4) + (c - 'A') + 10; |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1864 |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
1865 args[0] = build_ascstring ("?\\x%x"); |
4483
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1866 args[1] = make_int (i); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1867 syntax_error ("Overlong hex character escape", |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1868 Fformat (2, args)); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1869 } |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1870 unreadchar (readcharfun, c); |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1871 } |
7869173584fc
Error on over-long hex character escapes.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4450
diff
changeset
|
1872 |
428 | 1873 return i; |
1874 } | |
3367 | 1875 case 'U': |
1876 /* Post-Unicode-2.0: Up to eight hex chars */ | |
3543 | 1877 return read_unicode_escape(readcharfun, 8); |
3367 | 1878 case 'u': |
3543 | 1879 /* Unicode-2.0 and before; four hex chars. */ |
1880 return read_unicode_escape(readcharfun, 4); | |
428 | 1881 |
1882 default: | |
1883 return c; | |
1884 } | |
1885 } | |
1886 | |
1887 | |
1888 | |
1889 /* read symbol-constituent stuff into `Vread_buffer_stream'. */ | |
1890 static Bytecount | |
867 | 1891 read_atom_0 (Lisp_Object readcharfun, Ichar firstchar, int *saw_a_backslash) |
428 | 1892 { |
1893 /* This function can GC */ | |
867 | 1894 Ichar c = ((firstchar) >= 0 ? firstchar : readchar (readcharfun)); |
428 | 1895 Lstream_rewind (XLSTREAM (Vread_buffer_stream)); |
1896 | |
1897 *saw_a_backslash = 0; | |
1898 | |
1899 while (c > 040 /* #### - comma should be here as should backquote */ | |
1900 && !(c == '\"' || c == '\'' || c == ';' | |
1901 || c == '(' || c == ')' | |
1902 || c == '[' || c == ']' || c == '#' | |
1903 )) | |
1904 { | |
1905 if (c == '\\') | |
1906 { | |
1907 c = readchar (readcharfun); | |
1908 if (c < 0) | |
563 | 1909 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 1910 *saw_a_backslash = 1; |
1911 } | |
867 | 1912 Lstream_put_ichar (XLSTREAM (Vread_buffer_stream), c); |
428 | 1913 QUIT; |
1914 c = readchar (readcharfun); | |
1915 } | |
1916 | |
1917 if (c >= 0) | |
1918 unreadchar (readcharfun, c); | |
1919 /* blasted terminating 0 */ | |
867 | 1920 Lstream_put_ichar (XLSTREAM (Vread_buffer_stream), 0); |
428 | 1921 Lstream_flush (XLSTREAM (Vread_buffer_stream)); |
1922 | |
1923 return Lstream_byte_count (XLSTREAM (Vread_buffer_stream)) - 1; | |
1924 } | |
1925 | |
867 | 1926 static Lisp_Object parse_integer (const Ibyte *buf, Bytecount len, int base); |
428 | 1927 |
1928 static Lisp_Object | |
1929 read_atom (Lisp_Object readcharfun, | |
867 | 1930 Ichar firstchar, |
428 | 1931 int uninterned_symbol) |
1932 { | |
1933 /* This function can GC */ | |
1934 int saw_a_backslash; | |
1935 Bytecount len = read_atom_0 (readcharfun, firstchar, &saw_a_backslash); | |
1936 char *read_ptr = (char *) | |
1937 resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)); | |
1938 | |
1939 /* Is it an integer? */ | |
1940 if (! (saw_a_backslash || uninterned_symbol)) | |
1941 { | |
1942 /* If a token had any backslashes in it, it is disqualified from | |
1943 being an integer or a float. This means that 123\456 is a | |
1944 symbol, as is \123 (which is the way (intern "123") prints). | |
1945 Also, if token was preceded by #:, it's always a symbol. | |
1946 */ | |
1947 char *p = read_ptr + len; | |
1948 char *p1 = read_ptr; | |
1949 | |
1950 if (*p1 == '+' || *p1 == '-') p1++; | |
1951 if (p1 != p) | |
1952 { | |
1953 int c; | |
1954 | |
1955 while (p1 != p && (c = *p1) >= '0' && c <= '9') | |
1956 p1++; | |
1957 /* Integers can have trailing decimal points. */ | |
1958 if (p1 > read_ptr && p1 < p && *p1 == '.') | |
1959 p1++; | |
1960 if (p1 == p) | |
1961 { | |
1962 /* It is an integer. */ | |
1963 if (p1[-1] == '.') | |
1964 p1[-1] = '\0'; | |
1965 #if 0 | |
1966 { | |
1967 int number = 0; | |
1968 if (sizeof (int) == sizeof (EMACS_INT)) | |
1969 number = atoi (read_buffer); | |
1970 else if (sizeof (long) == sizeof (EMACS_INT)) | |
1971 number = atol (read_buffer); | |
1972 else | |
2500 | 1973 ABORT (); |
428 | 1974 return make_int (number); |
1975 } | |
1976 #else | |
867 | 1977 return parse_integer ((Ibyte *) read_ptr, len, 10); |
428 | 1978 #endif |
1979 } | |
1980 } | |
1983 | 1981 #ifdef HAVE_RATIO |
1982 if (isratio_string (read_ptr)) | |
1983 { | |
2013 | 1984 /* GMP ratio_set_string has no effect with initial + sign */ |
2010 | 1985 if (*read_ptr == '+') |
1986 read_ptr++; | |
1983 | 1987 ratio_set_string (scratch_ratio, read_ptr, 0); |
5088
207dad9e74f7
Signal an error upon reading 1/0.
Jerry James <james@xemacs.org>
parents:
5016
diff
changeset
|
1988 if (bignum_sign (ratio_denominator (scratch_ratio)) != 0) { |
207dad9e74f7
Signal an error upon reading 1/0.
Jerry James <james@xemacs.org>
parents:
5016
diff
changeset
|
1989 ratio_canonicalize (scratch_ratio); |
207dad9e74f7
Signal an error upon reading 1/0.
Jerry James <james@xemacs.org>
parents:
5016
diff
changeset
|
1990 return Fcanonicalize_number (make_ratio_rt (scratch_ratio)); |
207dad9e74f7
Signal an error upon reading 1/0.
Jerry James <james@xemacs.org>
parents:
5016
diff
changeset
|
1991 } |
207dad9e74f7
Signal an error upon reading 1/0.
Jerry James <james@xemacs.org>
parents:
5016
diff
changeset
|
1992 return Fsignal (Qinvalid_read_syntax, |
207dad9e74f7
Signal an error upon reading 1/0.
Jerry James <james@xemacs.org>
parents:
5016
diff
changeset
|
1993 list2 (build_msg_string |
207dad9e74f7
Signal an error upon reading 1/0.
Jerry James <james@xemacs.org>
parents:
5016
diff
changeset
|
1994 ("Invalid ratio constant in reader"), |
207dad9e74f7
Signal an error upon reading 1/0.
Jerry James <james@xemacs.org>
parents:
5016
diff
changeset
|
1995 make_string ((Ibyte *) read_ptr, len))); |
1983 | 1996 } |
1997 #endif | |
428 | 1998 if (isfloat_string (read_ptr)) |
1999 return make_float (atof (read_ptr)); | |
2000 } | |
2001 | |
2002 { | |
2003 Lisp_Object sym; | |
2004 if (uninterned_symbol) | |
867 | 2005 sym = Fmake_symbol ( make_string ((Ibyte *) read_ptr, len)); |
428 | 2006 else |
2007 { | |
867 | 2008 Lisp_Object name = make_string ((Ibyte *) read_ptr, len); |
428 | 2009 sym = Fintern (name, Qnil); |
2010 } | |
2011 return sym; | |
2012 } | |
2013 } | |
2014 | |
2015 | |
2016 static Lisp_Object | |
867 | 2017 parse_integer (const Ibyte *buf, Bytecount len, int base) |
428 | 2018 { |
867 | 2019 const Ibyte *lim = buf + len; |
2020 const Ibyte *p = buf; | |
428 | 2021 EMACS_UINT num = 0; |
2022 int negativland = 0; | |
2023 | |
2024 if (*p == '-') | |
2025 { | |
2026 negativland = 1; | |
2027 p++; | |
2028 } | |
2029 else if (*p == '+') | |
2030 { | |
2031 p++; | |
2032 } | |
2033 | |
2034 if (p == lim) | |
2035 goto loser; | |
2036 | |
2037 for (; (p < lim) && (*p != '\0'); p++) | |
2038 { | |
2039 int c = *p; | |
2040 EMACS_UINT onum; | |
2041 | |
2042 if (isdigit (c)) | |
2043 c = c - '0'; | |
2044 else if (isupper (c)) | |
2045 c = c - 'A' + 10; | |
2046 else if (islower (c)) | |
2047 c = c - 'a' + 10; | |
2048 else | |
2049 goto loser; | |
2050 | |
2051 if (c < 0 || c >= base) | |
2052 goto loser; | |
2053 | |
2054 onum = num; | |
2055 num = num * base + c; | |
2056 if (num < onum) | |
2057 goto overflow; | |
2058 } | |
2059 | |
2060 { | |
2061 EMACS_INT int_result = negativland ? - (EMACS_INT) num : (EMACS_INT) num; | |
2062 Lisp_Object result = make_int (int_result); | |
2063 if (num && ((XINT (result) < 0) != negativland)) | |
2064 goto overflow; | |
2065 if (XINT (result) != int_result) | |
2066 goto overflow; | |
2067 return result; | |
2068 } | |
2069 overflow: | |
1983 | 2070 #ifdef HAVE_BIGNUM |
2071 { | |
4329
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4268
diff
changeset
|
2072 bignum_set_string (scratch_bignum, (const char *) buf, base); |
1983 | 2073 return make_bignum_bg (scratch_bignum); |
2074 } | |
2075 #else | |
428 | 2076 return Fsignal (Qinvalid_read_syntax, |
771 | 2077 list3 (build_msg_string |
428 | 2078 ("Integer constant overflow in reader"), |
2079 make_string (buf, len), | |
2080 make_int (base))); | |
1983 | 2081 #endif /* HAVE_BIGNUM */ |
428 | 2082 loser: |
2083 return Fsignal (Qinvalid_read_syntax, | |
771 | 2084 list3 (build_msg_string |
428 | 2085 ("Invalid integer constant in reader"), |
2086 make_string (buf, len), | |
2087 make_int (base))); | |
2088 } | |
2089 | |
2090 | |
2091 static Lisp_Object | |
2092 read_integer (Lisp_Object readcharfun, int base) | |
2093 { | |
2094 /* This function can GC */ | |
2095 int saw_a_backslash; | |
2096 Bytecount len = read_atom_0 (readcharfun, -1, &saw_a_backslash); | |
2097 return (parse_integer | |
2098 (resizing_buffer_stream_ptr (XLSTREAM (Vread_buffer_stream)), | |
2099 ((saw_a_backslash) | |
2100 ? 0 /* make parse_integer signal error */ | |
2101 : len), | |
2102 base)); | |
2103 } | |
2104 | |
2105 static Lisp_Object | |
2106 read_bit_vector (Lisp_Object readcharfun) | |
2107 { | |
2108 unsigned_char_dynarr *dyn = Dynarr_new (unsigned_char); | |
440 | 2109 Lisp_Object val; |
428 | 2110 |
2111 while (1) | |
2112 { | |
444 | 2113 unsigned char bit; |
867 | 2114 Ichar c = readchar (readcharfun); |
444 | 2115 if (c == '0') |
2116 bit = 0; | |
2117 else if (c == '1') | |
2118 bit = 1; | |
2119 else | |
2120 { | |
2121 if (c >= 0) | |
2122 unreadchar (readcharfun, c); | |
2123 break; | |
2124 } | |
2125 Dynarr_add (dyn, bit); | |
428 | 2126 } |
2127 | |
4967 | 2128 val = make_bit_vector_from_byte_vector (Dynarr_begin (dyn), |
440 | 2129 Dynarr_length (dyn)); |
2130 Dynarr_free (dyn); | |
2131 | |
2132 return val; | |
428 | 2133 } |
2134 | |
2135 | |
2136 | |
2137 /* structures */ | |
2138 | |
2139 struct structure_type * | |
2140 define_structure_type (Lisp_Object type, | |
2141 int (*validate) (Lisp_Object data, | |
578 | 2142 Error_Behavior errb), |
428 | 2143 Lisp_Object (*instantiate) (Lisp_Object data)) |
2144 { | |
2145 struct structure_type st; | |
2146 | |
2147 st.type = type; | |
2148 st.keywords = Dynarr_new (structure_keyword_entry); | |
2149 st.validate = validate; | |
2150 st.instantiate = instantiate; | |
2151 Dynarr_add (the_structure_type_dynarr, st); | |
2152 | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4677
diff
changeset
|
2153 return Dynarr_lastp (the_structure_type_dynarr); |
428 | 2154 } |
2155 | |
2156 void | |
2157 define_structure_type_keyword (struct structure_type *st, Lisp_Object keyword, | |
2158 int (*validate) (Lisp_Object keyword, | |
2159 Lisp_Object value, | |
578 | 2160 Error_Behavior errb)) |
428 | 2161 { |
2162 struct structure_keyword_entry en; | |
2163 | |
2164 en.keyword = keyword; | |
2165 en.validate = validate; | |
2166 Dynarr_add (st->keywords, en); | |
2167 } | |
2168 | |
2169 static struct structure_type * | |
2170 recognized_structure_type (Lisp_Object type) | |
2171 { | |
2172 int i; | |
2173 | |
2174 for (i = 0; i < Dynarr_length (the_structure_type_dynarr); i++) | |
2175 { | |
2176 struct structure_type *st = Dynarr_atp (the_structure_type_dynarr, i); | |
2177 if (EQ (st->type, type)) | |
2178 return st; | |
2179 } | |
2180 | |
2181 return 0; | |
2182 } | |
2183 | |
2184 static Lisp_Object | |
2185 read_structure (Lisp_Object readcharfun) | |
2186 { | |
867 | 2187 Ichar c = readchar (readcharfun); |
428 | 2188 Lisp_Object list = Qnil; |
2189 Lisp_Object orig_list = Qnil; | |
2190 Lisp_Object already_seen = Qnil; | |
2191 int keyword_count; | |
2192 struct structure_type *st; | |
2193 struct gcpro gcpro1, gcpro2; | |
2194 | |
2195 GCPRO2 (orig_list, already_seen); | |
2196 if (c != '(') | |
442 | 2197 RETURN_UNGCPRO (continuable_read_syntax_error ("#s not followed by paren")); |
428 | 2198 list = read_list (readcharfun, ')', 0, 0); |
2199 orig_list = list; | |
2200 { | |
2201 int len = XINT (Flength (list)); | |
2202 if (len == 0) | |
442 | 2203 RETURN_UNGCPRO (continuable_read_syntax_error |
428 | 2204 ("structure type not specified")); |
2205 if (!(len & 1)) | |
2206 RETURN_UNGCPRO | |
442 | 2207 (continuable_read_syntax_error |
428 | 2208 ("structures must have alternating keyword/value pairs")); |
2209 } | |
2210 | |
2211 st = recognized_structure_type (XCAR (list)); | |
2212 if (!st) | |
2213 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2214 list2 (build_msg_string |
428 | 2215 ("unrecognized structure type"), |
2216 XCAR (list)))); | |
2217 | |
2218 list = Fcdr (list); | |
2219 keyword_count = Dynarr_length (st->keywords); | |
2220 while (!NILP (list)) | |
2221 { | |
2222 Lisp_Object keyword, value; | |
2223 int i; | |
2224 struct structure_keyword_entry *en = NULL; | |
2225 | |
2226 keyword = Fcar (list); | |
2227 list = Fcdr (list); | |
2228 value = Fcar (list); | |
2229 list = Fcdr (list); | |
2230 | |
2231 if (!NILP (memq_no_quit (keyword, already_seen))) | |
2232 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2233 list2 (build_msg_string |
428 | 2234 ("structure keyword already seen"), |
2235 keyword))); | |
2236 | |
2237 for (i = 0; i < keyword_count; i++) | |
2238 { | |
2239 en = Dynarr_atp (st->keywords, i); | |
2240 if (EQ (keyword, en->keyword)) | |
2241 break; | |
2242 } | |
2243 | |
2244 if (i == keyword_count) | |
2245 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2246 list2 (build_msg_string |
428 | 2247 ("unrecognized structure keyword"), |
2248 keyword))); | |
2249 | |
2250 if (en->validate && ! (en->validate) (keyword, value, ERROR_ME)) | |
2251 RETURN_UNGCPRO | |
2252 (Fsignal (Qinvalid_read_syntax, | |
771 | 2253 list3 (build_msg_string |
428 | 2254 ("invalid value for structure keyword"), |
2255 keyword, value))); | |
2256 | |
2257 already_seen = Fcons (keyword, already_seen); | |
2258 } | |
2259 | |
2260 if (st->validate && ! (st->validate) (orig_list, ERROR_ME)) | |
2261 RETURN_UNGCPRO (Fsignal (Qinvalid_read_syntax, | |
771 | 2262 list2 (build_msg_string |
428 | 2263 ("invalid structure initializer"), |
2264 orig_list))); | |
2265 | |
2266 RETURN_UNGCPRO ((st->instantiate) (XCDR (orig_list))); | |
2267 } | |
2268 | |
2269 | |
2270 static Lisp_Object read_compiled_function (Lisp_Object readcharfun, | |
2271 int terminator); | |
2272 static Lisp_Object read_vector (Lisp_Object readcharfun, int terminator); | |
2273 | |
2274 /* Get the next character; filter out whitespace and comments */ | |
2275 | |
867 | 2276 static Ichar |
428 | 2277 reader_nextchar (Lisp_Object readcharfun) |
2278 { | |
2279 /* This function can GC */ | |
867 | 2280 Ichar c; |
428 | 2281 |
2282 retry: | |
2283 QUIT; | |
2284 c = readchar (readcharfun); | |
2285 if (c < 0) | |
563 | 2286 signal_error (Qend_of_file, 0, READCHARFUN_MAYBE (readcharfun)); |
428 | 2287 |
2288 switch (c) | |
2289 { | |
2290 default: | |
2291 { | |
2292 /* Ignore whitespace and control characters */ | |
2293 if (c <= 040) | |
2294 goto retry; | |
2295 return c; | |
2296 } | |
2297 | |
2298 case ';': | |
2299 { | |
2300 /* Comment */ | |
2301 while ((c = readchar (readcharfun)) >= 0 && c != '\n') | |
2302 QUIT; | |
2303 goto retry; | |
2304 } | |
2305 } | |
2306 } | |
2307 | |
2308 #if 0 | |
2309 static Lisp_Object | |
2310 list2_pure (int pure, Lisp_Object a, Lisp_Object b) | |
2311 { | |
2312 return pure ? pure_cons (a, pure_cons (b, Qnil)) : list2 (a, b); | |
2313 } | |
2314 #endif | |
2315 | |
3543 | 2316 static Lisp_Object |
2317 read_string (Lisp_Object readcharfun, Ichar delim, int raw, | |
2318 int honor_unicode) | |
2319 { | |
2320 #ifdef I18N3 | |
2321 /* #### If the input stream is translating, then the string | |
2322 should be marked as translatable by setting its | |
2323 `string-translatable' property to t. .el and .elc files | |
2324 normally are translating input streams. See Fgettext() | |
2325 and print_internal(). */ | |
2326 #endif | |
2327 Ichar c; | |
2328 int cancel = 0; | |
2329 | |
2330 Lstream_rewind(XLSTREAM(Vread_buffer_stream)); | |
2331 while ((c = readchar(readcharfun)) >= 0 && c != delim) | |
2332 { | |
2333 if (c == '\\') | |
2334 { | |
2335 if (raw) | |
2336 { | |
2337 c = readchar(readcharfun); | |
2338 if (honor_unicode && ('u' == c || 'U' == c)) | |
2339 { | |
2340 c = read_unicode_escape(readcharfun, | |
2341 'U' == c ? 8 : 4); | |
2342 } | |
2343 else | |
2344 { | |
2345 /* For raw strings, insert the | |
2346 backslash and the next char, */ | |
2347 Lstream_put_ichar(XLSTREAM | |
2348 (Vread_buffer_stream), | |
2349 '\\'); | |
2350 } | |
2351 } | |
2352 else | |
2353 /* otherwise, backslash escapes the next char. */ | |
2354 c = read_escape(readcharfun); | |
2355 } | |
2356 /* c is -1 if \ newline has just been seen */ | |
2357 if (c == -1) | |
2358 { | |
2359 if (Lstream_byte_count | |
2360 (XLSTREAM(Vread_buffer_stream)) == | |
2361 0) | |
2362 cancel = 1; | |
2363 } | |
2364 else | |
2365 Lstream_put_ichar(XLSTREAM | |
2366 (Vread_buffer_stream), | |
2367 c); | |
2368 QUIT; | |
2369 } | |
2370 if (c < 0) | |
2371 return Fsignal(Qend_of_file, | |
2372 list1(READCHARFUN_MAYBE(readcharfun))); | |
2373 | |
2374 /* If purifying, and string starts with \ newline, | |
2375 return zero instead. This is for doc strings | |
2376 that we are really going to find in lib-src/DOC.nn.nn */ | |
2377 if (purify_flag && NILP(Vinternal_doc_file_name) | |
2378 && cancel) | |
2379 return Qzero; | |
2380 | |
2381 Lstream_flush(XLSTREAM(Vread_buffer_stream)); | |
2382 return make_string(resizing_buffer_stream_ptr | |
2383 (XLSTREAM(Vread_buffer_stream)), | |
2384 Lstream_byte_count(XLSTREAM(Vread_buffer_stream))); | |
2385 } | |
2386 | |
2387 static Lisp_Object | |
2388 read_raw_string (Lisp_Object readcharfun) | |
2389 { | |
2390 Ichar c; | |
2391 Ichar permit_unicode = 0; | |
2392 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2393 do |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2394 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2395 c = reader_nextchar (readcharfun); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2396 switch (c) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2397 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2398 /* #r:engine"my sexy raw string" -- raw string w/ flags*/ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2399 /* case ':': */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2400 /* #ru"Hi there\u20AC \U000020AC" -- raw string, honouring Unicode. */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2401 case 'u': |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2402 case 'U': |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2403 permit_unicode = c; |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2404 continue; |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2405 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2406 /* #r"my raw string" -- raw string */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2407 case '\"': |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2408 return read_string (readcharfun, '\"', 1, permit_unicode); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2409 /* invalid syntax */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2410 default: |
3543 | 2411 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2412 if (permit_unicode) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2413 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2414 unreadchar (readcharfun, permit_unicode); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2415 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2416 unreadchar (readcharfun, c); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2417 return Fsignal (Qinvalid_read_syntax, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2418 list1 (build_msg_string |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2419 ("unrecognized raw string syntax"))); |
3543 | 2420 } |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2421 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2422 } while (1); |
3543 | 2423 } |
2424 | |
428 | 2425 /* Read the next Lisp object from the stream READCHARFUN and return it. |
2426 If the return value is a cons whose car is Qunbound, then read1() | |
2427 encountered a misplaced token (e.g. a right bracket, right paren, | |
2428 or dot followed by a non-number). To filter this stuff out, | |
2429 use read0(). */ | |
2430 | |
2431 static Lisp_Object | |
2432 read1 (Lisp_Object readcharfun) | |
2433 { | |
867 | 2434 Ichar c; |
428 | 2435 |
2436 retry: | |
2437 c = reader_nextchar (readcharfun); | |
2438 | |
2439 switch (c) | |
2440 { | |
2441 case '(': | |
2442 { | |
2443 #ifdef LISP_BACKQUOTES /* old backquote compatibility in lisp reader */ | |
2444 /* if this is disabled, then other code in eval.c must be enabled */ | |
867 | 2445 Ichar ch = reader_nextchar (readcharfun); |
428 | 2446 switch (ch) |
2447 { | |
2448 case '`': | |
2449 { | |
2450 Lisp_Object tem; | |
853 | 2451 int speccount = internal_bind_int (&old_backquote_flag, |
2452 1 + old_backquote_flag); | |
428 | 2453 tem = read0 (readcharfun); |
771 | 2454 unbind_to (speccount); |
428 | 2455 ch = reader_nextchar (readcharfun); |
2456 if (ch != ')') | |
2457 { | |
2458 unreadchar (readcharfun, ch); | |
2459 return Fsignal (Qinvalid_read_syntax, | |
771 | 2460 list1 (build_msg_string |
428 | 2461 ("Weird old-backquote syntax"))); |
2462 } | |
2463 return list2 (Qbacktick, tem); | |
2464 } | |
2465 case ',': | |
2466 { | |
2467 if (old_backquote_flag) | |
2468 { | |
2469 Lisp_Object tem, comma_type; | |
2470 ch = readchar (readcharfun); | |
2471 if (ch == '@') | |
2472 comma_type = Qcomma_at; | |
2473 else | |
2474 { | |
2475 if (ch >= 0) | |
2476 unreadchar (readcharfun, ch); | |
2477 comma_type = Qcomma; | |
2478 } | |
2479 tem = read0 (readcharfun); | |
2480 ch = reader_nextchar (readcharfun); | |
2481 if (ch != ')') | |
2482 { | |
2483 unreadchar (readcharfun, ch); | |
2484 return Fsignal (Qinvalid_read_syntax, | |
771 | 2485 list1 (build_msg_string |
428 | 2486 ("Weird old-backquote syntax"))); |
2487 } | |
2488 return list2 (comma_type, tem); | |
2489 } | |
2490 else | |
2491 { | |
2492 unreadchar (readcharfun, ch); | |
2493 #if 0 | |
2494 return Fsignal (Qinvalid_read_syntax, | |
771 | 2495 list1 (build_msg_string ("Comma outside of backquote"))); |
428 | 2496 #else |
2497 /* #### - yuck....but this is reverse compatible. */ | |
2498 /* mostly this is required by edebug, which does its own | |
2499 annotated reading. We need to have an annotated_read | |
2500 function that records (with markers) the buffer | |
2501 positions of the elements that make up lists, then that | |
2502 can be used in edebug and bytecomp and the check above | |
2503 can go back in. --Stig */ | |
2504 break; | |
2505 #endif | |
2506 } | |
2507 } | |
2508 default: | |
2509 unreadchar (readcharfun, ch); | |
2510 } /* switch(ch) */ | |
2511 #endif /* old backquote crap... */ | |
2512 return read_list (readcharfun, ')', 1, 1); | |
2513 } | |
2514 case '[': | |
2515 return read_vector (readcharfun, ']'); | |
2516 | |
2517 case ')': | |
2518 case ']': | |
2519 /* #### - huh? these don't do what they seem... */ | |
2520 return noseeum_cons (Qunbound, make_char (c)); | |
2521 case '.': | |
2522 { | |
2523 /* If a period is followed by a number, then we should read it | |
2524 as a floating point number. Otherwise, it denotes a dotted | |
2525 pair. | |
2526 */ | |
2527 c = readchar (readcharfun); | |
2528 unreadchar (readcharfun, c); | |
2529 | |
867 | 2530 /* Can't use isdigit on Ichars */ |
428 | 2531 if (c < '0' || c > '9') |
2532 return noseeum_cons (Qunbound, make_char ('.')); | |
2533 | |
2534 /* Note that read_atom will loop | |
2535 at least once, assuring that we will not try to UNREAD | |
2536 two characters in a row. | |
2537 (I think this doesn't matter anymore because there should | |
2538 be no more danger in unreading multiple characters) */ | |
2539 return read_atom (readcharfun, '.', 0); | |
2540 } | |
2541 | |
2542 case '#': | |
2543 { | |
2544 c = readchar (readcharfun); | |
2545 switch (c) | |
2546 { | |
2547 #if 0 /* FSFmacs silly char-table syntax */ | |
2548 case '^': | |
2549 #endif | |
2550 #if 0 /* FSFmacs silly bool-vector syntax */ | |
2551 case '&': | |
2552 #endif | |
2553 /* "#["-- byte-code constant syntax */ | |
2554 /* purecons #[...] syntax */ | |
2555 case '[': return read_compiled_function (readcharfun, ']' | |
2556 /*, purify_flag */ ); | |
2557 /* "#:"-- gensym syntax */ | |
2558 case ':': return read_atom (readcharfun, -1, 1); | |
2559 /* #'x => (function x) */ | |
2560 case '\'': return list2 (Qfunction, read0 (readcharfun)); | |
2561 #if 0 | |
2562 /* RMS uses this syntax for fat-strings. | |
2563 If we use it for vectors, then obscure bugs happen. | |
2564 */ | |
2565 /* "#(" -- Scheme/CL vector syntax */ | |
2566 case '(': return read_vector (readcharfun, ')'); | |
2567 #endif | |
2568 #if 0 /* FSFmacs */ | |
2569 case '(': | |
2570 { | |
2571 Lisp_Object tmp; | |
2572 struct gcpro gcpro1; | |
2573 | |
2574 /* Read the string itself. */ | |
2575 tmp = read1 (readcharfun); | |
2576 if (!STRINGP (tmp)) | |
2577 { | |
2578 if (CONSP (tmp) && UNBOUNDP (XCAR (tmp))) | |
853 | 2579 free_cons (tmp); |
428 | 2580 return Fsignal (Qinvalid_read_syntax, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2581 list1 (build_ascstring ("#"))); |
428 | 2582 } |
2583 GCPRO1 (tmp); | |
2584 /* Read the intervals and their properties. */ | |
2585 while (1) | |
2586 { | |
2587 Lisp_Object beg, end, plist; | |
867 | 2588 Ichar ch; |
428 | 2589 int invalid = 0; |
2590 | |
2591 beg = read1 (readcharfun); | |
2592 if (CONSP (beg) && UNBOUNDP (XCAR (beg))) | |
2593 { | |
2594 ch = XCHAR (XCDR (beg)); | |
853 | 2595 free_cons (beg); |
428 | 2596 if (ch == ')') |
2597 break; | |
2598 else | |
2599 invalid = 1; | |
2600 } | |
2601 if (!invalid) | |
2602 { | |
2603 end = read1 (readcharfun); | |
2604 if (CONSP (end) && UNBOUNDP (XCAR (end))) | |
2605 { | |
853 | 2606 free_cons (end); |
428 | 2607 invalid = 1; |
2608 } | |
2609 } | |
2610 if (!invalid) | |
2611 { | |
2612 plist = read1 (readcharfun); | |
2613 if (CONSP (plist) && UNBOUNDP (XCAR (plist))) | |
2614 { | |
853 | 2615 free_cons (plist); |
428 | 2616 invalid = 1; |
2617 } | |
2618 } | |
2619 if (invalid) | |
2620 RETURN_UNGCPRO | |
2621 (Fsignal (Qinvalid_read_syntax, | |
2622 list2 | |
771 | 2623 (build_msg_string ("invalid string property list"), |
428 | 2624 XCDR (plist)))); |
2625 Fset_text_properties (beg, end, plist, tmp); | |
2626 } | |
2627 UNGCPRO; | |
2628 return tmp; | |
2629 } | |
2630 #endif /* 0 */ | |
2631 case '@': | |
2632 { | |
2633 /* #@NUMBER is used to skip NUMBER following characters. | |
2634 That's used in .elc files to skip over doc strings | |
2635 and function definitions. */ | |
2636 int i, nskip = 0; | |
2637 | |
2638 /* Read a decimal integer. */ | |
2639 while ((c = readchar (readcharfun)) >= 0 | |
2640 && c >= '0' && c <= '9') | |
2641 nskip = (10 * nskip) + (c - '0'); | |
2642 if (c >= 0) | |
2643 unreadchar (readcharfun, c); | |
2644 | |
2645 /* FSF has code here that maybe caches the skipped | |
2646 string. See above for why this is totally | |
2647 losing. We handle this differently. */ | |
2648 | |
2649 /* Skip that many characters. */ | |
2650 for (i = 0; i < nskip && c >= 0; i++) | |
2651 c = readchar (readcharfun); | |
2652 | |
2653 goto retry; | |
2654 } | |
2655 case '$': return Vload_file_name_internal; | |
2656 /* bit vectors */ | |
2657 case '*': return read_bit_vector (readcharfun); | |
2658 /* #o10 => 8 -- octal constant syntax */ | |
2659 case 'o': return read_integer (readcharfun, 8); | |
2660 /* #xdead => 57005 -- hex constant syntax */ | |
2661 case 'x': return read_integer (readcharfun, 16); | |
2662 /* #b010 => 2 -- binary constant syntax */ | |
2663 case 'b': return read_integer (readcharfun, 2); | |
3543 | 2664 /* #r"raw\stringt" -- raw string syntax */ |
2665 case 'r': return read_raw_string(readcharfun); | |
428 | 2666 /* #s(foobar key1 val1 key2 val2) -- structure syntax */ |
2667 case 's': return read_structure (readcharfun); | |
2668 case '<': | |
2669 { | |
2670 unreadchar (readcharfun, c); | |
2671 return Fsignal (Qinvalid_read_syntax, | |
771 | 2672 list1 (build_msg_string ("Cannot read unreadable object"))); |
428 | 2673 } |
2674 #ifdef FEATUREP_SYNTAX | |
2675 case '+': | |
2676 case '-': | |
2677 { | |
456 | 2678 Lisp_Object feature_exp, obj, tem; |
428 | 2679 struct gcpro gcpro1, gcpro2; |
2680 | |
456 | 2681 feature_exp = read0(readcharfun); |
428 | 2682 obj = read0(readcharfun); |
2683 | |
2684 /* the call to `featurep' may GC. */ | |
456 | 2685 GCPRO2 (feature_exp, obj); |
2686 tem = call1 (Qfeaturep, feature_exp); | |
428 | 2687 UNGCPRO; |
2688 | |
2689 if (c == '+' && NILP(tem)) goto retry; | |
2690 if (c == '-' && !NILP(tem)) goto retry; | |
2691 return obj; | |
2692 } | |
2693 #endif | |
2694 case '0': case '1': case '2': case '3': case '4': | |
2695 case '5': case '6': case '7': case '8': case '9': | |
2696 /* Reader forms that can reuse previously read objects. */ | |
2697 { | |
2698 int n = 0; | |
2699 Lisp_Object found; | |
2700 | |
2701 /* Using read_integer() here is impossible, because it | |
2702 chokes on `='. Using parse_integer() is too hard. | |
2703 So we simply read it in, and ignore overflows, which | |
2704 is safe. */ | |
2705 while (c >= '0' && c <= '9') | |
2706 { | |
2707 n *= 10; | |
2708 n += c - '0'; | |
2709 c = readchar (readcharfun); | |
2710 } | |
2711 found = assq_no_quit (make_int (n), Vread_objects); | |
2712 if (c == '=') | |
2713 { | |
2714 /* #n=object returns object, but associates it with | |
2715 n for #n#. */ | |
2716 Lisp_Object obj; | |
2717 if (CONSP (found)) | |
2718 return Fsignal (Qinvalid_read_syntax, | |
771 | 2719 list2 (build_msg_string |
428 | 2720 ("Multiply defined symbol label"), |
2721 make_int (n))); | |
2722 obj = read0 (readcharfun); | |
2723 Vread_objects = Fcons (Fcons (make_int (n), obj), | |
2724 Vread_objects); | |
2725 return obj; | |
2726 } | |
2727 else if (c == '#') | |
2728 { | |
2729 /* #n# returns a previously read object. */ | |
2730 if (CONSP (found)) | |
2731 return XCDR (found); | |
2732 else | |
2733 return Fsignal (Qinvalid_read_syntax, | |
771 | 2734 list2 (build_msg_string |
428 | 2735 ("Undefined symbol label"), |
2736 make_int (n))); | |
2737 } | |
2738 return Fsignal (Qinvalid_read_syntax, | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2739 list1 (build_ascstring ("#"))); |
428 | 2740 } |
2741 default: | |
2742 { | |
2743 unreadchar (readcharfun, c); | |
2744 return Fsignal (Qinvalid_read_syntax, | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
2745 list1 (build_ascstring ("#"))); |
428 | 2746 } |
2747 } | |
2748 } | |
2749 | |
2750 /* Quote */ | |
2751 case '\'': return list2 (Qquote, read0 (readcharfun)); | |
2752 | |
2753 #ifdef LISP_BACKQUOTES | |
2754 case '`': | |
2755 { | |
2756 Lisp_Object tem; | |
853 | 2757 int speccount = internal_bind_int (&new_backquote_flag, |
2758 1 + new_backquote_flag); | |
428 | 2759 tem = read0 (readcharfun); |
771 | 2760 unbind_to (speccount); |
428 | 2761 return list2 (Qbackquote, tem); |
2762 } | |
2763 | |
2764 case ',': | |
2765 { | |
2766 if (new_backquote_flag) | |
2767 { | |
2768 Lisp_Object comma_type = Qnil; | |
2769 int ch = readchar (readcharfun); | |
2770 | |
2771 if (ch == '@') | |
2772 comma_type = Qcomma_at; | |
2773 else if (ch == '.') | |
2774 comma_type = Qcomma_dot; | |
2775 else | |
2776 { | |
2777 if (ch >= 0) | |
2778 unreadchar (readcharfun, ch); | |
2779 comma_type = Qcomma; | |
2780 } | |
2781 return list2 (comma_type, read0 (readcharfun)); | |
2782 } | |
2783 else | |
2784 { | |
2785 /* YUCK. 99.999% backwards compatibility. The Right | |
2786 Thing(tm) is to signal an error here, because it's | |
2787 really invalid read syntax. Instead, this permits | |
2788 commas to begin symbols (unless they're inside | |
2789 backquotes). If an error is signalled here in the | |
2790 future, then commas should be invalid read syntax | |
2791 outside of backquotes anywhere they're found (i.e. | |
2792 they must be quoted in symbols) -- Stig */ | |
2793 return read_atom (readcharfun, c, 0); | |
2794 } | |
2795 } | |
2796 #endif | |
2797 | |
2798 case '?': | |
2799 { | |
2800 /* Evil GNU Emacs "character" (ie integer) syntax */ | |
2801 c = readchar (readcharfun); | |
2802 if (c < 0) | |
2803 return Fsignal (Qend_of_file, list1 (READCHARFUN_MAYBE (readcharfun))); | |
2804 | |
2805 if (c == '\\') | |
2806 c = read_escape (readcharfun); | |
4439 | 2807 if (c < 0) |
2808 return Fsignal (Qinvalid_read_syntax, list1 (READCHARFUN_MAYBE (readcharfun))); | |
428 | 2809 return make_char (c); |
2810 } | |
2811 | |
2812 case '\"': | |
3543 | 2813 /* String */ |
2814 return read_string(readcharfun, '\"', 0, 1); | |
428 | 2815 |
2816 default: | |
2817 { | |
2818 /* Ignore whitespace and control characters */ | |
2819 if (c <= 040) | |
2820 goto retry; | |
2821 return read_atom (readcharfun, c, 0); | |
2822 } | |
2823 } | |
2824 } | |
2825 | |
2826 | |
2827 | |
2828 #define LEAD_INT 1 | |
2829 #define DOT_CHAR 2 | |
2830 #define TRAIL_INT 4 | |
2831 #define E_CHAR 8 | |
2832 #define EXP_INT 16 | |
2833 | |
2834 int | |
442 | 2835 isfloat_string (const char *cp) |
428 | 2836 { |
2837 int state = 0; | |
867 | 2838 const Ibyte *ucp = (const Ibyte *) cp; |
428 | 2839 |
2840 if (*ucp == '+' || *ucp == '-') | |
2841 ucp++; | |
2842 | |
2843 if (*ucp >= '0' && *ucp <= '9') | |
2844 { | |
2845 state |= LEAD_INT; | |
2846 while (*ucp >= '0' && *ucp <= '9') | |
2847 ucp++; | |
2848 } | |
2849 if (*ucp == '.') | |
2850 { | |
2851 state |= DOT_CHAR; | |
2852 ucp++; | |
2853 } | |
2854 if (*ucp >= '0' && *ucp <= '9') | |
2855 { | |
2856 state |= TRAIL_INT; | |
2857 while (*ucp >= '0' && *ucp <= '9') | |
2858 ucp++; | |
2859 } | |
2860 if (*ucp == 'e' || *ucp == 'E') | |
2861 { | |
2862 state |= E_CHAR; | |
2863 ucp++; | |
2864 if ((*ucp == '+') || (*ucp == '-')) | |
2865 ucp++; | |
2866 } | |
2867 | |
2868 if (*ucp >= '0' && *ucp <= '9') | |
2869 { | |
2870 state |= EXP_INT; | |
2871 while (*ucp >= '0' && *ucp <= '9') | |
2872 ucp++; | |
2873 } | |
2874 return (((*ucp == 0) || (*ucp == ' ') || (*ucp == '\t') || (*ucp == '\n') | |
2875 || (*ucp == '\r') || (*ucp == '\f')) | |
2876 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT) | |
2877 || state == (DOT_CHAR|TRAIL_INT) | |
2878 || state == (LEAD_INT|E_CHAR|EXP_INT) | |
2879 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT) | |
2880 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT))); | |
2881 } | |
1983 | 2882 |
2883 #ifdef HAVE_RATIO | |
2884 int | |
2885 isratio_string (const char *cp) | |
2886 { | |
2010 | 2887 /* Possible minus/plus sign */ |
2888 if (*cp == '-' || *cp == '+') | |
1983 | 2889 cp++; |
2890 | |
2891 /* Numerator */ | |
2892 if (*cp < '0' || *cp > '9') | |
2893 return 0; | |
2894 | |
2895 do { | |
2896 cp++; | |
2897 } while (*cp >= '0' && *cp <= '9'); | |
2898 | |
2899 /* Slash */ | |
2900 if (*cp++ != '/') | |
2901 return 0; | |
2902 | |
2903 /* Denominator */ | |
2904 if (*cp < '0' || *cp > '9') | |
2905 return 0; | |
2906 | |
2907 do { | |
2908 cp++; | |
2909 } while (*cp >= '0' && *cp <= '9'); | |
2910 | |
2911 return *cp == '\0' || *cp == ' ' || *cp =='\t' || *cp == '\n' || | |
2912 *cp == '\r' || *cp == '\f'; | |
2913 } | |
2914 #endif | |
428 | 2915 |
2916 static void * | |
2917 sequence_reader (Lisp_Object readcharfun, | |
867 | 2918 Ichar terminator, |
428 | 2919 void *state, |
2920 void * (*conser) (Lisp_Object readcharfun, | |
2921 void *state, Charcount len)) | |
2922 { | |
2923 Charcount len; | |
2924 | |
2925 for (len = 0; ; len++) | |
2926 { | |
867 | 2927 Ichar ch; |
428 | 2928 |
2929 QUIT; | |
2930 ch = reader_nextchar (readcharfun); | |
2931 | |
2932 if (ch == terminator) | |
2933 return state; | |
2934 else | |
2935 unreadchar (readcharfun, ch); | |
2936 #ifdef FEATUREP_SYNTAX | |
2937 if (ch == ']') | |
442 | 2938 read_syntax_error ("\"]\" in a list"); |
428 | 2939 else if (ch == ')') |
442 | 2940 read_syntax_error ("\")\" in a vector"); |
428 | 2941 #endif |
2942 state = ((conser) (readcharfun, state, len)); | |
2943 } | |
2944 } | |
2945 | |
2946 | |
2947 struct read_list_state | |
2948 { | |
2949 Lisp_Object head; | |
2950 Lisp_Object tail; | |
2951 int length; | |
2952 int allow_dotted_lists; | |
867 | 2953 Ichar terminator; |
428 | 2954 }; |
2955 | |
2956 static void * | |
2286 | 2957 read_list_conser (Lisp_Object readcharfun, void *state, Charcount UNUSED (len)) |
428 | 2958 { |
2959 struct read_list_state *s = (struct read_list_state *) state; | |
2960 Lisp_Object elt; | |
2961 | |
2962 elt = read1 (readcharfun); | |
2963 | |
2964 if (CONSP (elt) && UNBOUNDP (XCAR (elt))) | |
2965 { | |
2966 Lisp_Object tem = elt; | |
867 | 2967 Ichar ch; |
428 | 2968 |
2969 elt = XCDR (elt); | |
853 | 2970 free_cons (tem); |
428 | 2971 tem = Qnil; |
2972 ch = XCHAR (elt); | |
2973 #ifdef FEATUREP_SYNTAX | |
2974 if (ch == s->terminator) /* deal with #+, #- reader macros */ | |
2975 { | |
2976 unreadchar (readcharfun, s->terminator); | |
2977 goto done; | |
2978 } | |
2979 else if (ch == ']') | |
442 | 2980 read_syntax_error ("']' in a list"); |
428 | 2981 else if (ch == ')') |
442 | 2982 read_syntax_error ("')' in a vector"); |
428 | 2983 else |
2984 #endif | |
2985 if (ch != '.') | |
563 | 2986 signal_error (Qinternal_error, "BUG! Internal reader error", elt); |
428 | 2987 else if (!s->allow_dotted_lists) |
442 | 2988 read_syntax_error ("\".\" in a vector"); |
428 | 2989 else |
2990 { | |
2991 if (!NILP (s->tail)) | |
2992 XCDR (s->tail) = read0 (readcharfun); | |
2993 else | |
2994 s->head = read0 (readcharfun); | |
2995 elt = read1 (readcharfun); | |
2996 if (CONSP (elt) && UNBOUNDP (XCAR (elt))) | |
2997 { | |
2998 ch = XCHAR (XCDR (elt)); | |
853 | 2999 free_cons (elt); |
428 | 3000 if (ch == s->terminator) |
3001 { | |
3002 unreadchar (readcharfun, s->terminator); | |
3003 goto done; | |
3004 } | |
3005 } | |
442 | 3006 read_syntax_error (". in wrong context"); |
428 | 3007 } |
3008 } | |
3009 | |
3010 elt = Fcons (elt, Qnil); | |
3011 if (!NILP (s->tail)) | |
3012 XCDR (s->tail) = elt; | |
3013 else | |
3014 s->head = elt; | |
3015 s->tail = elt; | |
3016 done: | |
3017 s->length++; | |
3018 return s; | |
3019 } | |
3020 | |
3021 | |
814 | 3022 /* allow_dotted_lists means that something like (foo bar . baz) |
3023 is acceptable. If -1, means check for starting with defun | |
3024 and make structure pure. (not implemented, probably for very | |
3025 good reasons) | |
3026 | |
3027 If check_for_doc_references, look for (#$ . INT) doc references | |
3028 in the list and record if load_force_doc_strings is non-zero. | |
3029 (Such doc references will be destroyed during the loadup phase | |
3030 by replacing with Qzero, because Snarf-documentation will fill | |
3031 them in again.) | |
3032 | |
3033 WARNING: If you set this, you sure as hell better not call | |
3034 free_list() on the returned list here. | |
3035 */ | |
428 | 3036 |
3037 static Lisp_Object | |
3038 read_list (Lisp_Object readcharfun, | |
867 | 3039 Ichar terminator, |
428 | 3040 int allow_dotted_lists, |
3041 int check_for_doc_references) | |
3042 { | |
3043 struct read_list_state s; | |
3044 struct gcpro gcpro1, gcpro2; | |
3045 | |
3046 s.head = Qnil; | |
3047 s.tail = Qnil; | |
3048 s.length = 0; | |
3049 s.allow_dotted_lists = allow_dotted_lists; | |
3050 s.terminator = terminator; | |
3051 GCPRO2 (s.head, s.tail); | |
3052 | |
3053 sequence_reader (readcharfun, terminator, &s, read_list_conser); | |
3054 | |
3055 if ((purify_flag || load_force_doc_strings) && check_for_doc_references) | |
3056 { | |
3057 /* check now for any doc string references and record them | |
3058 for later. */ | |
3059 Lisp_Object tail; | |
3060 | |
3061 /* We might be dealing with an imperfect list so don't | |
3062 use LIST_LOOP */ | |
3063 for (tail = s.head; CONSP (tail); tail = XCDR (tail)) | |
3064 { | |
3065 Lisp_Object holding_cons = Qnil; | |
3066 | |
3067 { | |
3068 Lisp_Object elem = XCAR (tail); | |
3069 /* elem might be (#$ . INT) ... */ | |
3070 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal)) | |
3071 holding_cons = tail; | |
3072 /* or it might be (quote (#$ . INT)) i.e. | |
3073 (quote . ((#$ . INT) . nil)) in the case of | |
3074 `autoload' (autoload evaluates its arguments, while | |
3075 `defvar', `defun', etc. don't). */ | |
3076 if (CONSP (elem) && EQ (XCAR (elem), Qquote) | |
3077 && CONSP (XCDR (elem))) | |
3078 { | |
3079 elem = XCAR (XCDR (elem)); | |
3080 if (CONSP (elem) && EQ (XCAR (elem), Vload_file_name_internal)) | |
3081 holding_cons = XCDR (XCAR (tail)); | |
3082 } | |
3083 } | |
3084 | |
3085 if (CONSP (holding_cons)) | |
3086 { | |
3087 if (purify_flag) | |
3088 { | |
3089 if (NILP (Vinternal_doc_file_name)) | |
3090 /* We have not yet called Snarf-documentation, so | |
3091 assume this file is described in the DOC file | |
3092 and Snarf-documentation will fill in the right | |
3093 value later. For now, replace the whole list | |
3094 with 0. */ | |
3095 XCAR (holding_cons) = Qzero; | |
3096 else | |
3097 /* We have already called Snarf-documentation, so | |
3098 make a relative file name for this file, so it | |
3099 can be found properly in the installed Lisp | |
3100 directory. We don't use Fexpand_file_name | |
3101 because that would make the directory absolute | |
3102 now. */ | |
3103 XCAR (XCAR (holding_cons)) = | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
3104 concat2 (build_ascstring ("../lisp/"), |
428 | 3105 Ffile_name_nondirectory |
3106 (Vload_file_name_internal)); | |
3107 } | |
3108 else | |
3109 /* Not pure. Just add to Vload_force_doc_string_list, | |
3110 and the string will be filled in properly in | |
3111 load_force_doc_string_unwind(). */ | |
3112 Vload_force_doc_string_list = | |
3113 /* We pass the cons that holds the (#$ . INT) so we | |
3114 can modify it in-place. */ | |
3115 Fcons (holding_cons, Vload_force_doc_string_list); | |
3116 } | |
3117 } | |
3118 } | |
3119 | |
3120 UNGCPRO; | |
3121 return s.head; | |
3122 } | |
3123 | |
3124 static Lisp_Object | |
3125 read_vector (Lisp_Object readcharfun, | |
867 | 3126 Ichar terminator) |
428 | 3127 { |
3128 Lisp_Object tem; | |
3129 Lisp_Object *p; | |
3130 int len; | |
3131 int i; | |
3132 struct read_list_state s; | |
3133 struct gcpro gcpro1, gcpro2; | |
3134 | |
3135 s.head = Qnil; | |
3136 s.tail = Qnil; | |
3137 s.length = 0; | |
3138 s.allow_dotted_lists = 0; | |
3139 GCPRO2 (s.head, s.tail); | |
3140 | |
3141 sequence_reader (readcharfun, terminator, &s, read_list_conser); | |
3142 | |
3143 UNGCPRO; | |
3144 tem = s.head; | |
3145 len = XINT (Flength (tem)); | |
3146 | |
814 | 3147 s.head = make_vector (len, Qnil); |
428 | 3148 |
3149 for (i = 0, p = &(XVECTOR_DATA (s.head)[0]); | |
3150 i < len; | |
3151 i++, p++) | |
3152 { | |
853 | 3153 Lisp_Object otem = tem; |
428 | 3154 tem = Fcar (tem); |
3155 *p = tem; | |
853 | 3156 tem = XCDR (otem); |
428 | 3157 free_cons (otem); |
3158 } | |
3159 return s.head; | |
3160 } | |
3161 | |
3162 static Lisp_Object | |
867 | 3163 read_compiled_function (Lisp_Object readcharfun, Ichar terminator) |
428 | 3164 { |
3165 /* Accept compiled functions at read-time so that we don't | |
3166 have to build them at load-time. */ | |
3167 Lisp_Object stuff; | |
3168 Lisp_Object make_byte_code_args[COMPILED_DOMAIN + 1]; | |
3169 struct gcpro gcpro1; | |
3170 int len; | |
3171 int iii; | |
3172 int saw_a_doc_ref = 0; | |
3173 | |
3174 /* Note: we tell read_list not to search for doc references | |
3175 because we need to handle the "doc reference" for the | |
3176 instructions and constants differently. */ | |
3177 stuff = read_list (readcharfun, terminator, 0, 0); | |
3178 len = XINT (Flength (stuff)); | |
3179 if (len < COMPILED_STACK_DEPTH + 1 || len > COMPILED_DOMAIN + 1) | |
3180 return | |
442 | 3181 continuable_read_syntax_error ("#[...] used with wrong number of elements"); |
428 | 3182 |
3183 for (iii = 0; CONSP (stuff); iii++) | |
3184 { | |
853 | 3185 Lisp_Object victim = stuff; |
428 | 3186 make_byte_code_args[iii] = Fcar (stuff); |
3187 if ((purify_flag || load_force_doc_strings) | |
3188 && CONSP (make_byte_code_args[iii]) | |
3189 && EQ (XCAR (make_byte_code_args[iii]), Vload_file_name_internal)) | |
3190 { | |
3191 if (purify_flag && iii == COMPILED_DOC_STRING) | |
3192 { | |
3193 /* same as in read_list(). */ | |
3194 if (NILP (Vinternal_doc_file_name)) | |
3195 make_byte_code_args[iii] = Qzero; | |
3196 else | |
3197 XCAR (make_byte_code_args[iii]) = | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
3198 concat2 (build_ascstring ("../lisp/"), |
428 | 3199 Ffile_name_nondirectory |
3200 (Vload_file_name_internal)); | |
3201 } | |
3202 else | |
3203 saw_a_doc_ref = 1; | |
3204 } | |
3205 stuff = Fcdr (stuff); | |
3206 free_cons (victim); | |
3207 } | |
3208 GCPRO1 (make_byte_code_args[0]); | |
3209 gcpro1.nvars = len; | |
3210 | |
3211 /* v18 or v19 bytecode file. Need to Ebolify. */ | |
3212 if (load_byte_code_version < 20 && VECTORP (make_byte_code_args[2])) | |
3213 ebolify_bytecode_constants (make_byte_code_args[2]); | |
3214 | |
3215 /* make-byte-code looks at purify_flag, which should have the same | |
3216 * value as our "read-pure" argument */ | |
3217 stuff = Fmake_byte_code (len, make_byte_code_args); | |
3218 XCOMPILED_FUNCTION (stuff)->flags.ebolified = (load_byte_code_version < 20); | |
3219 if (saw_a_doc_ref) | |
3220 Vload_force_doc_string_list = Fcons (stuff, Vload_force_doc_string_list); | |
3221 UNGCPRO; | |
3222 return stuff; | |
3223 } | |
3224 | |
3225 | |
3226 | |
3227 void | |
3228 init_lread (void) | |
3229 { | |
3230 Vvalues = Qnil; | |
3231 | |
3232 load_in_progress = 0; | |
3233 | |
3234 Vload_descriptor_list = Qnil; | |
3235 | |
3236 /* kludge: locate-file does not work for a null load-path, even if | |
3237 the file name is absolute. */ | |
3238 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
3239 Vload_path = Fcons (build_ascstring (""), Qnil); |
428 | 3240 |
3241 /* This used to get initialized in init_lread because all streams | |
3242 got closed when dumping occurs. This is no longer true -- | |
3243 Vread_buffer_stream is a resizing output stream, and there is no | |
3244 reason to close it at dump-time. | |
3245 | |
3246 Vread_buffer_stream is set to Qnil in vars_of_lread, and this | |
3247 will initialize it only once, at dump-time. */ | |
3248 if (NILP (Vread_buffer_stream)) | |
3249 Vread_buffer_stream = make_resizing_buffer_output_stream (); | |
3250 | |
3251 Vload_force_doc_string_list = Qnil; | |
4608
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
3252 |
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
3253 Vload_file_name_internal = Qnil; |
1e3cf11fa27d
Make #$ truly read-only for Lisp; check this in the test suite.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4483
diff
changeset
|
3254 Vload_file_name = Qnil; |
428 | 3255 } |
3256 | |
3257 void | |
3258 syms_of_lread (void) | |
3259 { | |
3260 DEFSUBR (Fread); | |
3261 DEFSUBR (Fread_from_string); | |
3262 DEFSUBR (Fload_internal); | |
3263 DEFSUBR (Flocate_file); | |
3264 DEFSUBR (Flocate_file_clear_hashing); | |
3265 DEFSUBR (Feval_buffer); | |
3266 DEFSUBR (Feval_region); | |
3267 | |
563 | 3268 DEFSYMBOL (Qstandard_input); |
3269 DEFSYMBOL (Qread_char); | |
3270 DEFSYMBOL (Qload); | |
1292 | 3271 DEFSYMBOL (Qload_internal); |
563 | 3272 DEFSYMBOL (Qfset); |
428 | 3273 |
3274 #ifdef LISP_BACKQUOTES | |
563 | 3275 DEFSYMBOL (Qbackquote); |
428 | 3276 defsymbol (&Qbacktick, "`"); |
3277 defsymbol (&Qcomma, ","); | |
3278 defsymbol (&Qcomma_at, ",@"); | |
3279 defsymbol (&Qcomma_dot, ",."); | |
3280 #endif | |
3281 | |
563 | 3282 DEFSYMBOL (Qexists); |
3283 DEFSYMBOL (Qreadable); | |
3284 DEFSYMBOL (Qwritable); | |
3285 DEFSYMBOL (Qexecutable); | |
428 | 3286 } |
3287 | |
3288 void | |
3289 structure_type_create (void) | |
3290 { | |
3291 the_structure_type_dynarr = Dynarr_new (structure_type); | |
3292 } | |
3293 | |
3294 void | |
3295 reinit_vars_of_lread (void) | |
3296 { | |
3297 Vread_buffer_stream = Qnil; | |
3298 staticpro_nodump (&Vread_buffer_stream); | |
3299 } | |
3300 | |
3301 void | |
3302 vars_of_lread (void) | |
3303 { | |
3304 DEFVAR_LISP ("values", &Vvalues /* | |
3305 List of values of all expressions which were read, evaluated and printed. | |
3306 Order is reverse chronological. | |
3307 */ ); | |
3308 | |
3309 DEFVAR_LISP ("standard-input", &Vstandard_input /* | |
3310 Stream for read to get input from. | |
3311 See documentation of `read' for possible values. | |
3312 */ ); | |
3313 Vstandard_input = Qt; | |
3314 | |
3315 DEFVAR_LISP ("load-path", &Vload_path /* | |
3316 *List of directories to search for files to load. | |
3317 Each element is a string (directory name) or nil (try default directory). | |
3318 | |
3319 Note that the elements of this list *may not* begin with "~", so you must | |
3320 call `expand-file-name' on them before adding them to this list. | |
3321 | |
3322 Initialized based on EMACSLOADPATH environment variable, if any, | |
3323 otherwise to default specified in by file `paths.h' when XEmacs was built. | |
3324 If there were no paths specified in `paths.h', then XEmacs chooses a default | |
3325 value for this variable by looking around in the file-system near the | |
3326 directory in which the XEmacs executable resides. | |
3327 */ ); | |
3328 Vload_path = Qnil; | |
3329 | |
3330 /* xxxDEFVAR_LISP ("dump-load-path", &Vdump_load_path, | |
3331 "*Location of lisp files to be used when dumping ONLY."); */ | |
3332 | |
3333 DEFVAR_BOOL ("load-in-progress", &load_in_progress /* | |
3334 Non-nil iff inside of `load'. | |
3335 */ ); | |
3336 | |
2548 | 3337 DEFVAR_LISP ("load-suppress-alist", &Vload_suppress_alist /* |
3338 An alist of expressions controlling whether particular files can be loaded. | |
3339 Each element looks like (FILENAME EXPR). | |
3340 FILENAME should be a full pathname, but without the .el suffix. | |
3341 When `load' is run and is about to load the specified file, it evaluates | |
3342 the form to determine if the file can be loaded. | |
3343 This variable is normally initialized automatically. | |
3344 */ ); | |
3345 Vload_suppress_alist = Qnil; | |
3346 | |
428 | 3347 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist /* |
3348 An alist of expressions to be evalled when particular files are loaded. | |
3349 Each element looks like (FILENAME FORMS...). | |
3350 When `load' is run and the file-name argument is FILENAME, | |
3351 the FORMS in the corresponding element are executed at the end of loading. | |
3352 | |
3353 FILENAME must match exactly! Normally FILENAME is the name of a library, | |
3354 with no directory specified, since that is how `load' is normally called. | |
3355 An error in FORMS does not undo the load, | |
3356 but does prevent execution of the rest of the FORMS. | |
3357 */ ); | |
3358 Vafter_load_alist = Qnil; | |
3359 | |
3360 DEFVAR_BOOL ("load-warn-when-source-newer", &load_warn_when_source_newer /* | |
3361 *Whether `load' should check whether the source is newer than the binary. | |
3362 If this variable is true, then when a `.elc' file is being loaded and the | |
3363 corresponding `.el' is newer, a warning message will be printed. | |
3364 */ ); | |
1261 | 3365 load_warn_when_source_newer = 1; |
428 | 3366 |
3367 DEFVAR_BOOL ("load-warn-when-source-only", &load_warn_when_source_only /* | |
3368 *Whether `load' should warn when loading a `.el' file instead of an `.elc'. | |
3369 If this variable is true, then when `load' is called with a filename without | |
3370 an extension, and the `.elc' version doesn't exist but the `.el' version does, | |
3371 then a message will be printed. If an explicit extension is passed to `load', | |
3372 no warning will be printed. | |
3373 */ ); | |
3374 load_warn_when_source_only = 0; | |
3375 | |
3376 DEFVAR_BOOL ("load-ignore-elc-files", &load_ignore_elc_files /* | |
3377 *Whether `load' should ignore `.elc' files when a suffix is not given. | |
3378 This is normally used only to bootstrap the `.elc' files when building XEmacs. | |
3379 */ ); | |
3380 load_ignore_elc_files = 0; | |
3381 | |
1123 | 3382 DEFVAR_BOOL ("load-ignore-out-of-date-elc-files", |
3383 &load_ignore_out_of_date_elc_files /* | |
3384 *Whether `load' should ignore out-of-date `.elc' files when no suffix is given. | |
3385 This is normally used when compiling packages of elisp files that may have | |
3386 complex dependencies. Ignoring all elc files with `load-ignore-elc-files' | |
3387 would also be safe, but much slower. | |
3388 */ ); | |
4955
de64354ffcbf
turn on load-ignore-out-of-date-elc-files by default
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
3389 load_ignore_out_of_date_elc_files = 1; |
1123 | 3390 |
3391 DEFVAR_BOOL ("load-always-display-messages", | |
3392 &load_always_display_messages /* | |
3393 *Whether `load' should always display loading messages. | |
3394 If this is true, every file loaded will be shown, regardless of the setting | |
3395 of the NOMESSAGE parameter, and even when files are loaded indirectly, e.g. | |
2857 | 3396 due to `require'. |
1123 | 3397 */ ); |
3398 load_always_display_messages = 0; | |
3399 | |
3400 DEFVAR_BOOL ("load-show-full-path-in-messages", | |
3401 &load_show_full_path_in_messages /* | |
3402 *Whether `load' should show the full path in all loading messages. | |
3403 */ ); | |
3404 load_show_full_path_in_messages = 0; | |
3405 | |
428 | 3406 #ifdef LOADHIST |
3407 DEFVAR_LISP ("load-history", &Vload_history /* | |
3408 Alist mapping source file names to symbols and features. | |
3409 Each alist element is a list that starts with a file name, | |
3410 except for one element (optional) that starts with nil and describes | |
3411 definitions evaluated from buffers not visiting files. | |
3412 The remaining elements of each list are symbols defined as functions | |
3413 or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'. | |
3414 */ ); | |
3415 Vload_history = Qnil; | |
3416 | |
3417 DEFVAR_LISP ("current-load-list", &Vcurrent_load_list /* | |
3418 Used for internal purposes by `load'. | |
3419 */ ); | |
3420 Vcurrent_load_list = Qnil; | |
3421 #endif | |
3422 | |
3423 DEFVAR_LISP ("load-file-name", &Vload_file_name /* | |
3424 Full name of file being loaded by `load'. | |
3425 */ ); | |
3426 Vload_file_name = Qnil; | |
3427 | |
3428 DEFVAR_LISP ("load-read-function", &Vload_read_function /* | |
3429 Function used by `load' and `eval-region' for reading expressions. | |
3430 The default is nil, which means use the function `read'. | |
3431 */ ); | |
3432 Vload_read_function = Qnil; | |
3433 | |
3434 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings /* | |
3435 Non-nil means `load' should force-load all dynamic doc strings. | |
3436 This is useful when the file being loaded is a temporary copy. | |
3437 */ ); | |
3438 load_force_doc_strings = 0; | |
3439 | |
3440 /* See read_escape(). */ | |
3441 #if 0 | |
3442 /* Used to be named `puke-on-fsf-keys' */ | |
3443 DEFVAR_BOOL ("fail-on-bucky-bit-character-escapes", | |
3444 &fail_on_bucky_bit_character_escapes /* | |
3445 Whether `read' should signal an error when it encounters unsupported | |
3446 character escape syntaxes or just read them incorrectly. | |
3447 */ ); | |
3448 fail_on_bucky_bit_character_escapes = 0; | |
3449 #endif | |
3450 | |
3451 /* This must be initialized in init_lread otherwise it may start out | |
3452 with values saved when the image is dumped. */ | |
3453 staticpro (&Vload_descriptor_list); | |
3454 | |
3455 /* Initialized in init_lread. */ | |
3456 staticpro (&Vload_force_doc_string_list); | |
3457 | |
3458 Vload_file_name_internal = Qnil; | |
3459 staticpro (&Vload_file_name_internal); | |
3460 | |
3461 /* So that early-early stuff will work */ | |
1292 | 3462 Ffset (Qload, Qload_internal); |
428 | 3463 |
3464 #ifdef FEATUREP_SYNTAX | |
563 | 3465 DEFSYMBOL (Qfeaturep); |
771 | 3466 Fprovide (intern ("xemacs")); |
428 | 3467 #ifdef INFODOCK |
771 | 3468 Fprovide (intern ("infodock")); |
428 | 3469 #endif /* INFODOCK */ |
3470 #endif /* FEATUREP_SYNTAX */ | |
3471 | |
3472 #ifdef LISP_BACKQUOTES | |
3473 old_backquote_flag = new_backquote_flag = 0; | |
3474 #endif | |
3475 | |
3476 #ifdef I18N3 | |
3477 Vfile_domain = Qnil; | |
5139
a48ef26d87ee
Clean up prototypes for Lisp variables/symbols. Put decls for them with
Ben Wing <ben@xemacs.org>
parents:
5088
diff
changeset
|
3478 staticpro (&Vfile_domain); |
428 | 3479 #endif |
3480 | |
3481 Vread_objects = Qnil; | |
3482 staticpro (&Vread_objects); | |
3483 | |
3484 Vlocate_file_hash_table = make_lisp_hash_table (200, | |
3485 HASH_TABLE_NON_WEAK, | |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5139
diff
changeset
|
3486 Qequal); |
428 | 3487 staticpro (&Vlocate_file_hash_table); |
3488 #ifdef DEBUG_XEMACS | |
3489 symbol_value (XSYMBOL (intern ("Vlocate-file-hash-table"))) | |
3490 = Vlocate_file_hash_table; | |
3491 #endif | |
3492 } |