Update.
[glibc.git] / iconvdata / iso-2022-jp.c
blob105fd4753b3bd7b8edcc19e29757e34c3a2cb809
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 <gconv.h>
22 #include <stdint.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include "jis0201.h"
26 #include "jis0208.h"
27 #include "jis0212.h"
28 #include "gb2312.h"
29 #include "ksc5601.h"
31 struct gap
33 uint16_t start;
34 uint16_t end;
35 int32_t idx;
38 #include "iso8859-7jp.h"
40 /* This makes obvious what everybody knows: 0x1b is the Esc character. */
41 #define ESC 0x1b
43 /* We provide our own initialization and destructor function. */
44 #define DEFINE_INIT 0
45 #define DEFINE_FINI 0
47 /* Definitions used in the body of the `gconv' function. */
48 #define FROM_LOOP from_iso2022jp_loop
49 #define TO_LOOP to_iso2022jp_loop
50 #define MIN_NEEDED_FROM 1
51 #define MAX_NEEDED_FROM 4
52 #define MIN_NEEDED_TO 4
53 #define MAX_NEEDED_TO 4
54 #define FROM_DIRECTION (dir == from_iso2022jp)
55 #define PREPARE_LOOP \
56 enum direction dir = ((struct iso2022jp_data *) step->__data)->dir; \
57 enum variant var = ((struct iso2022jp_data *) step->__data)->var; \
58 int save_set; \
59 int *setp = &data->__statep->__count;
60 #define EXTRA_LOOP_ARGS , var, setp
63 /* Direction of the transformation. */
64 enum direction
66 illegal_dir,
67 to_iso2022jp,
68 from_iso2022jp
71 /* We handle ISO-2022-jp and ISO-2022-JP-2 here. */
72 enum variant
74 illegal_var,
75 iso2022jp,
76 iso2022jp2
80 struct iso2022jp_data
82 enum direction dir;
83 enum variant var;
87 /* The COUNT element of the state keeps track of the currently selected
88 character set. The possible values are: */
89 enum
91 ASCII_set = 0,
92 JISX0208_1978_set = 8,
93 JISX0208_1983_set = 16,
94 JISX0201_Roman_set = 24,
95 JISX0201_Kana_set = 32,
96 GB2312_set = 40,
97 KSC5601_set = 48,
98 JISX0212_set = 56,
99 CURRENT_SEL_MASK = 56
102 /* The second value stored is the designation of the G2 set. The following
103 values are possible: */
104 enum
106 UNSPECIFIED_set = 0,
107 ISO88591_set = 64,
108 ISO88597_set = 128,
109 CURRENT_ASSIGN_MASK = 192
114 gconv_init (struct __gconv_step *step)
116 /* Determine which direction. */
117 struct iso2022jp_data *new_data;
118 enum direction dir = illegal_dir;
119 enum variant var = illegal_var;
120 int result;
122 if (__strcasecmp (step->__from_name, "ISO-2022-JP//") == 0)
124 dir = from_iso2022jp;
125 var = iso2022jp;
127 else if (__strcasecmp (step->__to_name, "ISO-2022-JP//") == 0)
129 dir = to_iso2022jp;
130 var = iso2022jp;
132 else if (__strcasecmp (step->__from_name, "ISO-2022-JP-2//") == 0)
134 dir = from_iso2022jp;
135 var = iso2022jp2;
137 else if (__strcasecmp (step->__to_name, "ISO-2022-JP-2//") == 0)
139 dir = to_iso2022jp;
140 var = iso2022jp2;
143 result = __GCONV_NOCONV;
144 if (dir != illegal_dir)
146 new_data
147 = (struct iso2022jp_data *) malloc (sizeof (struct iso2022jp_data));
149 result = __GCONV_NOMEM;
150 if (new_data != NULL)
152 new_data->dir = dir;
153 new_data->var = var;
154 step->__data = new_data;
156 if (dir == from_iso2022jp)
158 step->__min_needed_from = MIN_NEEDED_FROM;
159 step->__max_needed_from = MAX_NEEDED_FROM;
160 step->__min_needed_to = MIN_NEEDED_TO;
161 step->__max_needed_to = MAX_NEEDED_TO;
163 else
165 step->__min_needed_from = MIN_NEEDED_TO;
166 step->__max_needed_from = MAX_NEEDED_TO;
167 step->__min_needed_to = MIN_NEEDED_FROM;
168 step->__max_needed_to = MAX_NEEDED_FROM + 2;
171 /* Yes, this is a stateful encoding. */
172 step->__stateful = 1;
174 result = __GCONV_OK;
178 return result;
182 void
183 gconv_end (struct __gconv_step *data)
185 free (data->__data);
189 /* Since this is a stateful encoding we have to provide code which resets
190 the output state to the initial state. This has to be done during the
191 flushing. */
192 #define EMIT_SHIFT_TO_INIT \
193 if ((data->__statep->__count & ~7) != ASCII_set) \
195 enum direction dir = ((struct iso2022jp_data *) step->__data)->dir; \
197 if (dir == from_iso2022jp) \
199 /* It's easy, we don't have to emit anything, we just reset the \
200 state for the input. Note that this also clears the G2 \
201 designation. */ \
202 data->__statep->__count &= 7; \
203 data->__statep->__count |= ASCII_set; \
205 else \
207 unsigned char *outbuf = data->__outbuf; \
209 /* We are not in the initial state. To switch back we have \
210 to emit the sequence `Esc ( B'. */ \
211 if (outbuf + 3 > data->__outbufend) \
212 /* We don't have enough room in the output buffer. */ \
213 status = __GCONV_FULL_OUTPUT; \
214 else \
216 /* Write out the shift sequence. */ \
217 *outbuf++ = ESC; \
218 *outbuf++ = '('; \
219 *outbuf++ = 'B'; \
220 if (data->__is_last) \
221 *written += 3; \
222 data->__outbuf = outbuf; \
223 /* Note that this also clears the G2 designation. */ \
224 data->__statep->__count &= ~7; \
225 data->__statep->__count |= ASCII_set; \
231 /* Since we might have to reset input pointer we must be able to save
232 and retore the state. */
233 #define SAVE_RESET_STATE(Save) \
234 if (Save) \
235 save_set = *setp; \
236 else \
237 *setp = save_set
240 /* First define the conversion function from ISO-2022-JP to UCS4. */
241 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
242 #define MAX_NEEDED_INPUT MAX_NEEDED_FROM
243 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
244 #define LOOPFCT FROM_LOOP
245 #define BODY \
247 uint32_t ch = *inptr; \
249 /* Recognize escape sequences. */ \
250 if (ch == ESC) \
252 /* We now must be prepared to read two to three more \
253 chracters. If we have a match in the first character but \
254 then the input buffer ends we terminate with an error since \
255 we must not risk missing an escape sequence just because it \
256 is not entirely in the current input buffer. */ \
257 if (inptr + 2 >= inend \
258 || (var == iso2022jp2 && inptr[1] == '$' && inptr[2] == '(' \
259 && inptr + 3 >= inend)) \
261 /* Not enough input available. */ \
262 result = __GCONV_EMPTY_INPUT; \
263 break; \
266 if (inptr[1] == '(') \
268 if (inptr[2] == 'B') \
270 /* ASCII selected. */ \
271 set = ASCII_set; \
272 inptr += 3; \
273 continue; \
275 else if (inptr[2] == 'J') \
277 /* JIS X 0201 selected. */ \
278 set = JISX0201_Roman_set; \
279 inptr += 3; \
280 continue; \
282 else if (var == iso2022jp2 && inptr[2] == 'I') \
284 /* JIS X 0201 selected. */ \
285 set = JISX0201_Kana_set; \
286 inptr += 3; \
287 continue; \
290 else if (inptr[1] == '$') \
292 if (inptr[2] == '@') \
294 /* JIS X 0208-1978 selected. */ \
295 set = JISX0208_1978_set; \
296 inptr += 3; \
297 continue; \
299 else if (inptr[2] == 'B') \
301 /* JIS X 0208-1983 selected. */ \
302 set = JISX0208_1983_set; \
303 inptr += 3; \
304 continue; \
306 else if (var == iso2022jp2) \
308 if (inptr[2] == 'A') \
310 /* GB 2312-1980 selected. */ \
311 set = GB2312_set; \
312 inptr += 3; \
313 continue; \
315 else if (inptr[2] == '(') \
317 if (inptr[3] == 'C') \
319 /* KSC 5601-1987 selected. */ \
320 set = KSC5601_set; \
321 inptr += 4; \
322 continue; \
324 else if (inptr[3] == 'D') \
326 /* JIS X 0212-1990 selected. */ \
327 set = JISX0212_set; \
328 inptr += 4; \
329 continue; \
334 else if (var == iso2022jp2 && inptr[1] == '.') \
336 if (inptr[2] == 'A') \
338 /* ISO 8859-1-GR selected. */ \
339 set2 = ISO88591_set; \
340 inptr += 3; \
341 continue; \
343 else if (inptr[2] == 'F') \
345 /* ISO 8859-7-GR selected. */ \
346 set2 = ISO88597_set; \
347 inptr += 3; \
348 continue; \
353 if (ch == ESC && var == iso2022jp2 && inptr[1] == 'N') \
355 if (set2 == ISO88591_set) \
357 ch = inptr[2] | 0x80; \
358 inptr += 3; \
360 else if (set2 == ISO88597_set) \
362 /* We use the table from the ISO 8859-7 module. */ \
363 if (inptr[2] < 0x20 || inptr[2] > 0x80) \
365 result = __GCONV_ILLEGAL_INPUT; \
366 break; \
368 ch = iso88597_to_ucs4[inptr[2] - 0x20]; \
369 if (ch == 0) \
371 result = __GCONV_ILLEGAL_INPUT; \
372 break; \
374 inptr += 3; \
376 else \
378 result = __GCONV_ILLEGAL_INPUT; \
379 break; \
382 else if (set == ASCII_set || (ch < 0x21 || ch == 0x7f)) \
383 /* Almost done, just advance the input pointer. */ \
384 ++inptr; \
385 else if (set == JISX0201_Roman_set) \
387 /* Use the JIS X 0201 table. */ \
388 ch = jisx0201_to_ucs4 (ch); \
389 if (ch == __UNKNOWN_10646_CHAR) \
391 result = __GCONV_ILLEGAL_INPUT; \
392 break; \
394 ++inptr; \
396 else if (set == JISX0201_Kana_set) \
398 /* Use the JIS X 0201 table. */ \
399 ch = jisx0201_to_ucs4 (ch + 0x80); \
400 if (ch == __UNKNOWN_10646_CHAR) \
402 result = __GCONV_ILLEGAL_INPUT; \
403 break; \
405 ++inptr; \
407 else \
409 if (set == JISX0208_1978_set || set == JISX0208_1983_set) \
410 /* XXX I don't have the tables for these two old variants of \
411 JIS X 0208. Therefore I'm using the tables for JIS X \
412 0208-1990. If somebody has problems with this please \
413 provide the appropriate tables. */ \
414 ch = jisx0208_to_ucs4 (&inptr, \
415 NEED_LENGTH_TEST ? inend - inptr : 2, 0); \
416 else if (set == JISX0212_set) \
417 /* Use the JIS X 0212 table. */ \
418 ch = jisx0212_to_ucs4 (&inptr, \
419 NEED_LENGTH_TEST ? inend - inptr : 2, 0); \
420 else if (set == GB2312_set) \
421 /* Use the GB 2312 table. */ \
422 ch = gb2312_to_ucs4 (&inptr, \
423 NEED_LENGTH_TEST ? inend - inptr : 2, 0); \
424 else \
426 assert (set == KSC5601_set); \
428 /* Use the KSC 5601 table. */ \
429 ch = ksc5601_to_ucs4 (&inptr, \
430 NEED_LENGTH_TEST ? inend - inptr : 2, 0); \
433 if (NEED_LENGTH_TEST && ch == 0) \
435 result = __GCONV_EMPTY_INPUT; \
436 break; \
438 else if (ch == __UNKNOWN_10646_CHAR) \
440 result = __GCONV_ILLEGAL_INPUT; \
441 break; \
445 put32 (outptr, ch); \
446 outptr += 4; \
448 #define EXTRA_LOOP_DECLS , enum variant var, int *setp
449 #define INIT_PARAMS int set = *setp & CURRENT_SEL_MASK; \
450 int set2 = *setp & CURRENT_ASSIGN_MASK
451 #define UPDATE_PARAMS *setp = set | set2
452 #include <iconv/loop.c>
455 /* Next, define the other direction. */
456 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
457 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
458 #define MAX_NEEDED_OUTPUT (MAX_NEEDED_FROM + 2)
459 #define LOOPFCT TO_LOOP
460 #define BODY \
462 uint32_t ch; \
463 size_t written = 0; \
465 ch = get32 (inptr); \
467 /* First see whether we can write the character using the currently \
468 selected character set. */ \
469 if (set == ASCII_set) \
471 /* Please note that the NUL byte is *not* matched if we are not \
472 currently using the ASCII charset. This is because we must \
473 switch to the initial state whenever a NUL byte is written. */ \
474 if (ch <= 0x7f) \
476 *outptr++ = ch; \
477 written = 1; \
479 /* At the beginning of a line, G2 designation is cleared. */ \
480 if (var == iso2022jp2 && ch == 0x0a) \
481 set2 = UNSPECIFIED_set; \
483 /* ISO-2022-JP recommends to encode the newline character always in \
484 ASCII since this allows a context-free interpretation of the \
485 characters at the beginning of the next line. Otherwise it would \
486 have to be known whether the last line ended using ASCII or \
487 JIS X 0201. */ \
488 else if (set == JISX0201_Roman_set) \
490 unsigned char buf[2]; \
491 written = ucs4_to_jisx0201 (ch, buf); \
492 if (written != __UNKNOWN_10646_CHAR && buf[0] > 0x20 \
493 && buf[0] < 0x80) \
495 *outptr++ = buf[0]; \
496 written = 1; \
498 else \
499 written = __UNKNOWN_10646_CHAR; \
501 else if (set == JISX0201_Kana_set) \
503 unsigned char buf[2]; \
504 written = ucs4_to_jisx0201 (ch, buf); \
505 if (written != __UNKNOWN_10646_CHAR && buf[0] > 0xa0 \
506 && buf[0] < 0xe0) \
508 *outptr++ = buf[0] - 0x80; \
509 written = 1; \
511 else \
512 written = __UNKNOWN_10646_CHAR; \
514 else \
516 if (set == JISX0208_1978_set || set == JISX0208_1983_set) \
517 written = ucs4_to_jisx0208 (ch, outptr, \
518 (NEED_LENGTH_TEST \
519 ? outend - outptr : 2)); \
520 else if (set == JISX0212_set) \
521 written = ucs4_to_jisx0212 (ch, outptr, \
522 (NEED_LENGTH_TEST \
523 ? outend - outptr : 2)); \
524 else if (set == GB2312_set) \
525 written = ucs4_to_gb2312 (ch, outptr, (NEED_LENGTH_TEST \
526 ? outend - outptr : 2)); \
527 else \
529 assert (set == KSC5601_set); \
531 written = ucs4_to_ksc5601 (ch, outptr, \
532 (NEED_LENGTH_TEST \
533 ? outend - outptr : 2)); \
536 if (NEED_LENGTH_TEST && written == 0) \
538 result = __GCONV_FULL_OUTPUT; \
539 break; \
541 else if (written != __UNKNOWN_10646_CHAR) \
542 outptr += written; \
545 if (written == __UNKNOWN_10646_CHAR || written == 0) \
547 if (set2 == ISO88591_set) \
549 if (ch >= 0x80 && ch <= 0xff) \
551 *outptr++ = ESC; \
552 *outptr++ = 'N'; \
553 *outptr++ = ch & 0x7f; \
554 written = 3; \
557 else if (set2 == ISO88597_set) \
559 const struct gap *rp = from_idx; \
561 while (ch > rp->end) \
562 ++rp; \
563 if (ch >= rp->start) \
565 unsigned char res = iso88597_from_ucs4[ch - 0xa0 + rp->idx]; \
566 if (res != '\0') \
568 *outptr++ = ESC; \
569 *outptr++ = 'N'; \
570 *outptr++ = res; \
571 written = 3; \
577 if (written == __UNKNOWN_10646_CHAR || written == 0) \
579 /* Either this is an unknown character or we have to switch \
580 the currently selected character set. The character sets \
581 do not code entirely separate parts of ISO 10646 and \
582 therefore there is no single correct result. If we choose \
583 the character set to use wrong we might be end up with \
584 using yet another character set for the next character \
585 though the current and the next could be encoded with one \
586 character set. We leave this kind of optimization for \
587 later and now simply use a fixed order in which we test for \
588 availability */ \
590 if (ch <= 0x7f) \
592 /* We must encode using ASCII. First write out the \
593 escape sequence. */ \
594 if (NEED_LENGTH_TEST && outptr + 3 > outend) \
596 result = __GCONV_FULL_OUTPUT; \
597 break; \
600 *outptr++ = ESC; \
601 *outptr++ = '('; \
602 *outptr++ = 'B'; \
603 set = ASCII_set; \
605 if (NEED_LENGTH_TEST && outptr + 1 > outend) \
607 result = __GCONV_FULL_OUTPUT; \
608 break; \
610 *outptr++ = ch; \
612 /* At the beginning of a line, G2 designation is cleared. */ \
613 if (var == iso2022jp2 && ch == 0x0a) \
614 set2 = UNSPECIFIED_set; \
616 else \
618 /* Now it becomes difficult. We must search the other \
619 character sets one by one and we cannot use simple \
620 arithmetic to determine whether the character can be \
621 encoded using this set. */ \
622 size_t written; \
623 unsigned char buf[2]; \
625 written = ucs4_to_jisx0201 (ch, buf); \
626 if (written != __UNKNOWN_10646_CHAR && buf[0] < 0x80) \
628 /* We use JIS X 0201. */ \
629 if (NEED_LENGTH_TEST && outptr + 3 > outend) \
631 result = __GCONV_FULL_OUTPUT; \
632 break; \
635 *outptr++ = ESC; \
636 *outptr++ = '('; \
637 *outptr++ = 'J'; \
638 set = JISX0201_Roman_set; \
640 if (NEED_LENGTH_TEST && outptr + 1 > outend) \
642 result = __GCONV_FULL_OUTPUT; \
643 break; \
645 *outptr++ = buf[0]; \
647 else \
649 written = ucs4_to_jisx0208 (ch, buf, 2); \
650 if (written != __UNKNOWN_10646_CHAR) \
652 /* We use JIS X 0208. */ \
653 if (NEED_LENGTH_TEST && outptr + 3 > outend) \
655 result = __GCONV_FULL_OUTPUT; \
656 break; \
659 *outptr++ = ESC; \
660 *outptr++ = '$'; \
661 *outptr++ = 'B'; \
662 set = JISX0208_1983_set; \
664 if (NEED_LENGTH_TEST && outptr + 2 > outend) \
666 result = __GCONV_FULL_OUTPUT; \
667 break; \
669 *outptr++ = buf[0]; \
670 *outptr++ = buf[1]; \
672 else if (var == iso2022jp) \
674 /* We have no other choice. */ \
675 result = __GCONV_ILLEGAL_INPUT; \
676 break; \
678 else \
680 written = ucs4_to_jisx0212 (ch, buf, 2); \
681 if (written != __UNKNOWN_10646_CHAR) \
683 /* We use JIS X 0212. */ \
684 if (NEED_LENGTH_TEST && outptr + 4 > outend) \
686 result = __GCONV_FULL_OUTPUT; \
687 break; \
689 *outptr++ = ESC; \
690 *outptr++ = '$'; \
691 *outptr++ = '('; \
692 *outptr++ = 'D'; \
693 set = JISX0212_set; \
695 if (NEED_LENGTH_TEST && outptr + 2 > outend) \
697 result = __GCONV_FULL_OUTPUT; \
698 break; \
700 *outptr++ = buf[0]; \
701 *outptr++ = buf[1]; \
703 else \
705 written = ucs4_to_jisx0201 (ch, buf); \
706 if (written != __UNKNOWN_10646_CHAR \
707 && buf[0] >= 0x80) \
709 /* We use JIS X 0201. */ \
710 if (NEED_LENGTH_TEST && outptr + 3 > outend) \
712 result = __GCONV_FULL_OUTPUT; \
713 break; \
716 *outptr++ = ESC; \
717 *outptr++ = '('; \
718 *outptr++ = 'I'; \
719 set = JISX0201_Kana_set; \
721 if (NEED_LENGTH_TEST && outptr + 1 > outend) \
723 result = __GCONV_FULL_OUTPUT; \
724 break; \
726 *outptr++ = buf[0] - 0x80; \
728 else if (ch != 0xa5 && ch >= 0x80 && ch <= 0xff) \
730 /* ISO 8859-1 upper half. */ \
731 if (NEED_LENGTH_TEST && outptr + 3 > outend) \
733 result = __GCONV_FULL_OUTPUT; \
734 break; \
737 *outptr++ = ESC; \
738 *outptr++ = '.'; \
739 *outptr++ = 'A'; \
740 set2 = ISO88591_set; \
742 if (NEED_LENGTH_TEST && outptr + 3 > outend) \
744 result = __GCONV_FULL_OUTPUT; \
745 break; \
747 *outptr++ = ESC; \
748 *outptr++ = 'N'; \
749 *outptr++ = ch; \
751 else \
753 written = ucs4_to_gb2312 (ch, buf, 2); \
754 if (written != __UNKNOWN_10646_CHAR) \
756 /* We use GB 2312. */ \
757 if (NEED_LENGTH_TEST && outptr + 3 > outend) \
759 result = __GCONV_FULL_OUTPUT; \
760 break; \
763 *outptr++ = ESC; \
764 *outptr++ = '$'; \
765 *outptr++ = 'A'; \
766 set = GB2312_set; \
768 if (NEED_LENGTH_TEST && outptr + 2 > outend) \
770 result = __GCONV_FULL_OUTPUT; \
771 break; \
773 *outptr++ = buf[0]; \
774 *outptr++ = buf[1]; \
776 else \
778 written = ucs4_to_ksc5601 (ch, buf, 2); \
779 if (written != __UNKNOWN_10646_CHAR) \
781 /* We use KSC 5601. */ \
782 if (NEED_LENGTH_TEST \
783 && outptr + 4 > outend) \
785 result = __GCONV_FULL_OUTPUT; \
786 break; \
788 *outptr++ = ESC; \
789 *outptr++ = '$'; \
790 *outptr++ = '('; \
791 *outptr++ = 'C'; \
792 set = KSC5601_set; \
794 if (NEED_LENGTH_TEST \
795 && outptr + 2 > outend) \
797 result = __GCONV_FULL_OUTPUT; \
798 break; \
800 *outptr++ = buf[0]; \
801 *outptr++ = buf[1]; \
803 else \
805 const struct gap *rp = from_idx; \
806 unsigned char gch = 0; \
808 while (ch > rp->end) \
809 ++rp; \
810 if (ch >= rp->start) \
812 ch = ch - 0xa0 + rp->idx; \
813 gch = iso88597_from_ucs4[ch]; \
816 if (gch != 0) \
818 /* We use ISO 8859-7 greek. */ \
819 if (NEED_LENGTH_TEST \
820 && outptr + 3 > outend) \
822 result = __GCONV_FULL_OUTPUT; \
823 break; \
825 *outptr++ = ESC; \
826 *outptr++ = '.'; \
827 *outptr++ = 'F'; \
828 set2 = ISO88597_set; \
830 if (NEED_LENGTH_TEST \
831 && outptr + 3 > outend) \
833 result = __GCONV_FULL_OUTPUT; \
834 break; \
836 *outptr++ = ESC; \
837 *outptr++ = 'N'; \
838 *outptr++ = gch; \
840 else \
842 result = __GCONV_ILLEGAL_INPUT; \
843 break; \
854 /* Now that we wrote the output increment the input pointer. */ \
855 inptr += 4; \
857 #define EXTRA_LOOP_DECLS , enum variant var, int *setp
858 #define INIT_PARAMS int set = *setp & CURRENT_SEL_MASK; \
859 int set2 = *setp & CURRENT_ASSIGN_MASK
860 #define UPDATE_PARAMS *setp = set | set2
861 #include <iconv/loop.c>
864 /* Now define the toplevel functions. */
865 #include <iconv/skeleton.c>