lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* Conversion from and to CP1255. |
| 2 | Copyright (C) 1998-2015 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 | <http://www.gnu.org/licenses/>. */ |
| 20 | |
| 21 | #include <dlfcn.h> |
| 22 | #include <stdint.h> |
| 23 | #include <assert.h> |
| 24 | |
| 25 | #define NELEMS(arr) (sizeof (arr) / sizeof (arr[0])) |
| 26 | |
| 27 | /* Definitions used in the body of the `gconv' function. */ |
| 28 | #define CHARSET_NAME "CP1255//" |
| 29 | #define FROM_LOOP from_cp1255 |
| 30 | #define TO_LOOP to_cp1255 |
| 31 | #define DEFINE_INIT 1 |
| 32 | #define DEFINE_FINI 1 |
| 33 | #define ONE_DIRECTION 0 |
| 34 | #define FROM_LOOP_MIN_NEEDED_FROM 1 |
| 35 | #define FROM_LOOP_MAX_NEEDED_FROM 1 |
| 36 | #define FROM_LOOP_MIN_NEEDED_TO 4 |
| 37 | #define FROM_LOOP_MAX_NEEDED_TO 4 |
| 38 | #define TO_LOOP_MIN_NEEDED_FROM 4 |
| 39 | #define TO_LOOP_MAX_NEEDED_FROM 4 |
| 40 | #define TO_LOOP_MIN_NEEDED_TO 1 |
| 41 | #define TO_LOOP_MAX_NEEDED_TO 3 |
| 42 | #define PREPARE_LOOP \ |
| 43 | int saved_state; \ |
| 44 | int *statep = &data->__statep->__count; |
| 45 | #define EXTRA_LOOP_ARGS , statep |
| 46 | |
| 47 | |
| 48 | /* Since we might have to reset input pointer we must be able to save |
| 49 | and restore the state. */ |
| 50 | #define SAVE_RESET_STATE(Save) \ |
| 51 | if (Save) \ |
| 52 | saved_state = *statep; \ |
| 53 | else \ |
| 54 | *statep = saved_state |
| 55 | |
| 56 | |
| 57 | /* During CP1255 to UCS4 conversion, the COUNT element of the state |
| 58 | contains the last UCS4 character, shifted by 3 bits. */ |
| 59 | |
| 60 | |
| 61 | /* Since this is a stateful encoding we have to provide code which resets |
| 62 | the output state to the initial state. This has to be done during the |
| 63 | flushing. */ |
| 64 | #define EMIT_SHIFT_TO_INIT \ |
| 65 | if (data->__statep->__count != 0) \ |
| 66 | { \ |
| 67 | if (FROM_DIRECTION) \ |
| 68 | { \ |
| 69 | if (__glibc_likely (outbuf + 4 <= outend)) \ |
| 70 | { \ |
| 71 | /* Write out the last character. */ \ |
| 72 | *((uint32_t *) outbuf) = data->__statep->__count >> 3; \ |
| 73 | outbuf += sizeof (uint32_t); \ |
| 74 | data->__statep->__count = 0; \ |
| 75 | } \ |
| 76 | else \ |
| 77 | /* We don't have enough room in the output buffer. */ \ |
| 78 | status = __GCONV_FULL_OUTPUT; \ |
| 79 | } \ |
| 80 | else \ |
| 81 | /* We don't use shift states in the TO_DIRECTION. */ \ |
| 82 | data->__statep->__count = 0; \ |
| 83 | } |
| 84 | |
| 85 | |
| 86 | /* First define the conversion function from CP1255 to UCS4. */ |
| 87 | |
| 88 | static const uint16_t to_ucs4[128] = { |
| 89 | /* 0x80 */ |
| 90 | 0x20AC, 0, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, |
| 91 | 0x02C6, 0x2030, 0, 0x2039, 0, 0, 0, 0, |
| 92 | /* 0x90 */ |
| 93 | 0, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, |
| 94 | 0x02DC, 0x2122, 0, 0x203A, 0, 0, 0, 0, |
| 95 | /* 0xA0 */ |
| 96 | 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AA, 0x00A5, 0x00A6, 0x00A7, |
| 97 | 0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, |
| 98 | /* 0xB0 */ |
| 99 | 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, |
| 100 | 0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, |
| 101 | /* 0xC0 */ |
| 102 | 0x05B0, 0x05B1, 0x05B2, 0x05B3, 0x05B4, 0x05B5, 0x05B6, 0x05B7, |
| 103 | 0x05B8, 0x05B9, 0, 0x05BB, 0x05BC, 0x05BD, 0x05BE, 0x05BF, |
| 104 | /* 0xD0 */ |
| 105 | 0x05C0, 0x05C1, 0x05C2, 0x05C3, 0x05F0, 0x05F1, 0x05F2, 0x05F3, |
| 106 | 0x05F4, 0, 0, 0, 0, 0, 0, 0, |
| 107 | /* 0xE0 */ |
| 108 | 0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7, |
| 109 | 0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF, |
| 110 | /* 0xF0 */ |
| 111 | 0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7, |
| 112 | 0x05E8, 0x05E9, 0x05EA, 0, 0, 0x200E, 0x200F, 0, |
| 113 | }; |
| 114 | |
| 115 | /* CP1255 contains eight combining characters: |
| 116 | 0x05b4, 0x05b7, 0x05b8, 0x05b9, 0x05bc, 0x05bf, 0x05c1, 0x05c2. */ |
| 117 | |
| 118 | /* Composition tables for each of the relevant combining characters. */ |
| 119 | static const struct { |
| 120 | uint16_t base; |
| 121 | uint16_t composed; |
| 122 | } comp_table_data[] = { |
| 123 | #define COMP_TABLE_IDX_05B4 0 |
| 124 | #define COMP_TABLE_LEN_05B4 1 |
| 125 | { 0x05D9, 0xFB1D }, |
| 126 | #define COMP_TABLE_IDX_05B7 (COMP_TABLE_IDX_05B4 + COMP_TABLE_LEN_05B4) |
| 127 | #define COMP_TABLE_LEN_05B7 2 |
| 128 | { 0x05D0, 0xFB2E }, |
| 129 | { 0x05F2, 0xFB1F }, |
| 130 | #define COMP_TABLE_IDX_05B8 (COMP_TABLE_IDX_05B7 + COMP_TABLE_LEN_05B7) |
| 131 | #define COMP_TABLE_LEN_05B8 1 |
| 132 | { 0x05D0, 0xFB2F }, |
| 133 | #define COMP_TABLE_IDX_05B9 (COMP_TABLE_IDX_05B8 + COMP_TABLE_LEN_05B8) |
| 134 | #define COMP_TABLE_LEN_05B9 1 |
| 135 | { 0x05D5, 0xFB4B }, |
| 136 | #define COMP_TABLE_IDX_05BC (COMP_TABLE_IDX_05B9 + COMP_TABLE_LEN_05B9) |
| 137 | #define COMP_TABLE_LEN_05BC 24 |
| 138 | { 0x05D0, 0xFB30 }, |
| 139 | { 0x05D1, 0xFB31 }, |
| 140 | { 0x05D2, 0xFB32 }, |
| 141 | { 0x05D3, 0xFB33 }, |
| 142 | { 0x05D4, 0xFB34 }, |
| 143 | { 0x05D5, 0xFB35 }, |
| 144 | { 0x05D6, 0xFB36 }, |
| 145 | { 0x05D8, 0xFB38 }, |
| 146 | { 0x05D9, 0xFB39 }, |
| 147 | { 0x05DA, 0xFB3A }, |
| 148 | { 0x05DB, 0xFB3B }, |
| 149 | { 0x05DC, 0xFB3C }, |
| 150 | { 0x05DE, 0xFB3E }, |
| 151 | { 0x05E0, 0xFB40 }, |
| 152 | { 0x05E1, 0xFB41 }, |
| 153 | { 0x05E3, 0xFB43 }, |
| 154 | { 0x05E4, 0xFB44 }, |
| 155 | { 0x05E6, 0xFB46 }, |
| 156 | { 0x05E7, 0xFB47 }, |
| 157 | { 0x05E8, 0xFB48 }, |
| 158 | { 0x05E9, 0xFB49 }, |
| 159 | { 0x05EA, 0xFB4A }, |
| 160 | { 0xFB2A, 0xFB2C }, |
| 161 | { 0xFB2B, 0xFB2D }, |
| 162 | #define COMP_TABLE_IDX_05BF (COMP_TABLE_IDX_05BC + COMP_TABLE_LEN_05BC) |
| 163 | #define COMP_TABLE_LEN_05BF 3 |
| 164 | { 0x05D1, 0xFB4C }, |
| 165 | { 0x05DB, 0xFB4D }, |
| 166 | { 0x05E4, 0xFB4E }, |
| 167 | #define COMP_TABLE_IDX_05C1 (COMP_TABLE_IDX_05BF + COMP_TABLE_LEN_05BF) |
| 168 | #define COMP_TABLE_LEN_05C1 2 |
| 169 | { 0x05E9, 0xFB2A }, |
| 170 | { 0xFB49, 0xFB2C }, |
| 171 | #define COMP_TABLE_IDX_05C2 (COMP_TABLE_IDX_05C1 + COMP_TABLE_LEN_05C1) |
| 172 | #define COMP_TABLE_LEN_05C2 2 |
| 173 | { 0x05E9, 0xFB2B }, |
| 174 | { 0xFB49, 0xFB2D }, |
| 175 | #define COMP_TABLE_IDX_END (COMP_TABLE_IDX_05C2 + COMP_TABLE_LEN_05C2) |
| 176 | }; |
| 177 | /* Compile-time verification of table size. */ |
| 178 | typedef int verify1[(NELEMS (comp_table_data) == COMP_TABLE_IDX_END) - 1]; |
| 179 | |
| 180 | static const struct { unsigned int idx; unsigned int len; } comp_table[8] = { |
| 181 | { COMP_TABLE_IDX_05B4, COMP_TABLE_LEN_05B4 }, |
| 182 | { COMP_TABLE_IDX_05B7, COMP_TABLE_LEN_05B7 }, |
| 183 | { COMP_TABLE_IDX_05B8, COMP_TABLE_LEN_05B8 }, |
| 184 | { COMP_TABLE_IDX_05B9, COMP_TABLE_LEN_05B9 }, |
| 185 | { COMP_TABLE_IDX_05BC, COMP_TABLE_LEN_05BC }, |
| 186 | { COMP_TABLE_IDX_05BF, COMP_TABLE_LEN_05BF }, |
| 187 | { COMP_TABLE_IDX_05C1, COMP_TABLE_LEN_05C1 }, |
| 188 | { COMP_TABLE_IDX_05C2, COMP_TABLE_LEN_05C2 }, |
| 189 | }; |
| 190 | |
| 191 | #define MIN_NEEDED_INPUT FROM_LOOP_MIN_NEEDED_FROM |
| 192 | #define MAX_NEEDED_INPUT FROM_LOOP_MAX_NEEDED_FROM |
| 193 | #define MIN_NEEDED_OUTPUT FROM_LOOP_MIN_NEEDED_TO |
| 194 | #define MAX_NEEDED_OUTPUT FROM_LOOP_MAX_NEEDED_TO |
| 195 | #define LOOPFCT FROM_LOOP |
| 196 | #define BODY \ |
| 197 | { \ |
| 198 | uint32_t ch = *inptr; \ |
| 199 | uint32_t last_ch; \ |
| 200 | int must_buffer_ch; \ |
| 201 | \ |
| 202 | if (ch >= 0x80) \ |
| 203 | { \ |
| 204 | ch = to_ucs4[ch - 0x80]; \ |
| 205 | if (__glibc_unlikely (ch == L'\0')) \ |
| 206 | { \ |
| 207 | /* This is an illegal character. */ \ |
| 208 | STANDARD_FROM_LOOP_ERR_HANDLER (1); \ |
| 209 | } \ |
| 210 | } \ |
| 211 | \ |
| 212 | /* Determine whether there is a buffered character pending. */ \ |
| 213 | last_ch = *statep >> 3; \ |
| 214 | \ |
| 215 | /* We have to buffer ch if it is a possible match in comp_table_data. */ \ |
| 216 | must_buffer_ch = (ch >= 0x05d0 && ch <= 0x05f2); \ |
| 217 | \ |
| 218 | if (last_ch) \ |
| 219 | { \ |
| 220 | if (ch >= 0x05b0 && ch < 0x05c5) \ |
| 221 | { \ |
| 222 | /* See whether last_ch and ch can be combined. */ \ |
| 223 | unsigned int i, i1, i2; \ |
| 224 | \ |
| 225 | switch (ch) \ |
| 226 | { \ |
| 227 | case 0x05b4: \ |
| 228 | i = 0; \ |
| 229 | break; \ |
| 230 | case 0x05b7: \ |
| 231 | i = 1; \ |
| 232 | break; \ |
| 233 | case 0x05b8: \ |
| 234 | i = 2; \ |
| 235 | break; \ |
| 236 | case 0x05b9: \ |
| 237 | i = 3; \ |
| 238 | break; \ |
| 239 | case 0x05bc: \ |
| 240 | i = 4; \ |
| 241 | break; \ |
| 242 | case 0x05bf: \ |
| 243 | i = 5; \ |
| 244 | break; \ |
| 245 | case 0x05c1: \ |
| 246 | i = 6; \ |
| 247 | break; \ |
| 248 | case 0x05c2: \ |
| 249 | i = 7; \ |
| 250 | break; \ |
| 251 | default: \ |
| 252 | goto not_combining; \ |
| 253 | } \ |
| 254 | \ |
| 255 | i1 = comp_table[i].idx; \ |
| 256 | i2 = i1 + comp_table[i].len - 1; \ |
| 257 | \ |
| 258 | if (last_ch >= comp_table_data[i1].base \ |
| 259 | && last_ch <= comp_table_data[i2].base) \ |
| 260 | { \ |
| 261 | for (;;) \ |
| 262 | { \ |
| 263 | i = (i1 + i2) >> 1; \ |
| 264 | if (last_ch == comp_table_data[i].base) \ |
| 265 | break; \ |
| 266 | if (last_ch < comp_table_data[i].base) \ |
| 267 | { \ |
| 268 | if (i1 == i) \ |
| 269 | goto not_combining; \ |
| 270 | i2 = i; \ |
| 271 | } \ |
| 272 | else \ |
| 273 | { \ |
| 274 | if (i1 != i) \ |
| 275 | i1 = i; \ |
| 276 | else \ |
| 277 | { \ |
| 278 | i = i2; \ |
| 279 | if (last_ch == comp_table_data[i].base) \ |
| 280 | break; \ |
| 281 | goto not_combining; \ |
| 282 | } \ |
| 283 | } \ |
| 284 | } \ |
| 285 | last_ch = comp_table_data[i].composed; \ |
| 286 | if (last_ch == 0xfb2a || last_ch == 0xfb2b \ |
| 287 | || last_ch == 0xfb49) \ |
| 288 | /* Buffer the combined character. */ \ |
| 289 | *statep = last_ch << 3; \ |
| 290 | else \ |
| 291 | { \ |
| 292 | /* Output the combined character. */ \ |
| 293 | put32 (outptr, last_ch); \ |
| 294 | outptr += 4; \ |
| 295 | *statep = 0; \ |
| 296 | } \ |
| 297 | ++inptr; \ |
| 298 | continue; \ |
| 299 | } \ |
| 300 | } \ |
| 301 | \ |
| 302 | not_combining: \ |
| 303 | /* Output the buffered character. */ \ |
| 304 | put32 (outptr, last_ch); \ |
| 305 | outptr += 4; \ |
| 306 | *statep = 0; \ |
| 307 | \ |
| 308 | /* If we don't have enough room to output ch as well, then deal \ |
| 309 | with it in another round. */ \ |
| 310 | if (!must_buffer_ch && __builtin_expect (outptr + 4 > outend, 0)) \ |
| 311 | continue; \ |
| 312 | } \ |
| 313 | \ |
| 314 | if (must_buffer_ch) \ |
| 315 | *statep = ch << 3; \ |
| 316 | else \ |
| 317 | { \ |
| 318 | put32 (outptr, ch); \ |
| 319 | outptr += 4; \ |
| 320 | } \ |
| 321 | ++inptr; \ |
| 322 | } |
| 323 | #define LOOP_NEED_FLAGS |
| 324 | #define EXTRA_LOOP_DECLS , int *statep |
| 325 | #define ONEBYTE_BODY \ |
| 326 | { \ |
| 327 | if (c < 0x80) \ |
| 328 | return c; \ |
| 329 | uint32_t ch = to_ucs4[c - 0x80]; \ |
| 330 | if (ch == L'\0' || (ch >= 0x05d0 && ch <= 0x05f2)) \ |
| 331 | return WEOF; \ |
| 332 | return ch; \ |
| 333 | } |
| 334 | #include <iconv/loop.c> |
| 335 | |
| 336 | |
| 337 | /* Next, define the conversion function from UCS4 to CP1255. */ |
| 338 | |
| 339 | static const unsigned char from_ucs4[] = { |
| 340 | #define FROM_IDX_00 0 |
| 341 | 0xa0, 0xa1, 0xa2, 0xa3, 0x00, 0xa5, 0xa6, 0xa7, /* 0x00a0-0x00a7 */ |
| 342 | 0xa8, 0xa9, 0x00, 0xab, 0xac, 0xad, 0xae, 0xaf, /* 0x00a8-0x00af */ |
| 343 | 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, /* 0x00b0-0x00b7 */ |
| 344 | 0xb8, 0xb9, 0x00, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, /* 0x00b8-0x00bf */ |
| 345 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00c0-0x00c7 */ |
| 346 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00c8-0x00cf */ |
| 347 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, /* 0x00d0-0x00d7 */ |
| 348 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00d8-0x00df */ |
| 349 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00e0-0x00e7 */ |
| 350 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00e8-0x00ef */ |
| 351 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xba, /* 0x00f0-0x00f7 */ |
| 352 | #define FROM_IDX_02 (FROM_IDX_00 + 88) |
| 353 | 0x88, 0x00, /* 0x02c6-0x02c7 */ |
| 354 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02c8-0x02cf */ |
| 355 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02d0-0x02d7 */ |
| 356 | 0x00, 0x00, 0x00, 0x00, 0x98, /* 0x02d8-0x02dc */ |
| 357 | #define FROM_IDX_05 (FROM_IDX_02 + 23) |
| 358 | 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* 0x05b0-0x05b7 */ |
| 359 | 0xc8, 0xc9, 0x00, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, /* 0x05b8-0x05bf */ |
| 360 | 0xd0, 0xd1, 0xd2, 0xd3, 0x00, 0x00, 0x00, 0x00, /* 0x05c0-0x05c7 */ |
| 361 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x05c8-0x05cf */ |
| 362 | 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, /* 0x05d0-0x05d7 */ |
| 363 | 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, /* 0x05d8-0x05df */ |
| 364 | 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, /* 0x05e0-0x05e7 */ |
| 365 | 0xf8, 0xf9, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x05e8-0x05ef */ |
| 366 | 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, /* 0x05f0-0x05f4 */ |
| 367 | #define FROM_IDX_20 (FROM_IDX_05 + 69) |
| 368 | 0xfd, 0xfe, /* 0x200e-0x200f */ |
| 369 | 0x00, 0x00, 0x00, 0x96, 0x97, 0x00, 0x00, 0x00, /* 0x2010-0x2017 */ |
| 370 | 0x91, 0x92, 0x82, 0x00, 0x93, 0x94, 0x84, 0x00, /* 0x2018-0x201f */ |
| 371 | 0x86, 0x87, 0x95, 0x00, 0x00, 0x00, 0x85, 0x00, /* 0x2020-0x2027 */ |
| 372 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2028-0x202f */ |
| 373 | 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2030-0x2037 */ |
| 374 | 0x00, 0x8b, 0x9b, /* 0x2038-0x203a */ |
| 375 | #define FROM_IDX_FF (FROM_IDX_20 + 45) |
| 376 | }; |
| 377 | /* Compile-time verification of table size. */ |
| 378 | typedef int verify2[(NELEMS (from_ucs4) == FROM_IDX_FF) - 1]; |
| 379 | |
| 380 | static const unsigned char comb_table[8] = { |
| 381 | 0xc4, 0xc7, 0xc8, 0xc9, 0xcc, 0xcf, 0xd1, 0xd2, |
| 382 | }; |
| 383 | |
| 384 | /* Decomposition table for the relevant Unicode characters. */ |
| 385 | static const struct { |
| 386 | uint16_t composed; |
| 387 | uint16_t base; |
| 388 | uint32_t comb1 : 8; |
| 389 | int32_t comb2 : 8; |
| 390 | } decomp_table[] = { |
| 391 | { 0xFB1D, 0x05D9, 0, -1 }, |
| 392 | { 0xFB1F, 0x05F2, 1, -1 }, |
| 393 | { 0xFB2A, 0x05E9, 6, -1 }, |
| 394 | { 0xFB2B, 0x05E9, 7, -1 }, |
| 395 | { 0xFB2C, 0x05E9, 4, 6 }, |
| 396 | { 0xFB2D, 0x05E9, 4, 7 }, |
| 397 | { 0xFB2E, 0x05D0, 1, -1 }, |
| 398 | { 0xFB2F, 0x05D0, 2, -1 }, |
| 399 | { 0xFB30, 0x05D0, 4, -1 }, |
| 400 | { 0xFB31, 0x05D1, 4, -1 }, |
| 401 | { 0xFB32, 0x05D2, 4, -1 }, |
| 402 | { 0xFB33, 0x05D3, 4, -1 }, |
| 403 | { 0xFB34, 0x05D4, 4, -1 }, |
| 404 | { 0xFB35, 0x05D5, 4, -1 }, |
| 405 | { 0xFB36, 0x05D6, 4, -1 }, |
| 406 | { 0xFB38, 0x05D8, 4, -1 }, |
| 407 | { 0xFB39, 0x05D9, 4, -1 }, |
| 408 | { 0xFB3A, 0x05DA, 4, -1 }, |
| 409 | { 0xFB3B, 0x05DB, 4, -1 }, |
| 410 | { 0xFB3C, 0x05DC, 4, -1 }, |
| 411 | { 0xFB3E, 0x05DE, 4, -1 }, |
| 412 | { 0xFB40, 0x05E0, 4, -1 }, |
| 413 | { 0xFB41, 0x05E1, 4, -1 }, |
| 414 | { 0xFB43, 0x05E3, 4, -1 }, |
| 415 | { 0xFB44, 0x05E4, 4, -1 }, |
| 416 | { 0xFB46, 0x05E6, 4, -1 }, |
| 417 | { 0xFB47, 0x05E7, 4, -1 }, |
| 418 | { 0xFB48, 0x05E8, 4, -1 }, |
| 419 | { 0xFB49, 0x05E9, 4, -1 }, |
| 420 | { 0xFB4A, 0x05EA, 4, -1 }, |
| 421 | { 0xFB4B, 0x05D5, 3, -1 }, |
| 422 | { 0xFB4C, 0x05D1, 5, -1 }, |
| 423 | { 0xFB4D, 0x05DB, 5, -1 }, |
| 424 | { 0xFB4E, 0x05E4, 5, -1 }, |
| 425 | }; |
| 426 | |
| 427 | #define MIN_NEEDED_INPUT TO_LOOP_MIN_NEEDED_FROM |
| 428 | #define MAX_NEEDED_INPUT TO_LOOP_MAX_NEEDED_FROM |
| 429 | #define MIN_NEEDED_OUTPUT TO_LOOP_MIN_NEEDED_TO |
| 430 | #define MAX_NEEDED_OUTPUT TO_LOOP_MAX_NEEDED_TO |
| 431 | #define LOOPFCT TO_LOOP |
| 432 | #define BODY \ |
| 433 | { \ |
| 434 | uint32_t ch = get32 (inptr); \ |
| 435 | \ |
| 436 | if (ch < 0x0080) \ |
| 437 | { \ |
| 438 | *outptr++ = ch; \ |
| 439 | inptr += 4; \ |
| 440 | } \ |
| 441 | else \ |
| 442 | { \ |
| 443 | unsigned char res; \ |
| 444 | \ |
| 445 | if (ch >= 0x00a0 && ch < 0x00f8) \ |
| 446 | res = from_ucs4[ch - 0x00a0 + FROM_IDX_00]; \ |
| 447 | else if (ch == 0x0192) \ |
| 448 | res = 0x83; \ |
| 449 | else if (ch >= 0x02c6 && ch < 0x02dd) \ |
| 450 | res = from_ucs4[ch - 0x02c6 + FROM_IDX_02]; \ |
| 451 | else if (ch >= 0x05b0 && ch < 0x05f5) \ |
| 452 | res = from_ucs4[ch - 0x05b0 + FROM_IDX_05]; \ |
| 453 | else if (ch >= 0x200e && ch < 0x203b) \ |
| 454 | res = from_ucs4[ch - 0x200e + FROM_IDX_20]; \ |
| 455 | else if (ch == 0x20aa) \ |
| 456 | res = 0xa4; \ |
| 457 | else if (ch == 0x20ac) \ |
| 458 | res = 0x80; \ |
| 459 | else if (ch == 0x2122) \ |
| 460 | res = 0x99; \ |
| 461 | else \ |
| 462 | { \ |
| 463 | UNICODE_TAG_HANDLER (ch, 4); \ |
| 464 | res = 0; \ |
| 465 | } \ |
| 466 | \ |
| 467 | if (__glibc_likely (res != 0)) \ |
| 468 | { \ |
| 469 | *outptr++ = res; \ |
| 470 | inptr += 4; \ |
| 471 | } \ |
| 472 | else \ |
| 473 | { \ |
| 474 | /* Try canonical decomposition. */ \ |
| 475 | unsigned int i1, i2; \ |
| 476 | \ |
| 477 | i1 = 0; \ |
| 478 | i2 = sizeof (decomp_table) / sizeof (decomp_table[0]) - 1; \ |
| 479 | if (ch >= decomp_table[i1].composed \ |
| 480 | && ch <= decomp_table[i2].composed) \ |
| 481 | { \ |
| 482 | unsigned int i; \ |
| 483 | \ |
| 484 | for (;;) \ |
| 485 | { \ |
| 486 | i = (i1 + i2) >> 1; \ |
| 487 | if (ch == decomp_table[i].composed) \ |
| 488 | break; \ |
| 489 | if (ch < decomp_table[i].composed) \ |
| 490 | { \ |
| 491 | if (i1 == i) \ |
| 492 | goto failed; \ |
| 493 | i2 = i; \ |
| 494 | } \ |
| 495 | else \ |
| 496 | { \ |
| 497 | if (i1 != i) \ |
| 498 | i1 = i; \ |
| 499 | else \ |
| 500 | { \ |
| 501 | i = i2; \ |
| 502 | if (ch == decomp_table[i].composed) \ |
| 503 | break; \ |
| 504 | goto failed; \ |
| 505 | } \ |
| 506 | } \ |
| 507 | } \ |
| 508 | \ |
| 509 | /* Found a canonical decomposition. */ \ |
| 510 | ch = decomp_table[i].base; \ |
| 511 | /* ch is one of 0x05d0..0x05d6, 0x05d8..0x05dc, 0x05de, \ |
| 512 | 0x05e0..0x05e1, 0x05e3..0x05e4, 0x05e6..0x05ea, 0x05f2. */ \ |
| 513 | ch = from_ucs4[ch - 0x05b0 + FROM_IDX_05]; \ |
| 514 | assert (ch != 0); \ |
| 515 | \ |
| 516 | if (decomp_table[i].comb2 < 0) \ |
| 517 | { \ |
| 518 | /* See whether we have room for two bytes. */ \ |
| 519 | if (__glibc_unlikely (outptr + 1 >= outend)) \ |
| 520 | { \ |
| 521 | result = __GCONV_FULL_OUTPUT; \ |
| 522 | break; \ |
| 523 | } \ |
| 524 | \ |
| 525 | *outptr++ = (unsigned char) ch; \ |
| 526 | *outptr++ = comb_table[decomp_table[i].comb1]; \ |
| 527 | } \ |
| 528 | else \ |
| 529 | { \ |
| 530 | /* See whether we have room for three bytes. */ \ |
| 531 | if (__glibc_unlikely (outptr + 2 >= outend)) \ |
| 532 | { \ |
| 533 | result = __GCONV_FULL_OUTPUT; \ |
| 534 | break; \ |
| 535 | } \ |
| 536 | \ |
| 537 | *outptr++ = (unsigned char) ch; \ |
| 538 | *outptr++ = comb_table[decomp_table[i].comb1]; \ |
| 539 | *outptr++ = comb_table[decomp_table[i].comb2]; \ |
| 540 | } \ |
| 541 | \ |
| 542 | inptr += 4; \ |
| 543 | continue; \ |
| 544 | } \ |
| 545 | \ |
| 546 | failed: \ |
| 547 | /* This is an illegal character. */ \ |
| 548 | STANDARD_TO_LOOP_ERR_HANDLER (4); \ |
| 549 | } \ |
| 550 | } \ |
| 551 | } |
| 552 | #define LOOP_NEED_FLAGS |
| 553 | #define EXTRA_LOOP_DECLS , int *statep |
| 554 | #include <iconv/loop.c> |
| 555 | |
| 556 | |
| 557 | /* Now define the toplevel functions. */ |
| 558 | #include <iconv/skeleton.c> |