* posix/execl.c: Fix last argument of memcpy. Reported by Brian
[glibc/pb-stable.git] / iconvdata / cp1258.c
blob69613c68f0e3e7a416f0e07a26c1d6cf4f5e2cdd
1 /* Conversion from and to CP1258.
2 Copyright (C) 1998, 2001 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998,
5 and Bruno Haible <haible@clisp.cons.org>, 2001.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #include <dlfcn.h>
23 #include <stdint.h>
24 #include <assert.h>
25 #include <stdlib.h>
27 #define NELEMS(arr) (sizeof (arr) / sizeof (arr[0]))
29 /* Definitions used in the body of the `gconv' function. */
30 #define CHARSET_NAME "CP1258//"
31 #define FROM_LOOP from_cp1258
32 #define TO_LOOP to_cp1258
33 #define DEFINE_INIT 1
34 #define DEFINE_FINI 1
35 #define MIN_NEEDED_FROM 1
36 #define MAX_NEEDED_FROM 1
37 #define MIN_NEEDED_TO 4
38 #define MAX_NEEDED_TO 4
39 #define PREPARE_LOOP \
40 int saved_state; \
41 int *statep = &data->__statep->__count;
42 #define EXTRA_LOOP_ARGS , statep
45 /* Since we might have to reset input pointer we must be able to save
46 and restore the state. */
47 #define SAVE_RESET_STATE(Save) \
48 if (Save) \
49 saved_state = *statep; \
50 else \
51 *statep = saved_state
54 /* During CP1258 to UCS4 conversion, the COUNT element of the state
55 contains the last UCS4 character, shifted by 3 bits. */
58 /* Since this is a stateful encoding we have to provide code which resets
59 the output state to the initial state. This has to be done during the
60 flushing. */
61 #define EMIT_SHIFT_TO_INIT \
62 if (data->__statep->__count != 0) \
63 { \
64 if (FROM_DIRECTION) \
65 { \
66 if (__builtin_expect (outbuf + 4 <= outend, 1)) \
67 { \
68 /* Write out the last character. */ \
69 *((uint32_t *) outbuf)++ = data->__statep->__count >> 3; \
70 data->__statep->__count = 0; \
71 } \
72 else \
73 /* We don't have enough room in the output buffer. */ \
74 status = __GCONV_FULL_OUTPUT; \
75 } \
76 else \
77 /* We don't use shift states in the TO_DIRECTION. */ \
78 data->__statep->__count = 0; \
82 /* First define the conversion function from CP1258 to UCS4. */
84 static const uint16_t to_ucs4[128] = {
85 /* 0x80 */
86 0x20AC, 0, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
87 0x02C6, 0x2030, 0, 0x2039, 0x0152, 0, 0, 0,
88 /* 0x90 */
89 0, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
90 0x02DC, 0x2122, 0, 0x203A, 0x0153, 0, 0, 0x0178,
91 /* 0xA0 */
92 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
93 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
94 /* 0xB0 */
95 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
96 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
97 /* 0xC0 */
98 0x00C0, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
99 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x0300, 0x00CD, 0x00CE, 0x00CF,
100 /* 0xD0 */
101 0x0110, 0x00D1, 0x0309, 0x00D3, 0x00D4, 0x01A0, 0x00D6, 0x00D7,
102 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x01AF, 0x0303, 0x00DF,
103 /* 0xE0 */
104 0x00E0, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
105 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0301, 0x00ED, 0x00EE, 0x00EF,
106 /* 0xF0 */
107 0x0111, 0x00F1, 0x0323, 0x00F3, 0x00F4, 0x01A1, 0x00F6, 0x00F7,
108 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x01B0, 0x20AB, 0x00FF,
111 /* CP1258 contains five combining characters:
112 0x0300, 0x0301, 0x0303, 0x0309, 0x0323. */
114 /* Composition tables for each of the relevant combining characters. */
115 static const struct {
116 uint16_t base;
117 uint16_t composed;
118 } comp_table_data[] = {
119 #define COMP_TABLE_IDX_0300 0
120 #define COMP_TABLE_LEN_0300 31
121 { 0x0041, 0x00C0 },
122 { 0x0045, 0x00C8 },
123 { 0x0049, 0x00CC },
124 { 0x004E, 0x01F8 },
125 { 0x004F, 0x00D2 },
126 { 0x0055, 0x00D9 },
127 { 0x0057, 0x1E80 },
128 { 0x0059, 0x1EF2 },
129 { 0x0061, 0x00E0 },
130 { 0x0065, 0x00E8 },
131 { 0x0069, 0x00EC },
132 { 0x006E, 0x01F9 },
133 { 0x006F, 0x00F2 },
134 { 0x0075, 0x00F9 },
135 { 0x0077, 0x1E81 },
136 { 0x0079, 0x1EF3 },
137 { 0x00A8, 0x1FED },
138 { 0x00C2, 0x1EA6 },
139 { 0x00CA, 0x1EC0 },
140 { 0x00D4, 0x1ED2 },
141 { 0x00DC, 0x01DB },
142 { 0x00E2, 0x1EA7 },
143 { 0x00EA, 0x1EC1 },
144 { 0x00F4, 0x1ED3 },
145 { 0x00FC, 0x01DC },
146 { 0x0102, 0x1EB0 },
147 { 0x0103, 0x1EB1 },
148 /*{ 0x0112, 0x1E14 },*/
149 /*{ 0x0113, 0x1E15 },*/
150 /*{ 0x014C, 0x1E50 },*/
151 /*{ 0x014D, 0x1E51 },*/
152 { 0x01A0, 0x1EDC },
153 { 0x01A1, 0x1EDD },
154 { 0x01AF, 0x1EEA },
155 { 0x01B0, 0x1EEB },
156 #define COMP_TABLE_IDX_0301 (COMP_TABLE_IDX_0300 + COMP_TABLE_LEN_0300)
157 #define COMP_TABLE_LEN_0301 60
158 { 0x0041, 0x00C1 },
159 { 0x0043, 0x0106 },
160 { 0x0045, 0x00C9 },
161 { 0x0047, 0x01F4 },
162 { 0x0049, 0x00CD },
163 { 0x004B, 0x1E30 },
164 { 0x004C, 0x0139 },
165 { 0x004D, 0x1E3E },
166 { 0x004E, 0x0143 },
167 { 0x004F, 0x00D3 },
168 { 0x0050, 0x1E54 },
169 { 0x0052, 0x0154 },
170 { 0x0053, 0x015A },
171 { 0x0055, 0x00DA },
172 { 0x0057, 0x1E82 },
173 { 0x0059, 0x00DD },
174 { 0x005A, 0x0179 },
175 { 0x0061, 0x00E1 },
176 { 0x0063, 0x0107 },
177 { 0x0065, 0x00E9 },
178 { 0x0067, 0x01F5 },
179 { 0x0069, 0x00ED },
180 { 0x006B, 0x1E31 },
181 { 0x006C, 0x013A },
182 { 0x006D, 0x1E3F },
183 { 0x006E, 0x0144 },
184 { 0x006F, 0x00F3 },
185 { 0x0070, 0x1E55 },
186 { 0x0072, 0x0155 },
187 { 0x0073, 0x015B },
188 { 0x0075, 0x00FA },
189 { 0x0077, 0x1E83 },
190 { 0x0079, 0x00FD },
191 { 0x007A, 0x017A },
192 { 0x00A5, 0x0385 },
193 { 0x00A8, 0x1FEE },
194 { 0x00C2, 0x1EA4 },
195 { 0x00C5, 0x01FA },
196 { 0x00C6, 0x01FC },
197 { 0x00C7, 0x1E08 },
198 { 0x00CA, 0x1EBE },
199 { 0x00CF, 0x1E2E },
200 { 0x00D4, 0x1ED0 },
201 /*{ 0x00D5, 0x1E4C },*/
202 { 0x00D8, 0x01FE },
203 { 0x00DC, 0x01D7 },
204 { 0x00E2, 0x1EA5 },
205 { 0x00E5, 0x01FB },
206 { 0x00E6, 0x01FD },
207 { 0x00E7, 0x1E09 },
208 { 0x00EA, 0x1EBF },
209 { 0x00EF, 0x1E2F },
210 { 0x00F4, 0x1ED1 },
211 /*{ 0x00F5, 0x1E4D },*/
212 { 0x00F8, 0x01FF },
213 { 0x00FC, 0x01D8 },
214 { 0x0102, 0x1EAE },
215 { 0x0103, 0x1EAF },
216 /*{ 0x0112, 0x1E16 },*/
217 /*{ 0x0113, 0x1E17 },*/
218 /*{ 0x014C, 0x1E52 },*/
219 /*{ 0x014D, 0x1E53 },*/
220 /*{ 0x0168, 0x1E78 },*/
221 /*{ 0x0169, 0x1E79 },*/
222 { 0x01A0, 0x1EDA },
223 { 0x01A1, 0x1EDB },
224 { 0x01AF, 0x1EE8 },
225 { 0x01B0, 0x1EE9 },
226 #define COMP_TABLE_IDX_0303 (COMP_TABLE_IDX_0301 + COMP_TABLE_LEN_0301)
227 #define COMP_TABLE_LEN_0303 34
228 { 0x0041, 0x00C3 },
229 { 0x0045, 0x1EBC },
230 { 0x0049, 0x0128 },
231 { 0x004E, 0x00D1 },
232 { 0x004F, 0x00D5 },
233 { 0x0055, 0x0168 },
234 { 0x0056, 0x1E7C },
235 { 0x0059, 0x1EF8 },
236 { 0x0061, 0x00E3 },
237 { 0x0065, 0x1EBD },
238 { 0x0069, 0x0129 },
239 { 0x006E, 0x00F1 },
240 { 0x006F, 0x00F5 },
241 { 0x0075, 0x0169 },
242 { 0x0076, 0x1E7D },
243 { 0x0079, 0x1EF9 },
244 { 0x00C2, 0x1EAA },
245 { 0x00CA, 0x1EC4 },
246 { 0x00D3, 0x1E4C },
247 { 0x00D4, 0x1ED6 },
248 { 0x00D6, 0x1E4E },
249 { 0x00DA, 0x1E78 },
250 { 0x00E2, 0x1EAB },
251 { 0x00EA, 0x1EC5 },
252 { 0x00F3, 0x1E4D },
253 { 0x00F4, 0x1ED7 },
254 { 0x00F6, 0x1E4F },
255 { 0x00FA, 0x1E79 },
256 { 0x0102, 0x1EB4 },
257 { 0x0103, 0x1EB5 },
258 { 0x01A0, 0x1EE0 },
259 { 0x01A1, 0x1EE1 },
260 { 0x01AF, 0x1EEE },
261 { 0x01B0, 0x1EEF },
262 #define COMP_TABLE_IDX_0309 (COMP_TABLE_IDX_0303 + COMP_TABLE_LEN_0303)
263 #define COMP_TABLE_LEN_0309 24
264 { 0x0041, 0x1EA2 },
265 { 0x0045, 0x1EBA },
266 { 0x0049, 0x1EC8 },
267 { 0x004F, 0x1ECE },
268 { 0x0055, 0x1EE6 },
269 { 0x0059, 0x1EF6 },
270 { 0x0061, 0x1EA3 },
271 { 0x0065, 0x1EBB },
272 { 0x0069, 0x1EC9 },
273 { 0x006F, 0x1ECF },
274 { 0x0075, 0x1EE7 },
275 { 0x0079, 0x1EF7 },
276 { 0x00C2, 0x1EA8 },
277 { 0x00CA, 0x1EC2 },
278 { 0x00D4, 0x1ED4 },
279 { 0x00E2, 0x1EA9 },
280 { 0x00EA, 0x1EC3 },
281 { 0x00F4, 0x1ED5 },
282 { 0x0102, 0x1EB2 },
283 { 0x0103, 0x1EB3 },
284 { 0x01A0, 0x1EDE },
285 { 0x01A1, 0x1EDF },
286 { 0x01AF, 0x1EEC },
287 { 0x01B0, 0x1EED },
288 #define COMP_TABLE_IDX_0323 (COMP_TABLE_IDX_0309 + COMP_TABLE_LEN_0309)
289 #define COMP_TABLE_LEN_0323 50
290 { 0x0041, 0x1EA0 },
291 { 0x0042, 0x1E04 },
292 { 0x0044, 0x1E0C },
293 { 0x0045, 0x1EB8 },
294 { 0x0048, 0x1E24 },
295 { 0x0049, 0x1ECA },
296 { 0x004B, 0x1E32 },
297 { 0x004C, 0x1E36 },
298 { 0x004D, 0x1E42 },
299 { 0x004E, 0x1E46 },
300 { 0x004F, 0x1ECC },
301 { 0x0052, 0x1E5A },
302 { 0x0053, 0x1E62 },
303 { 0x0054, 0x1E6C },
304 { 0x0055, 0x1EE4 },
305 { 0x0056, 0x1E7E },
306 { 0x0057, 0x1E88 },
307 { 0x0059, 0x1EF4 },
308 { 0x005A, 0x1E92 },
309 { 0x0061, 0x1EA1 },
310 { 0x0062, 0x1E05 },
311 { 0x0064, 0x1E0D },
312 { 0x0065, 0x1EB9 },
313 { 0x0068, 0x1E25 },
314 { 0x0069, 0x1ECB },
315 { 0x006B, 0x1E33 },
316 { 0x006C, 0x1E37 },
317 { 0x006D, 0x1E43 },
318 { 0x006E, 0x1E47 },
319 { 0x006F, 0x1ECD },
320 { 0x0072, 0x1E5B },
321 { 0x0073, 0x1E63 },
322 { 0x0074, 0x1E6D },
323 { 0x0075, 0x1EE5 },
324 { 0x0076, 0x1E7F },
325 { 0x0077, 0x1E89 },
326 { 0x0079, 0x1EF5 },
327 { 0x007A, 0x1E93 },
328 { 0x00C2, 0x1EAC },
329 { 0x00CA, 0x1EC6 },
330 { 0x00D4, 0x1ED8 },
331 { 0x00E2, 0x1EAD },
332 { 0x00EA, 0x1EC7 },
333 { 0x00F4, 0x1ED9 },
334 { 0x0102, 0x1EB6 },
335 { 0x0103, 0x1EB7 },
336 { 0x01A0, 0x1EE2 },
337 { 0x01A1, 0x1EE3 },
338 { 0x01AF, 0x1EF0 },
339 { 0x01B0, 0x1EF1 },
340 #define COMP_TABLE_IDX_END (COMP_TABLE_IDX_0323 + COMP_TABLE_LEN_0323)
342 /* Compile-time verification of table size. */
343 typedef int verify1[(NELEMS (comp_table_data) == COMP_TABLE_IDX_END) - 1];
345 static const struct { unsigned int idx; unsigned int len; } comp_table[5] = {
346 { COMP_TABLE_IDX_0300, COMP_TABLE_LEN_0300 },
347 { COMP_TABLE_IDX_0301, COMP_TABLE_LEN_0301 },
348 { COMP_TABLE_IDX_0303, COMP_TABLE_LEN_0303 },
349 { COMP_TABLE_IDX_0309, COMP_TABLE_LEN_0309 },
350 { COMP_TABLE_IDX_0323, COMP_TABLE_LEN_0323 },
353 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
354 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
355 #define MAX_NEEDED_OUTPUT 8
356 #define LOOPFCT FROM_LOOP
357 #define BODY \
359 uint32_t ch = *inptr; \
360 uint32_t last_ch; \
361 int must_buffer_ch; \
363 if (ch >= 0x80) \
365 ch = to_ucs4[ch - 0x80]; \
366 if (__builtin_expect (ch == L'\0', 0)) \
368 /* This is an illegal character. */ \
369 if (! ignore_errors_p ()) \
371 result = __GCONV_ILLEGAL_INPUT; \
372 break; \
375 ++inptr; \
376 ++*irreversible; \
377 continue; \
381 /* Determine whether there is a buffered character pending. */ \
382 last_ch = *statep >> 3; \
384 /* We have to buffer ch if it is a possible match in comp_table_data. */ \
385 must_buffer_ch = (ch >= 0x0041 && ch <= 0x01b0); \
387 if (last_ch) \
389 if (ch >= 0x0300 && ch < 0x0340) \
391 /* See whether last_ch and ch can be combined. */ \
392 unsigned int i, i1, i2; \
394 switch (ch) \
396 case 0x0300: \
397 i = 0; \
398 break; \
399 case 0x0301: \
400 i = 1; \
401 break; \
402 case 0x0303: \
403 i = 2; \
404 break; \
405 case 0x0309: \
406 i = 3; \
407 break; \
408 case 0x0323: \
409 i = 4; \
410 break; \
411 default: \
412 abort (); \
415 i1 = comp_table[i].idx; \
416 i2 = i1 + comp_table[i].len - 1; \
418 if (last_ch >= comp_table_data[i1].base \
419 && last_ch <= comp_table_data[i2].base) \
421 for (;;) \
423 i = (i1 + i2) >> 1; \
424 if (last_ch == comp_table_data[i].base) \
425 break; \
426 if (last_ch < comp_table_data[i].base) \
428 if (i1 == i) \
429 goto not_combining; \
430 i2 = i; \
432 else \
434 if (i1 != i) \
435 i1 = i; \
436 else \
438 i = i2; \
439 if (last_ch == comp_table_data[i].base) \
440 break; \
441 goto not_combining; \
445 last_ch = comp_table_data[i].composed; \
446 /* Output the combined character. */ \
447 put32 (outptr, last_ch); \
448 outptr += 4; \
449 *statep = 0; \
450 ++inptr; \
451 continue; \
455 not_combining: \
456 /* Output the buffered character. */ \
457 put32 (outptr, last_ch); \
458 outptr += 4; \
459 *statep = 0; \
461 /* If we don't have enough room to output ch as well, then deal \
462 with it in another round. */ \
463 if (!must_buffer_ch && __builtin_expect (outptr + 4 > outend, 0)) \
464 continue; \
467 if (must_buffer_ch) \
468 *statep = ch << 3; \
469 else \
471 put32 (outptr, ch); \
472 outptr += 4; \
474 ++inptr; \
476 #define LOOP_NEED_FLAGS
477 #define EXTRA_LOOP_DECLS , int *statep
478 #include <iconv/loop.c>
481 /* Next, define the conversion function from UCS4 to CP1258. */
483 static const unsigned char from_ucs4[] = {
484 #define FROM_IDX_00 0
485 0xc4, 0xc5, 0xc6, 0xc7, /* 0x00c4-0x00c7 */
486 0xc8, 0xc9, 0xca, 0xcb, 0x00, 0xcd, 0xce, 0xcf, /* 0x00c8-0x00cf */
487 0x00, 0xd1, 0x00, 0xd3, 0xd4, 0x00, 0xd6, 0xd7, /* 0x00d0-0x00d7 */
488 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0x00, 0x00, 0xdf, /* 0x00d8-0x00df */
489 0xe0, 0xe1, 0xe2, 0x00, 0xe4, 0xe5, 0xe6, 0xe7, /* 0x00e0-0x00e7 */
490 0xe8, 0xe9, 0xea, 0xeb, 0x00, 0xed, 0xee, 0xef, /* 0x00e8-0x00ef */
491 0x00, 0xf1, 0x00, 0xf3, 0xf4, 0x00, 0xf6, 0xf7, /* 0x00f0-0x00f7 */
492 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0x00, 0x00, 0xff, /* 0x00f8-0x00ff */
493 0x00, 0x00, 0xc3, 0xe3, 0x00, 0x00, 0x00, 0x00, /* 0x0100-0x0107 */
494 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0108-0x010f */
495 0xd0, 0xf0, /* 0x0110-0x0111 */
496 #define FROM_IDX_01 (FROM_IDX_00 + 78)
497 0x8c, 0x9c, 0x00, 0x00, 0x00, 0x00, /* 0x0152-0x0157 */
498 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0158-0x015f */
499 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0160-0x0167 */
500 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0168-0x016f */
501 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0170-0x0177 */
502 0x9f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0178-0x017f */
503 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0180-0x0187 */
504 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0188-0x018f */
505 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0190-0x0197 */
506 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0198-0x019f */
507 0xd5, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x01a0-0x01a7 */
508 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdd, /* 0x01a8-0x01af */
509 0xfd, /* 0x01b0-0x01b0 */
510 #define FROM_IDX_02 (FROM_IDX_01 + 95)
511 0x88, 0x00, /* 0x02c6-0x02c7 */
512 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02c8-0x02cf */
513 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02d0-0x02d7 */
514 0x00, 0x00, 0x00, 0x00, 0x98, /* 0x02d8-0x02dc */
515 #define FROM_IDX_03 (FROM_IDX_02 + 23)
516 0xcc, 0xec, 0x00, 0xde, 0x00, 0x00, 0x00, 0x00, /* 0x0300-0x0307 */
517 0x00, 0xd2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0308-0x030f */
518 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0310-0x0317 */
519 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0318-0x031f */
520 0x00, 0x00, 0x00, 0xf2, /* 0x0320-0x0323 */
521 #define FROM_IDX_20 (FROM_IDX_03 + 36)
522 0x96, 0x97, 0x00, 0x00, 0x00, /* 0x2013-0x2017 */
523 0x91, 0x92, 0x82, 0x00, 0x93, 0x94, 0x84, 0x00, /* 0x2018-0x201f */
524 0x86, 0x87, 0x95, 0x00, 0x00, 0x00, 0x85, 0x00, /* 0x2020-0x2027 */
525 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2028-0x202f */
526 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2030-0x2037 */
527 0x00, 0x8b, 0x9b, /* 0x2038-0x203a */
528 #define FROM_IDX_FF (FROM_IDX_20 + 40)
530 /* Compile-time verification of table size. */
531 typedef int verify2[(NELEMS (from_ucs4) == FROM_IDX_FF) - 1];
533 static const unsigned char comb_table[5] = {
534 0xcc, 0xec, 0xde, 0xd2, 0xf2,
537 /* Decomposition table for the relevant Unicode characters. */
538 static const struct {
539 uint16_t composed;
540 uint32_t base : 12;
541 uint32_t comb1 : 4;
542 } decomp_table[] = {
543 { 0x00c0, 0x0041, 0 },
544 { 0x00c1, 0x0041, 1 },
545 { 0x00c3, 0x0041, 2 },
546 { 0x00c8, 0x0045, 0 },
547 { 0x00c9, 0x0045, 1 },
548 { 0x00cc, 0x0049, 0 },
549 { 0x00cd, 0x0049, 1 },
550 { 0x00d1, 0x004e, 2 },
551 { 0x00d2, 0x004f, 0 },
552 { 0x00d3, 0x004f, 1 },
553 { 0x00d5, 0x004f, 2 },
554 { 0x00d9, 0x0055, 0 },
555 { 0x00da, 0x0055, 1 },
556 { 0x00dd, 0x0059, 1 },
557 { 0x00e0, 0x0061, 0 },
558 { 0x00e1, 0x0061, 1 },
559 { 0x00e3, 0x0061, 2 },
560 { 0x00e8, 0x0065, 0 },
561 { 0x00e9, 0x0065, 1 },
562 { 0x00ec, 0x0069, 0 },
563 { 0x00ed, 0x0069, 1 },
564 { 0x00f1, 0x006e, 2 },
565 { 0x00f2, 0x006f, 0 },
566 { 0x00f3, 0x006f, 1 },
567 { 0x00f5, 0x006f, 2 },
568 { 0x00f9, 0x0075, 0 },
569 { 0x00fa, 0x0075, 1 },
570 { 0x00fd, 0x0079, 1 },
571 { 0x0106, 0x0043, 1 },
572 { 0x0107, 0x0063, 1 },
573 { 0x0128, 0x0049, 2 },
574 { 0x0129, 0x0069, 2 },
575 { 0x0139, 0x004c, 1 },
576 { 0x013a, 0x006c, 1 },
577 { 0x0143, 0x004e, 1 },
578 { 0x0144, 0x006e, 1 },
579 { 0x0154, 0x0052, 1 },
580 { 0x0155, 0x0072, 1 },
581 { 0x015a, 0x0053, 1 },
582 { 0x015b, 0x0073, 1 },
583 { 0x0168, 0x0055, 2 },
584 { 0x0169, 0x0075, 2 },
585 { 0x0179, 0x005a, 1 },
586 { 0x017a, 0x007a, 1 },
587 { 0x01d7, 0x00dc, 1 },
588 { 0x01d8, 0x00fc, 1 },
589 { 0x01db, 0x00dc, 0 },
590 { 0x01dc, 0x00fc, 0 },
591 { 0x01f4, 0x0047, 1 },
592 { 0x01f5, 0x0067, 1 },
593 { 0x01f8, 0x004e, 0 },
594 { 0x01f9, 0x006e, 0 },
595 { 0x01fa, 0x00c5, 1 },
596 { 0x01fb, 0x00e5, 1 },
597 { 0x01fc, 0x00c6, 1 },
598 { 0x01fd, 0x00e6, 1 },
599 { 0x01fe, 0x00d8, 1 },
600 { 0x01ff, 0x00f8, 1 },
601 { 0x0385, 0x00a5, 1 },
602 { 0x1e04, 0x0042, 4 },
603 { 0x1e05, 0x0062, 4 },
604 { 0x1e08, 0x00c7, 1 },
605 { 0x1e09, 0x00e7, 1 },
606 { 0x1e0c, 0x0044, 4 },
607 { 0x1e0d, 0x0064, 4 },
608 { 0x1e24, 0x0048, 4 },
609 { 0x1e25, 0x0068, 4 },
610 { 0x1e2e, 0x00cf, 1 },
611 { 0x1e2f, 0x00ef, 1 },
612 { 0x1e30, 0x004b, 1 },
613 { 0x1e31, 0x006b, 1 },
614 { 0x1e32, 0x004b, 4 },
615 { 0x1e33, 0x006b, 4 },
616 { 0x1e36, 0x004c, 4 },
617 { 0x1e37, 0x006c, 4 },
618 { 0x1e3e, 0x004d, 1 },
619 { 0x1e3f, 0x006d, 1 },
620 { 0x1e42, 0x004d, 4 },
621 { 0x1e43, 0x006d, 4 },
622 { 0x1e46, 0x004e, 4 },
623 { 0x1e47, 0x006e, 4 },
624 { 0x1e4c, 0x00d3, 2 }, /*{ 0x1e4c, 0x00d5, 1 }, { 0x1e4c, 0x004f, 1, 2 },*/
625 { 0x1e4d, 0x00f3, 2 }, /*{ 0x1e4d, 0x00f5, 1 }, { 0x1e4d, 0x006f, 1, 2 },*/
626 { 0x1e4e, 0x00d6, 2 },
627 { 0x1e4f, 0x00f6, 2 },
628 { 0x1e54, 0x0050, 1 },
629 { 0x1e55, 0x0070, 1 },
630 { 0x1e5a, 0x0052, 4 },
631 { 0x1e5b, 0x0072, 4 },
632 { 0x1e62, 0x0053, 4 },
633 { 0x1e63, 0x0073, 4 },
634 { 0x1e6c, 0x0054, 4 },
635 { 0x1e6d, 0x0074, 4 },
636 { 0x1e78, 0x00da, 2 }, /*{ 0x1e78, 0x0168, 1 }, { 0x1e78, 0x0055, 1, 2 },*/
637 { 0x1e79, 0x00fa, 2 }, /*{ 0x1e79, 0x0169, 1 }, { 0x1e79, 0x0075, 1, 2 },*/
638 { 0x1e7c, 0x0056, 2 },
639 { 0x1e7d, 0x0076, 2 },
640 { 0x1e7e, 0x0056, 4 },
641 { 0x1e7f, 0x0076, 4 },
642 { 0x1e80, 0x0057, 0 },
643 { 0x1e81, 0x0077, 0 },
644 { 0x1e82, 0x0057, 1 },
645 { 0x1e83, 0x0077, 1 },
646 { 0x1e88, 0x0057, 4 },
647 { 0x1e89, 0x0077, 4 },
648 { 0x1e92, 0x005a, 4 },
649 { 0x1e93, 0x007a, 4 },
650 { 0x1ea0, 0x0041, 4 },
651 { 0x1ea1, 0x0061, 4 },
652 { 0x1ea2, 0x0041, 3 },
653 { 0x1ea3, 0x0061, 3 },
654 { 0x1ea4, 0x00c2, 1 },
655 { 0x1ea5, 0x00e2, 1 },
656 { 0x1ea6, 0x00c2, 0 },
657 { 0x1ea7, 0x00e2, 0 },
658 { 0x1ea8, 0x00c2, 3 },
659 { 0x1ea9, 0x00e2, 3 },
660 { 0x1eaa, 0x00c2, 2 },
661 { 0x1eab, 0x00e2, 2 },
662 { 0x1eac, 0x00c2, 4 },
663 { 0x1ead, 0x00e2, 4 },
664 { 0x1eae, 0x0102, 1 },
665 { 0x1eaf, 0x0103, 1 },
666 { 0x1eb0, 0x0102, 0 },
667 { 0x1eb1, 0x0103, 0 },
668 { 0x1eb2, 0x0102, 3 },
669 { 0x1eb3, 0x0103, 3 },
670 { 0x1eb4, 0x0102, 2 },
671 { 0x1eb5, 0x0103, 2 },
672 { 0x1eb6, 0x0102, 4 },
673 { 0x1eb7, 0x0103, 4 },
674 { 0x1eb8, 0x0045, 4 },
675 { 0x1eb9, 0x0065, 4 },
676 { 0x1eba, 0x0045, 3 },
677 { 0x1ebb, 0x0065, 3 },
678 { 0x1ebc, 0x0045, 2 },
679 { 0x1ebd, 0x0065, 2 },
680 { 0x1ebe, 0x00ca, 1 },
681 { 0x1ebf, 0x00ea, 1 },
682 { 0x1ec0, 0x00ca, 0 },
683 { 0x1ec1, 0x00ea, 0 },
684 { 0x1ec2, 0x00ca, 3 },
685 { 0x1ec3, 0x00ea, 3 },
686 { 0x1ec4, 0x00ca, 2 },
687 { 0x1ec5, 0x00ea, 2 },
688 { 0x1ec6, 0x00ca, 4 },
689 { 0x1ec7, 0x00ea, 4 },
690 { 0x1ec8, 0x0049, 3 },
691 { 0x1ec9, 0x0069, 3 },
692 { 0x1eca, 0x0049, 4 },
693 { 0x1ecb, 0x0069, 4 },
694 { 0x1ecc, 0x004f, 4 },
695 { 0x1ecd, 0x006f, 4 },
696 { 0x1ece, 0x004f, 3 },
697 { 0x1ecf, 0x006f, 3 },
698 { 0x1ed0, 0x00d4, 1 },
699 { 0x1ed1, 0x00f4, 1 },
700 { 0x1ed2, 0x00d4, 0 },
701 { 0x1ed3, 0x00f4, 0 },
702 { 0x1ed4, 0x00d4, 3 },
703 { 0x1ed5, 0x00f4, 3 },
704 { 0x1ed6, 0x00d4, 2 },
705 { 0x1ed7, 0x00f4, 2 },
706 { 0x1ed8, 0x00d4, 4 },
707 { 0x1ed9, 0x00f4, 4 },
708 { 0x1eda, 0x01a0, 1 },
709 { 0x1edb, 0x01a1, 1 },
710 { 0x1edc, 0x01a0, 0 },
711 { 0x1edd, 0x01a1, 0 },
712 { 0x1ede, 0x01a0, 3 },
713 { 0x1edf, 0x01a1, 3 },
714 { 0x1ee0, 0x01a0, 2 },
715 { 0x1ee1, 0x01a1, 2 },
716 { 0x1ee2, 0x01a0, 4 },
717 { 0x1ee3, 0x01a1, 4 },
718 { 0x1ee4, 0x0055, 4 },
719 { 0x1ee5, 0x0075, 4 },
720 { 0x1ee6, 0x0055, 3 },
721 { 0x1ee7, 0x0075, 3 },
722 { 0x1ee8, 0x01af, 1 },
723 { 0x1ee9, 0x01b0, 1 },
724 { 0x1eea, 0x01af, 0 },
725 { 0x1eeb, 0x01b0, 0 },
726 { 0x1eec, 0x01af, 3 },
727 { 0x1eed, 0x01b0, 3 },
728 { 0x1eee, 0x01af, 2 },
729 { 0x1eef, 0x01b0, 2 },
730 { 0x1ef0, 0x01af, 4 },
731 { 0x1ef1, 0x01b0, 4 },
732 { 0x1ef2, 0x0059, 0 },
733 { 0x1ef3, 0x0079, 0 },
734 { 0x1ef4, 0x0059, 4 },
735 { 0x1ef5, 0x0079, 4 },
736 { 0x1ef6, 0x0059, 3 },
737 { 0x1ef7, 0x0079, 3 },
738 { 0x1ef8, 0x0059, 2 },
739 { 0x1ef9, 0x0079, 2 },
740 { 0x1fed, 0x00a8, 0 },
741 { 0x1fee, 0x00a8, 1 },
744 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
745 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
746 #define MAX_NEEDED_OUTPUT 2
747 #define LOOPFCT TO_LOOP
748 #define BODY \
750 uint32_t ch = get32 (inptr); \
752 if (ch < 0x0080 || (ch >= 0x00a0 && ch < 0x00c3)) \
754 *outptr++ = ch; \
755 inptr += 4; \
757 else \
759 unsigned char res; \
761 if (ch >= 0x00c4 && ch < 0x0112) \
762 res = from_ucs4[ch - 0x00c4 + FROM_IDX_00]; \
763 else if (ch >= 0x0152 && ch < 0x01b1) \
764 res = from_ucs4[ch - 0x0152 + FROM_IDX_01]; \
765 else if (ch >= 0x02c6 && ch < 0x02dd) \
766 res = from_ucs4[ch - 0x02c6 + FROM_IDX_02]; \
767 else if (ch >= 0x0300 && ch < 0x0324) \
768 res = from_ucs4[ch - 0x0300 + FROM_IDX_03]; \
769 else if (ch >= 0x0340 && ch < 0x0342) /* Vietnamese tone marks */ \
770 res = from_ucs4[ch - 0x0340 + FROM_IDX_03]; \
771 else if (ch >= 0x2013 && ch < 0x203b) \
772 res = from_ucs4[ch - 0x2013 + FROM_IDX_20]; \
773 else if (ch == 0x20ab) \
774 res = 0xfe; \
775 else if (ch == 0x20ac) \
776 res = 0x80; \
777 else if (ch == 0x2122) \
778 res = 0x99; \
779 else \
781 UNICODE_TAG_HANDLER (ch, 4); \
782 res = 0; \
785 if (__builtin_expect (res != 0, 1)) \
787 *outptr++ = res; \
788 inptr += 4; \
790 else \
792 /* Try canonical decomposition. */ \
793 unsigned int i1, i2; \
795 i1 = 0; \
796 i2 = sizeof (decomp_table) / sizeof (decomp_table[0]) - 1; \
797 if (ch >= decomp_table[i1].composed \
798 && ch <= decomp_table[i2].composed) \
800 unsigned int i; \
802 for (;;) \
804 i = (i1 + i2) >> 1; \
805 if (ch == decomp_table[i].composed) \
806 break; \
807 if (ch < decomp_table[i].composed) \
809 if (i1 == i) \
810 goto failed; \
811 i2 = i; \
813 else \
815 if (i1 != i) \
816 i1 = i; \
817 else \
819 i = i2; \
820 if (ch == decomp_table[i].composed) \
821 break; \
822 goto failed; \
827 /* Found a canonical decomposition. */ \
828 ch = decomp_table[i].base; \
829 /* ch is one of 0x0020, 0x0041..0x005a, 0x0061..0x007a, \
830 0x00a5, 0x00a8, 0x00c2, 0x00c5..0x00c7, 0x00ca, 0x00cf, \
831 0x00d3, 0x00d4, 0x00d6, 0x00d8, 0x00da, 0x00dc, 0x00e2, \
832 0x00e5..0x00e7, 0x00ea, 0x00ef, 0x00f3, 0x00f4, 0x00f6, \
833 0x00f8, 0x00fc, 0x0102, 0x0103, 0x01a0, 0x01a1, 0x01af, \
834 0x01b0. */ \
835 if (ch >= 0x0100) \
837 if (ch < 0x0112) \
838 ch = from_ucs4[ch - 0x00c4 + FROM_IDX_00]; \
839 else \
840 ch = from_ucs4[ch - 0x0152 + FROM_IDX_01]; \
842 assert (ch != 0); \
844 /* See whether we have room for two bytes. */ \
845 if (__builtin_expect (outptr + 1 >= outend, 0)) \
847 result = __GCONV_FULL_OUTPUT; \
848 break; \
851 *outptr++ = (unsigned char) ch; \
852 *outptr++ = comb_table[decomp_table[i].comb1]; \
853 inptr += 4; \
854 continue; \
857 failed: \
858 /* This is an illegal character. */ \
859 STANDARD_ERR_HANDLER (4); \
863 #define LOOP_NEED_FLAGS
864 #define EXTRA_LOOP_DECLS , int *statep
865 #include <iconv/loop.c>
868 /* Now define the toplevel functions. */
869 #include <iconv/skeleton.c>