aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c203
1 files changed, 79 insertions, 124 deletions
diff --git a/src/coding.c b/src/coding.c
index f6310369ad3..9a6a4484e50 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -395,8 +395,6 @@ Lisp_Object Vbig5_coding_system;
395 395
396/* Control characters of ISO2022. */ 396/* Control characters of ISO2022. */
397 /* code */ /* function */ 397 /* code */ /* function */
398#define ISO_CODE_LF 0x0A /* line-feed */
399#define ISO_CODE_CR 0x0D /* carriage-return */
400#define ISO_CODE_SO 0x0E /* shift-out */ 398#define ISO_CODE_SO 0x0E /* shift-out */
401#define ISO_CODE_SI 0x0F /* shift-in */ 399#define ISO_CODE_SI 0x0F /* shift-in */
402#define ISO_CODE_SS2_7 0x19 /* single-shift-2 for 7-bit code */ 400#define ISO_CODE_SS2_7 0x19 /* single-shift-2 for 7-bit code */
@@ -479,7 +477,7 @@ enum iso_code_class_type
479 477
480#define CODING_ISO_FLAG_COMPOSITION 0x2000 478#define CODING_ISO_FLAG_COMPOSITION 0x2000
481 479
482#define CODING_ISO_FLAG_EUC_TW_SHIFT 0x4000 480/* #define CODING_ISO_FLAG_EUC_TW_SHIFT 0x4000 */
483 481
484#define CODING_ISO_FLAG_USE_ROMAN 0x8000 482#define CODING_ISO_FLAG_USE_ROMAN 0x8000
485 483
@@ -721,25 +719,6 @@ static struct coding_system coding_categories[coding_category_max];
721 } while (0) 719 } while (0)
722 720
723 721
724#define ONE_MORE_BYTE_NO_CHECK(c) \
725 do { \
726 c = *src++; \
727 if (multibytep && (c & 0x80)) \
728 { \
729 if ((c & 0xFE) == 0xC0) \
730 c = ((c & 1) << 6) | *src++; \
731 else \
732 { \
733 src--; \
734 c = - string_char (src, &src, NULL); \
735 record_conversion_result \
736 (coding, CODING_RESULT_INVALID_SRC); \
737 } \
738 } \
739 consumed_chars++; \
740 } while (0)
741
742
743/* Store a byte C in the place pointed by DST and increment DST to the 722/* Store a byte C in the place pointed by DST and increment DST to the
744 next free point, and increment PRODUCED_CHARS. The caller should 723 next free point, and increment PRODUCED_CHARS. The caller should
745 assure that C is 0..127, and declare and set the variable `dst' 724 assure that C is 0..127, and declare and set the variable `dst'
@@ -1051,9 +1030,10 @@ coding_set_source (struct coding_system *coding)
1051 coding->source = SDATA (coding->src_object) + coding->src_pos_byte; 1030 coding->source = SDATA (coding->src_object) + coding->src_pos_byte;
1052 } 1031 }
1053 else 1032 else
1054 /* Otherwise, the source is C string and is never relocated 1033 {
1055 automatically. Thus we don't have to update anything. */ 1034 /* Otherwise, the source is C string and is never relocated
1056 ; 1035 automatically. Thus we don't have to update anything. */
1036 }
1057} 1037}
1058 1038
1059static void 1039static void
@@ -1079,9 +1059,10 @@ coding_set_destination (struct coding_system *coding)
1079 } 1059 }
1080 } 1060 }
1081 else 1061 else
1082 /* Otherwise, the destination is C string and is never relocated 1062 {
1083 automatically. Thus we don't have to update anything. */ 1063 /* Otherwise, the destination is C string and is never relocated
1084 ; 1064 automatically. Thus we don't have to update anything. */
1065 }
1085} 1066}
1086 1067
1087 1068
@@ -1217,7 +1198,6 @@ alloc_destination (struct coding_system *coding, EMACS_INT nbytes,
1217#define UTF_8_4_OCTET_LEADING_P(c) (((c) & 0xF8) == 0xF0) 1198#define UTF_8_4_OCTET_LEADING_P(c) (((c) & 0xF8) == 0xF0)
1218#define UTF_8_5_OCTET_LEADING_P(c) (((c) & 0xFC) == 0xF8) 1199#define UTF_8_5_OCTET_LEADING_P(c) (((c) & 0xFC) == 0xF8)
1219 1200
1220#define UTF_BOM 0xFEFF
1221#define UTF_8_BOM_1 0xEF 1201#define UTF_8_BOM_1 0xEF
1222#define UTF_8_BOM_2 0xBB 1202#define UTF_8_BOM_2 0xBB
1223#define UTF_8_BOM_3 0xBF 1203#define UTF_8_BOM_3 0xBF
@@ -1318,7 +1298,7 @@ decode_coding_utf_8 (struct coding_system *coding)
1318 int multibytep = coding->src_multibyte; 1298 int multibytep = coding->src_multibyte;
1319 enum utf_bom_type bom = CODING_UTF_8_BOM (coding); 1299 enum utf_bom_type bom = CODING_UTF_8_BOM (coding);
1320 Lisp_Object attr, charset_list; 1300 Lisp_Object attr, charset_list;
1321 int eol_crlf = 1301 int eol_dos =
1322 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 1302 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
1323 int byte_after_cr = -1; 1303 int byte_after_cr = -1;
1324 1304
@@ -1379,7 +1359,7 @@ decode_coding_utf_8 (struct coding_system *coding)
1379 } 1359 }
1380 else if (UTF_8_1_OCTET_P (c1)) 1360 else if (UTF_8_1_OCTET_P (c1))
1381 { 1361 {
1382 if (eol_crlf && c1 == '\r') 1362 if (eol_dos && c1 == '\r')
1383 ONE_MORE_BYTE (byte_after_cr); 1363 ONE_MORE_BYTE (byte_after_cr);
1384 c = c1; 1364 c = c1;
1385 } 1365 }
@@ -1533,11 +1513,6 @@ encode_coding_utf_8 (struct coding_system *coding)
1533#define UTF_16_LOW_SURROGATE_P(val) \ 1513#define UTF_16_LOW_SURROGATE_P(val) \
1534 (((val) & 0xFC00) == 0xDC00) 1514 (((val) & 0xFC00) == 0xDC00)
1535 1515
1536#define UTF_16_INVALID_P(val) \
1537 (((val) == 0xFFFE) \
1538 || ((val) == 0xFFFF) \
1539 || UTF_16_LOW_SURROGATE_P (val))
1540
1541 1516
1542static int 1517static int
1543detect_coding_utf_16 (struct coding_system *coding, 1518detect_coding_utf_16 (struct coding_system *coding,
@@ -1637,7 +1612,7 @@ decode_coding_utf_16 (struct coding_system *coding)
1637 enum utf_16_endian_type endian = CODING_UTF_16_ENDIAN (coding); 1612 enum utf_16_endian_type endian = CODING_UTF_16_ENDIAN (coding);
1638 int surrogate = CODING_UTF_16_SURROGATE (coding); 1613 int surrogate = CODING_UTF_16_SURROGATE (coding);
1639 Lisp_Object attr, charset_list; 1614 Lisp_Object attr, charset_list;
1640 int eol_crlf = 1615 int eol_dos =
1641 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 1616 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
1642 int byte_after_cr1 = -1, byte_after_cr2 = -1; 1617 int byte_after_cr1 = -1, byte_after_cr2 = -1;
1643 1618
@@ -1734,7 +1709,7 @@ decode_coding_utf_16 (struct coding_system *coding)
1734 CODING_UTF_16_SURROGATE (coding) = surrogate = c; 1709 CODING_UTF_16_SURROGATE (coding) = surrogate = c;
1735 else 1710 else
1736 { 1711 {
1737 if (eol_crlf && c == '\r') 1712 if (eol_dos && c == '\r')
1738 { 1713 {
1739 ONE_MORE_BYTE (byte_after_cr1); 1714 ONE_MORE_BYTE (byte_after_cr1);
1740 ONE_MORE_BYTE (byte_after_cr2); 1715 ONE_MORE_BYTE (byte_after_cr2);
@@ -1918,17 +1893,17 @@ detect_coding_emacs_mule (struct coding_system *coding,
1918 it because analyzing it is too heavy for detecting. But, 1893 it because analyzing it is too heavy for detecting. But,
1919 at least, we check that the composite character 1894 at least, we check that the composite character
1920 constitutes of more than 4 bytes. */ 1895 constitutes of more than 4 bytes. */
1921 const unsigned char *src_base; 1896 const unsigned char *src_start;
1922 1897
1923 repeat: 1898 repeat:
1924 src_base = src; 1899 src_start = src;
1925 do 1900 do
1926 { 1901 {
1927 ONE_MORE_BYTE (c); 1902 ONE_MORE_BYTE (c);
1928 } 1903 }
1929 while (c >= 0xA0); 1904 while (c >= 0xA0);
1930 1905
1931 if (src - src_base <= 4) 1906 if (src - src_start <= 4)
1932 break; 1907 break;
1933 found = CATEGORY_MASK_EMACS_MULE; 1908 found = CATEGORY_MASK_EMACS_MULE;
1934 if (c == 0x80) 1909 if (c == 0x80)
@@ -1980,7 +1955,7 @@ detect_coding_emacs_mule (struct coding_system *coding,
1980 the decoded character or rule. If an invalid byte is found, return 1955 the decoded character or rule. If an invalid byte is found, return
1981 -1. If SRC is too short, return -2. */ 1956 -1. If SRC is too short, return -2. */
1982 1957
1983int 1958static int
1984emacs_mule_char (struct coding_system *coding, const unsigned char *src, 1959emacs_mule_char (struct coding_system *coding, const unsigned char *src,
1985 int *nbytes, int *nchars, int *id, 1960 int *nbytes, int *nchars, int *id,
1986 struct composition_status *cmp_status) 1961 struct composition_status *cmp_status)
@@ -1988,7 +1963,7 @@ emacs_mule_char (struct coding_system *coding, const unsigned char *src,
1988 const unsigned char *src_end = coding->source + coding->src_bytes; 1963 const unsigned char *src_end = coding->source + coding->src_bytes;
1989 const unsigned char *src_base = src; 1964 const unsigned char *src_base = src;
1990 int multibytep = coding->src_multibyte; 1965 int multibytep = coding->src_multibyte;
1991 int charset_id; 1966 int charset_ID;
1992 unsigned code; 1967 unsigned code;
1993 int c; 1968 int c;
1994 int consumed_chars = 0; 1969 int consumed_chars = 0;
@@ -1998,7 +1973,7 @@ emacs_mule_char (struct coding_system *coding, const unsigned char *src,
1998 if (c < 0) 1973 if (c < 0)
1999 { 1974 {
2000 c = -c; 1975 c = -c;
2001 charset_id = emacs_mule_charset[0]; 1976 charset_ID = emacs_mule_charset[0];
2002 } 1977 }
2003 else 1978 else
2004 { 1979 {
@@ -2034,7 +2009,7 @@ emacs_mule_char (struct coding_system *coding, const unsigned char *src,
2034 switch (emacs_mule_bytes[c]) 2009 switch (emacs_mule_bytes[c])
2035 { 2010 {
2036 case 2: 2011 case 2:
2037 if ((charset_id = emacs_mule_charset[c]) < 0) 2012 if ((charset_ID = emacs_mule_charset[c]) < 0)
2038 goto invalid_code; 2013 goto invalid_code;
2039 ONE_MORE_BYTE (c); 2014 ONE_MORE_BYTE (c);
2040 if (c < 0xA0) 2015 if (c < 0xA0)
@@ -2047,7 +2022,7 @@ emacs_mule_char (struct coding_system *coding, const unsigned char *src,
2047 || c == EMACS_MULE_LEADING_CODE_PRIVATE_12) 2022 || c == EMACS_MULE_LEADING_CODE_PRIVATE_12)
2048 { 2023 {
2049 ONE_MORE_BYTE (c); 2024 ONE_MORE_BYTE (c);
2050 if (c < 0xA0 || (charset_id = emacs_mule_charset[c]) < 0) 2025 if (c < 0xA0 || (charset_ID = emacs_mule_charset[c]) < 0)
2051 goto invalid_code; 2026 goto invalid_code;
2052 ONE_MORE_BYTE (c); 2027 ONE_MORE_BYTE (c);
2053 if (c < 0xA0) 2028 if (c < 0xA0)
@@ -2056,7 +2031,7 @@ emacs_mule_char (struct coding_system *coding, const unsigned char *src,
2056 } 2031 }
2057 else 2032 else
2058 { 2033 {
2059 if ((charset_id = emacs_mule_charset[c]) < 0) 2034 if ((charset_ID = emacs_mule_charset[c]) < 0)
2060 goto invalid_code; 2035 goto invalid_code;
2061 ONE_MORE_BYTE (c); 2036 ONE_MORE_BYTE (c);
2062 if (c < 0xA0) 2037 if (c < 0xA0)
@@ -2071,7 +2046,7 @@ emacs_mule_char (struct coding_system *coding, const unsigned char *src,
2071 2046
2072 case 4: 2047 case 4:
2073 ONE_MORE_BYTE (c); 2048 ONE_MORE_BYTE (c);
2074 if (c < 0 || (charset_id = emacs_mule_charset[c]) < 0) 2049 if (c < 0 || (charset_ID = emacs_mule_charset[c]) < 0)
2075 goto invalid_code; 2050 goto invalid_code;
2076 ONE_MORE_BYTE (c); 2051 ONE_MORE_BYTE (c);
2077 if (c < 0xA0) 2052 if (c < 0xA0)
@@ -2085,21 +2060,21 @@ emacs_mule_char (struct coding_system *coding, const unsigned char *src,
2085 2060
2086 case 1: 2061 case 1:
2087 code = c; 2062 code = c;
2088 charset_id = ASCII_BYTE_P (code) ? charset_ascii : charset_eight_bit; 2063 charset_ID = ASCII_BYTE_P (code) ? charset_ascii : charset_eight_bit;
2089 break; 2064 break;
2090 2065
2091 default: 2066 default:
2092 abort (); 2067 abort ();
2093 } 2068 }
2094 CODING_DECODE_CHAR (coding, src, src_base, src_end, 2069 CODING_DECODE_CHAR (coding, src, src_base, src_end,
2095 CHARSET_FROM_ID (charset_id), code, c); 2070 CHARSET_FROM_ID (charset_ID), code, c);
2096 if (c < 0) 2071 if (c < 0)
2097 goto invalid_code; 2072 goto invalid_code;
2098 } 2073 }
2099 *nbytes = src - src_base; 2074 *nbytes = src - src_base;
2100 *nchars = consumed_chars; 2075 *nchars = consumed_chars;
2101 if (id) 2076 if (id)
2102 *id = charset_id; 2077 *id = charset_ID;
2103 return (mseq_found ? -c : c); 2078 return (mseq_found ? -c : c);
2104 2079
2105 no_more_source: 2080 no_more_source:
@@ -2372,7 +2347,7 @@ decode_coding_emacs_mule (struct coding_system *coding)
2372 int char_offset = coding->produced_char; 2347 int char_offset = coding->produced_char;
2373 int last_offset = char_offset; 2348 int last_offset = char_offset;
2374 int last_id = charset_ascii; 2349 int last_id = charset_ascii;
2375 int eol_crlf = 2350 int eol_dos =
2376 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 2351 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
2377 int byte_after_cr = -1; 2352 int byte_after_cr = -1;
2378 struct composition_status *cmp_status = &coding->spec.emacs_mule.cmp_status; 2353 struct composition_status *cmp_status = &coding->spec.emacs_mule.cmp_status;
@@ -2390,7 +2365,7 @@ decode_coding_emacs_mule (struct coding_system *coding)
2390 2365
2391 while (1) 2366 while (1)
2392 { 2367 {
2393 int c, id; 2368 int c, id IF_LINT (= 0);
2394 2369
2395 src_base = src; 2370 src_base = src;
2396 consumed_chars_base = consumed_chars; 2371 consumed_chars_base = consumed_chars;
@@ -2422,7 +2397,7 @@ decode_coding_emacs_mule (struct coding_system *coding)
2422 2397
2423 if (c < 0x80) 2398 if (c < 0x80)
2424 { 2399 {
2425 if (eol_crlf && c == '\r') 2400 if (eol_dos && c == '\r')
2426 ONE_MORE_BYTE (byte_after_cr); 2401 ONE_MORE_BYTE (byte_after_cr);
2427 id = charset_ascii; 2402 id = charset_ascii;
2428 if (cmp_status->state != COMPOSING_NO) 2403 if (cmp_status->state != COMPOSING_NO)
@@ -2435,7 +2410,7 @@ decode_coding_emacs_mule (struct coding_system *coding)
2435 } 2410 }
2436 else 2411 else
2437 { 2412 {
2438 int nchars, nbytes; 2413 int nchars IF_LINT (= 0), nbytes IF_LINT (= 0);
2439 /* emacs_mule_char can load a charset map from a file, which 2414 /* emacs_mule_char can load a charset map from a file, which
2440 allocates a large structure and might cause buffer text 2415 allocates a large structure and might cause buffer text
2441 to be relocated as result. Thus, we need to remember the 2416 to be relocated as result. Thus, we need to remember the
@@ -2903,10 +2878,6 @@ enum iso_code_class_type iso_code_class[256];
2903 ((id) <= (coding)->max_charset_id \ 2878 ((id) <= (coding)->max_charset_id \
2904 && (coding)->safe_charsets[id] != 255) 2879 && (coding)->safe_charsets[id] != 255)
2905 2880
2906
2907#define SHIFT_OUT_OK(category) \
2908 (CODING_ISO_INITIAL (&coding_categories[category], 1) >= 0)
2909
2910static void 2881static void
2911setup_iso_safe_charsets (Lisp_Object attrs) 2882setup_iso_safe_charsets (Lisp_Object attrs)
2912{ 2883{
@@ -2983,7 +2954,12 @@ detect_coding_iso_2022 (struct coding_system *coding,
2983 const unsigned char *src_end = coding->source + coding->src_bytes; 2954 const unsigned char *src_end = coding->source + coding->src_bytes;
2984 int multibytep = coding->src_multibyte; 2955 int multibytep = coding->src_multibyte;
2985 int single_shifting = 0; 2956 int single_shifting = 0;
2986 int id; 2957
2958 /* FIXME: Does ID need to be initialized here? The "End of composition"
2959 code below does not initialize ID even though ID is used
2960 afterwards, and perhaps that is a bug. */
2961 int id = 0;
2962
2987 int c, c1; 2963 int c, c1;
2988 int consumed_chars = 0; 2964 int consumed_chars = 0;
2989 int i; 2965 int i;
@@ -3158,7 +3134,7 @@ detect_coding_iso_2022 (struct coding_system *coding,
3158 if (! single_shifting 3134 if (! single_shifting
3159 && ! (rejected & CATEGORY_MASK_ISO_8_2)) 3135 && ! (rejected & CATEGORY_MASK_ISO_8_2))
3160 { 3136 {
3161 int i = 1; 3137 int len = 1;
3162 while (src < src_end) 3138 while (src < src_end)
3163 { 3139 {
3164 src_base = src; 3140 src_base = src;
@@ -3168,20 +3144,20 @@ detect_coding_iso_2022 (struct coding_system *coding,
3168 src = src_base; 3144 src = src_base;
3169 break; 3145 break;
3170 } 3146 }
3171 i++; 3147 len++;
3172 } 3148 }
3173 3149
3174 if (i & 1 && src < src_end) 3150 if (len & 1 && src < src_end)
3175 { 3151 {
3176 rejected |= CATEGORY_MASK_ISO_8_2; 3152 rejected |= CATEGORY_MASK_ISO_8_2;
3177 if (composition_count >= 0) 3153 if (composition_count >= 0)
3178 composition_count += i; 3154 composition_count += len;
3179 } 3155 }
3180 else 3156 else
3181 { 3157 {
3182 found |= CATEGORY_MASK_ISO_8_2; 3158 found |= CATEGORY_MASK_ISO_8_2;
3183 if (composition_count >= 0) 3159 if (composition_count >= 0)
3184 composition_count += i / 2; 3160 composition_count += len / 2;
3185 } 3161 }
3186 } 3162 }
3187 break; 3163 break;
@@ -3309,10 +3285,10 @@ detect_coding_iso_2022 (struct coding_system *coding,
3309 } \ 3285 } \
3310 else /* new format (after ver.21) */ \ 3286 else /* new format (after ver.21) */ \
3311 { \ 3287 { \
3312 int c; \ 3288 int b; \
3313 \ 3289 \
3314 ONE_MORE_BYTE (c); \ 3290 ONE_MORE_BYTE (b); \
3315 rule = COMPOSITION_ENCODE_RULE (rule - 81, c - 32); \ 3291 rule = COMPOSITION_ENCODE_RULE (rule - 81, b - 32); \
3316 if (rule >= 0) \ 3292 if (rule >= 0) \
3317 rule += 0x100; /* to destinguish it from the old format */ \ 3293 rule += 0x100; /* to destinguish it from the old format */ \
3318 nbytes = 2; \ 3294 nbytes = 2; \
@@ -3504,7 +3480,7 @@ decode_coding_iso_2022 (struct coding_system *coding)
3504 int char_offset = coding->produced_char; 3480 int char_offset = coding->produced_char;
3505 int last_offset = char_offset; 3481 int last_offset = char_offset;
3506 int last_id = charset_ascii; 3482 int last_id = charset_ascii;
3507 int eol_crlf = 3483 int eol_dos =
3508 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 3484 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
3509 int byte_after_cr = -1; 3485 int byte_after_cr = -1;
3510 int i; 3486 int i;
@@ -3624,7 +3600,7 @@ decode_coding_iso_2022 (struct coding_system *coding)
3624 break; 3600 break;
3625 3601
3626 case ISO_control_0: 3602 case ISO_control_0:
3627 if (eol_crlf && c1 == '\r') 3603 if (eol_dos && c1 == '\r')
3628 ONE_MORE_BYTE (byte_after_cr); 3604 ONE_MORE_BYTE (byte_after_cr);
3629 MAYBE_FINISH_COMPOSITION (); 3605 MAYBE_FINISH_COMPOSITION ();
3630 charset = CHARSET_FROM_ID (charset_ascii); 3606 charset = CHARSET_FROM_ID (charset_ascii);
@@ -3897,6 +3873,10 @@ decode_coding_iso_2022 (struct coding_system *coding)
3897 } 3873 }
3898 continue; 3874 continue;
3899 } 3875 }
3876 break;
3877
3878 default:
3879 abort ();
3900 } 3880 }
3901 3881
3902 if (cmp_status->state == COMPOSING_NO 3882 if (cmp_status->state == COMPOSING_NO
@@ -4029,7 +4009,6 @@ decode_coding_iso_2022 (struct coding_system *coding)
4029 const char *intermediate_char_94 = "()*+"; \ 4009 const char *intermediate_char_94 = "()*+"; \
4030 const char *intermediate_char_96 = ",-./"; \ 4010 const char *intermediate_char_96 = ",-./"; \
4031 int revision = -1; \ 4011 int revision = -1; \
4032 int c; \
4033 \ 4012 \
4034 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_REVISION) \ 4013 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_REVISION) \
4035 revision = CHARSET_ISO_REVISION (charset); \ 4014 revision = CHARSET_ISO_REVISION (charset); \
@@ -4042,11 +4021,12 @@ decode_coding_iso_2022 (struct coding_system *coding)
4042 EMIT_ONE_ASCII_BYTE (ISO_CODE_ESC); \ 4021 EMIT_ONE_ASCII_BYTE (ISO_CODE_ESC); \
4043 if (CHARSET_DIMENSION (charset) == 1) \ 4022 if (CHARSET_DIMENSION (charset) == 1) \
4044 { \ 4023 { \
4024 int b; \
4045 if (! CHARSET_ISO_CHARS_96 (charset)) \ 4025 if (! CHARSET_ISO_CHARS_96 (charset)) \
4046 c = intermediate_char_94[reg]; \ 4026 b = intermediate_char_94[reg]; \
4047 else \ 4027 else \
4048 c = intermediate_char_96[reg]; \ 4028 b = intermediate_char_96[reg]; \
4049 EMIT_ONE_ASCII_BYTE (c); \ 4029 EMIT_ONE_ASCII_BYTE (b); \
4050 } \ 4030 } \
4051 else \ 4031 else \
4052 { \ 4032 { \
@@ -4226,7 +4206,7 @@ decode_coding_iso_2022 (struct coding_system *coding)
4226 to use CHARSET. The element `spec.iso_2022' of *CODING is updated. 4206 to use CHARSET. The element `spec.iso_2022' of *CODING is updated.
4227 Return new DST. */ 4207 Return new DST. */
4228 4208
4229unsigned char * 4209static unsigned char *
4230encode_invocation_designation (struct charset *charset, 4210encode_invocation_designation (struct charset *charset,
4231 struct coding_system *coding, 4211 struct coding_system *coding,
4232 unsigned char *dst, int *p_nchars) 4212 unsigned char *dst, int *p_nchars)
@@ -4289,30 +4269,6 @@ encode_invocation_designation (struct charset *charset,
4289 return dst; 4269 return dst;
4290} 4270}
4291 4271
4292/* The following three macros produce codes for indicating direction
4293 of text. */
4294#define ENCODE_CONTROL_SEQUENCE_INTRODUCER \
4295 do { \
4296 if (CODING_ISO_FLAGS (coding) == CODING_ISO_FLAG_SEVEN_BITS) \
4297 EMIT_TWO_ASCII_BYTES (ISO_CODE_ESC, '['); \
4298 else \
4299 EMIT_ONE_BYTE (ISO_CODE_CSI); \
4300 } while (0)
4301
4302
4303#define ENCODE_DIRECTION_R2L() \
4304 do { \
4305 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \
4306 EMIT_TWO_ASCII_BYTES ('2', ']'); \
4307 } while (0)
4308
4309
4310#define ENCODE_DIRECTION_L2R() \
4311 do { \
4312 ENCODE_CONTROL_SEQUENCE_INTRODUCER (dst); \
4313 EMIT_TWO_ASCII_BYTES ('0', ']'); \
4314 } while (0)
4315
4316 4272
4317/* Produce codes for designation and invocation to reset the graphic 4273/* Produce codes for designation and invocation to reset the graphic
4318 planes and registers to initial state. */ 4274 planes and registers to initial state. */
@@ -4707,7 +4663,7 @@ decode_coding_sjis (struct coding_system *coding)
4707 int char_offset = coding->produced_char; 4663 int char_offset = coding->produced_char;
4708 int last_offset = char_offset; 4664 int last_offset = char_offset;
4709 int last_id = charset_ascii; 4665 int last_id = charset_ascii;
4710 int eol_crlf = 4666 int eol_dos =
4711 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 4667 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
4712 int byte_after_cr = -1; 4668 int byte_after_cr = -1;
4713 4669
@@ -4742,7 +4698,7 @@ decode_coding_sjis (struct coding_system *coding)
4742 goto invalid_code; 4698 goto invalid_code;
4743 if (c < 0x80) 4699 if (c < 0x80)
4744 { 4700 {
4745 if (eol_crlf && c == '\r') 4701 if (eol_dos && c == '\r')
4746 ONE_MORE_BYTE (byte_after_cr); 4702 ONE_MORE_BYTE (byte_after_cr);
4747 charset = charset_roman; 4703 charset = charset_roman;
4748 } 4704 }
@@ -4824,7 +4780,7 @@ decode_coding_big5 (struct coding_system *coding)
4824 int char_offset = coding->produced_char; 4780 int char_offset = coding->produced_char;
4825 int last_offset = char_offset; 4781 int last_offset = char_offset;
4826 int last_id = charset_ascii; 4782 int last_id = charset_ascii;
4827 int eol_crlf = 4783 int eol_dos =
4828 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 4784 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
4829 int byte_after_cr = -1; 4785 int byte_after_cr = -1;
4830 4786
@@ -4857,7 +4813,7 @@ decode_coding_big5 (struct coding_system *coding)
4857 goto invalid_code; 4813 goto invalid_code;
4858 if (c < 0x80) 4814 if (c < 0x80)
4859 { 4815 {
4860 if (eol_crlf && c == '\r') 4816 if (eol_dos && c == '\r')
4861 ONE_MORE_BYTE (byte_after_cr); 4817 ONE_MORE_BYTE (byte_after_cr);
4862 charset = charset_roman; 4818 charset = charset_roman;
4863 } 4819 }
@@ -5261,13 +5217,13 @@ encode_coding_ccl (struct coding_system *coding)
5261static void 5217static void
5262decode_coding_raw_text (struct coding_system *coding) 5218decode_coding_raw_text (struct coding_system *coding)
5263{ 5219{
5264 int eol_crlf = 5220 int eol_dos =
5265 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 5221 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
5266 5222
5267 coding->chars_at_source = 1; 5223 coding->chars_at_source = 1;
5268 coding->consumed_char = coding->src_chars; 5224 coding->consumed_char = coding->src_chars;
5269 coding->consumed = coding->src_bytes; 5225 coding->consumed = coding->src_bytes;
5270 if (eol_crlf && coding->source[coding->src_bytes - 1] == '\r') 5226 if (eol_dos && coding->source[coding->src_bytes - 1] == '\r')
5271 { 5227 {
5272 coding->consumed_char--; 5228 coding->consumed_char--;
5273 coding->consumed--; 5229 coding->consumed--;
@@ -5480,7 +5436,7 @@ decode_coding_charset (struct coding_system *coding)
5480 int char_offset = coding->produced_char; 5436 int char_offset = coding->produced_char;
5481 int last_offset = char_offset; 5437 int last_offset = char_offset;
5482 int last_id = charset_ascii; 5438 int last_id = charset_ascii;
5483 int eol_crlf = 5439 int eol_dos =
5484 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); 5440 !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos);
5485 int byte_after_cr = -1; 5441 int byte_after_cr = -1;
5486 5442
@@ -5514,7 +5470,7 @@ decode_coding_charset (struct coding_system *coding)
5514 else 5470 else
5515 { 5471 {
5516 ONE_MORE_BYTE (c); 5472 ONE_MORE_BYTE (c);
5517 if (eol_crlf && c == '\r') 5473 if (eol_dos && c == '\r')
5518 ONE_MORE_BYTE (byte_after_cr); 5474 ONE_MORE_BYTE (byte_after_cr);
5519 } 5475 }
5520 if (c < 0) 5476 if (c < 0)
@@ -6607,15 +6563,15 @@ get_translation_table (Lisp_Object attrs, int encodep, int *max_lookup)
6607 } 6563 }
6608 else if (CONSP (translation_table)) 6564 else if (CONSP (translation_table))
6609 { 6565 {
6610 Lisp_Object tail, val; 6566 Lisp_Object tail;
6611 6567
6612 for (tail = translation_table; CONSP (tail); tail = XCDR (tail)) 6568 for (tail = translation_table; CONSP (tail); tail = XCDR (tail))
6613 if (CHAR_TABLE_P (XCAR (tail)) 6569 if (CHAR_TABLE_P (XCAR (tail))
6614 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (XCAR (tail))) > 1) 6570 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (XCAR (tail))) > 1)
6615 { 6571 {
6616 val = XCHAR_TABLE (XCAR (tail))->extras[1]; 6572 Lisp_Object tailval = XCHAR_TABLE (XCAR (tail))->extras[1];
6617 if (NATNUMP (val) && *max_lookup < XFASTINT (val)) 6573 if (NATNUMP (tailval) && *max_lookup < XFASTINT (tailval))
6618 *max_lookup = XFASTINT (val); 6574 *max_lookup = XFASTINT (tailval);
6619 } 6575 }
6620 } 6576 }
6621 } 6577 }
@@ -7652,12 +7608,12 @@ decode_coding_object (struct coding_system *coding,
7652 Lisp_Object dst_object) 7608 Lisp_Object dst_object)
7653{ 7609{
7654 int count = SPECPDL_INDEX (); 7610 int count = SPECPDL_INDEX ();
7655 unsigned char *destination; 7611 unsigned char *destination IF_LINT (= NULL);
7656 EMACS_INT dst_bytes; 7612 EMACS_INT dst_bytes IF_LINT (= 0);
7657 EMACS_INT chars = to - from; 7613 EMACS_INT chars = to - from;
7658 EMACS_INT bytes = to_byte - from_byte; 7614 EMACS_INT bytes = to_byte - from_byte;
7659 Lisp_Object attrs; 7615 Lisp_Object attrs;
7660 int saved_pt = -1, saved_pt_byte; 7616 int saved_pt = -1, saved_pt_byte IF_LINT (= 0);
7661 int need_marker_adjustment = 0; 7617 int need_marker_adjustment = 0;
7662 Lisp_Object old_deactivate_mark; 7618 Lisp_Object old_deactivate_mark;
7663 7619
@@ -7845,7 +7801,7 @@ encode_coding_object (struct coding_system *coding,
7845 EMACS_INT chars = to - from; 7801 EMACS_INT chars = to - from;
7846 EMACS_INT bytes = to_byte - from_byte; 7802 EMACS_INT bytes = to_byte - from_byte;
7847 Lisp_Object attrs; 7803 Lisp_Object attrs;
7848 int saved_pt = -1, saved_pt_byte; 7804 int saved_pt = -1, saved_pt_byte IF_LINT (= 0);
7849 int need_marker_adjustment = 0; 7805 int need_marker_adjustment = 0;
7850 int kill_src_buffer = 0; 7806 int kill_src_buffer = 0;
7851 Lisp_Object old_deactivate_mark; 7807 Lisp_Object old_deactivate_mark;
@@ -8178,8 +8134,8 @@ detect_coding_system (const unsigned char *src,
8178 base_category = XINT (CODING_ATTR_CATEGORY (attrs)); 8134 base_category = XINT (CODING_ATTR_CATEGORY (attrs));
8179 if (base_category == coding_category_undecided) 8135 if (base_category == coding_category_undecided)
8180 { 8136 {
8181 enum coding_category category; 8137 enum coding_category category IF_LINT (= 0);
8182 struct coding_system *this; 8138 struct coding_system *this IF_LINT (= NULL);
8183 int c, i; 8139 int c, i;
8184 8140
8185 /* Skip all ASCII bytes except for a few ISO2022 controls. */ 8141 /* Skip all ASCII bytes except for a few ISO2022 controls. */
@@ -9112,10 +9068,10 @@ Return the corresponding character. */)
9112 } 9068 }
9113 else 9069 else
9114 { 9070 {
9115 int s1 = c >> 8, s2 = c & 0xFF; 9071 int c1 = c >> 8, c2 = c & 0xFF;
9116 9072
9117 if (s1 < 0x81 || (s1 > 0x9F && s1 < 0xE0) || s1 > 0xEF 9073 if (c1 < 0x81 || (c1 > 0x9F && c1 < 0xE0) || c1 > 0xEF
9118 || s2 < 0x40 || s2 == 0x7F || s2 > 0xFC) 9074 || c2 < 0x40 || c2 == 0x7F || c2 > 0xFC)
9119 error ("Invalid code: %d", code); 9075 error ("Invalid code: %d", code);
9120 SJIS_TO_JIS (c); 9076 SJIS_TO_JIS (c);
9121 charset = charset_kanji; 9077 charset = charset_kanji;
@@ -9798,7 +9754,6 @@ usage: (define-coding-system-internal ...) */)
9798 else if (EQ (coding_type, Qiso_2022)) 9754 else if (EQ (coding_type, Qiso_2022))
9799 { 9755 {
9800 Lisp_Object initial, reg_usage, request, flags; 9756 Lisp_Object initial, reg_usage, request, flags;
9801 int i;
9802 9757
9803 if (nargs < coding_arg_iso2022_max) 9758 if (nargs < coding_arg_iso2022_max)
9804 goto short_args; 9759 goto short_args;
@@ -9830,12 +9785,12 @@ usage: (define-coding-system-internal ...) */)
9830 for (tail = request; ! NILP (tail); tail = Fcdr (tail)) 9785 for (tail = request; ! NILP (tail); tail = Fcdr (tail))
9831 { 9786 {
9832 int id; 9787 int id;
9833 Lisp_Object tmp; 9788 Lisp_Object tmp1;
9834 9789
9835 val = Fcar (tail); 9790 val = Fcar (tail);
9836 CHECK_CONS (val); 9791 CHECK_CONS (val);
9837 tmp = XCAR (val); 9792 tmp1 = XCAR (val);
9838 CHECK_CHARSET_GET_ID (tmp, id); 9793 CHECK_CHARSET_GET_ID (tmp1, id);
9839 CHECK_NATNUM_CDR (val); 9794 CHECK_NATNUM_CDR (val);
9840 if (XINT (XCDR (val)) >= 4) 9795 if (XINT (XCDR (val)) >= 4)
9841 error ("Invalid graphic register number: %d", XINT (XCDR (val))); 9796 error ("Invalid graphic register number: %d", XINT (XCDR (val)));