2 * iso2022.c - support for ISO/IEC 2022 (alias ECMA-35).
4 * This isn't a complete implementation of ISO/IEC 2022, but it's
5 * close. It only handles decoding, because a fully general encoder
6 * isn't really useful. It can decode 8-bit and 7-bit versions, with
7 * support for single-byte and multi-byte character sets, all four
8 * containers (G0, G1, G2, and G3), using both single-shift and
9 * locking-shift sequences.
11 * The general principle is that any valid ISO/IEC 2022 sequence
12 * should either be correctly decoded or should emit an ERROR. The
13 * only exception to this is that the C0 and C1 sets are fixed as
14 * those of ISO/IEC 6429. Escape sequences for designating control
15 * sets are passed through, so a post-processor could fix them up if
18 * DOCS to UTF-8 works. Other DOCS sequences are ignored, which will
19 * produce surprising results.
36 enum {S4
, S6
, M4
, M6
};
38 static long int emacs_big5_1_to_unicode(int, int);
39 static long int emacs_big5_2_to_unicode(int, int);
40 static long int null_dbcs_to_unicode(int, int);
42 const struct iso2022_subcharset
{
45 const sbcs_data
*sbcs_base
;
46 long int (*dbcs_fn
)(int, int);
47 } iso2022_subcharsets
[] = {
48 { S4
, 0, '0', 0x00, &sbcsdata_CS_DEC_GRAPHICS
},
49 { S4
, 0, '<', 0x80, &sbcsdata_CS_DEC_MCS
},
50 { S4
, 0, 'A', 0x00, &sbcsdata_CS_BS4730
},
51 { S4
, 0, 'B', 0x00, &sbcsdata_CS_ASCII
},
52 { S4
, 0, 'I', 0x80, &sbcsdata_CS_JISX0201
},
53 { S4
, 0, 'J', 0x00, &sbcsdata_CS_JISX0201
},
55 { S6
, 0, 'A', 0x80, &sbcsdata_CS_ISO8859_1
},
56 { S6
, 0, 'B', 0x80, &sbcsdata_CS_ISO8859_2
},
57 { S6
, 0, 'C', 0x80, &sbcsdata_CS_ISO8859_3
},
58 { S6
, 0, 'D', 0x80, &sbcsdata_CS_ISO8859_4
},
59 { S6
, 0, 'F', 0x80, &sbcsdata_CS_ISO8859_7
},
60 { S6
, 0, 'G', 0x80, &sbcsdata_CS_ISO8859_6
},
61 { S6
, 0, 'H', 0x80, &sbcsdata_CS_ISO8859_8
},
62 { S6
, 0, 'L', 0x80, &sbcsdata_CS_ISO8859_5
},
63 { S6
, 0, 'M', 0x80, &sbcsdata_CS_ISO8859_9
},
64 { S6
, 0, 'T', 0x80, &sbcsdata_CS_ISO8859_11
},
65 { S6
, 0, 'V', 0x80, &sbcsdata_CS_ISO8859_10
},
66 { S6
, 0, 'Y', 0x80, &sbcsdata_CS_ISO8859_13
},
67 { S6
, 0, '_', 0x80, &sbcsdata_CS_ISO8859_14
},
68 { S6
, 0, 'b', 0x80, &sbcsdata_CS_ISO8859_15
},
69 { S6
, 0, 'f', 0x80, &sbcsdata_CS_ISO8859_16
},
70 { S6
, 0, '~' }, /* empty 96-set */
72 { M4
, 0, '@' }, /* JIS C 6226-1978 */
74 { M4
, 0, '0', -0x21, 0, &emacs_big5_1_to_unicode
},
75 { M4
, 0, '1', -0x21, 0, &emacs_big5_2_to_unicode
},
76 { M4
, 0, 'A', -0x21, 0, &gb2312_to_unicode
},
77 { M4
, 0, 'B', -0x21, 0, &jisx0208_to_unicode
},
78 { M4
, 0, 'C', -0x21, 0, &ksx1001_to_unicode
},
79 { M4
, 0, 'D', -0x21, 0, &jisx0212_to_unicode
},
80 { M4
, 0, '~', 0, 0, &null_dbcs_to_unicode
}, /* empty 94^n-set */
81 { M6
, 0, '~', 0, 0, &null_dbcs_to_unicode
}, /* empty 96^n-set */
84 static long int null_dbcs_to_unicode(int r
, int c
)
90 * Emacs encodes Big5 in COMPOUND_TEXT as two 94x94 character sets.
91 * We treat Big5 as a 94x191 character set with a bunch of undefined
92 * columns in the middle, so we have to mess around a bit to make
96 static long int emacs_big5_1_to_unicode(int r
, int c
)
102 if (c
>= 64) c
+= 34; /* Skip over the gap */
103 return big5_to_unicode(r
, c
);
106 static long int emacs_big5_2_to_unicode(int r
, int c
)
112 if (c
>= 64) c
+= 34; /* Skip over the gap */
113 return big5_to_unicode(r
, c
);
117 /* States, or "what we're currently accumulating". */
119 IDLE
, /* None of the below */
120 SS2CHAR
, /* Accumulating a character after SS2 */
121 SS3CHAR
, /* Accumulating a character after SS3 */
122 ESCSEQ
, /* Accumulating an escape sequence */
123 ESCDROP
, /* Discarding an escape sequence */
124 ESCPASS
, /* Passing through an escape sequence */
125 DOCSUTF8
, /* DOCSed into UTF-8 */
126 DOCSCTEXT
/* DOCSed into a COMPOUND_TEXT extended segment */
131 static void dump_state(charset_state
*s
)
133 unsigned s0
= s
->s0
, s1
= s
->s1
;
134 char const * const modes
[] = { "IDLE", "SS2CHAR", "SS3CHAR",
135 "ESCSEQ", "ESCDROP", "ESCPASS",
138 fprintf(stderr
, "s0: %s", modes
[s0
>> 29]);
139 fprintf(stderr
, " %02x %02x %02x ", (s0
>> 16) & 0xff, (s0
>> 8) & 0xff,
141 fprintf(stderr
, "s1: LS%d LS%dR", (s1
>> 30) & 3, (s1
>> 28) & 3);
142 fprintf(stderr
, " %d %d %d %d\n", s1
& 0x7f, (s1
>> 7) & 0x7f,
143 (s1
>> 14) & 0x7f, (s1
>> 21) & 0x7f);
147 static void designate(charset_state
*state
, int container
,
148 int type
, int ibyte
, int fbyte
)
152 assert(container
>= 0 && container
<= 3);
153 assert(type
== S4
|| type
== S6
|| type
== M4
|| type
== M6
);
155 for (i
= 0; i
<= lenof(iso2022_subcharsets
); i
++) {
156 if (iso2022_subcharsets
[i
].type
== type
&&
157 iso2022_subcharsets
[i
].i
== ibyte
&&
158 iso2022_subcharsets
[i
].f
== fbyte
) {
159 state
->s1
&= ~(0x7fL
<< (container
* 7));
160 state
->s1
|= (i
<< (container
* 7));
165 * If we don't find the charset, invoke the empty one, so we
166 * output ERROR rather than garbage.
168 designate(state
, container
, type
, 0, '~');
171 static void do_utf8(long int input_chr
,
172 charset_state
*state
,
173 void (*emit
)(void *ctx
, long int output
),
176 charset_state ustate
;
177 charset_spec
const *utf8
;
180 ustate
.s0
= state
->s0
& 0x03ffffffL
;
181 read_utf8(NULL
, input_chr
, &ustate
, emit
, emitctx
);
182 state
->s0
= (state
->s0
& ~0x03ffffffL
) | (ustate
.s0
& 0x03ffffffL
);
185 static void docs_utf8(long int input_chr
,
186 charset_state
*state
,
187 void (*emit
)(void *ctx
, long int output
),
193 * Bits [25:0] of s0 are reserved for read_utf8().
194 * Bits [27:26] are a tiny state machine to recognise ESC % @.
196 retstate
= (state
->s0
& 0x0c000000L
) >> 26;
197 if (retstate
== 1 && input_chr
== '%')
199 else if (retstate
== 2 && input_chr
== '@') {
200 /* If we've got a partial UTF-8 sequence, complain. */
201 if (state
->s0
& 0x03ffffffL
)
202 emit(emitctx
, ERROR
);
206 if (retstate
>= 1) do_utf8(ESC
, state
, emit
, emitctx
);
207 if (retstate
>= 2) do_utf8('%', state
, emit
, emitctx
);
209 if (input_chr
== ESC
)
212 do_utf8(input_chr
, state
, emit
, emitctx
);
215 state
->s0
= (state
->s0
& ~0x0c000000L
) | (retstate
<< 26);
218 struct ctext_encoding
{
220 charset_spec
const *subcs
;
224 * In theory, this list is in <http://ftp.x.org/pub/docs/registry>,
225 * but XLib appears to have its own ideas, and encodes these three
229 extern charset_spec
const charset_CS_ISO8859_14
;
230 extern charset_spec
const charset_CS_ISO8859_15
;
231 extern charset_spec
const charset_CS_BIG5
;
233 static struct ctext_encoding
const ctext_encodings
[] = {
234 { "big5-0\2", &charset_CS_BIG5
},
235 { "iso8859-14\2", &charset_CS_ISO8859_14
},
236 { "iso8859-15\2", &charset_CS_ISO8859_15
}
239 static void docs_ctext(long int input_chr
,
240 charset_state
*state
,
241 void (*emit
)(void *ctx
, long int output
),
245 * s0[27:26] = first entry in ctext_encodings that matches
246 * s0[25:22] = number of characters successfully matched, 0xf if all
247 * s0[21:8] count the number of octets left in the segment
248 * s0[7:0] are for sub-charset use
250 int n
= (state
->s0
>> 22) & 0xf, i
= (state
->s0
>> 26) & 3, oi
= i
, j
;
251 int length
= (state
->s0
>> 8) & 0x3fff;
254 /* Haven't read length yet */
255 if ((state
->s0
& 0xff) == 0)
256 /* ... or even the first byte */
257 state
->s0
|= input_chr
;
259 length
= (state
->s0
& 0x7f) * 0x80 + (input_chr
& 0x7f);
263 state
->s0
= (state
->s0
& 0xf0000000) | (length
<< 8);
270 /* Skipping unknown encoding. Look out for STX. */
272 state
->s0
= (state
->s0
& 0xf0000000) | (i
<< 26) | (0xf << 22);
273 } else if (n
!= 0xf) {
274 while (j
< lenof(ctext_encodings
) &&
275 !memcmp(ctext_encodings
[j
].name
,
276 ctext_encodings
[oi
].name
, n
)) {
277 if (ctext_encodings
[j
].name
[n
] < input_chr
)
282 if (i
>= lenof(ctext_encodings
) ||
283 memcmp(ctext_encodings
[i
].name
,
284 ctext_encodings
[oi
].name
, n
) ||
285 ctext_encodings
[i
].name
[n
] != input_chr
) {
286 /* Doom! We haven't heard of this encoding */
287 i
= lenof(ctext_encodings
);
291 * Otherwise, we have found an additional character in our
292 * encoding name. See if we have reached the _end_ of our
296 if (!ctext_encodings
[i
].name
[n
])
300 * Failing _that_, we simply update our encoding-name-
303 assert(i
< 4 && n
< 16);
304 state
->s0
= (state
->s0
& 0xf0000000) | (i
<< 26) | (n
<< 22);
306 if (i
>= lenof(ctext_encodings
))
307 emit(emitctx
, ERROR
);
309 charset_state substate
;
310 charset_spec
const *subcs
= ctext_encodings
[i
].subcs
;
312 substate
.s0
= state
->s0
& 0xff;
313 subcs
->read(subcs
, input_chr
, &substate
, emit
, emitctx
);
314 state
->s0
= (state
->s0
& ~0xff) | (substate
.s0
& 0xff);
320 state
->s0
= (state
->s0
&~0x003fff00) | (length
<< 8);
323 static void read_iso2022(charset_spec
const *charset
, long int input_chr
,
324 charset_state
*state
,
325 void (*emit
)(void *ctx
, long int output
),
329 /* dump_state(state); */
331 * We have to make fairly efficient use of the 64 bits of state
332 * available to us. Long-term state goes in s1, and consists of
333 * the identities of the character sets designated as G0/G1/G2/G3
334 * and the locking-shift states for GL and GR. Short-term state
335 * goes in s0: The bottom half of s0 accumulates characters for an
336 * escape sequence or a multi-byte character, while the top three
337 * bits indicate what they're being accumulated for. After DOCS,
338 * the bottom 29 bits of state are available for the DOCS function
339 * to use -- the UTF-8 one uses the bottom 26 for UTF-8 decoding
340 * and the top two to recognised ESC % @.
342 * s0[31:29] = state enum
343 * s0[24:0] = accumulated bytes
344 * s1[31:30] = GL locking-shift state
345 * s1[29:28] = GR locking-shift state
346 * s1[27:21] = G3 charset
347 * s1[20:14] = G2 charset
348 * s1[13:7] = G1 charset
349 * s1[6:0] = G0 charset
354 #define LOCKING_SHIFT(n,side) \
355 (state->s1 = (state->s1 & ~(3L<<(side))) | ((n ## L)<<(side)))
356 #define MODE ((state->s0 & 0xe0000000L) >> 29)
357 #define ENTER_MODE(m) (state->s0 = (state->s0 & ~0xe0000000L) | ((m)<<29))
358 #define SINGLE_SHIFT(n) ENTER_MODE(SS2CHAR - 2 + (n))
359 #define ASSERT_IDLE do { \
360 if (state->s0 != 0) emit(emitctx, ERROR); \
364 if (state
->s1
== 0) {
366 * Since there's no LS0R, this means we must just have started.
367 * Set up a sane initial state (LS0, LS1R, ASCII in G0/G1/G2/G3).
369 LOCKING_SHIFT(0, LEFT
);
370 LOCKING_SHIFT(1, RIGHT
);
371 designate(state
, 0, S4
, 0, 'B');
372 designate(state
, 1, S4
, 0, 'B');
373 designate(state
, 2, S4
, 0, 'B');
374 designate(state
, 3, S4
, 0, 'B');
377 if (MODE
== DOCSUTF8
) {
378 docs_utf8(input_chr
, state
, emit
, emitctx
);
381 if (MODE
== DOCSCTEXT
) {
382 docs_ctext(input_chr
, state
, emit
, emitctx
);
386 if ((input_chr
& 0x60) == 0x00) {
387 /* C0 or C1 control */
394 LOCKING_SHIFT(0, LEFT
);
397 LOCKING_SHIFT(1, LEFT
);
406 emit(emitctx
, input_chr
);
409 } else if ((input_chr
& 0x80) || MODE
< ESCSEQ
) {
411 struct iso2022_subcharset
const *subcs
;
416 * Force idle state if we're in mid escape sequence, or in a
417 * multi-byte character with a different top bit.
419 if (MODE
>= ESCSEQ
||
420 ((state
->s0
& 0x00ff0000L
) != 0 &&
421 (((state
->s0
>> 16) ^ input_chr
) & 0x80)))
423 if (MODE
== SS2CHAR
|| MODE
== SS3CHAR
) /* Single-shift */
424 container
= MODE
- SS2CHAR
+ 2;
425 else if (input_chr
>= 0x80) /* GR */
426 container
= (state
->s1
>> 28) & 3;
428 container
= state
->s1
>> 30;
431 input_7bit
= input_chr
& ~0x80;
432 subcs
= &iso2022_subcharsets
[(state
->s1
>> (container
* 7)) & 0x7f];
433 if ((subcs
->type
== S4
|| subcs
->type
== M4
) &&
434 (input_7bit
== 0x20 || input_7bit
== 0x7f)) {
435 /* characters not in 94-char set */
436 if (is_gl
) emit(emitctx
, input_7bit
);
437 else emit(emitctx
, ERROR
);
438 } else if (subcs
->type
== M4
|| subcs
->type
== M6
) {
439 if ((state
->s0
& 0x00ff0000L
) == 0) {
440 state
->s0
|= input_chr
<< 16;
444 subcs
->dbcs_fn(((state
->s0
>> 16) & 0x7f) + subcs
->offset
,
445 input_7bit
+ subcs
->offset
));
448 if ((state
->s0
& 0x00ff0000L
) != 0)
449 emit(emitctx
, ERROR
);
450 emit(emitctx
, subcs
->sbcs_base ?
451 sbcs_to_unicode(subcs
->sbcs_base
, input_7bit
+ subcs
->offset
):
457 if (MODE
== ESCPASS
) {
458 emit(emitctx
, input_chr
);
459 if ((input_chr
& 0xf0) != 0x20)
465 * Intermediate bytes shall be any of the 16 positions of
466 * column 02 of the code table; they are denoted by the symbol
469 if ((input_chr
& 0xf0) == 0x20) {
470 if (((state
->s0
>> 16) & 0xff) == 0)
471 state
->s0
|= input_chr
<< 16;
472 else if (((state
->s0
>> 8) & 0xff) == 0)
473 state
->s0
|= input_chr
<< 8;
475 /* Long escape sequence. Switch to ESCPASS or ESCDROP. */
476 i1
= (state
->s0
>> 16) & 0xff;
477 i2
= (state
->s0
>> 8) & 0xff;
479 case '(': case ')': case '*': case '+':
480 case '-': case '.': case '/':
488 emit(emitctx
, input_chr
);
498 * Final bytes shall be any of the 79 positions of columns 03
499 * to 07 of the code table excluding position 07/15; they are
500 * denoted by the symbol F.
502 i1
= (state
->s0
>> 16) & 0xff;
503 i2
= (state
->s0
>> 8) & 0xff;
505 input_chr
= 0; /* Make sure it won't match. */
508 case 0: /* No intermediate bytes */
517 LOCKING_SHIFT(2, LEFT
);
520 LOCKING_SHIFT(3, LEFT
);
523 LOCKING_SHIFT(3, RIGHT
);
526 LOCKING_SHIFT(2, RIGHT
);
529 LOCKING_SHIFT(1, RIGHT
);
532 /* Unsupported escape sequence. Spit it back out. */
534 emit(emitctx
, input_chr
);
539 * Various coding structure facilities specify that designating
540 * a code element also invokes it. As far as I can see, invoking
541 * it now will have the same practical effect, since those
542 * facilities also ban the use of locking shifts.
545 case 'A': /* G0 element used and invoked into GL */
546 LOCKING_SHIFT(0, LEFT
);
548 case 'C': /* G0 in GL, G1 in GR */
549 case 'D': /* Ditto, at least for 8-bit codes */
550 case 'L': /* ISO 4873 (ECMA-43) level 1 */
551 case 'M': /* ISO 4873 (ECMA-43) level 2 */
552 LOCKING_SHIFT(0, LEFT
);
553 LOCKING_SHIFT(1, RIGHT
);
559 * IRR (Identify Revised Registration) is ignored here,
560 * since any revised registration must be
561 * upward-compatible with the old one, so either we'll
562 * support the new one or we'll emit ERROR when we run
563 * into a new character. In either case, there's nothing
567 case '(': /* GZD4 */ case ')': /* G1D4 */
568 case '*': /* G2D4 */ case '+': /* G3D4 */
569 designate(state
, i1
- '(', S4
, i2
, input_chr
);
571 case '-': /* G1D6 */ case '.': /* G2D6 */ case '/': /* G3D6 */
572 designate(state
, i1
- ',', S6
, i2
, input_chr
);
574 case '$': /* G?DM? */
576 case 0: /* Obsolete version of GZDM4 */
578 case '(': /* GZDM4 */ case ')': /* G1DM4 */
579 case '*': /* G2DM4 */ case '+': /* G3DM4 */
580 designate(state
, i2
- '(', M4
, 0, input_chr
);
582 case '-': /* G1DM6 */
583 case '.': /* G2DM6 */ case '/': /* G3DM6 */
584 designate(state
, i2
- ',', M6
, 0, input_chr
);
587 emit(emitctx
, ERROR
);
591 /* XXX What's a reasonable way to handle an unrecognised DOCS? */
596 ENTER_MODE(DOCSUTF8
);
603 ENTER_MODE(DOCSCTEXT
);
610 /* Unsupported nF escape sequence. Re-emit it. */
613 if (i2
) emit(emitctx
, i2
);
614 emit(emitctx
, input_chr
);
620 static int write_iso2022(charset_spec
const *charset
, long int input_chr
,
621 charset_state
*state
,
622 void (*emit
)(void *ctx
, long int output
),
628 const charset_spec charset_CS_ISO2022
= {
629 CS_ISO2022
, read_iso2022
, write_iso2022
, NULL
640 void iso2022_emit(void *ctx
, long output
)
642 wchar_t **p
= (wchar_t **)ctx
;
646 void iso2022_read_test(int line
, char *input
, int inlen
, ...)
649 wchar_t *p
, str
[512];
654 state
.s0
= state
.s1
= 0;
657 for (i
= 0; i
< inlen
; i
++)
658 read_iso2022(NULL
, input
[i
] & 0xFF, &state
, iso2022_emit
, &p
);
662 for (i
= 0; i
< p
- str
; i
++) {
663 l
= va_arg(ap
, long int);
665 printf("%d: correct string shorter than output\n", line
);
670 printf("%d: char %d came out as %08x, should be %08lx\n",
676 l
= va_arg(ap
, long int);
678 printf("%d: correct string longer than output\n", line
);
685 /* Macro to concoct the first three parameters of iso2022_read_test. */
686 #define TESTSTR(x) __LINE__, x, lenof(x)
690 printf("read tests beginning\n");
691 /* Simple test (Emacs sample text for Japanese, in ISO-2022-JP) */
692 iso2022_read_test(TESTSTR("Japanese (\x1b$BF|K\\8l\x1b(B)\t"
693 "\x1b$B$3$s$K$A$O\x1b(B, "
694 "\x1b$B%3%s%K%A%O\x1b(B\n"),
695 'J','a','p','a','n','e','s','e',' ','(',
696 0x65E5, 0x672C, 0x8A9E, ')', '\t',
697 0x3053, 0x3093, 0x306b, 0x3061, 0x306f, ',', ' ',
698 0x30b3, 0x30f3, 0x30cb, 0x30c1, 0x30cf, '\n', 0, -1);
699 /* Same thing in EUC-JP (with designations, and half-width katakana) */
700 iso2022_read_test(TESTSTR("\x1b$)B\x1b*I\x1b$+D"
701 "Japanese (\xc6\xfc\xcb\xdc\xb8\xec)\t"
702 "\xa4\xb3\xa4\xf3\xa4\xcb\xa4\xc1\xa4\xcf, "
703 "\x8e\xba\x8e\xdd\x8e\xc6\x8e\xc1\x8e\xca\n"),
704 'J','a','p','a','n','e','s','e',' ','(',
705 0x65E5, 0x672C, 0x8A9E, ')', '\t',
706 0x3053, 0x3093, 0x306b, 0x3061, 0x306f, ',', ' ',
707 0xff7a, 0xff9d, 0xff86, 0xff81, 0xff8a, '\n', 0, -1);
708 /* Multibyte single-shift */
709 iso2022_read_test(TESTSTR("\x1b$)B\x1b*I\x1b$+D\x8f\"/!"),
711 /* Non-existent SBCS */
712 iso2022_read_test(TESTSTR("\x1b(!Zfnord\n"),
713 ERROR
, ERROR
, ERROR
, ERROR
, ERROR
, '\n', 0, -1);
714 /* Pass-through of ordinary escape sequences, including a long one */
715 iso2022_read_test(TESTSTR("\x1b""b\x1b#5\x1b#!!!5"),
716 0x1B, 'b', 0x1B, '#', '5',
717 0x1B, '#', '!', '!', '!', '5', 0, -1);
718 /* Non-existent DBCS (also 5-byte escape sequence) */
719 iso2022_read_test(TESTSTR("\x1b$(!Bfnord!"),
720 ERROR
, ERROR
, ERROR
, 0, -1);
721 /* Incomplete DB characters */
722 iso2022_read_test(TESTSTR("\x1b$B(,(\x1b(BHi\x1b$B(,(\n"),
723 0x2501, ERROR
, 'H', 'i', 0x2501, ERROR
, '\n', 0, -1);
724 iso2022_read_test(TESTSTR("\x1b$)B\x1b*I\x1b$+D\xa4""B"),
726 iso2022_read_test(TESTSTR("\x1b$)B\x1b*I\x1b$+D\x0e\x1b|$\xa2\xaf"),
727 ERROR
, 0x02D8, 0, -1);
728 /* Incomplete escape sequence */
729 iso2022_read_test(TESTSTR("\x1b\n"), ERROR
, '\n', 0, -1);
730 iso2022_read_test(TESTSTR("\x1b-A\x1b~\x1b\xa1"), ERROR
, 0xa1, 0, -1);
731 /* Incomplete single-shift */
732 iso2022_read_test(TESTSTR("\x8e\n"), ERROR
, '\n', 0, -1);
733 iso2022_read_test(TESTSTR("\x1b$*B\x8e(\n"), ERROR
, '\n', 0, -1);
734 /* Corner cases (02/00 and 07/15) */
735 iso2022_read_test(TESTSTR("\x1b(B\x20\x7f"), 0x20, 0x7f, 0, -1);
736 iso2022_read_test(TESTSTR("\x1b(I\x20\x7f"), 0x20, 0x7f, 0, -1);
737 iso2022_read_test(TESTSTR("\x1b$B\x20\x7f"), 0x20, 0x7f, 0, -1);
738 iso2022_read_test(TESTSTR("\x1b-A\x0e\x20\x7f"), 0xa0, 0xff, 0, -1);
739 iso2022_read_test(TESTSTR("\x1b$-~\x0e\x20\x7f"), ERROR
, 0, -1);
740 iso2022_read_test(TESTSTR("\x1b)B\xa0\xff"), ERROR
, ERROR
, 0, -1);
741 iso2022_read_test(TESTSTR("\x1b)I\xa0\xff"), ERROR
, ERROR
, 0, -1);
742 iso2022_read_test(TESTSTR("\x1b$)B\xa0\xff"), ERROR
, ERROR
, 0, -1);
743 iso2022_read_test(TESTSTR("\x1b-A\x1b~\xa0\xff"), 0xa0, 0xff, 0, -1);
744 iso2022_read_test(TESTSTR("\x1b$-~\x1b~\xa0\xff"), ERROR
, 0, -1);
745 /* Designate control sets */
746 iso2022_read_test(TESTSTR("\x1b!@"), 0x1b, '!', '@', 0, -1);
747 /* Designate other coding system (UTF-8) */
748 iso2022_read_test(TESTSTR("\x1b%G"
749 "\xCE\xBA\xE1\xBD\xB9\xCF\x83\xCE\xBC\xCE\xB5"),
750 0x03BA, 0x1F79, 0x03C3, 0x03BC, 0x03B5, 0, -1);
751 iso2022_read_test(TESTSTR("\x1b-A\x1b%G\xCE\xBA\x1b%@\xa0"),
752 0x03BA, 0xA0, 0, -1);
753 iso2022_read_test(TESTSTR("\x1b%G\xCE\x1b%@"), ERROR
, 0, -1);
754 iso2022_read_test(TESTSTR("\x1b%G\xCE\xBA\x1b%\x1b%@"),
755 0x03BA, 0x1B, '%', 0, -1);
756 /* DOCS (COMPOUND_TEXT extended segment) */
757 iso2022_read_test(TESTSTR("\x1b%/1\x80\x80"), 0, -1);
758 iso2022_read_test(TESTSTR("\x1b%/1\x80\x8fiso-8859-15\2xyz\x1b(B"),
759 ERROR
, ERROR
, ERROR
, 0, -1);
760 iso2022_read_test(TESTSTR("\x1b%/1\x80\x8eiso8859-15\2xyz\x1b(B"),
761 'x', 'y', 'z', 0, -1);
762 iso2022_read_test(TESTSTR("\x1b-A\x1b%/2\x80\x89"
763 "big5-0\2\xa1\x40\xa1\x40"),
764 0x3000, 0xa1, 0x40, 0, -1);
765 /* Emacs Big5-in-ISO-2022 mapping */
766 iso2022_read_test(TESTSTR("\x1b$(0&x86\x1b(B \x1b$(0DeBv"),
767 0x5143, 0x6c23, ' ', ' ', 0x958b, 0x767c, 0, -1);
768 printf("read tests completed\n");
769 printf("total: %d errors\n", total_errs
);
770 return (total_errs
!= 0);
773 #endif /* TESTMODE */
775 #else /* ENUM_CHARSETS */
777 ENUM_CHARSET(CS_ISO2022
)