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