Mercurial > emacs
comparison src/lread.c @ 17038:f7a1e78fe210
Include charset.h.
(Vload_source_file_function): New variable.
(Fload): Call Vload_source_file_function if defined while loading
an Emacs Lisp source file. */
(read_multibyte): New function.
(read_escape): Handle multibyte characters.
(read1): Correct the value of size_in_chars of a bool vector.
Handle the case `?' is followed by a multibyte character.
(Vload_source_file_function): New variable.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 20 Feb 1997 06:52:14 +0000 |
parents | 71aff157cff2 |
children | 4a6c43010388 |
comparison
equal
deleted
inserted
replaced
17037:af637c0168ad | 17038:f7a1e78fe210 |
---|---|
28 #include <errno.h> | 28 #include <errno.h> |
29 #include "lisp.h" | 29 #include "lisp.h" |
30 | 30 |
31 #ifndef standalone | 31 #ifndef standalone |
32 #include "buffer.h" | 32 #include "buffer.h" |
33 #include "charset.h" | |
33 #include <paths.h> | 34 #include <paths.h> |
34 #include "commands.h" | 35 #include "commands.h" |
35 #include "keyboard.h" | 36 #include "keyboard.h" |
36 #include "termhooks.h" | 37 #include "termhooks.h" |
37 #endif | 38 #endif |
106 It must be set to nil before all top-level calls to read0. */ | 107 It must be set to nil before all top-level calls to read0. */ |
107 Lisp_Object read_objects; | 108 Lisp_Object read_objects; |
108 | 109 |
109 /* Nonzero means load should forcibly load all dynamic doc strings. */ | 110 /* Nonzero means load should forcibly load all dynamic doc strings. */ |
110 static int load_force_doc_strings; | 111 static int load_force_doc_strings; |
112 | |
113 /* Function to use for loading an Emacs lisp source file (not | |
114 compiled) instead of readevalloop. */ | |
115 Lisp_Object Vload_source_file_function; | |
111 | 116 |
112 /* List of descriptors now open for Fload. */ | 117 /* List of descriptors now open for Fload. */ |
113 static Lisp_Object load_descriptor_list; | 118 static Lisp_Object load_descriptor_list; |
114 | 119 |
115 /* File for get_file_char to read from. Use by load. */ | 120 /* File for get_file_char to read from. Use by load. */ |
137 or worry about what happens to it when there is an error. */ | 142 or worry about what happens to it when there is an error. */ |
138 static int new_backquote_flag; | 143 static int new_backquote_flag; |
139 | 144 |
140 /* Handle unreading and rereading of characters. | 145 /* Handle unreading and rereading of characters. |
141 Write READCHAR to read a character, | 146 Write READCHAR to read a character, |
142 UNREAD(c) to unread c to be read again. */ | 147 UNREAD(c) to unread c to be read again. |
148 | |
149 These macros actually read/unread a byte code, multibyte characters | |
150 are not handled here. The caller should manage them if necessary. | |
151 */ | |
143 | 152 |
144 #define READCHAR readchar (readcharfun) | 153 #define READCHAR readchar (readcharfun) |
145 #define UNREAD(c) unreadchar (readcharfun, c) | 154 #define UNREAD(c) unreadchar (readcharfun, c) |
146 | 155 |
147 static int | 156 static int |
466 message ("Source file `%s' newer than byte-compiled file", | 475 message ("Source file `%s' newer than byte-compiled file", |
467 XSTRING (found)->data); | 476 XSTRING (found)->data); |
468 } | 477 } |
469 XSTRING (found)->data[XSTRING (found)->size - 1] = 'c'; | 478 XSTRING (found)->data[XSTRING (found)->size - 1] = 'c'; |
470 } | 479 } |
480 else | |
481 { | |
482 /* We are loading a source file (*.el). */ | |
483 if (!NILP (Vload_source_file_function)) | |
484 { | |
485 close (fd); | |
486 return call3 (Vload_source_file_function, found, file, | |
487 NILP (noerror) ? Qnil : Qt, | |
488 NILP (nomessage) ? Qnil : Qt); | |
489 } | |
490 } | |
471 | 491 |
472 #ifdef DOS_NT | 492 #ifdef DOS_NT |
473 close (fd); | 493 close (fd); |
474 stream = fopen ((char *) XSTRING (found)->data, dosmode); | 494 stream = fopen ((char *) XSTRING (found)->data, dosmode); |
475 #else /* not DOS_NT */ | 495 #else /* not DOS_NT */ |
1082 return val; | 1102 return val; |
1083 } | 1103 } |
1084 | 1104 |
1085 static int read_buffer_size; | 1105 static int read_buffer_size; |
1086 static char *read_buffer; | 1106 static char *read_buffer; |
1107 | |
1108 /* Read multibyte form and return it as a character. C is a first | |
1109 byte of multibyte form, and rest of them are read from | |
1110 READCHARFUN. */ | |
1111 static int | |
1112 read_multibyte (c, readcharfun) | |
1113 register int c; | |
1114 Lisp_Object readcharfun; | |
1115 { | |
1116 /* We need the actual character code of this multibyte | |
1117 characters. */ | |
1118 unsigned char str[MAX_LENGTH_OF_MULTI_BYTE_FORM]; | |
1119 int len = 0; | |
1120 | |
1121 str[len++] = c; | |
1122 while ((c = READCHAR) >= 0xA0 | |
1123 && len < MAX_LENGTH_OF_MULTI_BYTE_FORM) | |
1124 str[len++] = c; | |
1125 UNREAD (c); | |
1126 return STRING_CHAR (str, len); | |
1127 } | |
1087 | 1128 |
1088 static int | 1129 static int |
1089 read_escape (readcharfun) | 1130 read_escape (readcharfun) |
1090 Lisp_Object readcharfun; | 1131 Lisp_Object readcharfun; |
1091 { | 1132 { |
1237 } | 1278 } |
1238 return i; | 1279 return i; |
1239 } | 1280 } |
1240 | 1281 |
1241 default: | 1282 default: |
1283 if (BASE_LEADING_CODE_P (c)) | |
1284 c = read_multibyte (c, readcharfun); | |
1242 return c; | 1285 return c; |
1243 } | 1286 } |
1244 } | 1287 } |
1245 | 1288 |
1246 /* If the next token is ')' or ']' or '.', we store that character | 1289 /* If the next token is ')' or ']' or '.', we store that character |
1521 | 1564 |
1522 c = READCHAR; | 1565 c = READCHAR; |
1523 if (c < 0) return Fsignal (Qend_of_file, Qnil); | 1566 if (c < 0) return Fsignal (Qend_of_file, Qnil); |
1524 | 1567 |
1525 if (c == '\\') | 1568 if (c == '\\') |
1526 XSETINT (val, read_escape (readcharfun)); | 1569 c = read_escape (readcharfun); |
1527 else | 1570 else if (BASE_LEADING_CODE_P (c)) |
1528 XSETINT (val, c); | 1571 c = read_multibyte (c, readcharfun); |
1572 XSETINT (val, c); | |
1529 | 1573 |
1530 return val; | 1574 return val; |
1531 } | 1575 } |
1532 | 1576 |
1533 case '\"': | 1577 case '\"': |
2594 DEFVAR_LISP ("load-read-function", &Vload_read_function, | 2638 DEFVAR_LISP ("load-read-function", &Vload_read_function, |
2595 "Function used by `load' and `eval-region' for reading expressions.\n\ | 2639 "Function used by `load' and `eval-region' for reading expressions.\n\ |
2596 The default is nil, which means use the function `read'."); | 2640 The default is nil, which means use the function `read'."); |
2597 Vload_read_function = Qnil; | 2641 Vload_read_function = Qnil; |
2598 | 2642 |
2643 DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function, | |
2644 "Function called in `load' for loading an Emacs lisp source file.\n\ | |
2645 This function is for doing code conversion before reading the source file.\n\ | |
2646 If nil, loading is done without any code conversion.\n\ | |
2647 Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\ | |
2648 FULLNAME is the full name of FILE.\n\ | |
2649 See `load' for the meaning of the remaining arguments."); | |
2650 Vload_source_file_function = Qnil; | |
2651 | |
2599 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings, | 2652 DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings, |
2600 "Non-nil means `load' should force-load all dynamic doc strings.\n\ | 2653 "Non-nil means `load' should force-load all dynamic doc strings.\n\ |
2601 This is useful when the file being loaded is a temporary copy."); | 2654 This is useful when the file being loaded is a temporary copy."); |
2602 load_force_doc_strings = 0; | 2655 load_force_doc_strings = 0; |
2603 | 2656 |