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