comparison src/ccl.c @ 89370:0888fb1bda3f

(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.
author Kenichi Handa <handa@m17n.org>
date Thu, 30 Jan 2003 02:19:06 +0000
parents aa33304a3bb8
children 2f877ed80fa6
comparison
equal deleted inserted replaced
89369:db3deaa3ae51 89370:0888fb1bda3f
769 } \ 769 } \
770 else \ 770 else \
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
777 of which should not exceed DST_SIZE. As a side effect, how many 805 of which should not exceed DST_SIZE. As a side effect, how many
778 characters are consumed and produced are recorded in CCL->consumed 806 characters are consumed and produced are recorded in CCL->consumed
794 822
795 /* For the moment, we only support depth 256 of stack. */ 823 /* For the moment, we only support depth 256 of 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;
806 register int code = 0, field1, field2; 835 register int code = 0, field1, field2;
807 register Lisp_Object *ccl_prog = ccl->prog; 836 register Lisp_Object *ccl_prog = ccl->prog;
1192 { 1221 {
1193 case CCL_ReadMultibyteChar2: 1222 case CCL_ReadMultibyteChar2:
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:
1231 op = XINT (ccl_prog[ic]); /* table */ 1251 op = XINT (ccl_prog[ic]); /* table */
1232 ic++; 1252 ic++;
1238 { 1258 {
1239 Lisp_Object opl; 1259 Lisp_Object opl;
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
1248 reg[7] = 0; 1268 reg[7] = 0;
1249 } 1269 }
1250 break; 1270 break;
1251 1271
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
1260 op = hash_lookup (h, make_number (i), NULL); 1279 op = hash_lookup (h, make_number (i), NULL);
1261 if (op >= 0) 1280 if (op >= 0)
1907 for (i = 0; i < 8; i++) 1926 for (i = 0; i < 8; i++)
1908 ccl.reg[i] = (INTEGERP (AREF (reg, i)) 1927 ccl.reg[i] = (INTEGERP (AREF (reg, i))
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);
1916 1935
1917 for (i = 0; i < 8; i++) 1936 for (i = 0; i < 8; i++)
2009 ccl.last_block = NILP (contin); 2028 ccl.last_block = NILP (contin);
2010 src = source; 2029 src = source;
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;
2018 if (NILP (unibyte_p)) 2038 if (NILP (unibyte_p))
2019 { 2039 {