Use get16, get32, put16, and put32 instead of direct casting pointer
[kopensolaris-gnu/glibc.git] / iconvdata / iso646.c
1 /* Conversion to and from the various ISO 646 CCS.
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.
5
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.
10
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.
15
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.  */
20
21 /* The implementation of the conversion which can be performed by this
22    module are not very sophisticated and not tuned at all.  There are
23    zillions of ISO 646 derivates and supporting them all in a separate
24    module is overkill since these coded character sets are hardly ever
25    used anymore (except ANSI_X3.4-1968 == ASCII, which is compatible
26    with ISO 8859-1).  The European variants are superceded by the
27    various ISO 8859-? standards and the Asian variants are embedded in
28    larger character sets.  Therefore this implementation is simply
29    here to make it possible to do the conversion if it is necessary.
30    The cost in the gconv-modules file is set to `2' and therefore
31    allows one to easily provide a tuned implementation in case this
32    proofs to be necessary.  */
33
34 #include <gconv.h>
35 #include <stdint.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 /* Definitions used in the body of the `gconv' function.  */
40 #define FROM_LOOP               from_ascii
41 #define TO_LOOP                 to_ascii
42 #define DEFINE_INIT             0
43 #define DEFINE_FINI             0
44 #define MIN_NEEDED_FROM         1
45 #define MIN_NEEDED_TO           4
46 #define FROM_DIRECTION          (dir == from_iso646)
47 #define PREPARE_LOOP \
48   enum direction dir = ((struct iso646_data *) step->__data)->dir;            \
49   enum variant var = ((struct iso646_data *) step->__data)->var;
50 #define EXTRA_LOOP_ARGS         , var
51
52
53 /* Direction of the transformation.  */
54 enum direction
55 {
56   illegal_dir,
57   to_iso646,
58   from_iso646
59 };
60
61 enum variant
62 {
63   illegal_var,
64   US,           /* ANSI_X3.4-1968 */
65   GB,           /* BS_4730 */
66   CA,           /* CSA_Z243.4-1985-1 */
67   CA2,          /* CSA_Z243.4-1985-2 */
68   DE,           /* DIN_66003 */
69   DK,           /* DS_2089 */
70   ES,           /* ES */
71   ES2,          /* ES2 */
72   CN,           /* GB_1988-80 */
73   IT,           /* IT */
74   JP,           /* JIS_C6220-1969-RO */
75   JP_OCR_B,     /* JIS_C6229-1984-B */
76   YU,           /* JUS_I.B1.002 */
77   KR,           /* KSC5636 */
78   HU,           /* MSZ_7795.3 */
79   CU,           /* NC_NC00-10 */
80   FR,           /* NF_Z_62-010 */
81   FR1,          /* NF_Z_62-010_(1973) */
82   NO,           /* NS_4551-1 */
83   NO2,          /* NS_4551-2 */
84   PT,           /* PT */
85   PT2,          /* PT2 */
86   SE,           /* SEN_850200_B */
87   SE2           /* SEN_850200_C */
88 };
89
90 static const char *names[] =
91 {
92   [US] = "ANSI_X3.4-1968//",
93   [GB] = "BS_4730//",
94   [CA] = "CSA_Z243.4-1985-1//",
95   [CA2] = "CSA_Z243.4-1985-2//",
96   [DE] = "DIN_66003//",
97   [DK] = "DS_2089//",
98   [ES] = "ES//",
99   [ES2] = "ES2//",
100   [CN] = "GB_1988-80//",
101   [IT] = "IT//",
102   [JP] = "JIS_C6220-1969-RO//",
103   [JP_OCR_B] = "JIS_C6229-1984-B//",
104   [YU] = "JUS_I.B1.002//",
105   [KR] = "KSC5636//",
106   [HU] = "MSZ_7795.3//",
107   [CU] = "NC_NC00-10//",
108   [FR] = "NF_Z_62-010//",
109   [FR1] = "NF_Z_62-010_1973//", /* Note that we don't have the parenthesis
110                                    in the name.  */
111   [NO] = "NS_4551-1//",
112   [NO2] = "NS_4551-2//",
113   [PT] = "PT//",
114   [PT2] = "PT2//",
115   [SE] = "SEN_850200_B//",
116   [SE2] = "SEN_850200_C//"
117 };
118
119 struct iso646_data
120 {
121   enum direction dir;
122   enum variant var;
123 };
124
125
126 int
127 gconv_init (struct __gconv_step *step)
128 {
129   /* Determine which direction.  */
130   struct iso646_data *new_data;
131   enum direction dir = illegal_dir;
132   enum variant var;
133   int result;
134
135   for (var = sizeof (names) / sizeof (names[0]) - 1; var > illegal_var; --var)
136     if (__strcasecmp (step->__from_name, names[var]) == 0)
137       {
138         dir = from_iso646;
139         break;
140       }
141     else if (__strcasecmp (step->__to_name, names[var]) == 0)
142       {
143         dir = to_iso646;
144         break;
145       }
146
147   result = __GCONV_NOCONV;
148   if (dir != illegal_dir)
149     {
150       new_data = (struct iso646_data *) malloc (sizeof (struct iso646_data));
151
152       result = __GCONV_NOMEM;
153       if (new_data != NULL)
154         {
155           new_data->dir = dir;
156           new_data->var = var;
157           step->__data = new_data;
158
159           if (var == from_iso646)
160             {
161               step->__min_needed_from = MIN_NEEDED_FROM;
162               step->__max_needed_from = MIN_NEEDED_FROM;
163               step->__min_needed_to = MIN_NEEDED_TO;
164               step->__max_needed_to = MIN_NEEDED_TO;
165             }
166           else
167             {
168               step->__min_needed_from = MIN_NEEDED_TO;
169               step->__max_needed_from = MIN_NEEDED_TO;
170               step->__min_needed_to = MIN_NEEDED_FROM;
171               step->__max_needed_to = MIN_NEEDED_FROM;
172             }
173
174           step->__stateful = 0;
175
176           result = __GCONV_OK;
177         }
178     }
179
180   return result;
181 }
182
183
184 void
185 gconv_end (struct __gconv_step *data)
186 {
187   free (data->__data);
188 }
189
190
191 /* First define the conversion function from ASCII to UCS4.  */
192 #define MIN_NEEDED_INPUT        MIN_NEEDED_FROM
193 #define MIN_NEEDED_OUTPUT       MIN_NEEDED_TO
194 #define LOOPFCT                 FROM_LOOP
195 #define BODY \
196   {                                                                           \
197     uint32_t ch;                                                              \
198     int failure = __GCONV_OK;                                                 \
199                                                                               \
200     ch = *inptr;                                                              \
201     switch (ch)                                                               \
202       {                                                                       \
203       case 0x23:                                                              \
204         if (var == GB || var == ES || var == IT || var == FR || var == FR1)   \
205           ch = 0xa3;                                                          \
206         else if (var == NO2)                                                  \
207           ch = 0xa7;                                                          \
208         break;                                                                \
209       case 0x24:                                                              \
210         if (var == CN)                                                        \
211           ch = 0xa5;                                                          \
212         else if (var == HU || var == CU || var == SE || var == SE2)           \
213           ch = 0xa4;                                                          \
214         break;                                                                \
215       case 0x40:                                                              \
216         if (var == CA || var == CA2 || var == FR || var == FR1)               \
217           ch = 0xe0;                                                          \
218         else if (var == DE || var == ES || var == IT || var == PT)            \
219           ch = 0xa7;                                                          \
220         else if (var == ES2)                                                  \
221           ch = 0x2022;                                                        \
222         else if (var == YU)                                                   \
223           ch = 0x17d;                                                         \
224         else if (var == HU)                                                   \
225           ch = 0xc1;                                                          \
226         else if (var == PT2)                                                  \
227           ch = 0xb4;                                                          \
228         else if (var == SE2)                                                  \
229           ch = 0xc9;                                                          \
230         break;                                                                \
231       case 0x5b:                                                              \
232         if (var == CA || var == CA2)                                          \
233           ch = 0xe2;                                                          \
234         else if (var == DE || var == SE || var == SE2)                        \
235           ch = 0xc4;                                                          \
236         else if (var == DK || var == NO || var == NO2)                        \
237           ch = 0xc6;                                                          \
238         else if (var == ES || var == ES2 || var == CU)                        \
239           ch = 0xa1;                                                          \
240         else if (var == IT || var == FR || var == FR1)                        \
241           ch = 0xb0;                                                          \
242         else if (var == JP_OCR_B)                                             \
243           ch = 0x2329;                                                        \
244         else if (var == YU)                                                   \
245           ch = 0x160;                                                         \
246         else if (var == HU)                                                   \
247           ch = 0xc9;                                                          \
248         else if (var == PT || var == PT2)                                     \
249           ch = 0xc3;                                                          \
250         break;                                                                \
251       case 0x5c:                                                              \
252         if (var == CA || var == CA2 || var == IT || var == FR || var == FR1)  \
253           ch = 0xe7;                                                          \
254         else if (var == DE || var == HU || var == SE || var == SE2)           \
255           ch = 0xd6;                                                          \
256         else if (var == DK || var == NO || var == NO2)                        \
257           ch = 0xd8;                                                          \
258         else if (var == ES || var == ES2 || var == CU)                        \
259           ch = 0xd1;                                                          \
260         else if (var == JP || var == JP_OCR_B)                                \
261           ch = 0xa5;                                                          \
262         else if (var == YU)                                                   \
263           ch = 0x110;                                                         \
264         else if (var == KR)                                                   \
265           ch = 0x20a9;                                                        \
266         else if (var == PT || var == PT2)                                     \
267           ch = 0xc7;                                                          \
268         break;                                                                \
269       case 0x5d:                                                              \
270         if (var == CA || var == CA2)                                          \
271           ch = 0xea;                                                          \
272         else if (var == DE || var == HU)                                      \
273           ch = 0xdc;                                                          \
274         else if (var == DK || var == NO || var == NO2 || var == SE            \
275                  || var == SE2)                                               \
276           ch = 0xc5;                                                          \
277         else if (var == ES)                                                   \
278           ch = 0xbf;                                                          \
279         else if (var == ES2)                                                  \
280           ch = 0xc7;                                                          \
281         else if (var == IT)                                                   \
282           ch = 0xe9;                                                          \
283         else if (var == JP_OCR_B)                                             \
284           ch = 0x232a;                                                        \
285         else if (var == YU)                                                   \
286           ch = 0x106;                                                         \
287         else if (var == FR || var == FR1)                                     \
288           ch = 0xa7;                                                          \
289         else if (var == PT || var == PT2)                                     \
290           ch = 0xd5;                                                          \
291         break;                                                                \
292       case 0x5e:                                                              \
293         if (var == CA)                                                        \
294           ch = 0xee;                                                          \
295         else if (var == CA2)                                                  \
296           ch = 0xc9;                                                          \
297         else if (var == ES2 || var == CU)                                     \
298           ch = 0xbf;                                                          \
299         else if (var == YU)                                                   \
300           ch = 0x10c;                                                         \
301         else if (var == SE2)                                                  \
302           ch = 0xdc;                                                          \
303         break;                                                                \
304       case 0x60:                                                              \
305         if (var == CA || var == CA2)                                          \
306           ch = 0xf4;                                                          \
307         else if (var == IT)                                                   \
308           ch = 0xf9;                                                          \
309         else if (var == JP_OCR_B)                                             \
310           /* Illegal character.  */                                           \
311           failure = __GCONV_ILLEGAL_INPUT;                                    \
312         else if (var == YU)                                                   \
313           ch = 0x17e;                                                         \
314         else if (var == HU)                                                   \
315           ch = 0xe1;                                                          \
316         else if (var == FR)                                                   \
317           ch = 0xb5;                                                          \
318         else if (var == SE2)                                                  \
319           ch = 0xe9;                                                          \
320         break;                                                                \
321       case 0x7b:                                                              \
322         if (var == CA || var == CA2 || var == HU || var == FR || var == FR1)  \
323           ch = 0xe9;                                                          \
324         else if (var == DE || var == SE || var == SE2)                        \
325           ch = 0xe4;                                                          \
326         else if (var == DK || var == NO || var == NO2)                        \
327           ch = 0xe6;                                                          \
328         else if (var == ES)                                                   \
329           ch = 0xb0;                                                          \
330         else if (var == ES2 || var == CU)                                     \
331           ch = 0xb4;                                                          \
332         else if (var == IT)                                                   \
333           ch = 0xe0;                                                          \
334         else if (var == YU)                                                   \
335           ch = 0x161;                                                         \
336         else if (var == PT || var == PT2)                                     \
337           ch = 0xe3;                                                          \
338         break;                                                                \
339       case 0x7c:                                                              \
340         if (var == CA || var == CA2 || var == FR || var == FR1)               \
341           ch = 0xf9;                                                          \
342         else if (var == DE || var == HU || var == SE || var == SE2)           \
343           ch = 0xf6;                                                          \
344         else if (var == DK || var == NO || var == NO2)                        \
345           ch = 0xf8;                                                          \
346         else if (var == ES || var == ES2 || var == CU)                        \
347           ch = 0xf1;                                                          \
348         else if (var == IT)                                                   \
349           ch = 0xf2;                                                          \
350         else if (var == YU)                                                   \
351           ch = 0x111;                                                         \
352         else if (var == PT || var == PT2)                                     \
353           ch = 0xe7;                                                          \
354         break;                                                                \
355       case 0x7d:                                                              \
356         if (var == CA || var == CA2 || var == IT || var == FR || var == FR1)  \
357           ch = 0xe8;                                                          \
358         else if (var == DE || var == HU)                                      \
359           ch = 0xfc;                                                          \
360         else if (var == DK || var == NO || var == NO2 || var == SE            \
361                  || var == SE2)                                               \
362           ch = 0xe5;                                                          \
363         else if (var == ES || var == ES2)                                     \
364           ch = 0xe7;                                                          \
365         else if (var == YU)                                                   \
366           ch = 0x107;                                                         \
367         else if (var == CU)                                                   \
368           ch = 0x5b;                                                          \
369         else if (var == PT || var == PT2)                                     \
370           ch = 0xf5;                                                          \
371         break;                                                                \
372       case 0x7e:                                                              \
373         if (var == GB || var == CN || var == JP || var == NO || var == SE)    \
374           ch = 0x203e;                                                        \
375         else if (var == CA || var == CA2)                                     \
376           ch = 0xfb;                                                          \
377         else if (var == DE)                                                   \
378           ch = 0xdf;                                                          \
379         else if (var == ES2 || var == CU || var == FR || var == FR1)          \
380           ch = 0xa8;                                                          \
381         else if (var == IT)                                                   \
382           ch = 0xec;                                                          \
383         else if (var == JP_OCR_B)                                             \
384           /* Illegal character.  */                                           \
385           failure = __GCONV_ILLEGAL_INPUT;                                    \
386         else if (var == YU)                                                   \
387           ch = 0x10d;                                                         \
388         else if (var == HU)                                                   \
389           ch = 0x2dd;                                                         \
390         else if (var == NO2)                                                  \
391           ch = 0x7c;                                                          \
392         else if (var == PT)                                                   \
393           ch = 0xb0;                                                          \
394         else if (var == SE2)                                                  \
395           ch = 0xfc;                                                          \
396         break;                                                                \
397       default:                                                                \
398         break;                                                                \
399       case 0x80 ... 0xff:                                                     \
400         /* Illegal character.  */                                             \
401         failure = __GCONV_ILLEGAL_INPUT;                                      \
402         break;                                                                \
403       }                                                                       \
404                                                                               \
405     /* Hopefully gcc can recognize that the following `if' is only true       \
406        when we reach the default case in the `switch' statement.  */          \
407     if (failure == __GCONV_ILLEGAL_INPUT)                                     \
408       {                                                                       \
409         /* Exit the loop with an error.  */                                   \
410         result = failure;                                                     \
411         break;                                                                \
412       }                                                                       \
413     put32 (outptr, ch);                                                       \
414     outptr += 4;                                                              \
415     ++inptr;                                                                  \
416   }
417 #define EXTRA_LOOP_DECLS        , enum variant var
418 #include <iconv/loop.c>
419
420
421 /* Next, define the other direction.  */
422 #define MIN_NEEDED_INPUT        MIN_NEEDED_TO
423 #define MIN_NEEDED_OUTPUT       MIN_NEEDED_FROM
424 #define LOOPFCT                 TO_LOOP
425 #define BODY \
426   {                                                                           \
427     unsigned char ch;                                                         \
428     int failure = __GCONV_OK;                                                 \
429                                                                               \
430     ch = get32 (inptr);                                                       \
431     switch (*((uint32_t *) inptr))                                            \
432       {                                                                       \
433       case 0x23:                                                              \
434         if (var == GB || var == ES || var == IT || var == FR || var == FR1    \
435             || var == NO2)                                                    \
436           failure = __GCONV_ILLEGAL_INPUT;                                    \
437         break;                                                                \
438       case 0x24:                                                              \
439         if (var == CN || var == HU || var == CU || var == SE || var == SE2)   \
440           failure = __GCONV_ILLEGAL_INPUT;                                    \
441         break;                                                                \
442       case 0x40:                                                              \
443         if (var == CA || var == CA2 || var == DE || var == ES || var == ES2   \
444             || var == IT || var == YU || var == HU || var == FR || var == FR1 \
445             || var == PT || var == PT2 || var == SE2)                         \
446           failure = __GCONV_ILLEGAL_INPUT;                                    \
447         break;                                                                \
448       case 0x5b:                                                              \
449         if (var == CA || var == CA2 || var == DE || var == DK || var == ES    \
450             || var == ES2 || var == IT || var == JP_OCR_B || var == YU        \
451             || var == HU || var == FR || var == FR1 || var == NO              \
452             || var == NO2 || var == PT || var == PT2 || var == SE             \
453             || var == SE2)                                                    \
454           failure = __GCONV_ILLEGAL_INPUT;                                    \
455         else if (var == CU)                                                   \
456           ch = 0x7d;                                                          \
457         break;                                                                \
458       case 0x5c:                                                              \
459         if (var == CA || var == CA2 || var == DE || var == DK || var == ES    \
460             || var == ES2 || var == IT || var == JP || var == JP_OCR_B        \
461             || var == YU || var == KR || var == HU || var == CU || var == FR  \
462             || var == FR1 || var == NO || var == NO2 || var == PT             \
463             || var == PT2 || var == SE || var == SE2)                         \
464           failure = __GCONV_ILLEGAL_INPUT;                                    \
465         break;                                                                \
466       case 0x5d:                                                              \
467         if (var == CA || var == CA2 || var == DE || var == DK || var == ES    \
468             || var == ES2 || var == IT || var == JP_OCR_B || var == YU        \
469             || var == HU || var == FR || var == FR1 || var == NO              \
470             || var == NO2 || var == PT || var == PT2 || var == SE             \
471             || var == SE2)                                                    \
472           failure = __GCONV_ILLEGAL_INPUT;                                    \
473         break;                                                                \
474       case 0x5e:                                                              \
475         if (var == CA || var == CA2 || var == ES2 || var == YU || var == CU   \
476             || var == SE2)                                                    \
477           failure = __GCONV_ILLEGAL_INPUT;                                    \
478         break;                                                                \
479       case 0x60:                                                              \
480         if (var == CA || var == CA2 || var == IT || var == JP_OCR_B           \
481             || var == YU || var == HU || var == FR || var == SE2)             \
482           failure = __GCONV_ILLEGAL_INPUT;                                    \
483         break;                                                                \
484       case 0x7b:                                                              \
485         if (var == CA || var == CA2 || var == DE || var == DK || var == ES    \
486             || var == ES2 || var == IT || var == YU || var == HU              \
487             || var == CU || var == FR || var == FR1 || var == NO              \
488             || var == NO2 || var == PT || var == PT2 || var == SE             \
489             || var == SE2)                                                    \
490           failure = __GCONV_ILLEGAL_INPUT;                                    \
491         break;                                                                \
492       case 0x7c:                                                              \
493         if (var == CA || var == CA2 || var == DE || var == DK || var == ES    \
494             || var == ES2 || var == IT || var == YU || var == HU || var == CU \
495             || var == FR || var == FR1 || var == NO || var == PT              \
496             || var == PT2 || var == SE || var == SE2)                         \
497           failure = __GCONV_ILLEGAL_INPUT;                                    \
498         else if (var == NO2)                                                  \
499           ch = 0x7e;                                                          \
500         break;                                                                \
501       case 0x7d:                                                              \
502         if (var == CA || var == CA2 || var == DE || var == DK || var == ES    \
503             || var == ES2 || var == IT || var == YU || var == HU || var == CU \
504             || var == FR || var == FR1 || var == NO || var == NO2             \
505             || var == PT || var == PT2 || var == SE || var == SE2)            \
506           failure = __GCONV_ILLEGAL_INPUT;                                    \
507         break;                                                                \
508       case 0x7e:                                                              \
509         if (var == GB || var == CA || var == CA2 || var == DE || var == ES2   \
510             || var == CN || var == IT || var == JP || var == JP_OCR_B         \
511             || var == YU || var == HU || var == CU || var == FR || var == FR1 \
512             || var == NO || var == NO2 || var == PT || var == SE              \
513             || var == SE2)                                                    \
514           failure = __GCONV_ILLEGAL_INPUT;                                    \
515         break;                                                                \
516       case 0xa1:                                                              \
517         if (var != ES && var != ES2 && var != CU)                             \
518           failure = __GCONV_ILLEGAL_INPUT;                                    \
519         ch = 0x5b;                                                            \
520         break;                                                                \
521       case 0xa3:                                                              \
522         if (var != GB && var != ES && var != IT && var != FR && var != FR1)   \
523           failure = __GCONV_ILLEGAL_INPUT;                                    \
524         ch = 0x23;                                                            \
525         break;                                                                \
526       case 0xa4:                                                              \
527         if (var != HU && var != CU && var != SE && var != SE2)                \
528           failure = __GCONV_ILLEGAL_INPUT;                                    \
529         ch = 0x24;                                                            \
530         break;                                                                \
531       case 0xa5:                                                              \
532         if (var == CN)                                                        \
533           ch = 0x24;                                                          \
534         else if (var == JP || var == JP_OCR_B)                                \
535           ch = 0x5c;                                                          \
536         else                                                                  \
537           failure = __GCONV_ILLEGAL_INPUT;                                    \
538         break;                                                                \
539       case 0xa7:                                                              \
540         if (var == DE || var == ES || var == IT || var == PT)                 \
541           ch = 0x40;                                                          \
542         else if (var == FR || var == FR1)                                     \
543           ch = 0x5d;                                                          \
544         else if (var == NO2)                                                  \
545           ch = 0x23;                                                          \
546         else                                                                  \
547           failure = __GCONV_ILLEGAL_INPUT;                                    \
548         break;                                                                \
549       case 0xa8:                                                              \
550         if (var != ES2 && var != CU && var != FR && var != FR1)               \
551           failure = __GCONV_ILLEGAL_INPUT;                                    \
552         ch = 0x7e;                                                            \
553         break;                                                                \
554       case 0xb0:                                                              \
555         if (var == ES)                                                        \
556           ch = 0x7b;                                                          \
557         else if (var == IT || var == FR || var == FR1)                        \
558           ch = 0x5b;                                                          \
559         else if (var == PT)                                                   \
560           ch = 0x7e;                                                          \
561         else                                                                  \
562           failure = __GCONV_ILLEGAL_INPUT;                                    \
563         break;                                                                \
564       case 0xb4:                                                              \
565         if (var == ES2 || var == CU)                                          \
566           ch = 0x7b;                                                          \
567         else if (var == PT2)                                                  \
568           ch = 0x40;                                                          \
569         else                                                                  \
570           failure = __GCONV_ILLEGAL_INPUT;                                    \
571         break;                                                                \
572       case 0xb5:                                                              \
573         if (var != FR)                                                        \
574           failure = __GCONV_ILLEGAL_INPUT;                                    \
575         ch = 0x60;                                                            \
576         break;                                                                \
577       case 0xbf:                                                              \
578         if (var == ES)                                                        \
579           ch = 0x5d;                                                          \
580         else if (var == ES2 || var == CU)                                     \
581           ch = 0x5e;                                                          \
582         else                                                                  \
583           failure = __GCONV_ILLEGAL_INPUT;                                    \
584         break;                                                                \
585       case 0xc1:                                                              \
586         if (var != HU)                                                        \
587           failure = __GCONV_ILLEGAL_INPUT;                                    \
588         ch = 0x40;                                                            \
589         break;                                                                \
590       case 0xc3:                                                              \
591         if (var != PT && var != PT2)                                          \
592           failure = __GCONV_ILLEGAL_INPUT;                                    \
593         ch = 0x5b;                                                            \
594         break;                                                                \
595       case 0xc4:                                                              \
596         if (var != DE && var != SE && var != SE2)                             \
597           failure = __GCONV_ILLEGAL_INPUT;                                    \
598         ch = 0x5b;                                                            \
599         break;                                                                \
600       case 0xc5:                                                              \
601         if (var != DK && var != NO && var != NO2 && var != SE && var != SE2)  \
602           failure = __GCONV_ILLEGAL_INPUT;                                    \
603         ch = 0x5d;                                                            \
604         break;                                                                \
605       case 0xc6:                                                              \
606         if (var != DK && var != NO && var != NO2)                             \
607           failure = __GCONV_ILLEGAL_INPUT;                                    \
608         ch = 0x5b;                                                            \
609         break;                                                                \
610       case 0xc7:                                                              \
611         if (var == ES2)                                                       \
612           ch = 0x5d;                                                          \
613         else if (var == PT || var == PT2)                                     \
614           ch = 0x5c;                                                          \
615         else                                                                  \
616           failure = __GCONV_ILLEGAL_INPUT;                                    \
617         break;                                                                \
618       case 0xc9:                                                              \
619         if (var == CA2)                                                       \
620           ch = 0x5e;                                                          \
621         else if (var == HU)                                                   \
622           ch = 0x5b;                                                          \
623         else if (var == SE2)                                                  \
624           ch = 0x40;                                                          \
625         else                                                                  \
626           failure = __GCONV_ILLEGAL_INPUT;                                    \
627         break;                                                                \
628       case 0xd1:                                                              \
629         if (var != ES && var != ES2 && var != CU)                             \
630           failure = __GCONV_ILLEGAL_INPUT;                                    \
631         ch = 0x5c;                                                            \
632         break;                                                                \
633       case 0xd5:                                                              \
634         if (var != PT && var != PT2)                                          \
635           failure = __GCONV_ILLEGAL_INPUT;                                    \
636         ch = 0x5d;                                                            \
637         break;                                                                \
638       case 0xd6:                                                              \
639         if (var != DE && var != HU && var != SE && var != SE2)                \
640           failure = __GCONV_ILLEGAL_INPUT;                                    \
641         ch = 0x5c;                                                            \
642         break;                                                                \
643       case 0xd8:                                                              \
644         if (var != DK && var != NO && var != NO2)                             \
645           failure = __GCONV_ILLEGAL_INPUT;                                    \
646         ch = 0x5c;                                                            \
647         break;                                                                \
648       case 0xdc:                                                              \
649         if (var == DE || var == HU)                                           \
650           ch = 0x5d;                                                          \
651         else if (var == SE2)                                                  \
652           ch = 0x5e;                                                          \
653         else                                                                  \
654           failure = __GCONV_ILLEGAL_INPUT;                                    \
655         break;                                                                \
656       case 0xdf:                                                              \
657         if (var != DE)                                                        \
658           failure = __GCONV_ILLEGAL_INPUT;                                    \
659         ch = 0x7e;                                                            \
660         break;                                                                \
661       case 0xe0:                                                              \
662         if (var == CA || var == CA2 || var == FR || var == FR1)               \
663           ch = 0x40;                                                          \
664         else if (var == IT)                                                   \
665           ch = 0x7b;                                                          \
666         else                                                                  \
667           failure = __GCONV_ILLEGAL_INPUT;                                    \
668         break;                                                                \
669       case 0xe1:                                                              \
670         if (var != HU)                                                        \
671           failure = __GCONV_ILLEGAL_INPUT;                                    \
672         ch = 0x60;                                                            \
673         break;                                                                \
674       case 0xe2:                                                              \
675         if (var != CA && var != CA2)                                          \
676           failure = __GCONV_ILLEGAL_INPUT;                                    \
677         ch = 0x5b;                                                            \
678         break;                                                                \
679       case 0xe3:                                                              \
680         if (var != PT && var != PT2)                                          \
681           failure = __GCONV_ILLEGAL_INPUT;                                    \
682         ch = 0x7b;                                                            \
683         break;                                                                \
684       case 0xe4:                                                              \
685         if (var != DE && var != SE && var != SE2)                             \
686           failure = __GCONV_ILLEGAL_INPUT;                                    \
687         ch = 0x7b;                                                            \
688         break;                                                                \
689       case 0xe5:                                                              \
690         if (var != DK && var != NO && var != NO2 && var != SE && var != SE2)  \
691           failure = __GCONV_ILLEGAL_INPUT;                                    \
692         ch = 0x7d;                                                            \
693         break;                                                                \
694       case 0xe6:                                                              \
695         if (var != DK && var != NO && var != NO2)                             \
696           failure = __GCONV_ILLEGAL_INPUT;                                    \
697         ch = 0x7b;                                                            \
698         break;                                                                \
699       case 0xe7:                                                              \
700         if (var == CA || var == CA2 || var == IT || var == FR || var == FR1)  \
701           ch = 0x5c;                                                          \
702         else if (var == ES || var == ES2)                                     \
703           ch = 0x7d;                                                          \
704         else if (var == PT || var == PT2)                                     \
705           ch = 0x7c;                                                          \
706         else                                                                  \
707           failure = __GCONV_ILLEGAL_INPUT;                                    \
708         break;                                                                \
709       case 0xe8:                                                              \
710         if (var != CA && var != CA2 && var != IT && var != FR && var != FR1)  \
711           failure = __GCONV_ILLEGAL_INPUT;                                    \
712         ch = 0x7d;                                                            \
713         break;                                                                \
714       case 0xe9:                                                              \
715         if (var == CA || var == CA2 || var == HU || var == FR || var == FR1)  \
716           ch = 0x7b;                                                          \
717         else if (var == IT)                                                   \
718           ch = 0x5d;                                                          \
719         else if (var == SE2)                                                  \
720           ch = 0x60;                                                          \
721         else                                                                  \
722           failure = __GCONV_ILLEGAL_INPUT;                                    \
723         break;                                                                \
724       case 0xea:                                                              \
725         if (var != CA && var != CA2)                                          \
726           failure = __GCONV_ILLEGAL_INPUT;                                    \
727         ch = 0x5d;                                                            \
728         break;                                                                \
729       case 0xec:                                                              \
730         if (var != IT)                                                        \
731           failure = __GCONV_ILLEGAL_INPUT;                                    \
732         ch = 0x7e;                                                            \
733         break;                                                                \
734       case 0xee:                                                              \
735         if (var != CA)                                                        \
736           failure = __GCONV_ILLEGAL_INPUT;                                    \
737         ch = 0x5e;                                                            \
738         break;                                                                \
739       case 0xf1:                                                              \
740         if (var != ES && var != ES2 && var != CU)                             \
741           failure = __GCONV_ILLEGAL_INPUT;                                    \
742         ch = 0x7c;                                                            \
743         break;                                                                \
744       case 0xf2:                                                              \
745         if (var != IT)                                                        \
746           failure = __GCONV_ILLEGAL_INPUT;                                    \
747         ch = 0x7c;                                                            \
748         break;                                                                \
749       case 0xf4:                                                              \
750         if (var != CA && var != CA2)                                          \
751           failure = __GCONV_ILLEGAL_INPUT;                                    \
752         ch = 0x60;                                                            \
753         break;                                                                \
754       case 0xf5:                                                              \
755         if (var != PT && var != PT2)                                          \
756           failure = __GCONV_ILLEGAL_INPUT;                                    \
757         ch = 0x7d;                                                            \
758         break;                                                                \
759       case 0xf6:                                                              \
760         if (var != DE && var != HU && var != SE && var != SE2)                \
761           failure = __GCONV_ILLEGAL_INPUT;                                    \
762         ch = 0x7c;                                                            \
763         break;                                                                \
764       case 0xf8:                                                              \
765         if (var != DK && var != NO && var != NO2)                             \
766           failure = __GCONV_ILLEGAL_INPUT;                                    \
767         ch = 0x7c;                                                            \
768         break;                                                                \
769       case 0xf9:                                                              \
770         if (var == CA || var == CA2 || var == FR || var == FR1)               \
771           ch = 0x7c;                                                          \
772         else if (var == IT)                                                   \
773           ch = 0x60;                                                          \
774         else                                                                  \
775           failure = __GCONV_ILLEGAL_INPUT;                                    \
776         break;                                                                \
777       case 0xfb:                                                              \
778         if (var != CA && var != CA2)                                          \
779           failure = __GCONV_ILLEGAL_INPUT;                                    \
780         ch = 0x7e;                                                            \
781         break;                                                                \
782       case 0xfc:                                                              \
783         if (var == DE || var == HU)                                           \
784           ch = 0x7d;                                                          \
785         else if (var == SE2)                                                  \
786           ch = 0x7e;                                                          \
787         else                                                                  \
788           failure = __GCONV_ILLEGAL_INPUT;                                    \
789         break;                                                                \
790       case 0x160:                                                             \
791         if (var != YU)                                                        \
792           failure = __GCONV_ILLEGAL_INPUT;                                    \
793         ch = 0x5b;                                                            \
794         break;                                                                \
795       case 0x106:                                                             \
796         if (var != YU)                                                        \
797           failure = __GCONV_ILLEGAL_INPUT;                                    \
798         ch = 0x5d;                                                            \
799         break;                                                                \
800       case 0x107:                                                             \
801         if (var != YU)                                                        \
802           failure = __GCONV_ILLEGAL_INPUT;                                    \
803         ch = 0x7d;                                                            \
804         break;                                                                \
805       case 0x10c:                                                             \
806         if (var != YU)                                                        \
807           failure = __GCONV_ILLEGAL_INPUT;                                    \
808         ch = 0x5e;                                                            \
809         break;                                                                \
810       case 0x10d:                                                             \
811         if (var != YU)                                                        \
812           failure = __GCONV_ILLEGAL_INPUT;                                    \
813         ch = 0x7e;                                                            \
814         break;                                                                \
815       case 0x110:                                                             \
816         if (var != YU)                                                        \
817           failure = __GCONV_ILLEGAL_INPUT;                                    \
818         ch = 0x5c;                                                            \
819         break;                                                                \
820       case 0x111:                                                             \
821         if (var != YU)                                                        \
822           failure = __GCONV_ILLEGAL_INPUT;                                    \
823         ch = 0x7c;                                                            \
824         break;                                                                \
825       case 0x161:                                                             \
826         if (var != YU)                                                        \
827           failure = __GCONV_ILLEGAL_INPUT;                                    \
828         ch = 0x7b;                                                            \
829         break;                                                                \
830       case 0x17d:                                                             \
831         if (var != YU)                                                        \
832           failure = __GCONV_ILLEGAL_INPUT;                                    \
833         ch = 0x40;                                                            \
834         break;                                                                \
835       case 0x17e:                                                             \
836         if (var != YU)                                                        \
837           failure = __GCONV_ILLEGAL_INPUT;                                    \
838         ch = 0x60;                                                            \
839         break;                                                                \
840       case 0x2dd:                                                             \
841         if (var != HU)                                                        \
842           failure = __GCONV_ILLEGAL_INPUT;                                    \
843         ch = 0x7e;                                                            \
844         break;                                                                \
845       case 0x2022:                                                            \
846         if (var != ES2)                                                       \
847           failure = __GCONV_ILLEGAL_INPUT;                                    \
848         ch = 0x40;                                                            \
849         break;                                                                \
850       case 0x203e:                                                            \
851         if (var != GB && var != CN && var != JP && var != NO && var != SE)    \
852           failure = __GCONV_ILLEGAL_INPUT;                                    \
853         ch = 0x7e;                                                            \
854         break;                                                                \
855       case 0x20a9:                                                            \
856         if (var != KR)                                                        \
857           failure = __GCONV_ILLEGAL_INPUT;                                    \
858         ch = 0x5c;                                                            \
859         break;                                                                \
860       case 0x2329:                                                            \
861         if (var != JP_OCR_B)                                                  \
862           failure = __GCONV_ILLEGAL_INPUT;                                    \
863         ch = 0x5b;                                                            \
864         break;                                                                \
865       case 0x232a:                                                            \
866         if (var != JP_OCR_B)                                                  \
867           failure = __GCONV_ILLEGAL_INPUT;                                    \
868         ch = 0x5d;                                                            \
869         break;                                                                \
870       default:                                                                \
871         if (*((uint32_t *) inptr) > 0x7f)                                     \
872           failure = __GCONV_ILLEGAL_INPUT;                                    \
873         break;                                                                \
874       }                                                                       \
875                                                                               \
876     if (failure == __GCONV_ILLEGAL_INPUT)                                     \
877       {                                                                       \
878         /* Exit the loop with an error.  */                                   \
879         result = failure;                                                     \
880         break;                                                                \
881       }                                                                       \
882     *outptr++ = (unsigned char) ch;                                           \
883     inptr += 4;                                                               \
884   }
885 #define EXTRA_LOOP_DECLS        , enum variant var
886 #include <iconv/loop.c>
887
888
889 /* Now define the toplevel functions.  */
890 #include <iconv/skeleton.c>