]> git.ipfire.org Git - thirdparty/glibc.git/blame - iconvdata/iso646.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / iconvdata / iso646.c
CommitLineData
d2374599 1/* Conversion to and from the various ISO 646 CCS.
04277e02 2 Copyright (C) 1998-2019 Free Software Foundation, Inc.
d2374599
UD
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
41bdb6e2
AJ
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.
d2374599
UD
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
41bdb6e2 14 Lesser General Public License for more details.
d2374599 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6 17 License along with the GNU C Library; if not, see
5a82c748 18 <https://www.gnu.org/licenses/>. */
d2374599 19
b60816b1
UD
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. */
32
55985355 33#include <dlfcn.h>
d2374599 34#include <gconv.h>
28f1c862 35#include <stdint.h>
7ef90c15 36#include <stdlib.h>
d2374599
UD
37#include <string.h>
38
28f1c862
UD
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
13e402e7
SE
46#define ONE_DIRECTION 0
47
e3e0a182 48#define FROM_DIRECTION (dir == from_iso646)
28f1c862 49#define PREPARE_LOOP \
d64b6ad0
UD
50 enum direction dir = ((struct iso646_data *) step->__data)->dir; \
51 enum variant var = ((struct iso646_data *) step->__data)->var;
28f1c862
UD
52#define EXTRA_LOOP_ARGS , var
53
54
d2374599
UD
55/* Direction of the transformation. */
56enum direction
57{
b60816b1 58 illegal_dir,
d2374599
UD
59 to_iso646,
60 from_iso646
61};
62
261e6758 63/* See names below, must be in the same order. */
d2374599
UD
64enum variant
65{
d2374599 66 GB, /* BS_4730 */
9b26f5c4
UD
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 */
89};
90
261e6758
FW
91/* Must be in the same order as enum variant above. */
92static 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";
d2374599
UD
118
119struct iso646_data
120{
121 enum direction dir;
122 enum variant var;
123};
124
125
8c0b7170 126extern int gconv_init (struct __gconv_step *step);
d2374599 127int
d64b6ad0 128gconv_init (struct __gconv_step *step)
d2374599
UD
129{
130 /* Determine which direction. */
131 struct iso646_data *new_data;
9b26f5c4 132 enum direction dir = illegal_dir;
d2374599
UD
133 int result;
134
261e6758
FW
135 enum variant var = 0;
136 for (const char *name = names; *name != '\0';
137 name = __rawmemchr (name, '\0') + 1)
138 {
139 if (__strcasecmp (step->__from_name, name) == 0)
140 {
141 dir = from_iso646;
142 break;
143 }
144 else if (__strcasecmp (step->__to_name, name) == 0)
145 {
146 dir = to_iso646;
147 break;
148 }
149 ++var;
150 }
d2374599 151
d64b6ad0 152 result = __GCONV_NOCONV;
019357d2 153 if (__builtin_expect (dir, from_iso646) != illegal_dir)
d2374599 154 {
09376451 155 new_data = (struct iso646_data *) malloc (sizeof (struct iso646_data));
d2374599 156
d64b6ad0 157 result = __GCONV_NOMEM;
09376451 158 if (new_data != NULL)
918b9d72 159 {
09376451
UD
160 new_data->dir = dir;
161 new_data->var = var;
d64b6ad0 162 step->__data = new_data;
09376451 163
ae0f0dbd 164 if (dir == from_iso646)
09376451 165 {
d64b6ad0
UD
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;
09376451
UD
170 }
171 else
172 {
d64b6ad0
UD
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;
09376451
UD
177 }
178
d64b6ad0 179 step->__stateful = 0;
09376451 180
d64b6ad0 181 result = __GCONV_OK;
918b9d72 182 }
9b26f5c4 183 }
28f1c862 184
d2374599
UD
185 return result;
186}
187
188
8c0b7170 189extern void gconv_end (struct __gconv_step *data);
d2374599 190void
d64b6ad0 191gconv_end (struct __gconv_step *data)
d2374599 192{
d64b6ad0 193 free (data->__data);
d2374599
UD
194}
195
196
28f1c862
UD
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 \
202 { \
203 uint32_t ch; \
d64b6ad0 204 int failure = __GCONV_OK; \
28f1c862 205 \
9b26f5c4
UD
206 ch = *inptr; \
207 switch (ch) \
28f1c862 208 { \
9b26f5c4
UD
209 case 0x23: \
210 if (var == GB || var == ES || var == IT || var == FR || var == FR1) \
28f1c862 211 ch = 0xa3; \
9b26f5c4
UD
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; \
28f1c862 256 break; \
9b26f5c4
UD
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. */ \
d64b6ad0 317 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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) \
28f1c862 380 ch = 0x203e; \
9b26f5c4
UD
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. */ \
d64b6ad0 391 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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; \
28f1c862
UD
402 break; \
403 default: \
28f1c862 404 break; \
4b8f94d3 405 case 0x80 ... 0xff: \
28f1c862 406 /* Illegal character. */ \
d64b6ad0 407 failure = __GCONV_ILLEGAL_INPUT; \
28f1c862
UD
408 break; \
409 } \
410 \
411 /* Hopefully gcc can recognize that the following `if' is only true \
412 when we reach the default case in the `switch' statement. */ \
019357d2 413 if (__builtin_expect (failure, __GCONV_OK) == __GCONV_ILLEGAL_INPUT) \
28f1c862 414 { \
e438a468 415 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
85830c4c
UD
416 } \
417 else \
418 { \
419 put32 (outptr, ch); \
420 outptr += 4; \
28f1c862 421 } \
28f1c862
UD
422 ++inptr; \
423 }
55985355 424#define LOOP_NEED_FLAGS
28f1c862
UD
425#define EXTRA_LOOP_DECLS , enum variant var
426#include <iconv/loop.c>
427
428
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 \
434 { \
7888313d 435 unsigned int ch; \
d64b6ad0 436 int failure = __GCONV_OK; \
28f1c862 437 \
77e1d15a 438 ch = get32 (inptr); \
7888313d 439 switch (ch) \
28f1c862 440 { \
9b26f5c4
UD
441 case 0x23: \
442 if (var == GB || var == ES || var == IT || var == FR || var == FR1 \
443 || var == NO2) \
d64b6ad0 444 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
445 break; \
446 case 0x24: \
447 if (var == CN || var == HU || var == CU || var == SE || var == SE2) \
d64b6ad0 448 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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) \
d64b6ad0 454 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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) \
d64b6ad0 462 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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) \
d64b6ad0 472 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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) \
d64b6ad0 480 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
481 break; \
482 case 0x5e: \
483 if (var == CA || var == CA2 || var == ES2 || var == YU || var == CU \
484 || var == SE2) \
d64b6ad0 485 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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) \
d64b6ad0 490 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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) \
d64b6ad0 498 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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) \
d64b6ad0 505 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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) \
d64b6ad0 514 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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) \
d64b6ad0 522 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
523 break; \
524 case 0xa1: \
525 if (var != ES && var != ES2 && var != CU) \
d64b6ad0 526 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
527 ch = 0x5b; \
528 break; \
529 case 0xa3: \
530 if (var != GB && var != ES && var != IT && var != FR && var != FR1) \
d64b6ad0 531 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
532 ch = 0x23; \
533 break; \
534 case 0xa4: \
535 if (var != HU && var != CU && var != SE && var != SE2) \
d64b6ad0 536 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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 \
d64b6ad0 545 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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 \
d64b6ad0 555 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
556 break; \
557 case 0xa8: \
558 if (var != ES2 && var != CU && var != FR && var != FR1) \
d64b6ad0 559 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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 \
d64b6ad0 570 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
571 break; \
572 case 0xb4: \
573 if (var == ES2 || var == CU) \
574 ch = 0x7b; \
575 else if (var == PT2) \
576 ch = 0x40; \
577 else \
d64b6ad0 578 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
579 break; \
580 case 0xb5: \
581 if (var != FR) \
d64b6ad0 582 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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 \
d64b6ad0 591 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
592 break; \
593 case 0xc1: \
594 if (var != HU) \
d64b6ad0 595 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
596 ch = 0x40; \
597 break; \
598 case 0xc3: \
599 if (var != PT && var != PT2) \
d64b6ad0 600 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
601 ch = 0x5b; \
602 break; \
603 case 0xc4: \
604 if (var != DE && var != SE && var != SE2) \
d64b6ad0 605 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
606 ch = 0x5b; \
607 break; \
608 case 0xc5: \
609 if (var != DK && var != NO && var != NO2 && var != SE && var != SE2) \
d64b6ad0 610 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
611 ch = 0x5d; \
612 break; \
613 case 0xc6: \
614 if (var != DK && var != NO && var != NO2) \
d64b6ad0 615 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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 \
d64b6ad0 624 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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 \
d64b6ad0 634 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
635 break; \
636 case 0xd1: \
637 if (var != ES && var != ES2 && var != CU) \
d64b6ad0 638 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
639 ch = 0x5c; \
640 break; \
641 case 0xd5: \
642 if (var != PT && var != PT2) \
d64b6ad0 643 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
644 ch = 0x5d; \
645 break; \
646 case 0xd6: \
647 if (var != DE && var != HU && var != SE && var != SE2) \
d64b6ad0 648 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
649 ch = 0x5c; \
650 break; \
651 case 0xd8: \
652 if (var != DK && var != NO && var != NO2) \
d64b6ad0 653 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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 \
d64b6ad0 662 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
663 break; \
664 case 0xdf: \
665 if (var != DE) \
d64b6ad0 666 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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 \
d64b6ad0 675 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
676 break; \
677 case 0xe1: \
678 if (var != HU) \
d64b6ad0 679 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
680 ch = 0x60; \
681 break; \
682 case 0xe2: \
683 if (var != CA && var != CA2) \
d64b6ad0 684 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
685 ch = 0x5b; \
686 break; \
687 case 0xe3: \
688 if (var != PT && var != PT2) \
d64b6ad0 689 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
690 ch = 0x7b; \
691 break; \
692 case 0xe4: \
693 if (var != DE && var != SE && var != SE2) \
d64b6ad0 694 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
695 ch = 0x7b; \
696 break; \
697 case 0xe5: \
698 if (var != DK && var != NO && var != NO2 && var != SE && var != SE2) \
d64b6ad0 699 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
700 ch = 0x7d; \
701 break; \
702 case 0xe6: \
703 if (var != DK && var != NO && var != NO2) \
d64b6ad0 704 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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 \
d64b6ad0 715 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
716 break; \
717 case 0xe8: \
718 if (var != CA && var != CA2 && var != IT && var != FR && var != FR1) \
d64b6ad0 719 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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 \
d64b6ad0 730 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
731 break; \
732 case 0xea: \
733 if (var != CA && var != CA2) \
d64b6ad0 734 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
735 ch = 0x5d; \
736 break; \
737 case 0xec: \
738 if (var != IT) \
d64b6ad0 739 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
740 ch = 0x7e; \
741 break; \
742 case 0xee: \
743 if (var != CA) \
d64b6ad0 744 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
745 ch = 0x5e; \
746 break; \
747 case 0xf1: \
748 if (var != ES && var != ES2 && var != CU) \
d64b6ad0 749 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
750 ch = 0x7c; \
751 break; \
752 case 0xf2: \
753 if (var != IT) \
d64b6ad0 754 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
755 ch = 0x7c; \
756 break; \
757 case 0xf4: \
758 if (var != CA && var != CA2) \
d64b6ad0 759 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
760 ch = 0x60; \
761 break; \
762 case 0xf5: \
763 if (var != PT && var != PT2) \
d64b6ad0 764 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
765 ch = 0x7d; \
766 break; \
767 case 0xf6: \
768 if (var != DE && var != HU && var != SE && var != SE2) \
d64b6ad0 769 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
770 ch = 0x7c; \
771 break; \
772 case 0xf8: \
773 if (var != DK && var != NO && var != NO2) \
d64b6ad0 774 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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 \
d64b6ad0 783 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
784 break; \
785 case 0xfb: \
786 if (var != CA && var != CA2) \
d64b6ad0 787 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
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 \
d64b6ad0 796 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
797 break; \
798 case 0x160: \
799 if (var != YU) \
d64b6ad0 800 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
801 ch = 0x5b; \
802 break; \
803 case 0x106: \
804 if (var != YU) \
d64b6ad0 805 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
806 ch = 0x5d; \
807 break; \
808 case 0x107: \
809 if (var != YU) \
d64b6ad0 810 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
811 ch = 0x7d; \
812 break; \
813 case 0x10c: \
814 if (var != YU) \
d64b6ad0 815 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
816 ch = 0x5e; \
817 break; \
818 case 0x10d: \
819 if (var != YU) \
d64b6ad0 820 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
821 ch = 0x7e; \
822 break; \
823 case 0x110: \
824 if (var != YU) \
d64b6ad0 825 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
826 ch = 0x5c; \
827 break; \
828 case 0x111: \
829 if (var != YU) \
d64b6ad0 830 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
831 ch = 0x7c; \
832 break; \
833 case 0x161: \
834 if (var != YU) \
d64b6ad0 835 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
836 ch = 0x7b; \
837 break; \
838 case 0x17d: \
839 if (var != YU) \
d64b6ad0 840 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
841 ch = 0x40; \
842 break; \
843 case 0x17e: \
844 if (var != YU) \
d64b6ad0 845 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
846 ch = 0x60; \
847 break; \
848 case 0x2dd: \
849 if (var != HU) \
d64b6ad0 850 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
851 ch = 0x7e; \
852 break; \
853 case 0x2022: \
854 if (var != ES2) \
d64b6ad0 855 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
856 ch = 0x40; \
857 break; \
858 case 0x203e: \
859 if (var != GB && var != CN && var != JP && var != NO && var != SE) \
d64b6ad0 860 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
861 ch = 0x7e; \
862 break; \
863 case 0x20a9: \
864 if (var != KR) \
d64b6ad0 865 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
866 ch = 0x5c; \
867 break; \
868 case 0x2329: \
869 if (var != JP_OCR_B) \
d64b6ad0 870 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
871 ch = 0x5b; \
872 break; \
873 case 0x232a: \
874 if (var != JP_OCR_B) \
d64b6ad0 875 failure = __GCONV_ILLEGAL_INPUT; \
9b26f5c4
UD
876 ch = 0x5d; \
877 break; \
878 default: \
a1ffb40e 879 if (__glibc_unlikely (ch > 0x7f)) \
601d2942
UD
880 { \
881 UNICODE_TAG_HANDLER (ch, 4); \
882 failure = __GCONV_ILLEGAL_INPUT; \
883 } \
9b26f5c4 884 break; \
28f1c862 885 } \
28f1c862 886 \
019357d2 887 if (__builtin_expect (failure, __GCONV_OK) == __GCONV_ILLEGAL_INPUT) \
28f1c862 888 { \
e438a468 889 STANDARD_TO_LOOP_ERR_HANDLER (4); \
28f1c862 890 } \
d6204268
UD
891 \
892 *outptr++ = (unsigned char) ch; \
28f1c862
UD
893 inptr += 4; \
894 }
55985355 895#define LOOP_NEED_FLAGS
28f1c862
UD
896#define EXTRA_LOOP_DECLS , enum variant var
897#include <iconv/loop.c>
898
899
900/* Now define the toplevel functions. */
901#include <iconv/skeleton.c>