Mercurial > emacs
comparison src/fileio.c @ 29009:85822da9ece9
(Finsert_file_contents): Setup src_multibyte and
dst_multibyte members of coding. On handling REPLACE on unibyte
buffer, convert the result of decode_coding to unibyte. On
inserting into a mutibyte buffer, always call code_convert_region.
(e_write): Setup cdoing->src_multibyte according to the
multibyteness of the source (buffer or string).
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 19 May 2000 23:59:27 +0000 |
parents | 242cad59b698 |
children | 9e9b47b53f50 |
comparison
equal
deleted
inserted
replaced
29008:939760ef7379 | 29009:85822da9ece9 |
---|---|
3648 && ! NILP (val)) | 3648 && ! NILP (val)) |
3649 /* We must suppress all character code conversion except for | 3649 /* We must suppress all character code conversion except for |
3650 end-of-line conversion. */ | 3650 end-of-line conversion. */ |
3651 setup_raw_text_coding_system (&coding); | 3651 setup_raw_text_coding_system (&coding); |
3652 | 3652 |
3653 coding.src_multibyte = 0; | |
3654 coding.dst_multibyte | |
3655 = !NILP (current_buffer->enable_multibyte_characters); | |
3653 coding_system_decided = 1; | 3656 coding_system_decided = 1; |
3654 } | 3657 } |
3655 | 3658 |
3656 /* Ensure we always set Vlast_coding_system_used. */ | 3659 /* Ensure we always set Vlast_coding_system_used. */ |
3657 set_coding_system = 1; | 3660 set_coding_system = 1; |
3670 method and hope for the best. | 3673 method and hope for the best. |
3671 But if we discover the need for conversion, we give up on this method | 3674 But if we discover the need for conversion, we give up on this method |
3672 and let the following if-statement handle the replace job. */ | 3675 and let the following if-statement handle the replace job. */ |
3673 if (!NILP (replace) | 3676 if (!NILP (replace) |
3674 && BEGV < ZV | 3677 && BEGV < ZV |
3675 && ! CODING_REQUIRE_DECODING (&coding) | 3678 && !(coding.common_flags & CODING_REQUIRE_DECODING_MASK)) |
3676 && (coding.eol_type == CODING_EOL_UNDECIDED | |
3677 || coding.eol_type == CODING_EOL_LF)) | |
3678 { | 3679 { |
3679 /* same_at_start and same_at_end count bytes, | 3680 /* same_at_start and same_at_end count bytes, |
3680 because file access counts bytes | 3681 because file access counts bytes |
3681 and BEG and END count bytes. */ | 3682 and BEG and END count bytes. */ |
3682 int same_at_start = BEGV_BYTE; | 3683 int same_at_start = BEGV_BYTE; |
3709 else if (nread == 0) | 3710 else if (nread == 0) |
3710 break; | 3711 break; |
3711 | 3712 |
3712 if (coding.type == coding_type_undecided) | 3713 if (coding.type == coding_type_undecided) |
3713 detect_coding (&coding, buffer, nread); | 3714 detect_coding (&coding, buffer, nread); |
3714 if (CODING_REQUIRE_DECODING (&coding)) | 3715 if (coding.common_flags & CODING_REQUIRE_DECODING_MASK) |
3715 /* We found that the file should be decoded somehow. | 3716 /* We found that the file should be decoded somehow. |
3716 Let's give up here. */ | 3717 Let's give up here. */ |
3717 { | 3718 { |
3718 giveup_match_end = 1; | 3719 giveup_match_end = 1; |
3719 break; | 3720 break; |
3927 this, bufsize - inserted); | 3928 this, bufsize - inserted); |
3928 | 3929 |
3929 /* Save for next iteration whatever we didn't convert. */ | 3930 /* Save for next iteration whatever we didn't convert. */ |
3930 unprocessed = this - coding.consumed; | 3931 unprocessed = this - coding.consumed; |
3931 bcopy (read_buf + coding.consumed, read_buf, unprocessed); | 3932 bcopy (read_buf + coding.consumed, read_buf, unprocessed); |
3932 this = coding.produced; | 3933 if (!NILP (current_buffer->enable_multibyte_characters)) |
3934 this = coding.produced; | |
3935 else | |
3936 this = str_as_unibyte (conversion_buffer + inserted, | |
3937 coding.produced); | |
3933 } | 3938 } |
3934 | 3939 |
3935 inserted += this; | 3940 inserted += this; |
3936 } | 3941 } |
3937 | 3942 |
4196 /* We must suppress all character code conversion except for | 4201 /* We must suppress all character code conversion except for |
4197 end-of-line conversion. */ | 4202 end-of-line conversion. */ |
4198 setup_raw_text_coding_system (&coding); | 4203 setup_raw_text_coding_system (&coding); |
4199 } | 4204 } |
4200 | 4205 |
4206 if (!NILP (visit) | |
4207 && (coding.type == coding_type_no_conversion | |
4208 || coding.type == coding_type_raw_text)) | |
4209 { | |
4210 /* Visiting a file with these coding system always make the buffer | |
4211 unibyte. */ | |
4212 current_buffer->enable_multibyte_characters = Qnil; | |
4213 coding.dst_multibyte = 0; | |
4214 } | |
4215 | |
4201 if (inserted > 0 || coding.type == coding_type_ccl) | 4216 if (inserted > 0 || coding.type == coding_type_ccl) |
4202 { | 4217 { |
4203 if (CODING_MAY_REQUIRE_DECODING (&coding)) | 4218 if (CODING_MAY_REQUIRE_DECODING (&coding)) |
4204 { | 4219 { |
4205 /* Here, we don't have to consider byte combining (see the | |
4206 comment below) because code_convert_region takes care of | |
4207 it. */ | |
4208 code_convert_region (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted, | 4220 code_convert_region (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted, |
4209 &coding, 0, 0); | 4221 &coding, 0, 0); |
4210 inserted = (NILP (current_buffer->enable_multibyte_characters) | 4222 inserted = coding.produced_char; |
4211 ? coding.produced : coding.produced_char); | |
4212 } | |
4213 else if (!NILP (current_buffer->enable_multibyte_characters)) | |
4214 { | |
4215 int inserted_byte = inserted; | |
4216 | |
4217 /* There's a possibility that we must combine bytes at the | |
4218 head (resp. the tail) of the just inserted text with the | |
4219 bytes before (resp. after) the gap to form a single | |
4220 character. */ | |
4221 inserted = multibyte_chars_in_text (GPT_ADDR - inserted, inserted); | |
4222 adjust_after_insert (PT, PT_BYTE, | |
4223 PT + inserted_byte, PT_BYTE + inserted_byte, | |
4224 inserted); | |
4225 } | 4223 } |
4226 else | 4224 else |
4227 adjust_after_insert (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted, | 4225 adjust_after_insert (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted, |
4228 inserted); | 4226 inserted); |
4229 } | 4227 } |
4230 | 4228 |
4231 #ifdef DOS_NT | 4229 #ifdef DOS_NT |
4232 /* Use the conversion type to determine buffer-file-type | 4230 /* Use the conversion type to determine buffer-file-type |
4233 (find-buffer-file-type is now used to help determine the | 4231 (find-buffer-file-type is now used to help determine the |
5018 { | 5016 { |
5019 register char *addr; | 5017 register char *addr; |
5020 register int nbytes; | 5018 register int nbytes; |
5021 char buf[WRITE_BUF_SIZE]; | 5019 char buf[WRITE_BUF_SIZE]; |
5022 int return_val = 0; | 5020 int return_val = 0; |
5021 int require_encoding_p; | |
5023 | 5022 |
5024 if (start >= end) | 5023 if (start >= end) |
5025 coding->composing = COMPOSITION_DISABLED; | 5024 coding->composing = COMPOSITION_DISABLED; |
5026 if (coding->composing != COMPOSITION_DISABLED) | 5025 if (coding->composing != COMPOSITION_DISABLED) |
5027 coding_save_composition (coding, start, end, string); | 5026 coding_save_composition (coding, start, end, string); |
5028 | 5027 |
5029 if (STRINGP (string)) | 5028 if (STRINGP (string)) |
5030 { | 5029 { |
5031 addr = XSTRING (string)->data; | 5030 addr = XSTRING (string)->data; |
5032 nbytes = STRING_BYTES (XSTRING (string)); | 5031 nbytes = STRING_BYTES (XSTRING (string)); |
5032 coding->src_multibyte = STRING_MULTIBYTE (string); | |
5033 } | 5033 } |
5034 else if (start < end) | 5034 else if (start < end) |
5035 { | 5035 { |
5036 /* It is assured that the gap is not in the range START and END-1. */ | 5036 /* It is assured that the gap is not in the range START and END-1. */ |
5037 addr = CHAR_POS_ADDR (start); | 5037 addr = CHAR_POS_ADDR (start); |
5038 nbytes = CHAR_TO_BYTE (end) - CHAR_TO_BYTE (start); | 5038 nbytes = CHAR_TO_BYTE (end) - CHAR_TO_BYTE (start); |
5039 coding->src_multibyte | |
5040 = !NILP (current_buffer->enable_multibyte_characters); | |
5039 } | 5041 } |
5040 else | 5042 else |
5041 { | 5043 { |
5042 addr = ""; | 5044 addr = ""; |
5043 nbytes = 0; | 5045 nbytes = 0; |
5046 coding->src_multibyte = 1; | |
5044 } | 5047 } |
5045 | 5048 |
5046 /* We used to have a code for handling selective display here. But, | 5049 /* We used to have a code for handling selective display here. But, |
5047 now it is handled within encode_coding. */ | 5050 now it is handled within encode_coding. */ |
5048 while (1) | 5051 while (1) |