diff options
| author | Kenichi Handa | 2003-01-30 02:19:06 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2003-01-30 02:19:06 +0000 |
| commit | bda731af93ef3c3b9e709657db8fff9bd722c1c5 (patch) | |
| tree | e1ea7588ec40e4eaf5619975ba2c50192cf432a7 /src | |
| parent | 01ca0a766d09f70a38c0aecf77dbb8272fadbaed (diff) | |
| download | emacs-bda731af93ef3c3b9e709657db8fff9bd722c1c5.tar.gz emacs-bda731af93ef3c3b9e709657db8fff9bd722c1c5.zip | |
(CCL_DECODE_CHAR, CCL_ENCODE_CHAR): New macros.
(ccl_driver): New arg CHARSET_LIST. Use the above macros instead
of DECODE_CAHR, ENCODE_CHAR, CHAR_CHARSET.
(Fccl_execute): Call ccl_driver with the last arg Qnil.
(Fccl_execute_on_string): Likewise.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ccl.c | 64 |
1 files changed, 42 insertions, 22 deletions
| @@ -771,6 +771,34 @@ while(0) | |||
| 771 | CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC); \ | 771 | CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC); \ |
| 772 | } while (0) | 772 | } while (0) |
| 773 | 773 | ||
| 774 | /* Decode CODE by a charset whose id is ID. If ID is 0, return CODE | ||
| 775 | as is for backward compatibility. Assume that we can use the | ||
| 776 | variable `charset'. */ | ||
| 777 | |||
| 778 | #define CCL_DECODE_CHAR(id, code) \ | ||
| 779 | ((id) == 0 ? (code) \ | ||
| 780 | : (charset = CHARSET_FROM_ID ((id)), DECODE_CHAR (charset, (code)))) | ||
| 781 | |||
| 782 | |||
| 783 | /* Encode character C by some of charsets in CHARSET_LIST. Set ID to | ||
| 784 | the id of the used charset, ENCODED to the resulf of encoding. | ||
| 785 | Assume that we can use the variable `charset'. */ | ||
| 786 | |||
| 787 | #define CCL_ENCODE_CHAR(c, charset_list, id, encoded) \ | ||
| 788 | do { \ | ||
| 789 | unsigned code; \ | ||
| 790 | \ | ||
| 791 | charset = char_charset ((c), (charset_list), &code); \ | ||
| 792 | if (! charset && ! NILP (charset_list)) \ | ||
| 793 | charset = char_charset ((c), Qnil, &code); \ | ||
| 794 | if (charset) \ | ||
| 795 | { \ | ||
| 796 | (id) = CHARSET_ID (charset); \ | ||
| 797 | (encoded) = code; \ | ||
| 798 | } \ | ||
| 799 | } while (0) | ||
| 800 | |||
| 801 | |||
| 774 | 802 | ||
| 775 | /* Execute CCL code on characters at SOURCE (length SRC_SIZE). The | 803 | /* Execute CCL code on characters at SOURCE (length SRC_SIZE). The |
| 776 | resulting text goes to a place pointed by DESTINATION, the length | 804 | resulting text goes to a place pointed by DESTINATION, the length |
| @@ -796,10 +824,11 @@ struct ccl_prog_stack | |||
| 796 | static struct ccl_prog_stack ccl_prog_stack_struct[256]; | 824 | static struct ccl_prog_stack ccl_prog_stack_struct[256]; |
| 797 | 825 | ||
| 798 | void | 826 | void |
| 799 | ccl_driver (ccl, source, destination, src_size, dst_size) | 827 | ccl_driver (ccl, source, destination, src_size, dst_size, charset_list) |
| 800 | struct ccl_program *ccl; | 828 | struct ccl_program *ccl; |
| 801 | int *source, *destination; | 829 | int *source, *destination; |
| 802 | int src_size, dst_size; | 830 | int src_size, dst_size; |
| 831 | Lisp_Object charset_list; | ||
| 803 | { | 832 | { |
| 804 | register int *reg = ccl->reg; | 833 | register int *reg = ccl->reg; |
| 805 | register int ic = ccl->ic; | 834 | register int ic = ccl->ic; |
| @@ -1194,37 +1223,28 @@ ccl_driver (ccl, source, destination, src_size, dst_size) | |||
| 1194 | if (!src) | 1223 | if (!src) |
| 1195 | CCL_INVALID_CMD; | 1224 | CCL_INVALID_CMD; |
| 1196 | CCL_READ_CHAR (i); | 1225 | CCL_READ_CHAR (i); |
| 1197 | charset = CHAR_CHARSET (i); | 1226 | CCL_ENCODE_CHAR (i, charset_list, reg[RRR], reg[rrr]); |
| 1198 | reg[rrr] = CHARSET_ID (charset); | ||
| 1199 | reg[RRR] = ENCODE_CHAR (charset, i); | ||
| 1200 | break; | 1227 | break; |
| 1201 | 1228 | ||
| 1202 | case CCL_WriteMultibyteChar2: | 1229 | case CCL_WriteMultibyteChar2: |
| 1203 | if (! dst) | 1230 | if (! dst) |
| 1204 | CCL_INVALID_CMD; | 1231 | CCL_INVALID_CMD; |
| 1205 | charset = CHARSET_FROM_ID (reg[RRR]); | 1232 | i = CCL_DECODE_CHAR (reg[RRR], reg[rrr]); |
| 1206 | i = DECODE_CHAR (charset, reg[rrr]); | ||
| 1207 | CCL_WRITE_CHAR (i); | 1233 | CCL_WRITE_CHAR (i); |
| 1208 | break; | 1234 | break; |
| 1209 | 1235 | ||
| 1210 | case CCL_TranslateCharacter: | 1236 | case CCL_TranslateCharacter: |
| 1211 | charset = CHARSET_FROM_ID (reg[RRR]); | 1237 | i = CCL_DECODE_CHAR (reg[RRR], reg[rrr]); |
| 1212 | i = DECODE_CHAR (charset, reg[rrr]); | ||
| 1213 | op = translate_char (GET_TRANSLATION_TABLE (reg[Rrr]), i); | 1238 | op = translate_char (GET_TRANSLATION_TABLE (reg[Rrr]), i); |
| 1214 | charset = CHAR_CHARSET (op); | 1239 | CCL_ENCODE_CHAR (op, charset_list, reg[RRR], reg[rrr]); |
| 1215 | reg[RRR] = CHARSET_ID (charset); | ||
| 1216 | reg[rrr] = ENCODE_CHAR (charset, op); | ||
| 1217 | break; | 1240 | break; |
| 1218 | 1241 | ||
| 1219 | case CCL_TranslateCharacterConstTbl: | 1242 | case CCL_TranslateCharacterConstTbl: |
| 1220 | op = XINT (ccl_prog[ic]); /* table */ | 1243 | op = XINT (ccl_prog[ic]); /* table */ |
| 1221 | ic++; | 1244 | ic++; |
| 1222 | charset = CHARSET_FROM_ID (reg[RRR]); | 1245 | i = CCL_DECODE_CHAR (reg[RRR], reg[rrr]); |
| 1223 | i = DECODE_CHAR (charset, reg[rrr]); | ||
| 1224 | op = translate_char (GET_TRANSLATION_TABLE (op), i); | 1246 | op = translate_char (GET_TRANSLATION_TABLE (op), i); |
| 1225 | charset = CHAR_CHARSET (op); | 1247 | CCL_ENCODE_CHAR (op, charset_list, reg[RRR], reg[rrr]); |
| 1226 | reg[RRR] = CHARSET_ID (charset); | ||
| 1227 | reg[rrr] = ENCODE_CHAR (charset, op); | ||
| 1228 | break; | 1248 | break; |
| 1229 | 1249 | ||
| 1230 | case CCL_LookupIntConstTbl: | 1250 | case CCL_LookupIntConstTbl: |
| @@ -1240,8 +1260,8 @@ ccl_driver (ccl, source, destination, src_size, dst_size) | |||
| 1240 | opl = HASH_VALUE (h, op); | 1260 | opl = HASH_VALUE (h, op); |
| 1241 | if (!CHARACTERP (opl)) | 1261 | if (!CHARACTERP (opl)) |
| 1242 | CCL_INVALID_CMD; | 1262 | CCL_INVALID_CMD; |
| 1243 | reg[rrr] = ENCODE_CHAR (CHAR_CHARSET (charset_unicode), | 1263 | reg[RRR] = charset_unicode; |
| 1244 | op); | 1264 | reg[rrr] = op; |
| 1245 | reg[7] = 1; /* r7 true for success */ | 1265 | reg[7] = 1; /* r7 true for success */ |
| 1246 | } | 1266 | } |
| 1247 | else | 1267 | else |
| @@ -1252,8 +1272,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size) | |||
| 1252 | case CCL_LookupCharConstTbl: | 1272 | case CCL_LookupCharConstTbl: |
| 1253 | op = XINT (ccl_prog[ic]); /* table */ | 1273 | op = XINT (ccl_prog[ic]); /* table */ |
| 1254 | ic++; | 1274 | ic++; |
| 1255 | charset = CHARSET_FROM_ID (reg[RRR]); | 1275 | i = CCL_DECODE_CHAR (reg[RRR], reg[rrr]); |
| 1256 | i = DECODE_CHAR (charset, reg[rrr]); | ||
| 1257 | { | 1276 | { |
| 1258 | struct Lisp_Hash_Table *h = GET_HASH_TABLE (op); | 1277 | struct Lisp_Hash_Table *h = GET_HASH_TABLE (op); |
| 1259 | 1278 | ||
| @@ -1909,7 +1928,7 @@ programs. */) | |||
| 1909 | ? XINT (AREF (reg, i)) | 1928 | ? XINT (AREF (reg, i)) |
| 1910 | : 0); | 1929 | : 0); |
| 1911 | 1930 | ||
| 1912 | ccl_driver (&ccl, NULL, NULL, 0, 0); | 1931 | ccl_driver (&ccl, NULL, NULL, 0, 0, Qnil); |
| 1913 | QUIT; | 1932 | QUIT; |
| 1914 | if (ccl.status != CCL_STAT_SUCCESS) | 1933 | if (ccl.status != CCL_STAT_SUCCESS) |
| 1915 | error ("Error in CCL program at %dth code", ccl.ic); | 1934 | error ("Error in CCL program at %dth code", ccl.ic); |
| @@ -2011,7 +2030,8 @@ See the documentation of `define-ccl-program' for the detail of CCL program. */ | |||
| 2011 | src_size = i; | 2030 | src_size = i; |
| 2012 | while (1) | 2031 | while (1) |
| 2013 | { | 2032 | { |
| 2014 | ccl_driver (&ccl, src, destination, src_size, CCL_EXECUTE_BUF_SIZE); | 2033 | ccl_driver (&ccl, src, destination, src_size, CCL_EXECUTE_BUF_SIZE, |
| 2034 | Qnil); | ||
| 2015 | if (ccl.status != CCL_STAT_SUSPEND_BY_DST) | 2035 | if (ccl.status != CCL_STAT_SUSPEND_BY_DST) |
| 2016 | break; | 2036 | break; |
| 2017 | produced_chars += ccl.produced; | 2037 | produced_chars += ccl.produced; |