Mercurial > emacs
comparison src/coding.c @ 30950:5682de5cfdac
(decode_coding_string): Set members consumed,
consumed_char, produced, produced_char of *coding correctly. If
decode_coding doesn't consume any byte, don't try anymore.
(encode_coding_string): Likewise.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Fri, 18 Aug 2000 06:41:15 +0000 |
| parents | 91e24edb537a |
| children | e6acd4b6a8d5 |
comparison
equal
deleted
inserted
replaced
| 30949:54e668cd8c0b | 30950:5682de5cfdac |
|---|---|
| 5233 Lisp_Object saved_coding_symbol; | 5233 Lisp_Object saved_coding_symbol; |
| 5234 int result; | 5234 int result; |
| 5235 int require_decoding; | 5235 int require_decoding; |
| 5236 int shrinked_bytes = 0; | 5236 int shrinked_bytes = 0; |
| 5237 Lisp_Object newstr; | 5237 Lisp_Object newstr; |
| 5238 int consumed, produced, produced_char; | 5238 int consumed, consumed_char, produced, produced_char; |
| 5239 | 5239 |
| 5240 from = 0; | 5240 from = 0; |
| 5241 to = XSTRING (str)->size; | 5241 to = XSTRING (str)->size; |
| 5242 to_byte = STRING_BYTES (XSTRING (str)); | 5242 to_byte = STRING_BYTES (XSTRING (str)); |
| 5243 | 5243 |
| 5304 if (coding->composing != COMPOSITION_DISABLED) | 5304 if (coding->composing != COMPOSITION_DISABLED) |
| 5305 coding_allocate_composition_data (coding, from); | 5305 coding_allocate_composition_data (coding, from); |
| 5306 len = decoding_buffer_size (coding, to_byte - from); | 5306 len = decoding_buffer_size (coding, to_byte - from); |
| 5307 allocate_conversion_buffer (buf, len); | 5307 allocate_conversion_buffer (buf, len); |
| 5308 | 5308 |
| 5309 consumed = produced = produced_char = 0; | 5309 consumed = consumed_char = produced = produced_char = 0; |
| 5310 while (1) | 5310 while (1) |
| 5311 { | 5311 { |
| 5312 result = decode_coding (coding, XSTRING (str)->data + from + consumed, | 5312 result = decode_coding (coding, XSTRING (str)->data + from + consumed, |
| 5313 buf.data + produced, to_byte - from - consumed, | 5313 buf.data + produced, to_byte - from - consumed, |
| 5314 buf.size - produced); | 5314 buf.size - produced); |
| 5315 consumed += coding->consumed; | 5315 consumed += coding->consumed; |
| 5316 consumed_char += coding->consumed_char; | |
| 5316 produced += coding->produced; | 5317 produced += coding->produced; |
| 5317 produced_char += coding->produced_char; | 5318 produced_char += coding->produced_char; |
| 5318 if (result == CODING_FINISH_NORMAL) | 5319 if (result == CODING_FINISH_NORMAL |
| 5320 || (result == CODING_FINISH_INSUFFICIENT_SRC | |
| 5321 && coding->consumed == 0)) | |
| 5319 break; | 5322 break; |
| 5320 if (result == CODING_FINISH_INSUFFICIENT_CMP) | 5323 if (result == CODING_FINISH_INSUFFICIENT_CMP) |
| 5321 coding_allocate_composition_data (coding, from + produced_char); | 5324 coding_allocate_composition_data (coding, from + produced_char); |
| 5322 else if (result == CODING_FINISH_INSUFFICIENT_DST) | 5325 else if (result == CODING_FINISH_INSUFFICIENT_DST) |
| 5323 extend_conversion_buffer (&buf); | 5326 extend_conversion_buffer (&buf); |
| 5349 coding->eol_type = CODING_EOL_LF; | 5352 coding->eol_type = CODING_EOL_LF; |
| 5350 coding->symbol = saved_coding_symbol; | 5353 coding->symbol = saved_coding_symbol; |
| 5351 } | 5354 } |
| 5352 } | 5355 } |
| 5353 | 5356 |
| 5357 coding->consumed = consumed; | |
| 5358 coding->consumed_char = consumed_char; | |
| 5359 coding->produced = produced; | |
| 5360 coding->produced_char = produced_char; | |
| 5361 | |
| 5354 if (coding->dst_multibyte) | 5362 if (coding->dst_multibyte) |
| 5355 newstr = make_uninit_multibyte_string (produced_char + shrinked_bytes, | 5363 newstr = make_uninit_multibyte_string (produced_char + shrinked_bytes, |
| 5356 produced + shrinked_bytes); | 5364 produced + shrinked_bytes); |
| 5357 else | 5365 else |
| 5358 newstr = make_uninit_string (produced + shrinked_bytes); | 5366 newstr = make_uninit_string (produced + shrinked_bytes); |
| 5388 struct gcpro gcpro1; | 5396 struct gcpro gcpro1; |
| 5389 Lisp_Object saved_coding_symbol; | 5397 Lisp_Object saved_coding_symbol; |
| 5390 int result; | 5398 int result; |
| 5391 int shrinked_bytes = 0; | 5399 int shrinked_bytes = 0; |
| 5392 Lisp_Object newstr; | 5400 Lisp_Object newstr; |
| 5393 int consumed, consumed_char, produced; | 5401 int consumed, consumed_char, produced, produced_char; |
| 5394 | 5402 |
| 5395 if (SYMBOLP (coding->pre_write_conversion) | 5403 if (SYMBOLP (coding->pre_write_conversion) |
| 5396 && !NILP (Ffboundp (coding->pre_write_conversion))) | 5404 && !NILP (Ffboundp (coding->pre_write_conversion))) |
| 5397 str = run_pre_post_conversion_on_str (str, coding, 1); | 5405 str = run_pre_post_conversion_on_str (str, coding, 1); |
| 5398 | 5406 |
| 5401 to_byte = STRING_BYTES (XSTRING (str)); | 5409 to_byte = STRING_BYTES (XSTRING (str)); |
| 5402 | 5410 |
| 5403 saved_coding_symbol = Qnil; | 5411 saved_coding_symbol = Qnil; |
| 5404 if (! CODING_REQUIRE_ENCODING (coding)) | 5412 if (! CODING_REQUIRE_ENCODING (coding)) |
| 5405 { | 5413 { |
| 5414 coding->consumed = STRING_BYTES (XSTRING (str)); | |
| 5415 coding->consumed_char = XSTRING (str)->size; | |
| 5406 if (STRING_MULTIBYTE (str)) | 5416 if (STRING_MULTIBYTE (str)) |
| 5407 { | 5417 { |
| 5408 str = Fstring_as_unibyte (str); | 5418 str = Fstring_as_unibyte (str); |
| 5409 nocopy = 1; | 5419 nocopy = 1; |
| 5410 } | 5420 } |
| 5421 coding->produced = STRING_BYTES (XSTRING (str)); | |
| 5422 coding->produced_char = XSTRING (str)->size; | |
| 5411 return (nocopy ? str : Fcopy_sequence (str)); | 5423 return (nocopy ? str : Fcopy_sequence (str)); |
| 5412 } | 5424 } |
| 5413 | 5425 |
| 5414 /* Encoding routines determine the multibyteness of the source text | 5426 /* Encoding routines determine the multibyteness of the source text |
| 5415 by coding->src_multibyte. */ | 5427 by coding->src_multibyte. */ |
| 5430 } | 5442 } |
| 5431 | 5443 |
| 5432 len = encoding_buffer_size (coding, to_byte - from); | 5444 len = encoding_buffer_size (coding, to_byte - from); |
| 5433 allocate_conversion_buffer (buf, len); | 5445 allocate_conversion_buffer (buf, len); |
| 5434 | 5446 |
| 5435 consumed = consumed_char = produced = 0; | 5447 consumed = consumed_char = produced = produced_char = 0; |
| 5436 | |
| 5437 while (1) | 5448 while (1) |
| 5438 { | 5449 { |
| 5439 result = encode_coding (coding, XSTRING (str)->data + from + consumed, | 5450 result = encode_coding (coding, XSTRING (str)->data + from + consumed, |
| 5440 buf.data + produced, to_byte - from - consumed, | 5451 buf.data + produced, to_byte - from - consumed, |
| 5441 buf.size - produced); | 5452 buf.size - produced); |
| 5442 consumed += coding->consumed; | 5453 consumed += coding->consumed; |
| 5443 produced += coding->produced; | 5454 consumed_char += coding->consumed_char; |
| 5444 if (result == CODING_FINISH_NORMAL) | 5455 produced_char += coding->produced_char; |
| 5456 if (result == CODING_FINISH_NORMAL | |
| 5457 || (result == CODING_FINISH_INSUFFICIENT_SRC | |
| 5458 && coding->consumed == 0)) | |
| 5445 break; | 5459 break; |
| 5446 /* Now result should be CODING_FINISH_INSUFFICIENT_DST. */ | 5460 /* Now result should be CODING_FINISH_INSUFFICIENT_DST. */ |
| 5447 extend_conversion_buffer (&buf); | 5461 extend_conversion_buffer (&buf); |
| 5448 } | 5462 } |
| 5463 | |
| 5464 coding->consumed = consumed; | |
| 5465 coding->consumed_char = consumed_char; | |
| 5466 coding->produced = produced; | |
| 5467 coding->produced_char = produced_char; | |
| 5449 | 5468 |
| 5450 newstr = make_uninit_string (produced + shrinked_bytes); | 5469 newstr = make_uninit_string (produced + shrinked_bytes); |
| 5451 if (from > 0) | 5470 if (from > 0) |
| 5452 bcopy (XSTRING (str)->data, XSTRING (newstr)->data, from); | 5471 bcopy (XSTRING (str)->data, XSTRING (newstr)->data, from); |
| 5453 bcopy (buf.data, XSTRING (newstr)->data + from, produced); | 5472 bcopy (buf.data, XSTRING (newstr)->data + from, produced); |
