Mercurial > emacs
comparison src/coding.c @ 21190:d704dd953837
(code_convert_region): The 6th arg name is changed to
REPLACE. Even if there's no need of code conversion, call
adjust_after_replace to handle bytes combining.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Mon, 16 Mar 1998 05:51:07 +0000 |
| parents | 179c73d91f70 |
| children | 50929073a0ba |
comparison
equal
deleted
inserted
replaced
| 21189:14e52c1a5d68 | 21190:d704dd953837 |
|---|---|
| 3937 | 3937 |
| 3938 How many characters (and bytes) are converted to how many | 3938 How many characters (and bytes) are converted to how many |
| 3939 characters (and bytes) are recorded in members of the structure | 3939 characters (and bytes) are recorded in members of the structure |
| 3940 CODING. | 3940 CODING. |
| 3941 | 3941 |
| 3942 If ADJUST is nonzero, we do various things as if the original text | 3942 If REPLACE is nonzero, we do various things as if the original text |
| 3943 is deleted and a new text is inserted. See the comments in | 3943 is deleted and a new text is inserted. See the comments in |
| 3944 replace_range (insdel.c) to know what we are doing. | 3944 replace_range (insdel.c) to know what we are doing. */ |
| 3945 | |
| 3946 ADJUST nonzero also means that post-read-conversion or | |
| 3947 pre-write-conversion functions (if any) should be processed. */ | |
| 3948 | 3945 |
| 3949 int | 3946 int |
| 3950 code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust) | 3947 code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace) |
| 3951 int from, from_byte, to, to_byte, encodep, adjust; | 3948 int from, from_byte, to, to_byte, encodep, replace; |
| 3952 struct coding_system *coding; | 3949 struct coding_system *coding; |
| 3953 { | 3950 { |
| 3954 int len = to - from, len_byte = to_byte - from_byte; | 3951 int len = to - from, len_byte = to_byte - from_byte; |
| 3955 int require, inserted, inserted_byte; | 3952 int require, inserted, inserted_byte; |
| 3956 int from_byte_orig, to_byte_orig; | 3953 int from_byte_orig, to_byte_orig; |
| 3957 Lisp_Object saved_coding_symbol = Qnil; | 3954 Lisp_Object saved_coding_symbol = Qnil; |
| 3958 int multibyte = !NILP (current_buffer->enable_multibyte_characters); | 3955 int multibyte = !NILP (current_buffer->enable_multibyte_characters); |
| 3959 int first = 1; | 3956 int first = 1; |
| 3960 int fake_multibyte = 0; | 3957 int fake_multibyte = 0; |
| 3961 unsigned char *src, *dst; | 3958 unsigned char *src, *dst; |
| 3962 int combined_before_bytes = 0, combined_after_bytes = 0; | 3959 |
| 3963 | 3960 if (replace) |
| 3964 if (adjust) | |
| 3965 { | 3961 { |
| 3966 int saved_from = from; | 3962 int saved_from = from; |
| 3967 | 3963 |
| 3968 prepare_to_modify_buffer (from, to, &from); | 3964 prepare_to_modify_buffer (from, to, &from); |
| 3969 if (saved_from != from) | 3965 if (saved_from != from) |
| 4011 : ! CODING_REQUIRE_DECODING (coding)) | 4007 : ! CODING_REQUIRE_DECODING (coding)) |
| 4012 { | 4008 { |
| 4013 coding->produced = len_byte; | 4009 coding->produced = len_byte; |
| 4014 if (multibyte) | 4010 if (multibyte) |
| 4015 { | 4011 { |
| 4016 if (GPT < from || GPT > to) | 4012 /* We still may have to combine byte at the head and the |
| 4017 move_gap_both (from, from_byte); | 4013 tail of the text in the region. */ |
| 4014 if (GPT != to) | |
| 4015 move_gap_both (to, to_byte); | |
| 4018 coding->produced_char | 4016 coding->produced_char |
| 4019 = multibyte_chars_in_text (BYTE_POS_ADDR (from_byte), len_byte); | 4017 = multibyte_chars_in_text (BYTE_POS_ADDR (from_byte), len_byte); |
| 4018 GAP_SIZE += len_byte; | |
| 4019 GPT_BYTE -= len_byte; | |
| 4020 ZV_BYTE -= len_byte; | |
| 4021 Z_BYTE -= len_byte; | |
| 4022 GPT -= len_byte; | |
| 4023 ZV -= len_byte; | |
| 4024 Z -= len_byte; | |
| 4025 adjust_after_replace (from, from_byte, to, to_byte, | |
| 4026 coding->produced_char, len_byte, replace); | |
| 4020 } | 4027 } |
| 4021 else | 4028 else |
| 4022 coding->produced_char = len_byte; | 4029 coding->produced_char = len_byte; |
| 4023 return 0; | 4030 return 0; |
| 4024 } | 4031 } |
| 4079 | 4086 |
| 4080 if (GAP_SIZE < require) | 4087 if (GAP_SIZE < require) |
| 4081 make_gap (require - GAP_SIZE); | 4088 make_gap (require - GAP_SIZE); |
| 4082 move_gap_both (from, from_byte); | 4089 move_gap_both (from, from_byte); |
| 4083 | 4090 |
| 4084 if (adjust) | 4091 if (replace) |
| 4085 adjust_before_replace (from, from_byte, to, to_byte); | 4092 adjust_before_replace (from, from_byte, to, to_byte); |
| 4086 | 4093 |
| 4087 if (GPT - BEG < beg_unchanged) | 4094 if (GPT - BEG < beg_unchanged) |
| 4088 beg_unchanged = GPT - BEG; | 4095 beg_unchanged = GPT - BEG; |
| 4089 if (Z - GPT < end_unchanged) | 4096 if (Z - GPT < end_unchanged) |
| 4202 NEW bytes (coding->produced). To convert the remaining | 4209 NEW bytes (coding->produced). To convert the remaining |
| 4203 LEN bytes, we may need REQUIRE bytes of gap, where: | 4210 LEN bytes, we may need REQUIRE bytes of gap, where: |
| 4204 REQUIRE + LEN_BYTE = LEN_BYTE * (NEW / ORIG) | 4211 REQUIRE + LEN_BYTE = LEN_BYTE * (NEW / ORIG) |
| 4205 REQUIRE = LEN_BYTE * (NEW - ORIG) / ORIG | 4212 REQUIRE = LEN_BYTE * (NEW - ORIG) / ORIG |
| 4206 Here, we are sure that NEW >= ORIG. */ | 4213 Here, we are sure that NEW >= ORIG. */ |
| 4207 require = (len_byte * (coding->produced - coding->consumed) | 4214 float ratio = coding->produced - coding->consumed; |
| 4208 / coding->consumed); | 4215 ratio /= coding->consumed; |
| 4216 require = len_byte * ratio; | |
| 4209 first = 0; | 4217 first = 0; |
| 4210 } | 4218 } |
| 4211 if ((src - dst) < (require + 2000)) | 4219 if ((src - dst) < (require + 2000)) |
| 4212 { | 4220 { |
| 4213 /* See the comment above the previous call of make_gap. */ | 4221 /* See the comment above the previous call of make_gap. */ |
| 4230 if (multibyte | 4238 if (multibyte |
| 4231 && (fake_multibyte || !encodep && (to - from) != (to_byte - from_byte))) | 4239 && (fake_multibyte || !encodep && (to - from) != (to_byte - from_byte))) |
| 4232 inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte); | 4240 inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte); |
| 4233 | 4241 |
| 4234 adjust_after_replace (from, from_byte, to, to_byte, | 4242 adjust_after_replace (from, from_byte, to, to_byte, |
| 4235 inserted, inserted_byte); | 4243 inserted, inserted_byte, replace); |
| 4236 if (from_byte_orig == from_byte) | 4244 if (from_byte_orig == from_byte) |
| 4237 from_byte_orig = from_byte = PT_BYTE; | 4245 from_byte_orig = from_byte = PT_BYTE; |
| 4238 | 4246 |
| 4239 if (! encodep && ! NILP (coding->post_read_conversion)) | 4247 if (! encodep && ! NILP (coding->post_read_conversion)) |
| 4240 { | 4248 { |
