]> Savannah Git Hosting - gnulib.git/commitdiff
localcharset: improve charset detection on OS/2
authorKO Myung-Hun <komh@chollian.net>
Wed, 7 Jan 2015 05:36:52 +0000 (14:36 +0900)
committerDaiki Ueno <ueno@gnu.org>
Wed, 7 Jan 2015 05:39:52 +0000 (14:39 +0900)
Use system codepage when appropriate.  Map OS/2 codepages to
GNU canonical charset names if possible.

* lib/config.charset: Don't output aliases if "$os" is os2*.
* lib/localcharset.c (get_charset_aliases) [OS2]: Hardcode the
result for OS/2.
(locale_charset) [OS2]: Use system codepage if codeset is omitted
from the locale name which is neither "C" nor "POSIX".

ChangeLog
lib/config.charset
lib/localcharset.c

index 79787f154b4ad11105b8c14eaa96d8be30e7deb0..56b75de8442eb9fe29556ac0169e4b4e9443471c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2015-01-07  KO Myung-Hun  <komh@chollian.net>
+
+       localcharset: improve charset detection on OS/2
+       Use system codepage when appropriate.  Map OS/2 codepages to
+       GNU canonical charset names if possible.
+       * lib/config.charset: Don't output aliases if "$os" is os2*.
+       * lib/localcharset.c (get_charset_aliases) [OS2]: Hardcode the
+       result for OS/2.
+       (locale_charset) [OS2]: Use system codepage if codeset is omitted
+       from the locale name which is neither "C" nor "POSIX".
+
 2015-01-06  Paul Eggert  <eggert@cs.ucla.edu>
 
        count-leading-zeros: use 64-bit intrinsics on 32-bit Windows
index 1b8a3f71d85e38b3e0e4edeb16e9bbe64321278e..ac10e4bef48dce3ff11a9a15d52037c2088f0792 100644 (file)
@@ -348,12 +348,10 @@ case "$os" in
     #echo "sun_eu_greek ?" # what is this?
     echo "UTF-8 UTF-8"
     ;;
-  freebsd* | os2*)
+  freebsd*)
     # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore
     # localcharset.c falls back to using the full locale name
     # from the environment variables.
-    # Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just
-    # reuse FreeBSD's locale data for OS/2.
     echo "C ASCII"
     echo "US-ASCII ASCII"
     for l in la_LN lt_LN; do
index d54dbfb0a1ba1a7b1dc391fade0606dcf4aa6fb0..b4af28cd952063a40eb856e4dd5be9b38fab5cde 100644 (file)
@@ -128,7 +128,7 @@ get_charset_aliases (void)
   cp = charset_aliases;
   if (cp == NULL)
     {
-#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGWIN__)
+#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGWIN__ || defined OS2)
       const char *dir;
       const char *base = "charset.alias";
       char *file_name;
@@ -342,6 +342,36 @@ get_charset_aliases (void)
            "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
 
       charset_aliases = cp;
@@ -499,6 +529,8 @@ locale_charset (void)
   ULONG cp[3];
   ULONG cplen;
 
+  codeset = NULL;
+
   /* Allow user to override the codeset, as set in the operating system,
      with standard language environment variables.  */
   locale = getenv ("LC_ALL");
@@ -530,10 +562,12 @@ locale_charset (void)
             }
         }
 
-      /* Resolve through the charset.alias file.  */
-      codeset = locale;
+      /* For the POSIX locale, don't use the system's codepage.  */
+      if (strcmp (locale, "C") == 0 || strcmp (locale, "POSIX") == 0)
+        codeset = "";
     }
-  else
+
+  if (codeset == NULL)
     {
       /* OS/2 has a function returning the locale's codepage as a number.  */
       if (DosQueryCp (sizeof (cp), cp, &cplen))