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