Commit 84fbb8a0 authored by Kenichi Handa's avatar Kenichi Handa
Browse files

Change terms unify/unification to

translate/translation respectively throughtout the file.
(encode_coding_iso2022): Fix bug in encoding a text ending by a
composite character.
(check_composing_code): If we are decoding the last block of data,
return 0 even if the source doesn't end by an escape sequence
which terminates the current composing sequence.
(decode_coding_iso2022): Decode correctly even if the source
doesn't end by an escape sequence which terminates the current
composing sequence.
parent ab45712c
...@@ -367,17 +367,18 @@ char *coding_category_name[CODING_CATEGORY_IDX_MAX] = { ...@@ -367,17 +367,18 @@ char *coding_category_name[CODING_CATEGORY_IDX_MAX] = {
categories. */ categories. */
struct coding_system *coding_system_table[CODING_CATEGORY_IDX_MAX]; struct coding_system *coding_system_table[CODING_CATEGORY_IDX_MAX];
/* Flag to tell if we look up unification table on character code /* Flag to tell if we look up character translation table on character
conversion. */ code conversion. */
Lisp_Object Venable_character_unification; Lisp_Object Venable_character_translation;
/* Standard unification table to look up on decoding (reading). */ /* Standard character translation table to look up on decoding (reading). */
Lisp_Object Vstandard_character_unification_table_for_decode; Lisp_Object Vstandard_character_translation_table_for_decode;
/* Standard unification table to look up on encoding (writing). */ /* Standard character translation table to look up on encoding (writing). */
Lisp_Object Vstandard_character_unification_table_for_encode; Lisp_Object Vstandard_character_translation_table_for_encode;
Lisp_Object Qcharacter_unification_table; Lisp_Object Qcharacter_translation_table;
Lisp_Object Qcharacter_unification_table_for_decode; Lisp_Object Qcharacter_translation_table_id;
Lisp_Object Qcharacter_unification_table_for_encode; Lisp_Object Qcharacter_translation_table_for_decode;
Lisp_Object Qcharacter_translation_table_for_encode;
/* Alist of charsets vs revision number. */ /* Alist of charsets vs revision number. */
Lisp_Object Vcharset_revision_alist; Lisp_Object Vcharset_revision_alist;
...@@ -890,8 +891,8 @@ detect_coding_iso2022 (src, src_end) ...@@ -890,8 +891,8 @@ detect_coding_iso2022 (src, src_end)
c2 = ' '; \ c2 = ' '; \
} \ } \
} \ } \
if (!NILP (unification_table) \ if (!NILP (translation_table) \
&& ((c_alt = unify_char (unification_table, \ && ((c_alt = translate_char (translation_table, \
-1, (charset), c1, c2)) >= 0)) \ -1, (charset), c1, c2)) >= 0)) \
SPLIT_CHAR (c_alt, charset_alt, c1, c2); \ SPLIT_CHAR (c_alt, charset_alt, c1, c2); \
} \ } \
...@@ -943,7 +944,8 @@ detect_coding_iso2022 (src, src_end) ...@@ -943,7 +944,8 @@ detect_coding_iso2022 (src, src_end)
Else, if it contains only valid codes, return 0. Else, if it contains only valid codes, return 0.
Else return the length of the composing sequence. */ Else return the length of the composing sequence. */
int check_composing_code (coding, src, src_end) int
check_composing_code (coding, src, src_end)
struct coding_system *coding; struct coding_system *coding;
unsigned char *src, *src_end; unsigned char *src, *src_end;
{ {
...@@ -982,7 +984,9 @@ int check_composing_code (coding, src, src_end) ...@@ -982,7 +984,9 @@ int check_composing_code (coding, src, src_end)
invalid_code_found = 1; invalid_code_found = 1;
} }
} }
return ((coding->mode & CODING_MODE_LAST_BLOCK) ? src_end - src_start : -1); return (invalid_code_found
? src - src_start
: (coding->mode & CODING_MODE_LAST_BLOCK ? 0 : -1));
} }
/* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ /* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */
...@@ -1005,12 +1009,12 @@ decode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes) ...@@ -1005,12 +1009,12 @@ decode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
/* Charsets invoked to graphic plane 0 and 1 respectively. */ /* Charsets invoked to graphic plane 0 and 1 respectively. */
int charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0); int charset0 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 0);
int charset1 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 1); int charset1 = CODING_SPEC_ISO_PLANE_CHARSET (coding, 1);
Lisp_Object unification_table Lisp_Object translation_table
= coding->character_unification_table_for_decode; = coding->character_translation_table_for_decode;
int result = CODING_FINISH_NORMAL; int result = CODING_FINISH_NORMAL;
if (!NILP (Venable_character_unification) && NILP (unification_table)) if (!NILP (Venable_character_translation) && NILP (translation_table))
unification_table = Vstandard_character_unification_table_for_decode; translation_table = Vstandard_character_translation_table_for_decode;
coding->produced_char = 0; coding->produced_char = 0;
coding->fake_multibyte = 0; coding->fake_multibyte = 0;
...@@ -1222,9 +1226,12 @@ decode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes) ...@@ -1222,9 +1226,12 @@ decode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
result1 = check_composing_code (coding, src, src_end); result1 = check_composing_code (coding, src, src_end);
if (result1 == 0) if (result1 == 0)
{
coding->composing = (c1 == '0' coding->composing = (c1 == '0'
? COMPOSING_NO_RULE_HEAD ? COMPOSING_NO_RULE_HEAD
: COMPOSING_WITH_RULE_HEAD); : COMPOSING_WITH_RULE_HEAD);
coding->produced_char++;
}
else if (result1 > 0) else if (result1 > 0)
{ {
if (result1 + 2 < (dst_bytes ? dst_end : src_base) - dst) if (result1 + 2 < (dst_bytes ? dst_end : src_base) - dst)
...@@ -1247,7 +1254,6 @@ decode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes) ...@@ -1247,7 +1254,6 @@ decode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
case '1': /* end composing */ case '1': /* end composing */
coding->composing = COMPOSING_NO; coding->composing = COMPOSING_NO;
coding->produced_char++;
break; break;
case '[': /* specification of direction */ case '[': /* specification of direction */
...@@ -1555,8 +1561,9 @@ decode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes) ...@@ -1555,8 +1561,9 @@ decode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
#define ENCODE_ISO_CHARACTER(charset, c1, c2) \ #define ENCODE_ISO_CHARACTER(charset, c1, c2) \
do { \ do { \
int c_alt, charset_alt; \ int c_alt, charset_alt; \
if (!NILP (unification_table) \ if (!NILP (translation_table) \
&& ((c_alt = unify_char (unification_table, -1, charset, c1, c2)) \ && ((c_alt = translate_char (translation_table, -1, \
charset, c1, c2)) \
>= 0)) \ >= 0)) \
SPLIT_CHAR (c_alt, charset_alt, c1, c2); \ SPLIT_CHAR (c_alt, charset_alt, c1, c2); \
else \ else \
...@@ -1710,7 +1717,7 @@ encode_designation_at_bol (coding, table, src, src_end, dstp) ...@@ -1710,7 +1717,7 @@ encode_designation_at_bol (coding, table, src, src_end, dstp)
unsigned char c1, c2; unsigned char c1, c2;
SPLIT_STRING(src, bytes, charset, c1, c2); SPLIT_STRING(src, bytes, charset, c1, c2);
if ((c_alt = unify_char (table, -1, charset, c1, c2)) >= 0) if ((c_alt = translate_char (table, -1, charset, c1, c2)) >= 0)
charset = CHAR_CHARSET (c_alt); charset = CHAR_CHARSET (c_alt);
} }
...@@ -1750,12 +1757,12 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes) ...@@ -1750,12 +1757,12 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
from DST_END to assure overflow checking is necessary only at the from DST_END to assure overflow checking is necessary only at the
head of loop. */ head of loop. */
unsigned char *adjusted_dst_end = dst_end - 19; unsigned char *adjusted_dst_end = dst_end - 19;
Lisp_Object unification_table Lisp_Object translation_table
= coding->character_unification_table_for_encode; = coding->character_translation_table_for_encode;
int result = CODING_FINISH_NORMAL; int result = CODING_FINISH_NORMAL;
if (!NILP (Venable_character_unification) && NILP (unification_table)) if (!NILP (Venable_character_translation) && NILP (translation_table))
unification_table = Vstandard_character_unification_table_for_encode; translation_table = Vstandard_character_translation_table_for_encode;
coding->consumed_char = 0; coding->consumed_char = 0;
coding->fake_multibyte = 0; coding->fake_multibyte = 0;
...@@ -1775,7 +1782,7 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes) ...@@ -1775,7 +1782,7 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
&& CODING_SPEC_ISO_BOL (coding)) && CODING_SPEC_ISO_BOL (coding))
{ {
/* We have to produce designation sequences if any now. */ /* We have to produce designation sequences if any now. */
encode_designation_at_bol (coding, unification_table, encode_designation_at_bol (coding, translation_table,
src, src_end, &dst); src, src_end, &dst);
CODING_SPEC_ISO_BOL (coding) = 0; CODING_SPEC_ISO_BOL (coding) = 0;
} }
...@@ -1950,8 +1957,11 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes) ...@@ -1950,8 +1957,11 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
reset graphic planes and registers to the initial state, and reset graphic planes and registers to the initial state, and
flush out the carryover if any. */ flush out the carryover if any. */
if (coding->mode & CODING_MODE_LAST_BLOCK) if (coding->mode & CODING_MODE_LAST_BLOCK)
{
ENCODE_RESET_PLANE_AND_REGISTER; ENCODE_RESET_PLANE_AND_REGISTER;
if (COMPOSING_P (coding->composing))
ENCODE_COMPOSITION_END;
}
coding->consumed = src - source; coding->consumed = src - source;
coding->produced = coding->produced_char = dst - destination; coding->produced = coding->produced_char = dst - destination;
return result; return result;
...@@ -2035,8 +2045,8 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes) ...@@ -2035,8 +2045,8 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
#define DECODE_SJIS_BIG5_CHARACTER(charset, c1, c2) \ #define DECODE_SJIS_BIG5_CHARACTER(charset, c1, c2) \
do { \ do { \
int c_alt, charset_alt = (charset); \ int c_alt, charset_alt = (charset); \
if (!NILP (unification_table) \ if (!NILP (translation_table) \
&& ((c_alt = unify_char (unification_table, \ && ((c_alt = translate_char (translation_table, \
-1, (charset), c1, c2)) >= 0)) \ -1, (charset), c1, c2)) >= 0)) \
SPLIT_CHAR (c_alt, charset_alt, c1, c2); \ SPLIT_CHAR (c_alt, charset_alt, c1, c2); \
if (charset_alt == CHARSET_ASCII || charset_alt < 0) \ if (charset_alt == CHARSET_ASCII || charset_alt < 0) \
...@@ -2050,8 +2060,9 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes) ...@@ -2050,8 +2060,9 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
#define ENCODE_SJIS_BIG5_CHARACTER(charset, c1, c2) \ #define ENCODE_SJIS_BIG5_CHARACTER(charset, c1, c2) \
do { \ do { \
int c_alt, charset_alt; \ int c_alt, charset_alt; \
if (!NILP (unification_table) \ if (!NILP (translation_table) \
&& ((c_alt = unify_char (unification_table, -1, charset, c1, c2)) \ && ((c_alt = translate_char (translation_table, -1, \
charset, c1, c2)) \
>= 0)) \ >= 0)) \
SPLIT_CHAR (c_alt, charset_alt, c1, c2); \ SPLIT_CHAR (c_alt, charset_alt, c1, c2); \
else \ else \
...@@ -2163,12 +2174,12 @@ decode_coding_sjis_big5 (coding, source, destination, ...@@ -2163,12 +2174,12 @@ decode_coding_sjis_big5 (coding, source, destination,
from DST_END to assure overflow checking is necessary only at the from DST_END to assure overflow checking is necessary only at the
head of loop. */ head of loop. */
unsigned char *adjusted_dst_end = dst_end - 3; unsigned char *adjusted_dst_end = dst_end - 3;
Lisp_Object unification_table Lisp_Object translation_table
= coding->character_unification_table_for_decode; = coding->character_translation_table_for_decode;
int result = CODING_FINISH_NORMAL; int result = CODING_FINISH_NORMAL;
if (!NILP (Venable_character_unification) && NILP (unification_table)) if (!NILP (Venable_character_translation) && NILP (translation_table))
unification_table = Vstandard_character_unification_table_for_decode; translation_table = Vstandard_character_translation_table_for_decode;
coding->produced_char = 0; coding->produced_char = 0;
coding->fake_multibyte = 0; coding->fake_multibyte = 0;
...@@ -2352,12 +2363,12 @@ encode_coding_sjis_big5 (coding, source, destination, ...@@ -2352,12 +2363,12 @@ encode_coding_sjis_big5 (coding, source, destination,
from DST_END to assure overflow checking is necessary only at the from DST_END to assure overflow checking is necessary only at the
head of loop. */ head of loop. */
unsigned char *adjusted_dst_end = dst_end - 1; unsigned char *adjusted_dst_end = dst_end - 1;
Lisp_Object unification_table Lisp_Object translation_table
= coding->character_unification_table_for_encode; = coding->character_translation_table_for_encode;
int result = CODING_FINISH_NORMAL; int result = CODING_FINISH_NORMAL;
if (!NILP (Venable_character_unification) && NILP (unification_table)) if (!NILP (Venable_character_translation) && NILP (translation_table))
unification_table = Vstandard_character_unification_table_for_encode; translation_table = Vstandard_character_translation_table_for_encode;
coding->consumed_char = 0; coding->consumed_char = 0;
coding->fake_multibyte = 0; coding->fake_multibyte = 0;
...@@ -2805,25 +2816,25 @@ setup_coding_system (coding_system, coding) ...@@ -2805,25 +2816,25 @@ setup_coding_system (coding_system, coding)
/* Initialize remaining fields. */ /* Initialize remaining fields. */
coding->composing = 0; coding->composing = 0;
coding->character_unification_table_for_decode = Qnil; coding->character_translation_table_for_decode = Qnil;
coding->character_unification_table_for_encode = Qnil; coding->character_translation_table_for_encode = Qnil;
/* Get values of coding system properties: /* Get values of coding system properties:
`post-read-conversion', `pre-write-conversion', `post-read-conversion', `pre-write-conversion',
`character-unification-table-for-decode', `character-translation-table-for-decode',
`character-unification-table-for-encode'. */ `character-translation-table-for-encode'. */
plist = XVECTOR (coding_spec)->contents[3]; plist = XVECTOR (coding_spec)->contents[3];
coding->post_read_conversion = Fplist_get (plist, Qpost_read_conversion); coding->post_read_conversion = Fplist_get (plist, Qpost_read_conversion);
coding->pre_write_conversion = Fplist_get (plist, Qpre_write_conversion); coding->pre_write_conversion = Fplist_get (plist, Qpre_write_conversion);
val = Fplist_get (plist, Qcharacter_unification_table_for_decode); val = Fplist_get (plist, Qcharacter_translation_table_for_decode);
if (SYMBOLP (val)) if (SYMBOLP (val))
val = Fget (val, Qcharacter_unification_table_for_decode); val = Fget (val, Qcharacter_translation_table_for_decode);
coding->character_unification_table_for_decode coding->character_translation_table_for_decode
= CHAR_TABLE_P (val) ? val : Qnil; = CHAR_TABLE_P (val) ? val : Qnil;
val = Fplist_get (plist, Qcharacter_unification_table_for_encode); val = Fplist_get (plist, Qcharacter_translation_table_for_encode);
if (SYMBOLP (val)) if (SYMBOLP (val))
val = Fget (val, Qcharacter_unification_table_for_encode); val = Fget (val, Qcharacter_translation_table_for_encode);
coding->character_unification_table_for_encode coding->character_translation_table_for_encode
= CHAR_TABLE_P (val) ? val : Qnil; = CHAR_TABLE_P (val) ? val : Qnil;
val = Fplist_get (plist, Qcoding_category); val = Fplist_get (plist, Qcoding_category);
if (!NILP (val)) if (!NILP (val))
...@@ -5129,18 +5140,21 @@ syms_of_coding () ...@@ -5129,18 +5140,21 @@ syms_of_coding ()
} }
} }
Qcharacter_unification_table = intern ("character-unification-table"); Qcharacter_translation_table = intern ("character-translation-table");
staticpro (&Qcharacter_unification_table); staticpro (&Qcharacter_translation_table);
Fput (Qcharacter_unification_table, Qchar_table_extra_slots, Fput (Qcharacter_translation_table, Qchar_table_extra_slots,
make_number (0)); make_number (0));
Qcharacter_unification_table_for_decode Qcharacter_translation_table_id = intern ("character-translation-table-id");
= intern ("character-unification-table-for-decode"); staticpro (&Qcharacter_translation_table_id);
staticpro (&Qcharacter_unification_table_for_decode);
Qcharacter_translation_table_for_decode
= intern ("character-translation-table-for-decode");
staticpro (&Qcharacter_translation_table_for_decode);
Qcharacter_unification_table_for_encode Qcharacter_translation_table_for_encode
= intern ("character-unification-table-for-encode"); = intern ("character-translation-table-for-encode");
staticpro (&Qcharacter_unification_table_for_encode); staticpro (&Qcharacter_translation_table_for_encode);
Qsafe_charsets = intern ("safe-charsets"); Qsafe_charsets = intern ("safe-charsets");
staticpro (&Qsafe_charsets); staticpro (&Qsafe_charsets);
...@@ -5297,19 +5311,19 @@ See also the function `find-operation-coding-system'."); ...@@ -5297,19 +5311,19 @@ See also the function `find-operation-coding-system'.");
"Mnemonic character indicating end-of-line format is not yet decided."); "Mnemonic character indicating end-of-line format is not yet decided.");
eol_mnemonic_undecided = ':'; eol_mnemonic_undecided = ':';
DEFVAR_LISP ("enable-character-unification", &Venable_character_unification, DEFVAR_LISP ("enable-character-translation", &Venable_character_translation,
"Non-nil means ISO 2022 encoder/decoder do character unification."); "Non-nil means ISO 2022 encoder/decoder do character translation.");
Venable_character_unification = Qt; Venable_character_translation = Qt;
DEFVAR_LISP ("standard-character-unification-table-for-decode", DEFVAR_LISP ("standard-character-translation-table-for-decode",
&Vstandard_character_unification_table_for_decode, &Vstandard_character_translation_table_for_decode,
"Table for unifying characters when reading."); "Table for translating characters while decoding.");
Vstandard_character_unification_table_for_decode = Qnil; Vstandard_character_translation_table_for_decode = Qnil;
DEFVAR_LISP ("standard-character-unification-table-for-encode", DEFVAR_LISP ("standard-character-translation-table-for-encode",
&Vstandard_character_unification_table_for_encode, &Vstandard_character_translation_table_for_encode,
"Table for unifying characters when writing."); "Table for translationg characters while encoding.");
Vstandard_character_unification_table_for_encode = Qnil; Vstandard_character_translation_table_for_encode = Qnil;
DEFVAR_LISP ("charset-revision-table", &Vcharset_revision_alist, DEFVAR_LISP ("charset-revision-table", &Vcharset_revision_alist,
"Alist of charsets vs revision numbers.\n\ "Alist of charsets vs revision numbers.\n\
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment