Mercurial > hg > xemacs-beta
comparison src/mule-ccl.c @ 456:e7ef97881643 r21-2-43
Import from CVS: tag r21-2-43
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:41:24 +0200 |
parents | 98528da0b7fc |
children | 223736d75acb |
comparison
equal
deleted
inserted
replaced
455:5b97c1cd6ed0 | 456:e7ef97881643 |
---|---|
421 IC += ADDRESS; | 421 IC += ADDRESS; |
422 else | 422 else |
423 IC += 2; | 423 IC += 2; |
424 */ | 424 */ |
425 | 425 |
426 #define CCL_Extention 0x1F /* Extended CCL code | 426 #define CCL_Extension 0x1F /* Extended CCL code |
427 1:ExtendedCOMMNDRrrRRRrrrXXXXX | 427 1:ExtendedCOMMNDRrrRRRrrrXXXXX |
428 2:ARGUMENT | 428 2:ARGUMENT |
429 3:... | 429 3:... |
430 ------------------------------ | 430 ------------------------------ |
431 extended_command (rrr,RRR,Rrr,ARGS) | 431 extended_command (rrr,RRR,Rrr,ARGS) |
632 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog; \ | 632 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog; \ |
633 ccl_prog_stack_struct[stack_idx].ic = (ret_ic); \ | 633 ccl_prog_stack_struct[stack_idx].ic = (ret_ic); \ |
634 stack_idx++; \ | 634 stack_idx++; \ |
635 ccl_prog = called_ccl.prog; \ | 635 ccl_prog = called_ccl.prog; \ |
636 ic = CCL_HEADER_MAIN; \ | 636 ic = CCL_HEADER_MAIN; \ |
637 goto ccl_repeat; \ | 637 /* The "if (1)" prevents warning \ |
638 "end-of loop code not reached" */ \ | |
639 if (1) goto ccl_repeat; \ | |
638 } while (0) | 640 } while (0) |
639 | 641 |
640 #define CCL_MapSingle 0x12 /* Map by single code conversion map | 642 #define CCL_MapSingle 0x12 /* Map by single code conversion map |
641 1:ExtendedCOMMNDXXXRRRrrrXXXXX | 643 1:ExtendedCOMMNDXXXRRRrrrXXXXX |
642 2:MAP-ID | 644 2:MAP-ID |
673 r[7] = LOWER_BYTE (DE-SJIS (Y, Z)) */ | 675 r[7] = LOWER_BYTE (DE-SJIS (Y, Z)) */ |
674 #define CCL_ENCODE_SJIS 0x17 /* X = HIGHER_BYTE (SJIS (Y, Z)) | 676 #define CCL_ENCODE_SJIS 0x17 /* X = HIGHER_BYTE (SJIS (Y, Z)) |
675 r[7] = LOWER_BYTE (SJIS (Y, Z) */ | 677 r[7] = LOWER_BYTE (SJIS (Y, Z) */ |
676 | 678 |
677 /* Terminate CCL program successfully. */ | 679 /* Terminate CCL program successfully. */ |
678 #define CCL_SUCCESS \ | 680 #define CCL_SUCCESS \ |
679 do { \ | 681 do { \ |
680 ccl->status = CCL_STAT_SUCCESS; \ | 682 ccl->status = CCL_STAT_SUCCESS; \ |
681 goto ccl_finish; \ | 683 /* The "if (1)" inhibits the warning \ |
682 } while (0) | 684 "end-of loop code not reached" */ \ |
685 if (1) goto ccl_finish; \ | |
686 } while (0) | |
683 | 687 |
684 /* Suspend CCL program because of reading from empty input buffer or | 688 /* Suspend CCL program because of reading from empty input buffer or |
685 writing to full output buffer. When this program is resumed, the | 689 writing to full output buffer. When this program is resumed, the |
686 same I/O command is executed. */ | 690 same I/O command is executed. */ |
687 #define CCL_SUSPEND(stat) \ | 691 #define CCL_SUSPEND(stat) \ |
688 do { \ | 692 do { \ |
689 ic--; \ | 693 ic--; \ |
690 ccl->status = stat; \ | 694 ccl->status = (stat); \ |
691 goto ccl_finish; \ | 695 /* The "if (1)" inhibits the warning \ |
692 } while (0) | 696 "end-of loop code not reached" */ \ |
697 if (1) goto ccl_finish; \ | |
698 } while (0) | |
693 | 699 |
694 /* Terminate CCL program because of invalid command. Should not occur | 700 /* Terminate CCL program because of invalid command. Should not occur |
695 in the normal case. */ | 701 in the normal case. */ |
696 #define CCL_INVALID_CMD \ | 702 #define CCL_INVALID_CMD \ |
697 do { \ | 703 do { \ |
698 ccl->status = CCL_STAT_INVALID_CMD; \ | 704 ccl->status = CCL_STAT_INVALID_CMD; \ |
699 goto ccl_error_handler; \ | 705 /* The "if (1)" inhibits the warning \ |
700 } while (0) | 706 "end-of loop code not reached" */ \ |
707 if (1) goto ccl_error_handler; \ | |
708 } while (0) | |
701 | 709 |
702 /* Encode one character CH to multibyte form and write to the current | 710 /* Encode one character CH to multibyte form and write to the current |
703 output buffer. At encoding time, if CH is less than 256, CH is | 711 output buffer. At encoding time, if CH is less than 256, CH is |
704 written as is. At decoding time, if CH cannot be regarded as an | 712 written as is. At decoding time, if CH cannot be regarded as an |
705 ASCII character, write it in multibyte form. */ | 713 ASCII character, write it in multibyte form. */ |
707 do { \ | 715 do { \ |
708 if (!destination) \ | 716 if (!destination) \ |
709 CCL_INVALID_CMD; \ | 717 CCL_INVALID_CMD; \ |
710 if (conversion_mode == CCL_MODE_ENCODING) \ | 718 if (conversion_mode == CCL_MODE_ENCODING) \ |
711 { \ | 719 { \ |
712 if (ch == '\n') \ | 720 if ((ch) == '\n') \ |
713 { \ | 721 { \ |
714 if (ccl->eol_type == CCL_CODING_EOL_CRLF) \ | 722 if (ccl->eol_type == CCL_CODING_EOL_CRLF) \ |
715 { \ | 723 { \ |
716 Dynarr_add (destination, '\r'); \ | 724 Dynarr_add (destination, '\r'); \ |
717 Dynarr_add (destination, '\n'); \ | 725 Dynarr_add (destination, '\n'); \ |
719 else if (ccl->eol_type == CCL_CODING_EOL_CR) \ | 727 else if (ccl->eol_type == CCL_CODING_EOL_CR) \ |
720 Dynarr_add (destination, '\r'); \ | 728 Dynarr_add (destination, '\r'); \ |
721 else \ | 729 else \ |
722 Dynarr_add (destination, '\n'); \ | 730 Dynarr_add (destination, '\n'); \ |
723 } \ | 731 } \ |
724 else if (ch < 0x100) \ | 732 else if ((ch) < 0x100) \ |
725 { \ | 733 { \ |
726 Dynarr_add (destination, ch); \ | 734 Dynarr_add (destination, ch); \ |
727 } \ | 735 } \ |
728 else \ | 736 else \ |
729 { \ | 737 { \ |
758 int ch, bytes; \ | 766 int ch, bytes; \ |
759 if (!destination) \ | 767 if (!destination) \ |
760 CCL_INVALID_CMD; \ | 768 CCL_INVALID_CMD; \ |
761 else if (conversion_mode == CCL_MODE_ENCODING) \ | 769 else if (conversion_mode == CCL_MODE_ENCODING) \ |
762 { \ | 770 { \ |
763 for (i = 0; i < len; i++) \ | 771 for (i = 0; i < (len); i++) \ |
764 { \ | 772 { \ |
765 ch = ((XINT (ccl_prog[ic + (i / 3)])) \ | 773 ch = ((XINT (ccl_prog[ic + (i / 3)])) \ |
766 >> ((2 - (i % 3)) * 8)) & 0xFF; \ | 774 >> ((2 - (i % 3)) * 8)) & 0xFF; \ |
767 if (ch == '\n') \ | 775 if (ch == '\n') \ |
768 { \ | 776 { \ |
787 } \ | 795 } \ |
788 } \ | 796 } \ |
789 } \ | 797 } \ |
790 else \ | 798 else \ |
791 { \ | 799 { \ |
792 for (i = 0; i < len; i++) \ | 800 for (i = 0; i < (len); i++) \ |
793 { \ | 801 { \ |
794 ch = ((XINT (ccl_prog[ic + (i / 3)])) \ | 802 ch = ((XINT (ccl_prog[ic + (i / 3)])) \ |
795 >> ((2 - (i % 3)) * 8)) & 0xFF; \ | 803 >> ((2 - (i % 3)) * 8)) & 0xFF; \ |
796 if (!CHAR_MULTIBYTE_P(ch)) \ | 804 if (!CHAR_MULTIBYTE_P(ch)) \ |
797 { \ | 805 { \ |
810 #define CCL_READ_CHAR(r) \ | 818 #define CCL_READ_CHAR(r) \ |
811 do { \ | 819 do { \ |
812 if (!src) \ | 820 if (!src) \ |
813 CCL_INVALID_CMD; \ | 821 CCL_INVALID_CMD; \ |
814 if (src < src_end) \ | 822 if (src < src_end) \ |
815 r = *src++; \ | 823 (r) = *src++; \ |
816 else \ | 824 else \ |
817 { \ | 825 { \ |
818 if (ccl->last_block) \ | 826 if (ccl->last_block) \ |
819 { \ | 827 { \ |
820 ic = ccl->eof_ic; \ | 828 ic = ccl->eof_ic; \ |
835 /* On XEmacs, TranslateCharacter is not supported. Thus, this | 843 /* On XEmacs, TranslateCharacter is not supported. Thus, this |
836 macro is not used. */ | 844 macro is not used. */ |
837 #if 0 | 845 #if 0 |
838 #define CCL_MAKE_CHAR(charset, code, c) \ | 846 #define CCL_MAKE_CHAR(charset, code, c) \ |
839 do { \ | 847 do { \ |
840 if (charset == CHARSET_ASCII) \ | 848 if ((charset) == CHARSET_ASCII) \ |
841 c = code & 0xFF; \ | 849 (c) = (code) & 0xFF; \ |
842 else if (CHARSET_DEFINED_P (charset) \ | 850 else if (CHARSET_DEFINED_P (charset) \ |
843 && (code & 0x7F) >= 32 \ | 851 && ((code) & 0x7F) >= 32 \ |
844 && (code < 256 || ((code >> 7) & 0x7F) >= 32)) \ | 852 && ((code) < 256 || ((code >> 7) & 0x7F) >= 32)) \ |
845 { \ | 853 { \ |
846 int c1 = code & 0x7F, c2 = 0; \ | 854 int c1 = (code) & 0x7F, c2 = 0; \ |
847 \ | 855 \ |
848 if (code >= 256) \ | 856 if ((code) >= 256) \ |
849 c2 = c1, c1 = (code >> 7) & 0x7F; \ | 857 c2 = c1, c1 = ((code) >> 7) & 0x7F; \ |
850 c = MAKE_CHAR (charset, c1, c2); \ | 858 (c) = MAKE_CHAR (charset, c1, c2); \ |
851 } \ | 859 } \ |
852 else \ | 860 else \ |
853 c = code & 0xFF; \ | 861 (c) = (code) & 0xFF; \ |
854 } while (0) | 862 } while (0) |
855 #endif | 863 #endif |
856 | 864 |
857 | 865 |
858 /* Execute CCL code on SRC_BYTES length text at SOURCE. The resulting | 866 /* Execute CCL code on SRC_BYTES length text at SOURCE. The resulting |
1266 } | 1274 } |
1267 else if (!reg[rrr]) | 1275 else if (!reg[rrr]) |
1268 ic = jump_address; | 1276 ic = jump_address; |
1269 break; | 1277 break; |
1270 | 1278 |
1271 case CCL_Extention: | 1279 case CCL_Extension: |
1272 switch (EXCMD) | 1280 switch (EXCMD) |
1273 { | 1281 { |
1274 case CCL_ReadMultibyteChar2: | 1282 case CCL_ReadMultibyteChar2: |
1275 if (!src) | 1283 if (!src) |
1276 CCL_INVALID_CMD; | 1284 CCL_INVALID_CMD; |
1277 | 1285 |
1278 do { | 1286 if (src >= src_end) |
1279 if (src >= src_end) | 1287 { |
1280 { | 1288 src++; |
1281 src++; | 1289 goto ccl_read_multibyte_character_suspend; |
1290 } | |
1291 | |
1292 i = *src++; | |
1293 if (i < 0x80) | |
1294 { | |
1295 /* ASCII */ | |
1296 reg[rrr] = i; | |
1297 reg[RRR] = LEADING_BYTE_ASCII; | |
1298 } | |
1299 else if (i <= MAX_LEADING_BYTE_OFFICIAL_1) | |
1300 { | |
1301 if (src >= src_end) | |
1282 goto ccl_read_multibyte_character_suspend; | 1302 goto ccl_read_multibyte_character_suspend; |
1283 } | 1303 reg[RRR] = i; |
1284 | 1304 reg[rrr] = (*src++ & 0x7F); |
1285 i = *src++; | 1305 } |
1286 if (i < 0x80) | 1306 else if (i <= MAX_LEADING_BYTE_OFFICIAL_2) |
1287 { | 1307 { |
1288 /* ASCII */ | 1308 if ((src + 1) >= src_end) |
1289 reg[rrr] = i; | 1309 goto ccl_read_multibyte_character_suspend; |
1290 reg[RRR] = LEADING_BYTE_ASCII; | 1310 reg[RRR] = i; |
1291 } | 1311 i = (*src++ & 0x7F); |
1292 else if (i <= MAX_LEADING_BYTE_OFFICIAL_1) | 1312 reg[rrr] = ((i << 7) | (*src & 0x7F)); |
1293 { | 1313 src++; |
1294 if (src >= src_end) | 1314 } |
1295 goto ccl_read_multibyte_character_suspend; | 1315 else if (i == PRE_LEADING_BYTE_PRIVATE_1) |
1296 reg[RRR] = i; | 1316 { |
1297 reg[rrr] = (*src++ & 0x7F); | 1317 if ((src + 1) >= src_end) |
1298 } | 1318 goto ccl_read_multibyte_character_suspend; |
1299 else if (i <= MAX_LEADING_BYTE_OFFICIAL_2) | 1319 reg[RRR] = *src++; |
1300 { | 1320 reg[rrr] = (*src++ & 0x7F); |
1301 if ((src + 1) >= src_end) | 1321 } |
1302 goto ccl_read_multibyte_character_suspend; | 1322 else if (i == PRE_LEADING_BYTE_PRIVATE_2) |
1303 reg[RRR] = i; | 1323 { |
1304 i = (*src++ & 0x7F); | 1324 if ((src + 2) >= src_end) |
1305 reg[rrr] = ((i << 7) | (*src & 0x7F)); | 1325 goto ccl_read_multibyte_character_suspend; |
1306 src++; | 1326 reg[RRR] = *src++; |
1307 } | 1327 i = (*src++ & 0x7F); |
1308 else if (i == PRE_LEADING_BYTE_PRIVATE_1) | 1328 reg[rrr] = ((i << 7) | (*src & 0x7F)); |
1309 { | 1329 src++; |
1310 if ((src + 1) >= src_end) | 1330 } |
1311 goto ccl_read_multibyte_character_suspend; | 1331 else |
1312 reg[RRR] = *src++; | 1332 { |
1313 reg[rrr] = (*src++ & 0x7F); | 1333 /* INVALID CODE. Return a single byte character. */ |
1314 } | 1334 reg[RRR] = LEADING_BYTE_ASCII; |
1315 else if (i == PRE_LEADING_BYTE_PRIVATE_2) | 1335 reg[rrr] = i; |
1316 { | 1336 } |
1317 if ((src + 2) >= src_end) | |
1318 goto ccl_read_multibyte_character_suspend; | |
1319 reg[RRR] = *src++; | |
1320 i = (*src++ & 0x7F); | |
1321 reg[rrr] = ((i << 7) | (*src & 0x7F)); | |
1322 src++; | |
1323 } | |
1324 else | |
1325 { | |
1326 /* INVALID CODE. Return a single byte character. */ | |
1327 reg[RRR] = LEADING_BYTE_ASCII; | |
1328 reg[rrr] = i; | |
1329 } | |
1330 break; | |
1331 } while (1); | |
1332 break; | 1337 break; |
1333 | 1338 |
1334 ccl_read_multibyte_character_suspend: | 1339 ccl_read_multibyte_character_suspend: |
1335 src--; | 1340 src--; |
1336 if (ccl->last_block) | 1341 if (ccl->last_block) |