diff options
| author | Kenichi Handa | 2002-07-24 10:51:15 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2002-07-24 10:51:15 +0000 |
| commit | 8792be6679372e6ba9908123fb1cf81798b6fd61 (patch) | |
| tree | 70380692661ef6f5bfb1e2515f2e3f2f5c7248ff /src | |
| parent | 571407d6e005f973a75f9db8afcb3f92a203b9b1 (diff) | |
| download | emacs-8792be6679372e6ba9908123fb1cf81798b6fd61.tar.gz emacs-8792be6679372e6ba9908123fb1cf81798b6fd61.zip | |
Include "coding.h".
(Qget_emacs_mule_file_char, Qload_force_doc_strings,
load_each_byte, unread_char): New variables.
(readchar_backlog): This variable deleted.
(readchar): Return a character unless load_each_byte is nonzero.
Handle the case that readcharfun is Qget_emacs_mule_file_char or a
cons. If unread_char is not -1, simply return it.
(unreadchar): Handle the case that readcharfun is
Qget_emacs_mule_file_char or a cons. Set unread_char if
necessary.
(read_multibyte): This function deleted.
(readbyte_for_lambda, readbyte_from_file, readbyte_from_string)
(read_emacs_mule_char): New functions.
(Fload): Even if the file doesn't have the extention ".elc", if
safe_to_load_p returns a positive version number, assume that the
file contains bytecompiled code. If the version is less than 22,
load the file while decoding multibyte sequences by emacs-mule.
(readevalloop): Don't use readchar_backlog.
(Fread): Likewise. Pay attention to the case that STREAM is a
cons.
(Fread_from_string): Pay attention to the case that STREAM is a
cons.
(read_escape): The arg BYTEREP deleted.
(read1): Set load_each_byte to 1 temporarily while handling
#@NUMBER. Don't call read_multibyte.
(read_vector): Call Fread with a cons. If readcharfun is
Qget_emacs_mule_file_char, decode the read string by emacs-mule.
(read_list): If doc_reference is 2, make the cdr part string as
unibyte.
(syms_of_lread): Intern and staticpro Qget_emacs_mule_file_char
and Qload_force_doc_strings.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lread.c | 603 |
1 files changed, 350 insertions, 253 deletions
diff --git a/src/lread.c b/src/lread.c index b4dc71514d9..3d4a6394185 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -31,6 +31,7 @@ Boston, MA 02111-1307, USA. */ | |||
| 31 | #include "buffer.h" | 31 | #include "buffer.h" |
| 32 | #include "character.h" | 32 | #include "character.h" |
| 33 | #include "charset.h" | 33 | #include "charset.h" |
| 34 | #include "coding.h" | ||
| 34 | #include <epaths.h> | 35 | #include <epaths.h> |
| 35 | #include "commands.h" | 36 | #include "commands.h" |
| 36 | #include "keyboard.h" | 37 | #include "keyboard.h" |
| @@ -83,6 +84,12 @@ Lisp_Object Qascii_character, Qload, Qload_file_name; | |||
| 83 | Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction; | 84 | Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction; |
| 84 | Lisp_Object Qinhibit_file_name_operation; | 85 | Lisp_Object Qinhibit_file_name_operation; |
| 85 | 86 | ||
| 87 | /* Used instead of Qget_file_char while loading *.elc files compiled | ||
| 88 | by Emacs 21 or older. */ | ||
| 89 | static Lisp_Object Qget_emacs_mule_file_char; | ||
| 90 | |||
| 91 | static Lisp_Object Qload_force_doc_strings; | ||
| 92 | |||
| 86 | extern Lisp_Object Qevent_symbol_element_mask; | 93 | extern Lisp_Object Qevent_symbol_element_mask; |
| 87 | extern Lisp_Object Qfile_exists_p; | 94 | extern Lisp_Object Qfile_exists_p; |
| 88 | 95 | ||
| @@ -126,6 +133,11 @@ static int load_force_doc_strings; | |||
| 126 | /* Nonzero means read should convert strings to unibyte. */ | 133 | /* Nonzero means read should convert strings to unibyte. */ |
| 127 | static int load_convert_to_unibyte; | 134 | static int load_convert_to_unibyte; |
| 128 | 135 | ||
| 136 | /* Nonzero means READCHAR should read bytes one by one (not character) | ||
| 137 | when READCHARFUN is Qget_file_char or Qget_emacs_mule_file_char. | ||
| 138 | This is set to 1 by read1 temporarily while handling #@NUMBER. */ | ||
| 139 | static int load_each_byte; | ||
| 140 | |||
| 129 | /* Function to use for loading an Emacs lisp source file (not | 141 | /* Function to use for loading an Emacs lisp source file (not |
| 130 | compiled) instead of readevalloop. */ | 142 | compiled) instead of readevalloop. */ |
| 131 | Lisp_Object Vload_source_file_function; | 143 | Lisp_Object Vload_source_file_function; |
| @@ -147,10 +159,6 @@ static int read_from_string_index; | |||
| 147 | static int read_from_string_index_byte; | 159 | static int read_from_string_index_byte; |
| 148 | static int read_from_string_limit; | 160 | static int read_from_string_limit; |
| 149 | 161 | ||
| 150 | /* Number of bytes left to read in the buffer character | ||
| 151 | that `readchar' has already advanced over. */ | ||
| 152 | static int readchar_backlog; | ||
| 153 | |||
| 154 | /* This contains the last string skipped with #@. */ | 162 | /* This contains the last string skipped with #@. */ |
| 155 | static char *saved_doc_string; | 163 | static char *saved_doc_string; |
| 156 | /* Length of buffer allocated in saved_doc_string. */ | 164 | /* Length of buffer allocated in saved_doc_string. */ |
| @@ -190,6 +198,9 @@ int load_dangerous_libraries; | |||
| 190 | 198 | ||
| 191 | static Lisp_Object Vbytecomp_version_regexp; | 199 | static Lisp_Object Vbytecomp_version_regexp; |
| 192 | 200 | ||
| 201 | static int read_emacs_mule_char P_ ((int, int (*) (int, Lisp_Object), | ||
| 202 | Lisp_Object)); | ||
| 203 | |||
| 193 | static void readevalloop P_ ((Lisp_Object, FILE*, Lisp_Object, | 204 | static void readevalloop P_ ((Lisp_Object, FILE*, Lisp_Object, |
| 194 | Lisp_Object (*) (), int, | 205 | Lisp_Object (*) (), int, |
| 195 | Lisp_Object, Lisp_Object)); | 206 | Lisp_Object, Lisp_Object)); |
| @@ -197,23 +208,42 @@ static Lisp_Object load_unwind P_ ((Lisp_Object)); | |||
| 197 | static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object)); | 208 | static Lisp_Object load_descriptor_unwind P_ ((Lisp_Object)); |
| 198 | 209 | ||
| 199 | 210 | ||
| 211 | /* Functions that read one byte from the current source READCHARFUN | ||
| 212 | or unreads one byte. If the integer argument C is -1, it returns | ||
| 213 | one read byte, or -1 when there's no more byte in the source. If C | ||
| 214 | is 0 or positive, it unreads C, and the return value is not | ||
| 215 | interesting. */ | ||
| 216 | |||
| 217 | static int readbyte_for_lambda P_ ((int, Lisp_Object)); | ||
| 218 | static int readbyte_from_file P_ ((int, Lisp_Object)); | ||
| 219 | static int readbyte_from_string P_ ((int, Lisp_Object)); | ||
| 220 | |||
| 200 | /* Handle unreading and rereading of characters. | 221 | /* Handle unreading and rereading of characters. |
| 201 | Write READCHAR to read a character, | 222 | Write READCHAR to read a character, |
| 202 | UNREAD(c) to unread c to be read again. | 223 | UNREAD(c) to unread c to be read again. |
| 203 | 224 | ||
| 204 | These macros actually read/unread a byte code, multibyte characters | 225 | These macros correctly read/unread multibyte characters. */ |
| 205 | are not handled here. The caller should manage them if necessary. | ||
| 206 | */ | ||
| 207 | 226 | ||
| 208 | #define READCHAR readchar (readcharfun) | 227 | #define READCHAR readchar (readcharfun) |
| 209 | #define UNREAD(c) unreadchar (readcharfun, c) | 228 | #define UNREAD(c) unreadchar (readcharfun, c) |
| 210 | 229 | ||
| 230 | /* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char, | ||
| 231 | Qlambda, or a cons, we use this to keep unread character because a | ||
| 232 | file stream can't handle multibyte-char unreading. The value -1 | ||
| 233 | means that there's no unread character. */ | ||
| 234 | static int unread_char; | ||
| 235 | |||
| 236 | |||
| 211 | static int | 237 | static int |
| 212 | readchar (readcharfun) | 238 | readchar (readcharfun) |
| 213 | Lisp_Object readcharfun; | 239 | Lisp_Object readcharfun; |
| 214 | { | 240 | { |
| 215 | Lisp_Object tem; | 241 | Lisp_Object tem; |
| 216 | register int c; | 242 | register int c; |
| 243 | int (*readbyte) P_ ((int, Lisp_Object)); | ||
| 244 | unsigned char buf[MAX_MULTIBYTE_LENGTH]; | ||
| 245 | int i, len; | ||
| 246 | int emacs_mule_encoding = 0; | ||
| 217 | 247 | ||
| 218 | if (BUFFERP (readcharfun)) | 248 | if (BUFFERP (readcharfun)) |
| 219 | { | 249 | { |
| @@ -221,19 +251,9 @@ readchar (readcharfun) | |||
| 221 | 251 | ||
| 222 | int pt_byte = BUF_PT_BYTE (inbuffer); | 252 | int pt_byte = BUF_PT_BYTE (inbuffer); |
| 223 | 253 | ||
| 224 | if (readchar_backlog > 0) | ||
| 225 | /* We get the address of the byte just passed, | ||
| 226 | which is the last byte of the character. | ||
| 227 | The other bytes in this character are consecutive with it, | ||
| 228 | because the gap can't be in the middle of a character. */ | ||
| 229 | return *(BUF_BYTE_ADDRESS (inbuffer, BUF_PT_BYTE (inbuffer) - 1) | ||
| 230 | - --readchar_backlog); | ||
| 231 | |||
| 232 | if (pt_byte >= BUF_ZV_BYTE (inbuffer)) | 254 | if (pt_byte >= BUF_ZV_BYTE (inbuffer)) |
| 233 | return -1; | 255 | return -1; |
| 234 | 256 | ||
| 235 | readchar_backlog = -1; | ||
| 236 | |||
| 237 | if (! NILP (inbuffer->enable_multibyte_characters)) | 257 | if (! NILP (inbuffer->enable_multibyte_characters)) |
| 238 | { | 258 | { |
| 239 | /* Fetch the character code from the buffer. */ | 259 | /* Fetch the character code from the buffer. */ |
| @@ -244,6 +264,8 @@ readchar (readcharfun) | |||
| 244 | else | 264 | else |
| 245 | { | 265 | { |
| 246 | c = BUF_FETCH_BYTE (inbuffer, pt_byte); | 266 | c = BUF_FETCH_BYTE (inbuffer, pt_byte); |
| 267 | if (! ASCII_BYTE_P (c)) | ||
| 268 | c = BYTE8_TO_CHAR (c); | ||
| 247 | pt_byte++; | 269 | pt_byte++; |
| 248 | } | 270 | } |
| 249 | SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte); | 271 | SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte); |
| @@ -256,19 +278,9 @@ readchar (readcharfun) | |||
| 256 | 278 | ||
| 257 | int bytepos = marker_byte_position (readcharfun); | 279 | int bytepos = marker_byte_position (readcharfun); |
| 258 | 280 | ||
| 259 | if (readchar_backlog > 0) | ||
| 260 | /* We get the address of the byte just passed, | ||
| 261 | which is the last byte of the character. | ||
| 262 | The other bytes in this character are consecutive with it, | ||
| 263 | because the gap can't be in the middle of a character. */ | ||
| 264 | return *(BUF_BYTE_ADDRESS (inbuffer, XMARKER (readcharfun)->bytepos - 1) | ||
| 265 | - --readchar_backlog); | ||
| 266 | |||
| 267 | if (bytepos >= BUF_ZV_BYTE (inbuffer)) | 281 | if (bytepos >= BUF_ZV_BYTE (inbuffer)) |
| 268 | return -1; | 282 | return -1; |
| 269 | 283 | ||
| 270 | readchar_backlog = -1; | ||
| 271 | |||
| 272 | if (! NILP (inbuffer->enable_multibyte_characters)) | 284 | if (! NILP (inbuffer->enable_multibyte_characters)) |
| 273 | { | 285 | { |
| 274 | /* Fetch the character code from the buffer. */ | 286 | /* Fetch the character code from the buffer. */ |
| @@ -279,6 +291,8 @@ readchar (readcharfun) | |||
| 279 | else | 291 | else |
| 280 | { | 292 | { |
| 281 | c = BUF_FETCH_BYTE (inbuffer, bytepos); | 293 | c = BUF_FETCH_BYTE (inbuffer, bytepos); |
| 294 | if (! ASCII_BYTE_P (c)) | ||
| 295 | c = BYTE8_TO_CHAR (c); | ||
| 282 | bytepos++; | 296 | bytepos++; |
| 283 | } | 297 | } |
| 284 | 298 | ||
| @@ -289,22 +303,15 @@ readchar (readcharfun) | |||
| 289 | } | 303 | } |
| 290 | 304 | ||
| 291 | if (EQ (readcharfun, Qlambda)) | 305 | if (EQ (readcharfun, Qlambda)) |
| 292 | return read_bytecode_char (0); | 306 | { |
| 293 | 307 | readbyte = readbyte_for_lambda; | |
| 308 | goto read_multibyte; | ||
| 309 | } | ||
| 294 | if (EQ (readcharfun, Qget_file_char)) | 310 | if (EQ (readcharfun, Qget_file_char)) |
| 295 | { | 311 | { |
| 296 | c = getc (instream); | 312 | readbyte = readbyte_from_file; |
| 297 | #ifdef EINTR | 313 | goto read_multibyte; |
| 298 | /* Interrupted reads have been observed while reading over the network */ | ||
| 299 | while (c == EOF && ferror (instream) && errno == EINTR) | ||
| 300 | { | ||
| 301 | clearerr (instream); | ||
| 302 | c = getc (instream); | ||
| 303 | } | ||
| 304 | #endif | ||
| 305 | return c; | ||
| 306 | } | 314 | } |
| 307 | |||
| 308 | if (STRINGP (readcharfun)) | 315 | if (STRINGP (readcharfun)) |
| 309 | { | 316 | { |
| 310 | if (read_from_string_index >= read_from_string_limit) | 317 | if (read_from_string_index >= read_from_string_limit) |
| @@ -316,14 +323,61 @@ readchar (readcharfun) | |||
| 316 | 323 | ||
| 317 | return c; | 324 | return c; |
| 318 | } | 325 | } |
| 326 | if (CONSP (readcharfun)) | ||
| 327 | { | ||
| 328 | /* This is the case that read_vector is reading from a unibyte | ||
| 329 | string that contains a byte sequence previously skipped | ||
| 330 | because of #@NUMBER. The car part of readcharfun is that | ||
| 331 | string, and the cdr part is a value of readcharfun given to | ||
| 332 | read_vector. */ | ||
| 333 | readbyte = readbyte_from_string; | ||
| 334 | if (EQ (XCDR (readcharfun), Qget_emacs_mule_file_char)) | ||
| 335 | emacs_mule_encoding = 1; | ||
| 336 | goto read_multibyte; | ||
| 337 | } | ||
| 338 | if (EQ (readcharfun, Qget_emacs_mule_file_char)) | ||
| 339 | { | ||
| 340 | readbyte = readbyte_from_file; | ||
| 341 | emacs_mule_encoding = 1; | ||
| 342 | goto read_multibyte; | ||
| 343 | } | ||
| 319 | 344 | ||
| 320 | tem = call0 (readcharfun); | 345 | tem = call0 (readcharfun); |
| 321 | 346 | ||
| 322 | if (NILP (tem)) | 347 | if (NILP (tem)) |
| 323 | return -1; | 348 | return -1; |
| 324 | return XINT (tem); | 349 | return XINT (tem); |
| 350 | |||
| 351 | read_multibyte: | ||
| 352 | if (unread_char >= 0) | ||
| 353 | { | ||
| 354 | c = unread_char; | ||
| 355 | unread_char = -1; | ||
| 356 | return c; | ||
| 357 | } | ||
| 358 | c = (*readbyte) (-1, readcharfun); | ||
| 359 | if (c < 0 || ASCII_BYTE_P (c) || load_each_byte) | ||
| 360 | return c; | ||
| 361 | if (emacs_mule_encoding) | ||
| 362 | return read_emacs_mule_char (c, readbyte, readcharfun); | ||
| 363 | i = 0; | ||
| 364 | buf[i++] = c; | ||
| 365 | len = BYTES_BY_CHAR_HEAD (c); | ||
| 366 | while (i < len) | ||
| 367 | { | ||
| 368 | c = (*readbyte) (-1, readcharfun); | ||
| 369 | if (c < 0 || ! TRAILING_CODE_P (c)) | ||
| 370 | { | ||
| 371 | while (--i > 1) | ||
| 372 | (*readbyte) (buf[i], readcharfun); | ||
| 373 | return BYTE8_TO_CHAR (buf[0]); | ||
| 374 | } | ||
| 375 | buf[i++] = c; | ||
| 376 | } | ||
| 377 | return STRING_CHAR (buf, i); | ||
| 325 | } | 378 | } |
| 326 | 379 | ||
| 380 | |||
| 327 | /* Unread the character C in the way appropriate for the stream READCHARFUN. | 381 | /* Unread the character C in the way appropriate for the stream READCHARFUN. |
| 328 | If the stream is a user function, call it with the char as argument. */ | 382 | If the stream is a user function, call it with the char as argument. */ |
| 329 | 383 | ||
| @@ -341,36 +395,26 @@ unreadchar (readcharfun, c) | |||
| 341 | struct buffer *b = XBUFFER (readcharfun); | 395 | struct buffer *b = XBUFFER (readcharfun); |
| 342 | int bytepos = BUF_PT_BYTE (b); | 396 | int bytepos = BUF_PT_BYTE (b); |
| 343 | 397 | ||
| 344 | if (readchar_backlog >= 0) | 398 | BUF_PT (b)--; |
| 345 | readchar_backlog++; | 399 | if (! NILP (b->enable_multibyte_characters)) |
| 400 | BUF_DEC_POS (b, bytepos); | ||
| 346 | else | 401 | else |
| 347 | { | 402 | bytepos--; |
| 348 | BUF_PT (b)--; | ||
| 349 | if (! NILP (b->enable_multibyte_characters)) | ||
| 350 | BUF_DEC_POS (b, bytepos); | ||
| 351 | else | ||
| 352 | bytepos--; | ||
| 353 | 403 | ||
| 354 | BUF_PT_BYTE (b) = bytepos; | 404 | BUF_PT_BYTE (b) = bytepos; |
| 355 | } | ||
| 356 | } | 405 | } |
| 357 | else if (MARKERP (readcharfun)) | 406 | else if (MARKERP (readcharfun)) |
| 358 | { | 407 | { |
| 359 | struct buffer *b = XMARKER (readcharfun)->buffer; | 408 | struct buffer *b = XMARKER (readcharfun)->buffer; |
| 360 | int bytepos = XMARKER (readcharfun)->bytepos; | 409 | int bytepos = XMARKER (readcharfun)->bytepos; |
| 361 | 410 | ||
| 362 | if (readchar_backlog >= 0) | 411 | XMARKER (readcharfun)->charpos--; |
| 363 | readchar_backlog++; | 412 | if (! NILP (b->enable_multibyte_characters)) |
| 413 | BUF_DEC_POS (b, bytepos); | ||
| 364 | else | 414 | else |
| 365 | { | 415 | bytepos--; |
| 366 | XMARKER (readcharfun)->charpos--; | ||
| 367 | if (! NILP (b->enable_multibyte_characters)) | ||
| 368 | BUF_DEC_POS (b, bytepos); | ||
| 369 | else | ||
| 370 | bytepos--; | ||
| 371 | 416 | ||
| 372 | XMARKER (readcharfun)->bytepos = bytepos; | 417 | XMARKER (readcharfun)->bytepos = bytepos; |
| 373 | } | ||
| 374 | } | 418 | } |
| 375 | else if (STRINGP (readcharfun)) | 419 | else if (STRINGP (readcharfun)) |
| 376 | { | 420 | { |
| @@ -378,16 +422,152 @@ unreadchar (readcharfun, c) | |||
| 378 | read_from_string_index_byte | 422 | read_from_string_index_byte |
| 379 | = string_char_to_byte (readcharfun, read_from_string_index); | 423 | = string_char_to_byte (readcharfun, read_from_string_index); |
| 380 | } | 424 | } |
| 425 | else if (CONSP (readcharfun)) | ||
| 426 | { | ||
| 427 | unread_char = c; | ||
| 428 | } | ||
| 381 | else if (EQ (readcharfun, Qlambda)) | 429 | else if (EQ (readcharfun, Qlambda)) |
| 382 | read_bytecode_char (1); | 430 | { |
| 383 | else if (EQ (readcharfun, Qget_file_char)) | 431 | unread_char = c; |
| 384 | ungetc (c, instream); | 432 | } |
| 433 | else if (EQ (readcharfun, Qget_file_char) | ||
| 434 | || EQ (readcharfun, Qget_emacs_mule_file_char)) | ||
| 435 | { | ||
| 436 | if (load_each_byte) | ||
| 437 | ungetc (c, instream); | ||
| 438 | else | ||
| 439 | unread_char = c; | ||
| 440 | } | ||
| 385 | else | 441 | else |
| 386 | call1 (readcharfun, make_number (c)); | 442 | call1 (readcharfun, make_number (c)); |
| 387 | } | 443 | } |
| 388 | 444 | ||
| 445 | static int | ||
| 446 | readbyte_for_lambda (c, readcharfun) | ||
| 447 | int c; | ||
| 448 | Lisp_Object readcharfun; | ||
| 449 | { | ||
| 450 | return read_bytecode_char (c >= 0); | ||
| 451 | } | ||
| 452 | |||
| 453 | |||
| 454 | static int | ||
| 455 | readbyte_from_file (c, readcharfun) | ||
| 456 | int c; | ||
| 457 | Lisp_Object readcharfun; | ||
| 458 | { | ||
| 459 | if (c >= 0) | ||
| 460 | { | ||
| 461 | ungetc (c, instream); | ||
| 462 | return 0; | ||
| 463 | } | ||
| 464 | |||
| 465 | c = getc (instream); | ||
| 466 | #ifdef EINTR | ||
| 467 | /* Interrupted reads have been observed while reading over the network */ | ||
| 468 | while (c == EOF && ferror (instream) && errno == EINTR) | ||
| 469 | { | ||
| 470 | clearerr (instream); | ||
| 471 | c = getc (instream); | ||
| 472 | } | ||
| 473 | #endif | ||
| 474 | return (c == EOF ? -1 : c); | ||
| 475 | } | ||
| 476 | |||
| 477 | static int | ||
| 478 | readbyte_from_string (c, readcharfun) | ||
| 479 | int c; | ||
| 480 | Lisp_Object readcharfun; | ||
| 481 | { | ||
| 482 | Lisp_Object string = XCAR (readcharfun); | ||
| 483 | |||
| 484 | if (c >= 0) | ||
| 485 | { | ||
| 486 | read_from_string_index--; | ||
| 487 | read_from_string_index_byte | ||
| 488 | = string_char_to_byte (string, read_from_string_index); | ||
| 489 | } | ||
| 490 | |||
| 491 | if (read_from_string_index >= read_from_string_limit) | ||
| 492 | c = -1; | ||
| 493 | else | ||
| 494 | FETCH_STRING_CHAR_ADVANCE (c, string, | ||
| 495 | read_from_string_index, | ||
| 496 | read_from_string_index_byte); | ||
| 497 | return c; | ||
| 498 | } | ||
| 499 | |||
| 500 | |||
| 501 | /* Read one non-ASCII character from INSTREAM. The character is | ||
| 502 | encoded in `emacs-mule' and the first byte is already read in | ||
| 503 | C. */ | ||
| 504 | |||
| 505 | extern char emacs_mule_bytes[256]; | ||
| 506 | |||
| 507 | static int | ||
| 508 | read_emacs_mule_char (c, readbyte, readcharfun) | ||
| 509 | int c; | ||
| 510 | int (*readbyte) P_ ((int, Lisp_Object)); | ||
| 511 | Lisp_Object readcharfun; | ||
| 512 | { | ||
| 513 | /* Emacs-mule coding uses at most 4-byte for one character. */ | ||
| 514 | unsigned char buf[4]; | ||
| 515 | int len = emacs_mule_bytes[c]; | ||
| 516 | struct charset *charset; | ||
| 517 | int i; | ||
| 518 | unsigned code; | ||
| 519 | |||
| 520 | if (len == 1) | ||
| 521 | /* C is not a valid leading-code of `emacs-mule'. */ | ||
| 522 | return BYTE8_TO_CHAR (c); | ||
| 523 | |||
| 524 | i = 0; | ||
| 525 | buf[i++] = c; | ||
| 526 | while (i < len) | ||
| 527 | { | ||
| 528 | c = (*readbyte) (-1, readcharfun); | ||
| 529 | if (c < 0xA0) | ||
| 530 | { | ||
| 531 | while (--i > 1) | ||
| 532 | (*readbyte) (buf[i], readcharfun); | ||
| 533 | return BYTE8_TO_CHAR (buf[0]); | ||
| 534 | } | ||
| 535 | buf[i++] = c; | ||
| 536 | } | ||
| 537 | |||
| 538 | if (len == 2) | ||
| 539 | { | ||
| 540 | charset = emacs_mule_charset[c]; | ||
| 541 | code = buf[1] & 0x7F; | ||
| 542 | } | ||
| 543 | else if (len == 3) | ||
| 544 | { | ||
| 545 | if (buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_11 | ||
| 546 | || buf[0] == EMACS_MULE_LEADING_CODE_PRIVATE_12) | ||
| 547 | { | ||
| 548 | charset = emacs_mule_charset[buf[1]]; | ||
| 549 | code = buf[2] & 0x7F; | ||
| 550 | } | ||
| 551 | else | ||
| 552 | { | ||
| 553 | charset = emacs_mule_charset[buf[0]]; | ||
| 554 | code = ((buf[1] << 8) | buf[2]) & 0x7F7F; | ||
| 555 | } | ||
| 556 | } | ||
| 557 | else | ||
| 558 | { | ||
| 559 | charset = emacs_mule_charset[buf[1]]; | ||
| 560 | code = ((buf[2] << 8) | buf[3]) & 0x7F7F; | ||
| 561 | } | ||
| 562 | c = DECODE_CHAR (charset, code); | ||
| 563 | if (c < 0) | ||
| 564 | Fsignal (Qinvalid_read_syntax, | ||
| 565 | Fcons (build_string ("invalid multibyte form"), Qnil)); | ||
| 566 | return c; | ||
| 567 | } | ||
| 568 | |||
| 569 | |||
| 389 | static Lisp_Object read0 (), read1 (), read_list (), read_vector (); | 570 | static Lisp_Object read0 (), read1 (), read_list (), read_vector (); |
| 390 | static int read_multibyte (); | ||
| 391 | static Lisp_Object substitute_object_recurse (); | 571 | static Lisp_Object substitute_object_recurse (); |
| 392 | static void substitute_object_in_subtree (), substitute_in_interval (); | 572 | static void substitute_object_in_subtree (), substitute_in_interval (); |
| 393 | 573 | ||
| @@ -553,11 +733,11 @@ DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0, | |||
| 553 | 733 | ||
| 554 | 734 | ||
| 555 | 735 | ||
| 556 | /* Value is non-zero if the file asswociated with file descriptor FD | 736 | /* Value is a version number of byte compiled code if the file |
| 557 | is a compiled Lisp file that's safe to load. Only files compiled | 737 | associated with file descriptor FD is a compiled Lisp file that's |
| 558 | with Emacs are safe to load. Files compiled with XEmacs can lead | 738 | safe to load. Only files compiled with Emacs are safe to load. |
| 559 | to a crash in Fbyte_code because of an incompatible change in the | 739 | Files compiled with XEmacs can lead to a crash in Fbyte_code |
| 560 | byte compiler. */ | 740 | because of an incompatible change in the byte compiler. */ |
| 561 | 741 | ||
| 562 | static int | 742 | static int |
| 563 | safe_to_load_p (fd) | 743 | safe_to_load_p (fd) |
| @@ -578,7 +758,7 @@ safe_to_load_p (fd) | |||
| 578 | with NUL bytes following it, but note the version. */ | 758 | with NUL bytes following it, but note the version. */ |
| 579 | for (i = 0; i < nbytes && buf[i] != '\n'; ++i) | 759 | for (i = 0; i < nbytes && buf[i] != '\n'; ++i) |
| 580 | if (i == 4) | 760 | if (i == 4) |
| 581 | version = buf[i]; | 761 | version = buf[i]; |
| 582 | 762 | ||
| 583 | if (i < nbytes | 763 | if (i < nbytes |
| 584 | && fast_c_string_match_ignore_case (Vbytecomp_version_regexp, | 764 | && fast_c_string_match_ignore_case (Vbytecomp_version_regexp, |
| @@ -637,6 +817,8 @@ Return t if file exists. */) | |||
| 637 | Lisp_Object handler; | 817 | Lisp_Object handler; |
| 638 | int safe_p = 1; | 818 | int safe_p = 1; |
| 639 | char *fmode = "r"; | 819 | char *fmode = "r"; |
| 820 | int version; | ||
| 821 | |||
| 640 | #ifdef DOS_NT | 822 | #ifdef DOS_NT |
| 641 | fmode = "rt"; | 823 | fmode = "rt"; |
| 642 | #endif /* DOS_NT */ | 824 | #endif /* DOS_NT */ |
| @@ -744,17 +926,20 @@ Return t if file exists. */) | |||
| 744 | Vloads_in_progress = Fcons (found, Vloads_in_progress); | 926 | Vloads_in_progress = Fcons (found, Vloads_in_progress); |
| 745 | } | 927 | } |
| 746 | 928 | ||
| 929 | version = -1; | ||
| 747 | if (!bcmp (&(XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 4]), | 930 | if (!bcmp (&(XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 4]), |
| 748 | ".elc", 4)) | 931 | ".elc", 4) |
| 932 | || (version = safe_to_load_p (fd)) > 0) | ||
| 749 | /* Load .elc files directly, but not when they are | 933 | /* Load .elc files directly, but not when they are |
| 750 | remote and have no handler! */ | 934 | remote and have no handler! */ |
| 751 | { | 935 | { |
| 752 | if (fd != -2) | 936 | if (fd != -2) |
| 753 | { | 937 | { |
| 754 | struct stat s1, s2; | 938 | struct stat s1, s2; |
| 755 | int result, version; | 939 | int result; |
| 756 | 940 | ||
| 757 | if (!(version = safe_to_load_p (fd))) | 941 | if (version < 0 |
| 942 | && ! (version = safe_to_load_p (fd))) | ||
| 758 | { | 943 | { |
| 759 | safe_p = 0; | 944 | safe_p = 0; |
| 760 | if (!load_dangerous_libraries) | 945 | if (!load_dangerous_libraries) |
| @@ -769,30 +954,6 @@ Return t if file exists. */) | |||
| 769 | 954 | ||
| 770 | compiled = 1; | 955 | compiled = 1; |
| 771 | 956 | ||
| 772 | if (version == 20) /* 21 isn't used */ | ||
| 773 | /* We're loading something compiled with Mule 3, 4 or 5, | ||
| 774 | and thus potentially emacs-mule-encoded; load it with | ||
| 775 | code conversion. (Perhaps the test should actually be | ||
| 776 | <22?) We could check further on whether the comment | ||
| 777 | mentions multibyte and only code-convert if it does. I | ||
| 778 | doubt it's worth the effort. -- fx */ | ||
| 779 | { | ||
| 780 | Lisp_Object val; | ||
| 781 | |||
| 782 | if (fd >= 0) | ||
| 783 | emacs_close (fd); | ||
| 784 | /* load-with-code-conversion currently fails with | ||
| 785 | emacs-mule non-ASCII doc strings. */ | ||
| 786 | error ("Can't currently load Emacs 20/1-compiled files: %s", | ||
| 787 | XSTRING (found)->data); | ||
| 788 | #if 0 | ||
| 789 | val = call4 (intern ("load-with-code-conversion"), found, file, | ||
| 790 | NILP (noerror) ? Qnil : Qt, | ||
| 791 | NILP (nomessage) ? Qnil : Qt); | ||
| 792 | #endif | ||
| 793 | return unbind_to (count, val); | ||
| 794 | } | ||
| 795 | |||
| 796 | #ifdef DOS_NT | 957 | #ifdef DOS_NT |
| 797 | fmode = "rb"; | 958 | fmode = "rb"; |
| 798 | #endif /* DOS_NT */ | 959 | #endif /* DOS_NT */ |
| @@ -868,7 +1029,16 @@ Return t if file exists. */) | |||
| 868 | load_descriptor_list | 1029 | load_descriptor_list |
| 869 | = Fcons (make_number (fileno (stream)), load_descriptor_list); | 1030 | = Fcons (make_number (fileno (stream)), load_descriptor_list); |
| 870 | load_in_progress++; | 1031 | load_in_progress++; |
| 871 | readevalloop (Qget_file_char, stream, file, Feval, 0, Qnil, Qnil); | 1032 | if (version >= 22) |
| 1033 | readevalloop (Qget_file_char, stream, file, Feval, 0, Qnil, Qnil); | ||
| 1034 | else | ||
| 1035 | { | ||
| 1036 | /* We can't handle a file which was compiled with | ||
| 1037 | byte-compile-dynamic by older version of Emacs. */ | ||
| 1038 | specbind (Qload_force_doc_strings, Qt); | ||
| 1039 | readevalloop (Qget_emacs_mule_file_char, stream, file, Feval, 0, | ||
| 1040 | Qnil, Qnil); | ||
| 1041 | } | ||
| 872 | unbind_to (count, Qnil); | 1042 | unbind_to (count, Qnil); |
| 873 | 1043 | ||
| 874 | /* Run any load-hooks for this file. */ | 1044 | /* Run any load-hooks for this file. */ |
| @@ -1242,8 +1412,6 @@ readevalloop (readcharfun, stream, sourcename, evalfun, printflag, unibyte, read | |||
| 1242 | record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil); | 1412 | record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil); |
| 1243 | load_convert_to_unibyte = !NILP (unibyte); | 1413 | load_convert_to_unibyte = !NILP (unibyte); |
| 1244 | 1414 | ||
| 1245 | readchar_backlog = -1; | ||
| 1246 | |||
| 1247 | GCPRO1 (sourcename); | 1415 | GCPRO1 (sourcename); |
| 1248 | 1416 | ||
| 1249 | LOADHIST_ATTACH (sourcename); | 1417 | LOADHIST_ATTACH (sourcename); |
| @@ -1423,14 +1591,13 @@ STREAM or the value of `standard-input' may be: | |||
| 1423 | if (EQ (stream, Qt)) | 1591 | if (EQ (stream, Qt)) |
| 1424 | stream = Qread_char; | 1592 | stream = Qread_char; |
| 1425 | 1593 | ||
| 1426 | readchar_backlog = -1; | ||
| 1427 | new_backquote_flag = 0; | 1594 | new_backquote_flag = 0; |
| 1428 | read_objects = Qnil; | 1595 | read_objects = Qnil; |
| 1429 | 1596 | ||
| 1430 | if (EQ (stream, Qread_char)) | 1597 | if (EQ (stream, Qread_char)) |
| 1431 | return Fread_minibuffer (build_string ("Lisp expression: "), Qnil); | 1598 | return Fread_minibuffer (build_string ("Lisp expression: "), Qnil); |
| 1432 | 1599 | ||
| 1433 | if (STRINGP (stream)) | 1600 | if (STRINGP (stream) || ((CONSP (stream) && STRINGP (XCAR (stream))))) |
| 1434 | return Fcar (Fread_from_string (stream, Qnil, Qnil)); | 1601 | return Fcar (Fread_from_string (stream, Qnil, Qnil)); |
| 1435 | 1602 | ||
| 1436 | return read0 (stream); | 1603 | return read0 (stream); |
| @@ -1445,18 +1612,23 @@ START and END optionally delimit a substring of STRING from which to read; | |||
| 1445 | Lisp_Object string, start, end; | 1612 | Lisp_Object string, start, end; |
| 1446 | { | 1613 | { |
| 1447 | int startval, endval; | 1614 | int startval, endval; |
| 1615 | Lisp_Object str; | ||
| 1448 | Lisp_Object tem; | 1616 | Lisp_Object tem; |
| 1449 | 1617 | ||
| 1450 | CHECK_STRING (string); | 1618 | if (CONSP (string)) |
| 1619 | str = XCAR (string); | ||
| 1620 | else | ||
| 1621 | str = string; | ||
| 1622 | CHECK_STRING (str); | ||
| 1451 | 1623 | ||
| 1452 | if (NILP (end)) | 1624 | if (NILP (end)) |
| 1453 | endval = XSTRING (string)->size; | 1625 | endval = XSTRING (str)->size; |
| 1454 | else | 1626 | else |
| 1455 | { | 1627 | { |
| 1456 | CHECK_NUMBER (end); | 1628 | CHECK_NUMBER (end); |
| 1457 | endval = XINT (end); | 1629 | endval = XINT (end); |
| 1458 | if (endval < 0 || endval > XSTRING (string)->size) | 1630 | if (endval < 0 || endval > XSTRING (str)->size) |
| 1459 | args_out_of_range (string, end); | 1631 | args_out_of_range (str, end); |
| 1460 | } | 1632 | } |
| 1461 | 1633 | ||
| 1462 | if (NILP (start)) | 1634 | if (NILP (start)) |
| @@ -1466,11 +1638,11 @@ START and END optionally delimit a substring of STRING from which to read; | |||
| 1466 | CHECK_NUMBER (start); | 1638 | CHECK_NUMBER (start); |
| 1467 | startval = XINT (start); | 1639 | startval = XINT (start); |
| 1468 | if (startval < 0 || startval > endval) | 1640 | if (startval < 0 || startval > endval) |
| 1469 | args_out_of_range (string, start); | 1641 | args_out_of_range (str, start); |
| 1470 | } | 1642 | } |
| 1471 | 1643 | ||
| 1472 | read_from_string_index = startval; | 1644 | read_from_string_index = startval; |
| 1473 | read_from_string_index_byte = string_char_to_byte (string, startval); | 1645 | read_from_string_index_byte = string_char_to_byte (str, startval); |
| 1474 | read_from_string_limit = endval; | 1646 | read_from_string_limit = endval; |
| 1475 | 1647 | ||
| 1476 | new_backquote_flag = 0; | 1648 | new_backquote_flag = 0; |
| @@ -1502,65 +1674,16 @@ read0 (readcharfun) | |||
| 1502 | static int read_buffer_size; | 1674 | static int read_buffer_size; |
| 1503 | static char *read_buffer; | 1675 | static char *read_buffer; |
| 1504 | 1676 | ||
| 1505 | /* Read multibyte form and return it as a character. C is a first | ||
| 1506 | byte of multibyte form, and rest of them are read from | ||
| 1507 | READCHARFUN. Store the byte length of the form into *NBYTES. */ | ||
| 1508 | |||
| 1509 | static int | ||
| 1510 | read_multibyte (c, readcharfun, nbytes) | ||
| 1511 | register int c; | ||
| 1512 | Lisp_Object readcharfun; | ||
| 1513 | int *nbytes; | ||
| 1514 | { | ||
| 1515 | /* We need the actual character code of this multibyte | ||
| 1516 | characters. */ | ||
| 1517 | unsigned char str[MAX_MULTIBYTE_LENGTH]; | ||
| 1518 | int len = 0; | ||
| 1519 | int bytes = BYTES_BY_CHAR_HEAD (c); | ||
| 1520 | |||
| 1521 | str[len++] = c; | ||
| 1522 | while (len < bytes) | ||
| 1523 | { | ||
| 1524 | c = READCHAR; | ||
| 1525 | if (CHAR_HEAD_P (c)) | ||
| 1526 | { | ||
| 1527 | UNREAD (c); | ||
| 1528 | break; | ||
| 1529 | } | ||
| 1530 | str[len++] = c; | ||
| 1531 | } | ||
| 1532 | |||
| 1533 | if (len == bytes && MULTIBYTE_LENGTH_NO_CHECK (str) > 0) | ||
| 1534 | { | ||
| 1535 | *nbytes = len; | ||
| 1536 | return STRING_CHAR (str, len); | ||
| 1537 | } | ||
| 1538 | /* The byte sequence is not valid as multibyte. Unread all bytes | ||
| 1539 | but the first one, and return the first byte. */ | ||
| 1540 | while (--len > 0) | ||
| 1541 | UNREAD (str[len]); | ||
| 1542 | *nbytes = 1; | ||
| 1543 | return str[0]; | ||
| 1544 | } | ||
| 1545 | |||
| 1546 | /* Read a \-escape sequence, assuming we already read the `\'. | 1677 | /* Read a \-escape sequence, assuming we already read the `\'. |
| 1547 | If the escape sequence forces unibyte, store 1 into *BYTEREP. | 1678 | If the escape sequence forces unibyte, return eight-bit-char. */ |
| 1548 | If the escape sequence forces multibyte and the returned character | ||
| 1549 | is raw 8-bit char, store 2 into *BYTEREP. | ||
| 1550 | If the escape sequence forces multibyte and the returned character | ||
| 1551 | is not raw 8-bit char, store 3 into *BYTEREP. | ||
| 1552 | Otherwise store 0 into *BYTEREP. */ | ||
| 1553 | 1679 | ||
| 1554 | static int | 1680 | static int |
| 1555 | read_escape (readcharfun, stringp, byterep) | 1681 | read_escape (readcharfun, stringp) |
| 1556 | Lisp_Object readcharfun; | 1682 | Lisp_Object readcharfun; |
| 1557 | int stringp; | 1683 | int stringp; |
| 1558 | int *byterep; | ||
| 1559 | { | 1684 | { |
| 1560 | register int c = READCHAR; | 1685 | register int c = READCHAR; |
| 1561 | 1686 | ||
| 1562 | *byterep = 0; | ||
| 1563 | |||
| 1564 | switch (c) | 1687 | switch (c) |
| 1565 | { | 1688 | { |
| 1566 | case -1: | 1689 | case -1: |
| @@ -1597,7 +1720,7 @@ read_escape (readcharfun, stringp, byterep) | |||
| 1597 | error ("Invalid escape character syntax"); | 1720 | error ("Invalid escape character syntax"); |
| 1598 | c = READCHAR; | 1721 | c = READCHAR; |
| 1599 | if (c == '\\') | 1722 | if (c == '\\') |
| 1600 | c = read_escape (readcharfun, 0, byterep); | 1723 | c = read_escape (readcharfun, 0); |
| 1601 | return c | meta_modifier; | 1724 | return c | meta_modifier; |
| 1602 | 1725 | ||
| 1603 | case 'S': | 1726 | case 'S': |
| @@ -1606,7 +1729,7 @@ read_escape (readcharfun, stringp, byterep) | |||
| 1606 | error ("Invalid escape character syntax"); | 1729 | error ("Invalid escape character syntax"); |
| 1607 | c = READCHAR; | 1730 | c = READCHAR; |
| 1608 | if (c == '\\') | 1731 | if (c == '\\') |
| 1609 | c = read_escape (readcharfun, 0, byterep); | 1732 | c = read_escape (readcharfun, 0); |
| 1610 | return c | shift_modifier; | 1733 | return c | shift_modifier; |
| 1611 | 1734 | ||
| 1612 | case 'H': | 1735 | case 'H': |
| @@ -1615,7 +1738,7 @@ read_escape (readcharfun, stringp, byterep) | |||
| 1615 | error ("Invalid escape character syntax"); | 1738 | error ("Invalid escape character syntax"); |
| 1616 | c = READCHAR; | 1739 | c = READCHAR; |
| 1617 | if (c == '\\') | 1740 | if (c == '\\') |
| 1618 | c = read_escape (readcharfun, 0, byterep); | 1741 | c = read_escape (readcharfun, 0); |
| 1619 | return c | hyper_modifier; | 1742 | return c | hyper_modifier; |
| 1620 | 1743 | ||
| 1621 | case 'A': | 1744 | case 'A': |
| @@ -1624,7 +1747,7 @@ read_escape (readcharfun, stringp, byterep) | |||
| 1624 | error ("Invalid escape character syntax"); | 1747 | error ("Invalid escape character syntax"); |
| 1625 | c = READCHAR; | 1748 | c = READCHAR; |
| 1626 | if (c == '\\') | 1749 | if (c == '\\') |
| 1627 | c = read_escape (readcharfun, 0, byterep); | 1750 | c = read_escape (readcharfun, 0); |
| 1628 | return c | alt_modifier; | 1751 | return c | alt_modifier; |
| 1629 | 1752 | ||
| 1630 | case 's': | 1753 | case 's': |
| @@ -1633,7 +1756,7 @@ read_escape (readcharfun, stringp, byterep) | |||
| 1633 | error ("Invalid escape character syntax"); | 1756 | error ("Invalid escape character syntax"); |
| 1634 | c = READCHAR; | 1757 | c = READCHAR; |
| 1635 | if (c == '\\') | 1758 | if (c == '\\') |
| 1636 | c = read_escape (readcharfun, 0, byterep); | 1759 | c = read_escape (readcharfun, 0); |
| 1637 | return c | super_modifier; | 1760 | return c | super_modifier; |
| 1638 | 1761 | ||
| 1639 | case 'C': | 1762 | case 'C': |
| @@ -1643,7 +1766,7 @@ read_escape (readcharfun, stringp, byterep) | |||
| 1643 | case '^': | 1766 | case '^': |
| 1644 | c = READCHAR; | 1767 | c = READCHAR; |
| 1645 | if (c == '\\') | 1768 | if (c == '\\') |
| 1646 | c = read_escape (readcharfun, 0, byterep); | 1769 | c = read_escape (readcharfun, 0); |
| 1647 | if ((c & ~CHAR_MODIFIER_MASK) == '?') | 1770 | if ((c & ~CHAR_MODIFIER_MASK) == '?') |
| 1648 | return 0177 | (c & CHAR_MODIFIER_MASK); | 1771 | return 0177 | (c & CHAR_MODIFIER_MASK); |
| 1649 | else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))) | 1772 | else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))) |
| @@ -1683,10 +1806,8 @@ read_escape (readcharfun, stringp, byterep) | |||
| 1683 | } | 1806 | } |
| 1684 | } | 1807 | } |
| 1685 | 1808 | ||
| 1686 | if (c < 0x100) | 1809 | if (! ASCII_BYTE_P (i)) |
| 1687 | *byterep = 1; | 1810 | i = BYTE8_TO_CHAR (i); |
| 1688 | else | ||
| 1689 | *byterep = 3; | ||
| 1690 | return i; | 1811 | return i; |
| 1691 | } | 1812 | } |
| 1692 | 1813 | ||
| @@ -1721,22 +1842,11 @@ read_escape (readcharfun, stringp, byterep) | |||
| 1721 | } | 1842 | } |
| 1722 | 1843 | ||
| 1723 | if (count < 3 && i >= 0x80) | 1844 | if (count < 3 && i >= 0x80) |
| 1724 | *byterep = 2; | 1845 | return BYTE8_TO_CHAR (i); |
| 1725 | else | ||
| 1726 | *byterep = 3; | ||
| 1727 | return i; | 1846 | return i; |
| 1728 | } | 1847 | } |
| 1729 | 1848 | ||
| 1730 | default: | 1849 | default: |
| 1731 | if (EQ (readcharfun, Qget_file_char) | ||
| 1732 | && BASE_LEADING_CODE_P (c)) | ||
| 1733 | { | ||
| 1734 | int nbytes; | ||
| 1735 | |||
| 1736 | c = read_multibyte (c, readcharfun, &nbytes); | ||
| 1737 | if (nbytes > 1) | ||
| 1738 | *byterep = 3; | ||
| 1739 | } | ||
| 1740 | return c; | 1850 | return c; |
| 1741 | } | 1851 | } |
| 1742 | } | 1852 | } |
| @@ -1824,6 +1934,7 @@ read1 (readcharfun, pch, first_in_list) | |||
| 1824 | int uninterned_symbol = 0; | 1934 | int uninterned_symbol = 0; |
| 1825 | 1935 | ||
| 1826 | *pch = 0; | 1936 | *pch = 0; |
| 1937 | load_each_byte = 0; | ||
| 1827 | 1938 | ||
| 1828 | retry: | 1939 | retry: |
| 1829 | 1940 | ||
| @@ -1898,12 +2009,14 @@ read1 (readcharfun, pch, first_in_list) | |||
| 1898 | 2009 | ||
| 1899 | UNREAD (c); | 2010 | UNREAD (c); |
| 1900 | tmp = read1 (readcharfun, pch, first_in_list); | 2011 | tmp = read1 (readcharfun, pch, first_in_list); |
| 1901 | if (size_in_chars != XSTRING (tmp)->size | 2012 | if (STRING_MULTIBYTE (tmp) |
| 1902 | /* We used to print 1 char too many | 2013 | || (size_in_chars != XSTRING (tmp)->size |
| 1903 | when the number of bits was a multiple of 8. | 2014 | /* We used to print 1 char too many |
| 1904 | Accept such input in case it came from an old version. */ | 2015 | when the number of bits was a multiple of 8. |
| 1905 | && ! (XFASTINT (length) | 2016 | Accept such input in case it came from an old |
| 1906 | == (XSTRING (tmp)->size - 1) * BITS_PER_CHAR)) | 2017 | version. */ |
| 2018 | && ! (XFASTINT (length) | ||
| 2019 | == (XSTRING (tmp)->size - 1) * BITS_PER_CHAR))) | ||
| 1907 | Fsignal (Qinvalid_read_syntax, | 2020 | Fsignal (Qinvalid_read_syntax, |
| 1908 | Fcons (make_string ("#&...", 5), Qnil)); | 2021 | Fcons (make_string ("#&...", 5), Qnil)); |
| 1909 | 2022 | ||
| @@ -1969,6 +2082,7 @@ read1 (readcharfun, pch, first_in_list) | |||
| 1969 | { | 2082 | { |
| 1970 | int i, nskip = 0; | 2083 | int i, nskip = 0; |
| 1971 | 2084 | ||
| 2085 | load_each_byte = 1; | ||
| 1972 | /* Read a decimal integer. */ | 2086 | /* Read a decimal integer. */ |
| 1973 | while ((c = READCHAR) >= 0 | 2087 | while ((c = READCHAR) >= 0 |
| 1974 | && c >= '0' && c <= '9') | 2088 | && c >= '0' && c <= '9') |
| @@ -1979,7 +2093,9 @@ read1 (readcharfun, pch, first_in_list) | |||
| 1979 | if (c >= 0) | 2093 | if (c >= 0) |
| 1980 | UNREAD (c); | 2094 | UNREAD (c); |
| 1981 | 2095 | ||
| 1982 | if (load_force_doc_strings && EQ (readcharfun, Qget_file_char)) | 2096 | if (load_force_doc_strings |
| 2097 | && (EQ (readcharfun, Qget_file_char) | ||
| 2098 | || EQ (readcharfun, Qget_emacs_mule_file_char))) | ||
| 1983 | { | 2099 | { |
| 1984 | /* If we are supposed to force doc strings into core right now, | 2100 | /* If we are supposed to force doc strings into core right now, |
| 1985 | record the last string that we skipped, | 2101 | record the last string that we skipped, |
| @@ -2031,6 +2147,7 @@ read1 (readcharfun, pch, first_in_list) | |||
| 2031 | c = READCHAR; | 2147 | c = READCHAR; |
| 2032 | } | 2148 | } |
| 2033 | 2149 | ||
| 2150 | load_each_byte = 0; | ||
| 2034 | goto retry; | 2151 | goto retry; |
| 2035 | } | 2152 | } |
| 2036 | if (c == '$') | 2153 | if (c == '$') |
| @@ -2152,17 +2269,18 @@ read1 (readcharfun, pch, first_in_list) | |||
| 2152 | 2269 | ||
| 2153 | case '?': | 2270 | case '?': |
| 2154 | { | 2271 | { |
| 2155 | int discard; | 2272 | int modifiers; |
| 2156 | 2273 | ||
| 2157 | c = READCHAR; | 2274 | c = READCHAR; |
| 2158 | if (c < 0) | 2275 | if (c < 0) |
| 2159 | end_of_file_error (); | 2276 | end_of_file_error (); |
| 2160 | |||
| 2161 | if (c == '\\') | 2277 | if (c == '\\') |
| 2162 | c = read_escape (readcharfun, 0, &discard); | 2278 | c = read_escape (readcharfun, 0); |
| 2163 | else if (EQ (readcharfun, Qget_file_char) | 2279 | modifiers = c & CHAR_MODIFIER_MASK; |
| 2164 | && BASE_LEADING_CODE_P (c)) | 2280 | c &= ~CHAR_MODIFIER_MASK; |
| 2165 | c = read_multibyte (c, readcharfun, &discard); | 2281 | if (CHAR_BYTE8_P (c)) |
| 2282 | c = CHAR_TO_BYTE8 (c); | ||
| 2283 | c |= modifiers; | ||
| 2166 | 2284 | ||
| 2167 | return make_number (c); | 2285 | return make_number (c); |
| 2168 | } | 2286 | } |
| @@ -2196,9 +2314,8 @@ read1 (readcharfun, pch, first_in_list) | |||
| 2196 | if (c == '\\') | 2314 | if (c == '\\') |
| 2197 | { | 2315 | { |
| 2198 | int modifiers; | 2316 | int modifiers; |
| 2199 | int byterep; | ||
| 2200 | 2317 | ||
| 2201 | c = read_escape (readcharfun, 1, &byterep); | 2318 | c = read_escape (readcharfun, 1); |
| 2202 | 2319 | ||
| 2203 | /* C is -1 if \ newline has just been seen */ | 2320 | /* C is -1 if \ newline has just been seen */ |
| 2204 | if (c == -1) | 2321 | if (c == -1) |
| @@ -2211,26 +2328,11 @@ read1 (readcharfun, pch, first_in_list) | |||
| 2211 | modifiers = c & CHAR_MODIFIER_MASK; | 2328 | modifiers = c & CHAR_MODIFIER_MASK; |
| 2212 | c = c & ~CHAR_MODIFIER_MASK; | 2329 | c = c & ~CHAR_MODIFIER_MASK; |
| 2213 | 2330 | ||
| 2214 | if (byterep == 1) | 2331 | if (CHAR_BYTE8_P (c)) |
| 2215 | { | 2332 | force_singlebyte = 1; |
| 2216 | force_singlebyte = 1; | 2333 | else if (! ASCII_CHAR_P (c)) |
| 2217 | if (c >= 0x80) | 2334 | force_multibyte = 1; |
| 2218 | /* Raw 8-bit code */ | 2335 | else /* i.e. ASCII_CHAR_P (c) */ |
| 2219 | c = BYTE8_TO_CHAR (c); | ||
| 2220 | } | ||
| 2221 | else if (byterep > 1) | ||
| 2222 | { | ||
| 2223 | force_multibyte = 1; | ||
| 2224 | if (byterep == 2) | ||
| 2225 | c = BYTE8_TO_CHAR (c); | ||
| 2226 | } | ||
| 2227 | else if (c >= 0x80) | ||
| 2228 | { | ||
| 2229 | force_singlebyte = 1; | ||
| 2230 | c = BYTE8_TO_CHAR (c); | ||
| 2231 | } | ||
| 2232 | |||
| 2233 | if (ASCII_CHAR_P (c)) | ||
| 2234 | { | 2336 | { |
| 2235 | /* Allow `\C- ' and `\C-?'. */ | 2337 | /* Allow `\C- ' and `\C-?'. */ |
| 2236 | if (modifiers == CHAR_CTL) | 2338 | if (modifiers == CHAR_CTL) |
| @@ -2264,34 +2366,10 @@ read1 (readcharfun, pch, first_in_list) | |||
| 2264 | error ("Invalid modifier in string"); | 2366 | error ("Invalid modifier in string"); |
| 2265 | p += CHAR_STRING (c, (unsigned char *) p); | 2367 | p += CHAR_STRING (c, (unsigned char *) p); |
| 2266 | } | 2368 | } |
| 2267 | else if (c >= 0x80) | 2369 | else |
| 2268 | { | 2370 | { |
| 2269 | if (EQ (readcharfun, Qget_file_char)) | ||
| 2270 | { | ||
| 2271 | if (BASE_LEADING_CODE_P (c)) | ||
| 2272 | { | ||
| 2273 | int nbytes; | ||
| 2274 | c = read_multibyte (c, readcharfun, &nbytes); | ||
| 2275 | if (nbytes > 1) | ||
| 2276 | force_multibyte = 1; | ||
| 2277 | else | ||
| 2278 | { | ||
| 2279 | force_singlebyte = 1; | ||
| 2280 | c = BYTE8_TO_CHAR (c); | ||
| 2281 | } | ||
| 2282 | } | ||
| 2283 | else | ||
| 2284 | { | ||
| 2285 | force_singlebyte = 1; | ||
| 2286 | c = BYTE8_TO_CHAR (c); | ||
| 2287 | } | ||
| 2288 | } | ||
| 2289 | else | ||
| 2290 | force_multibyte = 1; | ||
| 2291 | p += CHAR_STRING (c, (unsigned char *) p); | 2371 | p += CHAR_STRING (c, (unsigned char *) p); |
| 2292 | } | 2372 | } |
| 2293 | else | ||
| 2294 | *p++ = c; | ||
| 2295 | nchars++; | 2373 | nchars++; |
| 2296 | } | 2374 | } |
| 2297 | if (c < 0) | 2375 | if (c < 0) |
| @@ -2371,11 +2449,7 @@ read1 (readcharfun, pch, first_in_list) | |||
| 2371 | quoted = 1; | 2449 | quoted = 1; |
| 2372 | } | 2450 | } |
| 2373 | 2451 | ||
| 2374 | if (! SINGLE_BYTE_CHAR_P (c)) | 2452 | p += CHAR_STRING (c, p); |
| 2375 | p += CHAR_STRING (c, p); | ||
| 2376 | else | ||
| 2377 | *p++ = c; | ||
| 2378 | |||
| 2379 | c = READCHAR; | 2453 | c = READCHAR; |
| 2380 | } | 2454 | } |
| 2381 | 2455 | ||
| @@ -2702,7 +2776,7 @@ read_vector (readcharfun, bytecodeflag) | |||
| 2702 | XSTRING (bytestr)->size = STRING_BYTES (XSTRING (bytestr)); | 2776 | XSTRING (bytestr)->size = STRING_BYTES (XSTRING (bytestr)); |
| 2703 | SET_STRING_BYTES (XSTRING (bytestr), -1); | 2777 | SET_STRING_BYTES (XSTRING (bytestr), -1); |
| 2704 | 2778 | ||
| 2705 | item = Fread (bytestr); | 2779 | item = Fread (Fcons (bytestr, readcharfun)); |
| 2706 | if (!CONSP (item)) | 2780 | if (!CONSP (item)) |
| 2707 | error ("invalid byte code"); | 2781 | error ("invalid byte code"); |
| 2708 | 2782 | ||
| @@ -2715,6 +2789,15 @@ read_vector (readcharfun, bytecodeflag) | |||
| 2715 | /* Now handle the bytecode slot. */ | 2789 | /* Now handle the bytecode slot. */ |
| 2716 | ptr[COMPILED_BYTECODE] = read_pure ? Fpurecopy (bytestr) : bytestr; | 2790 | ptr[COMPILED_BYTECODE] = read_pure ? Fpurecopy (bytestr) : bytestr; |
| 2717 | } | 2791 | } |
| 2792 | else if (i == COMPILED_DOC_STRING | ||
| 2793 | && STRINGP (item) | ||
| 2794 | && ! STRING_MULTIBYTE (item)) | ||
| 2795 | { | ||
| 2796 | if (EQ (readcharfun, Qget_emacs_mule_file_char)) | ||
| 2797 | item = Fdecode_coding_string (item, Qemacs_mule, Qnil, Qnil); | ||
| 2798 | else | ||
| 2799 | item = Fstring_as_multibyte (item); | ||
| 2800 | } | ||
| 2718 | } | 2801 | } |
| 2719 | ptr[i] = read_pure ? Fpurecopy (item) : item; | 2802 | ptr[i] = read_pure ? Fpurecopy (item) : item; |
| 2720 | otem = XCONS (tem); | 2803 | otem = XCONS (tem); |
| @@ -2812,7 +2895,14 @@ read_list (flag, readcharfun) | |||
| 2812 | if (doc_reference == 2) | 2895 | if (doc_reference == 2) |
| 2813 | { | 2896 | { |
| 2814 | /* Get a doc string from the file we are loading. | 2897 | /* Get a doc string from the file we are loading. |
| 2815 | If it's in saved_doc_string, get it from there. */ | 2898 | If it's in saved_doc_string, get it from there. |
| 2899 | |||
| 2900 | Here, we don't know if the string is a | ||
| 2901 | bytecode string or a doc string. As a | ||
| 2902 | bytecode string must be unibyte, we always | ||
| 2903 | return a unibyte string. If it is actually a | ||
| 2904 | doc string, caller must make it | ||
| 2905 | multibyte. */ | ||
| 2816 | int pos = XINT (XCDR (val)); | 2906 | int pos = XINT (XCDR (val)); |
| 2817 | /* Position is negative for user variables. */ | 2907 | /* Position is negative for user variables. */ |
| 2818 | if (pos < 0) pos = -pos; | 2908 | if (pos < 0) pos = -pos; |
| @@ -2844,8 +2934,8 @@ read_list (flag, readcharfun) | |||
| 2844 | saved_doc_string[to++] = c; | 2934 | saved_doc_string[to++] = c; |
| 2845 | } | 2935 | } |
| 2846 | 2936 | ||
| 2847 | return make_string (saved_doc_string + start, | 2937 | return make_unibyte_string (saved_doc_string + start, |
| 2848 | to - start); | 2938 | to - start); |
| 2849 | } | 2939 | } |
| 2850 | /* Look in prev_saved_doc_string the same way. */ | 2940 | /* Look in prev_saved_doc_string the same way. */ |
| 2851 | else if (pos >= prev_saved_doc_string_position | 2941 | else if (pos >= prev_saved_doc_string_position |
| @@ -2876,11 +2966,12 @@ read_list (flag, readcharfun) | |||
| 2876 | prev_saved_doc_string[to++] = c; | 2966 | prev_saved_doc_string[to++] = c; |
| 2877 | } | 2967 | } |
| 2878 | 2968 | ||
| 2879 | return make_string (prev_saved_doc_string + start, | 2969 | return make_unibyte_string (prev_saved_doc_string |
| 2880 | to - start); | 2970 | + start, |
| 2971 | to - start); | ||
| 2881 | } | 2972 | } |
| 2882 | else | 2973 | else |
| 2883 | return get_doc_string (val, 0, 0); | 2974 | return get_doc_string (val, 1, 0); |
| 2884 | } | 2975 | } |
| 2885 | 2976 | ||
| 2886 | return val; | 2977 | return val; |
| @@ -3764,6 +3855,12 @@ to load. See also `load-dangerous-libraries'. */); | |||
| 3764 | Qget_file_char = intern ("get-file-char"); | 3855 | Qget_file_char = intern ("get-file-char"); |
| 3765 | staticpro (&Qget_file_char); | 3856 | staticpro (&Qget_file_char); |
| 3766 | 3857 | ||
| 3858 | Qget_emacs_mule_file_char = intern ("get-emacs-mule-file-char"); | ||
| 3859 | staticpro (&Qget_emacs_mule_file_char); | ||
| 3860 | |||
| 3861 | Qload_force_doc_strings = intern ("load-force-doc-strings"); | ||
| 3862 | staticpro (&Qload_force_doc_strings); | ||
| 3863 | |||
| 3767 | Qbackquote = intern ("`"); | 3864 | Qbackquote = intern ("`"); |
| 3768 | staticpro (&Qbackquote); | 3865 | staticpro (&Qbackquote); |
| 3769 | Qcomma = intern (","); | 3866 | Qcomma = intern (","); |