* sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h: Support cancellation
[glibc.git] / iconvdata / iso-2022-jp-3.c
blob2704a17b7fe702c6757106de8d055843df90350d
1 /* Conversion module for ISO-2022-JP-3.
2 Copyright (C) 1998-1999, 2000-2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998,
5 and Bruno Haible <bruno@clisp.org>, 2002.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #include <assert.h>
23 #include <dlfcn.h>
24 #include <gconv.h>
25 #include <stdint.h>
26 #include <string.h>
28 #include "jis0201.h"
29 #include "jis0208.h"
30 #include "jisx0213.h"
32 /* This makes obvious what everybody knows: 0x1b is the Esc character. */
33 #define ESC 0x1b
35 /* Definitions used in the body of the `gconv' function. */
36 #define CHARSET_NAME "ISO-2022-JP-3//"
37 #define FROM_LOOP from_iso2022jp3_loop
38 #define TO_LOOP to_iso2022jp3_loop
39 #define DEFINE_INIT 1
40 #define DEFINE_FINI 1
41 #define FROM_LOOP_MIN_NEEDED_FROM 1
42 #define FROM_LOOP_MAX_NEEDED_FROM 4
43 #define FROM_LOOP_MIN_NEEDED_TO 4
44 #define FROM_LOOP_MAX_NEEDED_TO 8
45 #define TO_LOOP_MIN_NEEDED_FROM 4
46 #define TO_LOOP_MAX_NEEDED_FROM 4
47 #define TO_LOOP_MIN_NEEDED_TO 1
48 #define TO_LOOP_MAX_NEEDED_TO 6
49 #define PREPARE_LOOP \
50 int saved_state; \
51 int *statep = &data->__statep->__count;
52 #define EXTRA_LOOP_ARGS , statep
55 /* The COUNT element of the state keeps track of the currently selected
56 character set. The possible values are: */
57 enum
59 ASCII_set = 0, /* Esc ( B */
60 JISX0208_1978_set = 1 << 3, /* Esc $ @ */
61 JISX0208_1983_set = 2 << 3, /* Esc $ B */
62 JISX0201_Roman_set = 3 << 3, /* Esc ( J */
63 JISX0201_Kana_set = 4 << 3, /* Esc ( I */
64 JISX0213_1_set = 5 << 3, /* Esc $ ( O */
65 JISX0213_2_set = 6 << 3, /* Esc $ ( P */
66 CURRENT_SEL_MASK = 7 << 3
69 /* During UCS-4 to ISO-2022-JP-3 conversion, the COUNT element of the state
70 also contains the last two bytes to be output, shifted by 6 bits, and a
71 one-bit indicator whether they must be preceded by the shift sequence,
72 in bit 22. */
74 /* Since this is a stateful encoding we have to provide code which resets
75 the output state to the initial state. This has to be done during the
76 flushing. */
77 #define EMIT_SHIFT_TO_INIT \
78 if ((data->__statep->__count & ~7) != ASCII_set) \
79 { \
80 if (FROM_DIRECTION) \
81 { \
82 /* It's easy, we don't have to emit anything, we just reset the \
83 state for the input. */ \
84 data->__statep->__count &= 7; \
85 data->__statep->__count |= ASCII_set; \
86 } \
87 else \
88 { \
89 /* We are not in the initial state. To switch back we have \
90 to write out the buffered character and/or emit the sequence \
91 `Esc ( B'. */ \
92 size_t need = \
93 (data->__statep->__count >> 6 \
94 ? (data->__statep->__count >> 22 ? 3 : 0) + 2 \
95 : 0) \
96 + ((data->__statep->__count & CURRENT_SEL_MASK) != ASCII_set \
97 ? 3 : 0); \
99 if (__builtin_expect (outbuf + need > outend, 0)) \
100 /* We don't have enough room in the output buffer. */ \
101 status = __GCONV_FULL_OUTPUT; \
102 else \
104 if (data->__statep->__count >> 6) \
106 uint32_t lasttwo = data->__statep->__count >> 6; \
108 if (lasttwo >> 16) \
110 /* Write out the shift sequence before the last \
111 character. */ \
112 assert ((data->__statep->__count & CURRENT_SEL_MASK) \
113 == JISX0208_1983_set); \
114 *outbuf++ = ESC; \
115 *outbuf++ = '$'; \
116 *outbuf++ = 'B'; \
118 /* Write out the last character. */ \
119 *outbuf++ = (lasttwo >> 8) & 0xff; \
120 *outbuf++ = lasttwo & 0xff; \
122 if ((data->__statep->__count & CURRENT_SEL_MASK) != ASCII_set) \
124 /* Write out the shift sequence. */ \
125 *outbuf++ = ESC; \
126 *outbuf++ = '('; \
127 *outbuf++ = 'B'; \
129 data->__statep->__count &= 7; \
130 data->__statep->__count |= ASCII_set; \
136 /* Since we might have to reset input pointer we must be able to save
137 and retore the state. */
138 #define SAVE_RESET_STATE(Save) \
139 if (Save) \
140 saved_state = *statep; \
141 else \
142 *statep = saved_state
145 /* First define the conversion function from ISO-2022-JP-3 to UCS-4. */
146 #define MIN_NEEDED_INPUT FROM_LOOP_MIN_NEEDED_FROM
147 #define MAX_NEEDED_INPUT FROM_LOOP_MAX_NEEDED_FROM
148 #define MIN_NEEDED_OUTPUT FROM_LOOP_MIN_NEEDED_TO
149 #define MAX_NEEDED_OUTPUT FROM_LOOP_MAX_NEEDED_TO
150 #define LOOPFCT FROM_LOOP
151 #define BODY \
153 uint32_t ch = *inptr; \
155 /* Recognize escape sequences. */ \
156 if (__builtin_expect (ch == ESC, 0)) \
158 /* We now must be prepared to read two to three more bytes. \
159 If we have a match in the first byte but then the input buffer \
160 ends we terminate with an error since we must not risk missing \
161 an escape sequence just because it is not entirely in the \
162 current input buffer. */ \
163 if (__builtin_expect (inptr + 2 >= inend, 0) \
164 || (inptr[1] == '$' && inptr[2] == '(' \
165 && __builtin_expect (inptr + 3 >= inend, 0))) \
167 /* Not enough input available. */ \
168 result = __GCONV_INCOMPLETE_INPUT; \
169 break; \
172 if (inptr[1] == '(') \
174 if (inptr[2] == 'B') \
176 /* ASCII selected. */ \
177 set = ASCII_set; \
178 inptr += 3; \
179 continue; \
181 else if (inptr[2] == 'J') \
183 /* JIS X 0201 selected. */ \
184 set = JISX0201_Roman_set; \
185 inptr += 3; \
186 continue; \
188 else if (inptr[2] == 'I') \
190 /* JIS X 0201 selected. */ \
191 set = JISX0201_Kana_set; \
192 inptr += 3; \
193 continue; \
196 else if (inptr[1] == '$') \
198 if (inptr[2] == '@') \
200 /* JIS X 0208-1978 selected. */ \
201 set = JISX0208_1978_set; \
202 inptr += 3; \
203 continue; \
205 else if (inptr[2] == 'B') \
207 /* JIS X 0208-1983 selected. */ \
208 set = JISX0208_1983_set; \
209 inptr += 3; \
210 continue; \
212 else if (inptr[2] == '(') \
214 if (inptr[3] == 'O') \
216 /* JIS X 0213 plane 1 selected. */ \
217 set = JISX0213_1_set; \
218 inptr += 4; \
219 continue; \
221 else if (inptr[3] == 'P') \
223 /* JIS X 0213 plane 2 selected. */ \
224 set = JISX0213_2_set; \
225 inptr += 4; \
226 continue; \
232 if (ch >= 0x80) \
234 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
236 else if (set == ASCII_set || (ch < 0x21 || ch == 0x7f)) \
237 /* Almost done, just advance the input pointer. */ \
238 ++inptr; \
239 else if (set == JISX0201_Roman_set) \
241 /* Use the JIS X 0201 table. */ \
242 ch = jisx0201_to_ucs4 (ch); \
243 if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0)) \
245 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
247 ++inptr; \
249 else if (set == JISX0201_Kana_set) \
251 /* Use the JIS X 0201 table. */ \
252 ch = jisx0201_to_ucs4 (ch + 0x80); \
253 if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0)) \
255 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
257 ++inptr; \
259 else if (set == JISX0208_1978_set || set == JISX0208_1983_set) \
261 /* XXX I don't have the tables for these two old variants of \
262 JIS X 0208. Therefore I'm using the tables for JIS X \
263 0208-1990. If somebody has problems with this please \
264 provide the appropriate tables. */ \
265 ch = jisx0208_to_ucs4 (&inptr, inend - inptr, 0); \
267 if (__builtin_expect (ch == 0, 0)) \
269 result = __GCONV_INCOMPLETE_INPUT; \
270 break; \
272 else if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0)) \
274 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
277 else /* (set == JISX0213_1_set || set == JISX0213_2_set) */ \
279 if (__builtin_expect (inptr + 1 >= inend, 0)) \
281 result = __GCONV_INCOMPLETE_INPUT; \
282 break; \
285 ch = jisx0213_to_ucs4 (((set - JISX0213_1_set + (1 << 3)) << 5) + ch, \
286 inptr[1]); \
287 if (ch == 0) \
288 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
290 if (ch < 0x80) \
292 /* It's a combining character. */ \
293 uint32_t u1 = __jisx0213_to_ucs_combining[ch - 1][0]; \
294 uint32_t u2 = __jisx0213_to_ucs_combining[ch - 1][1]; \
296 /* See whether we have room for two characters. */ \
297 if (outptr + 8 <= outend) \
299 inptr += 2; \
300 put32 (outptr, u1); \
301 outptr += 4; \
302 put32 (outptr, u2); \
303 outptr += 4; \
304 continue; \
306 else \
308 result = __GCONV_FULL_OUTPUT; \
309 break; \
313 inptr += 2; \
316 put32 (outptr, ch); \
317 outptr += 4; \
319 #define LOOP_NEED_FLAGS
320 #define EXTRA_LOOP_DECLS , int *statep
321 #define INIT_PARAMS int set = *statep
322 #define UPDATE_PARAMS *statep = set
323 #include <iconv/loop.c>
326 /* Next, define the other direction, from UCS-4 to ISO-2022-JP-3. */
328 /* Composition tables for each of the relevant combining characters. */
329 static const struct
331 uint16_t base;
332 uint16_t composed;
333 } comp_table_data[] =
335 #define COMP_TABLE_IDX_02E5 0
336 #define COMP_TABLE_LEN_02E5 1
337 { 0x2b64, 0x2b65 }, /* 0x12B65 = 0x12B64 U+02E5 */
338 #define COMP_TABLE_IDX_02E9 (COMP_TABLE_IDX_02E5 + COMP_TABLE_LEN_02E5)
339 #define COMP_TABLE_LEN_02E9 1
340 { 0x2b60, 0x2b66 }, /* 0x12B66 = 0x12B60 U+02E9 */
341 #define COMP_TABLE_IDX_0300 (COMP_TABLE_IDX_02E9 + COMP_TABLE_LEN_02E9)
342 #define COMP_TABLE_LEN_0300 5
343 { 0x295c, 0x2b44 }, /* 0x12B44 = 0x1295C U+0300 */
344 { 0x2b38, 0x2b48 }, /* 0x12B48 = 0x12B38 U+0300 */
345 { 0x2b37, 0x2b4a }, /* 0x12B4A = 0x12B37 U+0300 */
346 { 0x2b30, 0x2b4c }, /* 0x12B4C = 0x12B30 U+0300 */
347 { 0x2b43, 0x2b4e }, /* 0x12B4E = 0x12B43 U+0300 */
348 #define COMP_TABLE_IDX_0301 (COMP_TABLE_IDX_0300 + COMP_TABLE_LEN_0300)
349 #define COMP_TABLE_LEN_0301 4
350 { 0x2b38, 0x2b49 }, /* 0x12B49 = 0x12B38 U+0301 */
351 { 0x2b37, 0x2b4b }, /* 0x12B4B = 0x12B37 U+0301 */
352 { 0x2b30, 0x2b4d }, /* 0x12B4D = 0x12B30 U+0301 */
353 { 0x2b43, 0x2b4f }, /* 0x12B4F = 0x12B43 U+0301 */
354 #define COMP_TABLE_IDX_309A (COMP_TABLE_IDX_0301 + COMP_TABLE_LEN_0301)
355 #define COMP_TABLE_LEN_309A 14
356 { 0x242b, 0x2477 }, /* 0x12477 = 0x1242B U+309A */
357 { 0x242d, 0x2478 }, /* 0x12478 = 0x1242D U+309A */
358 { 0x242f, 0x2479 }, /* 0x12479 = 0x1242F U+309A */
359 { 0x2431, 0x247a }, /* 0x1247A = 0x12431 U+309A */
360 { 0x2433, 0x247b }, /* 0x1247B = 0x12433 U+309A */
361 { 0x252b, 0x2577 }, /* 0x12577 = 0x1252B U+309A */
362 { 0x252d, 0x2578 }, /* 0x12578 = 0x1252D U+309A */
363 { 0x252f, 0x2579 }, /* 0x12579 = 0x1252F U+309A */
364 { 0x2531, 0x257a }, /* 0x1257A = 0x12531 U+309A */
365 { 0x2533, 0x257b }, /* 0x1257B = 0x12533 U+309A */
366 { 0x253b, 0x257c }, /* 0x1257C = 0x1253B U+309A */
367 { 0x2544, 0x257d }, /* 0x1257D = 0x12544 U+309A */
368 { 0x2548, 0x257e }, /* 0x1257E = 0x12548 U+309A */
369 { 0x2675, 0x2678 }, /* 0x12678 = 0x12675 U+309A */
372 #define MIN_NEEDED_INPUT TO_LOOP_MIN_NEEDED_FROM
373 #define MAX_NEEDED_INPUT TO_LOOP_MAX_NEEDED_FROM
374 #define MIN_NEEDED_OUTPUT TO_LOOP_MIN_NEEDED_TO
375 #define MAX_NEEDED_OUTPUT TO_LOOP_MAX_NEEDED_TO
376 #define LOOPFCT TO_LOOP
377 #define BODY \
379 uint32_t ch = get32 (inptr); \
381 if (lasttwo != 0) \
383 /* Attempt to combine the last character with this one. */ \
384 unsigned int idx; \
385 unsigned int len; \
387 if (ch == 0x02e5) \
388 idx = COMP_TABLE_IDX_02E5, len = COMP_TABLE_LEN_02E5; \
389 else if (ch == 0x02e9) \
390 idx = COMP_TABLE_IDX_02E9, len = COMP_TABLE_LEN_02E9; \
391 else if (ch == 0x0300) \
392 idx = COMP_TABLE_IDX_0300, len = COMP_TABLE_LEN_0300; \
393 else if (ch == 0x0301) \
394 idx = COMP_TABLE_IDX_0301, len = COMP_TABLE_LEN_0301; \
395 else if (ch == 0x309a) \
396 idx = COMP_TABLE_IDX_309A, len = COMP_TABLE_LEN_309A; \
397 else \
398 goto not_combining; \
400 do \
401 if (comp_table_data[idx].base == (uint16_t) lasttwo) \
402 break; \
403 while (++idx, --len > 0); \
405 if (len > 0) \
407 /* Output the combined character. */ \
408 /* We know the combined character is in JISX0213 plane 1, \
409 but the buffered character may have been in JISX0208 or in \
410 JISX0213 plane 1. */ \
411 size_t need = (lasttwo >> 16 || set != JISX0213_1_set ? 4 : 0); \
413 if (__builtin_expect (outptr + need + 2 > outend, 0)) \
415 result = __GCONV_FULL_OUTPUT; \
416 break; \
418 if (need) \
420 /* But first, output the escape sequence. */ \
421 *outptr++ = ESC; \
422 *outptr++ = '$'; \
423 *outptr++ = '('; \
424 *outptr++ = 'O'; \
425 set = JISX0213_1_set; \
427 lasttwo = comp_table_data[idx].composed; \
428 *outptr++ = (lasttwo >> 8) & 0xff; \
429 *outptr++ = lasttwo & 0xff; \
430 lasttwo = 0; \
431 inptr += 4; \
432 continue; \
435 not_combining: \
436 /* Output the buffered character. */ \
437 /* We know it is in JISX0208 or in JISX0213 plane 1. */ \
439 size_t need = (lasttwo >> 16 ? 3 : 0); \
441 if (__builtin_expect (outptr + need + 2 > outend, 0)) \
443 result = __GCONV_FULL_OUTPUT; \
444 break; \
446 if (need) \
448 /* But first, output the escape sequence. */ \
449 assert (set == JISX0208_1983_set); \
450 *outptr++ = ESC; \
451 *outptr++ = '$'; \
452 *outptr++ = 'B'; \
454 *outptr++ = (lasttwo >> 8) & 0xff; \
455 *outptr++ = lasttwo & 0xff; \
456 lasttwo = 0; \
457 continue; \
461 /* First see whether we can write the character using the currently \
462 selected character set. */ \
463 if (set == ASCII_set) \
465 /* Please note that the NUL byte is *not* matched if we are not \
466 currently using the ASCII charset. This is because we must \
467 switch to the initial state whenever a NUL byte is written. */ \
468 if (ch <= 0x7f) \
470 *outptr++ = ch; \
471 inptr += 4; \
472 continue; \
475 /* ISO-2022-JP recommends to encode the newline character always in \
476 ASCII since this allows a context-free interpretation of the \
477 characters at the beginning of the next line. Otherwise it would \
478 have to be known whether the last line ended using ASCII or \
479 JIS X 0201. */ \
480 else if (set == JISX0201_Roman_set) \
482 unsigned char buf[1]; \
483 if (ucs4_to_jisx0201 (ch, buf) != __UNKNOWN_10646_CHAR \
484 && buf[0] > 0x20 && buf[0] < 0x80) \
486 *outptr++ = buf[0]; \
487 inptr += 4; \
488 continue; \
491 else if (set == JISX0201_Kana_set) \
493 unsigned char buf[1]; \
494 if (ucs4_to_jisx0201 (ch, buf) != __UNKNOWN_10646_CHAR \
495 && buf[0] >= 0x80) \
497 *outptr++ = buf[0] - 0x80; \
498 inptr += 4; \
499 continue; \
502 else if (/*set == JISX0208_1978_set || */ set == JISX0208_1983_set) \
504 size_t written = ucs4_to_jisx0208 (ch, outptr, outend - outptr); \
506 if (written != __UNKNOWN_10646_CHAR) \
508 uint32_t jch = ucs4_to_jisx0213 (ch); \
510 if (jch & 0x0080) \
512 /* A possible match in comp_table_data. Buffer it. */ \
513 lasttwo = jch & 0x7f7f; \
514 inptr += 4; \
515 continue; \
517 if (__builtin_expect (written == 0, 0)) \
519 result = __GCONV_FULL_OUTPUT; \
520 break; \
522 else \
524 outptr += written; \
525 inptr += 4; \
526 continue; \
530 else \
532 /* (set == JISX0213_1_set || set == JISX0213_2_set) */ \
533 uint32_t jch = ucs4_to_jisx0213 (ch); \
535 if (jch != 0 \
536 && (set == (jch & 0x8000 ? JISX0213_2_set : JISX0213_1_set))) \
538 if (jch & 0x0080) \
540 /* A possible match in comp_table_data. Buffer it. */ \
542 /* We know it's a JISX 0213 plane 1 character. */ \
543 assert ((jch & 0x8000) == 0); \
545 lasttwo = jch & 0x7f7f; \
546 inptr += 4; \
547 continue; \
550 if (__builtin_expect (outptr + 1 >= outend, 0)) \
552 result = __GCONV_FULL_OUTPUT; \
553 break; \
555 *outptr++ = (jch >> 8) & 0x7f; \
556 *outptr++ = jch & 0x7f; \
557 inptr += 4; \
558 continue; \
562 /* The attempts to use the currently selected character set failed, \
563 either because the character requires a different character set, \
564 or because the character is unknown. */ \
566 if (ch <= 0x7f) \
568 /* We must encode using ASCII. First write out the escape \
569 sequence. */ \
570 if (__builtin_expect (outptr + 3 > outend, 0)) \
572 result = __GCONV_FULL_OUTPUT; \
573 break; \
576 *outptr++ = ESC; \
577 *outptr++ = '('; \
578 *outptr++ = 'B'; \
579 set = ASCII_set; \
581 if (__builtin_expect (outptr >= outend, 0)) \
583 result = __GCONV_FULL_OUTPUT; \
584 break; \
586 *outptr++ = ch; \
588 else \
590 unsigned char buf[2]; \
592 /* Try JIS X 0201 Roman. */ \
593 if (ucs4_to_jisx0201 (ch, buf) != __UNKNOWN_10646_CHAR \
594 && buf[0] > 0x20 && buf[0] < 0x80) \
596 if (set != JISX0201_Roman_set) \
598 if (__builtin_expect (outptr + 3 > outend, 0)) \
600 result = __GCONV_FULL_OUTPUT; \
601 break; \
603 *outptr++ = ESC; \
604 *outptr++ = '('; \
605 *outptr++ = 'J'; \
606 set = JISX0201_Roman_set; \
609 if (__builtin_expect (outptr >= outend, 0)) \
611 result = __GCONV_FULL_OUTPUT; \
612 break; \
614 *outptr++ = buf[0]; \
616 else \
618 uint32_t jch = ucs4_to_jisx0213 (ch); \
620 /* Try JIS X 0208. */ \
621 size_t written = ucs4_to_jisx0208 (ch, buf, 2); \
622 if (written != __UNKNOWN_10646_CHAR) \
624 if (jch & 0x0080) \
626 /* A possible match in comp_table_data. Buffer it. */ \
627 lasttwo = ((set != JISX0208_1983_set ? 1 : 0) << 16) \
628 | (jch & 0x7f7f); \
629 set = JISX0208_1983_set; \
630 inptr += 4; \
631 continue; \
634 if (set != JISX0208_1983_set) \
636 if (__builtin_expect (outptr + 3 > outend, 0)) \
638 result = __GCONV_FULL_OUTPUT; \
639 break; \
641 *outptr++ = ESC; \
642 *outptr++ = '$'; \
643 *outptr++ = 'B'; \
644 set = JISX0208_1983_set; \
647 if (__builtin_expect (outptr + 2 > outend, 0)) \
649 result = __GCONV_FULL_OUTPUT; \
650 break; \
652 *outptr++ = buf[0]; \
653 *outptr++ = buf[1]; \
655 else \
657 /* Try JIS X 0213. */ \
658 if (jch != 0) \
660 int new_set = \
661 (jch & 0x8000 ? JISX0213_2_set : JISX0213_1_set); \
663 if (set != new_set) \
665 if (__builtin_expect (outptr + 4 > outend, 0)) \
667 result = __GCONV_FULL_OUTPUT; \
668 break; \
670 *outptr++ = ESC; \
671 *outptr++ = '$'; \
672 *outptr++ = '('; \
673 *outptr++ = ((new_set - JISX0213_1_set) >> 3) + 'O'; \
674 set = new_set; \
677 if (jch & 0x0080) \
679 /* A possible match in comp_table_data. \
680 Buffer it. */ \
682 /* We know it's a JIS X 0213 plane 1 character. */ \
683 assert ((jch & 0x8000) == 0); \
685 lasttwo = jch & 0x7f7f; \
686 inptr += 4; \
687 continue; \
690 if (__builtin_expect (outptr + 1 >= outend, 0)) \
692 result = __GCONV_FULL_OUTPUT; \
693 break; \
695 *outptr++ = (jch >> 8) & 0x7f; \
696 *outptr++ = jch & 0x7f; \
698 else \
700 /* Try JIS X 0201 Katakana. This is officially not part \
701 of ISO-2022-JP-3. Therefore we try it after all other \
702 attempts. */ \
703 if (ucs4_to_jisx0201 (ch, buf) != __UNKNOWN_10646_CHAR \
704 && buf[0] >= 0x80) \
706 if (set != JISX0201_Kana_set) \
708 if (__builtin_expect (outptr + 3 > outend, 0)) \
710 result = __GCONV_FULL_OUTPUT; \
711 break; \
713 *outptr++ = ESC; \
714 *outptr++ = '('; \
715 *outptr++ = 'I'; \
716 set = JISX0201_Kana_set; \
719 if (__builtin_expect (outptr >= outend, 0)) \
721 result = __GCONV_FULL_OUTPUT; \
722 break; \
724 *outptr++ = buf[0] - 0x80; \
726 else \
728 UNICODE_TAG_HANDLER (ch, 4); \
730 /* Illegal character. */ \
731 STANDARD_TO_LOOP_ERR_HANDLER (4); \
738 /* Now that we wrote the output increment the input pointer. */ \
739 inptr += 4; \
741 #define LOOP_NEED_FLAGS
742 #define EXTRA_LOOP_DECLS , int *statep
743 #define INIT_PARAMS int set = *statep & CURRENT_SEL_MASK; \
744 uint32_t lasttwo = *statep >> 6
745 #define UPDATE_PARAMS *statep = set | (lasttwo << 6)
746 #include <iconv/loop.c>
749 /* Now define the toplevel functions. */
750 #include <iconv/skeleton.c>