Update.
[glibc.git] / iconvdata / iso-2022-jp.c
blob1d9164d818dd0015d194743de014ebe1d0f52424
1 /* Conversion module for ISO-2022-JP.
2 Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include <dlfcn.h>
22 #include <gconv.h>
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include "jis0201.h"
27 #include "jis0208.h"
28 #include "jis0212.h"
29 #include "gb2312.h"
30 #include "ksc5601.h"
32 struct gap
34 uint16_t start;
35 uint16_t end;
36 int32_t idx;
39 #include "iso8859-7jp.h"
41 /* This makes obvious what everybody knows: 0x1b is the Esc character. */
42 #define ESC 0x1b
44 /* We provide our own initialization and destructor function. */
45 #define DEFINE_INIT 0
46 #define DEFINE_FINI 0
48 /* Definitions used in the body of the `gconv' function. */
49 #define FROM_LOOP from_iso2022jp_loop
50 #define TO_LOOP to_iso2022jp_loop
51 #define MIN_NEEDED_FROM 1
52 #define MAX_NEEDED_FROM 4
53 #define MIN_NEEDED_TO 4
54 #define MAX_NEEDED_TO 4
55 #define FROM_DIRECTION (dir == from_iso2022jp)
56 #define PREPARE_LOOP \
57 enum direction dir = ((struct iso2022jp_data *) step->__data)->dir; \
58 enum variant var = ((struct iso2022jp_data *) step->__data)->var; \
59 int save_set; \
60 int *setp = &data->__statep->__count;
61 #define EXTRA_LOOP_ARGS , var, setp
64 /* Direction of the transformation. */
65 enum direction
67 illegal_dir,
68 to_iso2022jp,
69 from_iso2022jp
72 /* We handle ISO-2022-jp and ISO-2022-JP-2 here. */
73 enum variant
75 illegal_var,
76 iso2022jp,
77 iso2022jp2
81 struct iso2022jp_data
83 enum direction dir;
84 enum variant var;
88 /* The COUNT element of the state keeps track of the currently selected
89 character set. The possible values are: */
90 enum
92 ASCII_set = 0,
93 JISX0208_1978_set = 8,
94 JISX0208_1983_set = 16,
95 JISX0201_Roman_set = 24,
96 JISX0201_Kana_set = 32,
97 GB2312_set = 40,
98 KSC5601_set = 48,
99 JISX0212_set = 56,
100 CURRENT_SEL_MASK = 56
103 /* The second value stored is the designation of the G2 set. The following
104 values are possible: */
105 enum
107 UNSPECIFIED_set = 0,
108 ISO88591_set = 64,
109 ISO88597_set = 128,
110 CURRENT_ASSIGN_MASK = 192
114 extern int gconv_init (struct __gconv_step *step);
116 gconv_init (struct __gconv_step *step)
118 /* Determine which direction. */
119 struct iso2022jp_data *new_data;
120 enum direction dir = illegal_dir;
121 enum variant var = illegal_var;
122 int result;
124 if (__strcasecmp (step->__from_name, "ISO-2022-JP//") == 0)
126 dir = from_iso2022jp;
127 var = iso2022jp;
129 else if (__strcasecmp (step->__to_name, "ISO-2022-JP//") == 0)
131 dir = to_iso2022jp;
132 var = iso2022jp;
134 else if (__strcasecmp (step->__from_name, "ISO-2022-JP-2//") == 0)
136 dir = from_iso2022jp;
137 var = iso2022jp2;
139 else if (__strcasecmp (step->__to_name, "ISO-2022-JP-2//") == 0)
141 dir = to_iso2022jp;
142 var = iso2022jp2;
145 result = __GCONV_NOCONV;
146 if (__builtin_expect (dir, from_iso2022jp) != illegal_dir)
148 new_data
149 = (struct iso2022jp_data *) malloc (sizeof (struct iso2022jp_data));
151 result = __GCONV_NOMEM;
152 if (new_data != NULL)
154 new_data->dir = dir;
155 new_data->var = var;
156 step->__data = new_data;
158 if (dir == from_iso2022jp)
160 step->__min_needed_from = MIN_NEEDED_FROM;
161 step->__max_needed_from = MAX_NEEDED_FROM;
162 step->__min_needed_to = MIN_NEEDED_TO;
163 step->__max_needed_to = MAX_NEEDED_TO;
165 else
167 step->__min_needed_from = MIN_NEEDED_TO;
168 step->__max_needed_from = MAX_NEEDED_TO;
169 step->__min_needed_to = MIN_NEEDED_FROM;
170 step->__max_needed_to = MAX_NEEDED_FROM + 2;
173 /* Yes, this is a stateful encoding. */
174 step->__stateful = 1;
176 result = __GCONV_OK;
180 return result;
184 extern void gconv_end (struct __gconv_step *data);
185 void
186 gconv_end (struct __gconv_step *data)
188 free (data->__data);
192 /* Since this is a stateful encoding we have to provide code which resets
193 the output state to the initial state. This has to be done during the
194 flushing. */
195 #define EMIT_SHIFT_TO_INIT \
196 if ((data->__statep->__count & ~7) != ASCII_set) \
198 enum direction dir = ((struct iso2022jp_data *) step->__data)->dir; \
200 if (dir == from_iso2022jp) \
202 /* It's easy, we don't have to emit anything, we just reset the \
203 state for the input. Note that this also clears the G2 \
204 designation. */ \
205 data->__statep->__count &= 7; \
206 data->__statep->__count |= ASCII_set; \
208 else \
210 unsigned char *outbuf = data->__outbuf; \
212 /* We are not in the initial state. To switch back we have \
213 to emit the sequence `Esc ( B'. */ \
214 if (__builtin_expect (outbuf + 3 > data->__outbufend, 0)) \
215 /* We don't have enough room in the output buffer. */ \
216 status = __GCONV_FULL_OUTPUT; \
217 else \
219 /* Write out the shift sequence. */ \
220 *outbuf++ = ESC; \
221 *outbuf++ = '('; \
222 *outbuf++ = 'B'; \
223 data->__outbuf = outbuf; \
224 /* Note that this also clears the G2 designation. */ \
225 data->__statep->__count &= ~7; \
226 data->__statep->__count |= ASCII_set; \
232 /* Since we might have to reset input pointer we must be able to save
233 and retore the state. */
234 #define SAVE_RESET_STATE(Save) \
235 if (Save) \
236 save_set = *setp; \
237 else \
238 *setp = save_set
241 /* First define the conversion function from ISO-2022-JP to UCS4. */
242 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
243 #define MAX_NEEDED_INPUT MAX_NEEDED_FROM
244 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
245 #define LOOPFCT FROM_LOOP
246 #define BODY \
248 uint32_t ch = *inptr; \
250 /* Recognize escape sequences. */ \
251 if (__builtin_expect (ch, 0) == ESC) \
253 /* We now must be prepared to read two to three more \
254 chracters. If we have a match in the first character but \
255 then the input buffer ends we terminate with an error since \
256 we must not risk missing an escape sequence just because it \
257 is not entirely in the current input buffer. */ \
258 if (__builtin_expect (inptr + 2 >= inend, 0) \
259 || (var == iso2022jp2 && inptr[1] == '$' && inptr[2] == '(' \
260 && __builtin_expect (inptr + 3 >= inend, 0))) \
262 /* Not enough input available. */ \
263 result = __GCONV_INCOMPLETE_INPUT; \
264 break; \
267 if (inptr[1] == '(') \
269 if (inptr[2] == 'B') \
271 /* ASCII selected. */ \
272 set = ASCII_set; \
273 inptr += 3; \
274 continue; \
276 else if (inptr[2] == 'J') \
278 /* JIS X 0201 selected. */ \
279 set = JISX0201_Roman_set; \
280 inptr += 3; \
281 continue; \
283 else if (var == iso2022jp2 && inptr[2] == 'I') \
285 /* JIS X 0201 selected. */ \
286 set = JISX0201_Kana_set; \
287 inptr += 3; \
288 continue; \
291 else if (inptr[1] == '$') \
293 if (inptr[2] == '@') \
295 /* JIS X 0208-1978 selected. */ \
296 set = JISX0208_1978_set; \
297 inptr += 3; \
298 continue; \
300 else if (inptr[2] == 'B') \
302 /* JIS X 0208-1983 selected. */ \
303 set = JISX0208_1983_set; \
304 inptr += 3; \
305 continue; \
307 else if (var == iso2022jp2) \
309 if (inptr[2] == 'A') \
311 /* GB 2312-1980 selected. */ \
312 set = GB2312_set; \
313 inptr += 3; \
314 continue; \
316 else if (inptr[2] == '(') \
318 if (inptr[3] == 'C') \
320 /* KSC 5601-1987 selected. */ \
321 set = KSC5601_set; \
322 inptr += 4; \
323 continue; \
325 else if (inptr[3] == 'D') \
327 /* JIS X 0212-1990 selected. */ \
328 set = JISX0212_set; \
329 inptr += 4; \
330 continue; \
335 else if (var == iso2022jp2 && inptr[1] == '.') \
337 if (inptr[2] == 'A') \
339 /* ISO 8859-1-GR selected. */ \
340 set2 = ISO88591_set; \
341 inptr += 3; \
342 continue; \
344 else if (inptr[2] == 'F') \
346 /* ISO 8859-7-GR selected. */ \
347 set2 = ISO88597_set; \
348 inptr += 3; \
349 continue; \
354 if (ch == ESC && var == iso2022jp2 && inptr[1] == 'N') \
356 if (set2 == ISO88591_set) \
358 ch = inptr[2] | 0x80; \
359 inptr += 3; \
361 else if (__builtin_expect (set2, ISO88597_set) == ISO88597_set) \
363 /* We use the table from the ISO 8859-7 module. */ \
364 if (inptr[2] < 0x20 || inptr[2] >= 0x80) \
366 if (! ignore_errors_p ()) \
368 result = __GCONV_ILLEGAL_INPUT; \
369 break; \
372 ++inptr; \
373 ++*irreversible; \
374 continue; \
376 ch = iso88597_to_ucs4[inptr[2] - 0x20]; \
377 if (ch == 0) \
379 if (! ignore_errors_p ()) \
381 result = __GCONV_ILLEGAL_INPUT; \
382 break; \
385 inptr += 3; \
386 ++*irreversible; \
387 continue; \
389 inptr += 3; \
391 else \
393 if (! ignore_errors_p ()) \
395 result = __GCONV_ILLEGAL_INPUT; \
396 break; \
399 ++inptr; \
400 ++*irreversible; \
401 continue; \
404 else if (ch >= 0x80) \
406 if (! ignore_errors_p ()) \
408 result = __GCONV_ILLEGAL_INPUT; \
409 break; \
412 ++inptr; \
413 ++*irreversible; \
414 continue; \
416 else if (set == ASCII_set || (ch < 0x21 || ch == 0x7f)) \
417 /* Almost done, just advance the input pointer. */ \
418 ++inptr; \
419 else if (set == JISX0201_Roman_set) \
421 /* Use the JIS X 0201 table. */ \
422 ch = jisx0201_to_ucs4 (ch); \
423 if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \
425 if (! ignore_errors_p ()) \
427 result = __GCONV_ILLEGAL_INPUT; \
428 break; \
431 ++inptr; \
432 ++*irreversible; \
433 continue; \
435 ++inptr; \
437 else if (set == JISX0201_Kana_set) \
439 /* Use the JIS X 0201 table. */ \
440 ch = jisx0201_to_ucs4 (ch + 0x80); \
441 if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \
443 if (! ignore_errors_p ()) \
445 result = __GCONV_ILLEGAL_INPUT; \
446 break; \
449 ++inptr; \
450 ++*irreversible; \
451 continue; \
453 ++inptr; \
455 else \
457 if (set == JISX0208_1978_set || set == JISX0208_1983_set) \
458 /* XXX I don't have the tables for these two old variants of \
459 JIS X 0208. Therefore I'm using the tables for JIS X \
460 0208-1990. If somebody has problems with this please \
461 provide the appropriate tables. */ \
462 ch = jisx0208_to_ucs4 (&inptr, inend - inptr, 0); \
463 else if (set == JISX0212_set) \
464 /* Use the JIS X 0212 table. */ \
465 ch = jisx0212_to_ucs4 (&inptr, inend - inptr, 0); \
466 else if (set == GB2312_set) \
467 /* Use the GB 2312 table. */ \
468 ch = gb2312_to_ucs4 (&inptr, inend - inptr, 0); \
469 else \
471 assert (set == KSC5601_set); \
473 /* Use the KSC 5601 table. */ \
474 ch = ksc5601_to_ucs4 (&inptr, inend - inptr, 0); \
477 if (__builtin_expect (ch, 1) == 0) \
479 result = __GCONV_INCOMPLETE_INPUT; \
480 break; \
482 else if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \
484 if (! ignore_errors_p ()) \
486 result = __GCONV_ILLEGAL_INPUT; \
487 break; \
490 ++inptr; \
491 ++*irreversible; \
492 continue; \
496 put32 (outptr, ch); \
497 outptr += 4; \
499 #define LOOP_NEED_FLAGS
500 #define EXTRA_LOOP_DECLS , enum variant var, int *setp
501 #define INIT_PARAMS int set = *setp & CURRENT_SEL_MASK; \
502 int set2 = *setp & CURRENT_ASSIGN_MASK
503 #define UPDATE_PARAMS *setp = set | set2
504 #include <iconv/loop.c>
507 /* Next, define the other direction. */
508 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
509 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
510 #define MAX_NEEDED_OUTPUT (MAX_NEEDED_FROM + 2)
511 #define LOOPFCT TO_LOOP
512 #define BODY \
514 uint32_t ch; \
515 size_t written = 0; \
517 ch = get32 (inptr); \
519 /* First see whether we can write the character using the currently \
520 selected character set. */ \
521 if (set == ASCII_set) \
523 /* Please note that the NUL byte is *not* matched if we are not \
524 currently using the ASCII charset. This is because we must \
525 switch to the initial state whenever a NUL byte is written. */ \
526 if (ch <= 0x7f) \
528 *outptr++ = ch; \
529 written = 1; \
531 /* At the beginning of a line, G2 designation is cleared. */ \
532 if (var == iso2022jp2 && ch == 0x0a) \
533 set2 = UNSPECIFIED_set; \
535 /* ISO-2022-JP recommends to encode the newline character always in \
536 ASCII since this allows a context-free interpretation of the \
537 characters at the beginning of the next line. Otherwise it would \
538 have to be known whether the last line ended using ASCII or \
539 JIS X 0201. */ \
540 else if (set == JISX0201_Roman_set) \
542 unsigned char buf[2]; \
543 written = ucs4_to_jisx0201 (ch, buf); \
544 if (written != __UNKNOWN_10646_CHAR && buf[0] > 0x20 \
545 && buf[0] < 0x80) \
547 *outptr++ = buf[0]; \
548 written = 1; \
550 else \
551 written = __UNKNOWN_10646_CHAR; \
553 else if (set == JISX0201_Kana_set) \
555 unsigned char buf[2]; \
556 written = ucs4_to_jisx0201 (ch, buf); \
557 if (written != __UNKNOWN_10646_CHAR && buf[0] > 0xa0 \
558 && buf[0] < 0xe0) \
560 *outptr++ = buf[0] - 0x80; \
561 written = 1; \
563 else \
564 written = __UNKNOWN_10646_CHAR; \
566 else \
568 if (set == JISX0208_1978_set || set == JISX0208_1983_set) \
569 written = ucs4_to_jisx0208 (ch, outptr, outend - outptr); \
570 else if (set == JISX0212_set) \
571 written = ucs4_to_jisx0212 (ch, outptr, outend - outptr); \
572 else if (set == GB2312_set) \
573 written = ucs4_to_gb2312 (ch, outptr, outend - outptr); \
574 else \
576 assert (set == KSC5601_set); \
578 written = ucs4_to_ksc5601 (ch, outptr, outend - outptr); \
581 if (__builtin_expect (written, 1) == 0) \
583 result = __GCONV_FULL_OUTPUT; \
584 break; \
586 else if (written != __UNKNOWN_10646_CHAR) \
587 outptr += written; \
590 if (written == __UNKNOWN_10646_CHAR || written == 0) \
592 if (set2 == ISO88591_set) \
594 if (__builtin_expect (outptr + 3 > outend, 0)) \
596 result = __GCONV_FULL_OUTPUT; \
597 break; \
600 if (ch >= 0x80 && ch <= 0xff) \
602 *outptr++ = ESC; \
603 *outptr++ = 'N'; \
604 *outptr++ = ch & 0x7f; \
605 written = 3; \
608 else if (set2 == ISO88597_set) \
610 const struct gap *rp = from_idx; \
612 while (ch > rp->end) \
613 ++rp; \
614 if (ch >= rp->start) \
616 unsigned char res = iso88597_from_ucs4[ch - 0xa0 + rp->idx]; \
617 if (res != '\0') \
619 if (__builtin_expect (outptr + 3 > outend, 0)) \
621 result = __GCONV_FULL_OUTPUT; \
622 break; \
625 *outptr++ = ESC; \
626 *outptr++ = 'N'; \
627 *outptr++ = res; \
628 written = 3; \
634 if (written == __UNKNOWN_10646_CHAR || written == 0) \
636 /* Either this is an unknown character or we have to switch \
637 the currently selected character set. The character sets \
638 do not code entirely separate parts of ISO 10646 and \
639 therefore there is no single correct result. If we choose \
640 the character set to use wrong we might be end up with \
641 using yet another character set for the next character \
642 though the current and the next could be encoded with one \
643 character set. We leave this kind of optimization for \
644 later and now simply use a fixed order in which we test for \
645 availability */ \
647 if (ch <= 0x7f) \
649 /* We must encode using ASCII. First write out the \
650 escape sequence. */ \
651 if (__builtin_expect (outptr + 3 > outend, 0)) \
653 result = __GCONV_FULL_OUTPUT; \
654 break; \
657 *outptr++ = ESC; \
658 *outptr++ = '('; \
659 *outptr++ = 'B'; \
660 set = ASCII_set; \
662 if (__builtin_expect (outptr + 1 > outend, 0)) \
664 result = __GCONV_FULL_OUTPUT; \
665 break; \
667 *outptr++ = ch; \
669 /* At the beginning of a line, G2 designation is cleared. */ \
670 if (var == iso2022jp2 && ch == 0x0a) \
671 set2 = UNSPECIFIED_set; \
673 else \
675 /* Now it becomes difficult. We must search the other \
676 character sets one by one and we cannot use simple \
677 arithmetic to determine whether the character can be \
678 encoded using this set. */ \
679 size_t written; \
680 unsigned char buf[2]; \
682 written = ucs4_to_jisx0201 (ch, buf); \
683 if (written != __UNKNOWN_10646_CHAR && buf[0] < 0x80) \
685 /* We use JIS X 0201. */ \
686 if (__builtin_expect (outptr + 3 > outend, 0)) \
688 result = __GCONV_FULL_OUTPUT; \
689 break; \
692 *outptr++ = ESC; \
693 *outptr++ = '('; \
694 *outptr++ = 'J'; \
695 set = JISX0201_Roman_set; \
697 if (__builtin_expect (outptr + 1 > outend, 0)) \
699 result = __GCONV_FULL_OUTPUT; \
700 break; \
702 *outptr++ = buf[0]; \
704 else \
706 written = ucs4_to_jisx0208 (ch, buf, 2); \
707 if (written != __UNKNOWN_10646_CHAR) \
709 /* We use JIS X 0208. */ \
710 if (__builtin_expect (outptr + 3 > outend, 0)) \
712 result = __GCONV_FULL_OUTPUT; \
713 break; \
716 *outptr++ = ESC; \
717 *outptr++ = '$'; \
718 *outptr++ = 'B'; \
719 set = JISX0208_1983_set; \
721 if (__builtin_expect (outptr + 2 > outend, 0)) \
723 result = __GCONV_FULL_OUTPUT; \
724 break; \
726 *outptr++ = buf[0]; \
727 *outptr++ = buf[1]; \
729 else if (__builtin_expect (var, iso2022jp2) == iso2022jp) \
731 /* We have no other choice. */ \
732 STANDARD_ERR_HANDLER (4); \
734 else \
736 written = ucs4_to_jisx0212 (ch, buf, 2); \
737 if (written != __UNKNOWN_10646_CHAR) \
739 /* We use JIS X 0212. */ \
740 if (__builtin_expect (outptr + 4 > outend, 0)) \
742 result = __GCONV_FULL_OUTPUT; \
743 break; \
745 *outptr++ = ESC; \
746 *outptr++ = '$'; \
747 *outptr++ = '('; \
748 *outptr++ = 'D'; \
749 set = JISX0212_set; \
751 if (__builtin_expect (outptr + 2 > outend, 0)) \
753 result = __GCONV_FULL_OUTPUT; \
754 break; \
756 *outptr++ = buf[0]; \
757 *outptr++ = buf[1]; \
759 else \
761 written = ucs4_to_jisx0201 (ch, buf); \
762 if (written != __UNKNOWN_10646_CHAR \
763 && buf[0] >= 0x80) \
765 /* We use JIS X 0201. */ \
766 if (__builtin_expect (outptr + 3 > outend, 0)) \
768 result = __GCONV_FULL_OUTPUT; \
769 break; \
772 *outptr++ = ESC; \
773 *outptr++ = '('; \
774 *outptr++ = 'I'; \
775 set = JISX0201_Kana_set; \
777 if (__builtin_expect (outptr + 1 > outend, 0)) \
779 result = __GCONV_FULL_OUTPUT; \
780 break; \
782 *outptr++ = buf[0] - 0x80; \
784 else if (ch != 0xa5 && ch >= 0x80 && ch <= 0xff) \
786 /* ISO 8859-1 upper half. */ \
787 if (__builtin_expect (outptr + 3 > outend, 0)) \
789 result = __GCONV_FULL_OUTPUT; \
790 break; \
793 *outptr++ = ESC; \
794 *outptr++ = '.'; \
795 *outptr++ = 'A'; \
796 set2 = ISO88591_set; \
798 if (__builtin_expect (outptr + 3 > outend, 0)) \
800 result = __GCONV_FULL_OUTPUT; \
801 break; \
803 *outptr++ = ESC; \
804 *outptr++ = 'N'; \
805 *outptr++ = ch - 0x80; \
807 else \
809 written = ucs4_to_gb2312 (ch, buf, 2); \
810 if (written != __UNKNOWN_10646_CHAR) \
812 /* We use GB 2312. */ \
813 if (__builtin_expect (outptr + 3 > outend, 0))\
815 result = __GCONV_FULL_OUTPUT; \
816 break; \
819 *outptr++ = ESC; \
820 *outptr++ = '$'; \
821 *outptr++ = 'A'; \
822 set = GB2312_set; \
824 if (__builtin_expect (outptr + 2 > outend, 0))\
826 result = __GCONV_FULL_OUTPUT; \
827 break; \
829 *outptr++ = buf[0]; \
830 *outptr++ = buf[1]; \
832 else \
834 written = ucs4_to_ksc5601 (ch, buf, 2); \
835 if (written != __UNKNOWN_10646_CHAR) \
837 /* We use KSC 5601. */ \
838 if (__builtin_expect (outptr + 4 > outend,\
839 0)) \
841 result = __GCONV_FULL_OUTPUT; \
842 break; \
844 *outptr++ = ESC; \
845 *outptr++ = '$'; \
846 *outptr++ = '('; \
847 *outptr++ = 'C'; \
848 set = KSC5601_set; \
850 if (__builtin_expect (outptr + 2 > outend,\
851 0)) \
853 result = __GCONV_FULL_OUTPUT; \
854 break; \
856 *outptr++ = buf[0]; \
857 *outptr++ = buf[1]; \
859 else \
861 const struct gap *rp = from_idx; \
862 unsigned char gch = 0; \
864 while (ch > rp->end) \
865 ++rp; \
866 if (ch >= rp->start) \
868 ch = ch - 0xa0 + rp->idx; \
869 gch = iso88597_from_ucs4[ch]; \
872 if (__builtin_expect (gch, 1) != 0) \
874 /* We use ISO 8859-7 greek. */ \
875 if (__builtin_expect (outptr + 3 \
876 > outend, 0)) \
878 result = __GCONV_FULL_OUTPUT; \
879 break; \
881 *outptr++ = ESC; \
882 *outptr++ = '.'; \
883 *outptr++ = 'F'; \
884 set2 = ISO88597_set; \
886 if (__builtin_expect (outptr + 3 \
887 > outend, 0)) \
889 result = __GCONV_FULL_OUTPUT; \
890 break; \
892 *outptr++ = ESC; \
893 *outptr++ = 'N'; \
894 *outptr++ = gch; \
896 else \
898 STANDARD_ERR_HANDLER (4); \
909 /* Now that we wrote the output increment the input pointer. */ \
910 inptr += 4; \
912 #define LOOP_NEED_FLAGS
913 #define EXTRA_LOOP_DECLS , enum variant var, int *setp
914 #define INIT_PARAMS int set = *setp & CURRENT_SEL_MASK; \
915 int set2 = *setp & CURRENT_ASSIGN_MASK
916 #define UPDATE_PARAMS *setp = set | set2
917 #include <iconv/loop.c>
920 /* Now define the toplevel functions. */
921 #include <iconv/skeleton.c>