(ipc_perm): Put back __key.
[glibc.git] / iconvdata / iso-2022-jp.c
blob8825dcc0fd51d227fd7b6926bd0644334b318b12
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 /* Avoid warning about unused variable 'var'. */ \
197 (void) var; \
199 if ((data->__statep->__count & ~7) != ASCII_set) \
201 if (dir == from_iso2022jp) \
203 /* It's easy, we don't have to emit anything, we just reset the \
204 state for the input. Note that this also clears the G2 \
205 designation. */ \
206 data->__statep->__count &= 7; \
207 data->__statep->__count |= ASCII_set; \
209 else \
211 /* We are not in the initial state. To switch back we have \
212 to emit the sequence `Esc ( B'. */ \
213 if (__builtin_expect (outbuf + 3 > outend, 0)) \
214 /* We don't have enough room in the output buffer. */ \
215 status = __GCONV_FULL_OUTPUT; \
216 else \
218 /* Write out the shift sequence. */ \
219 *outbuf++ = ESC; \
220 *outbuf++ = '('; \
221 *outbuf++ = 'B'; \
222 /* Note that this also clears the G2 designation. */ \
223 data->__statep->__count &= ~7; \
224 data->__statep->__count |= ASCII_set; \
230 /* Since we might have to reset input pointer we must be able to save
231 and retore the state. */
232 #define SAVE_RESET_STATE(Save) \
233 if (Save) \
234 save_set = *setp; \
235 else \
236 *setp = save_set
239 /* First define the conversion function from ISO-2022-JP to UCS4. */
240 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
241 #define MAX_NEEDED_INPUT MAX_NEEDED_FROM
242 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
243 #define LOOPFCT FROM_LOOP
244 #define BODY \
246 uint32_t ch = *inptr; \
248 /* Recognize escape sequences. */ \
249 if (__builtin_expect (ch, 0) == ESC) \
251 /* We now must be prepared to read two to three more \
252 chracters. If we have a match in the first character but \
253 then the input buffer ends we terminate with an error since \
254 we must not risk missing an escape sequence just because it \
255 is not entirely in the current input buffer. */ \
256 if (__builtin_expect (inptr + 2 >= inend, 0) \
257 || (var == iso2022jp2 && inptr[1] == '$' && inptr[2] == '(' \
258 && __builtin_expect (inptr + 3 >= inend, 0))) \
260 /* Not enough input available. */ \
261 result = __GCONV_INCOMPLETE_INPUT; \
262 break; \
265 if (inptr[1] == '(') \
267 if (inptr[2] == 'B') \
269 /* ASCII selected. */ \
270 set = ASCII_set; \
271 inptr += 3; \
272 continue; \
274 else if (inptr[2] == 'J') \
276 /* JIS X 0201 selected. */ \
277 set = JISX0201_Roman_set; \
278 inptr += 3; \
279 continue; \
281 else if (var == iso2022jp2 && inptr[2] == 'I') \
283 /* JIS X 0201 selected. */ \
284 set = JISX0201_Kana_set; \
285 inptr += 3; \
286 continue; \
289 else if (inptr[1] == '$') \
291 if (inptr[2] == '@') \
293 /* JIS X 0208-1978 selected. */ \
294 set = JISX0208_1978_set; \
295 inptr += 3; \
296 continue; \
298 else if (inptr[2] == 'B') \
300 /* JIS X 0208-1983 selected. */ \
301 set = JISX0208_1983_set; \
302 inptr += 3; \
303 continue; \
305 else if (var == iso2022jp2) \
307 if (inptr[2] == 'A') \
309 /* GB 2312-1980 selected. */ \
310 set = GB2312_set; \
311 inptr += 3; \
312 continue; \
314 else if (inptr[2] == '(') \
316 if (inptr[3] == 'C') \
318 /* KSC 5601-1987 selected. */ \
319 set = KSC5601_set; \
320 inptr += 4; \
321 continue; \
323 else if (inptr[3] == 'D') \
325 /* JIS X 0212-1990 selected. */ \
326 set = JISX0212_set; \
327 inptr += 4; \
328 continue; \
333 else if (var == iso2022jp2 && inptr[1] == '.') \
335 if (inptr[2] == 'A') \
337 /* ISO 8859-1-GR selected. */ \
338 set2 = ISO88591_set; \
339 inptr += 3; \
340 continue; \
342 else if (inptr[2] == 'F') \
344 /* ISO 8859-7-GR selected. */ \
345 set2 = ISO88597_set; \
346 inptr += 3; \
347 continue; \
352 if (ch == ESC && var == iso2022jp2 && inptr[1] == 'N') \
354 if (set2 == ISO88591_set) \
356 ch = inptr[2] | 0x80; \
357 inptr += 3; \
359 else if (__builtin_expect (set2, ISO88597_set) == ISO88597_set) \
361 /* We use the table from the ISO 8859-7 module. */ \
362 if (inptr[2] < 0x20 || inptr[2] >= 0x80) \
364 if (! ignore_errors_p ()) \
366 result = __GCONV_ILLEGAL_INPUT; \
367 break; \
370 ++inptr; \
371 ++*irreversible; \
372 continue; \
374 ch = iso88597_to_ucs4[inptr[2] - 0x20]; \
375 if (ch == 0) \
377 if (! ignore_errors_p ()) \
379 result = __GCONV_ILLEGAL_INPUT; \
380 break; \
383 inptr += 3; \
384 ++*irreversible; \
385 continue; \
387 inptr += 3; \
389 else \
391 if (! ignore_errors_p ()) \
393 result = __GCONV_ILLEGAL_INPUT; \
394 break; \
397 ++inptr; \
398 ++*irreversible; \
399 continue; \
402 else if (ch >= 0x80) \
404 if (! ignore_errors_p ()) \
406 result = __GCONV_ILLEGAL_INPUT; \
407 break; \
410 ++inptr; \
411 ++*irreversible; \
412 continue; \
414 else if (set == ASCII_set || (ch < 0x21 || ch == 0x7f)) \
415 /* Almost done, just advance the input pointer. */ \
416 ++inptr; \
417 else if (set == JISX0201_Roman_set) \
419 /* Use the JIS X 0201 table. */ \
420 ch = jisx0201_to_ucs4 (ch); \
421 if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \
423 if (! ignore_errors_p ()) \
425 result = __GCONV_ILLEGAL_INPUT; \
426 break; \
429 ++inptr; \
430 ++*irreversible; \
431 continue; \
433 ++inptr; \
435 else if (set == JISX0201_Kana_set) \
437 /* Use the JIS X 0201 table. */ \
438 ch = jisx0201_to_ucs4 (ch + 0x80); \
439 if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \
441 if (! ignore_errors_p ()) \
443 result = __GCONV_ILLEGAL_INPUT; \
444 break; \
447 ++inptr; \
448 ++*irreversible; \
449 continue; \
451 ++inptr; \
453 else \
455 if (set == JISX0208_1978_set || set == JISX0208_1983_set) \
456 /* XXX I don't have the tables for these two old variants of \
457 JIS X 0208. Therefore I'm using the tables for JIS X \
458 0208-1990. If somebody has problems with this please \
459 provide the appropriate tables. */ \
460 ch = jisx0208_to_ucs4 (&inptr, inend - inptr, 0); \
461 else if (set == JISX0212_set) \
462 /* Use the JIS X 0212 table. */ \
463 ch = jisx0212_to_ucs4 (&inptr, inend - inptr, 0); \
464 else if (set == GB2312_set) \
465 /* Use the GB 2312 table. */ \
466 ch = gb2312_to_ucs4 (&inptr, inend - inptr, 0); \
467 else \
469 assert (set == KSC5601_set); \
471 /* Use the KSC 5601 table. */ \
472 ch = ksc5601_to_ucs4 (&inptr, inend - inptr, 0); \
475 if (__builtin_expect (ch, 1) == 0) \
477 result = __GCONV_INCOMPLETE_INPUT; \
478 break; \
480 else if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \
482 if (! ignore_errors_p ()) \
484 result = __GCONV_ILLEGAL_INPUT; \
485 break; \
488 ++inptr; \
489 ++*irreversible; \
490 continue; \
494 put32 (outptr, ch); \
495 outptr += 4; \
497 #define LOOP_NEED_FLAGS
498 #define EXTRA_LOOP_DECLS , enum variant var, int *setp
499 #define INIT_PARAMS int set = *setp & CURRENT_SEL_MASK; \
500 int set2 = *setp & CURRENT_ASSIGN_MASK
501 #define UPDATE_PARAMS *setp = set | set2
502 #include <iconv/loop.c>
505 /* Next, define the other direction. */
506 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
507 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
508 #define MAX_NEEDED_OUTPUT (MAX_NEEDED_FROM + 2)
509 #define LOOPFCT TO_LOOP
510 #define BODY \
512 uint32_t ch; \
513 size_t written = 0; \
515 ch = get32 (inptr); \
517 /* First see whether we can write the character using the currently \
518 selected character set. */ \
519 if (set == ASCII_set) \
521 /* Please note that the NUL byte is *not* matched if we are not \
522 currently using the ASCII charset. This is because we must \
523 switch to the initial state whenever a NUL byte is written. */ \
524 if (ch <= 0x7f) \
526 *outptr++ = ch; \
527 written = 1; \
529 /* At the beginning of a line, G2 designation is cleared. */ \
530 if (var == iso2022jp2 && ch == 0x0a) \
531 set2 = UNSPECIFIED_set; \
533 /* ISO-2022-JP recommends to encode the newline character always in \
534 ASCII since this allows a context-free interpretation of the \
535 characters at the beginning of the next line. Otherwise it would \
536 have to be known whether the last line ended using ASCII or \
537 JIS X 0201. */ \
538 else if (set == JISX0201_Roman_set) \
540 unsigned char buf[2]; \
541 written = ucs4_to_jisx0201 (ch, buf); \
542 if (written != __UNKNOWN_10646_CHAR && buf[0] > 0x20 \
543 && buf[0] < 0x80) \
545 *outptr++ = buf[0]; \
546 written = 1; \
548 else \
549 written = __UNKNOWN_10646_CHAR; \
551 else if (set == JISX0201_Kana_set) \
553 unsigned char buf[2]; \
554 written = ucs4_to_jisx0201 (ch, buf); \
555 if (written != __UNKNOWN_10646_CHAR && buf[0] > 0xa0 \
556 && buf[0] < 0xe0) \
558 *outptr++ = buf[0] - 0x80; \
559 written = 1; \
561 else \
562 written = __UNKNOWN_10646_CHAR; \
564 else \
566 if (set == JISX0208_1978_set || set == JISX0208_1983_set) \
567 written = ucs4_to_jisx0208 (ch, outptr, outend - outptr); \
568 else if (set == JISX0212_set) \
569 written = ucs4_to_jisx0212 (ch, outptr, outend - outptr); \
570 else if (set == GB2312_set) \
571 written = ucs4_to_gb2312 (ch, outptr, outend - outptr); \
572 else \
574 assert (set == KSC5601_set); \
576 written = ucs4_to_ksc5601 (ch, outptr, outend - outptr); \
579 if (__builtin_expect (written, 1) == 0) \
581 result = __GCONV_FULL_OUTPUT; \
582 break; \
584 else if (written != __UNKNOWN_10646_CHAR) \
585 outptr += written; \
588 if (written == __UNKNOWN_10646_CHAR || written == 0) \
590 if (set2 == ISO88591_set) \
592 if (__builtin_expect (outptr + 3 > outend, 0)) \
594 result = __GCONV_FULL_OUTPUT; \
595 break; \
598 if (ch >= 0x80 && ch <= 0xff) \
600 *outptr++ = ESC; \
601 *outptr++ = 'N'; \
602 *outptr++ = ch & 0x7f; \
603 written = 3; \
606 else if (set2 == ISO88597_set) \
608 const struct gap *rp = from_idx; \
610 while (ch > rp->end) \
611 ++rp; \
612 if (ch >= rp->start) \
614 unsigned char res = iso88597_from_ucs4[ch - 0xa0 + rp->idx]; \
615 if (res != '\0') \
617 if (__builtin_expect (outptr + 3 > outend, 0)) \
619 result = __GCONV_FULL_OUTPUT; \
620 break; \
623 *outptr++ = ESC; \
624 *outptr++ = 'N'; \
625 *outptr++ = res; \
626 written = 3; \
632 if (written == __UNKNOWN_10646_CHAR || written == 0) \
634 /* Either this is an unknown character or we have to switch \
635 the currently selected character set. The character sets \
636 do not code entirely separate parts of ISO 10646 and \
637 therefore there is no single correct result. If we choose \
638 the character set to use wrong we might be end up with \
639 using yet another character set for the next character \
640 though the current and the next could be encoded with one \
641 character set. We leave this kind of optimization for \
642 later and now simply use a fixed order in which we test for \
643 availability */ \
645 if (ch <= 0x7f) \
647 /* We must encode using ASCII. First write out the \
648 escape sequence. */ \
649 if (__builtin_expect (outptr + 3 > outend, 0)) \
651 result = __GCONV_FULL_OUTPUT; \
652 break; \
655 *outptr++ = ESC; \
656 *outptr++ = '('; \
657 *outptr++ = 'B'; \
658 set = ASCII_set; \
660 if (__builtin_expect (outptr + 1 > outend, 0)) \
662 result = __GCONV_FULL_OUTPUT; \
663 break; \
665 *outptr++ = ch; \
667 /* At the beginning of a line, G2 designation is cleared. */ \
668 if (var == iso2022jp2 && ch == 0x0a) \
669 set2 = UNSPECIFIED_set; \
671 else \
673 /* Now it becomes difficult. We must search the other \
674 character sets one by one and we cannot use simple \
675 arithmetic to determine whether the character can be \
676 encoded using this set. */ \
677 size_t written; \
678 unsigned char buf[2]; \
680 written = ucs4_to_jisx0201 (ch, buf); \
681 if (written != __UNKNOWN_10646_CHAR && buf[0] < 0x80) \
683 /* We use JIS X 0201. */ \
684 if (__builtin_expect (outptr + 3 > outend, 0)) \
686 result = __GCONV_FULL_OUTPUT; \
687 break; \
690 *outptr++ = ESC; \
691 *outptr++ = '('; \
692 *outptr++ = 'J'; \
693 set = JISX0201_Roman_set; \
695 if (__builtin_expect (outptr + 1 > outend, 0)) \
697 result = __GCONV_FULL_OUTPUT; \
698 break; \
700 *outptr++ = buf[0]; \
702 else \
704 written = ucs4_to_jisx0208 (ch, buf, 2); \
705 if (written != __UNKNOWN_10646_CHAR) \
707 /* We use JIS X 0208. */ \
708 if (__builtin_expect (outptr + 3 > outend, 0)) \
710 result = __GCONV_FULL_OUTPUT; \
711 break; \
714 *outptr++ = ESC; \
715 *outptr++ = '$'; \
716 *outptr++ = 'B'; \
717 set = JISX0208_1983_set; \
719 if (__builtin_expect (outptr + 2 > outend, 0)) \
721 result = __GCONV_FULL_OUTPUT; \
722 break; \
724 *outptr++ = buf[0]; \
725 *outptr++ = buf[1]; \
727 else if (__builtin_expect (var, iso2022jp2) == iso2022jp) \
729 /* We have no other choice. */ \
730 STANDARD_ERR_HANDLER (4); \
732 else \
734 written = ucs4_to_jisx0212 (ch, buf, 2); \
735 if (written != __UNKNOWN_10646_CHAR) \
737 /* We use JIS X 0212. */ \
738 if (__builtin_expect (outptr + 4 > outend, 0)) \
740 result = __GCONV_FULL_OUTPUT; \
741 break; \
743 *outptr++ = ESC; \
744 *outptr++ = '$'; \
745 *outptr++ = '('; \
746 *outptr++ = 'D'; \
747 set = JISX0212_set; \
749 if (__builtin_expect (outptr + 2 > outend, 0)) \
751 result = __GCONV_FULL_OUTPUT; \
752 break; \
754 *outptr++ = buf[0]; \
755 *outptr++ = buf[1]; \
757 else \
759 written = ucs4_to_jisx0201 (ch, buf); \
760 if (written != __UNKNOWN_10646_CHAR \
761 && buf[0] >= 0x80) \
763 /* We use JIS X 0201. */ \
764 if (__builtin_expect (outptr + 3 > outend, 0)) \
766 result = __GCONV_FULL_OUTPUT; \
767 break; \
770 *outptr++ = ESC; \
771 *outptr++ = '('; \
772 *outptr++ = 'I'; \
773 set = JISX0201_Kana_set; \
775 if (__builtin_expect (outptr + 1 > outend, 0)) \
777 result = __GCONV_FULL_OUTPUT; \
778 break; \
780 *outptr++ = buf[0] - 0x80; \
782 else if (ch != 0xa5 && ch >= 0x80 && ch <= 0xff) \
784 /* ISO 8859-1 upper half. */ \
785 if (__builtin_expect (outptr + 3 > outend, 0)) \
787 result = __GCONV_FULL_OUTPUT; \
788 break; \
791 *outptr++ = ESC; \
792 *outptr++ = '.'; \
793 *outptr++ = 'A'; \
794 set2 = ISO88591_set; \
796 if (__builtin_expect (outptr + 3 > outend, 0)) \
798 result = __GCONV_FULL_OUTPUT; \
799 break; \
801 *outptr++ = ESC; \
802 *outptr++ = 'N'; \
803 *outptr++ = ch - 0x80; \
805 else \
807 written = ucs4_to_gb2312 (ch, buf, 2); \
808 if (written != __UNKNOWN_10646_CHAR) \
810 /* We use GB 2312. */ \
811 if (__builtin_expect (outptr + 3 > outend, 0))\
813 result = __GCONV_FULL_OUTPUT; \
814 break; \
817 *outptr++ = ESC; \
818 *outptr++ = '$'; \
819 *outptr++ = 'A'; \
820 set = GB2312_set; \
822 if (__builtin_expect (outptr + 2 > outend, 0))\
824 result = __GCONV_FULL_OUTPUT; \
825 break; \
827 *outptr++ = buf[0]; \
828 *outptr++ = buf[1]; \
830 else \
832 written = ucs4_to_ksc5601 (ch, buf, 2); \
833 if (written != __UNKNOWN_10646_CHAR) \
835 /* We use KSC 5601. */ \
836 if (__builtin_expect (outptr + 4 > outend,\
837 0)) \
839 result = __GCONV_FULL_OUTPUT; \
840 break; \
842 *outptr++ = ESC; \
843 *outptr++ = '$'; \
844 *outptr++ = '('; \
845 *outptr++ = 'C'; \
846 set = KSC5601_set; \
848 if (__builtin_expect (outptr + 2 > outend,\
849 0)) \
851 result = __GCONV_FULL_OUTPUT; \
852 break; \
854 *outptr++ = buf[0]; \
855 *outptr++ = buf[1]; \
857 else \
859 const struct gap *rp = from_idx; \
860 unsigned char gch = 0; \
862 while (ch > rp->end) \
863 ++rp; \
864 if (ch >= rp->start) \
866 ch = ch - 0xa0 + rp->idx; \
867 gch = iso88597_from_ucs4[ch]; \
870 if (__builtin_expect (gch, 1) != 0) \
872 /* We use ISO 8859-7 greek. */ \
873 if (__builtin_expect (outptr + 3 \
874 > outend, 0)) \
876 result = __GCONV_FULL_OUTPUT; \
877 break; \
879 *outptr++ = ESC; \
880 *outptr++ = '.'; \
881 *outptr++ = 'F'; \
882 set2 = ISO88597_set; \
884 if (__builtin_expect (outptr + 3 \
885 > outend, 0)) \
887 result = __GCONV_FULL_OUTPUT; \
888 break; \
890 *outptr++ = ESC; \
891 *outptr++ = 'N'; \
892 *outptr++ = gch; \
894 else \
896 STANDARD_ERR_HANDLER (4); \
907 /* Now that we wrote the output increment the input pointer. */ \
908 inptr += 4; \
910 #define LOOP_NEED_FLAGS
911 #define EXTRA_LOOP_DECLS , enum variant var, int *setp
912 #define INIT_PARAMS int set = *setp & CURRENT_SEL_MASK; \
913 int set2 = *setp & CURRENT_ASSIGN_MASK
914 #define UPDATE_PARAMS *setp = set | set2
915 #include <iconv/loop.c>
918 /* Now define the toplevel functions. */
919 #include <iconv/skeleton.c>