Update.
[glibc.git] / iconvdata / iso646.c
blob9888208122e82358ab5163c08037ec41ea7b26c4
1 /* Conversion to and from the various ISO 646 CCS.
2 Copyright (C) 1998 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 /* 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. */
34 #include <gconv.h>
35 #include <stdint.h>
36 #include <stdlib.h>
37 #include <string.h>
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
53 /* Direction of the transformation. */
54 enum direction
56 illegal_dir,
57 to_iso646,
58 from_iso646
61 enum variant
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 */
90 static const char *names[] =
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)//",
110 [NO] = "NS_4551-1//",
111 [NO2] = "NS_4551-2//",
112 [PT] = "PT//",
113 [PT2] = "PT2//",
114 [SE] = "SEN_850200_B//",
115 [SE2] = "SEN_850200_C//"
118 struct iso646_data
120 enum direction dir;
121 enum variant var;
126 gconv_init (struct gconv_step *step)
128 /* Determine which direction. */
129 struct iso646_data *new_data;
130 enum direction dir = illegal_dir;
131 enum variant var;
132 int result;
134 for (var = sizeof (names) / sizeof (names[0]) - 1; var > illegal_var; --var)
135 if (__strcasecmp (step->from_name, names[var]) == 0)
137 dir = from_iso646;
138 break;
140 else if (__strcasecmp (step->to_name, names[var]) == 0)
142 dir = to_iso646;
143 break;
146 result = GCONV_NOCONV;
147 if (dir != illegal_dir
148 && ((new_data
149 = (struct iso646_data *) malloc (sizeof (struct iso646_data)))
150 != NULL))
152 new_data->dir = dir;
153 new_data->var = var;
154 step->data = new_data;
156 if (var == from_iso646)
158 step->min_needed_from = MIN_NEEDED_FROM;
159 step->max_needed_from = MIN_NEEDED_FROM;
160 step->min_needed_to = MIN_NEEDED_TO;
161 step->max_needed_to = MIN_NEEDED_TO;
163 else
165 step->min_needed_from = MIN_NEEDED_TO;
166 step->max_needed_from = MIN_NEEDED_TO;
167 step->min_needed_to = MIN_NEEDED_FROM;
168 step->max_needed_to = MIN_NEEDED_FROM;
171 step->stateful = 0;
173 result = GCONV_OK;
176 return result;
180 void
181 gconv_end (struct gconv_step *data)
183 free (data->data);
187 /* First define the conversion function from ASCII to UCS4. */
188 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
189 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
190 #define LOOPFCT FROM_LOOP
191 #define BODY \
193 uint32_t ch; \
194 int failure = GCONV_OK; \
196 ch = *inptr; \
197 switch (ch) \
199 case 0x23: \
200 if (var == GB || var == ES || var == IT || var == FR || var == FR1) \
201 ch = 0xa3; \
202 else if (var == NO2) \
203 ch = 0xa7; \
204 break; \
205 case 0x24: \
206 if (var == CN) \
207 ch = 0xa5; \
208 else if (var == HU || var == CU || var == SE || var == SE2) \
209 ch = 0xa4; \
210 break; \
211 case 0x40: \
212 if (var == CA || var == CA2 || var == FR || var == FR1) \
213 ch = 0xe0; \
214 else if (var == DE || var == ES || var == IT || var == PT) \
215 ch = 0xa7; \
216 else if (var == ES2) \
217 ch = 0x2022; \
218 else if (var == YU) \
219 ch = 0x17d; \
220 else if (var == HU) \
221 ch = 0xc1; \
222 else if (var == PT2) \
223 ch = 0xb4; \
224 else if (var == SE2) \
225 ch = 0xc9; \
226 break; \
227 case 0x5b: \
228 if (var == CA || var == CA2) \
229 ch = 0xe2; \
230 else if (var == DE || var == SE || var == SE2) \
231 ch = 0xc4; \
232 else if (var == DK || var == NO || var == NO2) \
233 ch = 0xc6; \
234 else if (var == ES || var == ES2 || var == CU) \
235 ch = 0xa1; \
236 else if (var == IT || var == FR || var == FR1) \
237 ch = 0xb0; \
238 else if (var == JP_OCR_B) \
239 ch = 0x2329; \
240 else if (var == YU) \
241 ch = 0x160; \
242 else if (var == HU) \
243 ch = 0xc9; \
244 else if (var == PT || var == PT2) \
245 ch = 0xc3; \
246 break; \
247 case 0x5c: \
248 if (var == CA || var == CA2 || var == IT || var == FR || var == FR1) \
249 ch = 0xe7; \
250 else if (var == DE || var == HU || var == SE || var == SE2) \
251 ch = 0xd6; \
252 else if (var == DK || var == NO || var == NO2) \
253 ch = 0xd8; \
254 else if (var == ES || var == ES2 || var == CU) \
255 ch = 0xd1; \
256 else if (var == JP || var == JP_OCR_B) \
257 ch = 0xa5; \
258 else if (var == YU) \
259 ch = 0x110; \
260 else if (var == KR) \
261 ch = 0x20a9; \
262 else if (var == PT || var == PT2) \
263 ch = 0xc7; \
264 break; \
265 case 0x5d: \
266 if (var == CA || var == CA2) \
267 ch = 0xea; \
268 else if (var == DE || var == HU) \
269 ch = 0xdc; \
270 else if (var == DK || var == NO || var == NO2 || var == SE \
271 || var == SE2) \
272 ch = 0xc5; \
273 else if (var == ES) \
274 ch = 0xbf; \
275 else if (var == ES2) \
276 ch = 0xc7; \
277 else if (var == IT) \
278 ch = 0xe9; \
279 else if (var == JP_OCR_B) \
280 ch = 0x232a; \
281 else if (var == YU) \
282 ch = 0x106; \
283 else if (var == FR || var == FR1) \
284 ch = 0xa7; \
285 else if (var == PT || var == PT2) \
286 ch = 0xd5; \
287 break; \
288 case 0x5e: \
289 if (var == CA) \
290 ch = 0xee; \
291 else if (var == CA2) \
292 ch = 0xc9; \
293 else if (var == ES2 || var == CU) \
294 ch = 0xbf; \
295 else if (var == YU) \
296 ch = 0x10c; \
297 else if (var == SE2) \
298 ch = 0xdc; \
299 break; \
300 case 0x60: \
301 if (var == CA || var == CA2) \
302 ch = 0xf4; \
303 else if (var == IT) \
304 ch = 0xf9; \
305 else if (var == JP_OCR_B) \
306 /* Illegal character. */ \
307 failure = GCONV_ILLEGAL_INPUT; \
308 else if (var == YU) \
309 ch = 0x17e; \
310 else if (var == HU) \
311 ch = 0xe1; \
312 else if (var == FR) \
313 ch = 0xb5; \
314 else if (var == SE2) \
315 ch = 0xe9; \
316 break; \
317 case 0x7b: \
318 if (var == CA || var == CA2 || var == HU || var == FR || var == FR1) \
319 ch = 0xe9; \
320 else if (var == DE || var == SE || var == SE2) \
321 ch = 0xe4; \
322 else if (var == DK || var == NO || var == NO2) \
323 ch = 0xe6; \
324 else if (var == ES) \
325 ch = 0xb0; \
326 else if (var == ES2 || var == CU) \
327 ch = 0xb4; \
328 else if (var == IT) \
329 ch = 0xe0; \
330 else if (var == YU) \
331 ch = 0x161; \
332 else if (var == PT || var == PT2) \
333 ch = 0xe3; \
334 break; \
335 case 0x7c: \
336 if (var == CA || var == CA2 || var == FR || var == FR1) \
337 ch = 0xf9; \
338 else if (var == DE || var == HU || var == SE || var == SE2) \
339 ch = 0xf6; \
340 else if (var == DK || var == NO || var == NO2) \
341 ch = 0xf8; \
342 else if (var == ES || var == ES2 || var == CU) \
343 ch = 0xf1; \
344 else if (var == IT) \
345 ch = 0xf2; \
346 else if (var == YU) \
347 ch = 0x111; \
348 else if (var == PT || var == PT2) \
349 ch = 0xe7; \
350 break; \
351 case 0x7d: \
352 if (var == CA || var == CA2 || var == IT || var == FR || var == FR1) \
353 ch = 0xe8; \
354 else if (var == DE || var == HU) \
355 ch = 0xfc; \
356 else if (var == DK || var == NO || var == NO2 || var == SE \
357 || var == SE2) \
358 ch = 0xe5; \
359 else if (var == ES || var == ES2) \
360 ch = 0xe7; \
361 else if (var == YU) \
362 ch = 0x107; \
363 else if (var == CU) \
364 ch = 0x5b; \
365 else if (var == PT || var == PT2) \
366 ch = 0xf5; \
367 break; \
368 case 0x7e: \
369 if (var == GB || var == CN || var == JP || var == NO || var == SE) \
370 ch = 0x203e; \
371 else if (var == CA || var == CA2) \
372 ch = 0xfb; \
373 else if (var == DE) \
374 ch = 0xdf; \
375 else if (var == ES2 || var == CU || var == FR || var == FR1) \
376 ch = 0xa8; \
377 else if (var == IT) \
378 ch = 0xec; \
379 else if (var == JP_OCR_B) \
380 /* Illegal character. */ \
381 failure = GCONV_ILLEGAL_INPUT; \
382 else if (var == YU) \
383 ch = 0x10d; \
384 else if (var == HU) \
385 ch = 0x2dd; \
386 else if (var == NO2) \
387 ch = 0x7c; \
388 else if (var == PT) \
389 ch = 0xb0; \
390 else if (var == SE2) \
391 ch = 0xfc; \
392 break; \
393 default: \
394 break; \
395 case 0x80 ... 0xff: \
396 /* Illegal character. */ \
397 failure = GCONV_ILLEGAL_INPUT; \
398 break; \
401 /* Hopefully gcc can recognize that the following `if' is only true \
402 when we reach the default case in the `switch' statement. */ \
403 if (failure == GCONV_ILLEGAL_INPUT) \
405 /* Exit the loop with an error. */ \
406 result = failure; \
407 break; \
409 *((uint32_t *) outptr)++ = ch; \
410 ++inptr; \
412 #define EXTRA_LOOP_DECLS , enum variant var
413 #include <iconv/loop.c>
416 /* Next, define the other direction. */
417 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
418 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
419 #define LOOPFCT TO_LOOP
420 #define BODY \
422 unsigned char ch; \
423 int failure = GCONV_OK; \
425 ch = *((uint32_t *) inptr); \
426 switch (*((uint32_t *) inptr)) \
428 case 0x23: \
429 if (var == GB || var == ES || var == IT || var == FR || var == FR1 \
430 || var == NO2) \
431 failure = GCONV_ILLEGAL_INPUT; \
432 break; \
433 case 0x24: \
434 if (var == CN || var == HU || var == CU || var == SE || var == SE2) \
435 failure = GCONV_ILLEGAL_INPUT; \
436 break; \
437 case 0x40: \
438 if (var == CA || var == CA2 || var == DE || var == ES || var == ES2 \
439 || var == IT || var == YU || var == HU || var == FR || var == FR1 \
440 || var == PT || var == PT2 || var == SE2) \
441 failure = GCONV_ILLEGAL_INPUT; \
442 break; \
443 case 0x5b: \
444 if (var == CA || var == CA2 || var == DE || var == DK || var == ES \
445 || var == ES2 || var == IT || var == JP_OCR_B || var == YU \
446 || var == HU || var == FR || var == FR1 || var == NO \
447 || var == NO2 || var == PT || var == PT2 || var == SE \
448 || var == SE2) \
449 failure = GCONV_ILLEGAL_INPUT; \
450 else if (var == CU) \
451 ch = 0x7d; \
452 break; \
453 case 0x5c: \
454 if (var == CA || var == CA2 || var == DE || var == DK || var == ES \
455 || var == ES2 || var == IT || var == JP || var == JP_OCR_B \
456 || var == YU || var == KR || var == HU || var == CU || var == FR \
457 || var == FR1 || var == NO || var == NO2 || var == PT \
458 || var == PT2 || var == SE || var == SE2) \
459 failure = GCONV_ILLEGAL_INPUT; \
460 break; \
461 case 0x5d: \
462 if (var == CA || var == CA2 || var == DE || var == DK || var == ES \
463 || var == ES2 || var == IT || var == JP_OCR_B || var == YU \
464 || var == HU || var == FR || var == FR1 || var == NO \
465 || var == NO2 || var == PT || var == PT2 || var == SE \
466 || var == SE2) \
467 failure = GCONV_ILLEGAL_INPUT; \
468 break; \
469 case 0x5e: \
470 if (var == CA || var == CA2 || var == ES2 || var == YU || var == CU \
471 || var == SE2) \
472 failure = GCONV_ILLEGAL_INPUT; \
473 break; \
474 case 0x60: \
475 if (var == CA || var == CA2 || var == IT || var == JP_OCR_B \
476 || var == YU || var == HU || var == FR || var == SE2) \
477 failure = GCONV_ILLEGAL_INPUT; \
478 break; \
479 case 0x7b: \
480 if (var == CA || var == CA2 || var == DE || var == DK || var == ES \
481 || var == ES2 || var == IT || var == YU || var == HU \
482 || var == CU || var == FR || var == FR1 || var == NO \
483 || var == NO2 || var == PT || var == PT2 || var == SE \
484 || var == SE2) \
485 failure = GCONV_ILLEGAL_INPUT; \
486 break; \
487 case 0x7c: \
488 if (var == CA || var == CA2 || var == DE || var == DK || var == ES \
489 || var == ES2 || var == IT || var == YU || var == HU || var == CU \
490 || var == FR || var == FR1 || var == NO || var == PT \
491 || var == PT2 || var == SE || var == SE2) \
492 failure = GCONV_ILLEGAL_INPUT; \
493 else if (var == NO2) \
494 ch = 0x7e; \
495 break; \
496 case 0x7d: \
497 if (var == CA || var == CA2 || var == DE || var == DK || var == ES \
498 || var == ES2 || var == IT || var == YU || var == HU || var == CU \
499 || var == FR || var == FR1 || var == NO || var == NO2 \
500 || var == PT || var == PT2 || var == SE || var == SE2) \
501 failure = GCONV_ILLEGAL_INPUT; \
502 break; \
503 case 0x7e: \
504 if (var == GB || var == CA || var == CA2 || var == DE || var == ES2 \
505 || var == CN || var == IT || var == JP || var == JP_OCR_B \
506 || var == YU || var == HU || var == CU || var == FR || var == FR1 \
507 || var == NO || var == NO2 || var == PT || var == SE \
508 || var == SE2) \
509 failure = GCONV_ILLEGAL_INPUT; \
510 break; \
511 case 0xa1: \
512 if (var != ES && var != ES2 && var != CU) \
513 failure = GCONV_ILLEGAL_INPUT; \
514 ch = 0x5b; \
515 break; \
516 case 0xa3: \
517 if (var != GB && var != ES && var != IT && var != FR && var != FR1) \
518 failure = GCONV_ILLEGAL_INPUT; \
519 ch = 0x23; \
520 break; \
521 case 0xa4: \
522 if (var != HU && var != CU && var != SE && var != SE2) \
523 failure = GCONV_ILLEGAL_INPUT; \
524 ch = 0x24; \
525 break; \
526 case 0xa5: \
527 if (var == CN) \
528 ch = 0x24; \
529 else if (var == JP || var == JP_OCR_B) \
530 ch = 0x5c; \
531 else \
532 failure = GCONV_ILLEGAL_INPUT; \
533 break; \
534 case 0xa7: \
535 if (var == DE || var == ES || var == IT || var == PT) \
536 ch = 0x40; \
537 else if (var == FR || var == FR1) \
538 ch = 0x5d; \
539 else if (var == NO2) \
540 ch = 0x23; \
541 else \
542 failure = GCONV_ILLEGAL_INPUT; \
543 break; \
544 case 0xa8: \
545 if (var != ES2 && var != CU && var != FR && var != FR1) \
546 failure = GCONV_ILLEGAL_INPUT; \
547 ch = 0x7e; \
548 break; \
549 case 0xb0: \
550 if (var == ES) \
551 ch = 0x7b; \
552 else if (var == IT || var == FR || var == FR1) \
553 ch = 0x5b; \
554 else if (var == PT) \
555 ch = 0x7e; \
556 else \
557 failure = GCONV_ILLEGAL_INPUT; \
558 break; \
559 case 0xb4: \
560 if (var == ES2 || var == CU) \
561 ch = 0x7b; \
562 else if (var == PT2) \
563 ch = 0x40; \
564 else \
565 failure = GCONV_ILLEGAL_INPUT; \
566 break; \
567 case 0xb5: \
568 if (var != FR) \
569 failure = GCONV_ILLEGAL_INPUT; \
570 ch = 0x60; \
571 break; \
572 case 0xbf: \
573 if (var == ES) \
574 ch = 0x5d; \
575 else if (var == ES2 || var == CU) \
576 ch = 0x5e; \
577 else \
578 failure = GCONV_ILLEGAL_INPUT; \
579 break; \
580 case 0xc1: \
581 if (var != HU) \
582 failure = GCONV_ILLEGAL_INPUT; \
583 ch = 0x40; \
584 break; \
585 case 0xc3: \
586 if (var != PT && var != PT2) \
587 failure = GCONV_ILLEGAL_INPUT; \
588 ch = 0x5b; \
589 break; \
590 case 0xc4: \
591 if (var != DE && var != SE && var != SE2) \
592 failure = GCONV_ILLEGAL_INPUT; \
593 ch = 0x5b; \
594 break; \
595 case 0xc5: \
596 if (var != DK && var != NO && var != NO2 && var != SE && var != SE2) \
597 failure = GCONV_ILLEGAL_INPUT; \
598 ch = 0x5d; \
599 break; \
600 case 0xc6: \
601 if (var != DK && var != NO && var != NO2) \
602 failure = GCONV_ILLEGAL_INPUT; \
603 ch = 0x5b; \
604 break; \
605 case 0xc7: \
606 if (var == ES2) \
607 ch = 0x5d; \
608 else if (var == PT || var == PT2) \
609 ch = 0x5c; \
610 else \
611 failure = GCONV_ILLEGAL_INPUT; \
612 break; \
613 case 0xc9: \
614 if (var == CA2) \
615 ch = 0x5e; \
616 else if (var == HU) \
617 ch = 0x5b; \
618 else if (var == SE2) \
619 ch = 0x40; \
620 else \
621 failure = GCONV_ILLEGAL_INPUT; \
622 break; \
623 case 0xd1: \
624 if (var != ES && var != ES2 && var != CU) \
625 failure = GCONV_ILLEGAL_INPUT; \
626 ch = 0x5c; \
627 break; \
628 case 0xd5: \
629 if (var != PT && var != PT2) \
630 failure = GCONV_ILLEGAL_INPUT; \
631 ch = 0x5d; \
632 break; \
633 case 0xd6: \
634 if (var != DE && var != HU && var != SE && var != SE2) \
635 failure = GCONV_ILLEGAL_INPUT; \
636 ch = 0x5c; \
637 break; \
638 case 0xd8: \
639 if (var != DK && var != NO && var != NO2) \
640 failure = GCONV_ILLEGAL_INPUT; \
641 ch = 0x5c; \
642 break; \
643 case 0xdc: \
644 if (var == DE || var == HU) \
645 ch = 0x5d; \
646 else if (var == SE2) \
647 ch = 0x5e; \
648 else \
649 failure = GCONV_ILLEGAL_INPUT; \
650 break; \
651 case 0xdf: \
652 if (var != DE) \
653 failure = GCONV_ILLEGAL_INPUT; \
654 ch = 0x7e; \
655 break; \
656 case 0xe0: \
657 if (var == CA || var == CA2 || var == FR || var == FR1) \
658 ch = 0x40; \
659 else if (var == IT) \
660 ch = 0x7b; \
661 else \
662 failure = GCONV_ILLEGAL_INPUT; \
663 break; \
664 case 0xe1: \
665 if (var != HU) \
666 failure = GCONV_ILLEGAL_INPUT; \
667 ch = 0x60; \
668 break; \
669 case 0xe2: \
670 if (var != CA && var != CA2) \
671 failure = GCONV_ILLEGAL_INPUT; \
672 ch = 0x5b; \
673 break; \
674 case 0xe3: \
675 if (var != PT && var != PT2) \
676 failure = GCONV_ILLEGAL_INPUT; \
677 ch = 0x7b; \
678 break; \
679 case 0xe4: \
680 if (var != DE && var != SE && var != SE2) \
681 failure = GCONV_ILLEGAL_INPUT; \
682 ch = 0x7b; \
683 break; \
684 case 0xe5: \
685 if (var != DK && var != NO && var != NO2 && var != SE && var != SE2) \
686 failure = GCONV_ILLEGAL_INPUT; \
687 ch = 0x7d; \
688 break; \
689 case 0xe6: \
690 if (var != DK && var != NO && var != NO2) \
691 failure = GCONV_ILLEGAL_INPUT; \
692 ch = 0x7b; \
693 break; \
694 case 0xe7: \
695 if (var == CA || var == CA2 || var == IT || var == FR || var == FR1) \
696 ch = 0x5c; \
697 else if (var == ES || var == ES2) \
698 ch = 0x7d; \
699 else if (var == PT || var == PT2) \
700 ch = 0x7c; \
701 else \
702 failure = GCONV_ILLEGAL_INPUT; \
703 break; \
704 case 0xe8: \
705 if (var != CA && var != CA2 && var != IT && var != FR && var != FR1) \
706 failure = GCONV_ILLEGAL_INPUT; \
707 ch = 0x7d; \
708 break; \
709 case 0xe9: \
710 if (var == CA || var == CA2 || var == HU || var == FR || var == FR1) \
711 ch = 0x7b; \
712 else if (var == IT) \
713 ch = 0x5d; \
714 else if (var == SE2) \
715 ch = 0x60; \
716 else \
717 failure = GCONV_ILLEGAL_INPUT; \
718 break; \
719 case 0xea: \
720 if (var != CA && var != CA2) \
721 failure = GCONV_ILLEGAL_INPUT; \
722 ch = 0x5d; \
723 break; \
724 case 0xec: \
725 if (var != IT) \
726 failure = GCONV_ILLEGAL_INPUT; \
727 ch = 0x7e; \
728 break; \
729 case 0xee: \
730 if (var != CA) \
731 failure = GCONV_ILLEGAL_INPUT; \
732 ch = 0x5e; \
733 break; \
734 case 0xf1: \
735 if (var != ES && var != ES2 && var != CU) \
736 failure = GCONV_ILLEGAL_INPUT; \
737 ch = 0x7c; \
738 break; \
739 case 0xf2: \
740 if (var != IT) \
741 failure = GCONV_ILLEGAL_INPUT; \
742 ch = 0x7c; \
743 break; \
744 case 0xf4: \
745 if (var != CA && var != CA2) \
746 failure = GCONV_ILLEGAL_INPUT; \
747 ch = 0x60; \
748 break; \
749 case 0xf5: \
750 if (var != PT && var != PT2) \
751 failure = GCONV_ILLEGAL_INPUT; \
752 ch = 0x7d; \
753 break; \
754 case 0xf6: \
755 if (var != DE && var != HU && var != SE && var != SE2) \
756 failure = GCONV_ILLEGAL_INPUT; \
757 ch = 0x7c; \
758 break; \
759 case 0xf8: \
760 if (var != DK && var != NO && var != NO2) \
761 failure = GCONV_ILLEGAL_INPUT; \
762 ch = 0x7c; \
763 break; \
764 case 0xf9: \
765 if (var == CA || var == CA2 || var == FR || var == FR1) \
766 ch = 0x7c; \
767 else if (var == IT) \
768 ch = 0x60; \
769 else \
770 failure = GCONV_ILLEGAL_INPUT; \
771 break; \
772 case 0xfb: \
773 if (var != CA && var != CA2) \
774 failure = GCONV_ILLEGAL_INPUT; \
775 ch = 0x7e; \
776 break; \
777 case 0xfc: \
778 if (var == DE || var == HU) \
779 ch = 0x7d; \
780 else if (var == SE2) \
781 ch = 0x7e; \
782 else \
783 failure = GCONV_ILLEGAL_INPUT; \
784 break; \
785 case 0x160: \
786 if (var != YU) \
787 failure = GCONV_ILLEGAL_INPUT; \
788 ch = 0x5b; \
789 break; \
790 case 0x106: \
791 if (var != YU) \
792 failure = GCONV_ILLEGAL_INPUT; \
793 ch = 0x5d; \
794 break; \
795 case 0x107: \
796 if (var != YU) \
797 failure = GCONV_ILLEGAL_INPUT; \
798 ch = 0x7d; \
799 break; \
800 case 0x10c: \
801 if (var != YU) \
802 failure = GCONV_ILLEGAL_INPUT; \
803 ch = 0x5e; \
804 break; \
805 case 0x10d: \
806 if (var != YU) \
807 failure = GCONV_ILLEGAL_INPUT; \
808 ch = 0x7e; \
809 break; \
810 case 0x110: \
811 if (var != YU) \
812 failure = GCONV_ILLEGAL_INPUT; \
813 ch = 0x5c; \
814 break; \
815 case 0x111: \
816 if (var != YU) \
817 failure = GCONV_ILLEGAL_INPUT; \
818 ch = 0x7c; \
819 break; \
820 case 0x161: \
821 if (var != YU) \
822 failure = GCONV_ILLEGAL_INPUT; \
823 ch = 0x7b; \
824 break; \
825 case 0x17d: \
826 if (var != YU) \
827 failure = GCONV_ILLEGAL_INPUT; \
828 ch = 0x40; \
829 break; \
830 case 0x17e: \
831 if (var != YU) \
832 failure = GCONV_ILLEGAL_INPUT; \
833 ch = 0x60; \
834 break; \
835 case 0x2dd: \
836 if (var != HU) \
837 failure = GCONV_ILLEGAL_INPUT; \
838 ch = 0x7e; \
839 break; \
840 case 0x2022: \
841 if (var != ES2) \
842 failure = GCONV_ILLEGAL_INPUT; \
843 ch = 0x40; \
844 break; \
845 case 0x203e: \
846 if (var != GB && var != CN && var != JP && var != NO && var != SE) \
847 failure = GCONV_ILLEGAL_INPUT; \
848 ch = 0x7e; \
849 break; \
850 case 0x20a9: \
851 if (var != KR) \
852 failure = GCONV_ILLEGAL_INPUT; \
853 ch = 0x5c; \
854 break; \
855 case 0x2329: \
856 if (var != JP_OCR_B) \
857 failure = GCONV_ILLEGAL_INPUT; \
858 ch = 0x5b; \
859 break; \
860 case 0x232a: \
861 if (var != JP_OCR_B) \
862 failure = GCONV_ILLEGAL_INPUT; \
863 ch = 0x5d; \
864 break; \
865 default: \
866 if (*((uint32_t *) inptr) > 0x7f) \
867 failure = GCONV_ILLEGAL_INPUT; \
868 break; \
871 if (failure == GCONV_ILLEGAL_INPUT) \
873 /* Exit the loop with an error. */ \
874 result = failure; \
875 break; \
877 *outptr++ = (unsigned char) ch; \
878 inptr += 4; \
880 #define EXTRA_LOOP_DECLS , enum variant var
881 #include <iconv/loop.c>
884 /* Now define the toplevel functions. */
885 #include <iconv/skeleton.c>