diff options
| author | Kenichi Handa | 2000-12-28 07:03:56 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2000-12-28 07:03:56 +0000 |
| commit | 1c3478b085e2e12ef10b61c2e96915410745e82c (patch) | |
| tree | 7ddb1f6e730cb5c09fdd259ed8204998c28edf17 /src/coding.c | |
| parent | 898f33125fffc6d201de840e5b936c5be83a45c8 (diff) | |
| download | emacs-1c3478b085e2e12ef10b61c2e96915410745e82c.tar.gz emacs-1c3478b085e2e12ef10b61c2e96915410745e82c.zip | |
(setup_coding_system): Initialize
coding->spec.ccl.eight_bit_carryover.
(ccl_coding_driver): Pay attention to carried over 8-bit bytes.
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/src/coding.c b/src/coding.c index ade20141c57..854e2b004b4 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -3710,6 +3710,7 @@ setup_coding_system (coding_system, coding) | |||
| 3710 | } | 3710 | } |
| 3711 | coding->common_flags |= CODING_REQUIRE_FLUSHING_MASK; | 3711 | coding->common_flags |= CODING_REQUIRE_FLUSHING_MASK; |
| 3712 | coding->spec.ccl.cr_carryover = 0; | 3712 | coding->spec.ccl.cr_carryover = 0; |
| 3713 | coding->spec.ccl.eight_bit_carryover[0] = 0; | ||
| 3713 | break; | 3714 | break; |
| 3714 | 3715 | ||
| 3715 | case 5: | 3716 | case 5: |
| @@ -4422,6 +4423,7 @@ ccl_coding_driver (coding, source, destination, src_bytes, dst_bytes, encodep) | |||
| 4422 | struct ccl_program *ccl | 4423 | struct ccl_program *ccl |
| 4423 | = encodep ? &coding->spec.ccl.encoder : &coding->spec.ccl.decoder; | 4424 | = encodep ? &coding->spec.ccl.encoder : &coding->spec.ccl.decoder; |
| 4424 | int result; | 4425 | int result; |
| 4426 | unsigned char *dst = destination; | ||
| 4425 | 4427 | ||
| 4426 | ccl->last_block = coding->mode & CODING_MODE_LAST_BLOCK; | 4428 | ccl->last_block = coding->mode & CODING_MODE_LAST_BLOCK; |
| 4427 | if (encodep) | 4429 | if (encodep) |
| @@ -4434,8 +4436,21 @@ ccl_coding_driver (coding, source, destination, src_bytes, dst_bytes, encodep) | |||
| 4434 | ccl->cr_consumed = coding->spec.ccl.cr_carryover; | 4436 | ccl->cr_consumed = coding->spec.ccl.cr_carryover; |
| 4435 | } | 4437 | } |
| 4436 | ccl->multibyte = coding->src_multibyte; | 4438 | ccl->multibyte = coding->src_multibyte; |
| 4437 | coding->produced = ccl_driver (ccl, source, destination, | 4439 | if (coding->spec.ccl.eight_bit_carryover[0] != 0) |
| 4438 | src_bytes, dst_bytes, &(coding->consumed)); | 4440 | { |
| 4441 | /* Move carryover bytes to DESTINATION. */ | ||
| 4442 | unsigned char *p = coding->spec.ccl.eight_bit_carryover; | ||
| 4443 | while (*p) | ||
| 4444 | *dst++ = *p++; | ||
| 4445 | coding->spec.ccl.eight_bit_carryover[0] = 0; | ||
| 4446 | if (dst_bytes) | ||
| 4447 | dst_bytes -= dst - destination; | ||
| 4448 | } | ||
| 4449 | |||
| 4450 | coding->produced = (ccl_driver (ccl, source, dst, src_bytes, dst_bytes, | ||
| 4451 | &(coding->consumed)) | ||
| 4452 | + dst - destination); | ||
| 4453 | |||
| 4439 | if (encodep) | 4454 | if (encodep) |
| 4440 | { | 4455 | { |
| 4441 | coding->produced_char = coding->produced; | 4456 | coding->produced_char = coding->produced; |
| @@ -4443,8 +4458,47 @@ ccl_coding_driver (coding, source, destination, src_bytes, dst_bytes, encodep) | |||
| 4443 | } | 4458 | } |
| 4444 | else | 4459 | else |
| 4445 | { | 4460 | { |
| 4461 | /* On decoding, the destination should always multibyte. But, | ||
| 4462 | CCL program might have been generated an invalid multibyte | ||
| 4463 | sequence. Here we make such a sequence valid as | ||
| 4464 | multibyte. */ | ||
| 4446 | int bytes | 4465 | int bytes |
| 4447 | = dst_bytes ? dst_bytes : source + coding->consumed - destination; | 4466 | = dst_bytes ? dst_bytes : source + coding->consumed - destination; |
| 4467 | |||
| 4468 | if ((coding->consumed < src_bytes | ||
| 4469 | || !ccl->last_block) | ||
| 4470 | && coding->produced >= 1 | ||
| 4471 | && destination[coding->produced - 1] >= 0x80) | ||
| 4472 | { | ||
| 4473 | /* We should not convert the tailing 8-bit codes to | ||
| 4474 | multibyte form even if they doesn't form a valid | ||
| 4475 | multibyte sequence. They may form a valid sequence in | ||
| 4476 | the next call. */ | ||
| 4477 | int carryover = 0; | ||
| 4478 | |||
| 4479 | if (destination[coding->produced - 1] < 0xA0) | ||
| 4480 | carryover = 1; | ||
| 4481 | else if (coding->produced >= 2) | ||
| 4482 | { | ||
| 4483 | if (destination[coding->produced - 2] >= 0x80) | ||
| 4484 | { | ||
| 4485 | if (destination[coding->produced - 2] < 0xA0) | ||
| 4486 | carryover = 2; | ||
| 4487 | else if (coding->produced >= 3 | ||
| 4488 | && destination[coding->produced - 3] >= 0x80 | ||
| 4489 | && destination[coding->produced - 3] < 0xA0) | ||
| 4490 | carryover = 3; | ||
| 4491 | } | ||
| 4492 | } | ||
| 4493 | if (carryover > 0) | ||
| 4494 | { | ||
| 4495 | BCOPY_SHORT (destination + coding->produced - carryover, | ||
| 4496 | coding->spec.ccl.eight_bit_carryover, | ||
| 4497 | carryover); | ||
| 4498 | coding->spec.ccl.eight_bit_carryover[carryover] = 0; | ||
| 4499 | coding->produced -= carryover; | ||
| 4500 | } | ||
| 4501 | } | ||
| 4448 | coding->produced = str_as_multibyte (destination, bytes, | 4502 | coding->produced = str_as_multibyte (destination, bytes, |
| 4449 | coding->produced, | 4503 | coding->produced, |
| 4450 | &(coding->produced_char)); | 4504 | &(coding->produced_char)); |