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