aboutsummaryrefslogtreecommitdiffstats
path: root/src/ccl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ccl.c')
-rw-r--r--src/ccl.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/ccl.c b/src/ccl.c
index 5eac485bf2c..71a08fdf7c7 100644
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -634,14 +634,17 @@ do \
634 { \ 634 { \
635 ccl_prog = ccl_prog_stack_struct[0].ccl_prog; \ 635 ccl_prog = ccl_prog_stack_struct[0].ccl_prog; \
636 ic = ccl_prog_stack_struct[0].ic; \ 636 ic = ccl_prog_stack_struct[0].ic; \
637 eof_ic = ccl_prog_stack_struct[0].eof_ic; \
637 } \ 638 } \
638 CCL_INVALID_CMD; \ 639 CCL_INVALID_CMD; \
639 } \ 640 } \
640 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog; \ 641 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog; \
641 ccl_prog_stack_struct[stack_idx].ic = (ret_ic); \ 642 ccl_prog_stack_struct[stack_idx].ic = (ret_ic); \
643 ccl_prog_stack_struct[stack_idx].eof_ic = eof_ic; \
642 stack_idx++; \ 644 stack_idx++; \
643 ccl_prog = called_ccl.prog; \ 645 ccl_prog = called_ccl.prog; \
644 ic = CCL_HEADER_MAIN; \ 646 ic = CCL_HEADER_MAIN; \
647 eof_ic = XFASTINT (ccl_prog[CCL_HEADER_EOF]); \
645 goto ccl_repeat; \ 648 goto ccl_repeat; \
646 } \ 649 } \
647while (0) 650while (0)
@@ -718,14 +721,29 @@ while (0)
718 721
719/* Terminate CCL program because of invalid command. Should not occur 722/* Terminate CCL program because of invalid command. Should not occur
720 in the normal case. */ 723 in the normal case. */
724#ifndef CCL_DEBUG
725
726#define CCL_INVALID_CMD \
727do \
728 { \
729 ccl->status = CCL_STAT_INVALID_CMD; \
730 goto ccl_error_handler; \
731 } \
732while(0)
733
734#else
735
721#define CCL_INVALID_CMD \ 736#define CCL_INVALID_CMD \
722do \ 737do \
723 { \ 738 { \
739 ccl_debug_hook (this_ic); \
724 ccl->status = CCL_STAT_INVALID_CMD; \ 740 ccl->status = CCL_STAT_INVALID_CMD; \
725 goto ccl_error_handler; \ 741 goto ccl_error_handler; \
726 } \ 742 } \
727while(0) 743while(0)
728 744
745#endif
746
729/* Encode one character CH to multibyte form and write to the current 747/* Encode one character CH to multibyte form and write to the current
730 output buffer. If CH is less than 256, CH is written as is. */ 748 output buffer. If CH is less than 256, CH is written as is. */
731#define CCL_WRITE_CHAR(ch) \ 749#define CCL_WRITE_CHAR(ch) \
@@ -762,6 +780,7 @@ while(0)
762 r = *src++; \ 780 r = *src++; \
763 else if (ccl->last_block) \ 781 else if (ccl->last_block) \
764 { \ 782 { \
783 r = -1; \
765 ic = ccl->eof_ic; \ 784 ic = ccl->eof_ic; \
766 goto ccl_repeat; \ 785 goto ccl_repeat; \
767 } \ 786 } \
@@ -807,12 +826,20 @@ while(0)
807#define CCL_DEBUG_BACKTRACE_LEN 256 826#define CCL_DEBUG_BACKTRACE_LEN 256
808int ccl_backtrace_table[CCL_DEBUG_BACKTRACE_LEN]; 827int ccl_backtrace_table[CCL_DEBUG_BACKTRACE_LEN];
809int ccl_backtrace_idx; 828int ccl_backtrace_idx;
829
830int
831ccl_debug_hook (int ic)
832{
833 return ic;
834}
835
810#endif 836#endif
811 837
812struct ccl_prog_stack 838struct ccl_prog_stack
813 { 839 {
814 Lisp_Object *ccl_prog; /* Pointer to an array of CCL code. */ 840 Lisp_Object *ccl_prog; /* Pointer to an array of CCL code. */
815 int ic; /* Instruction Counter. */ 841 int ic; /* Instruction Counter. */
842 int eof_ic; /* Instruction Counter to jump on EOF. */
816 }; 843 };
817 844
818/* For the moment, we only support depth 256 of stack. */ 845/* For the moment, we only support depth 256 of stack. */
@@ -837,8 +864,10 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
837 /* Instruction counter of the current CCL code. */ 864 /* Instruction counter of the current CCL code. */
838 int this_ic = 0; 865 int this_ic = 0;
839 struct charset *charset; 866 struct charset *charset;
867 int eof_ic = ccl->eof_ic;
868 int eof_hit = 0;
840 869
841 if (ic >= ccl->eof_ic) 870 if (ic >= eof_ic)
842 ic = CCL_HEADER_MAIN; 871 ic = CCL_HEADER_MAIN;
843 872
844 if (ccl->buf_magnification == 0) /* We can't read/produce any bytes. */ 873 if (ccl->buf_magnification == 0) /* We can't read/produce any bytes. */
@@ -1042,15 +1071,18 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
1042 { 1071 {
1043 ccl_prog = ccl_prog_stack_struct[0].ccl_prog; 1072 ccl_prog = ccl_prog_stack_struct[0].ccl_prog;
1044 ic = ccl_prog_stack_struct[0].ic; 1073 ic = ccl_prog_stack_struct[0].ic;
1074 eof_ic = ccl_prog_stack_struct[0].eof_ic;
1045 } 1075 }
1046 CCL_INVALID_CMD; 1076 CCL_INVALID_CMD;
1047 } 1077 }
1048 1078
1049 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog; 1079 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog;
1050 ccl_prog_stack_struct[stack_idx].ic = ic; 1080 ccl_prog_stack_struct[stack_idx].ic = ic;
1081 ccl_prog_stack_struct[stack_idx].eof_ic = eof_ic;
1051 stack_idx++; 1082 stack_idx++;
1052 ccl_prog = XVECTOR (AREF (slot, 1))->contents; 1083 ccl_prog = XVECTOR (AREF (slot, 1))->contents;
1053 ic = CCL_HEADER_MAIN; 1084 ic = CCL_HEADER_MAIN;
1085 eof_ic = XFASTINT (ccl_prog[CCL_HEADER_EOF]);
1054 } 1086 }
1055 break; 1087 break;
1056 1088
@@ -1080,6 +1112,9 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
1080 stack_idx--; 1112 stack_idx--;
1081 ccl_prog = ccl_prog_stack_struct[stack_idx].ccl_prog; 1113 ccl_prog = ccl_prog_stack_struct[stack_idx].ccl_prog;
1082 ic = ccl_prog_stack_struct[stack_idx].ic; 1114 ic = ccl_prog_stack_struct[stack_idx].ic;
1115 eof_ic = ccl_prog_stack_struct[stack_idx].eof_ic;
1116 if (eof_hit)
1117 ic = eof_ic;
1083 break; 1118 break;
1084 } 1119 }
1085 if (src) 1120 if (src)