| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <config.h> |
| 21 |
|
| 22 |
|
| 23 |
#include "localcharset.h" |
| 24 |
|
| 25 |
#include <stddef.h> |
| 26 |
#include <stdio.h> |
| 27 |
#include <string.h> |
| 28 |
#include <stdlib.h> |
| 29 |
|
| 30 |
#if defined __APPLE__ && defined __MACH__ && HAVE_LANGINFO_CODESET |
| 31 |
# define DARWIN7 |
| 32 |
#endif |
| 33 |
|
| 34 |
#if defined _WIN32 && !defined __CYGWIN__ |
| 35 |
# define WINDOWS_NATIVE |
| 36 |
# include <locale.h> |
| 37 |
#endif |
| 38 |
|
| 39 |
#if defined __EMX__ |
| 40 |
|
| 41 |
# ifndef OS2 |
| 42 |
# define OS2 |
| 43 |
# endif |
| 44 |
#endif |
| 45 |
|
| 46 |
#if !defined WINDOWS_NATIVE |
| 47 |
# if HAVE_LANGINFO_CODESET |
| 48 |
# include <langinfo.h> |
| 49 |
# else |
| 50 |
# if 0 |
| 51 |
# include <locale.h> |
| 52 |
# endif |
| 53 |
# endif |
| 54 |
# ifdef __CYGWIN__ |
| 55 |
# define WIN32_LEAN_AND_MEAN |
| 56 |
# include <windows.h> |
| 57 |
# endif |
| 58 |
#elif defined WINDOWS_NATIVE |
| 59 |
# define WIN32_LEAN_AND_MEAN |
| 60 |
# include <windows.h> |
| 61 |
|
| 62 |
|
| 63 |
# undef setlocale |
| 64 |
#endif |
| 65 |
#if defined OS2 |
| 66 |
# define INCL_DOS |
| 67 |
# include <os2.h> |
| 68 |
#endif |
| 69 |
|
| 70 |
|
| 71 |
#if defined DARWIN7 |
| 72 |
# include <xlocale.h> |
| 73 |
#endif |
| 74 |
|
| 75 |
|
| 76 |
#if HAVE_LANGINFO_CODESET || defined WINDOWS_NATIVE || defined OS2 |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
# if !((defined __GNU_LIBRARY__ && __GLIBC__ >= 2) || defined __UCLIBC__) |
| 85 |
|
| 86 |
struct table_entry |
| 87 |
{ |
| 88 |
const char alias[11+1]; |
| 89 |
const char canonical[11+1]; |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
static const struct table_entry alias_table[] = |
| 94 |
{ |
| 95 |
# if defined __FreeBSD__ |
| 96 |
|
| 97 |
{ "Big5", "BIG5" }, |
| 98 |
{ "C", "ASCII" }, |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
{ "ISO8859-1", "ISO-8859-1" }, |
| 107 |
{ "ISO8859-13", "ISO-8859-13" }, |
| 108 |
{ "ISO8859-15", "ISO-8859-15" }, |
| 109 |
{ "ISO8859-2", "ISO-8859-2" }, |
| 110 |
{ "ISO8859-5", "ISO-8859-5" }, |
| 111 |
{ "ISO8859-7", "ISO-8859-7" }, |
| 112 |
{ "ISO8859-9", "ISO-8859-9" }, |
| 113 |
|
| 114 |
|
| 115 |
{ "SJIS", "SHIFT_JIS" }, |
| 116 |
{ "US-ASCII", "ASCII" }, |
| 117 |
{ "eucCN", "GB2312" }, |
| 118 |
{ "eucJP", "EUC-JP" }, |
| 119 |
{ "eucKR", "EUC-KR" } |
| 120 |
# define alias_table_defined |
| 121 |
# endif |
| 122 |
# if defined __NetBSD__ |
| 123 |
{ "646", "ASCII" }, |
| 124 |
|
| 125 |
|
| 126 |
{ "Big5-HKSCS", "BIG5-HKSCS" }, |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
{ "ISO8859-1", "ISO-8859-1" }, |
| 132 |
{ "ISO8859-13", "ISO-8859-13" }, |
| 133 |
{ "ISO8859-15", "ISO-8859-15" }, |
| 134 |
{ "ISO8859-2", "ISO-8859-2" }, |
| 135 |
{ "ISO8859-4", "ISO-8859-4" }, |
| 136 |
{ "ISO8859-5", "ISO-8859-5" }, |
| 137 |
{ "ISO8859-7", "ISO-8859-7" }, |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
{ "SJIS", "SHIFT_JIS" }, |
| 142 |
{ "eucCN", "GB2312" }, |
| 143 |
{ "eucJP", "EUC-JP" }, |
| 144 |
{ "eucKR", "EUC-KR" }, |
| 145 |
{ "eucTW", "EUC-TW" } |
| 146 |
# define alias_table_defined |
| 147 |
# endif |
| 148 |
# if defined __OpenBSD__ |
| 149 |
{ "646", "ASCII" }, |
| 150 |
{ "ISO8859-1", "ISO-8859-1" }, |
| 151 |
{ "ISO8859-13", "ISO-8859-13" }, |
| 152 |
{ "ISO8859-15", "ISO-8859-15" }, |
| 153 |
{ "ISO8859-2", "ISO-8859-2" }, |
| 154 |
{ "ISO8859-4", "ISO-8859-4" }, |
| 155 |
{ "ISO8859-5", "ISO-8859-5" }, |
| 156 |
{ "ISO8859-7", "ISO-8859-7" }, |
| 157 |
{ "US-ASCII", "ASCII" } |
| 158 |
# define alias_table_defined |
| 159 |
# endif |
| 160 |
# if defined __APPLE__ && defined __MACH__ |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
{ "ARMSCII-8", "ARMSCII-8" }, |
| 195 |
{ "Big5", "BIG5" }, |
| 196 |
{ "Big5HKSCS", "BIG5-HKSCS" }, |
| 197 |
{ "CP1131", "CP1131" }, |
| 198 |
{ "CP1251", "CP1251" }, |
| 199 |
{ "CP866", "CP866" }, |
| 200 |
{ "CP949", "CP949" }, |
| 201 |
{ "GB18030", "GB18030" }, |
| 202 |
{ "GB2312", "GB2312" }, |
| 203 |
{ "GBK", "GBK" }, |
| 204 |
|
| 205 |
{ "ISO8859-1", "ISO-8859-1" }, |
| 206 |
{ "ISO8859-13", "ISO-8859-13" }, |
| 207 |
{ "ISO8859-15", "ISO-8859-15" }, |
| 208 |
{ "ISO8859-2", "ISO-8859-2" }, |
| 209 |
{ "ISO8859-4", "ISO-8859-4" }, |
| 210 |
{ "ISO8859-5", "ISO-8859-5" }, |
| 211 |
{ "ISO8859-7", "ISO-8859-7" }, |
| 212 |
{ "ISO8859-9", "ISO-8859-9" }, |
| 213 |
{ "KOI8-R", "KOI8-R" }, |
| 214 |
{ "KOI8-U", "KOI8-U" }, |
| 215 |
{ "PT154", "PT154" }, |
| 216 |
{ "SJIS", "SHIFT_JIS" }, |
| 217 |
{ "eucCN", "GB2312" }, |
| 218 |
{ "eucJP", "EUC-JP" }, |
| 219 |
{ "eucKR", "EUC-KR" } |
| 220 |
# define alias_table_defined |
| 221 |
# endif |
| 222 |
# if defined _AIX |
| 223 |
|
| 224 |
{ "IBM-1046", "CP1046" }, |
| 225 |
{ "IBM-1124", "CP1124" }, |
| 226 |
{ "IBM-1129", "CP1129" }, |
| 227 |
{ "IBM-1252", "CP1252" }, |
| 228 |
{ "IBM-850", "CP850" }, |
| 229 |
{ "IBM-856", "CP856" }, |
| 230 |
{ "IBM-921", "ISO-8859-13" }, |
| 231 |
{ "IBM-922", "CP922" }, |
| 232 |
{ "IBM-932", "CP932" }, |
| 233 |
{ "IBM-943", "CP943" }, |
| 234 |
{ "IBM-eucCN", "GB2312" }, |
| 235 |
{ "IBM-eucJP", "EUC-JP" }, |
| 236 |
{ "IBM-eucKR", "EUC-KR" }, |
| 237 |
{ "IBM-eucTW", "EUC-TW" }, |
| 238 |
{ "ISO8859-1", "ISO-8859-1" }, |
| 239 |
{ "ISO8859-15", "ISO-8859-15" }, |
| 240 |
{ "ISO8859-2", "ISO-8859-2" }, |
| 241 |
{ "ISO8859-5", "ISO-8859-5" }, |
| 242 |
{ "ISO8859-6", "ISO-8859-6" }, |
| 243 |
{ "ISO8859-7", "ISO-8859-7" }, |
| 244 |
{ "ISO8859-8", "ISO-8859-8" }, |
| 245 |
{ "ISO8859-9", "ISO-8859-9" }, |
| 246 |
{ "TIS-620", "TIS-620" }, |
| 247 |
|
| 248 |
{ "big5", "BIG5" } |
| 249 |
# define alias_table_defined |
| 250 |
# endif |
| 251 |
# if defined __hpux |
| 252 |
{ "SJIS", "SHIFT_JIS" }, |
| 253 |
{ "arabic8", "HP-ARABIC8" }, |
| 254 |
{ "big5", "BIG5" }, |
| 255 |
{ "cp1251", "CP1251" }, |
| 256 |
{ "eucJP", "EUC-JP" }, |
| 257 |
{ "eucKR", "EUC-KR" }, |
| 258 |
{ "eucTW", "EUC-TW" }, |
| 259 |
{ "gb18030", "GB18030" }, |
| 260 |
{ "greek8", "HP-GREEK8" }, |
| 261 |
{ "hebrew8", "HP-HEBREW8" }, |
| 262 |
{ "hkbig5", "BIG5-HKSCS" }, |
| 263 |
{ "hp15CN", "GB2312" }, |
| 264 |
{ "iso88591", "ISO-8859-1" }, |
| 265 |
{ "iso885913", "ISO-8859-13" }, |
| 266 |
{ "iso885915", "ISO-8859-15" }, |
| 267 |
{ "iso88592", "ISO-8859-2" }, |
| 268 |
{ "iso88594", "ISO-8859-4" }, |
| 269 |
{ "iso88595", "ISO-8859-5" }, |
| 270 |
{ "iso88596", "ISO-8859-6" }, |
| 271 |
{ "iso88597", "ISO-8859-7" }, |
| 272 |
{ "iso88598", "ISO-8859-8" }, |
| 273 |
{ "iso88599", "ISO-8859-9" }, |
| 274 |
{ "kana8", "HP-KANA8" }, |
| 275 |
{ "koi8r", "KOI8-R" }, |
| 276 |
{ "roman8", "HP-ROMAN8" }, |
| 277 |
{ "tis620", "TIS-620" }, |
| 278 |
{ "turkish8", "HP-TURKISH8" }, |
| 279 |
{ "utf8", "UTF-8" } |
| 280 |
# define alias_table_defined |
| 281 |
# endif |
| 282 |
# if defined __sgi |
| 283 |
{ "ISO8859-1", "ISO-8859-1" }, |
| 284 |
{ "ISO8859-15", "ISO-8859-15" }, |
| 285 |
{ "ISO8859-2", "ISO-8859-2" }, |
| 286 |
{ "ISO8859-5", "ISO-8859-5" }, |
| 287 |
{ "ISO8859-7", "ISO-8859-7" }, |
| 288 |
{ "ISO8859-9", "ISO-8859-9" }, |
| 289 |
{ "eucCN", "GB2312" }, |
| 290 |
{ "eucJP", "EUC-JP" }, |
| 291 |
{ "eucKR", "EUC-KR" }, |
| 292 |
{ "eucTW", "EUC-TW" } |
| 293 |
# define alias_table_defined |
| 294 |
# endif |
| 295 |
# if defined __osf__ |
| 296 |
|
| 297 |
{ "ISO8859-1", "ISO-8859-1" }, |
| 298 |
{ "ISO8859-15", "ISO-8859-15" }, |
| 299 |
{ "ISO8859-2", "ISO-8859-2" }, |
| 300 |
{ "ISO8859-4", "ISO-8859-4" }, |
| 301 |
{ "ISO8859-5", "ISO-8859-5" }, |
| 302 |
{ "ISO8859-7", "ISO-8859-7" }, |
| 303 |
{ "ISO8859-8", "ISO-8859-8" }, |
| 304 |
{ "ISO8859-9", "ISO-8859-9" }, |
| 305 |
{ "KSC5601", "CP949" }, |
| 306 |
{ "SJIS", "SHIFT_JIS" }, |
| 307 |
{ "TACTIS", "TIS-620" }, |
| 308 |
|
| 309 |
{ "big5", "BIG5" }, |
| 310 |
{ "cp850", "CP850" }, |
| 311 |
{ "dechanyu", "DEC-HANYU" }, |
| 312 |
{ "dechanzi", "GB2312" }, |
| 313 |
{ "deckanji", "DEC-KANJI" }, |
| 314 |
{ "deckorean", "EUC-KR" }, |
| 315 |
{ "eucJP", "EUC-JP" }, |
| 316 |
{ "eucKR", "EUC-KR" }, |
| 317 |
{ "eucTW", "EUC-TW" }, |
| 318 |
{ "sdeckanji", "EUC-JP" } |
| 319 |
# define alias_table_defined |
| 320 |
# endif |
| 321 |
# if defined __sun |
| 322 |
{ "5601", "EUC-KR" }, |
| 323 |
{ "646", "ASCII" }, |
| 324 |
|
| 325 |
{ "Big5-HKSCS", "BIG5-HKSCS" }, |
| 326 |
{ "GB18030", "GB18030" }, |
| 327 |
|
| 328 |
{ "ISO8859-1", "ISO-8859-1" }, |
| 329 |
{ "ISO8859-11", "TIS-620" }, |
| 330 |
{ "ISO8859-13", "ISO-8859-13" }, |
| 331 |
{ "ISO8859-15", "ISO-8859-15" }, |
| 332 |
{ "ISO8859-2", "ISO-8859-2" }, |
| 333 |
{ "ISO8859-3", "ISO-8859-3" }, |
| 334 |
{ "ISO8859-4", "ISO-8859-4" }, |
| 335 |
{ "ISO8859-5", "ISO-8859-5" }, |
| 336 |
{ "ISO8859-6", "ISO-8859-6" }, |
| 337 |
{ "ISO8859-7", "ISO-8859-7" }, |
| 338 |
{ "ISO8859-8", "ISO-8859-8" }, |
| 339 |
{ "ISO8859-9", "ISO-8859-9" }, |
| 340 |
{ "PCK", "SHIFT_JIS" }, |
| 341 |
{ "TIS620.2533", "TIS-620" }, |
| 342 |
|
| 343 |
{ "ansi-1251", "CP1251" }, |
| 344 |
{ "cns11643", "EUC-TW" }, |
| 345 |
{ "eucJP", "EUC-JP" }, |
| 346 |
{ "gb2312", "GB2312" }, |
| 347 |
{ "koi8-r", "KOI8-R" } |
| 348 |
# define alias_table_defined |
| 349 |
# endif |
| 350 |
# if defined __minix |
| 351 |
{ "646", "ASCII" } |
| 352 |
# define alias_table_defined |
| 353 |
# endif |
| 354 |
# if defined WINDOWS_NATIVE || defined __CYGWIN__ |
| 355 |
{ "CP1361", "JOHAB" }, |
| 356 |
{ "CP20127", "ASCII" }, |
| 357 |
{ "CP20866", "KOI8-R" }, |
| 358 |
{ "CP20936", "GB2312" }, |
| 359 |
{ "CP21866", "KOI8-RU" }, |
| 360 |
{ "CP28591", "ISO-8859-1" }, |
| 361 |
{ "CP28592", "ISO-8859-2" }, |
| 362 |
{ "CP28593", "ISO-8859-3" }, |
| 363 |
{ "CP28594", "ISO-8859-4" }, |
| 364 |
{ "CP28595", "ISO-8859-5" }, |
| 365 |
{ "CP28596", "ISO-8859-6" }, |
| 366 |
{ "CP28597", "ISO-8859-7" }, |
| 367 |
{ "CP28598", "ISO-8859-8" }, |
| 368 |
{ "CP28599", "ISO-8859-9" }, |
| 369 |
{ "CP28605", "ISO-8859-15" }, |
| 370 |
{ "CP38598", "ISO-8859-8" }, |
| 371 |
{ "CP51932", "EUC-JP" }, |
| 372 |
{ "CP51936", "GB2312" }, |
| 373 |
{ "CP51949", "EUC-KR" }, |
| 374 |
{ "CP51950", "EUC-TW" }, |
| 375 |
{ "CP54936", "GB18030" }, |
| 376 |
{ "CP65001", "UTF-8" }, |
| 377 |
{ "CP936", "GBK" } |
| 378 |
# define alias_table_defined |
| 379 |
# endif |
| 380 |
# if defined OS2 |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
{ "CP1004", "CP1252" }, |
| 387 |
|
| 388 |
|
| 389 |
{ "CP1089", "ISO-8859-6" }, |
| 390 |
|
| 391 |
|
| 392 |
{ "CP1208", "UTF-8" }, |
| 393 |
|
| 394 |
{ "CP1381", "GB2312" }, |
| 395 |
{ "CP1383", "GB2312" }, |
| 396 |
{ "CP1386", "GBK" }, |
| 397 |
|
| 398 |
{ "CP3372", "EUC-JP" }, |
| 399 |
{ "CP4946", "CP850" }, |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
{ "CP813", "ISO-8859-7" }, |
| 404 |
{ "CP819", "ISO-8859-1" }, |
| 405 |
{ "CP878", "KOI8-R" }, |
| 406 |
|
| 407 |
{ "CP912", "ISO-8859-2" }, |
| 408 |
{ "CP913", "ISO-8859-3" }, |
| 409 |
{ "CP914", "ISO-8859-4" }, |
| 410 |
{ "CP915", "ISO-8859-5" }, |
| 411 |
{ "CP916", "ISO-8859-8" }, |
| 412 |
{ "CP920", "ISO-8859-9" }, |
| 413 |
{ "CP921", "ISO-8859-13" }, |
| 414 |
{ "CP923", "ISO-8859-15" }, |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
{ "CP954", "EUC-JP" }, |
| 421 |
{ "CP964", "EUC-TW" }, |
| 422 |
{ "CP970", "EUC-KR" }, |
| 423 |
|
| 424 |
{ "IBM-1004", "CP1252" }, |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
{ "IBM-1089", "ISO-8859-6" }, |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
{ "IBM-1124", "CP1124" }, |
| 439 |
{ "IBM-1125", "CP1125" }, |
| 440 |
{ "IBM-1131", "CP1131" }, |
| 441 |
{ "IBM-1208", "UTF-8" }, |
| 442 |
{ "IBM-1250", "CP1250" }, |
| 443 |
{ "IBM-1251", "CP1251" }, |
| 444 |
{ "IBM-1252", "CP1252" }, |
| 445 |
{ "IBM-1253", "CP1253" }, |
| 446 |
{ "IBM-1254", "CP1254" }, |
| 447 |
{ "IBM-1255", "CP1255" }, |
| 448 |
{ "IBM-1256", "CP1256" }, |
| 449 |
{ "IBM-1257", "CP1257" }, |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
{ "IBM-1381", "GB2312" }, |
| 459 |
{ "IBM-1383", "GB2312" }, |
| 460 |
{ "IBM-1386", "GBK" }, |
| 461 |
|
| 462 |
{ "IBM-3372", "EUC-JP" }, |
| 463 |
{ "IBM-367", "ASCII" }, |
| 464 |
{ "IBM-437", "CP437" }, |
| 465 |
{ "IBM-4946", "CP850" }, |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
{ "IBM-813", "ISO-8859-7" }, |
| 470 |
{ "IBM-819", "ISO-8859-1" }, |
| 471 |
{ "IBM-850", "CP850" }, |
| 472 |
|
| 473 |
{ "IBM-852", "CP852" }, |
| 474 |
{ "IBM-855", "CP855" }, |
| 475 |
{ "IBM-856", "CP856" }, |
| 476 |
{ "IBM-857", "CP857" }, |
| 477 |
|
| 478 |
{ "IBM-860", "CP860" }, |
| 479 |
{ "IBM-861", "CP861" }, |
| 480 |
{ "IBM-862", "CP862" }, |
| 481 |
{ "IBM-863", "CP863" }, |
| 482 |
{ "IBM-864", "CP864" }, |
| 483 |
{ "IBM-865", "CP865" }, |
| 484 |
{ "IBM-866", "CP866" }, |
| 485 |
|
| 486 |
{ "IBM-869", "CP869" }, |
| 487 |
{ "IBM-874", "CP874" }, |
| 488 |
{ "IBM-878", "KOI8-R" }, |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
{ "IBM-912", "ISO-8859-2" }, |
| 494 |
{ "IBM-913", "ISO-8859-3" }, |
| 495 |
{ "IBM-914", "ISO-8859-4" }, |
| 496 |
{ "IBM-915", "ISO-8859-5" }, |
| 497 |
{ "IBM-916", "ISO-8859-8" }, |
| 498 |
{ "IBM-920", "ISO-8859-9" }, |
| 499 |
{ "IBM-921", "ISO-8859-13" }, |
| 500 |
{ "IBM-922", "CP922" }, |
| 501 |
{ "IBM-923", "ISO-8859-15" }, |
| 502 |
{ "IBM-932", "CP932" }, |
| 503 |
|
| 504 |
|
| 505 |
{ "IBM-943", "CP943" }, |
| 506 |
|
| 507 |
{ "IBM-949", "CP949" }, |
| 508 |
{ "IBM-950", "CP950" }, |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
{ "IBM-954", "EUC-JP" }, |
| 513 |
|
| 514 |
{ "IBM-964", "EUC-TW" }, |
| 515 |
{ "IBM-970", "EUC-KR" }, |
| 516 |
|
| 517 |
{ "IBM-eucCN", "GB2312" }, |
| 518 |
{ "IBM-eucJP", "EUC-JP" }, |
| 519 |
{ "IBM-eucKR", "EUC-KR" }, |
| 520 |
{ "IBM-eucTW", "EUC-TW" }, |
| 521 |
{ "IBM33722", "EUC-JP" }, |
| 522 |
{ "ISO8859-1", "ISO-8859-1" }, |
| 523 |
{ "ISO8859-2", "ISO-8859-2" }, |
| 524 |
{ "ISO8859-3", "ISO-8859-3" }, |
| 525 |
{ "ISO8859-4", "ISO-8859-4" }, |
| 526 |
{ "ISO8859-5", "ISO-8859-5" }, |
| 527 |
{ "ISO8859-6", "ISO-8859-6" }, |
| 528 |
{ "ISO8859-7", "ISO-8859-7" }, |
| 529 |
{ "ISO8859-8", "ISO-8859-8" }, |
| 530 |
{ "ISO8859-9", "ISO-8859-9" }, |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
{ "SJIS-1", "CP943" }, |
| 538 |
{ "SJIS-2", "CP943" }, |
| 539 |
{ "eucJP", "EUC-JP" }, |
| 540 |
{ "eucKR", "EUC-KR" }, |
| 541 |
{ "eucTW-1993", "EUC-TW" } |
| 542 |
# define alias_table_defined |
| 543 |
# endif |
| 544 |
# if defined VMS |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
{ "DECHANYU", "DEC-HANYU" }, |
| 549 |
{ "DECHANZI", "GB2312" }, |
| 550 |
{ "DECKANJI", "DEC-KANJI" }, |
| 551 |
{ "DECKOREAN", "EUC-KR" }, |
| 552 |
{ "ISO8859-1", "ISO-8859-1" }, |
| 553 |
{ "ISO8859-2", "ISO-8859-2" }, |
| 554 |
{ "ISO8859-5", "ISO-8859-5" }, |
| 555 |
{ "ISO8859-7", "ISO-8859-7" }, |
| 556 |
{ "ISO8859-8", "ISO-8859-8" }, |
| 557 |
{ "ISO8859-9", "ISO-8859-9" }, |
| 558 |
{ "SDECKANJI", "EUC-JP" }, |
| 559 |
{ "SJIS", "SHIFT_JIS" }, |
| 560 |
{ "eucJP", "EUC-JP" }, |
| 561 |
{ "eucTW", "EUC-TW" } |
| 562 |
# define alias_table_defined |
| 563 |
# endif |
| 564 |
# ifndef alias_table_defined |
| 565 |
|
| 566 |
{ "", "" } |
| 567 |
# endif |
| 568 |
}; |
| 569 |
|
| 570 |
# endif |
| 571 |
|
| 572 |
#else |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
struct table_entry |
| 578 |
{ |
| 579 |
const char locale[17+1]; |
| 580 |
const char canonical[11+1]; |
| 581 |
}; |
| 582 |
|
| 583 |
|
| 584 |
static const struct table_entry locale_table[] = |
| 585 |
{ |
| 586 |
# if defined __FreeBSD__ |
| 587 |
{ "cs_CZ.ISO_8859-2", "ISO-8859-2" }, |
| 588 |
{ "da_DK.DIS_8859-15", "ISO-8859-15" }, |
| 589 |
{ "da_DK.ISO_8859-1", "ISO-8859-1" }, |
| 590 |
{ "de_AT.DIS_8859-15", "ISO-8859-15" }, |
| 591 |
{ "de_AT.ISO_8859-1", "ISO-8859-1" }, |
| 592 |
{ "de_CH.DIS_8859-15", "ISO-8859-15" }, |
| 593 |
{ "de_CH.ISO_8859-1", "ISO-8859-1" }, |
| 594 |
{ "de_DE.DIS_8859-15", "ISO-8859-15" }, |
| 595 |
{ "de_DE.ISO_8859-1", "ISO-8859-1" }, |
| 596 |
{ "en_AU.DIS_8859-15", "ISO-8859-15" }, |
| 597 |
{ "en_AU.ISO_8859-1", "ISO-8859-1" }, |
| 598 |
{ "en_CA.DIS_8859-15", "ISO-8859-15" }, |
| 599 |
{ "en_CA.ISO_8859-1", "ISO-8859-1" }, |
| 600 |
{ "en_GB.DIS_8859-15", "ISO-8859-15" }, |
| 601 |
{ "en_GB.ISO_8859-1", "ISO-8859-1" }, |
| 602 |
{ "en_US.DIS_8859-15", "ISO-8859-15" }, |
| 603 |
{ "en_US.ISO_8859-1", "ISO-8859-1" }, |
| 604 |
{ "es_ES.DIS_8859-15", "ISO-8859-15" }, |
| 605 |
{ "es_ES.ISO_8859-1", "ISO-8859-1" }, |
| 606 |
{ "fi_FI.DIS_8859-15", "ISO-8859-15" }, |
| 607 |
{ "fi_FI.ISO_8859-1", "ISO-8859-1" }, |
| 608 |
{ "fr_BE.DIS_8859-15", "ISO-8859-15" }, |
| 609 |
{ "fr_BE.ISO_8859-1", "ISO-8859-1" }, |
| 610 |
{ "fr_CA.DIS_8859-15", "ISO-8859-15" }, |
| 611 |
{ "fr_CA.ISO_8859-1", "ISO-8859-1" }, |
| 612 |
{ "fr_CH.DIS_8859-15", "ISO-8859-15" }, |
| 613 |
{ "fr_CH.ISO_8859-1", "ISO-8859-1" }, |
| 614 |
{ "fr_FR.DIS_8859-15", "ISO-8859-15" }, |
| 615 |
{ "fr_FR.ISO_8859-1", "ISO-8859-1" }, |
| 616 |
{ "hr_HR.ISO_8859-2", "ISO-8859-2" }, |
| 617 |
{ "hu_HU.ISO_8859-2", "ISO-8859-2" }, |
| 618 |
{ "is_IS.DIS_8859-15", "ISO-8859-15" }, |
| 619 |
{ "is_IS.ISO_8859-1", "ISO-8859-1" }, |
| 620 |
{ "it_CH.DIS_8859-15", "ISO-8859-15" }, |
| 621 |
{ "it_CH.ISO_8859-1", "ISO-8859-1" }, |
| 622 |
{ "it_IT.DIS_8859-15", "ISO-8859-15" }, |
| 623 |
{ "it_IT.ISO_8859-1", "ISO-8859-1" }, |
| 624 |
{ "ja_JP.EUC", "EUC-JP" }, |
| 625 |
{ "ja_JP.SJIS", "SHIFT_JIS" }, |
| 626 |
{ "ja_JP.Shift_JIS", "SHIFT_JIS" }, |
| 627 |
{ "ko_KR.EUC", "EUC-KR" }, |
| 628 |
{ "la_LN.ASCII", "ASCII" }, |
| 629 |
{ "la_LN.DIS_8859-15", "ISO-8859-15" }, |
| 630 |
{ "la_LN.ISO_8859-1", "ISO-8859-1" }, |
| 631 |
{ "la_LN.ISO_8859-2", "ISO-8859-2" }, |
| 632 |
{ "la_LN.ISO_8859-4", "ISO-8859-4" }, |
| 633 |
{ "lt_LN.ASCII", "ASCII" }, |
| 634 |
{ "lt_LN.DIS_8859-15", "ISO-8859-15" }, |
| 635 |
{ "lt_LN.ISO_8859-1", "ISO-8859-1" }, |
| 636 |
{ "lt_LN.ISO_8859-2", "ISO-8859-2" }, |
| 637 |
{ "lt_LT.ISO_8859-4", "ISO-8859-4" }, |
| 638 |
{ "nl_BE.DIS_8859-15", "ISO-8859-15" }, |
| 639 |
{ "nl_BE.ISO_8859-1", "ISO-8859-1" }, |
| 640 |
{ "nl_NL.DIS_8859-15", "ISO-8859-15" }, |
| 641 |
{ "nl_NL.ISO_8859-1", "ISO-8859-1" }, |
| 642 |
{ "no_NO.DIS_8859-15", "ISO-8859-15" }, |
| 643 |
{ "no_NO.ISO_8859-1", "ISO-8859-1" }, |
| 644 |
{ "pl_PL.ISO_8859-2", "ISO-8859-2" }, |
| 645 |
{ "pt_PT.DIS_8859-15", "ISO-8859-15" }, |
| 646 |
{ "pt_PT.ISO_8859-1", "ISO-8859-1" }, |
| 647 |
{ "ru_RU.CP866", "CP866" }, |
| 648 |
{ "ru_RU.ISO_8859-5", "ISO-8859-5" }, |
| 649 |
{ "ru_RU.KOI8-R", "KOI8-R" }, |
| 650 |
{ "ru_SU.CP866", "CP866" }, |
| 651 |
{ "ru_SU.ISO_8859-5", "ISO-8859-5" }, |
| 652 |
{ "ru_SU.KOI8-R", "KOI8-R" }, |
| 653 |
{ "sl_SI.ISO_8859-2", "ISO-8859-2" }, |
| 654 |
{ "sv_SE.DIS_8859-15", "ISO-8859-15" }, |
| 655 |
{ "sv_SE.ISO_8859-1", "ISO-8859-1" }, |
| 656 |
{ "uk_UA.KOI8-U", "KOI8-U" }, |
| 657 |
{ "zh_CN.EUC", "GB2312" }, |
| 658 |
{ "zh_TW.BIG5", "BIG5" }, |
| 659 |
{ "zh_TW.Big5", "BIG5" } |
| 660 |
# define locale_table_defined |
| 661 |
# endif |
| 662 |
# if defined __DJGPP__ |
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
{ "C", "ASCII" }, |
| 670 |
{ "ar", "CP864" }, |
| 671 |
{ "ar_AE", "CP864" }, |
| 672 |
{ "ar_DZ", "CP864" }, |
| 673 |
{ "ar_EG", "CP864" }, |
| 674 |
{ "ar_IQ", "CP864" }, |
| 675 |
{ "ar_IR", "CP864" }, |
| 676 |
{ "ar_JO", "CP864" }, |
| 677 |
{ "ar_KW", "CP864" }, |
| 678 |
{ "ar_MA", "CP864" }, |
| 679 |
{ "ar_OM", "CP864" }, |
| 680 |
{ "ar_QA", "CP864" }, |
| 681 |
{ "ar_SA", "CP864" }, |
| 682 |
{ "ar_SY", "CP864" }, |
| 683 |
{ "be", "CP866" }, |
| 684 |
{ "be_BE", "CP866" }, |
| 685 |
{ "bg", "CP866" }, |
| 686 |
{ "bg_BG", "CP866" }, |
| 687 |
{ "ca", "CP850" }, |
| 688 |
{ "ca_ES", "CP850" }, |
| 689 |
{ "cs", "CP852" }, |
| 690 |
{ "cs_CZ", "CP852" }, |
| 691 |
{ "da", "CP865" }, |
| 692 |
{ "da_DK", "CP865" }, |
| 693 |
{ "de", "CP850" }, |
| 694 |
{ "de_AT", "CP850" }, |
| 695 |
{ "de_CH", "CP850" }, |
| 696 |
{ "de_DE", "CP850" }, |
| 697 |
{ "el", "CP869" }, |
| 698 |
{ "el_GR", "CP869" }, |
| 699 |
{ "en", "CP850" }, |
| 700 |
{ "en_AU", "CP850" }, |
| 701 |
{ "en_CA", "CP850" }, |
| 702 |
{ "en_GB", "CP850" }, |
| 703 |
{ "en_NZ", "CP437" }, |
| 704 |
{ "en_US", "CP437" }, |
| 705 |
{ "en_ZA", "CP850" }, |
| 706 |
{ "eo", "CP850" }, |
| 707 |
{ "eo_EO", "CP850" }, |
| 708 |
{ "es", "CP850" }, |
| 709 |
{ "es_AR", "CP850" }, |
| 710 |
{ "es_BO", "CP850" }, |
| 711 |
{ "es_CL", "CP850" }, |
| 712 |
{ "es_CO", "CP850" }, |
| 713 |
{ "es_CR", "CP850" }, |
| 714 |
{ "es_CU", "CP850" }, |
| 715 |
{ "es_DO", "CP850" }, |
| 716 |
{ "es_EC", "CP850" }, |
| 717 |
{ "es_ES", "CP850" }, |
| 718 |
{ "es_GT", "CP850" }, |
| 719 |
{ "es_HN", "CP850" }, |
| 720 |
{ "es_MX", "CP850" }, |
| 721 |
{ "es_NI", "CP850" }, |
| 722 |
{ "es_PA", "CP850" }, |
| 723 |
{ "es_PE", "CP850" }, |
| 724 |
{ "es_PY", "CP850" }, |
| 725 |
{ "es_SV", "CP850" }, |
| 726 |
{ "es_UY", "CP850" }, |
| 727 |
{ "es_VE", "CP850" }, |
| 728 |
{ "et", "CP850" }, |
| 729 |
{ "et_EE", "CP850" }, |
| 730 |
{ "eu", "CP850" }, |
| 731 |
{ "eu_ES", "CP850" }, |
| 732 |
{ "fi", "CP850" }, |
| 733 |
{ "fi_FI", "CP850" }, |
| 734 |
{ "fr", "CP850" }, |
| 735 |
{ "fr_BE", "CP850" }, |
| 736 |
{ "fr_CA", "CP850" }, |
| 737 |
{ "fr_CH", "CP850" }, |
| 738 |
{ "fr_FR", "CP850" }, |
| 739 |
{ "ga", "CP850" }, |
| 740 |
{ "ga_IE", "CP850" }, |
| 741 |
{ "gd", "CP850" }, |
| 742 |
{ "gd_GB", "CP850" }, |
| 743 |
{ "gl", "CP850" }, |
| 744 |
{ "gl_ES", "CP850" }, |
| 745 |
{ "he", "CP862" }, |
| 746 |
{ "he_IL", "CP862" }, |
| 747 |
{ "hr", "CP852" }, |
| 748 |
{ "hr_HR", "CP852" }, |
| 749 |
{ "hu", "CP852" }, |
| 750 |
{ "hu_HU", "CP852" }, |
| 751 |
{ "id", "CP850" }, |
| 752 |
{ "id_ID", "CP850" }, |
| 753 |
{ "is", "CP861" }, |
| 754 |
{ "is_IS", "CP861" }, |
| 755 |
{ "it", "CP850" }, |
| 756 |
{ "it_CH", "CP850" }, |
| 757 |
{ "it_IT", "CP850" }, |
| 758 |
{ "ja", "CP932" }, |
| 759 |
{ "ja_JP", "CP932" }, |
| 760 |
{ "kr", "CP949" }, |
| 761 |
{ "kr_KR", "CP949" }, |
| 762 |
{ "lt", "CP775" }, |
| 763 |
{ "lt_LT", "CP775" }, |
| 764 |
{ "lv", "CP775" }, |
| 765 |
{ "lv_LV", "CP775" }, |
| 766 |
{ "mk", "CP866" }, |
| 767 |
{ "mk_MK", "CP866" }, |
| 768 |
{ "mt", "CP850" }, |
| 769 |
{ "mt_MT", "CP850" }, |
| 770 |
{ "nb", "CP865" }, |
| 771 |
{ "nb_NO", "CP865" }, |
| 772 |
{ "nl", "CP850" }, |
| 773 |
{ "nl_BE", "CP850" }, |
| 774 |
{ "nl_NL", "CP850" }, |
| 775 |
{ "nn", "CP865" }, |
| 776 |
{ "nn_NO", "CP865" }, |
| 777 |
{ "no", "CP865" }, |
| 778 |
{ "no_NO", "CP865" }, |
| 779 |
{ "pl", "CP852" }, |
| 780 |
{ "pl_PL", "CP852" }, |
| 781 |
{ "pt", "CP850" }, |
| 782 |
{ "pt_BR", "CP850" }, |
| 783 |
{ "pt_PT", "CP850" }, |
| 784 |
{ "ro", "CP852" }, |
| 785 |
{ "ro_RO", "CP852" }, |
| 786 |
{ "ru", "CP866" }, |
| 787 |
{ "ru_RU", "CP866" }, |
| 788 |
{ "sk", "CP852" }, |
| 789 |
{ "sk_SK", "CP852" }, |
| 790 |
{ "sl", "CP852" }, |
| 791 |
{ "sl_SI", "CP852" }, |
| 792 |
{ "sq", "CP852" }, |
| 793 |
{ "sq_AL", "CP852" }, |
| 794 |
{ "sr", "CP852" }, |
| 795 |
{ "sr_CS", "CP852" }, |
| 796 |
{ "sr_YU", "CP852" }, |
| 797 |
{ "sv", "CP850" }, |
| 798 |
{ "sv_SE", "CP850" }, |
| 799 |
{ "th", "CP874" }, |
| 800 |
{ "th_TH", "CP874" }, |
| 801 |
{ "tr", "CP857" }, |
| 802 |
{ "tr_TR", "CP857" }, |
| 803 |
{ "uk", "CP1125" }, |
| 804 |
{ "uk_UA", "CP1125" }, |
| 805 |
{ "zh_CN", "GBK" }, |
| 806 |
{ "zh_TW", "CP950" } |
| 807 |
# define locale_table_defined |
| 808 |
# endif |
| 809 |
# ifndef locale_table_defined |
| 810 |
|
| 811 |
{ "", "" } |
| 812 |
# endif |
| 813 |
}; |
| 814 |
|
| 815 |
#endif |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
#ifdef STATIC |
| 828 |
STATIC |
| 829 |
#endif |
| 830 |
const char * |
| 831 |
locale_charset (void) |
| 832 |
{ |
| 833 |
const char *codeset; |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
#if HAVE_LANGINFO_CODESET || defined WINDOWS_NATIVE || defined OS2 |
| 843 |
|
| 844 |
# if HAVE_LANGINFO_CODESET |
| 845 |
|
| 846 |
|
| 847 |
codeset = nl_langinfo (CODESET); |
| 848 |
|
| 849 |
# ifdef __CYGWIN__ |
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0) |
| 854 |
{ |
| 855 |
const char *locale; |
| 856 |
static char resultbuf[2 + 10 + 1]; |
| 857 |
|
| 858 |
locale = getenv ("LC_ALL"); |
| 859 |
if (locale == NULL || locale[0] == '\0') |
| 860 |
{ |
| 861 |
locale = getenv ("LC_CTYPE"); |
| 862 |
if (locale == NULL || locale[0] == '\0') |
| 863 |
locale = getenv ("LANG"); |
| 864 |
} |
| 865 |
if (locale != NULL && locale[0] != '\0') |
| 866 |
{ |
| 867 |
|
| 868 |
|
| 869 |
const char *dot = strchr (locale, '.'); |
| 870 |
|
| 871 |
if (dot != NULL) |
| 872 |
{ |
| 873 |
const char *modifier; |
| 874 |
|
| 875 |
dot++; |
| 876 |
|
| 877 |
modifier = strchr (dot, '@'); |
| 878 |
if (modifier == NULL) |
| 879 |
return dot; |
| 880 |
if (modifier - dot < sizeof (resultbuf)) |
| 881 |
{ |
| 882 |
|
| 883 |
memcpy (resultbuf, dot, modifier - dot); |
| 884 |
resultbuf [modifier - dot] = '\0'; |
| 885 |
return resultbuf; |
| 886 |
} |
| 887 |
} |
| 888 |
} |
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
{ |
| 902 |
char buf[2 + 10 + 1]; |
| 903 |
|
| 904 |
sprintf (buf, "CP%u", GetACP ()); |
| 905 |
strcpy (resultbuf, buf); |
| 906 |
codeset = resultbuf; |
| 907 |
} |
| 908 |
} |
| 909 |
# endif |
| 910 |
|
| 911 |
if (codeset == NULL) |
| 912 |
|
| 913 |
codeset = ""; |
| 914 |
|
| 915 |
# elif defined WINDOWS_NATIVE |
| 916 |
|
| 917 |
char buf[2 + 10 + 1]; |
| 918 |
static char resultbuf[2 + 10 + 1]; |
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
char *current_locale = setlocale (LC_CTYPE, NULL); |
| 926 |
char *pdot = strrchr (current_locale, '.'); |
| 927 |
|
| 928 |
if (pdot && 2 + strlen (pdot + 1) + 1 <= sizeof (buf)) |
| 929 |
sprintf (buf, "CP%s", pdot + 1); |
| 930 |
else |
| 931 |
{ |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
sprintf (buf, "CP%u", GetACP ()); |
| 940 |
} |
| 941 |
|
| 942 |
|
| 943 |
if (strcmp (buf + 2, "65001") == 0 || strcmp (buf + 2, "utf8") == 0) |
| 944 |
codeset = "UTF-8"; |
| 945 |
else |
| 946 |
{ |
| 947 |
strcpy (resultbuf, buf); |
| 948 |
codeset = resultbuf; |
| 949 |
} |
| 950 |
|
| 951 |
# elif defined OS2 |
| 952 |
|
| 953 |
const char *locale; |
| 954 |
static char resultbuf[2 + 10 + 1]; |
| 955 |
ULONG cp[3]; |
| 956 |
ULONG cplen; |
| 957 |
|
| 958 |
codeset = NULL; |
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
locale = getenv ("LC_ALL"); |
| 963 |
if (locale == NULL || locale[0] == '\0') |
| 964 |
{ |
| 965 |
locale = getenv ("LC_CTYPE"); |
| 966 |
if (locale == NULL || locale[0] == '\0') |
| 967 |
locale = getenv ("LANG"); |
| 968 |
} |
| 969 |
if (locale != NULL && locale[0] != '\0') |
| 970 |
{ |
| 971 |
|
| 972 |
const char *dot = strchr (locale, '.'); |
| 973 |
|
| 974 |
if (dot != NULL) |
| 975 |
{ |
| 976 |
const char *modifier; |
| 977 |
|
| 978 |
dot++; |
| 979 |
|
| 980 |
modifier = strchr (dot, '@'); |
| 981 |
if (modifier == NULL) |
| 982 |
return dot; |
| 983 |
if (modifier - dot < sizeof (resultbuf)) |
| 984 |
{ |
| 985 |
|
| 986 |
memcpy (resultbuf, dot, modifier - dot); |
| 987 |
resultbuf [modifier - dot] = '\0'; |
| 988 |
return resultbuf; |
| 989 |
} |
| 990 |
} |
| 991 |
|
| 992 |
|
| 993 |
if (strcmp (locale, "C") == 0 || strcmp (locale, "POSIX") == 0) |
| 994 |
codeset = ""; |
| 995 |
} |
| 996 |
|
| 997 |
if (codeset == NULL) |
| 998 |
{ |
| 999 |
|
| 1000 |
if (DosQueryCp (sizeof (cp), cp, &cplen)) |
| 1001 |
codeset = ""; |
| 1002 |
else |
| 1003 |
{ |
| 1004 |
char buf[2 + 10 + 1]; |
| 1005 |
|
| 1006 |
sprintf (buf, "CP%u", cp[0]); |
| 1007 |
strcpy (resultbuf, buf); |
| 1008 |
codeset = resultbuf; |
| 1009 |
} |
| 1010 |
} |
| 1011 |
|
| 1012 |
# else |
| 1013 |
|
| 1014 |
# error "Add code for other platforms here." |
| 1015 |
|
| 1016 |
# endif |
| 1017 |
|
| 1018 |
|
| 1019 |
{ |
| 1020 |
# ifdef alias_table_defined |
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
# if defined __OpenBSD__ || (defined __APPLE__ && defined __MACH__) || defined __sun || defined __CYGWIN__ |
| 1025 |
if (strcmp (codeset, "UTF-8") == 0) |
| 1026 |
goto done_table_lookup; |
| 1027 |
else |
| 1028 |
# endif |
| 1029 |
{ |
| 1030 |
const struct table_entry * const table = alias_table; |
| 1031 |
size_t const table_size = |
| 1032 |
sizeof (alias_table) / sizeof (struct table_entry); |
| 1033 |
|
| 1034 |
size_t hi = table_size; |
| 1035 |
size_t lo = 0; |
| 1036 |
while (lo < hi) |
| 1037 |
{ |
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
size_t mid = (hi + lo) >> 1; |
| 1042 |
int cmp = strcmp (table[mid].alias, codeset); |
| 1043 |
if (cmp < 0) |
| 1044 |
lo = mid + 1; |
| 1045 |
else if (cmp > 0) |
| 1046 |
hi = mid; |
| 1047 |
else |
| 1048 |
{ |
| 1049 |
|
| 1050 |
|
| 1051 |
codeset = table[mid].canonical; |
| 1052 |
goto done_table_lookup; |
| 1053 |
} |
| 1054 |
} |
| 1055 |
} |
| 1056 |
if (0) |
| 1057 |
done_table_lookup: ; |
| 1058 |
else |
| 1059 |
# endif |
| 1060 |
{ |
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
# if (defined __APPLE__ && defined __MACH__) || defined __BEOS__ || defined __HAIKU__ |
| 1065 |
codeset = "UTF-8"; |
| 1066 |
# else |
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
if (codeset[0] == '\0') |
| 1071 |
codeset = "ASCII"; |
| 1072 |
# endif |
| 1073 |
} |
| 1074 |
} |
| 1075 |
|
| 1076 |
#else |
| 1077 |
|
| 1078 |
|
| 1079 |
const char *locale = NULL; |
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
# if 0 |
| 1086 |
locale = setlocale (LC_CTYPE, NULL); |
| 1087 |
# endif |
| 1088 |
if (locale == NULL || locale[0] == '\0') |
| 1089 |
{ |
| 1090 |
locale = getenv ("LC_ALL"); |
| 1091 |
if (locale == NULL || locale[0] == '\0') |
| 1092 |
{ |
| 1093 |
locale = getenv ("LC_CTYPE"); |
| 1094 |
if (locale == NULL || locale[0] == '\0') |
| 1095 |
locale = getenv ("LANG"); |
| 1096 |
if (locale == NULL) |
| 1097 |
locale = ""; |
| 1098 |
} |
| 1099 |
} |
| 1100 |
|
| 1101 |
|
| 1102 |
{ |
| 1103 |
# ifdef locale_table_defined |
| 1104 |
const struct table_entry * const table = locale_table; |
| 1105 |
size_t const table_size = |
| 1106 |
sizeof (locale_table) / sizeof (struct table_entry); |
| 1107 |
|
| 1108 |
size_t hi = table_size; |
| 1109 |
size_t lo = 0; |
| 1110 |
while (lo < hi) |
| 1111 |
{ |
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
size_t mid = (hi + lo) >> 1; |
| 1116 |
int cmp = strcmp (table[mid].locale, locale); |
| 1117 |
if (cmp < 0) |
| 1118 |
lo = mid + 1; |
| 1119 |
else if (cmp > 0) |
| 1120 |
hi = mid; |
| 1121 |
else |
| 1122 |
{ |
| 1123 |
|
| 1124 |
|
| 1125 |
codeset = table[mid].canonical; |
| 1126 |
goto done_table_lookup; |
| 1127 |
} |
| 1128 |
} |
| 1129 |
if (0) |
| 1130 |
done_table_lookup: ; |
| 1131 |
else |
| 1132 |
# endif |
| 1133 |
{ |
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
# if (defined __APPLE__ && defined __MACH__) || defined __BEOS__ || defined __HAIKU__ |
| 1138 |
codeset = "UTF-8"; |
| 1139 |
# else |
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
codeset = "ASCII"; |
| 1145 |
# endif |
| 1146 |
} |
| 1147 |
} |
| 1148 |
|
| 1149 |
#endif |
| 1150 |
|
| 1151 |
#ifdef DARWIN7 |
| 1152 |
|
| 1153 |
|
| 1154 |
if (strcmp (codeset, "UTF-8") == 0 && MB_CUR_MAX_L (uselocale (NULL)) <= 1) |
| 1155 |
codeset = "ASCII"; |
| 1156 |
#endif |
| 1157 |
|
| 1158 |
return codeset; |
| 1159 |
} |