aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorK. Handa2016-06-01 07:53:03 +0900
committerK. Handa2016-06-01 07:53:03 +0900
commit694d5e5b56a9d55023ffc292188bd88f6f6cbca6 (patch)
tree88b600c763f75a140669f14f05f363011ffc51da /src/coding.c
parent66cd9187e396abfa7220d6a8f8d1a7064ef20b1e (diff)
downloademacs-694d5e5b56a9d55023ffc292188bd88f6f6cbca6.tar.gz
emacs-694d5e5b56a9d55023ffc292188bd88f6f6cbca6.zip
Fix incomplete handling of translation table in a coding system.
* coding.c (get_translation): New arg NCHARS. Even if TRANS is an alist, return a character or a vector of character. (produce_chars): Adjust for the above change. (consume_chars): Likewise.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c61
1 files changed, 27 insertions, 34 deletions
diff --git a/src/coding.c b/src/coding.c
index 7d199567fd0..55a4cea7c0b 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6947,18 +6947,21 @@ get_translation_table (Lisp_Object attrs, bool encodep, int *max_lookup)
6947 6947
6948 6948
6949/* Return a translation of character(s) at BUF according to TRANS. 6949/* Return a translation of character(s) at BUF according to TRANS.
6950 TRANS is TO-CHAR or ((FROM . TO) ...) where 6950 TRANS is TO-CHAR, [TO-CHAR ...], or ((FROM . TO) ...) where FROM =
6951 FROM = [FROM-CHAR ...], TO is TO-CHAR or [TO-CHAR ...]. 6951 [FROM-CHAR ...], TO is TO-CHAR or [TO-CHAR ...]. The return value
6952 The return value is TO-CHAR or ([FROM-CHAR ...] . TO) if a 6952 is TO-CHAR or [TO-CHAR ...] if a translation is found, Qnil if not
6953 translation is found, and Qnil if not found.. 6953 found, or Qt if BUF is too short to lookup characters in FROM. As
6954 If BUF is too short to lookup characters in FROM, return Qt. */ 6954 a side effect, if a translation is found, *NCHARS is set to the
6955 number of characters being translated. */
6955 6956
6956static Lisp_Object 6957static Lisp_Object
6957get_translation (Lisp_Object trans, int *buf, int *buf_end) 6958get_translation (Lisp_Object trans, int *buf, int *buf_end, ptrdiff_t *nchars)
6958{ 6959{
6959 6960 if (INTEGERP (trans) || VECTORP (trans))
6960 if (INTEGERP (trans)) 6961 {
6961 return trans; 6962 *nchars = 1;
6963 return trans;
6964 }
6962 for (; CONSP (trans); trans = XCDR (trans)) 6965 for (; CONSP (trans); trans = XCDR (trans))
6963 { 6966 {
6964 Lisp_Object val = XCAR (trans); 6967 Lisp_Object val = XCAR (trans);
@@ -6974,7 +6977,10 @@ get_translation (Lisp_Object trans, int *buf, int *buf_end)
6974 break; 6977 break;
6975 } 6978 }
6976 if (i == len) 6979 if (i == len)
6977 return val; 6980 {
6981 *nchars = len;
6982 return XCDR (val);
6983 }
6978 } 6984 }
6979 return Qnil; 6985 return Qnil;
6980} 6986}
@@ -7017,20 +7023,13 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
7017 LOOKUP_TRANSLATION_TABLE (translation_table, c, trans); 7023 LOOKUP_TRANSLATION_TABLE (translation_table, c, trans);
7018 if (! NILP (trans)) 7024 if (! NILP (trans))
7019 { 7025 {
7020 trans = get_translation (trans, buf, buf_end); 7026 trans = get_translation (trans, buf, buf_end, &from_nchars);
7021 if (INTEGERP (trans)) 7027 if (INTEGERP (trans))
7022 c = XINT (trans); 7028 c = XINT (trans);
7023 else if (CONSP (trans)) 7029 else if (VECTORP (trans))
7024 { 7030 {
7025 from_nchars = ASIZE (XCAR (trans)); 7031 to_nchars = ASIZE (trans);
7026 trans = XCDR (trans); 7032 c = XINT (AREF (trans, 0));
7027 if (INTEGERP (trans))
7028 c = XINT (trans);
7029 else
7030 {
7031 to_nchars = ASIZE (trans);
7032 c = XINT (AREF (trans, 0));
7033 }
7034 } 7033 }
7035 else if (EQ (trans, Qt) && ! last_block) 7034 else if (EQ (trans, Qt) && ! last_block)
7036 break; 7035 break;
@@ -7671,22 +7670,16 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table,
7671 for (i = 1; i < max_lookup && p < src_end; i++) 7670 for (i = 1; i < max_lookup && p < src_end; i++)
7672 lookup_buf[i] = STRING_CHAR_ADVANCE (p); 7671 lookup_buf[i] = STRING_CHAR_ADVANCE (p);
7673 lookup_buf_end = lookup_buf + i; 7672 lookup_buf_end = lookup_buf + i;
7674 trans = get_translation (trans, lookup_buf, lookup_buf_end); 7673 trans = get_translation (trans, lookup_buf, lookup_buf_end,
7674 &from_nchars);
7675 if (INTEGERP (trans)) 7675 if (INTEGERP (trans))
7676 c = XINT (trans); 7676 c = XINT (trans);
7677 else if (CONSP (trans)) 7677 else if (VECTORP (trans))
7678 { 7678 {
7679 from_nchars = ASIZE (XCAR (trans)); 7679 to_nchars = ASIZE (trans);
7680 trans = XCDR (trans); 7680 if (buf_end - buf < to_nchars)
7681 if (INTEGERP (trans)) 7681 break;
7682 c = XINT (trans); 7682 c = XINT (AREF (trans, 0));
7683 else
7684 {
7685 to_nchars = ASIZE (trans);
7686 if (buf_end - buf < to_nchars)
7687 break;
7688 c = XINT (AREF (trans, 0));
7689 }
7690 } 7683 }
7691 else 7684 else
7692 break; 7685 break;