23 #include "fileutils.h"
52 #define MAIN_ERR_PREFIX "ENC: "
55 #define ENC_UC_NORM_DEBUG 0
58 #define ENC_MIME_PARA_LENGTH_MAX (size_t) 127
73 #define ENC_MIME_HEADER_FOLD_ASCII_LINES 1
146 struct mime_parameter
150 size_t attribute_len;
151 unsigned int section;
153 const char* value_start;
154 const char* value_end;
167 #define ENC_UA "\xEF\xBF\xBD"
170 #define ENC_RC 0xFFFDL
176 #define ENC_UC_DECOMPOSITION_BUFSIZE (size_t) 16
179 #define ENC_HDR_BUFSIZE (size_t) 998
182 #define ENC_FMT_BUFLEN (size_t) 7
185 #include "../uc_cdc.c"
188 #include "../uc_hst.c"
191 #include "../uc_qc_nfc.c"
194 #include "../uc_fce.c"
197 #include "../uc_cf.c"
200 #include "../iso2022-jp.c"
203 static const char enc_base64[64] =
205 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
206 'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
207 'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
208 'Y',
'Z',
'a',
'b',
'c',
'd',
'e',
'f',
209 'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
210 'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
211 'w',
'x',
'y',
'z',
'0',
'1',
'2',
'3',
212 '4',
'5',
'6',
'7',
'8',
'9',
'+',
'/'
220 static volatile int ign;
232 static const char* enc_iso8859_1[128] =
234 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
235 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
236 "\xC2\xA0",
"\xC2\xA1",
"\xC2\xA2",
"\xC2\xA3",
"\xC2\xA4",
"\xC2\xA5",
"\xC2\xA6",
"\xC2\xA7",
"\xC2\xA8",
"\xC2\xA9",
"\xC2\xAA",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xC2\xAF",
237 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xC2\xB4",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xC2\xB8",
"\xC2\xB9",
"\xC2\xBA",
"\xC2\xBB",
"\xC2\xBC",
"\xC2\xBD",
"\xC2\xBE",
"\xC2\xBF",
238 "\xC3\x80",
"\xC3\x81",
"\xC3\x82",
"\xC3\x83",
"\xC3\x84",
"\xC3\x85",
"\xC3\x86",
"\xC3\x87",
"\xC3\x88",
"\xC3\x89",
"\xC3\x8A",
"\xC3\x8B",
"\xC3\x8C",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
239 "\xC3\x90",
"\xC3\x91",
"\xC3\x92",
"\xC3\x93",
"\xC3\x94",
"\xC3\x95",
"\xC3\x96",
"\xC3\x97",
"\xC3\x98",
"\xC3\x99",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x9C",
"\xC3\x9D",
"\xC3\x9E",
"\xC3\x9F",
240 "\xC3\xA0",
"\xC3\xA1",
"\xC3\xA2",
"\xC3\xA3",
"\xC3\xA4",
"\xC3\xA5",
"\xC3\xA6",
"\xC3\xA7",
"\xC3\xA8",
"\xC3\xA9",
"\xC3\xAA",
"\xC3\xAB",
"\xC3\xAC",
"\xC3\xAD",
"\xC3\xAE",
"\xC3\xAF",
241 "\xC3\xB0",
"\xC3\xB1",
"\xC3\xB2",
"\xC3\xB3",
"\xC3\xB4",
"\xC3\xB5",
"\xC3\xB6",
"\xC3\xB7",
"\xC3\xB8",
"\xC3\xB9",
"\xC3\xBA",
"\xC3\xBB",
"\xC3\xBC",
"\xC3\xBD",
"\xC3\xBE",
"\xC3\xBF"
245 static const char* enc_iso8859_2[128] =
247 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
248 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
249 "\xC2\xA0",
"\xC4\x84",
"\xCB\x98",
"\xC5\x81",
"\xC2\xA4",
"\xC4\xBD",
"\xC5\x9A",
"\xC2\xA7",
"\xC2\xA8",
"\xC5\xA0",
"\xC5\x9E",
"\xC5\xA4",
"\xC5\xB9",
"\xC2\xAD",
"\xC5\xBD",
"\xC5\xBB",
250 "\xC2\xB0",
"\xC4\x85",
"\xCB\x9B",
"\xC5\x82",
"\xC2\xB4",
"\xC4\xBE",
"\xC5\x9B",
"\xCB\x87",
"\xC2\xB8",
"\xC5\xA1",
"\xC5\x9F",
"\xC5\xA5",
"\xC5\xBA",
"\xCB\x9D",
"\xC5\xBE",
"\xC5\xBC",
251 "\xC5\x94",
"\xC3\x81",
"\xC3\x82",
"\xC4\x82",
"\xC3\x84",
"\xC4\xB9",
"\xC4\x86",
"\xC3\x87",
"\xC4\x8C",
"\xC3\x89",
"\xC4\x98",
"\xC3\x8B",
"\xC4\x9A",
"\xC3\x8D",
"\xC3\x8E",
"\xC4\x8E",
252 "\xC4\x90",
"\xC5\x83",
"\xC5\x87",
"\xC3\x93",
"\xC3\x94",
"\xC5\x90",
"\xC3\x96",
"\xC3\x97",
"\xC5\x98",
"\xC5\xAE",
"\xC3\x9A",
"\xC5\xB0",
"\xC3\x9C",
"\xC3\x9D",
"\xC5\xA2",
"\xC3\x9F",
253 "\xC5\x95",
"\xC3\xA1",
"\xC3\xA2",
"\xC4\x83",
"\xC3\xA4",
"\xC4\xBA",
"\xC4\x87",
"\xC3\xA7",
"\xC4\x8D",
"\xC3\xA9",
"\xC4\x99",
"\xC3\xAB",
"\xC4\x9B",
"\xC3\xAD",
"\xC3\xAE",
"\xC4\x8F",
254 "\xC4\x91",
"\xC5\x84",
"\xC5\x88",
"\xC3\xB3",
"\xC3\xB4",
"\xC5\x91",
"\xC3\xB6",
"\xC3\xB7",
"\xC5\x99",
"\xC5\xAF",
"\xC3\xBA",
"\xC5\xB1",
"\xC3\xBC",
"\xC3\xBD",
"\xC5\xA3",
"\xCB\x99"
258 static const char* enc_iso8859_3[128] =
260 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
261 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
262 "\xC2\xA0",
"\xC4\xA6",
"\xCB\x98",
"\xC2\xA3",
"\xC2\xA4", ENC_UA,
"\xC4\xA4",
"\xC2\xA7",
"\xC2\xA8",
"\xC4\xB0",
"\xC5\x9E",
"\xC4\x9E",
"\xC4\xB4",
"\xC2\xAD", ENC_UA,
"\xC5\xBB",
263 "\xC2\xB0",
"\xC4\xA7",
"\xC2\xB2",
"\xC2\xB3",
"\xC2\xB4",
"\xC2\xB5",
"\xC4\xA5",
"\xC2\xB7",
"\xC2\xB8",
"\xC4\xB1",
"\xC5\x9F",
"\xC4\x9F",
"\xC4\xB5",
"\xC2\xBD", ENC_UA,
"\xC5\xBC",
264 "\xC3\x80",
"\xC3\x81",
"\xC3\x82", ENC_UA,
"\xC3\x84",
"\xC4\x8A",
"\xC4\x88",
"\xC3\x87",
"\xC3\x88",
"\xC3\x89",
"\xC3\x8A",
"\xC3\x8B",
"\xC3\x8C",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
265 ENC_UA,
"\xC3\x91",
"\xC3\x92",
"\xC3\x93",
"\xC3\x94",
"\xC4\xA0",
"\xC3\x96",
"\xC3\x97",
"\xC4\x9C",
"\xC3\x99",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x9C",
"\xC5\xAC",
"\xC5\x9C",
"\xC3\x9F",
266 "\xC3\xA0",
"\xC3\xA1",
"\xC3\xA2", ENC_UA,
"\xC3\xA4",
"\xC4\x8B",
"\xC4\x89",
"\xC3\xA7",
"\xC3\xA8",
"\xC3\xA9",
"\xC3\xAA",
"\xC3\xAB",
"\xC3\xAC",
"\xC3\xAD",
"\xC3\xAE",
"\xC3\xAF",
267 ENC_UA,
"\xC3\xB1",
"\xC3\xB2",
"\xC3\xB3",
"\xC3\xB4",
"\xC4\xA1",
"\xC3\xB6",
"\xC3\xB7",
"\xC4\x9D",
"\xC3\xB9",
"\xC3\xBA",
"\xC3\xBB",
"\xC3\xBC",
"\xC5\xAD",
"\xC5\x9D",
"\xCB\x99"
271 static const char* enc_iso8859_4[128] =
273 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
274 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
275 "\xC2\xA0",
"\xC4\x84",
"\xC4\xB8",
"\xC5\x96",
"\xC2\xA4",
"\xC4\xA8",
"\xC4\xBB",
"\xC2\xA7",
"\xC2\xA8",
"\xC5\xA0",
"\xC4\x92",
"\xC4\xA2",
"\xC5\xA6",
"\xC2\xAD",
"\xC5\xBD",
"\xC2\xAF",
276 "\xC2\xB0",
"\xC4\x85",
"\xCB\x9B",
"\xC5\x97",
"\xC2\xB4",
"\xC4\xA9",
"\xC4\xBC",
"\xCB\x87",
"\xC2\xB8",
"\xC5\xA1",
"\xC4\x93",
"\xC4\xA3",
"\xC5\xA7",
"\xC5\x8A",
"\xC5\xBE",
"\xC5\x8B",
277 "\xC4\x80",
"\xC3\x81",
"\xC3\x82",
"\xC3\x83",
"\xC3\x84",
"\xC3\x85",
"\xC3\x86",
"\xC4\xAE",
"\xC4\x8C",
"\xC3\x89",
"\xC4\x98",
"\xC3\x8B",
"\xC4\x96",
"\xC3\x8D",
"\xC3\x8E",
"\xC4\xAA",
278 "\xC4\x90",
"\xC5\x85",
"\xC5\x8C",
"\xC4\xB6",
"\xC3\x94",
"\xC3\x95",
"\xC3\x96",
"\xC3\x97",
"\xC3\x98",
"\xC5\xB2",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x9C",
"\xC5\xA8",
"\xC5\xAA",
"\xC3\x9F",
279 "\xC4\x81",
"\xC3\xA1",
"\xC3\xA2",
"\xC3\xA3",
"\xC3\xA4",
"\xC3\xA5",
"\xC3\xA6",
"\xC4\xAF",
"\xC4\x8D",
"\xC3\xA9",
"\xC4\x99",
"\xC3\xAB",
"\xC4\x97",
"\xC3\xAD",
"\xC3\xAE",
"\xC4\xAB",
280 "\xC4\x91",
"\xC5\x86",
"\xC5\x8D",
"\xC4\xB7",
"\xC3\xB4",
"\xC3\xB5",
"\xC3\xB6",
"\xC3\xB7",
"\xC3\xB8",
"\xC5\xB3",
"\xC3\xBA",
"\xC3\xBB",
"\xC3\xBC",
"\xC5\xA9",
"\xC5\xAB",
"\xCB\x99"
284 static const char* enc_iso8859_5[128] =
286 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
287 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
288 "\xC2\xA0",
"\xD0\x81",
"\xD0\x82",
"\xD0\x83",
"\xD0\x84",
"\xD0\x85",
"\xD0\x86",
"\xD0\x87",
"\xD0\x88",
"\xD0\x89",
"\xD0\x8A",
"\xD0\x8B",
"\xD0\x8C",
"\xC2\xAD",
"\xD0\x8E",
"\xD0\x8F",
289 "\xD0\x90",
"\xD0\x91",
"\xD0\x92",
"\xD0\x93",
"\xD0\x94",
"\xD0\x95",
"\xD0\x96",
"\xD0\x97",
"\xD0\x98",
"\xD0\x99",
"\xD0\x9A",
"\xD0\x9B",
"\xD0\x9C",
"\xD0\x9D",
"\xD0\x9E",
"\xD0\x9F",
290 "\xD0\xA0",
"\xD0\xA1",
"\xD0\xA2",
"\xD0\xA3",
"\xD0\xA4",
"\xD0\xA5",
"\xD0\xA6",
"\xD0\xA7",
"\xD0\xA8",
"\xD0\xA9",
"\xD0\xAA",
"\xD0\xAB",
"\xD0\xAC",
"\xD0\xAD",
"\xD0\xAE",
"\xD0\xAF",
291 "\xD0\xB0",
"\xD0\xB1",
"\xD0\xB2",
"\xD0\xB3",
"\xD0\xB4",
"\xD0\xB5",
"\xD0\xB6",
"\xD0\xB7",
"\xD0\xB8",
"\xD0\xB9",
"\xD0\xBA",
"\xD0\xBB",
"\xD0\xBC",
"\xD0\xBD",
"\xD0\xBE",
"\xD0\xBF",
292 "\xD1\x80",
"\xD1\x81",
"\xD1\x82",
"\xD1\x83",
"\xD1\x84",
"\xD1\x85",
"\xD1\x86",
"\xD1\x87",
"\xD1\x88",
"\xD1\x89",
"\xD1\x8A",
"\xD1\x8B",
"\xD1\x8C",
"\xD1\x8D",
"\xD1\x8E",
"\xD1\x8F",
293 "\xE2\x84\x96",
"\xD1\x91",
"\xD1\x92",
"\xD1\x93",
"\xD1\x94",
"\xD1\x95",
"\xD1\x96",
"\xD1\x97",
"\xD1\x98",
"\xD1\x99",
"\xD1\x9A",
"\xD1\x9B",
"\xD1\x9C",
"\xC2\xA7",
"\xD1\x9E",
"\xD1\x9F"
297 static const char* enc_iso8859_6[128] =
299 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
300 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
301 "\xC2\xA0", ENC_UA, ENC_UA, ENC_UA,
"\xC2\xA4", ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA,
"\xD8\x8C",
"\xC2\xAD", ENC_UA, ENC_UA,
302 ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA,
"\xD8\x9B", ENC_UA, ENC_UA, ENC_UA,
"\xD8\x9F",
303 ENC_UA,
"\xD8\xA1",
"\xD8\xA2",
"\xD8\xA3",
"\xD8\xA4",
"\xD8\xA5",
"\xD8\xA6",
"\xD8\xA7",
"\xD8\xA8",
"\xD8\xA9",
"\xD8\xAA",
"\xD8\xAB",
"\xD8\xAC",
"\xD8\xAD",
"\xD8\xAE",
"\xD8\xAF",
304 "\xD8\xB0",
"\xD8\xB1",
"\xD8\xB2",
"\xD8\xB3",
"\xD8\xB4",
"\xD8\xB5",
"\xD8\xB6",
"\xD8\xB7",
"\xD8\xB8",
"\xD8\xB9",
"\xD8\xBA", ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA,
305 "\xD9\x80",
"\xD9\x81",
"\xD9\x82",
"\xD9\x83",
"\xD9\x84",
"\xD9\x85",
"\xD9\x86",
"\xD9\x87",
"\xD9\x88",
"\xD9\x89",
"\xD9\x8A",
"\xD9\x8B",
"\xD9\x8C",
"\xD9\x8D",
"\xD9\x8E",
"\xD9\x8F",
306 "\xD9\x90",
"\xD9\x91",
"\xD9\x92", ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA
310 static const char* enc_iso8859_7[128] =
312 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
313 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
314 "\xC2\xA0",
"\xE2\x80\x98",
"\xE2\x80\x99",
"\xC2\xA3",
"\xE2\x82\xAC",
"\xE2\x82\xAF",
"\xC2\xA6",
"\xC2\xA7",
"\xC2\xA8",
"\xC2\xA9",
"\xCD\xBA",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD", ENC_UA,
"\xE2\x80\x95",
315 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xCE\x84",
"\xCE\x85",
"\xCE\x86",
"\xC2\xB7",
"\xCE\x88",
"\xCE\x89",
"\xCE\x8A",
"\xC2\xBB",
"\xCE\x8C",
"\xC2\xBD",
"\xCE\x8E",
"\xCE\x8F",
316 "\xCE\x90",
"\xCE\x91",
"\xCE\x92",
"\xCE\x93",
"\xCE\x94",
"\xCE\x95",
"\xCE\x96",
"\xCE\x97",
"\xCE\x98",
"\xCE\x99",
"\xCE\x9A",
"\xCE\x9B",
"\xCE\x9C",
"\xCE\x9D",
"\xCE\x9E",
"\xCE\x9F",
317 "\xCE\xA0",
"\xCE\xA1", ENC_UA,
"\xCE\xA3",
"\xCE\xA4",
"\xCE\xA5",
"\xCE\xA6",
"\xCE\xA7",
"\xCE\xA8",
"\xCE\xA9",
"\xCE\xAA",
"\xCE\xAB",
"\xCE\xAC",
"\xCE\xAD",
"\xCE\xAE",
"\xCE\xAF",
318 "\xCE\xB0",
"\xCE\xB1",
"\xCE\xB2",
"\xCE\xB3",
"\xCE\xB4",
"\xCE\xB5",
"\xCE\xB6",
"\xCE\xB7",
"\xCE\xB8",
"\xCE\xB9",
"\xCE\xBA",
"\xCE\xBB",
"\xCE\xBC",
"\xCE\xBD",
"\xCE\xBE",
"\xCE\xBF",
319 "\xCF\x80",
"\xCF\x81",
"\xCF\x82",
"\xCF\x83",
"\xCF\x84",
"\xCF\x85",
"\xCF\x86",
"\xCF\x87",
"\xCF\x88",
"\xCF\x89",
"\xCF\x8A",
"\xCF\x8B",
"\xCF\x8C",
"\xCF\x8D",
"\xCF\x8E", ENC_UA
323 static const char* enc_iso8859_8[128] =
325 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
326 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
327 "\xC2\xA0", ENC_UA,
"\xC2\xA2",
"\xC2\xA3",
"\xC2\xA4",
"\xC2\xA5",
"\xC2\xA6",
"\xC2\xA7",
"\xC2\xA8",
"\xC2\xA9",
"\xC3\x97",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xC2\xAF",
328 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xC2\xB4",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xC2\xB8",
"\xC2\xB9",
"\xC3\xB7",
"\xC2\xBB",
"\xC2\xBC",
"\xC2\xBD",
"\xC2\xBE", ENC_UA,
329 ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA,
330 ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA,
"\xE2\x80\x97",
331 "\xD7\x90",
"\xD7\x91",
"\xD7\x92",
"\xD7\x93",
"\xD7\x94",
"\xD7\x95",
"\xD7\x96",
"\xD7\x97",
"\xD7\x98",
"\xD7\x99",
"\xD7\x9A",
"\xD7\x9B",
"\xD7\x9C",
"\xD7\x9D",
"\xD7\x9E",
"\xD7\x9F",
332 "\xD7\xA0",
"\xD7\xA1",
"\xD7\xA2",
"\xD7\xA3",
"\xD7\xA4",
"\xD7\xA5",
"\xD7\xA6",
"\xD7\xA7",
"\xD7\xA8",
"\xD7\xA9",
"\xD7\xAA", ENC_UA, ENC_UA,
"\xE2\x80\x8E",
"\xE2\x80\x8F", ENC_UA
336 static const char* enc_iso8859_9[128] =
338 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
339 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
340 "\xC2\xA0",
"\xC2\xA1",
"\xC2\xA2",
"\xC2\xA3",
"\xC2\xA4",
"\xC2\xA5",
"\xC2\xA6",
"\xC2\xA7",
"\xC2\xA8",
"\xC2\xA9",
"\xC2\xAA",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xC2\xAF",
341 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xC2\xB4",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xC2\xB8",
"\xC2\xB9",
"\xC2\xBA",
"\xC2\xBB",
"\xC2\xBC",
"\xC2\xBD",
"\xC2\xBE",
"\xC2\xBF",
342 "\xC3\x80",
"\xC3\x81",
"\xC3\x82",
"\xC3\x83",
"\xC3\x84",
"\xC3\x85",
"\xC3\x86",
"\xC3\x87",
"\xC3\x88",
"\xC3\x89",
"\xC3\x8A",
"\xC3\x8B",
"\xC3\x8C",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
343 "\xC4\x9E",
"\xC3\x91",
"\xC3\x92",
"\xC3\x93",
"\xC3\x94",
"\xC3\x95",
"\xC3\x96",
"\xC3\x97",
"\xC3\x98",
"\xC3\x99",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x9C",
"\xC4\xB0",
"\xC5\x9E",
"\xC3\x9F",
344 "\xC3\xA0",
"\xC3\xA1",
"\xC3\xA2",
"\xC3\xA3",
"\xC3\xA4",
"\xC3\xA5",
"\xC3\xA6",
"\xC3\xA7",
"\xC3\xA8",
"\xC3\xA9",
"\xC3\xAA",
"\xC3\xAB",
"\xC3\xAC",
"\xC3\xAD",
"\xC3\xAE",
"\xC3\xAF",
345 "\xC4\x9F",
"\xC3\xB1",
"\xC3\xB2",
"\xC3\xB3",
"\xC3\xB4",
"\xC3\xB5",
"\xC3\xB6",
"\xC3\xB7",
"\xC3\xB8",
"\xC3\xB9",
"\xC3\xBA",
"\xC3\xBB",
"\xC3\xBC",
"\xC4\xB1",
"\xC5\x9F",
"\xC3\xBF"
349 static const char* enc_iso8859_10[128] =
351 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
352 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
353 "\xC2\xA0",
"\xC4\x84",
"\xC4\x92",
"\xC4\xA2",
"\xC4\xAA",
"\xC4\xA8",
"\xC4\xB6",
"\xC2\xA7",
"\xC4\xBB",
"\xC4\x90",
"\xC5\xA0",
"\xC5\xA6",
"\xC5\xBD",
"\xC2\xAD",
"\xC5\xAA",
"\xC5\x8A",
354 "\xC2\xB0",
"\xC4\x85",
"\xC4\x93",
"\xC4\xA3",
"\xC4\xAB",
"\xC4\xA9",
"\xC4\xB7",
"\xC2\xB7",
"\xC4\xBC",
"\xC4\x91",
"\xC5\xA1",
"\xC5\xA7",
"\xC5\xBE",
"\xE2\x80\x95",
"\xC5\xAB",
"\xC5\x8B",
355 "\xC4\x80",
"\xC3\x81",
"\xC3\x82",
"\xC3\x83",
"\xC3\x84",
"\xC3\x85",
"\xC3\x86",
"\xC4\xAE",
"\xC4\x8C",
"\xC3\x89",
"\xC4\x98",
"\xC3\x8B",
"\xC4\x96",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
356 "\xC3\x90",
"\xC5\x85",
"\xC5\x8C",
"\xC3\x93",
"\xC3\x94",
"\xC3\x95",
"\xC3\x96",
"\xC5\xA8",
"\xC3\x98",
"\xC5\xB2",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x9C",
"\xC3\x9D",
"\xC3\x9E",
"\xC3\x9F",
357 "\xC4\x81",
"\xC3\xA1",
"\xC3\xA2",
"\xC3\xA3",
"\xC3\xA4",
"\xC3\xA5",
"\xC3\xA6",
"\xC4\xAF",
"\xC4\x8D",
"\xC3\xA9",
"\xC4\x99",
"\xC3\xAB",
"\xC4\x97",
"\xC3\xAD",
"\xC3\xAE",
"\xC3\xAF",
358 "\xC3\xB0",
"\xC5\x86",
"\xC5\x8D",
"\xC3\xB3",
"\xC3\xB4",
"\xC3\xB5",
"\xC3\xB6",
"\xC5\xA9",
"\xC3\xB8",
"\xC5\xB3",
"\xC3\xBA",
"\xC3\xBB",
"\xC3\xBC",
"\xC3\xBD",
"\xC3\xBE",
"\xC4\xB8"
362 static const char* enc_iso8859_11[128] =
364 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
365 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
366 "\xC2\xA0",
"\xE0\xB8\x81",
"\xE0\xB8\x82",
"\xE0\xB8\x83",
"\xE0\xB8\x84",
"\xE0\xB8\x85",
"\xE0\xB8\x86",
"\xE0\xB8\x87",
"\xE0\xB8\x88",
"\xE0\xB8\x89",
"\xE0\xB8\x8A",
"\xE0\xB8\x8B",
"\xE0\xB8\x8C",
"\xE0\xB8\x8D",
"\xE0\xB8\x8E",
"\xE0\xB8\x8F",
367 "\xE0\xB8\x90",
"\xE0\xB8\x91",
"\xE0\xB8\x92",
"\xE0\xB8\x93",
"\xE0\xB8\x94",
"\xE0\xB8\x95",
"\xE0\xB8\x96",
"\xE0\xB8\x97",
"\xE0\xB8\x98",
"\xE0\xB8\x99",
"\xE0\xB8\x9A",
"\xE0\xB8\x9B",
"\xE0\xB8\x9C",
"\xE0\xB8\x9D",
"\xE0\xB8\x9E",
"\xE0\xB8\x9F",
368 "\xE0\xB8\xA0",
"\xE0\xB8\xA1",
"\xE0\xB8\xA2",
"\xE0\xB8\xA3",
"\xE0\xB8\xA4",
"\xE0\xB8\xA5",
"\xE0\xB8\xA6",
"\xE0\xB8\xA7",
"\xE0\xB8\xA8",
"\xE0\xB8\xA9",
"\xE0\xB8\xAA",
"\xE0\xB8\xAB",
"\xE0\xB8\xAC",
"\xE0\xB8\xAD",
"\xE0\xB8\xAE",
"\xE0\xB8\xAF",
369 "\xE0\xB8\xB0",
"\xE0\xB8\xB1",
"\xE0\xB8\xB2",
"\xE0\xB8\xB3",
"\xE0\xB8\xB4",
"\xE0\xB8\xB5",
"\xE0\xB8\xB6",
"\xE0\xB8\xB7",
"\xE0\xB8\xB8",
"\xE0\xB8\xB9",
"\xE0\xB8\xBA", ENC_UA, ENC_UA, ENC_UA, ENC_UA,
"\xE0\xB8\xBF",
370 "\xE0\xB9\x80",
"\xE0\xB9\x81",
"\xE0\xB9\x82",
"\xE0\xB9\x83",
"\xE0\xB9\x84",
"\xE0\xB9\x85",
"\xE0\xB9\x86",
"\xE0\xB9\x87",
"\xE0\xB9\x88",
"\xE0\xB9\x89",
"\xE0\xB9\x8A",
"\xE0\xB9\x8B",
"\xE0\xB9\x8C",
"\xE0\xB9\x8D",
"\xE0\xB9\x8E",
"\xE0\xB9\x8F",
371 "\xE0\xB9\x90",
"\xE0\xB9\x91",
"\xE0\xB9\x92",
"\xE0\xB9\x93",
"\xE0\xB9\x94",
"\xE0\xB9\x95",
"\xE0\xB9\x96",
"\xE0\xB9\x97",
"\xE0\xB9\x98",
"\xE0\xB9\x99",
"\xE0\xB9\x9A",
"\xE0\xB9\x9B", ENC_UA, ENC_UA, ENC_UA, ENC_UA
375 static const char* enc_iso8859_13[128] =
377 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
378 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
379 "\xC2\xA0",
"\xE2\x80\x9D",
"\xC2\xA2",
"\xC2\xA3",
"\xC2\xA4",
"\xE2\x80\x9E",
"\xC2\xA6",
"\xC2\xA7",
"\xC3\x98",
"\xC2\xA9",
"\xC5\x96",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xC3\x86",
380 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xE2\x80\x9C",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xC3\xB8",
"\xC2\xB9",
"\xC5\x97",
"\xC2\xBB",
"\xC2\xBC",
"\xC2\xBD",
"\xC2\xBE",
"\xC3\xA6",
381 "\xC4\x84",
"\xC4\xAE",
"\xC4\x80",
"\xC4\x86",
"\xC3\x84",
"\xC3\x85",
"\xC4\x98",
"\xC4\x92",
"\xC4\x8C",
"\xC3\x89",
"\xC5\xB9",
"\xC4\x96",
"\xC4\xA2",
"\xC4\xB6",
"\xC4\xAA",
"\xC4\xBB",
382 "\xC5\xA0",
"\xC5\x83",
"\xC5\x85",
"\xC3\x93",
"\xC5\x8C",
"\xC3\x95",
"\xC3\x96",
"\xC3\x97",
"\xC5\xB2",
"\xC5\x81",
"\xC5\x9A",
"\xC5\xAA",
"\xC3\x9C",
"\xC5\xBB",
"\xC5\xBD",
"\xC3\x9F",
383 "\xC4\x85",
"\xC4\xAF",
"\xC4\x81",
"\xC4\x87",
"\xC3\xA4",
"\xC3\xA5",
"\xC4\x99",
"\xC4\x93",
"\xC4\x8D",
"\xC3\xA9",
"\xC5\xBA",
"\xC4\x97",
"\xC4\xA3",
"\xC4\xB7",
"\xC4\xAB",
"\xC4\xBC",
384 "\xC5\xA1",
"\xC5\x84",
"\xC5\x86",
"\xC3\xB3",
"\xC5\x8D",
"\xC3\xB5",
"\xC3\xB6",
"\xC3\xB7",
"\xC5\xB3",
"\xC5\x82",
"\xC5\x9B",
"\xC5\xAB",
"\xC3\xBC",
"\xC5\xBC",
"\xC5\xBE",
"\xE2\x80\x99"
388 static const char* enc_iso8859_14[128] =
390 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
391 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
392 "\xC2\xA0",
"\xE1\xB8\x82",
"\xE1\xB8\x83",
"\xC2\xA3",
"\xC4\x8A",
"\xC4\x8B",
"\xE1\xB8\x8A",
"\xC2\xA7",
"\xE1\xBA\x80",
"\xC2\xA9",
"\xE1\xBA\x82",
"\xE1\xB8\x8B",
"\xE1\xBB\xB2",
"\xC2\xAD",
"\xC2\xAE",
"\xC5\xB8",
393 "\xE1\xB8\x9E",
"\xE1\xB8\x9F",
"\xC4\xA0",
"\xC4\xA1",
"\xE1\xB9\x80",
"\xE1\xB9\x81",
"\xC2\xB6",
"\xE1\xB9\x96",
"\xE1\xBA\x81",
"\xE1\xB9\x97",
"\xE1\xBA\x83",
"\xE1\xB9\xA0",
"\xE1\xBB\xB3",
"\xE1\xBA\x84",
"\xE1\xBA\x85",
"\xE1\xB9\xA1",
394 "\xC3\x80",
"\xC3\x81",
"\xC3\x82",
"\xC3\x83",
"\xC3\x84",
"\xC3\x85",
"\xC3\x86",
"\xC3\x87",
"\xC3\x88",
"\xC3\x89",
"\xC3\x8A",
"\xC3\x8B",
"\xC3\x8C",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
395 "\xC5\xB4",
"\xC3\x91",
"\xC3\x92",
"\xC3\x93",
"\xC3\x94",
"\xC3\x95",
"\xC3\x96",
"\xE1\xB9\xAA",
"\xC3\x98",
"\xC3\x99",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x9C",
"\xC3\x9D",
"\xC5\xB6",
"\xC3\x9F",
396 "\xC3\xA0",
"\xC3\xA1",
"\xC3\xA2",
"\xC3\xA3",
"\xC3\xA4",
"\xC3\xA5",
"\xC3\xA6",
"\xC3\xA7",
"\xC3\xA8",
"\xC3\xA9",
"\xC3\xAA",
"\xC3\xAB",
"\xC3\xAC",
"\xC3\xAD",
"\xC3\xAE",
"\xC3\xAF",
397 "\xC5\xB5",
"\xC3\xB1",
"\xC3\xB2",
"\xC3\xB3",
"\xC3\xB4",
"\xC3\xB5",
"\xC3\xB6",
"\xE1\xB9\xAB",
"\xC3\xB8",
"\xC3\xB9",
"\xC3\xBA",
"\xC3\xBB",
"\xC3\xBC",
"\xC3\xBD",
"\xC5\xB7",
"\xC3\xBF"
401 static const char* enc_iso8859_15[128] =
403 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
404 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
405 "\xC2\xA0",
"\xC2\xA1",
"\xC2\xA2",
"\xC2\xA3",
"\xE2\x82\xAC",
"\xC2\xA5",
"\xC5\xA0",
"\xC2\xA7",
"\xC5\xA1",
"\xC2\xA9",
"\xC2\xAA",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xC2\xAF",
406 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xC5\xBD",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xC5\xBE",
"\xC2\xB9",
"\xC2\xBA",
"\xC2\xBB",
"\xC5\x92",
"\xC5\x93",
"\xC5\xB8",
"\xC2\xBF",
407 "\xC3\x80",
"\xC3\x81",
"\xC3\x82",
"\xC3\x83",
"\xC3\x84",
"\xC3\x85",
"\xC3\x86",
"\xC3\x87",
"\xC3\x88",
"\xC3\x89",
"\xC3\x8A",
"\xC3\x8B",
"\xC3\x8C",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
408 "\xC3\x90",
"\xC3\x91",
"\xC3\x92",
"\xC3\x93",
"\xC3\x94",
"\xC3\x95",
"\xC3\x96",
"\xC3\x97",
"\xC3\x98",
"\xC3\x99",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x9C",
"\xC3\x9D",
"\xC3\x9E",
"\xC3\x9F",
409 "\xC3\xA0",
"\xC3\xA1",
"\xC3\xA2",
"\xC3\xA3",
"\xC3\xA4",
"\xC3\xA5",
"\xC3\xA6",
"\xC3\xA7",
"\xC3\xA8",
"\xC3\xA9",
"\xC3\xAA",
"\xC3\xAB",
"\xC3\xAC",
"\xC3\xAD",
"\xC3\xAE",
"\xC3\xAF",
410 "\xC3\xB0",
"\xC3\xB1",
"\xC3\xB2",
"\xC3\xB3",
"\xC3\xB4",
"\xC3\xB5",
"\xC3\xB6",
"\xC3\xB7",
"\xC3\xB8",
"\xC3\xB9",
"\xC3\xBA",
"\xC3\xBB",
"\xC3\xBC",
"\xC3\xBD",
"\xC3\xBE",
"\xC3\xBF"
414 static const char* enc_iso8859_16[128] =
416 "\xC2\x80",
"\xC2\x81",
"\xC2\x82",
"\xC2\x83",
"\xC2\x84",
"\xC2\x85",
"\xC2\x86",
"\xC2\x87",
"\xC2\x88",
"\xC2\x89",
"\xC2\x8A",
"\xC2\x8B",
"\xC2\x8C",
"\xC2\x8D",
"\xC2\x8E",
"\xC2\x8F",
417 "\xC2\x90",
"\xC2\x91",
"\xC2\x92",
"\xC2\x93",
"\xC2\x94",
"\xC2\x95",
"\xC2\x96",
"\xC2\x97",
"\xC2\x98",
"\xC2\x99",
"\xC2\x9A",
"\xC2\x9B",
"\xC2\x9C",
"\xC2\x9D",
"\xC2\x9E",
"\xC2\x9F",
418 "\xC2\xA0",
"\xC4\x84",
"\xC4\x85",
"\xC5\x81",
"\xE2\x82\xAC",
"\xE2\x80\x9E",
"\xC5\xA0",
"\xC2\xA7",
"\xC5\xA1",
"\xC2\xA9",
"\xC8\x98",
"\xC2\xAB",
"\xC5\xB9",
"\xC2\xAD",
"\xC5\xBA",
"\xC5\xBB",
419 "\xC2\xB0",
"\xC2\xB1",
"\xC4\x8C",
"\xC5\x82",
"\xC5\xBD",
"\xE2\x80\x9D",
"\xC2\xB6",
"\xC2\xB7",
"\xC5\xBE",
"\xC4\x8D",
"\xC8\x99",
"\xC2\xBB",
"\xC5\x92",
"\xC5\x93",
"\xC5\xB8",
"\xC5\xBC",
420 "\xC3\x80",
"\xC3\x81",
"\xC3\x82",
"\xC4\x82",
"\xC3\x84",
"\xC4\x86",
"\xC3\x86",
"\xC3\x87",
"\xC3\x88",
"\xC3\x89",
"\xC3\x8A",
"\xC3\x8B",
"\xC3\x8C",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
421 "\xC4\x90",
"\xC5\x83",
"\xC3\x92",
"\xC3\x93",
"\xC3\x94",
"\xC5\x90",
"\xC3\x96",
"\xC5\x9A",
"\xC5\xB0",
"\xC3\x99",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x9C",
"\xC4\x98",
"\xC8\x9A",
"\xC3\x9F",
422 "\xC3\xA0",
"\xC3\xA1",
"\xC3\xA2",
"\xC4\x83",
"\xC3\xA4",
"\xC4\x87",
"\xC3\xA6",
"\xC3\xA7",
"\xC3\xA8",
"\xC3\xA9",
"\xC3\xAA",
"\xC3\xAB",
"\xC3\xAC",
"\xC3\xAD",
"\xC3\xAE",
"\xC3\xAF",
423 "\xC4\x91",
"\xC5\x84",
"\xC3\xB2",
"\xC3\xB3",
"\xC3\xB4",
"\xC5\x91",
"\xC3\xB6",
"\xC5\x9B",
"\xC5\xB1",
"\xC3\xB9",
"\xC3\xBA",
"\xC3\xBB",
"\xC3\xBC",
"\xC4\x99",
"\xC8\x9B",
"\xC3\xBF"
427 static const char* enc_mac_roman[128] =
429 "\xC3\x84",
"\xC3\x85",
"\xC3\x87",
"\xC3\x89",
"\xC3\x91",
"\xC3\x96",
"\xC3\x9C",
"\xC3\xA1",
"\xC3\xA0",
"\xC3\xA2",
"\xC3\xA4",
"\xC3\xA3",
"\xC3\xA5",
"\xC3\xA7",
"\xC3\xA9",
"\xC3\xA8",
430 "\xC3\xAA",
"\xC3\xAB",
"\xC3\xAD",
"\xC3\xAC",
"\xC3\xAE",
"\xC3\xAF",
"\xC3\xB1",
"\xC3\xB3",
"\xC3\xB2",
"\xC3\xB4",
"\xC3\xB6",
"\xC3\xB5",
"\xC3\xBA",
"\xC3\xB9",
"\xC3\xBB",
"\xC3\xBC",
431 "\xE2\x80\xA0",
"\xC2\xB0",
"\xC2\xA2",
"\xC2\xA3",
"\xC2\xA7",
"\xE2\x80\xA2",
"\xC2\xB6",
"\xC3\x9F",
"\xC2\xAE",
"\xC2\xA9",
"\xE2\x84\xA2",
"\xC2\xB4",
"\xC2\xA8",
"\xE2\x89\xA0",
"\xC3\x86",
"\xC3\x98",
432 "\xE2\x88\x9E",
"\xC2\xB1",
"\xE2\x89\xA4",
"\xE2\x89\xA5",
"\xC2\xA5",
"\xC2\xB5",
"\xE2\x88\x82",
"\xE2\x88\x91",
"\xE2\x88\x8F",
"\xCF\x80",
"\xE2\x88\xAB",
"\xC2\xAA",
"\xC2\xBA",
"\xCE\xA9",
"\xC3\xA6",
"\xC3\xB8",
433 "\xC2\xBF",
"\xC2\xA1",
"\xC2\xAC",
"\xE2\x88\x9A",
"\xC6\x92",
"\xE2\x89\x88",
"\xE2\x88\x86",
"\xC2\xAB",
"\xC2\xBB",
"\xE2\x80\xA6",
"\xC2\xA0",
"\xC3\x80",
"\xC3\x83",
"\xC3\x95",
"\xC5\x92",
"\xC5\x93",
434 "\xE2\x80\x93",
"\xE2\x80\x94",
"\xE2\x80\x9C",
"\xE2\x80\x9D",
"\xE2\x80\x98",
"\xE2\x80\x99",
"\xC3\xB7",
"\xE2\x97\x8A",
"\xC3\xBF",
"\xC5\xB8",
"\xE2\x81\x84",
"\xE2\x82\xAC",
"\xE2\x80\xB9",
"\xE2\x80\xBA",
"\xEF\xAC\x81",
"\xEF\xAC\x82",
435 "\xE2\x80\xA1",
"\xC2\xB7",
"\xE2\x80\x9A",
"\xE2\x80\x9E",
"\xE2\x80\xB0",
"\xC3\x82",
"\xC3\x8A",
"\xC3\x81",
"\xC3\x8B",
"\xC3\x88",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
"\xC3\x8C",
"\xC3\x93",
"\xC3\x94",
436 ENC_UA,
"\xC3\x92",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x99",
"\xC4\xB1",
"\xCB\x86",
"\xCB\x9C",
"\xC2\xAF",
"\xCB\x98",
"\xCB\x99",
"\xCB\x9A",
"\xC2\xB8",
"\xCB\x9D",
"\xCB\x9B",
"\xCB\x87"
441 static const char* enc_windows_1250[128] =
443 "\xE2\x82\xAC", ENC_UA,
"\xE2\x80\x9A", ENC_UA,
"\xE2\x80\x9E",
"\xE2\x80\xA6",
"\xE2\x80\xA0",
"\xE2\x80\xA1", ENC_UA,
"\xE2\x80\xB0",
"\xC5\xA0",
"\xE2\x80\xB9",
"\xC5\x9A",
"\xC5\xA4",
"\xC5\xBD",
"\xC5\xB9",
444 ENC_UA,
"\xE2\x80\x98",
"\xE2\x80\x99",
"\xE2\x80\x9C",
"\xE2\x80\x9D",
"\xE2\x80\xA2",
"\xE2\x80\x93",
"\xE2\x80\x94", ENC_UA,
"\xE2\x84\xA2",
"\xC5\xA1",
"\xE2\x80\xBA",
"\xC5\x9B",
"\xC5\xA5",
"\xC5\xBE",
"\xC5\xBA",
445 "\xC2\xA0",
"\xCB\x87",
"\xCB\x98",
"\xC5\x81",
"\xC2\xA4",
"\xC4\x84",
"\xC2\xA6",
"\xC2\xA7",
"\xC2\xA8",
"\xC2\xA9",
"\xC5\x9E",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xC5\xBB",
446 "\xC2\xB0",
"\xC2\xB1",
"\xCB\x9B",
"\xC5\x82",
"\xC2\xB4",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xC2\xB8",
"\xC4\x85",
"\xC5\x9F",
"\xC2\xBB",
"\xC4\xBD",
"\xCB\x9D",
"\xC4\xBE",
"\xC5\xBC",
447 "\xC5\x94",
"\xC3\x81",
"\xC3\x82",
"\xC4\x82",
"\xC3\x84",
"\xC4\xB9",
"\xC4\x86",
"\xC3\x87",
"\xC4\x8C",
"\xC3\x89",
"\xC4\x98",
"\xC3\x8B",
"\xC4\x9A",
"\xC3\x8D",
"\xC3\x8E",
"\xC4\x8E",
448 "\xC4\x90",
"\xC5\x83",
"\xC5\x87",
"\xC3\x93",
"\xC3\x94",
"\xC5\x90",
"\xC3\x96",
"\xC3\x97",
"\xC5\x98",
"\xC5\xAE",
"\xC3\x9A",
"\xC5\xB0",
"\xC3\x9C",
"\xC3\x9D",
"\xC5\xA2",
"\xC3\x9F",
449 "\xC5\x95",
"\xC3\xA1",
"\xC3\xA2",
"\xC4\x83",
"\xC3\xA4",
"\xC4\xBA",
"\xC4\x87",
"\xC3\xA7",
"\xC4\x8D",
"\xC3\xA9",
"\xC4\x99",
"\xC3\xAB",
"\xC4\x9B",
"\xC3\xAD",
"\xC3\xAE",
"\xC4\x8F",
450 "\xC4\x91",
"\xC5\x84",
"\xC5\x88",
"\xC3\xB3",
"\xC3\xB4",
"\xC5\x91",
"\xC3\xB6",
"\xC3\xB7",
"\xC5\x99",
"\xC5\xAF",
"\xC3\xBA",
"\xC5\xB1",
"\xC3\xBC",
"\xC3\xBD",
"\xC5\xA3",
"\xCB\x99"
454 static const char* enc_windows_1251[128] =
456 "\xD0\x82",
"\xD0\x83",
"\xE2\x80\x9A",
"\xD1\x93",
"\xE2\x80\x9E",
"\xE2\x80\xA6",
"\xE2\x80\xA0",
"\xE2\x80\xA1",
"\xE2\x82\xAC",
"\xE2\x80\xB0",
"\xD0\x89",
"\xE2\x80\xB9",
"\xD0\x8A",
"\xD0\x8C",
"\xD0\x8B",
"\xD0\x8F",
457 "\xD1\x92",
"\xE2\x80\x98",
"\xE2\x80\x99",
"\xE2\x80\x9C",
"\xE2\x80\x9D",
"\xE2\x80\xA2",
"\xE2\x80\x93",
"\xE2\x80\x94", ENC_UA,
"\xE2\x84\xA2",
"\xD1\x99",
"\xE2\x80\xBA",
"\xD1\x9A",
"\xD1\x9C",
"\xD1\x9B",
"\xD1\x9F",
458 "\xC2\xA0",
"\xD0\x8E",
"\xD1\x9E",
"\xD0\x88",
"\xC2\xA4",
"\xD2\x90",
"\xC2\xA6",
"\xC2\xA7",
"\xD0\x81",
"\xC2\xA9",
"\xD0\x84",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xD0\x87",
459 "\xC2\xB0",
"\xC2\xB1",
"\xD0\x86",
"\xD1\x96",
"\xD2\x91",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xD1\x91",
"\xE2\x84\x96",
"\xD1\x94",
"\xC2\xBB",
"\xD1\x98",
"\xD0\x85",
"\xD1\x95",
"\xD1\x97",
460 "\xD0\x90",
"\xD0\x91",
"\xD0\x92",
"\xD0\x93",
"\xD0\x94",
"\xD0\x95",
"\xD0\x96",
"\xD0\x97",
"\xD0\x98",
"\xD0\x99",
"\xD0\x9A",
"\xD0\x9B",
"\xD0\x9C",
"\xD0\x9D",
"\xD0\x9E",
"\xD0\x9F",
461 "\xD0\xA0",
"\xD0\xA1",
"\xD0\xA2",
"\xD0\xA3",
"\xD0\xA4",
"\xD0\xA5",
"\xD0\xA6",
"\xD0\xA7",
"\xD0\xA8",
"\xD0\xA9",
"\xD0\xAA",
"\xD0\xAB",
"\xD0\xAC",
"\xD0\xAD",
"\xD0\xAE",
"\xD0\xAF",
462 "\xD0\xB0",
"\xD0\xB1",
"\xD0\xB2",
"\xD0\xB3",
"\xD0\xB4",
"\xD0\xB5",
"\xD0\xB6",
"\xD0\xB7",
"\xD0\xB8",
"\xD0\xB9",
"\xD0\xBA",
"\xD0\xBB",
"\xD0\xBC",
"\xD0\xBD",
"\xD0\xBE",
"\xD0\xBF",
463 "\xD1\x80",
"\xD1\x81",
"\xD1\x82",
"\xD1\x83",
"\xD1\x84",
"\xD1\x85",
"\xD1\x86",
"\xD1\x87",
"\xD1\x88",
"\xD1\x89",
"\xD1\x8A",
"\xD1\x8B",
"\xD1\x8C",
"\xD1\x8D",
"\xD1\x8E",
"\xD1\x8F"
467 static const char* enc_windows_1252[128] =
469 "\xE2\x82\xAC", ENC_UA,
"\xE2\x80\x9A",
"\xC6\x92",
"\xE2\x80\x9E",
"\xE2\x80\xA6",
"\xE2\x80\xA0",
"\xE2\x80\xA1",
"\xCB\x86",
"\xE2\x80\xB0",
"\xC5\xA0",
"\xE2\x80\xB9",
"\xC5\x92", ENC_UA,
"\xC5\xBD", ENC_UA,
470 ENC_UA,
"\xE2\x80\x98",
"\xE2\x80\x99",
"\xE2\x80\x9C",
"\xE2\x80\x9D",
"\xE2\x80\xA2",
"\xE2\x80\x93",
"\xE2\x80\x94",
"\xCB\x9C",
"\xE2\x84\xA2",
"\xC5\xA1",
"\xE2\x80\xBA",
"\xC5\x93", ENC_UA,
"\xC5\xBE",
"\xC5\xB8",
471 "\xC2\xA0",
"\xC2\xA1",
"\xC2\xA2",
"\xC2\xA3",
"\xC2\xA4",
"\xC2\xA5",
"\xC2\xA6",
"\xC2\xA7",
"\xC2\xA8",
"\xC2\xA9",
"\xC2\xAA",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xC2\xAF",
472 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xC2\xB4",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xC2\xB8",
"\xC2\xB9",
"\xC2\xBA",
"\xC2\xBB",
"\xC2\xBC",
"\xC2\xBD",
"\xC2\xBE",
"\xC2\xBF",
473 "\xC3\x80",
"\xC3\x81",
"\xC3\x82",
"\xC3\x83",
"\xC3\x84",
"\xC3\x85",
"\xC3\x86",
"\xC3\x87",
"\xC3\x88",
"\xC3\x89",
"\xC3\x8A",
"\xC3\x8B",
"\xC3\x8C",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
474 "\xC3\x90",
"\xC3\x91",
"\xC3\x92",
"\xC3\x93",
"\xC3\x94",
"\xC3\x95",
"\xC3\x96",
"\xC3\x97",
"\xC3\x98",
"\xC3\x99",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x9C",
"\xC3\x9D",
"\xC3\x9E",
"\xC3\x9F",
475 "\xC3\xA0",
"\xC3\xA1",
"\xC3\xA2",
"\xC3\xA3",
"\xC3\xA4",
"\xC3\xA5",
"\xC3\xA6",
"\xC3\xA7",
"\xC3\xA8",
"\xC3\xA9",
"\xC3\xAA",
"\xC3\xAB",
"\xC3\xAC",
"\xC3\xAD",
"\xC3\xAE",
"\xC3\xAF",
476 "\xC3\xB0",
"\xC3\xB1",
"\xC3\xB2",
"\xC3\xB3",
"\xC3\xB4",
"\xC3\xB5",
"\xC3\xB6",
"\xC3\xB7",
"\xC3\xB8",
"\xC3\xB9",
"\xC3\xBA",
"\xC3\xBB",
"\xC3\xBC",
"\xC3\xBD",
"\xC3\xBE",
"\xC3\xBF"
480 static const char* enc_windows_1253[128] =
482 "\xE2\x82\xAC", ENC_UA,
"\xE2\x80\x9A",
"\xC6\x92",
"\xE2\x80\x9E",
"\xE2\x80\xA6",
"\xE2\x80\xA0",
"\xE2\x80\xA1", ENC_UA,
"\xE2\x80\xB0", ENC_UA,
"\xE2\x80\xB9", ENC_UA, ENC_UA, ENC_UA, ENC_UA,
483 ENC_UA,
"\xE2\x80\x98",
"\xE2\x80\x99",
"\xE2\x80\x9C",
"\xE2\x80\x9D",
"\xE2\x80\xA2",
"\xE2\x80\x93",
"\xE2\x80\x94", ENC_UA,
"\xE2\x84\xA2", ENC_UA,
"\xE2\x80\xBA", ENC_UA, ENC_UA, ENC_UA, ENC_UA,
484 "\xC2\xA0",
"\xCE\x85",
"\xCE\x86",
"\xC2\xA3",
"\xC2\xA4",
"\xC2\xA5",
"\xC2\xA6",
"\xC2\xA7",
"\xC2\xA8",
"\xC2\xA9", ENC_UA,
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xE2\x80\x95",
485 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xCE\x84",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xCE\x88",
"\xCE\x89",
"\xCE\x8A",
"\xC2\xBB",
"\xCE\x8C",
"\xC2\xBD",
"\xCE\x8E",
"\xCE\x8F",
486 "\xCE\x90",
"\xCE\x91",
"\xCE\x92",
"\xCE\x93",
"\xCE\x94",
"\xCE\x95",
"\xCE\x96",
"\xCE\x97",
"\xCE\x98",
"\xCE\x99",
"\xCE\x9A",
"\xCE\x9B",
"\xCE\x9C",
"\xCE\x9D",
"\xCE\x9E",
"\xCE\x9F",
487 "\xCE\xA0",
"\xCE\xA1", ENC_UA,
"\xCE\xA3",
"\xCE\xA4",
"\xCE\xA5",
"\xCE\xA6",
"\xCE\xA7",
"\xCE\xA8",
"\xCE\xA9",
"\xCE\xAA",
"\xCE\xAB",
"\xCE\xAC",
"\xCE\xAD",
"\xCE\xAE",
"\xCE\xAF",
488 "\xCE\xB0",
"\xCE\xB1",
"\xCE\xB2",
"\xCE\xB3",
"\xCE\xB4",
"\xCE\xB5",
"\xCE\xB6",
"\xCE\xB7",
"\xCE\xB8",
"\xCE\xB9",
"\xCE\xBA",
"\xCE\xBB",
"\xCE\xBC",
"\xCE\xBD",
"\xCE\xBE",
"\xCE\xBF",
489 "\xCF\x80",
"\xCF\x81",
"\xCF\x82",
"\xCF\x83",
"\xCF\x84",
"\xCF\x85",
"\xCF\x86",
"\xCF\x87",
"\xCF\x88",
"\xCF\x89",
"\xCF\x8A",
"\xCF\x8B",
"\xCF\x8C",
"\xCF\x8D",
"\xCF\x8E", ENC_UA
493 static const char* enc_windows_1254[128] =
495 "\xE2\x82\xAC", ENC_UA,
"\xE2\x80\x9A",
"\xC6\x92",
"\xE2\x80\x9E",
"\xE2\x80\xA6",
"\xE2\x80\xA0",
"\xE2\x80\xA1",
"\xCB\x86",
"\xE2\x80\xB0",
"\xC5\xA0",
"\xE2\x80\xB9",
"\xC5\x92", ENC_UA, ENC_UA, ENC_UA,
496 ENC_UA,
"\xE2\x80\x98",
"\xE2\x80\x99",
"\xE2\x80\x9C",
"\xE2\x80\x9D",
"\xE2\x80\xA2",
"\xE2\x80\x93",
"\xE2\x80\x94",
"\xCB\x9C",
"\xE2\x84\xA2",
"\xC5\xA1",
"\xE2\x80\xBA",
"\xC5\x93", ENC_UA, ENC_UA,
"\xC5\xB8",
497 "\xC2\xA0",
"\xC2\xA1",
"\xC2\xA2",
"\xC2\xA3",
"\xC2\xA4",
"\xC2\xA5",
"\xC2\xA6",
"\xC2\xA7",
"\xC2\xA8",
"\xC2\xA9",
"\xC2\xAA",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xC2\xAF",
498 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xC2\xB4",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xC2\xB8",
"\xC2\xB9",
"\xC2\xBA",
"\xC2\xBB",
"\xC2\xBC",
"\xC2\xBD",
"\xC2\xBE",
"\xC2\xBF",
499 "\xC3\x80",
"\xC3\x81",
"\xC3\x82",
"\xC3\x83",
"\xC3\x84",
"\xC3\x85",
"\xC3\x86",
"\xC3\x87",
"\xC3\x88",
"\xC3\x89",
"\xC3\x8A",
"\xC3\x8B",
"\xC3\x8C",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
500 "\xC4\x9E",
"\xC3\x91",
"\xC3\x92",
"\xC3\x93",
"\xC3\x94",
"\xC3\x95",
"\xC3\x96",
"\xC3\x97",
"\xC3\x98",
"\xC3\x99",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x9C",
"\xC4\xB0",
"\xC5\x9E",
"\xC3\x9F",
501 "\xC3\xA0",
"\xC3\xA1",
"\xC3\xA2",
"\xC3\xA3",
"\xC3\xA4",
"\xC3\xA5",
"\xC3\xA6",
"\xC3\xA7",
"\xC3\xA8",
"\xC3\xA9",
"\xC3\xAA",
"\xC3\xAB",
"\xC3\xAC",
"\xC3\xAD",
"\xC3\xAE",
"\xC3\xAF",
502 "\xC4\x9F",
"\xC3\xB1",
"\xC3\xB2",
"\xC3\xB3",
"\xC3\xB4",
"\xC3\xB5",
"\xC3\xB6",
"\xC3\xB7",
"\xC3\xB8",
"\xC3\xB9",
"\xC3\xBA",
"\xC3\xBB",
"\xC3\xBC",
"\xC4\xB1",
"\xC5\x9F",
"\xC3\xBF"
506 static const char* enc_windows_1255[128] =
508 "\xE2\x82\xAC", ENC_UA,
"\xE2\x80\x9A",
"\xC6\x92",
"\xE2\x80\x9E",
"\xE2\x80\xA6",
"\xE2\x80\xA0",
"\xE2\x80\xA1",
"\xCB\x86",
"\xE2\x80\xB0", ENC_UA,
"\xE2\x80\xB9", ENC_UA, ENC_UA, ENC_UA, ENC_UA,
509 ENC_UA,
"\xE2\x80\x98",
"\xE2\x80\x99",
"\xE2\x80\x9C",
"\xE2\x80\x9D",
"\xE2\x80\xA2",
"\xE2\x80\x93",
"\xE2\x80\x94",
"\xCB\x9C",
"\xE2\x84\xA2", ENC_UA,
"\xE2\x80\xBA", ENC_UA, ENC_UA, ENC_UA, ENC_UA,
510 "\xC2\xA0",
"\xC2\xA1",
"\xC2\xA2",
"\xC2\xA3",
"\xE2\x82\xAA",
"\xC2\xA5",
"\xC2\xA6",
"\xC2\xA7",
"\xC2\xA8",
"\xC2\xA9",
"\xC3\x97",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xC2\xAF",
511 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xC2\xB4",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xC2\xB8",
"\xC2\xB9",
"\xC3\xB7",
"\xC2\xBB",
"\xC2\xBC",
"\xC2\xBD",
"\xC2\xBE",
"\xC2\xBF",
512 "\xD6\xB0",
"\xD6\xB1",
"\xD6\xB2",
"\xD6\xB3",
"\xD6\xB4",
"\xD6\xB5",
"\xD6\xB6",
"\xD6\xB7",
"\xD6\xB8",
"\xD6\xB9",
"\xD6\xBA",
"\xD6\xBB",
"\xD6\xBC",
"\xD6\xBD",
"\xD6\xBE",
"\xD6\xBF",
513 "\xD7\x80",
"\xD7\x81",
"\xD7\x82",
"\xD7\x83",
"\xD7\xB0",
"\xD7\xB1",
"\xD7\xB2",
"\xD7\xB3",
"\xD7\xB4", ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA, ENC_UA,
514 "\xD7\x90",
"\xD7\x91",
"\xD7\x92",
"\xD7\x93",
"\xD7\x94",
"\xD7\x95",
"\xD7\x96",
"\xD7\x97",
"\xD7\x98",
"\xD7\x99",
"\xD7\x9A",
"\xD7\x9B",
"\xD7\x9C",
"\xD7\x9D",
"\xD7\x9E",
"\xD7\x9F",
515 "\xD7\xA0",
"\xD7\xA1",
"\xD7\xA2",
"\xD7\xA3",
"\xD7\xA4",
"\xD7\xA5",
"\xD7\xA6",
"\xD7\xA7",
"\xD7\xA8",
"\xD7\xA9",
"\xD7\xAA", ENC_UA, ENC_UA,
"\xE2\x80\x8E",
"\xE2\x80\x8F", ENC_UA
519 static const char* enc_windows_1256[128] =
521 "\xE2\x82\xAC",
"\xD9\xBE",
"\xE2\x80\x9A",
"\xC6\x92",
"\xE2\x80\x9E",
"\xE2\x80\xA6",
"\xE2\x80\xA0",
"\xE2\x80\xA1",
"\xCB\x86",
"\xE2\x80\xB0",
"\xD9\xB9",
"\xE2\x80\xB9",
"\xC5\x92",
"\xDA\x86",
"\xDA\x98",
"\xDA\x88",
522 "\xDA\xAF",
"\xE2\x80\x98",
"\xE2\x80\x99",
"\xE2\x80\x9C",
"\xE2\x80\x9D",
"\xE2\x80\xA2",
"\xE2\x80\x93",
"\xE2\x80\x94",
"\xDA\xA9",
"\xE2\x84\xA2",
"\xDA\x91",
"\xE2\x80\xBA",
"\xC5\x93",
"\xE2\x80\x8C",
"\xE2\x80\x8D",
"\xDA\xBA",
523 "\xC2\xA0",
"\xD8\x8C",
"\xC2\xA2",
"\xC2\xA3",
"\xC2\xA4",
"\xC2\xA5",
"\xC2\xA6",
"\xC2\xA7",
"\xC2\xA8",
"\xC2\xA9",
"\xDA\xBE",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xC2\xAF",
524 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xC2\xB4",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xC2\xB8",
"\xC2\xB9",
"\xD8\x9B",
"\xC2\xBB",
"\xC2\xBC",
"\xC2\xBD",
"\xC2\xBE",
"\xD8\x9F",
525 "\xDB\x81",
"\xD8\xA1",
"\xD8\xA2",
"\xD8\xA3",
"\xD8\xA4",
"\xD8\xA5",
"\xD8\xA6",
"\xD8\xA7",
"\xD8\xA8",
"\xD8\xA9",
"\xD8\xAA",
"\xD8\xAB",
"\xD8\xAC",
"\xD8\xAD",
"\xD8\xAE",
"\xD8\xAF",
526 "\xD8\xB0",
"\xD8\xB1",
"\xD8\xB2",
"\xD8\xB3",
"\xD8\xB4",
"\xD8\xB5",
"\xD8\xB6",
"\xC3\x97",
"\xD8\xB7",
"\xD8\xB8",
"\xD8\xB9",
"\xD8\xBA",
"\xD9\x80",
"\xD9\x81",
"\xD9\x82",
"\xD9\x83",
527 "\xC3\xA0",
"\xD9\x84",
"\xC3\xA2",
"\xD9\x85",
"\xD9\x86",
"\xD9\x87",
"\xD9\x88",
"\xC3\xA7",
"\xC3\xA8",
"\xC3\xA9",
"\xC3\xAA",
"\xC3\xAB",
"\xD9\x89",
"\xD9\x8A",
"\xC3\xAE",
"\xC3\xAF",
528 "\xD9\x8B",
"\xD9\x8C",
"\xD9\x8D",
"\xD9\x8E",
"\xC3\xB4",
"\xD9\x8F",
"\xD9\x90",
"\xC3\xB7",
"\xD9\x91",
"\xC3\xB9",
"\xD9\x92",
"\xC3\xBB",
"\xC3\xBC",
"\xE2\x80\x8E",
"\xE2\x80\x8F",
"\xDB\x92"
532 static const char* enc_windows_1257[128] =
534 "\xE2\x82\xAC", ENC_UA,
"\xE2\x80\x9A", ENC_UA,
"\xE2\x80\x9E",
"\xE2\x80\xA6",
"\xE2\x80\xA0",
"\xE2\x80\xA1", ENC_UA,
"\xE2\x80\xB0", ENC_UA,
"\xE2\x80\xB9", ENC_UA,
"\xC2\xA8",
"\xCB\x87",
"\xC2\xB8",
535 ENC_UA,
"\xE2\x80\x98",
"\xE2\x80\x99",
"\xE2\x80\x9C",
"\xE2\x80\x9D",
"\xE2\x80\xA2",
"\xE2\x80\x93",
"\xE2\x80\x94", ENC_UA,
"\xE2\x84\xA2", ENC_UA,
"\xE2\x80\xBA", ENC_UA,
"\xC2\xAF",
"\xCB\x9B", ENC_UA,
536 "\xC2\xA0", ENC_UA,
"\xC2\xA2",
"\xC2\xA3",
"\xC2\xA4", ENC_UA,
"\xC2\xA6",
"\xC2\xA7",
"\xC3\x98",
"\xC2\xA9",
"\xC5\x96",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xC3\x86",
537 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xC2\xB4",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xC3\xB8",
"\xC2\xB9",
"\xC5\x97",
"\xC2\xBB",
"\xC2\xBC",
"\xC2\xBD",
"\xC2\xBE",
"\xC3\xA6",
538 "\xC4\x84",
"\xC4\xAE",
"\xC4\x80",
"\xC4\x86",
"\xC3\x84",
"\xC3\x85",
"\xC4\x98",
"\xC4\x92",
"\xC4\x8C",
"\xC3\x89",
"\xC5\xB9",
"\xC4\x96",
"\xC4\xA2",
"\xC4\xB6",
"\xC4\xAA",
"\xC4\xBB",
539 "\xC5\xA0",
"\xC5\x83",
"\xC5\x85",
"\xC3\x93",
"\xC5\x8C",
"\xC3\x95",
"\xC3\x96",
"\xC3\x97",
"\xC5\xB2",
"\xC5\x81",
"\xC5\x9A",
"\xC5\xAA",
"\xC3\x9C",
"\xC5\xBB",
"\xC5\xBD",
"\xC3\x9F",
540 "\xC4\x85",
"\xC4\xAF",
"\xC4\x81",
"\xC4\x87",
"\xC3\xA4",
"\xC3\xA5",
"\xC4\x99",
"\xC4\x93",
"\xC4\x8D",
"\xC3\xA9",
"\xC5\xBA",
"\xC4\x97",
"\xC4\xA3",
"\xC4\xB7",
"\xC4\xAB",
"\xC4\xBC",
541 "\xC5\xA1",
"\xC5\x84",
"\xC5\x86",
"\xC3\xB3",
"\xC5\x8D",
"\xC3\xB5",
"\xC3\xB6",
"\xC3\xB7",
"\xC5\xB3",
"\xC5\x82",
"\xC5\x9B",
"\xC5\xAB",
"\xC3\xBC",
"\xC5\xBC",
"\xC5\xBE",
"\xCB\x99"
545 static const char* enc_windows_1258[128] =
547 "\xE2\x82\xAC", ENC_UA,
"\xE2\x80\x9A",
"\xC6\x92",
"\xE2\x80\x9E",
"\xE2\x80\xA6",
"\xE2\x80\xA0",
"\xE2\x80\xA1",
"\xCB\x86",
"\xE2\x80\xB0", ENC_UA,
"\xE2\x80\xB9",
"\xC5\x92", ENC_UA, ENC_UA, ENC_UA,
548 ENC_UA,
"\xE2\x80\x98",
"\xE2\x80\x99",
"\xE2\x80\x9C",
"\xE2\x80\x9D",
"\xE2\x80\xA2",
"\xE2\x80\x93",
"\xE2\x80\x94",
"\xCB\x9C",
"\xE2\x84\xA2", ENC_UA,
"\xE2\x80\xBA",
"\xC5\x93", ENC_UA, ENC_UA,
"\xC5\xB8",
549 "\xC2\xA0",
"\xC2\xA1",
"\xC2\xA2",
"\xC2\xA3",
"\xC2\xA4",
"\xC2\xA5",
"\xC2\xA6",
"\xC2\xA7",
"\xC2\xA8",
"\xC2\xA9",
"\xC2\xAA",
"\xC2\xAB",
"\xC2\xAC",
"\xC2\xAD",
"\xC2\xAE",
"\xC2\xAF",
550 "\xC2\xB0",
"\xC2\xB1",
"\xC2\xB2",
"\xC2\xB3",
"\xC2\xB4",
"\xC2\xB5",
"\xC2\xB6",
"\xC2\xB7",
"\xC2\xB8",
"\xC2\xB9",
"\xC2\xBA",
"\xC2\xBB",
"\xC2\xBC",
"\xC2\xBD",
"\xC2\xBE",
"\xC2\xBF",
551 "\xC3\x80",
"\xC3\x81",
"\xC3\x82",
"\xC4\x82",
"\xC3\x84",
"\xC3\x85",
"\xC3\x86",
"\xC3\x87",
"\xC3\x88",
"\xC3\x89",
"\xC3\x8A",
"\xC3\x8B",
"\xCC\x80",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
552 "\xC4\x90",
"\xC3\x91",
"\xCC\x89",
"\xC3\x93",
"\xC3\x94",
"\xC6\xA0",
"\xC3\x96",
"\xC3\x97",
"\xC3\x98",
"\xC3\x99",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x9C",
"\xC6\xAF",
"\xCC\x83",
"\xC3\x9F",
553 "\xC3\xA0",
"\xC3\xA1",
"\xC3\xA2",
"\xC4\x83",
"\xC3\xA4",
"\xC3\xA5",
"\xC3\xA6",
"\xC3\xA7",
"\xC3\xA8",
"\xC3\xA9",
"\xC3\xAA",
"\xC3\xAB",
"\xCC\x81",
"\xC3\xAD",
"\xC3\xAE",
"\xC3\xAF",
554 "\xC4\x91",
"\xC3\xB1",
"\xCC\xA3",
"\xC3\xB3",
"\xC3\xB4",
"\xC6\xA1",
"\xC3\xB6",
"\xC3\xB7",
"\xC3\xB8",
"\xC3\xB9",
"\xC3\xBA",
"\xC3\xBB",
"\xC3\xBC",
"\xC6\xB0",
"\xE2\x82\xAB",
"\xC3\xBF"
558 static const char* enc_koi8r[128] =
560 "\xE2\x94\x80",
"\xE2\x94\x82",
"\xE2\x94\x8C",
"\xE2\x94\x90",
"\xE2\x94\x94",
"\xE2\x94\x98",
"\xE2\x94\x9C",
"\xE2\x94\xA4",
"\xE2\x94\xAC",
"\xE2\x94\xB4",
"\xE2\x94\xBC",
"\xE2\x96\x80",
"\xE2\x96\x84",
"\xE2\x96\x88",
"\xE2\x96\x8C",
"\xE2\x96\x90",
561 "\xE2\x96\x91",
"\xE2\x96\x92",
"\xE2\x96\x93",
"\xE2\x8C\xA0",
"\xE2\x96\xA0",
"\xE2\x88\x99",
"\xE2\x88\x9A",
"\xE2\x89\x88",
"\xE2\x89\xA4",
"\xE2\x89\xA5",
"\xC2\xA0",
"\xE2\x8C\xA1",
"\xC2\xB0",
"\xC2\xB2",
"\xC2\xB7",
"\xC3\xB7",
562 "\xE2\x95\x90",
"\xE2\x95\x91",
"\xE2\x95\x92",
"\xD1\x91",
"\xE2\x95\x93",
"\xE2\x95\x94",
"\xE2\x95\x95",
"\xE2\x95\x96",
"\xE2\x95\x97",
"\xE2\x95\x98",
"\xE2\x95\x99",
"\xE2\x95\x9A",
"\xE2\x95\x9B",
"\xE2\x95\x9C",
"\xE2\x95\x9D",
"\xE2\x95\x9E",
563 "\xE2\x95\x9F",
"\xE2\x95\xA0",
"\xE2\x95\xA1",
"\xD0\x81",
"\xE2\x95\xA2",
"\xE2\x95\xA3",
"\xE2\x95\xA4",
"\xE2\x95\xA5",
"\xE2\x95\xA6",
"\xE2\x95\xA7",
"\xE2\x95\xA8",
"\xE2\x95\xA9",
"\xE2\x95\xAA",
"\xE2\x95\xAB",
"\xE2\x95\xAC",
"\xC2\xA9",
564 "\xD1\x8E",
"\xD0\xB0",
"\xD0\xB1",
"\xD1\x86",
"\xD0\xB4",
"\xD0\xB5",
"\xD1\x84",
"\xD0\xB3",
"\xD1\x85",
"\xD0\xB8",
"\xD0\xB9",
"\xD0\xBA",
"\xD0\xBB",
"\xD0\xBC",
"\xD0\xBD",
"\xD0\xBE",
565 "\xD0\xBF",
"\xD1\x8F",
"\xD1\x80",
"\xD1\x81",
"\xD1\x82",
"\xD1\x83",
"\xD0\xB6",
"\xD0\xB2",
"\xD1\x8C",
"\xD1\x8B",
"\xD0\xB7",
"\xD1\x88",
"\xD1\x8D",
"\xD1\x89",
"\xD1\x87",
"\xD1\x8A",
566 "\xD0\xAE",
"\xD0\x90",
"\xD0\x91",
"\xD0\xA6",
"\xD0\x94",
"\xD0\x95",
"\xD0\xA4",
"\xD0\x93",
"\xD0\xA5",
"\xD0\x98",
"\xD0\x99",
"\xD0\x9A",
"\xD0\x9B",
"\xD0\x9C",
"\xD0\x9D",
"\xD0\x9E",
567 "\xD0\x9F",
"\xD0\xAF",
"\xD0\xA0",
"\xD0\xA1",
"\xD0\xA2",
"\xD0\xA3",
"\xD0\x96",
"\xD0\x92",
"\xD0\xAC",
"\xD0\xAB",
"\xD0\x97",
"\xD0\xA8",
"\xD0\xAD",
"\xD0\xA9",
"\xD0\xA7",
"\xD0\xAA"
571 static const char* enc_koi8u[128] =
573 "\xE2\x94\x80",
"\xE2\x94\x82",
"\xE2\x94\x8C",
"\xE2\x94\x90",
"\xE2\x94\x94",
"\xE2\x94\x98",
"\xE2\x94\x9C",
"\xE2\x94\xA4",
"\xE2\x94\xAC",
"\xE2\x94\xB4",
"\xE2\x94\xBC",
"\xE2\x96\x80",
"\xE2\x96\x84",
"\xE2\x96\x88",
"\xE2\x96\x8C",
"\xE2\x96\x90",
574 "\xE2\x96\x91",
"\xE2\x96\x92",
"\xE2\x96\x93",
"\xE2\x8C\xA0",
"\xE2\x96\xA0",
"\xE2\x88\x99",
"\xE2\x88\x9A",
"\xE2\x89\x88",
"\xE2\x89\xA4",
"\xE2\x89\xA5",
"\xC2\xA0",
"\xE2\x8C\xA1",
"\xC2\xB0",
"\xC2\xB2",
"\xC2\xB7",
"\xC3\xB7",
575 "\xE2\x95\x90",
"\xE2\x95\x91",
"\xE2\x95\x92",
"\xD1\x91",
"\xD1\x94",
"\xE2\x95\x94",
"\xD1\x96",
"\xD1\x97",
"\xE2\x95\x97",
"\xE2\x95\x98",
"\xE2\x95\x99",
"\xE2\x95\x9A",
"\xE2\x95\x9B",
"\xD2\x91",
"\xE2\x95\x9D",
"\xE2\x95\x9E",
576 "\xE2\x95\x9F",
"\xE2\x95\xA0",
"\xE2\x95\xA1",
"\xD0\x81",
"\xD0\x84",
"\xE2\x95\xA3",
"\xD0\x86",
"\xD0\x87",
"\xE2\x95\xA6",
"\xE2\x95\xA7",
"\xE2\x95\xA8",
"\xE2\x95\xA9",
"\xE2\x95\xAA",
"\xD2\x90",
"\xE2\x95\xAC",
"\xC2\xA9",
577 "\xD1\x8E",
"\xD0\xB0",
"\xD0\xB1",
"\xD1\x86",
"\xD0\xB4",
"\xD0\xB5",
"\xD1\x84",
"\xD0\xB3",
"\xD1\x85",
"\xD0\xB8",
"\xD0\xB9",
"\xD0\xBA",
"\xD0\xBB",
"\xD0\xBC",
"\xD0\xBD",
"\xD0\xBE",
578 "\xD0\xBF",
"\xD1\x8F",
"\xD1\x80",
"\xD1\x81",
"\xD1\x82",
"\xD1\x83",
"\xD0\xB6",
"\xD0\xB2",
"\xD1\x8C",
"\xD1\x8B",
"\xD0\xB7",
"\xD1\x88",
"\xD1\x8D",
"\xD1\x89",
"\xD1\x87",
"\xD1\x8A",
579 "\xD0\xAE",
"\xD0\x90",
"\xD0\x91",
"\xD0\xA6",
"\xD0\x94",
"\xD0\x95",
"\xD0\xA4",
"\xD0\x93",
"\xD0\xA5",
"\xD0\x98",
"\xD0\x99",
"\xD0\x9A",
"\xD0\x9B",
"\xD0\x9C",
"\xD0\x9D",
"\xD0\x9E",
580 "\xD0\x9F",
"\xD0\xAF",
"\xD0\xA0",
"\xD0\xA1",
"\xD0\xA2",
"\xD0\xA3",
"\xD0\x96",
"\xD0\x92",
"\xD0\xAC",
"\xD0\xAB",
"\xD0\x97",
"\xD0\xA8",
"\xD0\xAD",
"\xD0\xA9",
"\xD0\xA7",
"\xD0\xAA"
584 static const char* enc_ibm437[128] =
586 "\xC3\x87",
"\xC3\xBC",
"\xC3\xA9",
"\xC3\xA2",
"\xC3\xA4",
"\xC3\xA0",
"\xC3\xA5",
"\xC3\xA7",
"\xC3\xAA",
"\xC3\xAB",
"\xC3\xA8",
"\xC3\xAF",
"\xC3\xAE",
"\xC3\xAC",
"\xC3\x84",
"\xC3\x85",
587 "\xC3\x89",
"\xC3\xA6",
"\xC3\x86",
"\xC3\xB4",
"\xC3\xB6",
"\xC3\xB2",
"\xC3\xBB",
"\xC3\xB9",
"\xC3\xBF",
"\xC3\x96",
"\xC3\x9C",
"\xC2\xA2",
"\xC2\xA3",
"\xC2\xA5",
"\xE2\x82\xA7",
"\xC6\x92",
588 "\xC3\xA1",
"\xC3\xAD",
"\xC3\xB3",
"\xC3\xBA",
"\xC3\xB1",
"\xC3\x91",
"\xC2\xAA",
"\xC2\xBA",
"\xC2\xBF",
"\xE2\x8C\x90",
"\xC2\xAC",
"\xC2\xBD",
"\xC2\xBC",
"\xC2\xA1",
"\xC2\xAB",
"\xC2\xBB",
589 "\xE2\x96\x91",
"\xE2\x96\x92",
"\xE2\x96\x93",
"\xE2\x94\x82",
"\xE2\x94\xA4",
"\xE2\x95\xA1",
"\xE2\x95\xA2",
"\xE2\x95\x96",
"\xE2\x95\x95",
"\xE2\x95\xA3",
"\xE2\x95\x91",
"\xE2\x95\x97",
"\xE2\x95\x9D",
"\xE2\x95\x9C",
"\xE2\x95\x9B",
"\xE2\x94\x90",
590 "\xE2\x94\x94",
"\xE2\x94\xB4",
"\xE2\x94\xAC",
"\xE2\x94\x9C",
"\xE2\x94\x80",
"\xE2\x94\xBC",
"\xE2\x95\x9E",
"\xE2\x95\x9F",
"\xE2\x95\x9A",
"\xE2\x95\x94",
"\xE2\x95\xA9",
"\xE2\x95\xA6",
"\xE2\x95\xA0",
"\xE2\x95\x90",
"\xE2\x95\xAC",
"\xE2\x95\xA7",
591 "\xE2\x95\xA8",
"\xE2\x95\xA4",
"\xE2\x95\xA5",
"\xE2\x95\x99",
"\xE2\x95\x98",
"\xE2\x95\x92",
"\xE2\x95\x93",
"\xE2\x95\xAB",
"\xE2\x95\xAA",
"\xE2\x94\x98",
"\xE2\x94\x8C",
"\xE2\x96\x88",
"\xE2\x96\x84",
"\xE2\x96\x8C",
"\xE2\x96\x90",
"\xE2\x96\x80",
592 "\xCE\xB1",
"\xC3\x9F",
"\xCE\x93",
"\xCF\x80",
"\xCE\xA3",
"\xCF\x83",
"\xC2\xB5",
"\xCF\x84",
"\xCE\xA6",
"\xCE\x98",
"\xCE\xA9",
"\xCE\xB4",
"\xE2\x88\x9E",
"\xCF\x86",
"\xCE\xB5",
"\xE2\x88\xA9",
593 "\xE2\x89\xA1",
"\xC2\xB1",
"\xE2\x89\xA5",
"\xE2\x89\xA4",
"\xE2\x8C\xA0",
"\xE2\x8C\xA1",
"\xC3\xB7",
"\xE2\x89\x88",
"\xC2\xB0",
"\xE2\x88\x99",
"\xC2\xB7",
"\xE2\x88\x9A",
"\xE2\x81\xBF",
"\xC2\xB2",
"\xE2\x96\xA0",
"\xC2\xA0"
597 static const char* enc_ibm775[128] =
599 "\xC4\x86",
"\xC3\xBC",
"\xC3\xA9",
"\xC4\x81",
"\xC3\xA4",
"\xC4\xA3",
"\xC3\xA5",
"\xC4\x87",
"\xC5\x82",
"\xC4\x93",
"\xC5\x96",
"\xC5\x97",
"\xC4\xAB",
"\xC5\xB9",
"\xC3\x84",
"\xC3\x85",
600 "\xC3\x89",
"\xC3\xA6",
"\xC3\x86",
"\xC5\x8D",
"\xC3\xB6",
"\xC4\xA2",
"\xC2\xA2",
"\xC5\x9A",
"\xC5\x9B",
"\xC3\x96",
"\xC3\x9C",
"\xC3\xB8",
"\xC2\xA3",
"\xC3\x98",
"\xC3\x97",
"\xC2\xA4",
601 "\xC4\x80",
"\xC4\xAA",
"\xC3\xB3",
"\xC5\xBB",
"\xC5\xBC",
"\xC5\xBA",
"\xE2\x80\x9D",
"\xC2\xA6",
"\xC2\xA9",
"\xC2\xAE",
"\xC2\xAC",
"\xC2\xBD",
"\xC2\xBC",
"\xC5\x81",
"\xC2\xAB",
"\xC2\xBB",
602 "\xE2\x96\x91",
"\xE2\x96\x92",
"\xE2\x96\x93",
"\xE2\x94\x82",
"\xE2\x94\xA4",
"\xC4\x84",
"\xC4\x8C",
"\xC4\x98",
"\xC4\x96",
"\xE2\x95\xA3",
"\xE2\x95\x91",
"\xE2\x95\x97",
"\xE2\x95\x9D",
"\xC4\xAE",
"\xC5\xA0",
"\xE2\x94\x90",
603 "\xE2\x94\x94",
"\xE2\x94\xB4",
"\xE2\x94\xAC",
"\xE2\x94\x9C",
"\xE2\x94\x80",
"\xE2\x94\xBC",
"\xC5\xB2",
"\xC5\xAA",
"\xE2\x95\x9A",
"\xE2\x95\x94",
"\xE2\x95\xA9",
"\xE2\x95\xA6",
"\xE2\x95\xA0",
"\xE2\x95\x90",
"\xE2\x95\xAC",
"\xC5\xBD",
604 "\xC4\x85",
"\xC4\x8D",
"\xC4\x99",
"\xC4\x97",
"\xC4\xAF",
"\xC5\xA1",
"\xC5\xB3",
"\xC5\xAB",
"\xC5\xBE",
"\xE2\x94\x98",
"\xE2\x94\x8C",
"\xE2\x96\x88",
"\xE2\x96\x84",
"\xE2\x96\x8C",
"\xE2\x96\x90",
"\xE2\x96\x80",
605 "\xC3\x93",
"\xC3\x9F",
"\xC5\x8C",
"\xC5\x83",
"\xC3\xB5",
"\xC3\x95",
"\xC2\xB5",
"\xC5\x84",
"\xC4\xB6",
"\xC4\xB7",
"\xC4\xBB",
"\xC4\xBC",
"\xC5\x86",
"\xC4\x92",
"\xC5\x85",
"\xE2\x80\x99",
606 "\xC2\xAD",
"\xC2\xB1",
"\xE2\x80\x9C",
"\xC2\xBE",
"\xC2\xB6",
"\xC2\xA7",
"\xC3\xB7",
"\xE2\x80\x9E",
"\xC2\xB0",
"\xE2\x88\x99",
"\xC2\xB7",
"\xC2\xB9",
"\xC2\xB3",
"\xC2\xB2",
"\xE2\x96\xA0",
"\xC2\xA0"
610 static const char* enc_ibm850[128] =
612 "\xC3\x87",
"\xC3\xBC",
"\xC3\xA9",
"\xC3\xA2",
"\xC3\xA4",
"\xC3\xA0",
"\xC3\xA5",
"\xC3\xA7",
"\xC3\xAA",
"\xC3\xAB",
"\xC3\xA8",
"\xC3\xAF",
"\xC3\xAE",
"\xC3\xAC",
"\xC3\x84",
"\xC3\x85",
613 "\xC3\x89",
"\xC3\xA6",
"\xC3\x86",
"\xC3\xB4",
"\xC3\xB6",
"\xC3\xB2",
"\xC3\xBB",
"\xC3\xB9",
"\xC3\xBF",
"\xC3\x96",
"\xC3\x9C",
"\xC3\xB8",
"\xC2\xA3",
"\xC3\x98",
"\xC3\x97",
"\xC6\x92",
614 "\xC3\xA1",
"\xC3\xAD",
"\xC3\xB3",
"\xC3\xBA",
"\xC3\xB1",
"\xC3\x91",
"\xC2\xAA",
"\xC2\xBA",
"\xC2\xBF",
"\xC2\xAE",
"\xC2\xAC",
"\xC2\xBD",
"\xC2\xBC",
"\xC2\xA1",
"\xC2\xAB",
"\xC2\xBB",
615 "\xE2\x96\x91",
"\xE2\x96\x92",
"\xE2\x96\x93",
"\xE2\x94\x82",
"\xE2\x94\xA4",
"\xC3\x81",
"\xC3\x82",
"\xC3\x80",
"\xC2\xA9",
"\xE2\x95\xA3",
"\xE2\x95\x91",
"\xE2\x95\x97",
"\xE2\x95\x9D",
"\xC2\xA2",
"\xC2\xA5",
"\xE2\x94\x90",
616 "\xE2\x94\x94",
"\xE2\x94\xB4",
"\xE2\x94\xAC",
"\xE2\x94\x9C",
"\xE2\x94\x80",
"\xE2\x94\xBC",
"\xC3\xA3",
"\xC3\x83",
"\xE2\x95\x9A",
"\xE2\x95\x94",
"\xE2\x95\xA9",
"\xE2\x95\xA6",
"\xE2\x95\xA0",
"\xE2\x95\x90",
"\xE2\x95\xAC",
"\xC2\xA4",
617 "\xC3\xB0",
"\xC3\x90",
"\xC3\x8A",
"\xC3\x8B",
"\xC3\x88",
"\xC4\xB1",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
"\xE2\x94\x98",
"\xE2\x94\x8C",
"\xE2\x96\x88",
"\xE2\x96\x84",
"\xC2\xA6",
"\xC3\x8C",
"\xE2\x96\x80",
618 "\xC3\x93",
"\xC3\x9F",
"\xC3\x94",
"\xC3\x92",
"\xC3\xB5",
"\xC3\x95",
"\xC2\xB5",
"\xC3\xBE",
"\xC3\x9E",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x99",
"\xC3\xBD",
"\xC3\x9D",
"\xC2\xAF",
"\xC2\xB4",
619 "\xC2\xAD",
"\xC2\xB1",
"\xE2\x80\x97",
"\xC2\xBE",
"\xC2\xB6",
"\xC2\xA7",
"\xC3\xB7",
"\xC2\xB8",
"\xC2\xB0",
"\xC2\xA8",
"\xC2\xB7",
"\xC2\xB9",
"\xC2\xB3",
"\xC2\xB2",
"\xE2\x96\xA0",
"\xC2\xA0"
623 static const char* enc_ibm852[128] =
625 "\xC3\x87",
"\xC3\xBC",
"\xC3\xA9",
"\xC3\xA2",
"\xC3\xA4",
"\xC5\xAF",
"\xC4\x87",
"\xC3\xA7",
"\xC5\x82",
"\xC3\xAB",
"\xC5\x90",
"\xC5\x91",
"\xC3\xAE",
"\xC5\xB9",
"\xC3\x84",
"\xC4\x86",
626 "\xC3\x89",
"\xC4\xB9",
"\xC4\xBA",
"\xC3\xB4",
"\xC3\xB6",
"\xC4\xBD",
"\xC4\xBE",
"\xC5\x9A",
"\xC5\x9B",
"\xC3\x96",
"\xC3\x9C",
"\xC5\xA4",
"\xC5\xA5",
"\xC5\x81",
"\xC3\x97",
"\xC4\x8D",
627 "\xC3\xA1",
"\xC3\xAD",
"\xC3\xB3",
"\xC3\xBA",
"\xC4\x84",
"\xC4\x85",
"\xC5\xBD",
"\xC5\xBE",
"\xC4\x98",
"\xC4\x99",
"\xC2\xAC",
"\xC5\xBA",
"\xC4\x8C",
"\xC5\x9F",
"\xC2\xAB",
"\xC2\xBB",
628 "\xE2\x96\x91",
"\xE2\x96\x92",
"\xE2\x96\x93",
"\xE2\x94\x82",
"\xE2\x94\xA4",
"\xC3\x81",
"\xC3\x82",
"\xC4\x9A",
"\xC5\x9E",
"\xE2\x95\xA3",
"\xE2\x95\x91",
"\xE2\x95\x97",
"\xE2\x95\x9D",
"\xC5\xBB",
"\xC5\xBC",
"\xE2\x94\x90",
629 "\xE2\x94\x94",
"\xE2\x94\xB4",
"\xE2\x94\xAC",
"\xE2\x94\x9C",
"\xE2\x94\x80",
"\xE2\x94\xBC",
"\xC4\x82",
"\xC4\x83",
"\xE2\x95\x9A",
"\xE2\x95\x94",
"\xE2\x95\xA9",
"\xE2\x95\xA6",
"\xE2\x95\xA0",
"\xE2\x95\x90",
"\xE2\x95\xAC",
"\xC2\xA4",
630 "\xC4\x91",
"\xC4\x90",
"\xC4\x8E",
"\xC3\x8B",
"\xC4\x8F",
"\xC5\x87",
"\xC3\x8D",
"\xC3\x8E",
"\xC4\x9B",
"\xE2\x94\x98",
"\xE2\x94\x8C",
"\xE2\x96\x88",
"\xE2\x96\x84",
"\xC5\xA2",
"\xC5\xAE",
"\xE2\x96\x80",
631 "\xC3\x93",
"\xC3\x9F",
"\xC3\x94",
"\xC5\x83",
"\xC5\x84",
"\xC5\x88",
"\xC5\xA0",
"\xC5\xA1",
"\xC5\x94",
"\xC3\x9A",
"\xC5\x95",
"\xC5\xB0",
"\xC3\xBD",
"\xC3\x9D",
"\xC5\xA3",
"\xC2\xB4",
632 "\xC2\xAD",
"\xCB\x9D",
"\xCB\x9B",
"\xCB\x87",
"\xCB\x98",
"\xC2\xA7",
"\xC3\xB7",
"\xC2\xB8",
"\xC2\xB0",
"\xC2\xA8",
"\xCB\x99",
"\xC5\xB1",
"\xC5\x98",
"\xC5\x99",
"\xE2\x96\xA0",
"\xC2\xA0"
636 static const char* enc_ibm858[128] =
638 "\xC3\x87",
"\xC3\xBC",
"\xC3\xA9",
"\xC3\xA2",
"\xC3\xA4",
"\xC3\xA0",
"\xC3\xA5",
"\xC3\xA7",
"\xC3\xAA",
"\xC3\xAB",
"\xC3\xA8",
"\xC3\xAF",
"\xC3\xAE",
"\xC3\xAC",
"\xC3\x84",
"\xC3\x85",
639 "\xC3\x89",
"\xC3\xA6",
"\xC3\x86",
"\xC3\xB4",
"\xC3\xB6",
"\xC3\xB2",
"\xC3\xBB",
"\xC3\xB9",
"\xC3\xBF",
"\xC3\x96",
"\xC3\x9C",
"\xC3\xB8",
"\xC2\xA3",
"\xC3\x98",
"\xC3\x97",
"\xC6\x92",
640 "\xC3\xA1",
"\xC3\xAD",
"\xC3\xB3",
"\xC3\xBA",
"\xC3\xB1",
"\xC3\x91",
"\xC2\xAA",
"\xC2\xBA",
"\xC2\xBF",
"\xC2\xAE",
"\xC2\xAC",
"\xC2\xBD",
"\xC2\xBC",
"\xC2\xA1",
"\xC2\xAB",
"\xC2\xBB",
641 "\xE2\x96\x91",
"\xE2\x96\x92",
"\xE2\x96\x93",
"\xE2\x94\x82",
"\xE2\x94\xA4",
"\xC3\x81",
"\xC3\x82",
"\xC3\x80",
"\xC2\xA9",
"\xE2\x95\xA3",
"\xE2\x95\x91",
"\xE2\x95\x97",
"\xE2\x95\x9D",
"\xC2\xA2",
"\xC2\xA5",
"\xE2\x94\x90",
642 "\xE2\x94\x94",
"\xE2\x94\xB4",
"\xE2\x94\xAC",
"\xE2\x94\x9C",
"\xE2\x94\x80",
"\xE2\x94\xBC",
"\xC3\xA3",
"\xC3\x83",
"\xE2\x95\x9A",
"\xE2\x95\x94",
"\xE2\x95\xA9",
"\xE2\x95\xA6",
"\xE2\x95\xA0",
"\xE2\x95\x90",
"\xE2\x95\xAC",
"\xC2\xA4",
643 "\xC3\xB0",
"\xC3\x90",
"\xC3\x8A",
"\xC3\x8B",
"\xC3\x88",
"\xE2\x82\xAC",
"\xC3\x8D",
"\xC3\x8E",
"\xC3\x8F",
"\xE2\x94\x98",
"\xE2\x94\x8C",
"\xE2\x96\x88",
"\xE2\x96\x84",
"\xC2\xA6",
"\xC3\x8C",
"\xE2\x96\x80",
644 "\xC3\x93",
"\xC3\x9F",
"\xC3\x94",
"\xC3\x92",
"\xC3\xB5",
"\xC3\x95",
"\xC2\xB5",
"\xC3\xBE",
"\xC3\x9E",
"\xC3\x9A",
"\xC3\x9B",
"\xC3\x99",
"\xC3\xBD",
"\xC3\x9D",
"\xC2\xAF",
"\xC2\xB4",
645 "\xC2\xAD",
"\xC2\xB1",
"\xE2\x80\x97",
"\xC2\xBE",
"\xC2\xB6",
"\xC2\xA7",
"\xC3\xB7",
"\xC2\xB8",
"\xC2\xB0",
"\xC2\xA8",
"\xC2\xB7",
"\xC2\xB9",
"\xC2\xB3",
"\xC2\xB2",
"\xE2\x96\xA0",
"\xC2\xA0"
659 static int enc_hex_decode_nibble(
char nibble)
664 if(0x30 <= n && 0x39 >= n) { res = n - 0x30; }
665 else if(0x41 <= n && 0x46 >= n) { res = n - 0x41 + 10; }
666 else if(0x61 <= n && 0x66 >= n) { res = n - 0x61 + 10; }
667 else {
PRINT_ERROR(
"Can't decode invalid hexadecimal nibble"); }
685 static const char* enc_8bit_convert_to_utf8_nfc(
enum enc_mime_cs charset,
688 static const char qm[] =
"?";
710 if(bi + (
size_t) 5 >= len)
713 if(!len) { len = 64; }
714 p = posix_realloc((
void*) buf, len *= (
size_t) 2);
715 if(NULL == p) { posix_free((
void*) buf); buf = NULL;
break; }
719 if(128U > (
unsigned char) s[i])
726 c = (
unsigned char) s[i] - (
unsigned char) 128;
762 default: { seq = NULL;
break; }
764 if(NULL == seq) { posix_free((
void*) buf); buf = NULL;
break; }
765 for(ii = 0; ii < 4; ++ii)
767 if(!seq[ii]) {
break; }
768 else { buf[bi++] = seq[ii]; }
804 static int enc_uc_check_cesu8(
const char* s,
unsigned char utf)
811 size_t remaining = 0;
812 unsigned long int mbc = 0;
815 while((c = (
int) s[i++]))
820 if(!(0 <= c && 127 >= c)) { multibyte = 1; }
827 if((c & 0xE0) == 0xC0) { len = 2; }
828 else if((c & 0xF0) == 0xE0) { len = 3; }
829 else if((c & 0xF8) == 0xF0) { len = 4; }
832 PRINT_ERROR(
"Invalid start of code sequence in UTF-8 data");
838 case 2: mbc |= (
unsigned long int) (c & 0x1F) << 6;
break;
839 case 3: mbc |= (
unsigned long int) (c & 0x0F) << 12;
break;
840 case 4: mbc |= (
unsigned long int) (c & 0x07) << 18;
break;
842 remaining = len - (size_t) 1;
846 if((c & 0xC0) != 0x80)
848 PRINT_ERROR(
"Invalid continuation character in UTF-8 sequence");
855 mbc |= (
unsigned long int) (c & 0x3F) << remaining * (size_t) 6;
874 || (utf && 0x00D800UL <= mbc && 0x00DFFFUL >= mbc))
883 if(0x010000UL > mbc || 0x10FFFFUL < mbc)
907 if(multibyte) { res = -1; }
931 static long int enc_uc_decode_utf8(
const char* s,
size_t* i)
937 size_t remaining = 0;
938 unsigned long int mbc = 0;
942 while((c = (
int) s[(*i)++]))
947 if(0 <= c && 127 >= c) { res = (
long int) c;
break; }
948 else { multibyte = 1; }
955 if((c & 0xE0) == 0xC0) { len = 2; }
956 else if((c & 0xF0) == 0xE0) { len = 3; }
957 else if((c & 0xF8) == 0xF0) { len = 4; }
960 case 2: mbc |= (
unsigned long int) (c & 0x1F) << 6;
break;
961 case 3: mbc |= (
unsigned long int) (c & 0x0F) << 12;
break;
962 case 4: mbc |= (
unsigned long int) (c & 0x07) << 18;
break;
965 PRINT_ERROR(
"UTF-8 decoder called with invalid data");
970 if(error) { res = -1L;
break; }
971 remaining = len - (size_t) 1;
976 mbc |= (
unsigned long int) (c & 0x3F) << remaining * (size_t) 6;
980 res = (
long int) mbc;
1012 unsigned char prefix;
1015 for(ii = 0; ii < *di; ++ii)
1017 if (0L > dbuf[ii]) { inval = 1; }
1018 else if(0x00007FL >= dbuf[ii]) { buf[(*i)++] = (char) dbuf[ii]; }
1019 else if(0x0007FFL >= dbuf[ii])
1021 data = (
unsigned char) ((dbuf[ii] >> 6) & 0x1FL);
1023 buf[(*i)++] = (char) (prefix |
data);
1024 data = (
unsigned char) (dbuf[ii] & 0x3FL);
1026 buf[(*i)++] = (char) (prefix |
data);
1028 else if(0x00FFFFL >= dbuf[ii])
1030 data = (
unsigned char) ((dbuf[ii] >> 12) & 0x0FL);
1032 buf[(*i)++] = (char) (prefix |
data);
1033 data = (
unsigned char) ((dbuf[ii] >> 6) & 0x3FL);
1035 buf[(*i)++] = (char) (prefix |
data);
1036 data = (
unsigned char) (dbuf[ii] & 0x3FL);
1038 buf[(*i)++] = (char) (prefix |
data);
1040 else if(0x10FFFFL >= dbuf[ii])
1042 data = (
unsigned char) ((dbuf[ii] >> 18) & 0x07L);
1044 buf[(*i)++] = (char) (prefix |
data);
1045 data = (
unsigned char) ((dbuf[ii] >> 12) & 0x3FL);
1047 buf[(*i)++] = (char) (prefix |
data);
1048 data = (
unsigned char) ((dbuf[ii] >> 6) & 0x3FL);
1050 buf[(*i)++] = (char) (prefix |
data);
1051 data = (
unsigned char) (dbuf[ii] & 0x3FL);
1053 buf[(*i)++] = (char) (prefix |
data);
1058 PRINT_ERROR(
"Unicode UTF-8 encoder: Invalid codepoint detected");
1084 static const char* enc_uc_convert_utf16be_to_utf8(
const char* mb,
size_t len)
1086 const char* res = NULL;
1092 long int lead_surrogate = 0;
1096 if((
size_t) 1 & len) { --len; }
1100 buf = (
char*) posix_malloc(len * (
size_t) 2 + (size_t) 1);
1104 for(i = 0; i < len; i += 2)
1107 ucp = (
long int) (
unsigned char) mb[i] << 8
1108 | (
long int) (
unsigned char) mb[i + (size_t) 1];
1110 if(0x00D800L <= ucp && 0x00DFFFL >= ucp)
1113 && (0x00D800L <= ucp && 0x00DBFFL >= ucp))
1115 lead_surrogate = ucp - 0x00D800L;
1120 && (0x00DC00L <= ucp && 0x00DFFFL >= ucp))
1122 ucp = (lead_surrogate << 10L) | (ucp - 0x00DC00L);
1129 ucp = (
long int) (
unsigned char)
'?';
1133 if(surrogate && !(0x00DC00L <= ucp && 0x00DFFFL >= ucp))
1136 ucp = (
long int) (
unsigned char)
'?';
1149 PRINT_ERROR(
"Unicode UTF-16 to UTF-8 converter failed");
1150 if(NULL != buf) { posix_free((
void*) buf); }
1179 static int enc_uc_check_control(
long int ucp)
1184 if(0x1FL >= ucp || 0x7FL == ucp)
1187 if(0x09L != ucp && 0x0AL != ucp && 0x0DL != ucp) { res = -1; }
1190 else if(0x80L <= ucp && 0x9FL >= ucp) { res = -1; }
1192 else if(0xFFF9L <= ucp && 0xFFFBL >= ucp) { res = -1; }
1194 else if(0x2028L <= ucp && 0x2029L >= ucp) { res = -1; }
1196 else if( 0xE0001L == ucp) { res = -1; }
1205 else if(0xE0020L <= ucp && 0xE007FL >= ucp) { res = -1; }
1219 static void enc_uc_lookup_cdc(
long int ucp,
struct uc_cdc* res)
1231 while(-1L != uc_cdc_table[i].cp)
1233 if(ucp == uc_cdc_table[i].cp)
1236 res->ccc = uc_cdc_table[i].ccc;
1237 res->dc1 = uc_cdc_table[i].dc1;
1238 res->dc2 = uc_cdc_table[i].dc2;
1245 if(-1L == res->dc1) { res->dc1 = ucp; res->dc2 = -1L; }
1264 static long int enc_uc_lookup_cc(
long int starter,
long int cm)
1274 const long int SBase = 0xAC00L;
1275 const long int LBase = 0x1100L;
1276 const long int VBase = 0x1161L;
1277 const long int TBase = 0x11A7L;
1278 const long int NCount = 588L;
1279 const long int LCount = 19L;
1280 const long int VCount = 21L;
1281 const long int TCount = 28L;
1283 enum uc_hs_type hst;
1284 enum uc_hs_type hst2;
1290 enc_uc_lookup_cdc(starter, &cdc);
1295 while(-1L != uc_cdc_table[i].cp)
1297 if(uc_cdc_table[i].dc1 == starter && uc_cdc_table[i].dc2 == cm)
1300 res = uc_cdc_table[i].cp;
1303 while(-1L != uc_fce_table[ii].first)
1305 first = uc_fce_table[ii].first;
1306 last = uc_fce_table[ii].last;
1307 if(first <= res && last >= res)
1310 #if ENC_UC_NORM_DEBUG
1311 printf(
" Canonical composition exception\n");
1327 enc_uc_lookup_cdc(cm, &cdc);
1331 while(-1L == res && -1L != uc_hst_table[i].first)
1333 first = uc_hst_table[i].first;
1334 last = uc_hst_table[i].last;
1335 hst = uc_hst_table[i].hst;
1336 if(first <= starter && last >= starter)
1338 if(UC_HST_L == hst || UC_HST_LV == hst)
1342 while(-1L != uc_hst_table[ii].first)
1344 first = uc_hst_table[ii].first;
1345 last = uc_hst_table[ii].last;
1346 hst2 = uc_hst_table[ii].hst;
1347 if(first <= cm && last >= cm)
1349 if(UC_HST_L == hst && UC_HST_V == hst2)
1351 if(LBase <= starter && VBase <= cm)
1353 LIndex = starter - LBase;
1356 VIndex = cm - VBase;
1359 #if ENC_UC_NORM_DEBUG
1360 printf(
" Canonical composition"
1361 " for hangul LV-syllable found\n");
1362 printf(
"Hangul LIndex: %ld\n", LIndex);
1363 printf(
"Hangul VIndex: %ld\n", VIndex);
1367 + LIndex * NCount + VIndex * TCount;
1372 else if(UC_HST_LV == hst && UC_HST_T == hst2)
1376 TIndex = cm - TBase;
1379 #if ENC_UC_NORM_DEBUG
1380 printf(
" Canonical composition"
1381 " for hangul LVT-syllable found\n");
1382 printf(
"Hangul TIndex: %ld\n", TIndex);
1385 res = starter + TIndex;
1394 " for hangul syllable failed");
1401 while(-1L != uc_hst_table[ii].first)
1403 first = uc_hst_table[ii].first;
1404 last = uc_hst_table[ii].last;
1405 hst = uc_hst_table[ii].hst;
1406 if(first <= res && last >= res)
1408 if(2 == jamo && UC_HST_LV != hst)
1413 if(3 == jamo && UC_HST_LVT != hst)
1459 static void enc_uc_lookup_cf(
long int ucp,
long int mapping[3])
1465 while(-1L != uc_cf_table[i].cp)
1467 if(ucp == uc_cf_table[i].cp)
1470 mapping[0] = uc_cf_table[i].first;
1471 mapping[1] = uc_cf_table[i].second;
1472 mapping[2] = uc_cf_table[i].third;
1509 static size_t enc_uc_get_glyph_count(
const char* s,
size_t end)
1518 ucp = enc_uc_decode_utf8(s, &i);
1519 if(-1L == ucp) {
break; }
1523 if (!((0x00ADL == ucp) && (end && i < end)))
1526 enc_uc_lookup_cdc(ucp, &cdc);
1527 if(!cdc.ccc) { ++res; }
1530 if(end && i >= end) {
break; }
1551 static int enc_uc_check_nfc(
const char* s)
1560 unsigned char ccc_last = 0;
1564 ucp = enc_uc_decode_utf8(s, &i);
1565 if(-1L == ucp) {
break; }
1571 while(-1L != uc_qc_nfc_table[ii].first)
1573 first = uc_qc_nfc_table[ii].first;
1574 last = uc_qc_nfc_table[ii].last;
1575 if(first <= ucp && last >= ucp)
1585 enc_uc_lookup_cdc(ucp, &cdc);
1586 if(cdc.ccc && (cdc.ccc < ccc_last)) { res = -1;
break; }
1589 else { ccc_last = 0; }
1592 #if ENC_UC_NORM_DEBUG
1595 printf(
"Maybe not NFC: %s (len: %u)\n ", s, (
unsigned int) strlen(s));
1598 printf(
" 0x%02X", (
unsigned int) (
unsigned char) s[i++]);
1622 static int enc_uc_engine_decompose(
long int ucp,
long int* dbuf,
size_t* di)
1628 if(ENC_UC_DECOMPOSITION_BUFSIZE - (
size_t) 2 <= *di)
1631 PRINT_ERROR(
"Unicode canonical decomposition engine failed");
1632 dbuf[0] = (
long int) (
unsigned char)
'[';
1633 dbuf[1] = (
long int) (
unsigned char)
'E';
1634 dbuf[2] = (
long int) (
unsigned char)
'r';
1635 dbuf[3] = (
long int) (
unsigned char)
'r';
1636 dbuf[4] = (
long int) (
unsigned char)
'o';
1637 dbuf[5] = (
long int) (
unsigned char)
'r';
1638 dbuf[6] = (
long int) (
unsigned char)
']';
1645 enc_uc_lookup_cdc(ucp, &cdc);
1646 if(cdc.dc1 != ucp) { res = enc_uc_engine_decompose(cdc.dc1, dbuf, di); }
1647 else { dbuf[(*di)++] = cdc.dc1; }
1648 if(-1L != cdc.dc2) { dbuf[(*di)++] = cdc.dc2; }
1665 static void enc_uc_engine_reorder(
long int* dbuf,
size_t di)
1667 size_t i, ii, iii, iiii;
1674 for(i = 0; i < di; ++i)
1676 enc_uc_lookup_cdc(dbuf[i], &cdc);
1680 #if ENC_UC_NORM_DEBUG
1681 printf(
" Nonstarter: U+%04lX (ccc=%u)\n",
1682 dbuf[i], (
unsigned int) cdc.ccc);
1687 enc_uc_lookup_cdc(dbuf[ii], &cdc);
1688 if(!cdc.ccc) {
break; }
1692 #if ENC_UC_NORM_DEBUG
1693 printf(
" Sort burst: len=%u\n", (
unsigned int) len);
1695 for(iii = i; iii < i + len; ++iii)
1703 for(iiii = i + len - (
size_t) 1; iiii > iii; --iiii)
1705 enc_uc_lookup_cdc(dbuf[iiii - (
size_t) 1], &cdc);
1707 enc_uc_lookup_cdc(dbuf[iiii], &cdc);
1711 tmp = dbuf[iiii - (size_t) 1];
1712 dbuf[iiii - (size_t) 1] = dbuf[iiii];
1718 #if ENC_UC_NORM_DEBUG
1719 else { printf(
" Starter : U+%04lX\n", dbuf[i]); }
1732 static void enc_uc_engine_compose(
long int* dbuf,
size_t* di)
1744 #if ENC_UC_NORM_DEBUG
1746 printf(
" Starter at beginning : U+%04lX\n", dbuf[0]);
1747 printf(
" Codepoint in question: U+%04lX\n", dbuf[i]);
1749 ucp = enc_uc_lookup_cc(dbuf[0], dbuf[i]);
1753 enc_uc_lookup_cdc(dbuf[i], &cdc);
1755 #if ENC_UC_NORM_DEBUG
1756 printf(
" Codepoint has ccc : %u\n", (
unsigned int) ccc);
1757 printf(
" Canonical composition: U+%04lX\n", ucp);
1761 for(ii = 1; ii < i; ++ii)
1763 enc_uc_lookup_cdc(dbuf[ii], &cdc);
1767 #if ENC_UC_NORM_DEBUG
1768 printf(
" => Don't compose\n");
1774 if(skip) {
continue; }
1776 #if ENC_UC_NORM_DEBUG
1777 printf(
" => Compose\n");
1779 for(ii = i; ii < *di - (size_t) 1; ++ii)
1781 dbuf[ii] = dbuf[ii + (size_t) 1];
1788 #if ENC_UC_NORM_DEBUG
1812 static const char* enc_uc_engine_n(
const char* s,
size_t* l,
int nfc)
1822 long int dbuf[ENC_UC_DECOMPOSITION_BUFSIZE];
1829 if(rlen - ri <= (
size_t) 4 * ENC_UC_DECOMPOSITION_BUFSIZE)
1836 if(!rlen) { rlen = (size_t) 4 * ENC_UC_DECOMPOSITION_BUFSIZE; }
1838 p = posix_realloc((
void*) res, rlen);
1839 if(NULL == p) { posix_free((
void*) res); res = NULL;
break; }
1844 ucp = enc_uc_decode_utf8(s, &i);
1845 if(-1L == ucp) {
break; }
1846 enc_uc_lookup_cdc(ucp, &cdc);
1854 enc_uc_engine_reorder(dbuf, di);
1855 if(nfc) { enc_uc_engine_compose(dbuf, &di); }
1862 if(!error) { error = enc_uc_engine_decompose(ucp, dbuf, &di); }
1867 enc_uc_engine_reorder(dbuf, di);
1868 if(nfc) { enc_uc_engine_compose(dbuf, &di); }
1899 static const char* enc_uc_engine_nfd(
const char* s,
size_t* l)
1901 return(enc_uc_engine_n(s, l, 0));
1925 static const char* enc_uc_engine_nfc_part1(
const char* s,
size_t* l)
1927 return(enc_uc_engine_n(s, l, 1));
1948 static const char* enc_uc_engine_nfc_part2(
const char* s,
size_t l,
1960 #if ENC_UC_NORM_DEBUG
1961 printf(
" *** Part 2 ***\n");
1963 res = posix_malloc(++l);
1969 ucp = enc_uc_decode_utf8(s, &i);
1970 if(-1L == ucp) {
break; }
1973 enc_uc_lookup_cdc(ucp, &cdc);
1982 if((
size_t) 2 == di)
1984 enc_uc_engine_compose(dbuf, &di);
1986 if((
size_t) 2 == di)
2005 if(NULL != res) { res[ri] = 0; }
2007 #if ENC_UC_NORM_DEBUG
2010 printf(
"Now NFC: %s (len: %u)\n ", res, (
unsigned int) strlen(res));
2011 i = 0;
while(res[i])
2013 printf(
" 0x%02X", (
unsigned int) (
unsigned char) res[i++]);
2042 static const char* enc_uc_strip_dccs(
const char* s)
2044 const char* res = NULL;
2055 ucp = enc_uc_decode_utf8(s, &i);
2056 if(-1L == ucp) {
break; }
2057 enc_uc_lookup_cdc(ucp, &cdc);
2058 if(!cdc.ccc) {
break; }
2062 if(!skip) {
PRINT_ERROR(
"Semantic error in Unicode string"); }
2069 len = strlen(&s[i]);
2070 res = (
const char*) posix_malloc(++len);
2071 if(NULL != res) { memcpy((
void*) res, &s[i], len); }
2108 static const char* enc_uc_normalize_to_nfd(
const char* s)
2110 const char* res = NULL;
2115 res = enc_uc_strip_dccs(s);
2119 tgt = enc_uc_engine_nfd(res, &l);
2120 if(res != s) { posix_free((
void*) res); }
2125 if(NULL == res) {
PRINT_ERROR(
"Unicode NFD normalization failed"); }
2163 static const char* enc_uc_normalize_to_nfc(
const char* s)
2165 const char* res = NULL;
2171 res = enc_uc_strip_dccs(s);
2174 if(NULL != res && enc_uc_check_nfc(res))
2177 tgt = enc_uc_engine_nfc_part1(res, &l);
2178 if(res != s) { posix_free((
void*) res); }
2183 tgt = enc_uc_engine_nfc_part2(res, l, &flag);
2184 posix_free((
void*) res);
2186 if(NULL != res && flag)
2189 tgt = enc_uc_engine_nfc_part1(res, &l);
2190 posix_free((
void*) res);
2197 if(NULL == res) {
PRINT_ERROR(
"Unicode NFC normalization failed"); }
2219 static const char* enc_iso2022_convert_to_utf8_nfc(
enum enc_mime_cs charset,
2222 const char* res = s;
2223 size_t len = strlen(s);
2225 enum iso2022_state state = ISO2022_ASCII;
2229 unsigned char ku = 0;
2242 if(NULL != strchr(s, 0x1B))
2249 buf = (
char*) posix_malloc(++len * (
size_t) 2);
2252 for(i = 0; i < len; ++i)
2255 if(0x1BU == (
unsigned int) s[i]) { esc = 1;
continue; }
2260 if(
'(' == s[i]) { mode = 1; }
2261 else if(
'$' == s[i]) { mode = 2; }
2269 if(
'B' == s[i]) { state = ISO2022_ASCII; }
2270 else if(
'J' == s[i]) { state = ISO2022_ISO646; }
2275 state = ISO2022_JIS_X_0208;
2281 state = ISO2022_ASCII;
2290 case ISO2022_ISO646:
2292 if(0x80U & (
unsigned int) s[i])
2295 " in ISO 2022-JP data");
2301 if(0x5CU == (
unsigned int) s[i])
2303 buf[bi++] = (char) 0xC2;
2304 buf[bi++] = (char) 0xA5;
2307 else if(
'~' == s[i])
2309 buf[bi++] = (char) 0xE2;
2310 buf[bi++] = (char) 0x80;
2311 buf[bi++] = (char) 0xBE;
2313 else { buf[bi++] = s[i]; }
2317 case ISO2022_JIS_X_0208:
2324 if(first) { ku = (
unsigned char) s[i]; }
2327 ten = (
unsigned char) s[i];
2328 if(33U > ku || 126U < ku || 33U > ten || 126U < ten)
2336 if( (32U + 9U <= ku && 32U + 15U >= ku)
2337 || (32U + 85U <= ku && 32U + 94U >= ku) )
2341 "Unassigned codepoint in ISO 2022-JP data");
2342 buf[bi++] = (char) 0xEF;
2343 buf[bi++] = (char) 0xBF;
2344 buf[bi++] = (char) 0xBD;
2348 jis = (
long int) ((
unsigned long int) ku << 8);
2349 jis |= (
long int) (
unsigned long int) ten;
2354 if(iso2022_jp_table[ii].jis == -1L)
2357 "ISO 2022-JP data failed");
2360 if(iso2022_jp_table[ii].jis == jis)
2362 ucp = iso2022_jp_table[ii].uc;
2369 buf[bi++] = (char) 0xEF;
2370 buf[bi++] = (char) 0xBF;
2371 buf[bi++] = (char) 0xBD;
2386 if(0x80U & (
unsigned int) s[i])
2389 " in US-ASCII data");
2403 if(ISO2022_ASCII != state)
2405 PRINT_ERROR(
"ISO 2022-JP data doesn't end in ASCII state");
2439 static enum enc_mime_cs enc_mime_get_charset(
const char* s,
size_t len)
2444 const char not_supported[] =
"MIME: Unsupported character set: ";
2454 PRINT_ERROR(
"MIME: Name of character set too long");
2459 for(i = 0; i < len; ++i)
2461 buf[i] = (char) toupper((
int) s[i]);
2494 else if(!strcmp(buf,
"KOI8-R")) { res =
ENC_CS_KOI8R; }
2495 else if(!strcmp(buf,
"KOI8-U")) { res =
ENC_CS_KOI8U; }
2506 else if(!strcmp(buf,
"ANSI_X3.4-1968")) { res =
ENC_CS_ASCII; }
2507 else if(!strcmp(buf,
"ANSI_X3.4-1986")) { res =
ENC_CS_ASCII; }
2508 else if(!strcmp(buf,
"ISO-IR-6")) { res =
ENC_CS_ASCII; }
2509 else if(!strcmp(buf,
"ISO_646.IRV:1991")) { res =
ENC_CS_ASCII; }
2510 else if(!strcmp(buf,
"ISO646-US")) { res =
ENC_CS_ASCII; }
2511 else if(!strcmp(buf,
"IBM367")) { res =
ENC_CS_ASCII; }
2513 else if(!strcmp(buf,
"CSASCII")) { res =
ENC_CS_ASCII; }
2516 else if(!strcmp(buf,
"CSUTF-8")) { res =
ENC_CS_UTF_8; }
2521 else if(!strcmp(buf,
"CSUTF-7")) { res =
ENC_CS_UTF_7; }
2645 else if(!strcmp(buf,
"CSKOI8R")) { res =
ENC_CS_KOI8R; }
2646 else if(!strcmp(buf,
"CSKOI8U")) { res =
ENC_CS_KOI8U; }
2654 else if(!strcmp(buf,
"CSPC8CODEPAGE437")) { res =
ENC_CS_IBM437; }
2658 else if(!strcmp(buf,
"CSPC775BALTIC")) { res =
ENC_CS_IBM775; }
2661 else if(!strcmp(buf,
"CSPC850MULTILINGUAL")) { res =
ENC_CS_IBM850; }
2669 else if(!strcmp(buf,
"PC-MULTILINGUAL-850+EURO"))
2671 else if(!strcmp(buf,
"CSIBM00858")) { res =
ENC_CS_IBM858; }
2672 else if(!strcmp(buf,
"CCSID00858")) { res =
ENC_CS_IBM858; }
2679 else if(!strcmp(buf,
"ISO8859-1"))
2681 else if(!strcmp(buf,
"ISO8859-2"))
2683 else if(!strcmp(buf,
"ISO8859-3"))
2685 else if(!strcmp(buf,
"ISO8859-4"))
2687 else if(!strcmp(buf,
"ISO8859-5"))
2689 else if(!strcmp(buf,
"ISO8859-6"))
2691 else if(!strcmp(buf,
"ISO8859-7"))
2693 else if(!strcmp(buf,
"ISO8859-8"))
2695 else if(!strcmp(buf,
"ISO8859-9"))
2697 else if(!strcmp(buf,
"ISO8859-10"))
2699 else if(!strcmp(buf,
"ISO-8859-11"))
2701 else if(!strcmp(buf,
"ISO8859-11"))
2703 else if(!strcmp(buf,
"ISO8859-13"))
2705 else if(!strcmp(buf,
"ISO8859-14"))
2707 else if(!strcmp(buf,
"ISO8859-15"))
2709 else if(!strcmp(buf,
"ISO8859-16"))
2714 else if(!strcmp(buf,
"MACROMAN"))
2716 else if(!strcmp(buf,
"X-MAC-ROMAN"))
2720 else if(!strcmp(buf,
"CP-437")) { ibminv = 1; res =
ENC_CS_IBM437; }
2721 else if(!strcmp(buf,
"IBM858")) { ibminv = 1; res =
ENC_CS_IBM858; }
2722 else if(!strcmp(buf,
"CP858")) { ibminv = 1; res =
ENC_CS_IBM858; }
2723 else if(!strcmp(buf,
"CP1250"))
2725 else if(!strcmp(buf,
"CP1251"))
2727 else if(!strcmp(buf,
"CP1252"))
2729 else if(!strcmp(buf,
"CP1253"))
2731 else if(!strcmp(buf,
"CP1254"))
2733 else if(!strcmp(buf,
"CP1255"))
2735 else if(!strcmp(buf,
"CP1256"))
2737 else if(!strcmp(buf,
"CP1257"))
2739 else if(!strcmp(buf,
"CP1258"))
2743 else if(!strcmp(buf,
"UTF7"))
2745 PRINT_ERROR(
"MIME: Invalid character set UTF7 accepted as UTF-7");
2748 else if(!strcmp(buf,
"UTF8"))
2750 PRINT_ERROR(
"MIME: Invalid character set UTF8 accepted as UTF-8");
2756 if(ENC_CS_UNKNOWN == res)
2759 p = (
char*) posix_malloc(++l);
2764 strcat(p, not_supported);
2765 strncat(p, buf, len);
2767 posix_free((
void*) p);
2777 PRINT_ERROR(
"MIME: Invalid ISO 8859 character set accepted");
2781 PRINT_ERROR(
"MIME: Invalid Macintosh character set accepted");
2785 PRINT_ERROR(
"MIME: Invalid IBM codepage accepted");
2829 static char* enc_mime_decode_qp(
const char* start,
const char* end,
2830 int ec,
size_t* dlen)
2837 size_t ws = POSIX_SIZE_MAX;
2843 char nibble_high = 0;
2848 len = (size_t) (end - start);
2849 p = posix_malloc(len + (
size_t) 1);
2850 if(NULL == p) {
return(NULL); }
2854 for(i = 0; i < len; ++i)
2857 if((
char) 0x0A == start[i] && i)
2859 if((
char) 0x0D == start[i - (
size_t) 1] && POSIX_SIZE_MAX != ws)
2867 if((
char) 0x09 == start[i] || (
char) 0x20 == start[i])
2869 if(POSIX_SIZE_MAX == ws) { ws = bi; }
2871 else if((
char) 0x0D != start[i]) { ws = POSIX_SIZE_MAX; }
2872 src[bi++] = start[i];
2884 for(i = 0; i < (size_t) (end - start); ++i)
2888 if(bi + (
size_t) 4 >= len)
2890 if(!len) { len = 64; }
2891 p = posix_realloc((
void*) tmp, len *= (
size_t) 2);
2894 posix_free((
void*) tmp);
2905 if(!((9 <= v && 10 >= v) || 13 == v || (32 <= v && 126 >= v)))
2910 if(ec && !invalid && (9 == v || 32 == v)) { invalid = 1; }
2914 PRINT_ERROR(
"MIME: Decoding invalid quoted printable data");
2919 if(!state &&
'=' == current) { ++state; }
2931 nibble_high = current;
2939 ((
char) 0x09 == nibble_high || (
char) 0x20 == nibble_high) )
2941 if((
char) 0x09 == current || (
char) 0x20 == current) {
break; }
2942 else if((
char) 0x0D == current)
2944 nibble_high = current;
2955 if(!ec && (
char) 0x0D == nibble_high && (
char) 0x0A == current)
2962 v = enc_hex_decode_nibble(nibble_high);
2963 if(0 > v) { invalid = 1; }
2966 c = (
unsigned char) (v * 16);
2967 v = enc_hex_decode_nibble(current);
2968 if(0 > v) { invalid = 1; }
2969 else { c += (
unsigned char) v; }
2974 PRINT_ERROR(
"MIME: Invalid quoted printable encoded data");
2976 tmp[bi++] = nibble_high;
2977 c = (
unsigned char) current;
2984 if(ec &&
'_' == current) { c = (
unsigned char) 0x20; }
2985 else { c = (
unsigned char) current; }
2989 if(c) { tmp[bi++] = (char) c; }
2993 if(NULL == tmp) { res = NULL; }
3001 posix_free((
void*) src);
3027 static const char* enc_mime_decode_q(
enum enc_mime_cs charset,
3028 const char* start,
const char* end,
3031 const char* res = NULL;
3035 tmp = enc_mime_decode_qp(start, end, ec, &len);
3040 if(tmp != res) { posix_free((
void*) tmp); }
3071 static char* enc_mime_decode_base64(
const char* start,
const char* end,
3072 int np,
size_t* dlen)
3082 unsigned long int ii = 0;
3083 unsigned long int input = 0;
3087 for(i = 0; i < (size_t) (end - start); ++i)
3090 if(bi + (
size_t) 4 >= len)
3092 if(!len) { len = 64; }
3093 p = posix_realloc((
void*) tmp, len *= (
size_t) 2);
3096 PRINT_ERROR(
"MIME: Out of memory while decoding base64 data");
3107 if(0 == state || 1 == state)
3110 PRINT_ERROR(
"MIME: Invalid padding in base64 encoded data");
3119 if(
' ' == start[i] || 0x09 == start[i]
3120 || 0x0A == start[i] || 0x0D == start[i])
3125 for(ii = 0; ii < 64UL; ++ii)
3127 if(enc_base64[ii] == start[i])
3137 PRINT_ERROR(
"MIME: Invalid character in base64 encoded data");
3162 if(
'=' == start[i]) { padding = 2; }
3163 else { input |= ii << 6; }
3172 if(!padding) { padding = 1; }
3176 PRINT_ERROR(
"MIME: Invalid padding in base64 encoded data");
3180 else { input |= ii; }
3182 tmp[bi++] = (char) (
unsigned char) ((input >> 16) & 0xFFUL);
3185 tmp[bi++] = (char) (
unsigned char) ((input >> 8) & 0xFFUL);
3188 tmp[bi++] = (char) (
unsigned char) (input & 0xFFUL);
3196 PRINT_ERROR(
"MIME: base64 state machine failed (Bug)");
3201 if(abort) {
break; }
3202 if(padding && 0 == state) {
break; }
3206 posix_free((
void*) tmp);
3211 if(!abort && np && state)
3218 if(input & 0x000FFFUL) { abort = 1; }
3221 tmp[bi++] = (char) (
unsigned char) ((input >> 16) & 0xFFUL);
3228 if(input & 0x00003FUL) { abort = 1; }
3231 tmp[bi++] = (char) (
unsigned char) ((input >> 16) & 0xFFUL);
3232 tmp[bi++] = (char) (
unsigned char) ((input >> 8) & 0xFFUL);
3244 PRINT_ERROR(
"MIME: Invalid end of unpadded base64 data");
3249 if(NULL == tmp) { res = NULL; }
3257 printf(
"Length of base64 decoded data: %u\n", (
unsigned int) *dlen);
3289 static const char* enc_mime_decode_b(
enum enc_mime_cs charset,
3290 const char* start,
const char* end,
3293 const char* res = NULL;
3296 const char* tmp2 = NULL;
3298 tmp = enc_mime_decode_base64(start, end, np, &len);
3305 tmp2 = enc_uc_convert_utf16be_to_utf8(tmp, len);
3312 else { posix_free((
void*) tmp); }
3321 if(tmp2 != res) { posix_free((
void*) tmp2); }
3340 static const char* enc_uc_convert_cesu8_to_utf8(
const char* s)
3342 const char* res = NULL;
3344 size_t len = strlen(s);
3353 rv = enc_uc_check_cesu8(s, 0);
3360 buf = (
char*) posix_malloc(len + (
size_t) 1);
3367 mbc = enc_uc_decode_utf8(s, &i);
3375 if(0x00D800L <= mbc && 0x00DFFFL >= mbc)
3377 if(0x00DBFFL >= mbc)
3382 PRINT_ERROR(
"Invalid high surrogate in CESU-8 data");
3397 PRINT_ERROR(
"Invalid low surrogate in CESU-8 data");
3404 ucp = (hs & 0x0003FFL) << 10;
3405 ucp |= (mbc & 0x0003FFL);
3437 static const char* enc_uc_convert_utf7_to_utf8(
const char* s)
3439 const char* res = NULL;
3444 size_t len = strlen(s);
3447 const char* start = NULL;
3448 const char* end = NULL;
3464 buf = (
char*) posix_malloc(++len * (
size_t) 2);
3475 if(
'-' == s[i + (
size_t) 1])
3483 start = &s[i + (size_t) 1];
3491 if(0x09 == c || 0x0A == c || 0x0D == c|| 0x20 == c)
3496 else if( (0x30 <= c && 0x39 >= c)
3497 || (0x41 <= c && 0x5A >= c) || (0x61 <= c && 0x7A >= c)
3498 || (0x27 <= c && 0x29 >= c) || (0x2C <= c && 0x2F >= c)
3499 || 0x3A == c || 0x3F == c )
3504 else if( (0x21 <= c && 0x26 >= c) || 0x2A == c
3505 || (0x3B <= c && 0x3E >= c)
3506 || 0x40 == c || 0x5B == c
3507 || (0x5D <= c && 0x60 >= c) || (0x7B <= c && 0x7D >= c) )
3513 PRINT_ERROR(
"Invalid character in UTF-7 data ignored");
3521 for(ii = 0; ii < (size_t) 64; ++ii)
3523 if(enc_base64[ii] == s[i]) { c = (int) s[i];
break; }
3526 if(!s[i + (
size_t) 1]) { eod = 1; }
3530 if(!c) { end = &s[i]; }
3531 else { end = &s[i + (size_t) 1]; }
3534 if(NULL == utf8) { buf[bi++] =
'?'; }
3537 utf8_len = strlen(utf8);
3538 for(ii = 0; ii < utf8_len; ++ii) { buf[bi++] = utf8[ii]; }
3539 posix_free((
void*) utf8);
3542 if(!c &&
'-' != s[i]) { --i; }
3557 PRINT_ERROR(
"UTF-7 converter terminated in shift state (bug)");
3572 static int enc_check_leap_year(
unsigned int year)
3574 if(!(year % 400U) || (!(year % 4U) && (year % 100U))) {
return(1); }
3598 static int enc_encode_posix_timestamp(
core_time_t* pts,
unsigned int year,
3599 unsigned int month,
unsigned int day,
3600 unsigned int hour,
unsigned int minute,
3601 unsigned int second,
int zone)
3603 static const unsigned int dom[12] = { 31U, 29U, 31U, 30U, 31U, 30U,
3604 31U, 31U, 30U, 31U, 30U, 31U };
3616 PRINT_ERROR(
"Warning: core_time_t overflow while decoding timestamp");
3619 for(i = 1970U; i < year; ++i)
3623 if(enc_check_leap_year(i)) { ts += (
core_time_t) 86400; }
3625 for(i = 0; i < month - 1U; ++i)
3629 if(1U == i && !enc_check_leap_year(year))
3647 if(ts >= zone_seconds)
3667 printf(
"Seconds : %lu\n", (
long int) ts);
3669 t = gmtime((posix_time_t*) &ts);
3670 printf(
"Conv. UTC: %04d-%02d-%02d %02d:%02d:%02d\n",
3671 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
3672 t->tm_hour, t->tm_min, t->tm_sec);
3690 static int enc_check_atom(
const char* s)
3696 if(0x30 <= c && 0x39 >=c) { res = 0; }
3697 else if(0x41 <= c && 0x5A >=c) { res = 0; }
3698 else if(0x61 <= c && 0x7A >=c) { res = 0; }
3699 else if((
int)
'!' == c) { res = 0; }
3700 else if((
int)
'#' == c) { res = 0; }
3701 else if((
int)
'$' == c) { res = 0; }
3702 else if((
int)
'%' == c) { res = 0; }
3703 else if((
int)
'&' == c) { res = 0; }
3704 else if(0x27 == c) { res = 0; }
3705 else if((
int)
'*' == c) { res = 0; }
3706 else if((
int)
'+' == c) { res = 0; }
3707 else if((
int)
'-' == c) { res = 0; }
3708 else if((
int)
'/' == c) { res = 0; }
3709 else if((
int)
'=' == c) { res = 0; }
3710 else if((
int)
'?' == c) { res = 0; }
3711 else if((
int)
'^' == c) { res = 0; }
3712 else if((
int)
'_' == c) { res = 0; }
3713 else if((
int)
'`' == c) { res = 0; }
3714 else if((
int)
'{' == c) { res = 0; }
3715 else if((
int)
'|' == c) { res = 0; }
3716 else if((
int)
'}' == c) { res = 0; }
3717 else if((
int)
'~' == c) { res = 0; }
3733 static int enc_check_dotatom(
const char* s)
3738 if(
'.' == *s) { res = 0; }
3739 else { res = enc_check_atom(s); }
3754 static void enc_encode_dispname(
char* s)
3757 char buf[ENC_HDR_BUFSIZE + (size_t) 1];
3759 char word[ENC_HDR_BUFSIZE + (size_t) 1];
3772 ii = i;
while(
' ' == s[ii]) { ++ii; }
3773 w = strchr(&s[ii], (
int)
' ');
3776 word_len = strlen(&s[i]);
3779 else { word_len = (size_t) (w - &s[i]); }
3780 if(ENC_HDR_BUFSIZE < word_len) { word[0] = 0; }
3783 memcpy((
void*) word, (
void*) &s[i], word_len);
3787 if(!last_word) { ++i; }
3794 if(0x80U <= (
unsigned int) (
unsigned char) word[ii])
3799 if(enc_check_atom(&word[ii])) { atom = 0; }
3806 if(ENC_HDR_BUFSIZE <= bi) {
break; }
else { buf[bi++] =
' '; }
3812 if(ENC_HDR_BUFSIZE - bi < word_len) {
break; }
3815 memcpy((
void*) &buf[bi], (
void*) word, word_len);
3825 if(ENC_HDR_BUFSIZE <= bi) { error = 1; }
else { buf[bi++] =
'"'; }
3827 for(ii = 0; ii < word_len; ++ii)
3830 cbuf[0] = word[ii]; cbuf[1] = 0;
3833 if(ENC_HDR_BUFSIZE - bi < (
size_t) 2) { error = 1;
break; }
3835 if(
'"' == word[ii] || 0x5C == (
int) word[ii]) { buf[bi++] = 0x5C; }
3836 buf[bi++] = word[ii];
3839 if(ENC_HDR_BUFSIZE <= bi) { error = 1; }
else { buf[bi++] =
'"'; }
3840 if(error) { bi = start; }
3842 if(last_word) {
break; }
3847 strncpy(s, buf, ++bi);
3869 static char* enc_mime_decode_parameter(
const char* buf,
const char* cs)
3873 const char* tmp2 = NULL;
3882 tmp = (
char*) posix_malloc(++len);
3885 memcpy((
void*) tmp, (
void*) buf, len);
3888 PRINT_ERROR(
"MIME: Nonprintable characters in parameter");
3895 PRINT_ERROR(
"MIME: Percent encoding failed for parameter");
3899 charset = enc_mime_get_charset(cs, strlen(cs));
3903 PRINT_ERROR(
"MIME: Parameter charset not supported");
3908 res = (
char*) posix_malloc(++len);
3911 memcpy((
void*) res, (
void*) tmp2, len);
3913 if(tmp != tmp2) { posix_free((
void*) tmp2); }
3919 posix_free((
void*) tmp);
3954 const char* res = NULL;
3962 char name[(size_t) 2 * ENC_HDR_BUFSIZE + (
size_t) 1];
3963 char addr_spec[ENC_HDR_BUFSIZE + (size_t) 1];
3966 if((
size_t) 2 * ENC_HDR_BUFSIZE < strlen(
data)) { error = 1; }
3971 if(!strlen(name)) { error = 1; }
3979 if(NULL == strchr(&name[i + (
size_t) 1], (
int)
'<'))
3981 if(!i) { name[0] = 0; }
3982 else { name[i - (size_t) 1] = 0; }
3983 if(ENC_HDR_BUFSIZE < strlen(&name[i])) { error = 1; }
3986 strcpy(addr_spec, &name[++i]);
3987 i = strlen(addr_spec) - (size_t) 1;
3988 if(
'>' != addr_spec[i]) { addr_spec[0] = 0; }
3989 else { addr_spec[i] = 0; }
4002 enc_encode_dispname(name);
4003 len += strlen(name);
4009 len += strlen(addr_spec);
4016 c = addr_spec[i];
if(!c) {
break; }
4017 if(
'@' != c && enc_check_dotatom(&c))
4026 if(!i || !addr_spec[i + (
size_t) 1])
4032 if(
'.' == addr_spec[i - (
size_t) 1]
4033 ||
'.' == addr_spec[i + (
size_t) 1])
4040 if(!error &&
'.' == c)
4042 if(!i || !addr_spec[i + (
size_t) 1])
4053 if(! (error || (
size_t) 1 != counter || (
size_t) 5 > strlen(addr_spec)) )
4056 buf = (
char*) posix_malloc(len);
4065 else { strcpy(buf,
"<"); }
4067 strcat(buf, addr_spec);
4071 if(0 >= rv) { posix_free((
void*) buf); }
4078 if(error) {
PRINT_ERROR(
"Creating name-addr construct failed"); }
4100 unsigned long int res;
4102 if(1 != sscanf(lines,
"%lu", &res)) { res = 0; }
4123 rv = posix_snprintf(l, 11,
"%lu", l_raw);
4124 if(0 > rv || 11 <= rv)
4156 static const char* months[12] = {
"JAN",
"FEB",
"MAR",
"APR",
"MAY",
"JUN",
4157 "JUL",
"AUG",
"SEP",
"OCT",
"NOV",
"DEC" };
4158 static const unsigned int dom[12] = { 31U, 29U, 31U, 30U, 31U, 30U,
4159 31U, 31U, 30U, 31U, 30U, 31U };
4167 unsigned int zh = 0;
4168 unsigned int zm = 0;
4171 unsigned int month = 13U;
4173 unsigned int hour = 0;
4174 unsigned int minute = 0;
4175 unsigned int second = 0;
4181 printf(
"------------------------------------------------------------\n");
4182 printf(
"Timestamp: %s\n", timestamp);
4186 p = strchr(timestamp, (
int)
',');
4187 if(NULL == p) { p = timestamp; }
else { ++p; }
4190 rv = sscanf(p,
"%u %3c %u%n", &day, m, &year, &pos);
4191 if(3 != rv) {
PRINT_ERROR(
"Invalid date in timestamp"); }
4197 if(50U > year) { year += 2000U; }
else { year += 1900U; }
4200 m[0] = (char) toupper((
int) m[0]);
4201 m[1] = (char) toupper((
int) m[1]);
4202 m[2] = (char) toupper((
int) m[2]);
4204 for(i = 0; i < 12; ++i)
4206 if(!strcmp(months[i], m)) { month = i + 1U;
break; }
4208 if(13U <= month) {
PRINT_ERROR(
"Invalid month in timestamp"); }
4212 if(1U > day || dom[i] < day) { month = 13U; }
4215 if(2U == month && 29U == day)
4218 if(!enc_check_leap_year(year)) { month = 13U; }
4232 rv = sscanf(p,
"%u : %u%n", &hour, &minute, &pos);
4240 q = strchr(p, (
int)
':');
4241 if(NULL != q) { p = q; }
4242 rv = sscanf(p,
": %u%n", &second, &pos);
4243 if(1 == rv) { p += pos; }
4244 rv = sscanf(p,
"%5s", z);
4253 if(23U < hour || 59U < minute || 60U < second)
4260 if(
'+' == z[0] ||
'-' == z[0])
4262 for(i = 1; i < 5; ++i)
4268 zh = ((
unsigned int) z[1] - 0x30) * 10U;
4269 zh += ((
unsigned int) z[2] - 0x30);
4270 zm = ((
unsigned int) z[3] - 0x30) * 10U;
4271 zm += ((
unsigned int) z[4] - 0x30);
4272 if(59U < zm) { zone = 0; }
4280 zone = (int) (zh * 60U + zm);
4281 if(
'-' == z[0]) { zone *= -1; }
4287 if(!strcmp(
"GMT", z)) { zone = 0; }
4288 else if(!strcmp(
"UT", z)) { zone = 0; }
4289 else if(!strcmp(
"EDT", z)) { zone = -4 * 60; }
4290 else if(!strcmp(
"EST", z)) { zone = -5 * 60; }
4291 else if(!strcmp(
"CDT", z)) { zone = -5 * 60; }
4292 else if(!strcmp(
"CST", z)) { zone = -6 * 60; }
4293 else if(!strcmp(
"MDT", z)) { zone = -6 * 60; }
4294 else if(!strcmp(
"MST", z)) { zone = -7 * 60; }
4295 else if(!strcmp(
"PDT", z)) { zone = -7 * 60; }
4296 else if(!strcmp(
"PST", z)) { zone = -8 * 60; }
4297 else if(!strcmp(
"Z", z)) { zone = 0; }
4301 PRINT_ERROR(
"Decode unknown timezone in timestamp as UTC");
4306 printf(
"Decoded : %04u-%02u-%02u %02u:%02u:%02u %+d minutes\n",
4307 year, month, day, hour, minute, second, zone);
4319 enc_encode_posix_timestamp(&res, year, month, day, hour, minute, second,
4346 struct_posix_tm t_data;
4357 PRINT_ERROR(
"Warning: time_t overflow while converting timestamp");
4360 else { ts = (posix_time_t) pts; }
4367 t = posix_localtime_r(&ts, &t_data);
4371 ign = posix_snprintf(isodate, 20,
"%04d-%02d-%02d %02d:%02d:%02d",
4372 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
4373 t->tm_hour, t->tm_min, t->tm_sec);
4377 if(0 > res) {
PRINT_ERROR(
"Timestamp conversion failed"); }
4399 struct_posix_tm t_data;
4408 if((posix_time_t) 0 > ts) { res = -1; }
4416 t = posix_gmtime_r(&ts, &t_data);
4420 ign = posix_snprintf(isodate, 21,
"%04d-%02d-%02dT%02d:%02d:%02dZ",
4421 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
4422 t->tm_hour, t->tm_min, t->tm_sec);
4427 if(0 > res) {
PRINT_ERROR(
"ISO 8601 date request failed"); }
4458 unsigned int minute;
4459 unsigned int second;
4462 rv = sscanf(isodate,
"%u-%u-%uT%u:%u:%uZ", &year, &month, &mday,
4463 &hour, &minute, &second);
4464 if(6 != rv) {
PRINT_ERROR(
"ISO 8601 timestamp has invalid format"); }
4467 if(1970U <= year && 9999U >= year
4468 && 1U <= month && 12U >= month
4469 && 1U <= mday && 31U >= mday
4470 && 23U >= hour && 59U >= minute && 59U >= second) { res = 0; }
4476 res = enc_encode_posix_timestamp(pts, year, month, mday,
4477 hour, minute, second, 0);
4505 static const char* months[12] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
4506 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" };
4516 rv = sscanf(isodate,
"%u-%u-%u", &year, &month, &mday);
4517 if(3 != rv) {
PRINT_ERROR(
"ISO 8601 timestamp has invalid format"); }
4520 if(1900U <= year && 9999U >= year
4521 && 1U <= month && 12U >= month
4522 && 1U <= mday && 31U >= mday) { res = 0; }
4527 buf = (
char*) posix_malloc(len);
4528 if(NULL == buf) { res = -1; }
4531 posix_snprintf(buf, 50,
"%u %s %04u %02d:%02d:%02d -0000",
4532 mday, months[--month], year, 0, 0, 0);
4533 *ts = (
const char*) buf;
4566 PRINT_ERROR(
"Value of CORE_ANUM_T_MAX is too large");
4570 rv = posix_snprintf(result, 17,
"%lu", (
unsigned long int) wm);
4571 if(rv > 0 && rv <= 16)
4614 if(0 < len && 20 >= len)
4620 c = (
unsigned char) wm[len-- - 1];
4641 if(0 > res) {
PRINT_ERROR(
"Article number conversion failed"); }
4670 if(2 == posix_snprintf(result, 3,
"%02X", octet)) { res = 0; }
4674 if(res) { strcpy(result,
"XX"); }
4702 if(65 <= c && 90 >= c)
4705 if(90 < c) { c = 65 - 1 + (c - 90); }
4709 else if(97 <= c && 122 >= c)
4712 if(122 < c) { c = 97 - 1 + (c - 122); }
4716 if(modified) {
data[i] = (char) c; }
4747 size_t enc_len = (size_t) 4 * len / (
size_t) 3;
4751 unsigned long int word;
4752 unsigned char b64[4];
4754 enc_len += (size_t) 5;
4755 buf = (
char*) posix_malloc(enc_len);
4760 while((
size_t) 3 <= len)
4763 word = (
unsigned long int) (
unsigned char)
data[i++] << 16;
4764 word |= (
unsigned long int) (
unsigned char)
data[i++] << 8;
4765 word |= (
unsigned long int) (
unsigned char)
data[i++];
4768 b64[3] = (
unsigned char) (word & 0x00003FUL);
4769 b64[2] = (
unsigned char) ((word & 0x000FC0UL) >> 6);
4770 b64[1] = (
unsigned char) ((word & 0x03F000UL) >> 12);
4771 b64[0] = (
unsigned char) ((word & 0xFC0000UL) >> 18);
4772 buf[enc_i++] = enc_base64[b64[0]];
4773 buf[enc_i++] = enc_base64[b64[1]];
4774 buf[enc_i++] = enc_base64[b64[2]];
4775 buf[enc_i++] = enc_base64[b64[3]];
4780 word = (
unsigned long int) (
unsigned char)
data[i++] << 16;
4781 if((
size_t) 1 < len)
4783 word |= (
unsigned long int) (
unsigned char)
data[i++] << 8;
4786 b64[3] = (
unsigned char) (word & 0x00003FUL);
4787 b64[2] = (
unsigned char) ((word & 0x000FC0UL) >> 6);
4788 b64[1] = (
unsigned char) ((word & 0x03F000UL) >> 12);
4789 b64[0] = (
unsigned char) ((word & 0xFC0000UL) >> 18);
4790 buf[enc_i++] = enc_base64[b64[0]];
4791 buf[enc_i++] = enc_base64[b64[1]];
4792 if((
size_t) 1 < len) { buf[enc_i++] = enc_base64[b64[2]]; }
4793 else { buf[enc_i++] =
'='; }
4803 if(res) { posix_free((
void*) buf); }
4841 len = strlen(mailbox);
4843 if((
size_t) 3 <= len)
4853 for(i = len; i; --i)
4855 ii = i - (size_t) 1;
4856 if(!state &&
'>' == mailbox[ii])
4862 if(1U == state &&
'@' == mailbox[ii]) { ++state;
continue; }
4863 if(2U == state &&
'<' == mailbox[ii])
4872 if((!state || 3U <= state) && e > s + 2)
4875 len = (size_t) (e - s);
4876 res = (
char*) posix_malloc(len + (
size_t) 1);
4879 memcpy((
void*) res, (
void*) s, len); res[len] = 0;
4883 while(res[i] &&
'@' != res[i])
4885 if(enc_check_dotatom(&res[i])) { state = 1;
break; }
4890 if(!i ||
'@' != res[i]) { state = 1; }
4892 else {
if(!res[++i]) { state = 1; } }
4908 if(enc_check_dotatom(&res[i]))
4919 posix_free((
void*) res);
4928 if(NULL == res) {
PRINT_ERROR(
"Invalid e-mail address"); }
4951 while((c = (
int) s[i++]))
4953 if(!(0 <= c && 127 >= c)) { res = -1; }
4977 if(!(65 <= c && 90 >= c) && !(97 <= c && 122 >= c)) { res = -1; }
5000 if(!(48 <= c && 57 >= c)) { res = -1; }
5029 while((c = (
int) s[i++]))
5031 if(!(9 == c || (32 <= c && 126 >= c))) { res = -1; }
5057 if(!(9 == c || (32 <= c && 126 >= c))) { s[i] =
'?'; }
5088 if(9 == c || 32 == c)
5090 len = strlen(&s[i + (
size_t) 1]);
5092 memmove((
void*) &s[i], (
void*) &s[i + (
size_t) 1], ++len);
5105 if(!start && !i) { error = 1; }
5106 else if(start && start + (
size_t) 1 == i) { error = 1; }
5110 if(
'+' != s[i] &&
'-' != s[i] &&
'_' != s[i] &&
',' != s[i])
5116 if(!error &&
',' == s[i])
5119 if(!s[i + (
size_t) 1]) { error = 1; }
5125 PRINT_ERROR(
"Invalid entry in distribution list removed");
5126 p = strchr(&s[i + (
size_t) 1], (
int)
',');
5128 if(NULL == p) { s[i] = 0; }
5132 if(!start) { p += 1; }
5135 memmove((
void*) &s[start], (
void*) p, ++len);
5165 return enc_uc_check_cesu8(s, 1);
5183 char* res = (
char*) posix_malloc(strlen(s) * (size_t) 3);
5184 const char rc[3] = { (char) 0xEF, (
char) 0xBF, (char) 0xBD };
5190 size_t remaining = 0;
5191 unsigned long int mbc = 0;
5197 while((c = (
int) s[i++]))
5202 if((c & 0xC0) == 0x80) {
continue; }
5203 else { multibyte = 0; }
5208 if(!(0 <= c && 127 >= c)) { multibyte = 1; }
5209 else { res[ri++] = (char) c; }
5220 if((c & 0xE0) == 0xC0) { len = 2; }
5221 else if((c & 0xF0) == 0xE0) { len = 3; }
5222 else if((c & 0xF8) == 0xF0) { len = 4; }
5226 res[ri++] = rc[0]; res[ri++] = rc[1]; res[ri++] = rc[2];
5231 case 2: mbc |= (
unsigned long int) (c & 0x1F) << 6;
break;
5232 case 3: mbc |= (
unsigned long int) (c & 0x0F) << 12;
break;
5233 case 4: mbc |= (
unsigned long int) (c & 0x07) << 18;
break;
5236 remaining = len - (size_t) 1;
5240 if((c & 0xC0) != 0x80)
5243 res[ri++] = rc[0]; res[ri++] = rc[1]; res[ri++] = rc[2];
5244 if(0 <= c && 127 >= c) { res[ri++] = (char) c; }
5250 mbc |= (
unsigned long int) (c & 0x3F) << remaining * (size_t) 6;
5252 if(!remaining && !error)
5259 if(0x000080UL > mbc)
5269 res[ri++] = s[i - (size_t) 2];
5270 res[ri++] = s[i - (size_t) 1];
5277 || (0x00D800UL <= mbc && 0x00DFFFUL >= mbc))
5287 res[ri++] = s[i - (size_t) 3];
5288 res[ri++] = s[i - (size_t) 2];
5289 res[ri++] = s[i - (size_t) 1];
5295 if(0x010000UL > mbc || 0x10FFFFUL < mbc)
5305 res[ri++] = s[i - (size_t) 4];
5306 res[ri++] = s[i - (size_t) 3];
5307 res[ri++] = s[i - (size_t) 2];
5308 res[ri++] = s[i - (size_t) 1];
5315 posix_free((
void*) res);
5336 PRINT_ERROR(
"UTF-8 data still invalid after repair (bug)");
5337 posix_free((
void*) res);
5391 if(NULL == strpbrk(wm,
"\x5C[]"))
5399 len = strlen(&wm[i]);
5401 buf = (
char*) posix_malloc(len * (
size_t) 3 + (size_t) 3);
5402 if(NULL == buf) {
break; }
5412 if((
size_t) 1 < bi) { store = 1; }
5417 if(NULL != strchr(
".()*+?{|^$", (
int) wm[i]))
5483 if(!store) { posix_free((
void*) buf); }
5486 if(INT_MAX == res) { error = 1; }
5494 if(NULL == p) { error = 1; }
5498 (*obj)[res].negate = negate;
5499 (*obj)[res].ere = buf;
5505 posix_free((
void*) buf);
5516 if(error || !eod || 0 >= res)
5518 PRINT_ERROR(
"Failed to convert RFC 3977 wildmat");
5541 if(NULL != obj && NULL != *obj)
5543 for(i = 0; i < num; ++i)
5545 posix_free((
void*) (*obj)[i].ere);
5547 posix_free((
void*) *obj);
5581 const char* res = NULL;
5589 long int rc_ucp = ENC_RC;
5597 p = (
char*) posix_malloc((
size_t) 1);
5598 if(NULL != p) { p[0] = 0; res = p; }
5609 if(bi + (
size_t) 4 + (size_t) 1 >= len)
5612 if(!len) { len = 64; }
5613 p = (
char*) posix_realloc((
void*) buf, len *= (size_t) 2);
5614 if(NULL == p) { posix_free((
void*) buf); buf = NULL;
break; }
5618 if(bi && i && 0x0A == (
int) s[i] && 0x0D == (
int) s[i - (
size_t) 1])
5621 buf[bi - (size_t) 1] = 0x0A;
5623 else if(i && 0x0A != (
int) s[i] && 0x0D == (int) s[i - (
size_t) 1])
5635 else if(0x0A == (
int) s[i])
5649 else { buf[bi++] = s[i]; }
5660 PRINT_ERROR(
"Invalid CR control character(s) detected"
5661 " while decoding canonical format");
5666 PRINT_ERROR(
"Invalid LF control character(s) detected"
5667 " while decoding canonical format");
5697 const char* res = NULL;
5709 p = (
char*) posix_malloc((
size_t) 1);
5710 if(NULL != p) { p[0] = 0; res = p; }
5717 if(bi + (
size_t) 4 >= len)
5720 if(!len) { len = 64; }
5721 p = (
char*) posix_realloc((
void*) buf, len *= (size_t) 2);
5722 if(NULL == p) { posix_free((
void*) buf); buf = NULL;
break; }
5726 if(0x0A == (
int) s[i])
5732 else if(0x0D == (
int) s[i])
5734 PRINT_ERROR(
"Invalid CR control character deleted"
5735 " while converting to canonical format");
5737 else { buf[bi++] = s[i]; }
5745 if(0x0A != (
int) buf[bi - (
size_t) 1])
5790 const char* res = NULL;
5797 long int rc_ucp = ENC_RC;
5798 char rc_utf8[5] = { 0 };
5806 PRINT_ERROR(
"Convert unsupported ISO 8859 character set as US-ASCII");
5812 p = (
char*) posix_malloc(++len);
5813 if(NULL == p) {
break; }
5814 for(i = 0; i < len; ++i)
5817 if((
unsigned char) 127 < (
unsigned char) p[i]) { p[i] =
'?'; }
5855 res = enc_8bit_convert_to_utf8_nfc(charset, s);
5860 res = enc_iso2022_convert_to_utf8_nfc(charset, s);
5865 res = enc_uc_convert_utf7_to_utf8(s);
5870 res = enc_uc_convert_cesu8_to_utf8(s);
5899 PRINT_ERROR(
"Invalid UTF-8 encoding detected (bug)");
5903 if(res != tmp && res != s) { posix_free((
void*) res); }
5911 tmp = enc_uc_normalize_to_nfc(res);
5912 if(res != tmp && res != s) { posix_free((
void*) res); }
5922 ucp = enc_uc_decode_utf8(res, &i);
5923 if(-1L == ucp) {
break; }
5924 if(enc_uc_check_control(ucp)) { cc_flag = 1;
break; }
5934 len *= strlen(rc_utf8);
5935 p = (
char*) posix_malloc(++len);
5938 if(s != res) { posix_free((
void*) res); }
5946 ucp = enc_uc_decode_utf8(res, &i);
5947 if(-1L == ucp) {
break; }
5948 if(enc_uc_check_control(ucp))
5961 if(s != res) { posix_free((
void*) res); }
5964 PRINT_ERROR(
"Unwanted control characters detected and replaced");
6006 const char** cs_iana)
6008 const char* res = NULL;
6021 p = (
char*) posix_malloc(++len);
6026 ucp = enc_uc_decode_utf8(s, &i);
6027 if(-1L == ucp) {
break; }
6029 if(256L <= ucp) { error = 1;
break; }
6030 else { p[ii++] = (char) (
unsigned char) ucp; }
6033 if(error) { posix_free((
void*) p); }
6039 if(NULL != cs_iana) { *cs_iana =
"ISO-8859-1"; }
6105 static const char error_msg[] =
"[Error]";
6106 static const char folding[] =
"\n ";
6109 size_t rbuf_len = 0;
6111 const char* body = NULL;
6112 const char* body_tmp = NULL;
6113 const char* cs_iana =
"UTF-8";
6123 char enc_word[1001];
6126 unsigned int dh, dl;
6132 #if !ENC_MIME_HEADER_FOLD_ASCII_LINES
6141 if((
size_t) 25 < pl)
6149 rem = (size_t) 76 - pl;
6155 && NULL == strstr(b,
"=?") && NULL == strstr(b,
"?="))
6166 PRINT_ERROR(
"MIME: Encoding of header field failed");
6167 p = (
char*) posix_malloc(strlen(error_msg) + (size_t) 1);
6168 if(NULL != p) { strcpy(p, error_msg); }
6174 body_tmp = enc_uc_normalize_to_nfc(b);
6176 if(NULL == body_tmp) { res = -1; }
6189 if(NULL == body) { body = body_tmp; }
6196 cs_iana =
"US-ASCII";
6204 if(!body[i] ||
' ' == body[i])
6209 if(
' ' == body[i + (
size_t) 1]
6210 || (
char) 0x09 == body[i + (
size_t) 1])
6216 enc_last = enc_flag; enc_flag = 0;
6218 for(ii = start; ii <= end; ++ii)
6220 enc_word[ei++] = body[ii];
6221 if(128U <= (
unsigned int) body[ii]) { enc_flag = 1;
break; }
6222 if(
'=' == (
unsigned int) body[ii])
6224 if((ii < end &&
'?' == body[ii + (
size_t) 1])
6225 || (ii > start &&
'?' == body[ii - (
size_t) 1]))
6232 if(enc_split) { enc_flag = 1; }
6236 #if !ENC_MIME_HEADER_FOLD_ASCII_LINES
6239 strcpy(enc_word,
"=?");
6240 strcat(enc_word, cs_iana);
6241 strcat(enc_word,
"?Q?");
6243 if(enc_last && !enc_split)
6246 strcat(enc_word,
"_");
6248 ei = strlen(enc_word);
6249 for(ii = start; ii <= end; ++ii)
6252 if(
ENC_CS_UTF_8 == cs && 0x80 != ((
int) body[ii] & 0xC0))
6260 gcpsl = iii * (size_t) 3;
6262 if(!body[ii + iii]) { eod = 1; }
6266 if(!body[ii + iii]) {
break; }
6267 ucp = enc_uc_decode_utf8(&body[ii], &iii);
6273 enc_uc_lookup_cdc(ucp, &cdc);
6278 if(!cdc.ccc) {
continue; }
6295 if((
size_t) (75 - 12) < gcpsl)
6299 "Combining character sequence too long");
6304 enc_word[ei++] =
'=';
6305 enc_word[ei++] =
'3';
6306 enc_word[ei++] =
'F';
6307 ii += iii - (size_t) 1;
6315 else if(first && ((
size_t) (rem - 2) - gcpsl < ei))
6319 else if((
size_t) (75 - 2) - gcpsl < ei)
6327 if(uc_split) { --ii; }
6331 if( (
'0' <= body[ii] &&
'9' >= body[ii])
6332 || (
'A' <= body[ii] &&
'Z' >= body[ii])
6333 || (
'a' <= body[ii] &&
'z' >= body[ii])
6334 ||
'!' == body[ii] ||
'*' == body[ii] ||
'+' == body[ii]
6335 ||
'-' == body[ii] ||
'/' == body[ii] )
6338 enc_word[ei++] = body[ii];
6343 enc_word[ei++] =
'=';
6344 dh = (
unsigned int) (
unsigned char) body[ii] / 16U;
6345 if(10U > dh) { enc_word[ei++] = (char) (48U + dh); }
6346 else { enc_word[ei++] = (char) (65U + dh - 10U); }
6347 dl = (
unsigned int) (
unsigned char) body[ii] % 16U;
6348 if(10U > dl) { enc_word[ei++] = (char) (48U + dl); }
6349 else { enc_word[ei++] = (char) (65U + dl - 10U); }
6357 if(uc_split || (
size_t) (75 - 3 - 2) < ei)
6369 else { enc_split = 0; }
6372 enc_word[ei++] =
'?';
6373 enc_word[ei++] =
'=';
6379 word_len = strlen(enc_word) + (size_t) 1;
6380 if((
size_t) 998 < word_len)
6387 if(word_len && (word_len > rem)
6389 && !(no_ec && !enc_flag && (word_len < rem + (
size_t) 922))
6396 PRINT_ERROR(
"MIME: Encoded-word too long for first line");
6400 else if(word_len > rem)
6402 memmove((
void*) &enc_word[strlen(folding)], (
void*) enc_word,
6405 memcpy((
void*) enc_word, (
void*) folding, strlen(folding));
6406 word_len += strlen(folding);
6409 #if !ENC_MIME_HEADER_FOLD_ASCII_LINES
6411 if(!enc_flag) { no_ec = 1; }
6421 if(init) { init = 0; --word_len; }
6424 memmove((
void*) &enc_word[1], (
void*) enc_word, word_len);
6430 while(ri + word_len >= rbuf_len)
6432 if(!rbuf_len) { rbuf_len = 128; }
6433 p = posix_realloc((
void*) rbuf, rbuf_len *= (
size_t) 2);
6434 if(NULL == p) { res = -1;
break; }
6437 if(-1 == res) {
break; }
6439 memcpy((
void*) &rbuf[ri], (
void*) enc_word, word_len);
6441 if(rem < word_len) { rem = 0; }
6442 else { rem -= word_len; }
6445 start = i + (size_t) 1;
6450 if(body != body_tmp) { posix_free((
void*) body); }
6451 if(body_tmp != b) { posix_free((
void*) body_tmp); }
6453 if(NULL != rbuf) { rbuf[ri] = 0; }
6460 *r = (
const char*) rbuf;
6470 posix_free((
void*) rbuf);
6522 size_t rbuf_len = 0;
6534 size_t word_trailing_space = 0;
6540 target = strchr(&b[i], (
int)
'=');
6544 target = strchr(&b[i], 0x0A);
6547 target = strchr(&b[i], 0x0D);
6548 if(NULL == target) { res = 1; }
6558 (
' ' == b[i + nbuf_len] || (
const char) 0x09 == b[i + nbuf_len]))
6567 if(
'=' == target[0])
6569 if(
'?' == target[1])
6572 p = strchr(&target[2], (
int)
'?');
6576 p2 = strchr(&target[2], (
int)
'*');
6577 if(NULL == p2) { p2 = p; }
6578 else if(p < p2) { p2 = p; }
6579 charset = enc_mime_get_charset(&target[2],
6580 (
size_t) (p2 - &target[2]));
6584 encoding = (char) toupper((
int) p[1]);
6587 PRINT_ERROR(
"MIME: Syntax error in encoded-word");
6593 p = strchr(target, (
int)
'?');
6599 "Too many fields in encoded-word");
6609 wbuf = enc_mime_decode_q(charset,
6616 wbuf = enc_mime_decode_b(charset,
6638 while( ri && (
' ' == rbuf[ri - (
size_t) 1] ||
6639 0x09 == (
int) rbuf[ri - (
size_t) 1]) )
6643 ri += word_trailing_space;
6648 nbuf_len = strlen(nbuf);
6649 i += (size_t) (&p[2] - &b[i]);
6651 word_trailing_space = 0;
6657 if(
' ' != nbuf[ii]) {
break; }
6658 else { ++word_trailing_space; }
6667 p = strchr(nbuf, (
int)
' ');
6668 p2 = strchr(nbuf, 0x09);
6669 if(NULL != p2 && p2 < p) { p = p2; }
6670 if(NULL == p) { nbuf_len = strlen(nbuf); }
6671 else { nbuf_len = (size_t) (p - nbuf); }
6683 while(ri + nbuf_len >= rbuf_len)
6685 if(!rbuf_len) { rbuf_len = 128; }
6686 if(POSIX_SIZE_MAX / (
size_t) 2 < rbuf_len) { res = -1;
break; }
6687 p = (
char*) posix_realloc((
void*) rbuf, rbuf_len *= (size_t) 2);
6688 if(NULL == p) { res = -1;
break; }
6693 memcpy((
void*) &rbuf[ri], (
void*) nbuf, nbuf_len);
6695 if(NULL != wbuf) { posix_free((
void*) wbuf); }
6698 if(NULL != rbuf) { len = ri; rbuf[len] = 0; }
6706 if(0x0A == (
int) rbuf[ri] || 0x0D == (
int) rbuf[ri])
6715 if(POSIX_SIZE_MAX / (
size_t) 3 <= len) { res = -1; }
6719 rbuf_len = len * (size_t) 3 + (
size_t) 1;
6720 p = (
char*) posix_realloc((
void*) rbuf, rbuf_len);
6721 if(NULL == p) { res = -1; }
6729 if(0x0A == (
int) rbuf[ri] || 0x0D == (int) rbuf[ri])
6731 memmove((
void*) &rbuf[ri + (
size_t) 2], (
void*) &rbuf[ri],
6732 rbuf_len - (ri + (
size_t) 2));
6741 "Unwanted CR and/or LF detected in header field");
6751 *r = (
const char*) rbuf;
6761 posix_free((
void*) rbuf);
6820 posix_locale_t loc_ctype_posix = 0;
6822 struct mime_parameter** parray = NULL;
6823 size_t ppsize =
sizeof(
struct mime_parameter*);
6824 struct mime_parameter* pdata;
6825 size_t psize =
sizeof(
struct mime_parameter);
6826 const char* first_end;
6829 const char* p_start;
6831 const char* p_eq_sign;
6832 const char* p_asterisk;
6838 struct mime_parameter** tmp;
6841 unsigned int sec_num;
6854 loc_ctype_posix = posix_newlocale(POSIX_LC_CTYPE_MASK,
"POSIX",
6855 (posix_locale_t) 0);
6856 if((posix_locale_t) 0 == loc_ctype_posix)
6863 if(NULL == strchr(b, (
int)
'*')) { *r = b; res = 1; }
6868 printf(
"---------------\n");
6869 printf(
"Header field body : %s\n", b);
6872 first_end = strchr(b, (
int)
';');
6873 if(NULL == first_end) { *r = b; res = 1; }
6877 parray = (
struct mime_parameter**) posix_malloc(ppsize);
6890 if(
' ' == *p) { ++p; }
6892 p_end = strchr(p, (
int)
';');
6895 p_end = p + strlen(p);
6897 if(
' ' == *(p_end - 1)) { --p_end; }
6901 p_eq_sign = strchr(p, (
int)
'=');
6902 if(NULL == p_eq_sign) {
break; }
6903 if(p_end < p_eq_sign) {
break; }
6905 p_asterisk = strchr(p, (
int)
'*');
6906 if(NULL != p_asterisk && p_eq_sign > p_asterisk)
6909 rv = sscanf(p_asterisk,
" * %u", &sec_num);
6915 sscanf(p_asterisk,
" %c", &ext_mark);
6920 sscanf(p_asterisk,
" * %*u %c", &ext_mark);
6923 else { p_asterisk = p_eq_sign; }
6924 alen = (size_t) (p_asterisk - p);
6925 if(alen &&
' ' == p[alen - (
size_t) 1])
6933 PRINT_ERROR(
"MIME: Parameter attribute too long");
6937 p_start = p_eq_sign + 1;
6939 if(!sec_num &&
'*' == ext_mark)
6941 q = strchr(p_start, 0x27);
6944 PRINT_ERROR(
"MIME: Parameter charset field missing");
6948 clen = (size_t) (q - p_start);
6955 q = strchr(p_start, 0x27);
6958 PRINT_ERROR(
"MIME: Parameter language field missing");
6960 else { p_start = q + 1; }
6966 if(posix_strncasecmp_l(p,
"Charset", alen, loc_ctype_posix)
6967 && posix_strncasecmp_l(p,
"Format", alen, loc_ctype_posix)
6968 && posix_strncasecmp_l(p,
"DelSp", alen, loc_ctype_posix)
6969 && posix_strncasecmp_l(p,
"InsLine", alen, loc_ctype_posix)
6970 && posix_strncasecmp_l(p,
"Boundary", alen, loc_ctype_posix)
6978 tmp = (
struct mime_parameter**)
6979 posix_realloc(parray,
6980 ppsize +=
sizeof(
struct mime_parameter*));
6983 PRINT_ERROR(
"MIME: Parameter memory allocation failed");
6988 pdata = (
struct mime_parameter*) posix_malloc(psize);
6991 PRINT_ERROR(
"MIME: Parameter memory allocation failed");
6994 strncpy(pdata->attribute, p, alen);
6995 pdata->attribute[alen] = 0;
6996 pdata->attribute_len = alen;
6997 pdata->section = sec_num;
6998 strncpy(pdata->charset, p_cs, clen);
6999 pdata->charset[clen] = 0;
7000 pdata->value_start = p_start;
7001 pdata->value_end = p_end;
7005 printf(
"Index : %u / Section: %u (%s): ", (
unsigned int) i,
7006 sec_num, pdata->attribute);
7007 if(strlen(pdata->charset))
7009 printf(
"[Charset: %s] ", pdata->charset);
7011 for(
size_t iii = 0; (size_t) (p_end - p_start) > iii; ++iii)
7013 printf(
"%c", pdata->value_start[iii]);
7024 rbuf_len = (size_t) (first_end - b);
7026 rbuf = (
char*) posix_malloc(rbuf_len + (
size_t) 3);
7030 strncpy(rbuf, b, rbuf_len);
7036 while(NULL != (q = strchr(rbuf, (
int)
' ')))
7038 memmove((
void*) q, (
void*) (q + 1),
7039 strlen(q + 1) + (
size_t) 1);
7040 if(rbuf_len) { --rbuf_len; }
7044 rbuf_len += (size_t) 3;
7048 if(NULL == parray[i])
7055 if(!parray[i]->valid) {
continue; }
7056 if(parray[i]->section) {
continue; }
7058 rbuf[ri++] =
';'; rbuf[ri++] =
' ';
7063 para_charset = NULL;
7067 if(rewind) { rewind = 0; ii = 0; }
7068 if(!parray[ii]->valid) {
continue; }
7069 if(sec_num != parray[ii]->section) {
continue; }
7070 else if(!strcmp(parray[i]->attribute,
7071 parray[ii]->attribute))
7077 alen = parray[ii]->attribute_len + (size_t) 1;
7081 len += (size_t) (parray[ii]->value_end
7082 - parray[ii]->value_start);
7085 while(ri + len >= rbuf_len)
7087 tmp2 = posix_realloc((
void*) rbuf,
7088 rbuf_len *= (
size_t) 2);
7092 " for result buffer failed");
7096 else { rbuf = tmp2; }
7102 strncpy(&rbuf[ri], parray[ii]->attribute, alen);
7103 rbuf[ri + alen - (size_t) 1] =
'=';
7108 if(!sec_num) { para_charset = parray[ii]->charset; }
7111 if(NULL != para_charset)
7114 if((
size_t) 0 == strlen(para_charset))
7116 para_charset=
"US-ASCII";
7119 tmp2 = posix_malloc(len + (
size_t) 1);
7122 strncpy(tmp2, parray[ii]->value_start, len);
7124 tmp3 = enc_mime_decode_parameter(tmp2,
7128 len2 = strlen(tmp3);
7132 posix_free((
void*) tmp3);
7137 strcpy(&rbuf[ri], tmp3);
7141 posix_free((
void*) tmp2);
7146 strncpy(&rbuf[ri], parray[ii]->value_start, len);
7150 posix_free((
void*) tmp3);
7151 parray[ii]->valid = 0;
7157 while(!error && (NULL != parray[++ii] || rewind));
7158 parray[i]->valid = 0;
7160 while(!error && NULL != parray[++i]);
7164 while(NULL != parray[i]) { posix_free((
void*) parray[i++]); }
7165 posix_free((
void*) parray);
7169 if(error) { res = -1; }
7172 if((posix_locale_t) 0 != loc_ctype_posix)
7174 posix_freelocale(loc_ctype_posix);
7178 if(0 > res) { *r = NULL; }
7183 printf(
"Result: %s\n", rbuf);
7184 printf(
"---------------\n");
7187 }
else { posix_free((
void*) rbuf); }
7241 char fmt[ENC_FMT_BUFLEN];
7243 size_t bo_len, bo_len_valid;
7244 int trailing_sp = 0;
7247 ct->
type = ENC_CT_UNKNOWN;
7248 ct->
subtype = ENC_CTS_UNKNOWN;
7257 printf(
"Content-Type: Not specified\n");
7266 len = strlen(hf_body);
7267 body = (
char*) posix_malloc(len + (
size_t) 1);
7271 for(i = 0; i < len; ++i) { body[i] = (char) toupper((
int) hf_body[i]); }
7275 printf(
"Content-Type: %s\n", body);
7278 if(!strncmp(
"TEXT", body, 4))
7282 if(!strncmp(
"TEXT/PLAIN", body, 10))
7286 for(i = 0; i < len; ++i)
7288 if(!strncmp(
"FORMAT", &body[i], 6))
7291 ii = i + (size_t) 6;
7294 if(
'=' != body[ii] &&
' ' != body[ii]) {
break; }
7297 for(i = 0; i < ENC_FMT_BUFLEN; ++i)
7300 ||
';' == body[ii + i] ||
' ' == body[ii + i])
7304 else { fmt[i] = body[ii + i]; }
7306 fmt[ENC_FMT_BUFLEN - (size_t) 1] = 0;
7307 if(!strncmp(
"FLOWED", fmt, 6))
7309 ct->
flags |= ENC_CT_FLAG_FLOWED;
7314 if(ct->
flags & ENC_CT_FLAG_FLOWED)
7317 for(i = 0; i < len; ++i)
7319 if(!strncmp(
"DELSP", &body[i], 5))
7322 ii = i + (size_t) 5;
7325 if(
'=' != body[ii] &&
' ' != body[ii]) {
break; }
7328 for(i = 0; i < ENC_FMT_BUFLEN; ++i)
7331 ||
';' == body[ii + i] ||
' ' == body[ii + i])
7335 else { fmt[i] = body[ii + i]; }
7337 fmt[ENC_FMT_BUFLEN - (size_t) 1] = 0;
7338 if(!strncmp(
"YES", fmt, 3))
7340 ct->
flags |= ENC_CT_FLAG_DELSP;
7346 for(i = 0; i < len; ++i)
7348 if(!strncmp(
"INSLINE", &body[i], 7))
7351 ii = i + (size_t) 7;
7354 if(
'=' != body[ii] &&
' ' != body[ii]) {
break; }
7357 for(i = 0; i < ENC_FMT_BUFLEN; ++i)
7360 ||
';' == body[ii + i] ||
' ' == body[ii + i])
7364 else { fmt[i] = body[ii + i]; }
7366 fmt[ENC_FMT_BUFLEN - (size_t) 1] = 0;
7367 if(!strncmp(
"YES", fmt, 3))
7369 ct->
flags |= ENC_CT_FLAG_INSLINE;
7377 for(i = 0; i < len; ++i)
7379 if(!strncmp(
"CHARSET", &body[i], 7))
7382 ii = i + (size_t) 7;
7385 if(
'=' != body[ii] &&
' ' != body[ii]) {
break; }
7391 ||
';' == body[ii + i] ||
' ' == body[ii + i])
7395 else { cs[i] = body[ii + i]; }
7398 ct->
charset = enc_mime_get_charset(cs, strlen(cs));
7404 else if(!strncmp(
"IMAGE", body, 5))
7409 else if(!strncmp(
"AUDIO", body, 5))
7414 else if(!strncmp(
"VIDEO", body, 5))
7419 else if(!strncmp(
"MESSAGE/RFC822", body, 14))
7425 else if(!strncmp(
"MULTIPART", body, 9))
7429 if(!strncmp(
"MULTIPART/ALTERNATIVE", body, 21))
7433 else if(!strncmp(
"MULTIPART/DIGEST", body, 16))
7439 for(i = 0; i < len; ++i)
7441 if(!strncmp(
"BOUNDARY", &body[i], 8))
7444 ii = i + (size_t) 8;
7445 if(
'=' != hf_body[ii++])
7448 "Missing multipart boundary parameter value");
7455 if(!hf_body[ii + i] ||
';' == hf_body[ii + i])
7459 else { bo[i] = hf_body[ii + i]; }
7463 bo_len = strlen(bo);
7464 bo_len_valid = strspn(bo,
7466 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
7469 if (bo_len_valid != bo_len)
7471 PRINT_ERROR(
"MIME: Invalid multipart boundary parameter");
7472 if(bo_len_valid &&
' ' != bo[bo_len_valid - (
size_t) 1])
7475 bo[bo_len_valid] = 0;
7476 bo_len = bo_len_valid;
7488 if(
' ' != bo[bo_len - (
size_t) 1]) {
break; }
7496 "from multipart boundary parameter");
7504 posix_free((
void*) body);
7542 const char not_supported[]
7543 =
"ENC: MIME: Unsupported content transfer encoding: ";
7550 res = ENC_CTE_UNKNOWN;
7551 len = strlen(hf_body);
7555 PRINT_ERROR(
"MIME: Name of content transfer encoding too long");
7560 for(i = 0; i < len; ++i)
7562 buf[i] = (char) toupper((
int) hf_body[i]);
7569 if(!strcmp(buf,
"QUOTED-PRINTABLE")) { res =
ENC_CTE_Q; }
7570 if(!strcmp(buf,
"BASE64")) { res =
ENC_CTE_B; }
7572 if(!strcmp(buf,
"7-BIT"))
7575 "Invalid content transfer encoding 7-bit accepted as 7bit");
7578 if(!strcmp(buf,
"8-BIT"))
7581 "Invalid content transfer encoding 8-bit accepted as 8bit");
7585 if(ENC_CTE_UNKNOWN == res)
7587 l = strlen(not_supported) + len;
7588 p = (
char*) posix_malloc(++l);
7591 strcpy(p, not_supported);
7592 strncat(p, buf, len);
7594 posix_free((
void*) p);
7622 posix_locale_t loc_ctype_posix;
7624 const char* fn_para =
"FILENAME=";
7632 *type = ENC_CD_UNKNOWN;
7636 loc_ctype_posix = posix_newlocale(POSIX_LC_CTYPE_MASK,
"POSIX",
7637 (posix_locale_t) 0);
7638 if((posix_locale_t) 0 == loc_ctype_posix)
7645 if(!posix_strncasecmp_l(hf_body,
"inline", strlen(
"inline"),
7648 *type = ENC_CD_INLINE;
7650 else if(!posix_strncasecmp_l(hf_body,
"attachment", strlen(
"attachment"),
7653 *type = ENC_CD_ATTACHMENT;
7655 posix_freelocale(loc_ctype_posix);
7659 len = strlen(hf_body);
7660 body = (
char*) posix_malloc(len + (
size_t) 1);
7664 for(i = 0; i < len; ++i) { body[i] = (char) toupper((
int) hf_body[i]); }
7667 p = strstr(body, fn_para);
7670 p += strlen(fn_para);
7672 if(NULL != q) { len = (size_t) (q - p); }
7673 else { len = strlen(p); }
7675 buf = (
char*) malloc(len + (
size_t) 1);
7678 i = (size_t) (p - body);
7679 strncpy(buf, &hf_body[i], len);
7682 p = strrchr(buf,
'/');
7683 if(NULL != p) { ++p; memmove(buf, p, strlen(p) + (
size_t) 1); }
7688 p = strpbrk(buf,
"~|\x5C");
7692 "Filename in Content-Disposition rejected");
7694 else { *filename = buf; }
7698 posix_free((
void*) body);
7721 size_t len = strlen(entity);
7722 const char* p = entity;
7723 const char* buf = NULL;
7726 posix_mode_t perm = POSIX_S_IRUSR | POSIX_S_IWUSR |
7727 POSIX_S_IRGRP | POSIX_S_IWGRP |
7728 POSIX_S_IROTH | POSIX_S_IWOTH;
7735 buf = enc_mime_decode_qp(entity, &entity[len], 0, &len);
7741 buf = enc_mime_decode_base64(entity, &entity[len], 0, &len);
7753 PRINT_ERROR(
"MIME: Content transfer encoding not supported");
7761 rv =
fu_open_file(pn, &fd, POSIX_O_WRONLY | POSIX_O_CREAT | POSIX_O_TRUNC,
7804 const char* res = NULL;
7805 size_t len = strlen(s);
7812 res = enc_mime_decode_q(charset, s, &s[len], 0);
7817 res = enc_mime_decode_b(charset, s, &s[len], 0);
7829 PRINT_ERROR(
"MIME: Content transfer encoding not supported");
7857 unsigned int insline)
7859 const char* quote_mark;
7871 int insert_crlf = 0;
7894 case 0: { quote_mark =
">";
break; }
7895 case 1: { quote_mark =
"> ";
break; }
7898 PRINT_ERROR(
"Quoting style configuration not supported");
7920 if(POSIX_INT_MAX <= qd) {
break; }
7924 if(-1 == qdepth) { qdepth = (int) qd; }
7927 if((
int) qd != qdepth)
7930 " (format=flowed)");
7936 if(
' ' == s[i]) { ++i; }
7941 if(i && 0x0A == (
int) s[i])
7943 if(0x0D != (
int) s[i - (
size_t) 1])
7947 " (format=flowed)");
7950 else { end = i - (size_t) 1; }
7955 if(!s[++i]) { end = i; }
7959 if(llen &&
' ' == s[end - (
size_t) 1])
7962 if(!((
size_t) 3 == llen
7963 &&
'-' == s[start] &&
'-' == s[start + (
size_t) 1]))
7967 if(delsp) { --llen; --end; }
7971 while(pi + llen + (
size_t) 1 >= plen)
7973 if(!plen) { plen = 128; }
7974 p = (
char*) posix_realloc((
void*) para, plen *= (size_t) 2);
7983 if(error) {
break; }
7985 strncpy(¶[pi], &s[start], llen);
7989 if(error) {
break; }
7992 if(pflowed && !llen) { pell = 1; };
7997 llen = (size_t) qdepth * strlen(quote_mark);
8013 if(!para[pi]) { abort = 1; }
8017 if(
' ' == para[pi]) { check = 1; }
8020 && 0xADU == (
unsigned int) (
unsigned char) para[pi]
8021 && 0xC2U == (
unsigned int)
8022 (
unsigned char) para[pi - (
size_t) 1])
8028 && 0x8BU == (
unsigned int) (
unsigned char) para[pi]
8029 && 0x80U == (
unsigned int)
8030 (
unsigned char) para[pi - (
size_t) 1]
8031 && 0xE2U == (
unsigned int)
8032 (
unsigned char) para[pi - (
size_t) 2])
8041 llimit = (size_t) 72;
8042 if(1 == qdepth) { llimit = (size_t) 74; }
8043 else if(2 == qdepth) { llimit = (size_t) 76; }
8044 else if(3 <= qdepth) { llimit = (size_t) 78; }
8046 if(llimit - (
size_t) 20
8047 <= (size_t) qdepth * strlen(quote_mark))
8049 llimit = (size_t) 20;
8053 llimit -= (size_t) qdepth * strlen(quote_mark);
8056 ustring_len = pi - start;
8060 if(pi &&
' ' == para[pi - (
size_t) 1]) { --ustring_len; }
8062 if(llimit < enc_uc_get_glyph_count(¶[start], ustring_len))
8065 if(last_space) { pi = last_space; }
8070 if(pell) { insert_crlf = 1; }
8078 if(pell) { insert_crlf = 1; }
8080 else { last_space = pi; }
8084 if(start < pi &&
' ' == para[pi - (
size_t) 1])
8086 end = pi - (size_t) 1;
8089 llen += end - start;
8100 if(insert_crlf) { llen += (size_t) 2; }
8102 while(bi + llen + (
size_t) 1 >= len)
8104 if(!len) { len = 256; }
8105 p = (
char*) posix_realloc((
void*) buf, len *= (size_t) 2);
8114 if(error) {
break; }
8116 for(ii = 0; ii < (size_t) qdepth; ++ii)
8118 strncpy(&buf[bi], quote_mark, strlen(quote_mark));
8119 bi += strlen(quote_mark);
8122 strncpy(&buf[bi], ¶[start], end - start);
8125 buf[bi++] = (char) 0x0D; buf[bi++] = (char) 0x0A;
8131 buf[bi++] = (char) 0x0D; buf[bi++] = (char) 0x0A;
8134 if(error) {
break; }
8136 posix_free((
void*) para);
8139 PRINT_ERROR(
"MIME: Decoding of format=flowed content failed");
8140 posix_free((
void*) buf);
8143 else if(NULL != buf)
8178 PRINT_ERROR(
"Parsing encapsulated message aborted");
8183 array[res].
start = s;
8189 if(res) { *mpe = array; }
8227 if(!b_len || (
size_t) 70 < b_len)
8229 PRINT_ERROR(
"Invalid MIME multipart boundary delimiter");
8233 PRINT_ERROR(
"Value of ENC_BO_BUFLEN must be at least 75");
8238 strncpy(&boundary[2], b, 71);
8239 b_len += (size_t) 2;
8248 if((
size_t) 2 <= i) { end = i - (size_t) 2; }
8251 if(!strncmp(&s[i], boundary, b_len)) { match = 1; }
8255 if(!s[i]) {
break; }
8256 else if((
char) 0x0D == s[i++])
8258 if((
char) 0x0A == s[i++]) {
break; }
8265 if(!preamble && end >
start)
8268 e_len = end -
start;
8270 posix_realloc(array, (res + (
size_t) 1)
8282 array[res++].
len = e_len;
8294 if(res) { *mpe = array; }
8325 unsigned char c = 0;
8331 p = strchr(q, (
int)
'%');
8336 if((
size_t) 3 > strlen(p)) { res = -1;
break; }
8338 v = enc_hex_decode_nibble(p[1]);
8339 if(0 > v) { invalid = 1; }
8342 c = (
unsigned char) (v * 16);
8343 v = enc_hex_decode_nibble(p[2]);
8344 if(0 > v) { invalid = 1; }
8345 else { c += (
unsigned char) v; }
8348 if(invalid) { res = -1;
break; }
8355 if(!p[0] ||
';' == p[0]) { p[0] =
'_'; }
8357 len = strlen(&p[3]);
8358 memmove((
void*) &p[1], (
void*) &p[3], ++
len);
8363 if(-1 == res) {
PRINT_ERROR(
"Percent decoding of URI failed"); }
8404 const char* res = NULL;
8405 const char* gen_delims =
8407 const char* sub_delims =
8409 const char* unreserved =
8410 "abcdefghijklmnopqrstuvwxyz"
8411 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
8420 size_t commercial_at = 0;
8421 unsigned int nibble;
8428 if(NULL == strchr(unreserved, (
int) s[i])) { process = 1;
break; }
8431 if(!process) { res = s; }
8435 buf = (
char*) posix_malloc(strlen(s) * (size_t) 3 + (
size_t) 1);
8452 if(
'/' == s[i]) { encode = 0; }
8453 else if(NULL == strchr(unreserved, (
int) s[i]))
8467 if(
' ' == s[i]) { error = 1; }
8468 else if(
'%' == s[i]) { encode = 1; }
8469 else if(
'@' == s[i])
8478 else if(NULL != strchr(gen_delims, (
int) s[i]))
8483 && NULL != strchr(sub_delims, (
int) s[i]))
8492 PRINT_ERROR(
"Invalid URI scheme for percent encoding");
8497 if(error) {
break; }
8498 if(!encode) { buf[bi++] = s[i]; }
8504 nibble = ((
unsigned int) s[i] & 0xF0U) >> 4;
8505 if(10U > nibble) { buf[bi] = 0x30; }
8506 else { buf[bi] = 0x41; nibble -= 10U; }
8507 buf[bi++] += (char) nibble;
8509 nibble = (
unsigned int) s[i] & 0x0FU;
8510 if(10 > nibble) { buf[bi] = 0x30; }
8511 else { buf[bi] = 0x41; nibble -= 10U; }
8512 buf[bi++] += (char) nibble;
8519 if(!error) { res = buf; }
8528 PRINT_ERROR(
"Missing \"@\" in URI with scheme \"mailto\"");
8535 posix_free((
void*) buf);
8575 int enc_uc_search(
const char* s,
size_t start_pos,
const char* search_s,
8576 size_t* found_pos,
size_t* found_len)
8579 int ok = 0, ok2 = 0, ok3 = 0, ok4 = 0, ok5 = 0;
8580 size_t search_s_len;
8585 struct uc_cdc ucp_attr;
8586 long int mapping[3];
8588 size_t match_pos = 0, match_len = 0;
8589 size_t tmp_pos = 0, end_pos = 0;
8590 const char* s_nfd = NULL;
8591 const char* search_s_nfd = NULL;
8592 const char* s_cf = NULL;
8593 const char* search_s_cf = NULL;
8607 const size_t mem_factor = 6;
8611 i = 0; ucp = enc_uc_decode_utf8(s, &i);
8612 if(-1L == ucp) {
goto error; }
8613 enc_uc_lookup_cdc(ucp, &ucp_attr);
8614 if(ucp_attr.ccc) {
goto error; }
8615 s_nfd = enc_uc_normalize_to_nfd(&s[start_pos]);
8616 if(NULL == s_nfd) {
goto error; }
8620 search_s_nfd = enc_uc_normalize_to_nfd(search_s);
8621 if(NULL == search_s_nfd) {
goto error; }
8624 search_s_len = strlen(search_s_nfd);
8625 if(!search_s_len) {
goto error; }
8626 if(search_s_len * mem_factor + (
size_t) 1 < search_s_len)
8633 p = (
char*) posix_malloc(search_s_len * mem_factor + (
size_t) 1);
8634 if(NULL == p) {
PRINT_ERROR(
"Memory allocation failed"); }
8641 ucp = enc_uc_decode_utf8(search_s_nfd, &i);
8642 if(-1L == ucp) {
break; }
8645 enc_uc_lookup_cf(ucp, mapping);
8646 for(j = 0; (size_t) 3 > j; ++j)
8648 if(-1L == mapping[j]) {
break; }
8659 q = enc_uc_normalize_to_nfd(p);
8660 if(NULL == q) {
enc_free((
void*) p); }
8663 if(p == q) { search_s_cf = p; }
8669 match_len = strlen(search_s_cf);
8678 s_len = strlen(s_nfd);
8679 if(s_len * mem_factor + (
size_t) 1 < s_len)
8686 p = (
char*) posix_malloc(s_len * mem_factor + (
size_t) 1);
8687 if(NULL == p) {
PRINT_ERROR(
"Memory allocation failed"); }
8694 ucp = enc_uc_decode_utf8(s_nfd, &i);
8695 if(-1L == ucp) {
break; }
8698 enc_uc_lookup_cf(ucp, mapping);
8699 for(j = 0; (size_t) 3 > j; ++j)
8701 if(-1L == mapping[j]) {
break; }
8712 q = enc_uc_normalize_to_nfd(p);
8713 if(NULL == q) {
enc_free((
void*) p); }
8716 if(strlen(p) != strlen(q))
8730 PRINT_ERROR(
"Case folding failed, length changed (bug)");
8734 if(p == q) { s_cf = p; }
8750 p = strstr(s_cf, search_s_cf);
8753 match_pos = (size_t) (p - s_cf);
8778 ucp = enc_uc_decode_utf8(s_nfd, &i);
8779 if(-1L == ucp) {
break; }
8782 enc_uc_lookup_cf(ucp, mapping);
8783 for(j = 0; (size_t) 3 > j; ++j)
8785 if(-1L == mapping[j]) {
break; }
8796 if(ok4 && (bi == match_pos + match_len))
8805 if(ok5 && tmp_pos < end_pos)
8807 p = (
char*) posix_malloc(end_pos + (
size_t) 1);
8808 if(NULL == p) {
PRINT_ERROR(
"Memory allocation failed"); }
8811 strncpy(p, s_nfd, end_pos); p[end_pos] = 0;
8812 q = enc_uc_normalize_to_nfc(p);
8816 if(p != q) { posix_free((
void*) q); }
8819 end_pos -= (end_pos - j);
8822 q = enc_uc_normalize_to_nfc(p);
8826 if(p != q) { posix_free((
void*) q); }
8829 tmp_pos -= (tmp_pos - j);
8830 *found_pos = start_pos + tmp_pos;
8831 *found_len = end_pos - tmp_pos;
8837 posix_free((
void*) p);
8842 posix_free((
void*) search_s_cf);
8843 posix_free((
void*) s_cf);
8846 if(search_s != search_s_nfd) { posix_free((
void*) search_s_nfd); }
8847 if(&s[start_pos] != s_nfd) { posix_free((
void*) s_nfd); }