comparison src/coding.c @ 34892:3868f2e7355a

(setup_coding_system): Initialize coding->spec.ccl.eight_bit_carryover. (ccl_coding_driver): Pay attention to carried over 8-bit bytes.
author Kenichi Handa <handa@m17n.org>
date Thu, 28 Dec 2000 07:03:56 +0000
parents b469d29c0815
children 8cd5e6ad71a2
comparison
equal deleted inserted replaced
34891:b9b14e62fe38 34892:3868f2e7355a
3708 } 3708 }
3709 } 3709 }
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:
3716 coding->type = coding_type_raw_text; 3717 coding->type = coding_type_raw_text;
3717 break; 3718 break;
4420 int src_bytes, dst_bytes, encodep; 4421 int src_bytes, dst_bytes, encodep;
4421 { 4422 {
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)
4428 { 4430 {
4429 /* On encoding, EOL format is converted within ccl_driver. For 4431 /* On encoding, EOL format is converted within ccl_driver. For
4432 if (ccl->eol_type ==CODING_EOL_UNDECIDED) 4434 if (ccl->eol_type ==CODING_EOL_UNDECIDED)
4433 ccl->eol_type = CODING_EOL_LF; 4435 ccl->eol_type = CODING_EOL_LF;
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;
4442 coding->spec.ccl.cr_carryover = ccl->cr_consumed; 4457 coding->spec.ccl.cr_carryover = ccl->cr_consumed;
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));
4451 } 4505 }
4452 4506