diff options
| author | Kenichi Handa | 2004-03-30 13:09:38 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2004-03-30 13:09:38 +0000 |
| commit | 134b9549696f50a682f3fdda47499c9cdd530401 (patch) | |
| tree | 52e885d1abe7c433bd8a5ea6e007db535d5ffa42 /src/coding.c | |
| parent | b7a2031e09793cd849f3d718fa95f25b7ee2b1d7 (diff) | |
| download | emacs-134b9549696f50a682f3fdda47499c9cdd530401.tar.gz emacs-134b9549696f50a682f3fdda47499c9cdd530401.zip | |
(DECODE_DESIGNATION): Set chars_96 to -1 instead of
goto invalid_code.
(decode_coding_iso_2022): Fix handling of invalid designation.
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 114 |
1 files changed, 73 insertions, 41 deletions
diff --git a/src/coding.c b/src/coding.c index f50bfa8d85b..d78f14b1445 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -2727,7 +2727,8 @@ detect_coding_iso_2022 (coding, detect_info) | |||
| 2727 | } | 2727 | } |
| 2728 | 2728 | ||
| 2729 | 2729 | ||
| 2730 | /* Set designation state into CODING. */ | 2730 | /* Set designation state into CODING. Set CHARS_96 to -1 if the |
| 2731 | escape sequence should be kept. */ | ||
| 2731 | #define DECODE_DESIGNATION(reg, dim, chars_96, final) \ | 2732 | #define DECODE_DESIGNATION(reg, dim, chars_96, final) \ |
| 2732 | do { \ | 2733 | do { \ |
| 2733 | int id, prev; \ | 2734 | int id, prev; \ |
| @@ -2737,7 +2738,8 @@ detect_coding_iso_2022 (coding, detect_info) | |||
| 2737 | || !SAFE_CHARSET_P (coding, id)) \ | 2738 | || !SAFE_CHARSET_P (coding, id)) \ |
| 2738 | { \ | 2739 | { \ |
| 2739 | CODING_ISO_DESIGNATION (coding, reg) = -2; \ | 2740 | CODING_ISO_DESIGNATION (coding, reg) = -2; \ |
| 2740 | goto invalid_code; \ | 2741 | chars_96 = -1; \ |
| 2742 | break; \ | ||
| 2741 | } \ | 2743 | } \ |
| 2742 | prev = CODING_ISO_DESIGNATION (coding, reg); \ | 2744 | prev = CODING_ISO_DESIGNATION (coding, reg); \ |
| 2743 | if (id == charset_jisx0201_roman) \ | 2745 | if (id == charset_jisx0201_roman) \ |
| @@ -2755,7 +2757,7 @@ detect_coding_iso_2022 (coding, detect_info) | |||
| 2755 | designation is ASCII to REG, we should keep this designation \ | 2757 | designation is ASCII to REG, we should keep this designation \ |
| 2756 | sequence. */ \ | 2758 | sequence. */ \ |
| 2757 | if (prev == -2 && id == charset_ascii) \ | 2759 | if (prev == -2 && id == charset_ascii) \ |
| 2758 | goto invalid_code; \ | 2760 | chars_96 = -1; \ |
| 2759 | } while (0) | 2761 | } while (0) |
| 2760 | 2762 | ||
| 2761 | 2763 | ||
| @@ -2903,6 +2905,7 @@ decode_coding_iso_2022 (coding) | |||
| 2903 | /* Charsets invoked to graphic plane 0 and 1 respectively. */ | 2905 | /* Charsets invoked to graphic plane 0 and 1 respectively. */ |
| 2904 | int charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); | 2906 | int charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); |
| 2905 | int charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | 2907 | int charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); |
| 2908 | int charset_id_2, charset_id_3; | ||
| 2906 | struct charset *charset; | 2909 | struct charset *charset; |
| 2907 | int c; | 2910 | int c; |
| 2908 | /* For handling composition sequence. */ | 2911 | /* For handling composition sequence. */ |
| @@ -2974,7 +2977,10 @@ decode_coding_iso_2022 (coding) | |||
| 2974 | continue; | 2977 | continue; |
| 2975 | } | 2978 | } |
| 2976 | } | 2979 | } |
| 2977 | charset = CHARSET_FROM_ID (charset_id_0); | 2980 | if (charset_id_0 < 0) |
| 2981 | charset = CHARSET_FROM_ID (charset_ascii); | ||
| 2982 | else | ||
| 2983 | charset = CHARSET_FROM_ID (charset_id_0); | ||
| 2978 | break; | 2984 | break; |
| 2979 | 2985 | ||
| 2980 | case ISO_0xA0_or_0xFF: | 2986 | case ISO_0xA0_or_0xFF: |
| @@ -3055,27 +3061,36 @@ decode_coding_iso_2022 (coding) | |||
| 3055 | case '$': /* designation of 2-byte character set */ | 3061 | case '$': /* designation of 2-byte character set */ |
| 3056 | if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) | 3062 | if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
| 3057 | goto invalid_code; | 3063 | goto invalid_code; |
| 3058 | ONE_MORE_BYTE (c1); | 3064 | { |
| 3059 | if (c1 >= '@' && c1 <= 'B') | 3065 | int reg, chars96; |
| 3060 | { /* designation of JISX0208.1978, GB2312.1980, | 3066 | |
| 3067 | ONE_MORE_BYTE (c1); | ||
| 3068 | if (c1 >= '@' && c1 <= 'B') | ||
| 3069 | { /* designation of JISX0208.1978, GB2312.1980, | ||
| 3061 | or JISX0208.1980 */ | 3070 | or JISX0208.1980 */ |
| 3062 | DECODE_DESIGNATION (0, 2, 0, c1); | 3071 | reg = 0, chars96 = 0; |
| 3063 | } | 3072 | } |
| 3064 | else if (c1 >= 0x28 && c1 <= 0x2B) | 3073 | else if (c1 >= 0x28 && c1 <= 0x2B) |
| 3065 | { /* designation of DIMENSION2_CHARS94 character set */ | 3074 | { /* designation of DIMENSION2_CHARS94 character set */ |
| 3066 | ONE_MORE_BYTE (c2); | 3075 | reg = c1 - 0x28, chars96 = 0; |
| 3067 | DECODE_DESIGNATION (c1 - 0x28, 2, 0, c2); | 3076 | ONE_MORE_BYTE (c1); |
| 3068 | } | 3077 | } |
| 3069 | else if (c1 >= 0x2C && c1 <= 0x2F) | 3078 | else if (c1 >= 0x2C && c1 <= 0x2F) |
| 3070 | { /* designation of DIMENSION2_CHARS96 character set */ | 3079 | { /* designation of DIMENSION2_CHARS96 character set */ |
| 3071 | ONE_MORE_BYTE (c2); | 3080 | reg = c1 - 0x2C, chars96 = 1; |
| 3072 | DECODE_DESIGNATION (c1 - 0x2C, 2, 1, c2); | 3081 | ONE_MORE_BYTE (c1); |
| 3073 | } | 3082 | } |
| 3074 | else | 3083 | else |
| 3075 | goto invalid_code; | 3084 | goto invalid_code; |
| 3076 | /* We must update these variables now. */ | 3085 | DECODE_DESIGNATION (reg, 2, chars96, c1); |
| 3077 | charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); | 3086 | /* We must update these variables now. */ |
| 3078 | charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | 3087 | if (reg == 0) |
| 3088 | charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); | ||
| 3089 | else if (reg == 1) | ||
| 3090 | charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | ||
| 3091 | if (chars96 < 0) | ||
| 3092 | goto invalid_code; | ||
| 3093 | } | ||
| 3079 | continue; | 3094 | continue; |
| 3080 | 3095 | ||
| 3081 | case 'n': /* invocation of locking-shift-2 */ | 3096 | case 'n': /* invocation of locking-shift-2 */ |
| @@ -3098,7 +3113,11 @@ decode_coding_iso_2022 (coding) | |||
| 3098 | if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) | 3113 | if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
| 3099 | || CODING_ISO_DESIGNATION (coding, 2) < 0) | 3114 | || CODING_ISO_DESIGNATION (coding, 2) < 0) |
| 3100 | goto invalid_code; | 3115 | goto invalid_code; |
| 3101 | charset = CHARSET_FROM_ID (CODING_ISO_DESIGNATION (coding, 2)); | 3116 | charset_id_2 = CODING_ISO_DESIGNATION (coding, 2); |
| 3117 | if (charset_id_2 < 0) | ||
| 3118 | charset = CHARSET_FROM_ID (charset_ascii); | ||
| 3119 | else | ||
| 3120 | charset = CHARSET_FROM_ID (charset_id_2); | ||
| 3102 | ONE_MORE_BYTE (c1); | 3121 | ONE_MORE_BYTE (c1); |
| 3103 | if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) | 3122 | if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
| 3104 | goto invalid_code; | 3123 | goto invalid_code; |
| @@ -3108,7 +3127,11 @@ decode_coding_iso_2022 (coding) | |||
| 3108 | if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) | 3127 | if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SINGLE_SHIFT) |
| 3109 | || CODING_ISO_DESIGNATION (coding, 3) < 0) | 3128 | || CODING_ISO_DESIGNATION (coding, 3) < 0) |
| 3110 | goto invalid_code; | 3129 | goto invalid_code; |
| 3111 | charset = CHARSET_FROM_ID (CODING_ISO_DESIGNATION (coding, 3)); | 3130 | charset_id_3 = CODING_ISO_DESIGNATION (coding, 3); |
| 3131 | if (charset_id_3 < 0) | ||
| 3132 | charset = CHARSET_FROM_ID (charset_ascii); | ||
| 3133 | else | ||
| 3134 | charset = CHARSET_FROM_ID (charset_id_3); | ||
| 3112 | ONE_MORE_BYTE (c1); | 3135 | ONE_MORE_BYTE (c1); |
| 3113 | if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) | 3136 | if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) |
| 3114 | goto invalid_code; | 3137 | goto invalid_code; |
| @@ -3227,21 +3250,30 @@ decode_coding_iso_2022 (coding) | |||
| 3227 | default: | 3250 | default: |
| 3228 | if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) | 3251 | if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) |
| 3229 | goto invalid_code; | 3252 | goto invalid_code; |
| 3230 | if (c1 >= 0x28 && c1 <= 0x2B) | 3253 | { |
| 3231 | { /* designation of DIMENSION1_CHARS94 character set */ | 3254 | int reg, chars96; |
| 3232 | ONE_MORE_BYTE (c2); | 3255 | |
| 3233 | DECODE_DESIGNATION (c1 - 0x28, 1, 0, c2); | 3256 | if (c1 >= 0x28 && c1 <= 0x2B) |
| 3234 | } | 3257 | { /* designation of DIMENSION1_CHARS94 character set */ |
| 3235 | else if (c1 >= 0x2C && c1 <= 0x2F) | 3258 | reg = c1 - 0x28, chars96 = 0; |
| 3236 | { /* designation of DIMENSION1_CHARS96 character set */ | 3259 | ONE_MORE_BYTE (c1); |
| 3237 | ONE_MORE_BYTE (c2); | 3260 | } |
| 3238 | DECODE_DESIGNATION (c1 - 0x2C, 1, 1, c2); | 3261 | else if (c1 >= 0x2C && c1 <= 0x2F) |
| 3239 | } | 3262 | { /* designation of DIMENSION1_CHARS96 character set */ |
| 3240 | else | 3263 | reg = c1 - 0x2C, chars96 = 1; |
| 3241 | goto invalid_code; | 3264 | ONE_MORE_BYTE (c1); |
| 3242 | /* We must update these variables now. */ | 3265 | } |
| 3243 | charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); | 3266 | else |
| 3244 | charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | 3267 | goto invalid_code; |
| 3268 | DECODE_DESIGNATION (reg, 1, chars96, c1); | ||
| 3269 | /* We must update these variables now. */ | ||
| 3270 | if (reg == 0) | ||
| 3271 | charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); | ||
| 3272 | else if (reg == 1) | ||
| 3273 | charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); | ||
| 3274 | if (chars96 < 0) | ||
| 3275 | goto invalid_code; | ||
| 3276 | } | ||
| 3245 | continue; | 3277 | continue; |
| 3246 | } | 3278 | } |
| 3247 | } | 3279 | } |