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