1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24: #include <config.h>
25: #include <stdio.h>
26: #include <sys/types.h>
27: #include <sys/stat.h>
28: #include <sys/file.h>
29: #include <errno.h>
30: #include "lisp.h"
31: #include "intervals.h"
32: #include "buffer.h"
33: #include "charset.h"
34: #include <epaths.h>
35: #include "commands.h"
36: #include "keyboard.h"
37: #include "termhooks.h"
38: #include "coding.h"
39: #include "blockinput.h"
40:
41: #ifdef lint
42: #include <sys/inode.h>
43: #endif
44:
45: #ifdef MSDOS
46: #if __DJGPP__ < 2
47: #include <unistd.h>
48: #endif
49: #include "msdos.h"
50: #endif
51:
52: #ifdef HAVE_UNISTD_H
53: #include <unistd.h>
54: #endif
55:
56: #ifndef X_OK
57: #define X_OK 01
58: #endif
59:
60: #include <math.h>
61:
62: #ifdef HAVE_SETLOCALE
63: #include <locale.h>
64: #endif
65:
66: #ifdef HAVE_FCNTL_H
67: #include <fcntl.h>
68: #endif
69: #ifndef O_RDONLY
70: #define O_RDONLY 0
71: #endif
72:
73: #ifdef HAVE_FSEEKO
74: #define file_offset off_t
75: #define file_tell ftello
76: #else
77: #define file_offset long
78: #define file_tell ftell
79: #endif
80:
81: #ifndef USE_CRT_DLL
82: extern int errno;
83: #endif
84:
85: Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list;
86: Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist;
87: Lisp_Object Qascii_character, Qload, Qload_file_name;
88: Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
89: Lisp_Object Qinhibit_file_name_operation;
90: Lisp_Object Qeval_buffer_list, Veval_buffer_list;
91: Lisp_Object Qfile_truename, Qdo_after_load_evaluation;
92:
93: extern Lisp_Object Qevent_symbol_element_mask;
94: extern Lisp_Object Qfile_exists_p;
95:
96:
97: int load_in_progress;
98:
99:
100: Lisp_Object Vsource_directory;
101:
102:
103: Lisp_Object Vload_path, Vload_suffixes, Vload_file_rep_suffixes;
104:
105:
106: Lisp_Object Vuser_init_file;
107:
108:
109:
110: Lisp_Object Vload_history;
111:
112:
113: Lisp_Object Vcurrent_load_list;
114:
115:
116: Lisp_Object Vpreloaded_file_list;
117:
118:
119: Lisp_Object Vload_file_name;
120:
121:
122: Lisp_Object Vload_read_function;
123:
124:
125:
126:
127:
128: Lisp_Object read_objects;
129:
130:
131: static int load_force_doc_strings;
132:
133:
134: static int load_convert_to_unibyte;
135:
136:
137:
138: Lisp_Object Vload_source_file_function;
139:
140:
141: Lisp_Object Vbyte_boolean_vars;
142:
143:
144:
145: Lisp_Object Vread_with_symbol_positions;
146:
147:
148: Lisp_Object Vread_symbol_positions_list;
149:
150:
151: static Lisp_Object load_descriptor_list;
152:
153:
154: static FILE *instream;
155:
156:
157: static int read_pure;
158:
159:
160: static int read_from_string_index;
161: static int read_from_string_index_byte;
162: static int read_from_string_limit;
163:
164:
165:
166: static int readchar_backlog;
167:
168:
169: static int readchar_count;
170:
171:
172: static char *saved_doc_string;
173:
174: static int saved_doc_string_size;
175:
176: static int saved_doc_string_length;
177:
178: static file_offset saved_doc_string_position;
179:
180:
181:
182:
183: static char *prev_saved_doc_string;
184:
185: static int prev_saved_doc_string_size;
186:
187: static int prev_saved_doc_string_length;
188:
189: static file_offset prev_saved_doc_string_position;
190:
191:
192:
193:
194:
195: static int new_backquote_flag;
196:
197:
198:
199:
200: static Lisp_Object Vloads_in_progress;
201:
202:
203:
204: int load_dangerous_libraries;
205:
206:
207:
208: static Lisp_Object Vbytecomp_version_regexp;
209:
210: static void to_multibyte P_ ((char **, char **, int *));
211: static void readevalloop P_ ((Lisp_Object, FILE*, Lisp_Object,
212: Lisp_Object (*) (), int,
213: Lisp_Object, Lisp_Object,
214: Lisp_Object, Lisp_Object));
215: static Lisp_Object load_unwind P_ ((Lisp_Object));
216: static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object));
217:
218: static void invalid_syntax P_ ((const char *, int)) NO_RETURN;
219: static void end_of_file_error P_ (()) NO_RETURN;
220:
221: ^L
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236: #define READCHAR readchar (readcharfun)
237: #define UNREAD(c) unreadchar (readcharfun, c)
238:
239: static int
240: readchar (readcharfun)
241: Lisp_Object readcharfun;
242: {
243: Lisp_Object tem;
244: register int c;
245:
246: readchar_count++;
247:
248: if (BUFFERP (readcharfun))
249: {
250: register struct buffer *inbuffer = XBUFFER (readcharfun);
251:
252: int pt_byte = BUF_PT_BYTE (inbuffer);
253: int orig_pt_byte = pt_byte;
254:
255: if (readchar_backlog > 0)
256:
257:
258:
259:
260: return *(BUF_BYTE_ADDRESS (inbuffer, BUF_PT_BYTE (inbuffer) - 1)
261: - --readchar_backlog);
262:
263: if (pt_byte >= BUF_ZV_BYTE (inbuffer))
264: return -1;
265:
266: readchar_backlog = -1;
267:
268: if (! NILP (inbuffer->enable_multibyte_characters))
269: {
270:
271: unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte);
272: BUF_INC_POS (inbuffer, pt_byte);
273: c = STRING_CHAR (p, pt_byte - orig_pt_byte);
274: }
275: else
276: {
277: c = BUF_FETCH_BYTE (inbuffer, pt_byte);
278: pt_byte++;
279: }
280: SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte);
281:
282: return c;
283: }
284: if (MARKERP (readcharfun))
285: {
286: register struct buffer *inbuffer = XMARKER (readcharfun)->buffer;
287:
288: int bytepos = marker_byte_position (readcharfun);
289: int orig_bytepos = bytepos;
290:
291: if (readchar_backlog > 0)
292:
293:
294:
295:
296: return *(BUF_BYTE_ADDRESS (inbuffer, XMARKER (readcharfun)->bytepos - 1)
297: - --readchar_backlog);
298:
299: if (bytepos >= BUF_ZV_BYTE (inbuffer))
300: return -1;
301:
302: readchar_backlog = -1;
303:
304: if (! NILP (inbuffer->enable_multibyte_characters))
305: {
306:
307: unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos);
308: BUF_INC_POS (inbuffer, bytepos);
309: c = STRING_CHAR (p, bytepos - orig_bytepos);
310: }
311: else
312: {
313: c = BUF_FETCH_BYTE (inbuffer, bytepos);
314: bytepos++;
315: }
316:
317: XMARKER (readcharfun)->bytepos = bytepos;
318: XMARKER (readcharfun)->charpos++;
319:
320: return c;
321: }
322:
323: if (EQ (readcharfun, Qlambda))
324: return read_bytecode_char (0);
325:
326: if (EQ (readcharfun, Qget_file_char))
327: {
328: BLOCK_INPUT;
329: c = getc (instream);
330: #ifdef EINTR
331:
332: while (c == EOF && ferror (instream) && errno == EINTR)
333: {
334: UNBLOCK_INPUT;
335: QUIT;
336: BLOCK_INPUT;
337: clearerr (instream);
338: c = getc (instream);
339: }
340: #endif
341: UNBLOCK_INPUT;
342: return c;
343: }
344:
345: if (STRINGP (readcharfun))
346: {
347: if (read_from_string_index >= read_from_string_limit)
348: c = -1;
349: else
350: FETCH_STRING_CHAR_ADVANCE (c, readcharfun,
351: read_from_string_index,
352: read_from_string_index_byte);
353:
354: return c;
355: }
356:
357: tem = call0 (readcharfun);
358:
359: if (NILP (tem))
360: return -1;
361: return XINT (tem);
362: }
363:
364:
365:
366:
367: static void
368: unreadchar (readcharfun, c)
369: Lisp_Object readcharfun;
370: int c;
371: {
372: readchar_count--;
373: if (c == -1)
374:
375:
376: ;
377: else if (BUFFERP (readcharfun))
378: {
379: struct buffer *b = XBUFFER (readcharfun);
380: int bytepos = BUF_PT_BYTE (b);
381:
382: if (readchar_backlog >= 0)
383: readchar_backlog++;
384: else
385: {
386: BUF_PT (b)--;
387: if (! NILP (b->enable_multibyte_characters))
388: BUF_DEC_POS (b, bytepos);
389: else
390: bytepos--;
391:
392: BUF_PT_BYTE (b) = bytepos;
393: }
394: }
395: else if (MARKERP (readcharfun))
396: {
397: struct buffer *b = XMARKER (readcharfun)->buffer;
398: int bytepos = XMARKER (readcharfun)->bytepos;
399:
400: if (readchar_backlog >= 0)
401: readchar_backlog++;
402: else
403: {
404: XMARKER (readcharfun)->charpos--;
405: if (! NILP (b->enable_multibyte_characters))
406: BUF_DEC_POS (b, bytepos);
407: else
408: bytepos--;
409:
410: XMARKER (readcharfun)->bytepos = bytepos;
411: }
412: }
413: else if (STRINGP (readcharfun))
414: {
415: read_from_string_index--;
416: read_from_string_index_byte
417: = string_char_to_byte (readcharfun, read_from_string_index);
418: }
419: else if (EQ (readcharfun, Qlambda))
420: read_bytecode_char (1);
421: else if (EQ (readcharfun, Qget_file_char))
422: {
423: BLOCK_INPUT;
424: ungetc (c, instream);
425: UNBLOCK_INPUT;
426: }
427: else
428: call1 (readcharfun, make_number (c));
429: }
430:
431: static Lisp_Object read_internal_start P_ ((Lisp_Object, Lisp_Object,
432: Lisp_Object));
433: static Lisp_Object read0 P_ ((Lisp_Object));
434: static Lisp_Object read1 P_ ((Lisp_Object, int *, int));
435:
436: static Lisp_Object read_list P_ ((int, Lisp_Object));
437: static Lisp_Object read_vector P_ ((Lisp_Object, int));
438: static int read_multibyte P_ ((int, Lisp_Object));
439:
440: static Lisp_Object substitute_object_recurse P_ ((Lisp_Object, Lisp_Object,
441: Lisp_Object));
442: static void substitute_object_in_subtree P_ ((Lisp_Object,
443: Lisp_Object));
444: static void substitute_in_interval P_ ((INTERVAL, Lisp_Object));
445:
446: ^L
447:
448:
449: extern Lisp_Object read_char ();
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472: Lisp_Object
473: read_filtered_event (no_switch_frame, ascii_required, error_nonascii,
474: input_method, seconds)
475: int no_switch_frame, ascii_required, error_nonascii, input_method;
476: Lisp_Object seconds;
477: {
478: Lisp_Object val, delayed_switch_frame;
479: EMACS_TIME end_time;
480:
481: #ifdef HAVE_WINDOW_SYSTEM
482: if (display_hourglass_p)
483: cancel_hourglass ();
484: #endif
485:
486: delayed_switch_frame = Qnil;
487:
488:
489: if (NUMBERP (seconds))
490: {
491: EMACS_TIME wait_time;
492: int sec, usec;
493: double duration = extract_float (seconds);
494:
495: sec = (int) duration;
496: usec = (duration - sec) * 1000000;
497: EMACS_GET_TIME (end_time);
498: EMACS_SET_SECS_USECS (wait_time, sec, usec);
499: EMACS_ADD_TIME (end_time, end_time, wait_time);
500: }
501:
502:
503: retry:
504: val = read_char (0, 0, 0, (input_method ? Qnil : Qt), 0,
505: NUMBERP (seconds) ? &end_time : NULL);
506:
507: if (BUFFERP (val))
508: goto retry;
509:
510:
511:
512:
513:
514:
515: if (no_switch_frame
516: && EVENT_HAS_PARAMETERS (val)
517: && EQ (EVENT_HEAD_KIND (EVENT_HEAD (val)), Qswitch_frame))
518: {
519: delayed_switch_frame = val;
520: goto retry;
521: }
522:
523: if (ascii_required && !(NUMBERP (seconds) && NILP (val)))
524: {
525:
526: if (SYMBOLP (val))
527: {
528: Lisp_Object tem, tem1;
529: tem = Fget (val, Qevent_symbol_element_mask);
530: if (!NILP (tem))
531: {
532: tem1 = Fget (Fcar (tem), Qascii_character);
533:
534:
535: if (!NILP (tem1))
536: XSETFASTINT (val, XINT (tem1) | XINT (Fcar (Fcdr (tem))));
537: }
538: }
539:
540:
541: if (!INTEGERP (val))
542: {
543: if (error_nonascii)
544: {
545: Vunread_command_events = Fcons (val, Qnil);
546: error ("Non-character input-event");
547: }
548: else
549: goto retry;
550: }
551: }
552:
553: if (! NILP (delayed_switch_frame))
554: unread_switch_frame = delayed_switch_frame;
555:
556: #if 0
557:
558: #ifdef HAVE_WINDOW_SYSTEM
559: if (display_hourglass_p)
560: start_hourglass ();
561: #endif
562:
563: #endif
564:
565: return val;
566: }
567:
568: DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0,
569: doc:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585: )
586: (prompt, inherit_input_method, seconds)
587: Lisp_Object prompt, inherit_input_method, seconds;
588: {
589: if (! NILP (prompt))
590: message_with_string ("%s", prompt, 0);
591: return read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds);
592: }
593:
594: DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0,
595: doc:
596:
597:
598:
599:
600:
601:
602:
603: )
604: (prompt, inherit_input_method, seconds)
605: Lisp_Object prompt, inherit_input_method, seconds;
606: {
607: if (! NILP (prompt))
608: message_with_string ("%s", prompt, 0);
609: return read_filter