Mercurial > emacs
annotate src/lread.c @ 1609:5beb9d2bc959
* bytecomp.el: Declare unread-command-char an obsolete variable.
* vip.el (vip-escape-to-emacs, vip-prefix-arg-value,
vip-prefix-arg-com): Use unread-command-event instead of
unread-command-char; respect its new semantics.
* electric.el (Electric-command-loop): Same.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Mon, 16 Nov 1992 01:31:33 +0000 |
parents | 765cb54fa9af |
children | 12c730b89ac8 |
rev | line source |
---|---|
341 | 1 /* Lisp parsing and input streams. |
692 | 2 Copyright (C) 1985, 1986, 1987, 1988, 1989, |
3 1992 Free Software Foundation, Inc. | |
341 | 4 |
5 This file is part of GNU Emacs. | |
6 | |
7 GNU Emacs is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
617 | 9 the Free Software Foundation; either version 2, or (at your option) |
341 | 10 any later version. |
11 | |
12 GNU Emacs is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with GNU Emacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | |
21 | |
22 #include <stdio.h> | |
23 #include <sys/types.h> | |
24 #include <sys/stat.h> | |
25 #include <sys/file.h> | |
796 | 26 #include <ctype.h> |
341 | 27 #undef NULL |
28 #include "config.h" | |
29 #include "lisp.h" | |
30 | |
31 #ifndef standalone | |
32 #include "buffer.h" | |
33 #include "paths.h" | |
34 #include "commands.h" | |
1591
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
35 #include "keyboard.h" |
341 | 36 #endif |
37 | |
38 #ifdef lint | |
39 #include <sys/inode.h> | |
40 #endif /* lint */ | |
41 | |
42 #ifndef X_OK | |
43 #define X_OK 01 | |
44 #endif | |
45 | |
46 #ifdef LISP_FLOAT_TYPE | |
47 #include <math.h> | |
48 #endif /* LISP_FLOAT_TYPE */ | |
49 | |
50 Lisp_Object Qread_char, Qget_file_char, Qstandard_input; | |
51 Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist; | |
52 | |
53 /* non-zero if inside `load' */ | |
54 int load_in_progress; | |
55 | |
56 /* Search path for files to be loaded. */ | |
57 Lisp_Object Vload_path; | |
58 | |
59 /* File for get_file_char to read from. Use by load */ | |
60 static FILE *instream; | |
61 | |
62 /* When nonzero, read conses in pure space */ | |
63 static int read_pure; | |
64 | |
65 /* For use within read-from-string (this reader is non-reentrant!!) */ | |
66 static int read_from_string_index; | |
67 static int read_from_string_limit; | |
68 | |
69 /* Handle unreading and rereading of characters. | |
70 Write READCHAR to read a character, | |
71 UNREAD(c) to unread c to be read again. */ | |
72 | |
73 #define READCHAR readchar (readcharfun) | |
74 #define UNREAD(c) unreadchar (readcharfun, c) | |
75 | |
76 static int | |
77 readchar (readcharfun) | |
78 Lisp_Object readcharfun; | |
79 { | |
80 Lisp_Object tem; | |
81 register struct buffer *inbuffer; | |
82 register int c, mpos; | |
83 | |
84 if (XTYPE (readcharfun) == Lisp_Buffer) | |
85 { | |
86 inbuffer = XBUFFER (readcharfun); | |
87 | |
88 if (BUF_PT (inbuffer) >= BUF_ZV (inbuffer)) | |
89 return -1; | |
90 c = *(unsigned char *) BUF_CHAR_ADDRESS (inbuffer, BUF_PT (inbuffer)); | |
91 SET_BUF_PT (inbuffer, BUF_PT (inbuffer) + 1); | |
92 | |
93 return c; | |
94 } | |
95 if (XTYPE (readcharfun) == Lisp_Marker) | |
96 { | |
97 inbuffer = XMARKER (readcharfun)->buffer; | |
98 | |
99 mpos = marker_position (readcharfun); | |
100 | |
101 if (mpos > BUF_ZV (inbuffer) - 1) | |
102 return -1; | |
103 c = *(unsigned char *) BUF_CHAR_ADDRESS (inbuffer, mpos); | |
104 if (mpos != BUF_GPT (inbuffer)) | |
105 XMARKER (readcharfun)->bufpos++; | |
106 else | |
107 Fset_marker (readcharfun, make_number (mpos + 1), | |
108 Fmarker_buffer (readcharfun)); | |
109 return c; | |
110 } | |
111 if (EQ (readcharfun, Qget_file_char)) | |
112 return getc (instream); | |
113 | |
114 if (XTYPE (readcharfun) == Lisp_String) | |
115 { | |
116 register int c; | |
117 /* This used to be return of a conditional expression, | |
118 but that truncated -1 to a char on VMS. */ | |
119 if (read_from_string_index < read_from_string_limit) | |
120 c = XSTRING (readcharfun)->data[read_from_string_index++]; | |
121 else | |
122 c = -1; | |
123 return c; | |
124 } | |
125 | |
126 tem = call0 (readcharfun); | |
127 | |
485 | 128 if (NILP (tem)) |
341 | 129 return -1; |
130 return XINT (tem); | |
131 } | |
132 | |
133 /* Unread the character C in the way appropriate for the stream READCHARFUN. | |
134 If the stream is a user function, call it with the char as argument. */ | |
135 | |
136 static void | |
137 unreadchar (readcharfun, c) | |
138 Lisp_Object readcharfun; | |
139 int c; | |
140 { | |
141 if (XTYPE (readcharfun) == Lisp_Buffer) | |
142 { | |
143 if (XBUFFER (readcharfun) == current_buffer) | |
144 SET_PT (point - 1); | |
145 else | |
146 SET_BUF_PT (XBUFFER (readcharfun), BUF_PT (XBUFFER (readcharfun)) - 1); | |
147 } | |
148 else if (XTYPE (readcharfun) == Lisp_Marker) | |
149 XMARKER (readcharfun)->bufpos--; | |
150 else if (XTYPE (readcharfun) == Lisp_String) | |
151 read_from_string_index--; | |
152 else if (EQ (readcharfun, Qget_file_char)) | |
153 ungetc (c, instream); | |
154 else | |
155 call1 (readcharfun, make_number (c)); | |
156 } | |
157 | |
158 static Lisp_Object read0 (), read1 (), read_list (), read_vector (); | |
159 | |
160 /* get a character from the tty */ | |
161 | |
1519
5d0837ebee9c
* lread.c (read_char): Add an extern declaration for this,
Jim Blandy <jimb@redhat.com>
parents:
1092
diff
changeset
|
162 extern Lisp_Object read_char (); |
5d0837ebee9c
* lread.c (read_char): Add an extern declaration for this,
Jim Blandy <jimb@redhat.com>
parents:
1092
diff
changeset
|
163 |
341 | 164 DEFUN ("read-char", Fread_char, Sread_char, 0, 0, 0, |
165 "Read a character from the command input (keyboard or macro).\n\ | |
851 | 166 It is returned as a number.\n\ |
167 If the user generates an event which is not a character (i.e. a mouse\n\ | |
1591
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
168 click or function key event), `read-char' signals an error. As an\n\ |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
169 exception, switch-frame events are put off until non-ASCII events can\n\ |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
170 be read.\n\ |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
171 If you want to read non-character events, or ignore them, call\n\ |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
172 `read-event' or `read-char-exclusive' instead.") |
341 | 173 () |
174 { | |
175 register Lisp_Object val; | |
176 | |
177 #ifndef standalone | |
1591
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
178 { |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
179 register Lisp_Object delayed_switch_frame; |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
180 |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
181 delayed_switch_frame = Qnil; |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
182 |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
183 for (;;) |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
184 { |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
185 val = read_char (0, 0, 0, Qnil, 0); |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
186 |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
187 /* switch-frame events are put off until after the next ASCII |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
188 character. This is better than signalling an error just |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
189 because the last characters were typed to a separate |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
190 minibuffer frame, for example. Eventually, some code which |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
191 can deal with switch-frame events will read it and process |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
192 it. */ |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
193 if (EVENT_HAS_PARAMETERS (val) |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
194 && EQ (EVENT_HEAD (val), Qswitch_frame)) |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
195 delayed_switch_frame = val; |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
196 else |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
197 break; |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
198 } |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
199 |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
200 if (! NILP (delayed_switch_frame)) |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
201 unread_switch_frame = delayed_switch_frame; |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
202 |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
203 /* Only ASCII characters are acceptable. */ |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
204 if (XTYPE (val) != Lisp_Int) |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
205 { |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
206 unread_command_event = val; |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
207 error ("Object read was not a character"); |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
208 } |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
209 } |
341 | 210 #else |
211 val = getchar (); | |
212 #endif | |
213 | |
214 return val; | |
215 } | |
216 | |
217 DEFUN ("read-event", Fread_event, Sread_event, 0, 0, 0, | |
218 "Read an event object from the input stream.") | |
219 () | |
220 { | |
221 register Lisp_Object val; | |
222 | |
1092
c2259db856ee
(Fread_char): Pass new args to read_char.
Richard M. Stallman <rms@gnu.org>
parents:
1009
diff
changeset
|
223 val = read_char (0, 0, 0, Qnil, 0); |
341 | 224 return val; |
225 } | |
226 | |
227 DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 0, 0, | |
228 "Read a character from the command input (keyboard or macro).\n\ | |
229 It is returned as a number. Non character events are ignored.") | |
230 () | |
231 { | |
232 register Lisp_Object val; | |
233 | |
234 #ifndef standalone | |
1591
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
235 { |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
236 Lisp_Object delayed_switch_frame; |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
237 |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
238 delayed_switch_frame = Qnil; |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
239 |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
240 for (;;) |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
241 { |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
242 val = read_char (0, 0, 0, Qnil, 0); |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
243 |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
244 if (XTYPE (val) == Lisp_Int) |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
245 break; |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
246 |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
247 /* switch-frame events are put off until after the next ASCII |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
248 character. This is better than signalling an error just |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
249 because the last characters were typed to a separate |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
250 minibuffer frame, for example. Eventually, some code which |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
251 can deal with switch-frame events will read it and process |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
252 it. */ |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
253 else if (EVENT_HAS_PARAMETERS (val) |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
254 && EQ (EVENT_HEAD (val), Qswitch_frame)) |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
255 delayed_switch_frame = val; |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
256 |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
257 /* Drop everything else. */ |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
258 } |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
259 |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
260 if (! NILP (delayed_switch_frame)) |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
261 unread_switch_frame = delayed_switch_frame; |
765cb54fa9af
* lread.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1519
diff
changeset
|
262 } |
341 | 263 #else |
264 val = getchar (); | |
265 #endif | |
266 | |
267 return val; | |
268 } | |
269 | |
270 DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0, | |
271 "Don't use this yourself.") | |
272 () | |
273 { | |
274 register Lisp_Object val; | |
275 XSET (val, Lisp_Int, getc (instream)); | |
276 return val; | |
277 } | |
278 | |
279 static void readevalloop (); | |
280 static Lisp_Object load_unwind (); | |
281 | |
282 DEFUN ("load", Fload, Sload, 1, 4, 0, | |
283 "Execute a file of Lisp code named FILE.\n\ | |
284 First try FILE with `.elc' appended, then try with `.el',\n\ | |
285 then try FILE unmodified.\n\ | |
286 This function searches the directories in `load-path'.\n\ | |
287 If optional second arg NOERROR is non-nil,\n\ | |
288 report no error if FILE doesn't exist.\n\ | |
289 Print messages at start and end of loading unless\n\ | |
290 optional third arg NOMESSAGE is non-nil.\n\ | |
291 If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\ | |
292 suffixes `.elc' or `.el' to the specified name FILE.\n\ | |
293 Return t if file exists.") | |
294 (str, noerror, nomessage, nosuffix) | |
295 Lisp_Object str, noerror, nomessage, nosuffix; | |
296 { | |
297 register FILE *stream; | |
298 register int fd = -1; | |
299 register Lisp_Object lispstream; | |
300 register FILE **ptr; | |
301 int count = specpdl_ptr - specpdl; | |
302 Lisp_Object temp; | |
303 struct gcpro gcpro1; | |
304 Lisp_Object found; | |
305 | |
306 CHECK_STRING (str, 0); | |
307 str = Fsubstitute_in_file_name (str); | |
308 | |
309 /* Avoid weird lossage with null string as arg, | |
310 since it would try to load a directory as a Lisp file */ | |
311 if (XSTRING (str)->size > 0) | |
312 { | |
485 | 313 fd = openp (Vload_path, str, !NILP (nosuffix) ? "" : ".elc:.el:", |
341 | 314 &found, 0); |
315 } | |
316 | |
317 if (fd < 0) | |
318 { | |
485 | 319 if (NILP (noerror)) |
341 | 320 while (1) |
321 Fsignal (Qfile_error, Fcons (build_string ("Cannot open load file"), | |
322 Fcons (str, Qnil))); | |
323 else | |
324 return Qnil; | |
325 } | |
326 | |
327 if (!bcmp (&(XSTRING (found)->data[XSTRING (found)->size - 4]), | |
328 ".elc", 4)) | |
329 { | |
330 struct stat s1, s2; | |
331 int result; | |
332 | |
333 stat (XSTRING (found)->data, &s1); | |
334 XSTRING (found)->data[XSTRING (found)->size - 1] = 0; | |
335 result = stat (XSTRING (found)->data, &s2); | |
336 if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime) | |
337 message ("Source file `%s' newer than byte-compiled file", | |
338 XSTRING (found)->data); | |
339 XSTRING (found)->data[XSTRING (found)->size - 1] = 'c'; | |
340 } | |
341 | |
342 stream = fdopen (fd, "r"); | |
343 if (stream == 0) | |
344 { | |
345 close (fd); | |
346 error ("Failure to create stdio stream for %s", XSTRING (str)->data); | |
347 } | |
348 | |
485 | 349 if (NILP (nomessage)) |
341 | 350 message ("Loading %s...", XSTRING (str)->data); |
351 | |
352 GCPRO1 (str); | |
353 /* We may not be able to store STREAM itself as a Lisp_Object pointer | |
354 since that is guaranteed to work only for data that has been malloc'd. | |
355 So malloc a full-size pointer, and record the address of that pointer. */ | |
356 ptr = (FILE **) xmalloc (sizeof (FILE *)); | |
357 *ptr = stream; | |
358 XSET (lispstream, Lisp_Internal_Stream, (int) ptr); | |
359 record_unwind_protect (load_unwind, lispstream); | |
360 load_in_progress++; | |
361 readevalloop (Qget_file_char, stream, Feval, 0); | |
362 unbind_to (count, Qnil); | |
363 | |
364 /* Run any load-hooks for this file. */ | |
365 temp = Fassoc (str, Vafter_load_alist); | |
485 | 366 if (!NILP (temp)) |
341 | 367 Fprogn (Fcdr (temp)); |
368 UNGCPRO; | |
369 | |
485 | 370 if (!noninteractive && NILP (nomessage)) |
341 | 371 message ("Loading %s...done", XSTRING (str)->data); |
372 return Qt; | |
373 } | |
374 | |
375 static Lisp_Object | |
376 load_unwind (stream) /* used as unwind-protect function in load */ | |
377 Lisp_Object stream; | |
378 { | |
379 fclose (*(FILE **) XSTRING (stream)); | |
380 free (XPNTR (stream)); | |
381 if (--load_in_progress < 0) load_in_progress = 0; | |
382 return Qnil; | |
383 } | |
384 | |
385 | |
386 static int | |
387 complete_filename_p (pathname) | |
388 Lisp_Object pathname; | |
389 { | |
390 register unsigned char *s = XSTRING (pathname)->data; | |
391 return (*s == '/' | |
392 #ifdef ALTOS | |
393 || *s == '@' | |
394 #endif | |
395 #ifdef VMS | |
396 || index (s, ':') | |
397 #endif /* VMS */ | |
398 ); | |
399 } | |
400 | |
401 /* Search for a file whose name is STR, looking in directories | |
402 in the Lisp list PATH, and trying suffixes from SUFFIX. | |
403 SUFFIX is a string containing possible suffixes separated by colons. | |
404 On success, returns a file descriptor. On failure, returns -1. | |
405 | |
406 EXEC_ONLY nonzero means don't open the files, | |
407 just look for one that is executable. In this case, | |
408 returns 1 on success. | |
409 | |
410 If STOREPTR is nonzero, it points to a slot where the name of | |
411 the file actually found should be stored as a Lisp string. | |
412 Nil is stored there on failure. */ | |
413 | |
414 int | |
415 openp (path, str, suffix, storeptr, exec_only) | |
416 Lisp_Object path, str; | |
417 char *suffix; | |
418 Lisp_Object *storeptr; | |
419 int exec_only; | |
420 { | |
421 register int fd; | |
422 int fn_size = 100; | |
423 char buf[100]; | |
424 register char *fn = buf; | |
425 int absolute = 0; | |
426 int want_size; | |
427 register Lisp_Object filename; | |
428 struct stat st; | |
429 | |
430 if (storeptr) | |
431 *storeptr = Qnil; | |
432 | |
433 if (complete_filename_p (str)) | |
434 absolute = 1; | |
435 | |
485 | 436 for (; !NILP (path); path = Fcdr (path)) |
341 | 437 { |
438 char *nsuffix; | |
439 | |
440 filename = Fexpand_file_name (str, Fcar (path)); | |
441 if (!complete_filename_p (filename)) | |
442 /* If there are non-absolute elts in PATH (eg ".") */ | |
443 /* Of course, this could conceivably lose if luser sets | |
444 default-directory to be something non-absolute... */ | |
445 { | |
446 filename = Fexpand_file_name (filename, current_buffer->directory); | |
447 if (!complete_filename_p (filename)) | |
448 /* Give up on this path element! */ | |
449 continue; | |
450 } | |
451 | |
452 /* Calculate maximum size of any filename made from | |
453 this path element/specified file name and any possible suffix. */ | |
454 want_size = strlen (suffix) + XSTRING (filename)->size + 1; | |
455 if (fn_size < want_size) | |
456 fn = (char *) alloca (fn_size = 100 + want_size); | |
457 | |
458 nsuffix = suffix; | |
459 | |
460 /* Loop over suffixes. */ | |
461 while (1) | |
462 { | |
463 char *esuffix = (char *) index (nsuffix, ':'); | |
464 int lsuffix = esuffix ? esuffix - nsuffix : strlen (nsuffix); | |
465 | |
466 /* Concatenate path element/specified name with the suffix. */ | |
467 strncpy (fn, XSTRING (filename)->data, XSTRING (filename)->size); | |
468 fn[XSTRING (filename)->size] = 0; | |
469 if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */ | |
470 strncat (fn, nsuffix, lsuffix); | |
471 | |
472 /* Ignore file if it's a directory. */ | |
473 if (stat (fn, &st) >= 0 | |
474 && (st.st_mode & S_IFMT) != S_IFDIR) | |
475 { | |
476 /* Check that we can access or open it. */ | |
477 if (exec_only) | |
478 fd = (access (fn, X_OK) == 0) ? 1 : -1; | |
479 else | |
480 fd = open (fn, 0, 0); | |
481 | |
482 if (fd >= 0) | |
483 { | |
484 /* We succeeded; return this descriptor and filename. */ | |
485 if (storeptr) | |
486 *storeptr = build_string (fn); | |
487 return fd; | |
488 } | |
489 } | |
490 | |
491 /* Advance to next suffix. */ | |
492 if (esuffix == 0) | |
493 break; | |
494 nsuffix += lsuffix + 1; | |
495 } | |
496 if (absolute) return -1; | |
497 } | |
498 | |
499 return -1; | |
500 } | |
501 | |
502 | |
503 Lisp_Object | |
504 unreadpure () /* Used as unwind-protect function in readevalloop */ | |
505 { | |
506 read_pure = 0; | |
507 return Qnil; | |
508 } | |
509 | |
510 static void | |
511 readevalloop (readcharfun, stream, evalfun, printflag) | |
512 Lisp_Object readcharfun; | |
513 FILE *stream; | |
514 Lisp_Object (*evalfun) (); | |
515 int printflag; | |
516 { | |
517 register int c; | |
518 register Lisp_Object val; | |
519 int count = specpdl_ptr - specpdl; | |
520 | |
521 specbind (Qstandard_input, readcharfun); | |
522 | |
523 while (1) | |
524 { | |
525 instream = stream; | |
526 c = READCHAR; | |
527 if (c == ';') | |
528 { | |
529 while ((c = READCHAR) != '\n' && c != -1); | |
530 continue; | |
531 } | |
532 if (c < 0) break; | |
533 if (c == ' ' || c == '\t' || c == '\n' || c == '\f') continue; | |
534 | |
485 | 535 if (!NILP (Vpurify_flag) && c == '(') |
341 | 536 { |
537 record_unwind_protect (unreadpure, Qnil); | |
538 val = read_list (-1, readcharfun); | |
539 unbind_to (count + 1, Qnil); | |
540 } | |
541 else | |
542 { | |
543 UNREAD (c); | |
544 val = read0 (readcharfun); | |
545 } | |
546 | |
547 val = (*evalfun) (val); | |
548 if (printflag) | |
549 { | |
550 Vvalues = Fcons (val, Vvalues); | |
551 if (EQ (Vstandard_output, Qt)) | |
552 Fprin1 (val, Qnil); | |
553 else | |
554 Fprint (val, Qnil); | |
555 } | |
556 } | |
557 | |
558 unbind_to (count, Qnil); | |
559 } | |
560 | |
561 #ifndef standalone | |
562 | |
732 | 563 DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 2, "", |
675
85fd29f25c75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
673
diff
changeset
|
564 "Execute the current buffer as Lisp code.\n\ |
85fd29f25c75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
673
diff
changeset
|
565 Programs can pass two arguments, BUFFER and PRINTFLAG.\n\ |
85fd29f25c75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
673
diff
changeset
|
566 BUFFER is the buffer to evaluate (nil means use current buffer).\n\ |
85fd29f25c75
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
673
diff
changeset
|
567 PRINTFLAG controls printing of output:\n\ |
672 | 568 nil means discard it; anything else is stream for print.\n\ |
569 \n\ | |
570 If there is no error, point does not move. If there is an error,\n\ | |
571 point remains at the end of the last character read from the buffer.") | |
572 (bufname, printflag) | |
573 Lisp_Object bufname, printflag; | |
574 { | |
575 int count = specpdl_ptr - specpdl; | |
576 Lisp_Object tem, buf; | |
577 | |
673 | 578 if (NILP (bufname)) |
672 | 579 buf = Fcurrent_buffer (); |
580 else | |
581 buf = Fget_buffer (bufname); | |
673 | 582 if (NILP (buf)) |
672 | 583 error ("No such buffer."); |
584 | |
673 | 585 if (NILP (printflag)) |
672 | 586 tem = Qsymbolp; |
587 else | |
588 tem = printflag; | |
589 specbind (Qstandard_output, tem); | |
590 record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
591 BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); | |
673 | 592 readevalloop (buf, 0, Feval, !NILP (printflag)); |
672 | 593 unbind_to (count); |
594 | |
595 return Qnil; | |
596 } | |
597 | |
598 #if 0 | |
341 | 599 DEFUN ("eval-current-buffer", Feval_current_buffer, Seval_current_buffer, 0, 1, "", |
600 "Execute the current buffer as Lisp code.\n\ | |
601 Programs can pass argument PRINTFLAG which controls printing of output:\n\ | |
602 nil means discard it; anything else is stream for print.\n\ | |
603 \n\ | |
604 If there is no error, point does not move. If there is an error,\n\ | |
605 point remains at the end of the last character read from the buffer.") | |
606 (printflag) | |
607 Lisp_Object printflag; | |
608 { | |
609 int count = specpdl_ptr - specpdl; | |
610 Lisp_Object tem; | |
611 | |
485 | 612 if (NILP (printflag)) |
341 | 613 tem = Qsymbolp; |
614 else | |
615 tem = printflag; | |
616 specbind (Qstandard_output, tem); | |
617 record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
618 SET_PT (BEGV); | |
485 | 619 readevalloop (Fcurrent_buffer (), 0, Feval, !NILP (printflag)); |
341 | 620 return unbind_to (count, Qnil); |
621 } | |
672 | 622 #endif |
341 | 623 |
624 DEFUN ("eval-region", Feval_region, Seval_region, 2, 3, "r", | |
625 "Execute the region as Lisp code.\n\ | |
626 When called from programs, expects two arguments,\n\ | |
627 giving starting and ending indices in the current buffer\n\ | |
628 of the text to be executed.\n\ | |
629 Programs can pass third argument PRINTFLAG which controls output:\n\ | |
630 nil means discard it; anything else is stream for printing it.\n\ | |
631 \n\ | |
632 If there is no error, point does not move. If there is an error,\n\ | |
633 point remains at the end of the last character read from the buffer.") | |
634 (b, e, printflag) | |
635 Lisp_Object b, e, printflag; | |
636 { | |
637 int count = specpdl_ptr - specpdl; | |
638 Lisp_Object tem; | |
639 | |
485 | 640 if (NILP (printflag)) |
341 | 641 tem = Qsymbolp; |
642 else | |
643 tem = printflag; | |
644 specbind (Qstandard_output, tem); | |
645 | |
485 | 646 if (NILP (printflag)) |
341 | 647 record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
648 record_unwind_protect (save_restriction_restore, save_restriction_save ()); | |
649 | |
650 /* This both uses b and checks its type. */ | |
651 Fgoto_char (b); | |
652 Fnarrow_to_region (make_number (BEGV), e); | |
485 | 653 readevalloop (Fcurrent_buffer (), 0, Feval, !NILP (printflag)); |
341 | 654 |
655 return unbind_to (count, Qnil); | |
656 } | |
657 | |
658 #endif /* standalone */ | |
659 | |
660 DEFUN ("read", Fread, Sread, 0, 1, 0, | |
661 "Read one Lisp expression as text from STREAM, return as Lisp object.\n\ | |
662 If STREAM is nil, use the value of `standard-input' (which see).\n\ | |
663 STREAM or the value of `standard-input' may be:\n\ | |
664 a buffer (read from point and advance it)\n\ | |
665 a marker (read from where it points and advance it)\n\ | |
666 a function (call it with no arguments for each character,\n\ | |
667 call it with a char as argument to push a char back)\n\ | |
668 a string (takes text from string, starting at the beginning)\n\ | |
669 t (read text line using minibuffer and use it).") | |
670 (readcharfun) | |
671 Lisp_Object readcharfun; | |
672 { | |
673 extern Lisp_Object Fread_minibuffer (); | |
674 | |
485 | 675 if (NILP (readcharfun)) |
341 | 676 readcharfun = Vstandard_input; |
677 if (EQ (readcharfun, Qt)) | |
678 readcharfun = Qread_char; | |
679 | |
680 #ifndef standalone | |
681 if (EQ (readcharfun, Qread_char)) | |
682 return Fread_minibuffer (build_string ("Lisp expression: "), Qnil); | |
683 #endif | |
684 | |
685 if (XTYPE (readcharfun) == Lisp_String) | |
686 return Fcar (Fread_from_string (readcharfun, Qnil, Qnil)); | |
687 | |
688 return read0 (readcharfun); | |
689 } | |
690 | |
691 DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0, | |
692 "Read one Lisp expression which is represented as text by STRING.\n\ | |
693 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\ | |
694 START and END optionally delimit a substring of STRING from which to read;\n\ | |
695 they default to 0 and (length STRING) respectively.") | |
696 (string, start, end) | |
697 Lisp_Object string, start, end; | |
698 { | |
699 int startval, endval; | |
700 Lisp_Object tem; | |
701 | |
702 CHECK_STRING (string,0); | |
703 | |
485 | 704 if (NILP (end)) |
341 | 705 endval = XSTRING (string)->size; |
706 else | |
707 { CHECK_NUMBER (end,2); | |
708 endval = XINT (end); | |
709 if (endval < 0 || endval > XSTRING (string)->size) | |
710 args_out_of_range (string, end); | |
711 } | |
712 | |
485 | 713 if (NILP (start)) |
341 | 714 startval = 0; |
715 else | |
716 { CHECK_NUMBER (start,1); | |
717 startval = XINT (start); | |
718 if (startval < 0 || startval > endval) | |
719 args_out_of_range (string, start); | |
720 } | |
721 | |
722 read_from_string_index = startval; | |
723 read_from_string_limit = endval; | |
724 | |
725 tem = read0 (string); | |
726 return Fcons (tem, make_number (read_from_string_index)); | |
727 } | |
728 | |
729 /* Use this for recursive reads, in contexts where internal tokens are not allowed. */ | |
730 | |
731 static Lisp_Object | |
732 read0 (readcharfun) | |
733 Lisp_Object readcharfun; | |
734 { | |
735 register Lisp_Object val; | |
736 char c; | |
737 | |
738 val = read1 (readcharfun); | |
739 if (XTYPE (val) == Lisp_Internal) | |
740 { | |
741 c = XINT (val); | |
742 return Fsignal (Qinvalid_read_syntax, Fcons (make_string (&c, 1), Qnil)); | |
743 } | |
744 | |
745 return val; | |
746 } | |
747 | |
748 static int read_buffer_size; | |
749 static char *read_buffer; | |
750 | |
751 static int | |
752 read_escape (readcharfun) | |
753 Lisp_Object readcharfun; | |
754 { | |
755 register int c = READCHAR; | |
756 switch (c) | |
757 { | |
758 case 'a': | |
485 | 759 return '\007'; |
341 | 760 case 'b': |
761 return '\b'; | |
762 case 'e': | |
763 return 033; | |
764 case 'f': | |
765 return '\f'; | |
766 case 'n': | |
767 return '\n'; | |
768 case 'r': | |
769 return '\r'; | |
770 case 't': | |
771 return '\t'; | |
772 case 'v': | |
773 return '\v'; | |
774 case '\n': | |
775 return -1; | |
776 | |
777 case 'M': | |
778 c = READCHAR; | |
779 if (c != '-') | |
780 error ("Invalid escape character syntax"); | |
781 c = READCHAR; | |
782 if (c == '\\') | |
783 c = read_escape (readcharfun); | |
784 return c | 0200; | |
785 | |
786 case 'C': | |
787 c = READCHAR; | |
788 if (c != '-') | |
789 error ("Invalid escape character syntax"); | |
790 case '^': | |
791 c = READCHAR; | |
792 if (c == '\\') | |
793 c = read_escape (readcharfun); | |
794 if (c == '?') | |
795 return 0177; | |
796 else | |
797 return (c & (0200 | 037)); | |
798 | |
799 case '0': | |
800 case '1': | |
801 case '2': | |
802 case '3': | |
803 case '4': | |
804 case '5': | |
805 case '6': | |
806 case '7': | |
807 /* An octal escape, as in ANSI C. */ | |
808 { | |
809 register int i = c - '0'; | |
810 register int count = 0; | |
811 while (++count < 3) | |
812 { | |
813 if ((c = READCHAR) >= '0' && c <= '7') | |
814 { | |
815 i *= 8; | |
816 i += c - '0'; | |
817 } | |
818 else | |
819 { | |
820 UNREAD (c); | |
821 break; | |
822 } | |
823 } | |
824 return i; | |
825 } | |
826 | |
827 case 'x': | |
828 /* A hex escape, as in ANSI C. */ | |
829 { | |
830 int i = 0; | |
831 while (1) | |
832 { | |
833 c = READCHAR; | |
834 if (c >= '0' && c <= '9') | |
835 { | |
836 i *= 16; | |
837 i += c - '0'; | |
838 } | |
839 else if ((c >= 'a' && c <= 'f') | |
840 || (c >= 'A' && c <= 'F')) | |
841 { | |
842 i *= 16; | |
843 if (c >= 'a' && c <= 'f') | |
844 i += c - 'a' + 10; | |
845 else | |
846 i += c - 'A' + 10; | |
847 } | |
848 else | |
849 { | |
850 UNREAD (c); | |
851 break; | |
852 } | |
853 } | |
854 return i; | |
855 } | |
856 | |
857 default: | |
858 return c; | |
859 } | |
860 } | |
861 | |
862 static Lisp_Object | |
863 read1 (readcharfun) | |
864 register Lisp_Object readcharfun; | |
865 { | |
866 register int c; | |
867 | |
868 retry: | |
869 | |
870 c = READCHAR; | |
871 if (c < 0) return Fsignal (Qend_of_file, Qnil); | |
872 | |
873 switch (c) | |
874 { | |
875 case '(': | |
876 return read_list (0, readcharfun); | |
877 | |
878 case '[': | |
879 return read_vector (readcharfun); | |
880 | |
881 case ')': | |
882 case ']': | |
883 { | |
884 register Lisp_Object val; | |
885 XSET (val, Lisp_Internal, c); | |
886 return val; | |
887 } | |
888 | |
889 case '#': | |
373
7c6f74ef31a3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
364
diff
changeset
|
890 c = READCHAR; |
7c6f74ef31a3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
364
diff
changeset
|
891 if (c == '[') |
7c6f74ef31a3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
364
diff
changeset
|
892 { |
7c6f74ef31a3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
364
diff
changeset
|
893 /* Accept compiled functions at read-time so that we don't have to |
7c6f74ef31a3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
364
diff
changeset
|
894 build them using function calls. */ |
7c6f74ef31a3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
364
diff
changeset
|
895 Lisp_Object tmp = read_vector (readcharfun); |
7c6f74ef31a3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
364
diff
changeset
|
896 return Fmake_byte_code (XVECTOR(tmp)->size, XVECTOR (tmp)->contents); |
7c6f74ef31a3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
364
diff
changeset
|
897 } |
7c6f74ef31a3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
364
diff
changeset
|
898 UNREAD (c); |
341 | 899 return Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil)); |
900 | |
901 case ';': | |
902 while ((c = READCHAR) >= 0 && c != '\n'); | |
903 goto retry; | |
904 | |
905 case '\'': | |
906 { | |
907 return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil)); | |
908 } | |
909 | |
910 case '?': | |
911 { | |
912 register Lisp_Object val; | |
913 | |
914 c = READCHAR; | |
915 if (c < 0) return Fsignal (Qend_of_file, Qnil); | |
916 | |
917 if (c == '\\') | |
918 XSET (val, Lisp_Int, read_escape (readcharfun)); | |
919 else | |
920 XSET (val, Lisp_Int, c); | |
921 | |
922 return val; | |
923 } | |
924 | |
925 case '\"': | |
926 { | |
927 register char *p = read_buffer; | |
928 register char *end = read_buffer + read_buffer_size; | |
929 register int c; | |
930 int cancel = 0; | |
931 | |
932 while ((c = READCHAR) >= 0 | |
933 && c != '\"') | |
934 { | |
935 if (p == end) | |
936 { | |
937 char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2); | |
938 p += new - read_buffer; | |
939 read_buffer += new - read_buffer; | |
940 end = read_buffer + read_buffer_size; | |
941 } | |
942 if (c == '\\') | |
943 c = read_escape (readcharfun); | |
944 /* c is -1 if \ newline has just been seen */ | |
945 if (c < 0) | |
946 { | |
947 if (p == read_buffer) | |
948 cancel = 1; | |
949 } | |
950 else | |
951 *p++ = c; | |
952 } | |
953 if (c < 0) return Fsignal (Qend_of_file, Qnil); | |
954 | |
955 /* If purifying, and string starts with \ newline, | |
956 return zero instead. This is for doc strings | |
604 | 957 that we are really going to find in etc/DOC.nn.nn */ |
485 | 958 if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel) |
341 | 959 return make_number (0); |
960 | |
961 if (read_pure) | |
962 return make_pure_string (read_buffer, p - read_buffer); | |
963 else | |
964 return make_string (read_buffer, p - read_buffer); | |
965 } | |
966 | |
762 | 967 case '.': |
968 { | |
969 #ifdef LISP_FLOAT_TYPE | |
970 /* If a period is followed by a number, then we should read it | |
971 as a floating point number. Otherwise, it denotes a dotted | |
972 pair. */ | |
973 int next_char = READCHAR; | |
974 UNREAD (next_char); | |
975 | |
976 if (! isdigit (next_char)) | |
977 #endif | |
978 { | |
979 register Lisp_Object val; | |
980 XSET (val, Lisp_Internal, c); | |
981 return val; | |
982 } | |
983 | |
984 /* Otherwise, we fall through! Note that the atom-reading loop | |
985 below will now loop at least once, assuring that we will not | |
986 try to UNREAD two characters in a row. */ | |
987 } | |
341 | 988 default: |
989 if (c <= 040) goto retry; | |
990 { | |
991 register char *p = read_buffer; | |
992 | |
993 { | |
994 register char *end = read_buffer + read_buffer_size; | |
995 | |
996 while (c > 040 && | |
997 !(c == '\"' || c == '\'' || c == ';' || c == '?' | |
998 || c == '(' || c == ')' | |
762 | 999 #ifndef LISP_FLOAT_TYPE |
1000 /* If we have floating-point support, then we need | |
1001 to allow <digits><dot><digits>. */ | |
341 | 1002 || c =='.' |
1003 #endif /* not LISP_FLOAT_TYPE */ | |
1004 || c == '[' || c == ']' || c == '#' | |
1005 )) | |
1006 { | |
1007 if (p == end) | |
1008 { | |
1009 register char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2); | |
1010 p += new - read_buffer; | |
1011 read_buffer += new - read_buffer; | |
1012 end = read_buffer + read_buffer_size; | |
1013 } | |
1014 if (c == '\\') | |
1015 c = READCHAR; | |
1016 *p++ = c; | |
1017 c = READCHAR; | |
1018 } | |
1019 | |
1020 if (p == end) | |
1021 { | |
1022 char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2); | |
1023 p += new - read_buffer; | |
1024 read_buffer += new - read_buffer; | |
1025 /* end = read_buffer + read_buffer_size; */ | |
1026 } | |
1027 *p = 0; | |
1028 if (c >= 0) | |
1029 UNREAD (c); | |
1030 } | |
1031 | |
1032 /* Is it an integer? */ | |
1033 { | |
1034 register char *p1; | |
1035 register Lisp_Object val; | |
1036 p1 = read_buffer; | |
1037 if (*p1 == '+' || *p1 == '-') p1++; | |
1038 if (p1 != p) | |
1039 { | |
1040 while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++; | |
1041 if (p1 == p) | |
1042 /* It is. */ | |
1043 { | |
1044 XSET (val, Lisp_Int, atoi (read_buffer)); | |
1045 return val; | |
1046 } | |
1047 } | |
1048 #ifdef LISP_FLOAT_TYPE | |
1049 if (isfloat_string (read_buffer)) | |
1050 return make_float (atof (read_buffer)); | |
1051 #endif | |
1052 } | |
1053 | |
1054 return intern (read_buffer); | |
1055 } | |
1056 } | |
1057 } | |
1058 | |
1059 #ifdef LISP_FLOAT_TYPE | |
1060 | |
1061 #define LEAD_INT 1 | |
1062 #define DOT_CHAR 2 | |
1063 #define TRAIL_INT 4 | |
1064 #define E_CHAR 8 | |
1065 #define EXP_INT 16 | |
1066 | |
1067 int | |
1068 isfloat_string (cp) | |
1069 register char *cp; | |
1070 { | |
1071 register state; | |
1072 | |
1073 state = 0; | |
1074 if (*cp == '+' || *cp == '-') | |
1075 cp++; | |
1076 | |
1077 if (isdigit(*cp)) | |
1078 { | |
1079 state |= LEAD_INT; | |
1080 while (isdigit (*cp)) | |
1081 cp ++; | |
1082 } | |
1083 if (*cp == '.') | |
1084 { | |
1085 state |= DOT_CHAR; | |
1086 cp++; | |
1087 } | |
1088 if (isdigit(*cp)) | |
1089 { | |
1090 state |= TRAIL_INT; | |
1091 while (isdigit (*cp)) | |
1092 cp++; | |
1093 } | |
1094 if (*cp == 'e') | |
1095 { | |
1096 state |= E_CHAR; | |
1097 cp++; | |
1098 } | |
1099 if ((*cp == '+') || (*cp == '-')) | |
1100 cp++; | |
1101 | |
1102 if (isdigit (*cp)) | |
1103 { | |
1104 state |= EXP_INT; | |
1105 while (isdigit (*cp)) | |
1106 cp++; | |
1107 } | |
1108 return (*cp == 0 | |
1109 && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT) | |
826 | 1110 || state == (DOT_CHAR|TRAIL_INT) |
341 | 1111 || state == (LEAD_INT|E_CHAR|EXP_INT) |
826 | 1112 || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT) |
1113 || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT))); | |
341 | 1114 } |
1115 #endif /* LISP_FLOAT_TYPE */ | |
1116 | |
1117 static Lisp_Object | |
1118 read_vector (readcharfun) | |
1119 Lisp_Object readcharfun; | |
1120 { | |
1121 register int i; | |
1122 register int size; | |
1123 register Lisp_Object *ptr; | |
1124 register Lisp_Object tem, vector; | |
1125 register struct Lisp_Cons *otem; | |
1126 Lisp_Object len; | |
1127 | |
1128 tem = read_list (1, readcharfun); | |
1129 len = Flength (tem); | |
1130 vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil)); | |
1131 | |
1132 | |
1133 size = XVECTOR (vector)->size; | |
1134 ptr = XVECTOR (vector)->contents; | |
1135 for (i = 0; i < size; i++) | |
1136 { | |
1137 ptr[i] = read_pure ? Fpurecopy (Fcar (tem)) : Fcar (tem); | |
1138 otem = XCONS (tem); | |
1139 tem = Fcdr (tem); | |
1140 free_cons (otem); | |
1141 } | |
1142 return vector; | |
1143 } | |
1144 | |
1145 /* flag = 1 means check for ] to terminate rather than ) and . | |
1146 flag = -1 means check for starting with defun | |
1147 and make structure pure. */ | |
1148 | |
1149 static Lisp_Object | |
1150 read_list (flag, readcharfun) | |
1151 int flag; | |
1152 register Lisp_Object readcharfun; | |
1153 { | |
1154 /* -1 means check next element for defun, | |
1155 0 means don't check, | |
1156 1 means already checked and found defun. */ | |
1157 int defunflag = flag < 0 ? -1 : 0; | |
1158 Lisp_Object val, tail; | |
1159 register Lisp_Object elt, tem; | |
1160 struct gcpro gcpro1, gcpro2; | |
1161 | |
1162 val = Qnil; | |
1163 tail = Qnil; | |
1164 | |
1165 while (1) | |
1166 { | |
1167 GCPRO2 (val, tail); | |
1168 elt = read1 (readcharfun); | |
1169 UNGCPRO; | |
1170 if (XTYPE (elt) == Lisp_Internal) | |
1171 { | |
1172 if (flag > 0) | |
1173 { | |
1174 if (XINT (elt) == ']') | |
1175 return val; | |
1176 return Fsignal (Qinvalid_read_syntax, Fcons (make_string (") or . in a vector", 18), Qnil)); | |
1177 } | |
1178 if (XINT (elt) == ')') | |
1179 return val; | |
1180 if (XINT (elt) == '.') | |
1181 { | |
1182 GCPRO2 (val, tail); | |
485 | 1183 if (!NILP (tail)) |
341 | 1184 XCONS (tail)->cdr = read0 (readcharfun); |
1185 else | |
1186 val = read0 (readcharfun); | |
1187 elt = read1 (readcharfun); | |
1188 UNGCPRO; | |
1189 if (XTYPE (elt) == Lisp_Internal && XINT (elt) == ')') | |
1190 return val; | |
1191 return Fsignal (Qinvalid_read_syntax, Fcons (make_string (". in wrong context", 18), Qnil)); | |
1192 } | |
1193 return Fsignal (Qinvalid_read_syntax, Fcons (make_string ("] in a list", 11), Qnil)); | |
1194 } | |
1195 tem = (read_pure && flag <= 0 | |
1196 ? pure_cons (elt, Qnil) | |
1197 : Fcons (elt, Qnil)); | |
485 | 1198 if (!NILP (tail)) |
341 | 1199 XCONS (tail)->cdr = tem; |
1200 else | |
1201 val = tem; | |
1202 tail = tem; | |
1203 if (defunflag < 0) | |
1204 defunflag = EQ (elt, Qdefun); | |
1205 else if (defunflag > 0) | |
1206 read_pure = 1; | |
1207 } | |
1208 } | |
1209 | |
1210 Lisp_Object Vobarray; | |
1211 Lisp_Object initial_obarray; | |
1212 | |
1213 Lisp_Object | |
1214 check_obarray (obarray) | |
1215 Lisp_Object obarray; | |
1216 { | |
1217 while (XTYPE (obarray) != Lisp_Vector || XVECTOR (obarray)->size == 0) | |
1218 { | |
1219 /* If Vobarray is now invalid, force it to be valid. */ | |
1220 if (EQ (Vobarray, obarray)) Vobarray = initial_obarray; | |
1221 | |
1222 obarray = wrong_type_argument (Qvectorp, obarray); | |
1223 } | |
1224 return obarray; | |
1225 } | |
1226 | |
1227 static int hash_string (); | |
1228 Lisp_Object oblookup (); | |
1229 | |
1230 Lisp_Object | |
1231 intern (str) | |
1232 char *str; | |
1233 { | |
1234 Lisp_Object tem; | |
1235 int len = strlen (str); | |
1236 Lisp_Object obarray = Vobarray; | |
1237 | |
1238 if (XTYPE (obarray) != Lisp_Vector || XVECTOR (obarray)->size == 0) | |
1239 obarray = check_obarray (obarray); | |
1240 tem = oblookup (obarray, str, len); | |
1241 if (XTYPE (tem) == Lisp_Symbol) | |
1242 return tem; | |
485 | 1243 return Fintern ((!NILP (Vpurify_flag) |
341 | 1244 ? make_pure_string (str, len) |
1245 : make_string (str, len)), | |
1246 obarray); | |
1247 } | |
1248 | |
1249 DEFUN ("intern", Fintern, Sintern, 1, 2, 0, | |
1250 "Return the canonical symbol whose name is STRING.\n\ | |
1251 If there is none, one is created by this function and returned.\n\ | |
1252 A second optional argument specifies the obarray to use;\n\ | |
1253 it defaults to the value of `obarray'.") | |
1254 (str, obarray) | |
1255 Lisp_Object str, obarray; | |
1256 { | |
1257 register Lisp_Object tem, sym, *ptr; | |
1258 | |
485 | 1259 if (NILP (obarray)) obarray = Vobarray; |
341 | 1260 obarray = check_obarray (obarray); |
1261 | |
1262 CHECK_STRING (str, 0); | |
1263 | |
1264 tem = oblookup (obarray, XSTRING (str)->data, XSTRING (str)->size); | |
1265 if (XTYPE (tem) != Lisp_Int) | |
1266 return tem; | |
1267 | |
485 | 1268 if (!NILP (Vpurify_flag)) |
341 | 1269 str = Fpurecopy (str); |
1270 sym = Fmake_symbol (str); | |
1271 | |
1272 ptr = &XVECTOR (obarray)->contents[XINT (tem)]; | |
1273 if (XTYPE (*ptr) == Lisp_Symbol) | |
1274 XSYMBOL (sym)->next = XSYMBOL (*ptr); | |
1275 else | |
1276 XSYMBOL (sym)->next = 0; | |
1277 *ptr = sym; | |
1278 return sym; | |
1279 } | |
1280 | |
1281 DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0, | |
1282 "Return the canonical symbol whose name is STRING, or nil if none exists.\n\ | |
1283 A second optional argument specifies the obarray to use;\n\ | |
1284 it defaults to the value of `obarray'.") | |
1285 (str, obarray) | |
1286 Lisp_Object str, obarray; | |
1287 { | |
1288 register Lisp_Object tem; | |
1289 | |
485 | 1290 if (NILP (obarray)) obarray = Vobarray; |
341 | 1291 obarray = check_obarray (obarray); |
1292 | |
1293 CHECK_STRING (str, 0); | |
1294 | |
1295 tem = oblookup (obarray, XSTRING (str)->data, XSTRING (str)->size); | |
1296 if (XTYPE (tem) != Lisp_Int) | |
1297 return tem; | |
1298 return Qnil; | |
1299 } | |
1300 | |
1301 Lisp_Object | |
1302 oblookup (obarray, ptr, size) | |
1303 Lisp_Object obarray; | |
1304 register char *ptr; | |
1305 register int size; | |
1306 { | |
1307 int hash, obsize; | |
1308 register Lisp_Object tail; | |
1309 Lisp_Object bucket, tem; | |
1310 | |
1311 if (XTYPE (obarray) != Lisp_Vector || | |
1312 (obsize = XVECTOR (obarray)->size) == 0) | |
1313 { | |
1314 obarray = check_obarray (obarray); | |
1315 obsize = XVECTOR (obarray)->size; | |
1316 } | |
1317 /* Combining next two lines breaks VMS C 2.3. */ | |
1318 hash = hash_string (ptr, size); | |
1319 hash %= obsize; | |
1320 bucket = XVECTOR (obarray)->contents[hash]; | |
1321 if (XFASTINT (bucket) == 0) | |
1322 ; | |
1323 else if (XTYPE (bucket) != Lisp_Symbol) | |
1324 error ("Bad data in guts of obarray"); /* Like CADR error message */ | |
1325 else for (tail = bucket; ; XSET (tail, Lisp_Symbol, XSYMBOL (tail)->next)) | |
1326 { | |
1327 if (XSYMBOL (tail)->name->size == size && | |
1328 !bcmp (XSYMBOL (tail)->name->data, ptr, size)) | |
1329 return tail; | |
1330 else if (XSYMBOL (tail)->next == 0) | |
1331 break; | |
1332 } | |
1333 XSET (tem, Lisp_Int, hash); | |
1334 return tem; | |
1335 } | |
1336 | |
1337 static int | |
1338 hash_string (ptr, len) | |
1339 unsigned char *ptr; | |
1340 int len; | |
1341 { | |
1342 register unsigned char *p = ptr; | |
1343 register unsigned char *end = p + len; | |
1344 register unsigned char c; | |
1345 register int hash = 0; | |
1346 | |
1347 while (p != end) | |
1348 { | |
1349 c = *p++; | |
1350 if (c >= 0140) c -= 40; | |
1351 hash = ((hash<<3) + (hash>>28) + c); | |
1352 } | |
1353 return hash & 07777777777; | |
1354 } | |
1355 | |
1356 void | |
1357 map_obarray (obarray, fn, arg) | |
1358 Lisp_Object obarray; | |
1359 int (*fn) (); | |
1360 Lisp_Object arg; | |
1361 { | |
1362 register int i; | |
1363 register Lisp_Object tail; | |
1364 CHECK_VECTOR (obarray, 1); | |
1365 for (i = XVECTOR (obarray)->size - 1; i >= 0; i--) | |
1366 { | |
1367 tail = XVECTOR (obarray)->contents[i]; | |
1368 if (XFASTINT (tail) != 0) | |
1369 while (1) | |
1370 { | |
1371 (*fn) (tail, arg); | |
1372 if (XSYMBOL (tail)->next == 0) | |
1373 break; | |
1374 XSET (tail, Lisp_Symbol, XSYMBOL (tail)->next); | |
1375 } | |
1376 } | |
1377 } | |
1378 | |
1379 mapatoms_1 (sym, function) | |
1380 Lisp_Object sym, function; | |
1381 { | |
1382 call1 (function, sym); | |
1383 } | |
1384 | |
1385 DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0, | |
1386 "Call FUNCTION on every symbol in OBARRAY.\n\ | |
1387 OBARRAY defaults to the value of `obarray'.") | |
1388 (function, obarray) | |
1389 Lisp_Object function, obarray; | |
1390 { | |
1391 Lisp_Object tem; | |
1392 | |
485 | 1393 if (NILP (obarray)) obarray = Vobarray; |
341 | 1394 obarray = check_obarray (obarray); |
1395 | |
1396 map_obarray (obarray, mapatoms_1, function); | |
1397 return Qnil; | |
1398 } | |
1399 | |
1400 #define OBARRAY_SIZE 509 | |
1401 | |
1402 void | |
1403 init_obarray () | |
1404 { | |
1405 Lisp_Object oblength; | |
1406 int hash; | |
1407 Lisp_Object *tem; | |
1408 | |
1409 XFASTINT (oblength) = OBARRAY_SIZE; | |
1410 | |
1411 Qnil = Fmake_symbol (make_pure_string ("nil", 3)); | |
1412 Vobarray = Fmake_vector (oblength, make_number (0)); | |
1413 initial_obarray = Vobarray; | |
1414 staticpro (&initial_obarray); | |
1415 /* Intern nil in the obarray */ | |
1416 /* These locals are to kludge around a pyramid compiler bug. */ | |
1417 hash = hash_string ("nil", 3); | |
1418 /* Separate statement here to avoid VAXC bug. */ | |
1419 hash %= OBARRAY_SIZE; | |
1420 tem = &XVECTOR (Vobarray)->contents[hash]; | |
1421 *tem = Qnil; | |
1422 | |
1423 Qunbound = Fmake_symbol (make_pure_string ("unbound", 7)); | |
1424 XSYMBOL (Qnil)->function = Qunbound; | |
1425 XSYMBOL (Qunbound)->value = Qunbound; | |
1426 XSYMBOL (Qunbound)->function = Qunbound; | |
1427 | |
1428 Qt = intern ("t"); | |
1429 XSYMBOL (Qnil)->value = Qnil; | |
1430 XSYMBOL (Qnil)->plist = Qnil; | |
1431 XSYMBOL (Qt)->value = Qt; | |
1432 | |
1433 /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */ | |
1434 Vpurify_flag = Qt; | |
1435 | |
1436 Qvariable_documentation = intern ("variable-documentation"); | |
1437 | |
1438 read_buffer_size = 100; | |
1439 read_buffer = (char *) malloc (read_buffer_size); | |
1440 } | |
1441 | |
1442 void | |
1443 defsubr (sname) | |
1444 struct Lisp_Subr *sname; | |
1445 { | |
1446 Lisp_Object sym; | |
1447 sym = intern (sname->symbol_name); | |
1448 XSET (XSYMBOL (sym)->function, Lisp_Subr, sname); | |
1449 } | |
1450 | |
1451 #ifdef NOTDEF /* use fset in subr.el now */ | |
1452 void | |
1453 defalias (sname, string) | |
1454 struct Lisp_Subr *sname; | |
1455 char *string; | |
1456 { | |
1457 Lisp_Object sym; | |
1458 sym = intern (string); | |
1459 XSET (XSYMBOL (sym)->function, Lisp_Subr, sname); | |
1460 } | |
1461 #endif /* NOTDEF */ | |
1462 | |
1463 /* New replacement for DefIntVar; it ignores the doc string argument | |
1464 on the assumption that make-docfile will handle that. */ | |
1465 /* Define an "integer variable"; a symbol whose value is forwarded | |
1466 to a C variable of type int. Sample call: */ | |
1467 /* DEFVARINT ("indent-tabs-mode", &indent_tabs_mode, "Documentation"); */ | |
1468 | |
1469 void | |
1470 defvar_int (namestring, address, doc) | |
1471 char *namestring; | |
1472 int *address; | |
1473 char *doc; | |
1474 { | |
1475 Lisp_Object sym; | |
1476 sym = intern (namestring); | |
1477 XSET (XSYMBOL (sym)->value, Lisp_Intfwd, address); | |
1478 } | |
1479 | |
1480 /* Similar but define a variable whose value is T if address contains 1, | |
1481 NIL if address contains 0 */ | |
1482 | |
1483 void | |
1484 defvar_bool (namestring, address, doc) | |
1485 char *namestring; | |
1486 int *address; | |
1487 char *doc; | |
1488 { | |
1489 Lisp_Object sym; | |
1490 sym = intern (namestring); | |
1491 XSET (XSYMBOL (sym)->value, Lisp_Boolfwd, address); | |
1492 } | |
1493 | |
1494 /* Similar but define a variable whose value is the Lisp Object stored at address. */ | |
1495 | |
1496 void | |
1497 defvar_lisp (namestring, address, doc) | |
1498 char *namestring; | |
1499 Lisp_Object *address; | |
1500 char *doc; | |
1501 { | |
1502 Lisp_Object sym; | |
1503 sym = intern (namestring); | |
1504 XSET (XSYMBOL (sym)->value, Lisp_Objfwd, address); | |
1505 staticpro (address); | |
1506 } | |
1507 | |
1508 /* Similar but don't request gc-marking of the C variable. | |
1509 Used when that variable will be gc-marked for some other reason, | |
1510 since marking the same slot twice can cause trouble with strings. */ | |
1511 | |
1512 void | |
1513 defvar_lisp_nopro (namestring, address, doc) | |
1514 char *namestring; | |
1515 Lisp_Object *address; | |
1516 char *doc; | |
1517 { | |
1518 Lisp_Object sym; | |
1519 sym = intern (namestring); | |
1520 XSET (XSYMBOL (sym)->value, Lisp_Objfwd, address); | |
1521 } | |
1522 | |
1523 #ifndef standalone | |
1524 | |
1525 /* Similar but define a variable whose value is the Lisp Object stored in | |
1526 the current buffer. address is the address of the slot in the buffer that is current now. */ | |
1527 | |
1528 void | |
1009
bf78b5ea9b3a
* lread.c (defvar_per_buffer): Support new TYPE argument, by
Jim Blandy <jimb@redhat.com>
parents:
851
diff
changeset
|
1529 defvar_per_buffer (namestring, address, type, doc) |
341 | 1530 char *namestring; |
1531 Lisp_Object *address; | |
1009
bf78b5ea9b3a
* lread.c (defvar_per_buffer): Support new TYPE argument, by
Jim Blandy <jimb@redhat.com>
parents:
851
diff
changeset
|
1532 Lisp_Object type; |
341 | 1533 char *doc; |
1534 { | |
1535 Lisp_Object sym; | |
1536 int offset; | |
1537 extern struct buffer buffer_local_symbols; | |
1538 | |
1539 sym = intern (namestring); | |
1540 offset = (char *)address - (char *)current_buffer; | |
1541 | |
1542 XSET (XSYMBOL (sym)->value, Lisp_Buffer_Objfwd, | |
1543 (Lisp_Object *) offset); | |
1544 *(Lisp_Object *)(offset + (char *)&buffer_local_symbols) = sym; | |
1009
bf78b5ea9b3a
* lread.c (defvar_per_buffer): Support new TYPE argument, by
Jim Blandy <jimb@redhat.com>
parents:
851
diff
changeset
|
1545 *(Lisp_Object *)(offset + (char *)&buffer_local_types) = type; |
341 | 1546 if (*(int *)(offset + (char *)&buffer_local_flags) == 0) |
1547 /* Did a DEFVAR_PER_BUFFER without initializing the corresponding | |
1548 slot of buffer_local_flags */ | |
1549 abort (); | |
1550 } | |
1551 | |
1552 #endif /* standalone */ | |
1553 | |
364 | 1554 init_lread () |
341 | 1555 { |
617 | 1556 char *normal; |
341 | 1557 |
364 | 1558 /* Compute the default load-path. */ |
617 | 1559 #ifdef CANNOT_DUMP |
1560 normal = PATH_LOADSEARCH; | |
638 | 1561 Vload_path = decode_env_path (0, normal); |
617 | 1562 #else |
1563 if (NILP (Vpurify_flag)) | |
1564 normal = PATH_LOADSEARCH; | |
1565 else | |
1566 normal = PATH_DUMPLOADSEARCH; | |
1567 | |
1568 /* In a dumped Emacs, we normally have to reset the value of | |
1569 Vload_path from PATH_LOADSEARCH, since the value that was dumped | |
1570 uses ../lisp, instead of the path of the installed elisp | |
1571 libraries. However, if it appears that Vload_path was changed | |
1572 from the default before dumping, don't override that value. */ | |
621 | 1573 if (initialized) |
1574 { | |
1575 Lisp_Object dump_path; | |
617 | 1576 |
638 | 1577 dump_path = decode_env_path (0, PATH_DUMPLOADSEARCH); |
621 | 1578 if (! NILP (Fequal (dump_path, Vload_path))) |
638 | 1579 Vload_path = decode_env_path (0, normal); |
621 | 1580 } |
1581 else | |
638 | 1582 Vload_path = decode_env_path (0, normal); |
364 | 1583 #endif |
1584 | |
341 | 1585 /* Warn if dirs in the *standard* path don't exist. */ |
617 | 1586 { |
1587 Lisp_Object path_tail; | |
341 | 1588 |
617 | 1589 for (path_tail = Vload_path; |
1590 !NILP (path_tail); | |
1591 path_tail = XCONS (path_tail)->cdr) | |
1592 { | |
1593 Lisp_Object dirfile; | |
1594 dirfile = Fcar (path_tail); | |
1595 if (XTYPE (dirfile) == Lisp_String) | |
1596 { | |
1597 dirfile = Fdirectory_file_name (dirfile); | |
1598 if (access (XSTRING (dirfile)->data, 0) < 0) | |
1599 printf ("Warning: lisp library (%s) does not exist.\n", | |
1600 XSTRING (Fcar (path_tail))->data); | |
1601 } | |
1602 } | |
1603 } | |
1604 | |
1605 /* If the EMACSLOADPATH environment variable is set, use its value. | |
1606 This doesn't apply if we're dumping. */ | |
1607 if (NILP (Vpurify_flag) | |
1608 && egetenv ("EMACSLOADPATH")) | |
364 | 1609 Vload_path = decode_env_path ("EMACSLOADPATH", normal); |
1610 | |
1611 Vvalues = Qnil; | |
1612 | |
341 | 1613 load_in_progress = 0; |
1614 } | |
1615 | |
1616 void | |
364 | 1617 syms_of_lread () |
341 | 1618 { |
1619 defsubr (&Sread); | |
1620 defsubr (&Sread_from_string); | |
1621 defsubr (&Sintern); | |
1622 defsubr (&Sintern_soft); | |
1623 defsubr (&Sload); | |
672 | 1624 defsubr (&Seval_buffer); |
341 | 1625 defsubr (&Seval_region); |
1626 defsubr (&Sread_char); | |
1627 defsubr (&Sread_char_exclusive); | |
1628 defsubr (&Sread_event); | |
1629 defsubr (&Sget_file_char); | |
1630 defsubr (&Smapatoms); | |
1631 | |
1632 DEFVAR_LISP ("obarray", &Vobarray, | |
1633 "Symbol table for use by `intern' and `read'.\n\ | |
1634 It is a vector whose length ought to be prime for best results.\n\ | |
1635 The vector's contents don't make sense if examined from Lisp programs;\n\ | |
1636 to find all the symbols in an obarray, use `mapatoms'."); | |
1637 | |
1638 DEFVAR_LISP ("values", &Vvalues, | |
1639 "List of values of all expressions which were read, evaluated and printed.\n\ | |
1640 Order is reverse chronological."); | |
1641 | |
1642 DEFVAR_LISP ("standard-input", &Vstandard_input, | |
1643 "Stream for read to get input from.\n\ | |
1644 See documentation of `read' for possible values."); | |
1645 Vstandard_input = Qt; | |
1646 | |
1647 DEFVAR_LISP ("load-path", &Vload_path, | |
1648 "*List of directories to search for files to load.\n\ | |
1649 Each element is a string (directory name) or nil (try default directory).\n\ | |
1650 Initialized based on EMACSLOADPATH environment variable, if any,\n\ | |
1651 otherwise to default specified in by file `paths.h' when Emacs was built."); | |
1652 | |
1653 DEFVAR_BOOL ("load-in-progress", &load_in_progress, | |
1654 "Non-nil iff inside of `load'."); | |
1655 | |
1656 DEFVAR_LISP ("after-load-alist", &Vafter_load_alist, | |
1657 "An alist of expressions to be evalled when particular files are loaded.\n\ | |
1658 Each element looks like (FILENAME FORMS...).\n\ | |
1659 When `load' is run and the file-name argument is FILENAME,\n\ | |
1660 the FORMS in the corresponding element are executed at the end of loading.\n\n\ | |
1661 FILENAME must match exactly! Normally FILENAME is the name of a library,\n\ | |
1662 with no directory specified, since that is how `load' is normally called.\n\ | |
1663 An error in FORMS does not undo the load,\n\ | |
1664 but does prevent execution of the rest of the FORMS."); | |
1665 Vafter_load_alist = Qnil; | |
1666 | |
1667 Qstandard_input = intern ("standard-input"); | |
1668 staticpro (&Qstandard_input); | |
1669 | |
1670 Qread_char = intern ("read-char"); | |
1671 staticpro (&Qread_char); | |
1672 | |
1673 Qget_file_char = intern ("get-file-char"); | |
1674 staticpro (&Qget_file_char); | |
1675 } |