"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/localcharset.c" between
le-1.16.5.tar.gz and le-1.16.6.tar.gz

About: le is a terminal text editor (many block operations with stream and rectangular blocks, tunable syntax highlighting, etc.).

localcharset.c  (le-1.16.5):localcharset.c  (le-1.16.6)
/* Determine a canonical name for the current locale's character encoding. /* Determine a canonical name for the current locale's character encoding.
Copyright (C) 2000-2006, 2008-2017 Free Software Foundation, Inc. Copyright (C) 2000-2006, 2008-2019 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option) the Free Software Foundation; either version 3, or (at your option)
any later version. any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along
with this program; if not, see <http://www.gnu.org/licenses/>. */ with this program; if not, see <https://www.gnu.org/licenses/>. */
/* Written by Bruno Haible <bruno@clisp.org>. */ /* Written by Bruno Haible <bruno@clisp.org>. */
#include <config.h> #include <config.h>
/* Specification. */ /* Specification. */
#include "localcharset.h" #include "localcharset.h"
#include <fcntl.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#if defined __APPLE__ && defined __MACH__ && HAVE_LANGINFO_CODESET #if defined __APPLE__ && defined __MACH__ && HAVE_LANGINFO_CODESET
# define DARWIN7 /* Darwin 7 or newer, i.e. Mac OS X 10.3 or newer */ # define DARWIN7 /* Darwin 7 or newer, i.e. Mac OS X 10.3 or newer */
#endif #endif
#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ #if defined _WIN32 && !defined __CYGWIN__
# define WINDOWS_NATIVE # define WINDOWS_NATIVE
# include <locale.h> # include <locale.h>
#endif #endif
#if defined __EMX__ #if defined __EMX__
/* Assume EMX program runs on OS/2, even if compiled under DOS. */ /* Assume EMX program runs on OS/2, even if compiled under DOS. */
# ifndef OS2 # ifndef OS2
# define OS2 # define OS2
# endif # endif
#endif #endif
#if !defined WINDOWS_NATIVE #if !defined WINDOWS_NATIVE
# include <unistd.h>
# if HAVE_LANGINFO_CODESET # if HAVE_LANGINFO_CODESET
# include <langinfo.h> # include <langinfo.h>
# else # else
# if 0 /* see comment below */ # if 0 /* see comment regarding use of setlocale(), below */
# include <locale.h> # include <locale.h>
# endif # endif
# endif # endif
# ifdef __CYGWIN__ # ifdef __CYGWIN__
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# include <windows.h> # include <windows.h>
# endif # endif
#elif defined WINDOWS_NATIVE #elif defined WINDOWS_NATIVE
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# include <windows.h> # include <windows.h>
skipping to change at line 74 skipping to change at line 72
#if defined OS2 #if defined OS2
# define INCL_DOS # define INCL_DOS
# include <os2.h> # include <os2.h>
#endif #endif
/* For MB_CUR_MAX_L */ /* For MB_CUR_MAX_L */
#if defined DARWIN7 #if defined DARWIN7
# include <xlocale.h> # include <xlocale.h>
#endif #endif
#if ENABLE_RELOCATABLE #if HAVE_LANGINFO_CODESET || defined WINDOWS_NATIVE || defined OS2
# include "relocatable.h"
#else
# define relocate(pathname) (pathname)
# define relocate2(pathname,allocatedp) (*(allocatedp) = NULL, (pathname))
#endif
/* Get LIBDIR. */
#ifndef LIBDIR
# include "configmake.h"
#endif
/* Define O_NOFOLLOW to 0 on platforms where it does not exist. */
#ifndef O_NOFOLLOW
# define O_NOFOLLOW 0
#endif
#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__
|| defined __DJGPP__
/* Native Windows, Cygwin, OS/2, DOS */
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
#endif
#ifndef DIRECTORY_SEPARATOR
# define DIRECTORY_SEPARATOR '/'
#endif
#ifndef ISSLASH /* On these platforms, we use a mapping from non-canonical encoding name
# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR) to GNU canonical encoding name. */
#endif
#if HAVE_DECL_GETC_UNLOCKED /* With glibc-2.1 or newer, we don't need any canonicalization,
# undef getc because glibc has iconv and both glibc and libiconv support all
# define getc getc_unlocked GNU canonical names directly. */
#endif # if !((defined __GNU_LIBRARY__ && __GLIBC__ >= 2) || defined __UCLIBC__)
/* The following static variable is declared 'volatile' to avoid a
possible multithread problem in the function get_charset_aliases. If we
are running in a threaded environment, and if two threads initialize
'charset_aliases' simultaneously, both will produce the same value,
and everything will be ok if the two assignments to 'charset_aliases'
are atomic. But I don't know what will happen if the two assignments mix. */
#if __STDC__ != 1
# define volatile /* empty */
#endif
/* Pointer to the ordered array of charset aliases read.
Format of a single alias is: ALIAS '\0' CANONICAL '\0' */
static const char ** volatile charset_aliases;
/* Aliases count, -1 until charset aliases are read. */
static int volatile charset_aliases_count = -1;
/* fallback charset name, "*" entry from aliases */
static const char * volatile charset_fallback;
static int struct table_entry
charset_alias_cmp(const void *a,const void *b)
{ {
return strcmp (*(const char**)a, *(const char**)b); const char alias[11+1];
} const char canonical[11+1];
};
/* Reads the contents of the charset.alias file. */
static void /* Table of platform-dependent mappings, sorted in ascending order. */
get_charset_aliases (void) static const struct table_entry alias_table[] =
{ {
const char *cp; # if defined __FreeBSD__ /* FreeBSD */
const char **cps = 0; /*{ "ARMSCII-8", "ARMSCII-8" },*/
int cnt = 0; { "Big5", "BIG5" },
const char *fb = 0; { "C", "ASCII" },
const char *aliases; /*{ "CP1131", "CP1131" },*/
/*{ "CP1251", "CP1251" },*/
if (charset_aliases_count < 0) /*{ "CP866", "CP866" },*/
{ /*{ "GB18030", "GB18030" },*/
#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGW /*{ "GB2312", "GB2312" },*/
IN__ || defined OS2) /*{ "GBK", "GBK" },*/
char *malloc_dir = NULL; /*{ "ISCII-DEV", "?" },*/
const char *dir; { "ISO8859-1", "ISO-8859-1" },
const char *base = "charset.alias"; { "ISO8859-13", "ISO-8859-13" },
char *file_name; { "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
/* Make it possible to override the charset.alias location. This is { "ISO8859-5", "ISO-8859-5" },
necessary for running the testsuite before "make install". */ { "ISO8859-7", "ISO-8859-7" },
dir = getenv ("CHARSETALIASDIR"); { "ISO8859-9", "ISO-8859-9" },
if (dir == NULL || dir[0] == '\0') /*{ "KOI8-R", "KOI8-R" },*/
dir = relocate2 (LIBDIR, &malloc_dir); /*{ "KOI8-U", "KOI8-U" },*/
{ "SJIS", "SHIFT_JIS" },
/* Concatenate dir and base into freshly allocated file_name. */ { "US-ASCII", "ASCII" },
{ { "eucCN", "GB2312" },
size_t dir_len = strlen (dir); { "eucJP", "EUC-JP" },
size_t base_len = strlen (base); { "eucKR", "EUC-KR" }
int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1])); # define alias_table_defined
file_name = (char *) malloc (dir_len + add_slash + base_len + 1); # endif
if (file_name != NULL) # if defined __NetBSD__ /* NetBSD */
{ { "646", "ASCII" },
memcpy (file_name, dir, dir_len); /*{ "ARMSCII-8", "ARMSCII-8" },*/
if (add_slash) /*{ "BIG5", "BIG5" },*/
file_name[dir_len] = DIRECTORY_SEPARATOR; { "Big5-HKSCS", "BIG5-HKSCS" },
memcpy (file_name + dir_len + add_slash, base, base_len + 1); /*{ "CP1251", "CP1251" },*/
} /*{ "CP866", "CP866" },*/
} /*{ "GB18030", "GB18030" },*/
/*{ "GB2312", "GB2312" },*/
free (malloc_dir); { "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-13", "ISO-8859-13" },
if (file_name == NULL) { "ISO8859-15", "ISO-8859-15" },
/* Out of memory. Treat the file as empty. */ { "ISO8859-2", "ISO-8859-2" },
cp = ""; { "ISO8859-4", "ISO-8859-4" },
else { "ISO8859-5", "ISO-8859-5" },
{ { "ISO8859-7", "ISO-8859-7" },
int fd; /*{ "KOI8-R", "KOI8-R" },*/
/*{ "KOI8-U", "KOI8-U" },*/
/* Open the file. Reject symbolic links on platforms that support /*{ "PT154", "PT154" },*/
O_NOFOLLOW. This is a security feature. Without it, an attacker { "SJIS", "SHIFT_JIS" },
could retrieve parts of the contents (namely, the tail of the { "eucCN", "GB2312" },
first line that starts with "* ") of an arbitrary file by placing { "eucJP", "EUC-JP" },
a symbolic link to that file under the name "charset.alias" in { "eucKR", "EUC-KR" },
some writable directory and defining the environment variable { "eucTW", "EUC-TW" }
CHARSETALIASDIR to point to that directory. */ # define alias_table_defined
fd = open (file_name, # endif
O_RDONLY | (HAVE_WORKING_O_NOFOLLOW ? O_NOFOLLOW : 0)); # if defined __OpenBSD__ /* OpenBSD */
if (fd < 0) { "646", "ASCII" },
/* File not found. Treat it as empty. */ { "ISO8859-1", "ISO-8859-1" },
cp = ""; { "ISO8859-13", "ISO-8859-13" },
else { "ISO8859-15", "ISO-8859-15" },
{ { "ISO8859-2", "ISO-8859-2" },
FILE *fp; { "ISO8859-4", "ISO-8859-4" },
{ "ISO8859-5", "ISO-8859-5" },
fp = fdopen (fd, "r"); { "ISO8859-7", "ISO-8859-7" }
if (fp == NULL) # define alias_table_defined
{ # endif
/* Out of memory. Treat the file as empty. */ # if defined __APPLE__ && defined __MACH__ /* Mac OS X */
close (fd); /* Darwin 7.5 has nl_langinfo(CODESET), but sometimes its value is
cp = ""; useless:
} - It returns the empty string when LANG is set to a locale of the
else form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8
{ LC_CTYPE file.
/* Parse the file's contents. */ - The environment variables LANG, LC_CTYPE, LC_ALL are not set by
char *res_ptr = NULL; the system; nl_langinfo(CODESET) returns "US-ASCII" in this case.
size_t res_size = 0; - The documentation says:
"... all code that calls BSD system routines should ensure
for (;;) that the const *char parameters of these routines are in UTF-8
{ encoding. All BSD system functions expect their string
int c; parameters to be in UTF-8 encoding and nothing else."
char buf1[50+1]; It also says
char buf2[50+1]; "An additional caveat is that string parameters for files,
size_t l1, l2; paths, and other file-system entities must be in canonical
char *old_res_ptr; UTF-8. In a canonical UTF-8 Unicode string, all decomposable
characters are decomposed ..."
c = getc (fp); but this is not true: You can pass non-decomposed UTF-8 strings
if (c == EOF) to file system functions, and it is the OS which will convert
break; them to decomposed UTF-8 before accessing the file system.
if (c == '\n' || c == ' ' || c == '\t') - The Apple Terminal application displays UTF-8 by default.
continue; - However, other applications are free to use different encodings:
if (c == '#') - xterm uses ISO-8859-1 by default.
{ - TextEdit uses MacRoman by default.
/* Skip comment, to end of line. */ We prefer UTF-8 over decomposed UTF-8-MAC because one should
do minimize the use of decomposed Unicode. Unfortunately, through the
c = getc (fp); Darwin file system, decomposed UTF-8 strings are leaked into user
while (!(c == EOF || c == '\n')); space nevertheless.
if (c == EOF) Then there are also the locales with encodings other than US-ASCII
break; and UTF-8. These locales can be occasionally useful to users (e.g.
continue; when grepping through ISO-8859-1 encoded text files), when all their
} file names are in US-ASCII.
ungetc (c, fp); */
if (fscanf (fp, "%50s %50s", buf1, buf2) < 2) { "ARMSCII-8", "ARMSCII-8" },
break; { "Big5", "BIG5" },
l1 = strlen (buf1); { "Big5HKSCS", "BIG5-HKSCS" },
l2 = strlen (buf2); { "CP1131", "CP1131" },
old_res_ptr = res_ptr; { "CP1251", "CP1251" },
if (res_size == 0) { "CP866", "CP866" },
{ { "CP949", "CP949" },
res_size = l1 + 1 + l2 + 1; { "GB18030", "GB18030" },
res_ptr = (char *) malloc (res_size + 1); { "GB2312", "GB2312" },
} { "GBK", "GBK" },
else /*{ "ISCII-DEV", "?" },*/
{ { "ISO8859-1", "ISO-8859-1" },
res_size += l1 + 1 + l2 + 1; { "ISO8859-13", "ISO-8859-13" },
res_ptr = (char *) realloc (res_ptr, res_size + 1); { "ISO8859-15", "ISO-8859-15" },
} { "ISO8859-2", "ISO-8859-2" },
if (res_ptr == NULL) { "ISO8859-4", "ISO-8859-4" },
{ { "ISO8859-5", "ISO-8859-5" },
/* Out of memory. */ { "ISO8859-7", "ISO-8859-7" },
res_size = 0; { "ISO8859-9", "ISO-8859-9" },
free (old_res_ptr); { "KOI8-R", "KOI8-R" },
break; { "KOI8-U", "KOI8-U" },
} { "PT154", "PT154" },
strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); { "SJIS", "SHIFT_JIS" },
strcpy (res_ptr + res_size - (l2 + 1), buf2); { "eucCN", "GB2312" },
} { "eucJP", "EUC-JP" },
fclose (fp); { "eucKR", "EUC-KR" }
if (res_size == 0) # define alias_table_defined
cp = ""; # endif
else # if defined _AIX /* AIX */
{ /*{ "GBK", "GBK" },*/
*(res_ptr + res_size) = '\0'; { "IBM-1046", "CP1046" },
cp = res_ptr; { "IBM-1124", "CP1124" },
} { "IBM-1129", "CP1129" },
} { "IBM-1252", "CP1252" },
} { "IBM-850", "CP850" },
{ "IBM-856", "CP856" },
free (file_name); { "IBM-921", "ISO-8859-13" },
} { "IBM-922", "CP922" },
{ "IBM-932", "CP932" },
#else { "IBM-943", "CP943" },
{ "IBM-eucCN", "GB2312" },
{ "IBM-eucJP", "EUC-JP" },
{ "IBM-eucKR", "EUC-KR" },
{ "IBM-eucTW", "EUC-TW" },
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-6", "ISO-8859-6" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-8", "ISO-8859-8" },
{ "ISO8859-9", "ISO-8859-9" },
{ "TIS-620", "TIS-620" },
/*{ "UTF-8", "UTF-8" },*/
{ "big5", "BIG5" }
# define alias_table_defined
# endif
# if defined __hpux /* HP-UX */
{ "SJIS", "SHIFT_JIS" },
{ "arabic8", "HP-ARABIC8" },
{ "big5", "BIG5" },
{ "cp1251", "CP1251" },
{ "eucJP", "EUC-JP" },
{ "eucKR", "EUC-KR" },
{ "eucTW", "EUC-TW" },
{ "gb18030", "GB18030" },
{ "greek8", "HP-GREEK8" },
{ "hebrew8", "HP-HEBREW8" },
{ "hkbig5", "BIG5-HKSCS" },
{ "hp15CN", "GB2312" },
{ "iso88591", "ISO-8859-1" },
{ "iso885913", "ISO-8859-13" },
{ "iso885915", "ISO-8859-15" },
{ "iso88592", "ISO-8859-2" },
{ "iso88594", "ISO-8859-4" },
{ "iso88595", "ISO-8859-5" },
{ "iso88596", "ISO-8859-6" },
{ "iso88597", "ISO-8859-7" },
{ "iso88598", "ISO-8859-8" },
{ "iso88599", "ISO-8859-9" },
{ "kana8", "HP-KANA8" },
{ "koi8r", "KOI8-R" },
{ "roman8", "HP-ROMAN8" },
{ "tis620", "TIS-620" },
{ "turkish8", "HP-TURKISH8" },
{ "utf8", "UTF-8" }
# define alias_table_defined
# endif
# if defined __sgi /* IRIX */
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-9", "ISO-8859-9" },
{ "eucCN", "GB2312" },
{ "eucJP", "EUC-JP" },
{ "eucKR", "EUC-KR" },
{ "eucTW", "EUC-TW" }
# define alias_table_defined
# endif
# if defined __osf__ /* OSF/1 */
/*{ "GBK", "GBK" },*/
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-4", "ISO-8859-4" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-8", "ISO-8859-8" },
{ "ISO8859-9", "ISO-8859-9" },
{ "KSC5601", "CP949" },
{ "SJIS", "SHIFT_JIS" },
{ "TACTIS", "TIS-620" },
/*{ "UTF-8", "UTF-8" },*/
{ "big5", "BIG5" },
{ "cp850", "CP850" },
{ "dechanyu", "DEC-HANYU" },
{ "dechanzi", "GB2312" },
{ "deckanji", "DEC-KANJI" },
{ "deckorean", "EUC-KR" },
{ "eucJP", "EUC-JP" },
{ "eucKR", "EUC-KR" },
{ "eucTW", "EUC-TW" },
{ "sdeckanji", "EUC-JP" }
# define alias_table_defined
# endif
# if defined __sun /* Solaris */
{ "5601", "EUC-KR" },
{ "646", "ASCII" },
/*{ "BIG5", "BIG5" },*/
{ "Big5-HKSCS", "BIG5-HKSCS" },
{ "GB18030", "GB18030" },
/*{ "GBK", "GBK" },*/
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-11", "TIS-620" },
{ "ISO8859-13", "ISO-8859-13" },
{ "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-3", "ISO-8859-3" },
{ "ISO8859-4", "ISO-8859-4" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-6", "ISO-8859-6" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-8", "ISO-8859-8" },
{ "ISO8859-9", "ISO-8859-9" },
{ "PCK", "SHIFT_JIS" },
{ "TIS620.2533", "TIS-620" },
/*{ "UTF-8", "UTF-8" },*/
{ "ansi-1251", "CP1251" },
{ "cns11643", "EUC-TW" },
{ "eucJP", "EUC-JP" },
{ "gb2312", "GB2312" },
{ "koi8-r", "KOI8-R" }
# define alias_table_defined
# endif
# if defined __minix /* Minix */
{ "646", "ASCII" }
# define alias_table_defined
# endif
# if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Windows */
{ "CP1361", "JOHAB" },
{ "CP20127", "ASCII" },
{ "CP20866", "KOI8-R" },
{ "CP20936", "GB2312" },
{ "CP21866", "KOI8-RU" },
{ "CP28591", "ISO-8859-1" },
{ "CP28592", "ISO-8859-2" },
{ "CP28593", "ISO-8859-3" },
{ "CP28594", "ISO-8859-4" },
{ "CP28595", "ISO-8859-5" },
{ "CP28596", "ISO-8859-6" },
{ "CP28597", "ISO-8859-7" },
{ "CP28598", "ISO-8859-8" },
{ "CP28599", "ISO-8859-9" },
{ "CP28605", "ISO-8859-15" },
{ "CP38598", "ISO-8859-8" },
{ "CP51932", "EUC-JP" },
{ "CP51936", "GB2312" },
{ "CP51949", "EUC-KR" },
{ "CP51950", "EUC-TW" },
{ "CP54936", "GB18030" },
{ "CP65001", "UTF-8" },
{ "CP936", "GBK" }
# define alias_table_defined
# endif
# if defined OS2 /* OS/2 */
/* The list of encodings is taken from "List of OS/2 Codepages"
by Alex Taylor:
<http://altsan.org/os2/toolkits/uls/index.html#codepages>.
See also "IBM Globalization - Code page identifiers":
<https://www-01.ibm.com/software/globalization/cp/cp_cpgid.html>. */
{ "CP1089", "ISO-8859-6" },
{ "CP1208", "UTF-8" },
{ "CP1381", "GB2312" },
{ "CP1386", "GBK" },
{ "CP3372", "EUC-JP" },
{ "CP813", "ISO-8859-7" },
{ "CP819", "ISO-8859-1" },
{ "CP878", "KOI8-R" },
{ "CP912", "ISO-8859-2" },
{ "CP913", "ISO-8859-3" },
{ "CP914", "ISO-8859-4" },
{ "CP915", "ISO-8859-5" },
{ "CP916", "ISO-8859-8" },
{ "CP920", "ISO-8859-9" },
{ "CP921", "ISO-8859-13" },
{ "CP923", "ISO-8859-15" },
{ "CP954", "EUC-JP" },
{ "CP964", "EUC-TW" },
{ "CP970", "EUC-KR" }
# define alias_table_defined
# endif
# if defined VMS /* OpenVMS */
/* The list of encodings is taken from the OpenVMS 7.3-1 documentation
"Compaq C Run-Time Library Reference Manual for OpenVMS systems"
section 10.7 "Handling Different Character Sets". */
{ "DECHANYU", "DEC-HANYU" },
{ "DECHANZI", "GB2312" },
{ "DECKANJI", "DEC-KANJI" },
{ "DECKOREAN", "EUC-KR" },
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-8", "ISO-8859-8" },
{ "ISO8859-9", "ISO-8859-9" },
{ "SDECKANJI", "EUC-JP" },
{ "SJIS", "SHIFT_JIS" },
{ "eucJP", "EUC-JP" },
{ "eucTW", "EUC-TW" }
# define alias_table_defined
# endif
# ifndef alias_table_defined
/* Just a dummy entry, to avoid a C syntax error. */
{ "", "" }
# endif
};
# if defined DARWIN7
/* To avoid the trouble of installing a file that is shared by many
GNU packages -- many packaging systems have problems with this --,
simply inline the aliases here. */
cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
"ISO8859-2" "\0" "ISO-8859-2" "\0"
"ISO8859-4" "\0" "ISO-8859-4" "\0"
"ISO8859-5" "\0" "ISO-8859-5" "\0"
"ISO8859-7" "\0" "ISO-8859-7" "\0"
"ISO8859-9" "\0" "ISO-8859-9" "\0"
"ISO8859-13" "\0" "ISO-8859-13" "\0"
"ISO8859-15" "\0" "ISO-8859-15" "\0"
"KOI8-R" "\0" "KOI8-R" "\0"
"KOI8-U" "\0" "KOI8-U" "\0"
"CP866" "\0" "CP866" "\0"
"CP949" "\0" "CP949" "\0"
"CP1131" "\0" "CP1131" "\0"
"CP1251" "\0" "CP1251" "\0"
"eucCN" "\0" "GB2312" "\0"
"GB2312" "\0" "GB2312" "\0"
"eucJP" "\0" "EUC-JP" "\0"
"eucKR" "\0" "EUC-KR" "\0"
"Big5" "\0" "BIG5" "\0"
"Big5HKSCS" "\0" "BIG5-HKSCS" "\0"
"GBK" "\0" "GBK" "\0"
"GB18030" "\0" "GB18030" "\0"
"SJIS" "\0" "SHIFT_JIS" "\0"
"ARMSCII-8" "\0" "ARMSCII-8" "\0"
"PT154" "\0" "PT154" "\0"
/*"ISCII-DEV" "\0" "?" "\0"*/
"*" "\0" "UTF-8" "\0";
# endif
# if defined VMS
/* To avoid the troubles of an extra file charset.alias_vms in the
sources of many GNU packages, simply inline the aliases here. */
/* The list of encodings is taken from the OpenVMS 7.3-1 documentation
"Compaq C Run-Time Library Reference Manual for OpenVMS systems"
section 10.7 "Handling Different Character Sets". */
cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
"ISO8859-2" "\0" "ISO-8859-2" "\0"
"ISO8859-5" "\0" "ISO-8859-5" "\0"
"ISO8859-7" "\0" "ISO-8859-7" "\0"
"ISO8859-8" "\0" "ISO-8859-8" "\0"
"ISO8859-9" "\0" "ISO-8859-9" "\0"
/* Japanese */
"eucJP" "\0" "EUC-JP" "\0"
"SJIS" "\0" "SHIFT_JIS" "\0"
"DECKANJI" "\0" "DEC-KANJI" "\0"
"SDECKANJI" "\0" "EUC-JP" "\0"
/* Chinese */
"eucTW" "\0" "EUC-TW" "\0"
"DECHANYU" "\0" "DEC-HANYU" "\0"
"DECHANZI" "\0" "GB2312" "\0"
/* Korean */
"DECKOREAN" "\0" "EUC-KR" "\0";
# endif
# if defined WINDOWS_NATIVE || defined __CYGWIN__
/* To avoid the troubles of installing a separate file in the same
directory as the DLL and of retrieving the DLL's directory at
runtime, simply inline the aliases here. */
cp = "CP936" "\0" "GBK" "\0"
"CP1361" "\0" "JOHAB" "\0"
"CP20127" "\0" "ASCII" "\0"
"CP20866" "\0" "KOI8-R" "\0"
"CP20936" "\0" "GB2312" "\0"
"CP21866" "\0" "KOI8-RU" "\0"
"CP28591" "\0" "ISO-8859-1" "\0"
"CP28592" "\0" "ISO-8859-2" "\0"
"CP28593" "\0" "ISO-8859-3" "\0"
"CP28594" "\0" "ISO-8859-4" "\0"
"CP28595" "\0" "ISO-8859-5" "\0"
"CP28596" "\0" "ISO-8859-6" "\0"
"CP28597" "\0" "ISO-8859-7" "\0"
"CP28598" "\0" "ISO-8859-8" "\0"
"CP28599" "\0" "ISO-8859-9" "\0"
"CP28605" "\0" "ISO-8859-15" "\0"
"CP38598" "\0" "ISO-8859-8" "\0"
"CP51932" "\0" "EUC-JP" "\0"
"CP51936" "\0" "GB2312" "\0"
"CP51949" "\0" "EUC-KR" "\0"
"CP51950" "\0" "EUC-TW" "\0"
"CP54936" "\0" "GB18030" "\0"
"CP65001" "\0" "UTF-8" "\0";
# endif
# if defined OS2
/* To avoid the troubles of installing a separate file in the same
directory as the DLL and of retrieving the DLL's directory at
runtime, simply inline the aliases here. */
/* The list of encodings is taken from "List of OS/2 Codepages"
by Alex Taylor:
<http://altsan.org/os2/toolkits/uls/index.html#codepages>.
See also "IBM Globalization - Code page identifiers":
<http://www-01.ibm.com/software/globalization/cp/cp_cpgid.html>. */
cp = "CP813" "\0" "ISO-8859-7" "\0"
"CP878" "\0" "KOI8-R" "\0"
"CP819" "\0" "ISO-8859-1" "\0"
"CP912" "\0" "ISO-8859-2" "\0"
"CP913" "\0" "ISO-8859-3" "\0"
"CP914" "\0" "ISO-8859-4" "\0"
"CP915" "\0" "ISO-8859-5" "\0"
"CP916" "\0" "ISO-8859-8" "\0"
"CP920" "\0" "ISO-8859-9" "\0"
"CP921" "\0" "ISO-8859-13" "\0"
"CP923" "\0" "ISO-8859-15" "\0"
"CP954" "\0" "EUC-JP" "\0"
"CP964" "\0" "EUC-TW" "\0"
"CP970" "\0" "EUC-KR" "\0"
"CP1089" "\0" "ISO-8859-6" "\0"
"CP1208" "\0" "UTF-8" "\0"
"CP1381" "\0" "GB2312" "\0"
"CP1386" "\0" "GBK" "\0"
"CP3372" "\0" "EUC-JP" "\0";
# endif # endif
#endif
/* build ordered array of aliases and also find fallback */ #else
cnt = 0;
for (aliases = cp; *aliases != '\0';
aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
{
if (aliases[0] == '*' && aliases[1] == '\0')
fb = aliases + strlen (aliases) + 1;
else
cnt ++;
}
if (cnt > 0)
{
cps = (const char **) malloc (cnt * sizeof(*cps));
if (cps == NULL)
{
/* out of memory */
charset_aliases_count = 0;
return;
}
cnt = 0;
for (aliases = cp; *aliases != '\0';
aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
{
if (!(aliases[0] == '*' && aliases[1] == '\0'))
cps[cnt++] = aliases;
}
qsort (cps, cnt, sizeof(*cps), charset_alias_cmp);
}
charset_aliases = cps;
charset_fallback = fb;
charset_aliases_count = cnt;
}
}
/* Replace codeset name using the alias table. /* On these platforms, we use a mapping from locale name to GNU canonical
The result must not be freed; it is statically allocated. encoding name. */
*/
static const char * struct table_entry
resolve_alias (const char *codeset)
{ {
const char **alias_ptr = 0; const char locale[17+1];
const char canonical[11+1];
get_charset_aliases (); };
if (charset_aliases_count > 0) /* Table of platform-dependent mappings, sorted in ascending order. */
alias_ptr = bsearch (&codeset, charset_aliases, static const struct table_entry locale_table[] =
charset_aliases_count, sizeof(codeset), {
charset_alias_cmp); # if defined __FreeBSD__ /* FreeBSD 4.2 */
{ "cs_CZ.ISO_8859-2", "ISO-8859-2" },
if (alias_ptr != NULL) { "da_DK.DIS_8859-15", "ISO-8859-15" },
return *alias_ptr + strlen (*alias_ptr) + 1; { "da_DK.ISO_8859-1", "ISO-8859-1" },
{ "de_AT.DIS_8859-15", "ISO-8859-15" },
if (charset_fallback != NULL) { "de_AT.ISO_8859-1", "ISO-8859-1" },
return charset_fallback; { "de_CH.DIS_8859-15", "ISO-8859-15" },
{ "de_CH.ISO_8859-1", "ISO-8859-1" },
{ "de_DE.DIS_8859-15", "ISO-8859-15" },
{ "de_DE.ISO_8859-1", "ISO-8859-1" },
{ "en_AU.DIS_8859-15", "ISO-8859-15" },
{ "en_AU.ISO_8859-1", "ISO-8859-1" },
{ "en_CA.DIS_8859-15", "ISO-8859-15" },
{ "en_CA.ISO_8859-1", "ISO-8859-1" },
{ "en_GB.DIS_8859-15", "ISO-8859-15" },
{ "en_GB.ISO_8859-1", "ISO-8859-1" },
{ "en_US.DIS_8859-15", "ISO-8859-15" },
{ "en_US.ISO_8859-1", "ISO-8859-1" },
{ "es_ES.DIS_8859-15", "ISO-8859-15" },
{ "es_ES.ISO_8859-1", "ISO-8859-1" },
{ "fi_FI.DIS_8859-15", "ISO-8859-15" },
{ "fi_FI.ISO_8859-1", "ISO-8859-1" },
{ "fr_BE.DIS_8859-15", "ISO-8859-15" },
{ "fr_BE.ISO_8859-1", "ISO-8859-1" },
{ "fr_CA.DIS_8859-15", "ISO-8859-15" },
{ "fr_CA.ISO_8859-1", "ISO-8859-1" },
{ "fr_CH.DIS_8859-15", "ISO-8859-15" },
{ "fr_CH.ISO_8859-1", "ISO-8859-1" },
{ "fr_FR.DIS_8859-15", "ISO-8859-15" },
{ "fr_FR.ISO_8859-1", "ISO-8859-1" },
{ "hr_HR.ISO_8859-2", "ISO-8859-2" },
{ "hu_HU.ISO_8859-2", "ISO-8859-2" },
{ "is_IS.DIS_8859-15", "ISO-8859-15" },
{ "is_IS.ISO_8859-1", "ISO-8859-1" },
{ "it_CH.DIS_8859-15", "ISO-8859-15" },
{ "it_CH.ISO_8859-1", "ISO-8859-1" },
{ "it_IT.DIS_8859-15", "ISO-8859-15" },
{ "it_IT.ISO_8859-1", "ISO-8859-1" },
{ "ja_JP.EUC", "EUC-JP" },
{ "ja_JP.SJIS", "SHIFT_JIS" },
{ "ja_JP.Shift_JIS", "SHIFT_JIS" },
{ "ko_KR.EUC", "EUC-KR" },
{ "la_LN.ASCII", "ASCII" },
{ "la_LN.DIS_8859-15", "ISO-8859-15" },
{ "la_LN.ISO_8859-1", "ISO-8859-1" },
{ "la_LN.ISO_8859-2", "ISO-8859-2" },
{ "la_LN.ISO_8859-4", "ISO-8859-4" },
{ "lt_LN.ASCII", "ASCII" },
{ "lt_LN.DIS_8859-15", "ISO-8859-15" },
{ "lt_LN.ISO_8859-1", "ISO-8859-1" },
{ "lt_LN.ISO_8859-2", "ISO-8859-2" },
{ "lt_LT.ISO_8859-4", "ISO-8859-4" },
{ "nl_BE.DIS_8859-15", "ISO-8859-15" },
{ "nl_BE.ISO_8859-1", "ISO-8859-1" },
{ "nl_NL.DIS_8859-15", "ISO-8859-15" },
{ "nl_NL.ISO_8859-1", "ISO-8859-1" },
{ "no_NO.DIS_8859-15", "ISO-8859-15" },
{ "no_NO.ISO_8859-1", "ISO-8859-1" },
{ "pl_PL.ISO_8859-2", "ISO-8859-2" },
{ "pt_PT.DIS_8859-15", "ISO-8859-15" },
{ "pt_PT.ISO_8859-1", "ISO-8859-1" },
{ "ru_RU.CP866", "CP866" },
{ "ru_RU.ISO_8859-5", "ISO-8859-5" },
{ "ru_RU.KOI8-R", "KOI8-R" },
{ "ru_SU.CP866", "CP866" },
{ "ru_SU.ISO_8859-5", "ISO-8859-5" },
{ "ru_SU.KOI8-R", "KOI8-R" },
{ "sl_SI.ISO_8859-2", "ISO-8859-2" },
{ "sv_SE.DIS_8859-15", "ISO-8859-15" },
{ "sv_SE.ISO_8859-1", "ISO-8859-1" },
{ "uk_UA.KOI8-U", "KOI8-U" },
{ "zh_CN.EUC", "GB2312" },
{ "zh_TW.BIG5", "BIG5" },
{ "zh_TW.Big5", "BIG5" }
# define locale_table_defined
# endif
# if defined __DJGPP__ /* DOS / DJGPP 2.03
*/
/* The encodings given here may not all be correct.
If you find that the encoding given for your language and
country is not the one your DOS machine actually uses, just
correct it in this file, and send a mail to
Juan Manuel Guerrero <juan.guerrero@gmx.de>
and <bug-gnulib@gnu.org>. */
{ "C", "ASCII" },
{ "ar", "CP864" },
{ "ar_AE", "CP864" },
{ "ar_DZ", "CP864" },
{ "ar_EG", "CP864" },
{ "ar_IQ", "CP864" },
{ "ar_IR", "CP864" },
{ "ar_JO", "CP864" },
{ "ar_KW", "CP864" },
{ "ar_MA", "CP864" },
{ "ar_OM", "CP864" },
{ "ar_QA", "CP864" },
{ "ar_SA", "CP864" },
{ "ar_SY", "CP864" },
{ "be", "CP866" },
{ "be_BE", "CP866" },
{ "bg", "CP866" }, /* not CP855 ?? */
{ "bg_BG", "CP866" }, /* not CP855 ?? */
{ "ca", "CP850" },
{ "ca_ES", "CP850" },
{ "cs", "CP852" },
{ "cs_CZ", "CP852" },
{ "da", "CP865" }, /* not CP850 ?? */
{ "da_DK", "CP865" }, /* not CP850 ?? */
{ "de", "CP850" },
{ "de_AT", "CP850" },
{ "de_CH", "CP850" },
{ "de_DE", "CP850" },
{ "el", "CP869" },
{ "el_GR", "CP869" },
{ "en", "CP850" },
{ "en_AU", "CP850" }, /* not CP437 ?? */
{ "en_CA", "CP850" },
{ "en_GB", "CP850" },
{ "en_NZ", "CP437" },
{ "en_US", "CP437" },
{ "en_ZA", "CP850" }, /* not CP437 ?? */
{ "eo", "CP850" },
{ "eo_EO", "CP850" },
{ "es", "CP850" },
{ "es_AR", "CP850" },
{ "es_BO", "CP850" },
{ "es_CL", "CP850" },
{ "es_CO", "CP850" },
{ "es_CR", "CP850" },
{ "es_CU", "CP850" },
{ "es_DO", "CP850" },
{ "es_EC", "CP850" },
{ "es_ES", "CP850" },
{ "es_GT", "CP850" },
{ "es_HN", "CP850" },
{ "es_MX", "CP850" },
{ "es_NI", "CP850" },
{ "es_PA", "CP850" },
{ "es_PE", "CP850" },
{ "es_PY", "CP850" },
{ "es_SV", "CP850" },
{ "es_UY", "CP850" },
{ "es_VE", "CP850" },
{ "et", "CP850" },
{ "et_EE", "CP850" },
{ "eu", "CP850" },
{ "eu_ES", "CP850" },
{ "fi", "CP850" },
{ "fi_FI", "CP850" },
{ "fr", "CP850" },
{ "fr_BE", "CP850" },
{ "fr_CA", "CP850" },
{ "fr_CH", "CP850" },
{ "fr_FR", "CP850" },
{ "ga", "CP850" },
{ "ga_IE", "CP850" },
{ "gd", "CP850" },
{ "gd_GB", "CP850" },
{ "gl", "CP850" },
{ "gl_ES", "CP850" },
{ "he", "CP862" },
{ "he_IL", "CP862" },
{ "hr", "CP852" },
{ "hr_HR", "CP852" },
{ "hu", "CP852" },
{ "hu_HU", "CP852" },
{ "id", "CP850" }, /* not CP437 ?? */
{ "id_ID", "CP850" }, /* not CP437 ?? */
{ "is", "CP861" }, /* not CP850 ?? */
{ "is_IS", "CP861" }, /* not CP850 ?? */
{ "it", "CP850" },
{ "it_CH", "CP850" },
{ "it_IT", "CP850" },
{ "ja", "CP932" },
{ "ja_JP", "CP932" },
{ "kr", "CP949" }, /* not CP934 ?? */
{ "kr_KR", "CP949" }, /* not CP934 ?? */
{ "lt", "CP775" },
{ "lt_LT", "CP775" },
{ "lv", "CP775" },
{ "lv_LV", "CP775" },
{ "mk", "CP866" }, /* not CP855 ?? */
{ "mk_MK", "CP866" }, /* not CP855 ?? */
{ "mt", "CP850" },
{ "mt_MT", "CP850" },
{ "nb", "CP865" }, /* not CP850 ?? */
{ "nb_NO", "CP865" }, /* not CP850 ?? */
{ "nl", "CP850" },
{ "nl_BE", "CP850" },
{ "nl_NL", "CP850" },
{ "nn", "CP865" }, /* not CP850 ?? */
{ "nn_NO", "CP865" }, /* not CP850 ?? */
{ "no", "CP865" }, /* not CP850 ?? */
{ "no_NO", "CP865" }, /* not CP850 ?? */
{ "pl", "CP852" },
{ "pl_PL", "CP852" },
{ "pt", "CP850" },
{ "pt_BR", "CP850" },
{ "pt_PT", "CP850" },
{ "ro", "CP852" },
{ "ro_RO", "CP852" },
{ "ru", "CP866" },
{ "ru_RU", "CP866" },
{ "sk", "CP852" },
{ "sk_SK", "CP852" },
{ "sl", "CP852" },
{ "sl_SI", "CP852" },
{ "sq", "CP852" },
{ "sq_AL", "CP852" },
{ "sr", "CP852" }, /* CP852 or CP866 or CP855 ?? */
{ "sr_CS", "CP852" }, /* CP852 or CP866 or CP855 ?? */
{ "sr_YU", "CP852" }, /* CP852 or CP866 or CP855 ?? */
{ "sv", "CP850" },
{ "sv_SE", "CP850" },
{ "th", "CP874" },
{ "th_TH", "CP874" },
{ "tr", "CP857" },
{ "tr_TR", "CP857" },
{ "uk", "CP1125" },
{ "uk_UA", "CP1125" },
{ "zh_CN", "GBK" },
{ "zh_TW", "CP950" } /* not CP938 ?? */
# define locale_table_defined
# endif
# ifndef locale_table_defined
/* Just a dummy entry, to avoid a C syntax error. */
{ "", "" }
# endif
};
return codeset; #endif
}
/* Determine the current locale's character encoding, and canonicalize it /* Determine the current locale's character encoding, and canonicalize it
into one of the canonical names listed in config.charset. into one of the canonical names listed in localcharset.h.
The result must not be freed; it is statically allocated. The result must not be freed; it is statically allocated.
If the canonical name cannot be determined, the result is a non-canonical If the canonical name cannot be determined, the result is a non-canonical
name. */ name. */
#ifdef STATIC #ifdef STATIC
STATIC STATIC
#endif #endif
const char * const char *
locale_charset (void) locale_charset (void)
{ {
const char *codeset; const char *codeset;
#if !(defined WINDOWS_NATIVE || defined OS2) #if HAVE_LANGINFO_CODESET || defined WINDOWS_NATIVE || defined OS2
# if HAVE_LANGINFO_CODESET # if HAVE_LANGINFO_CODESET
/* Most systems support nl_langinfo (CODESET) nowadays. */ /* Most systems support nl_langinfo (CODESET) nowadays. */
codeset = nl_langinfo (CODESET); codeset = nl_langinfo (CODESET);
# ifdef __CYGWIN__ # ifdef __CYGWIN__
/* Cygwin < 1.7 does not have locales. nl_langinfo (CODESET) always /* Cygwin < 1.7 does not have locales. nl_langinfo (CODESET) always
returns "US-ASCII". Return the suffix of the locale name from the returns "US-ASCII". Return the suffix of the locale name from the
environment variables (if present) or the codepage as a number. */ environment variables (if present) or the codepage as a number. */
skipping to change at line 533 skipping to change at line 752
GetConsoleOutputCP() if it is using a TrueType font). Cygwin does GetConsoleOutputCP() if it is using a TrueType font). Cygwin does
this conversion transparently (see winsup/cygwin/fhandler_console.cc), this conversion transparently (see winsup/cygwin/fhandler_console.cc),
converting to GetConsoleOutputCP(). This leads to correct results, converting to GetConsoleOutputCP(). This leads to correct results,
except when SetConsoleOutputCP has been called and a raster font is except when SetConsoleOutputCP has been called and a raster font is
in use. */ in use. */
sprintf (buf, "CP%u", GetACP ()); sprintf (buf, "CP%u", GetACP ());
codeset = buf; codeset = buf;
} }
# endif # endif
# else if (codeset == NULL)
/* The canonical name cannot be determined. */
/* On old systems which lack it, use setlocale or getenv. */ codeset = "";
const char *locale = NULL;
/* But most old systems don't have a complete set of locales. Some
(like SunOS 4 or DJGPP) have only the C locale. Therefore we don't
use setlocale here; it would return "C" when it doesn't support the
locale name the user has set. */
# if 0
locale = setlocale (LC_CTYPE, NULL);
# endif
if (locale == NULL || locale[0] == '\0')
{
locale = getenv ("LC_ALL");
if (locale == NULL || locale[0] == '\0')
{
locale = getenv ("LC_CTYPE");
if (locale == NULL || locale[0] == '\0')
locale = getenv ("LANG");
}
}
/* On some old systems, one used to set locale = "iso8859_1". On others,
you set it to "language_COUNTRY.charset". In any case, we resolve it
through the charset.alias file. */
codeset = locale;
# endif
#elif defined WINDOWS_NATIVE # elif defined WINDOWS_NATIVE
static char buf[2 + 10 + 1]; static char buf[2 + 10 + 1];
/* The Windows API has a function returning the locale's codepage as /* The Windows API has a function returning the locale's codepage as
a number, but the value doesn't change according to what the a number, but the value doesn't change according to what the
'setlocale' call specified. So we use it as a last resort, in 'setlocale' call specified. So we use it as a last resort, in
case the string returned by 'setlocale' doesn't specify the case the string returned by 'setlocale' doesn't specify the
codepage. */ codepage. */
char *current_locale = setlocale (LC_ALL, NULL); char *current_locale = setlocale (LC_ALL, NULL);
char *pdot; char *pdot;
skipping to change at line 597 skipping to change at line 790
number: GetACP(). number: GetACP().
When the output goes to a console window, it needs to be provided in When the output goes to a console window, it needs to be provided in
GetOEMCP() encoding if the console is using a raster font, or in GetOEMCP() encoding if the console is using a raster font, or in
GetConsoleOutputCP() encoding if it is using a TrueType font. GetConsoleOutputCP() encoding if it is using a TrueType font.
But in GUI programs and for output sent to files and pipes, GetACP() But in GUI programs and for output sent to files and pipes, GetACP()
encoding is the best bet. */ encoding is the best bet. */
sprintf (buf, "CP%u", GetACP ()); sprintf (buf, "CP%u", GetACP ());
} }
codeset = buf; codeset = buf;
#elif defined OS2 # elif defined OS2
const char *locale; const char *locale;
static char buf[2 + 10 + 1]; static char buf[2 + 10 + 1];
ULONG cp[3]; ULONG cp[3];
ULONG cplen; ULONG cplen;
codeset = NULL; codeset = NULL;
/* Allow user to override the codeset, as set in the operating system, /* Allow user to override the codeset, as set in the operating system,
with standard language environment variables. */ with standard language environment variables. */
skipping to change at line 654 skipping to change at line 847
/* OS/2 has a function returning the locale's codepage as a number. */ /* OS/2 has a function returning the locale's codepage as a number. */
if (DosQueryCp (sizeof (cp), cp, &cplen)) if (DosQueryCp (sizeof (cp), cp, &cplen))
codeset = ""; codeset = "";
else else
{ {
sprintf (buf, "CP%u", cp[0]); sprintf (buf, "CP%u", cp[0]);
codeset = buf; codeset = buf;
} }
} }
#endif # else
if (codeset == NULL) # error "Add code for other platforms here."
/* The canonical name cannot be determined. */
codeset = "";
codeset = resolve_alias (codeset); # endif
/* Don't return an empty string. GNU libc and GNU libiconv interpret /* Resolve alias. */
the empty string as denoting "the locale's character encoding", {
thus GNU libiconv would call this function a second time. */ # ifdef alias_table_defined
if (codeset[0] == '\0') /* On some platforms, UTF-8 locales are the most frequently used ones.
codeset = "ASCII"; Speed up the common case and slow down the less common cases by
testing for this case first. */
# if defined __OpenBSD__ || (defined __APPLE__ && defined __MACH__) || defined
__sun || defined __CYGWIN__
if (strcmp (codeset, "UTF-8") == 0)
goto done_table_lookup;
else
# endif
{
const struct table_entry * const table = alias_table;
size_t const table_size =
sizeof (alias_table) / sizeof (struct table_entry);
/* The table is sorted. Perform a binary search. */
size_t hi = table_size;
size_t lo = 0;
while (lo < hi)
{
/* Invariant:
for i < lo, strcmp (table[i].alias, codeset) < 0,
for i >= hi, strcmp (table[i].alias, codeset) > 0. */
size_t mid = (hi + lo) >> 1; /* >= lo, < hi */
int cmp = strcmp (table[mid].alias, codeset);
if (cmp < 0)
lo = mid + 1;
else if (cmp > 0)
hi = mid;
else
{
/* Found an i with
strcmp (table[i].alias, codeset) == 0. */
codeset = table[mid].canonical;
goto done_table_lookup;
}
}
}
if (0)
done_table_lookup: ;
else
# endif
{
/* Did not find it in the table. */
/* On Mac OS X, all modern locales use the UTF-8 encoding.
BeOS and Haiku have a single locale, and it has UTF-8 encoding. */
# if (defined __APPLE__ && defined __MACH__) || defined __BEOS__ || defined __HA
IKU__
codeset = "UTF-8";
# else
/* Don't return an empty string. GNU libc and GNU libiconv interpret
the empty string as denoting "the locale's character encoding",
thus GNU libiconv would call this function a second time. */
if (codeset[0] == '\0')
codeset = "ASCII";
# endif
}
}
#else
/* On old systems which lack it, use setlocale or getenv. */
const char *locale = NULL;
/* But most old systems don't have a complete set of locales. Some
(like DJGPP) have only the C locale. Therefore we don't use setlocale
here; it would return "C" when it doesn't support the locale name the
user has set. */
# if 0
locale = setlocale (LC_CTYPE, NULL);
# endif
if (locale == NULL || locale[0] == '\0')
{
locale = getenv ("LC_ALL");
if (locale == NULL || locale[0] == '\0')
{
locale = getenv ("LC_CTYPE");
if (locale == NULL || locale[0] == '\0')
locale = getenv ("LANG");
if (locale == NULL)
locale = "";
}
}
/* Map locale name to canonical encoding name. */
{
# ifdef locale_table_defined
const struct table_entry * const table = locale_table;
size_t const table_size =
sizeof (locale_table) / sizeof (struct table_entry);
/* The table is sorted. Perform a binary search. */
size_t hi = table_size;
size_t lo = 0;
while (lo < hi)
{
/* Invariant:
for i < lo, strcmp (table[i].locale, locale) < 0,
for i >= hi, strcmp (table[i].locale, locale) > 0. */
size_t mid = (hi + lo) >> 1; /* >= lo, < hi */
int cmp = strcmp (table[mid].locale, locale);
if (cmp < 0)
lo = mid + 1;
else if (cmp > 0)
hi = mid;
else
{
/* Found an i with
strcmp (table[i].locale, locale) == 0. */
codeset = table[mid].canonical;
goto done_table_lookup;
}
}
if (0)
done_table_lookup: ;
else
# endif
{
/* Did not find it in the table. */
/* On Mac OS X, all modern locales use the UTF-8 encoding.
BeOS and Haiku have a single locale, and it has UTF-8 encoding. */
# if (defined __APPLE__ && defined __MACH__) || defined __BEOS__ || defined __HA
IKU__
codeset = "UTF-8";
# else
/* The canonical name cannot be determined. */
/* Don't return an empty string. GNU libc and GNU libiconv interpret
the empty string as denoting "the locale's character encoding",
thus GNU libiconv would call this function a second time. */
codeset = "ASCII";
# endif
}
}
#endif
#ifdef DARWIN7 #ifdef DARWIN7
/* Mac OS X sets MB_CUR_MAX to 1 when LC_ALL=C, and "UTF-8" /* Mac OS X sets MB_CUR_MAX to 1 when LC_ALL=C, and "UTF-8"
(the default codeset) does not work when MB_CUR_MAX is 1. */ (the default codeset) does not work when MB_CUR_MAX is 1. */
if (strcmp (codeset, "UTF-8") == 0 && MB_CUR_MAX_L (uselocale (NULL)) <= 1) if (strcmp (codeset, "UTF-8") == 0 && MB_CUR_MAX_L (uselocale (NULL)) <= 1)
codeset = "ASCII"; codeset = "ASCII";
#endif #endif
return codeset; return codeset;
} }
 End of changes. 27 change blocks. 
421 lines changed or deleted 741 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)