comparison src/coding.c @ 89873:9a279ff9d245

(DECODE_DESIGNATION): Set chars_96 to -1 instead of goto invalid_code. (decode_coding_iso_2022): Fix handling of invalid designation.
author Kenichi Handa <handa@m17n.org>
date Tue, 30 Mar 2004 13:09:38 +0000
parents 428fc37b2ae6
children a2109a2c25d5
comparison
equal deleted inserted replaced
89872:dbc1a69bd2a7 89873:9a279ff9d245
2725 detect_info->found |= (found & ~rejected); 2725 detect_info->found |= (found & ~rejected);
2726 return 1; 2726 return 1;
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; \
2734 \ 2735 \
2735 if (final < '0' || final >= 128 \ 2736 if (final < '0' || final >= 128 \
2736 || ((id = ISO_CHARSET_TABLE (dim, chars_96, final)) < 0) \ 2737 || ((id = ISO_CHARSET_TABLE (dim, chars_96, final)) < 0) \
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) \
2744 { \ 2746 { \
2745 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_USE_ROMAN) \ 2747 if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_USE_ROMAN) \
2753 CODING_ISO_DESIGNATION (coding, reg) = id; \ 2755 CODING_ISO_DESIGNATION (coding, reg) = id; \
2754 /* If there was an invalid designation to REG previously, and this \ 2756 /* If there was an invalid designation to REG previously, and this \
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
2762 #define MAYBE_FINISH_COMPOSITION() \ 2764 #define MAYBE_FINISH_COMPOSITION() \
2763 do { \ 2765 do { \
2901 int consumed_chars = 0, consumed_chars_base; 2903 int consumed_chars = 0, consumed_chars_base;
2902 int multibytep = coding->src_multibyte; 2904 int multibytep = coding->src_multibyte;
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. */
2909 #define COMPOSING_NO 0 2912 #define COMPOSING_NO 0
2910 #define COMPOSING_CHAR 1 2913 #define COMPOSING_CHAR 1
2972 components[component_idx++] = c1; 2975 components[component_idx++] = c1;
2973 composition_state--; 2976 composition_state--;
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:
2981 if (charset_id_1 < 0 2987 if (charset_id_1 < 0
2982 || ! CHARSET_ISO_CHARS_96 (CHARSET_FROM_ID (charset_id_1)) 2988 || ! CHARSET_ISO_CHARS_96 (CHARSET_FROM_ID (charset_id_1))
3053 goto label_escape_sequence; 3059 goto label_escape_sequence;
3054 3060
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 */
3082 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT) 3097 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LOCKING_SHIFT)
3083 || CODING_ISO_DESIGNATION (coding, 2) < 0) 3098 || CODING_ISO_DESIGNATION (coding, 2) < 0)
3096 3111
3097 case 'N': /* invocation of single-shift-2 */ 3112 case 'N': /* invocation of single-shift-2 */
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;
3105 break; 3124 break;
3106 3125
3107 case 'O': /* invocation of single-shift-3 */ 3126 case 'O': /* invocation of single-shift-3 */
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;
3115 break; 3138 break;
3116 3139
3225 break; 3248 break;
3226 3249
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 }
3248 3280
3249 if (charset->id != charset_ascii 3281 if (charset->id != charset_ascii