]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Improved support for Cygwin.
authorBruno Haible <bruno@clisp.org>
Tue, 16 May 2006 16:42:39 +0000 (16:42 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:13:20 +0000 (12:13 +0200)
gettext-runtime/intl/ChangeLog
gettext-runtime/intl/localcharset.c
gettext-tools/lib/ChangeLog
gettext-tools/lib/localcharset.c

index 452c29a65e21d7b5d8305c473a5be12fd0d50f6d..b0e4930fe59e170d42af30608d93b0c8f95aab88 100644 (file)
@@ -1,3 +1,11 @@
+2006-05-16  Bruno Haible  <bruno@clisp.org>
+
+       * localcharset.c [CYGWIN]: Include <windows.h>.
+       (get_charset_aliases): For Cygwin, return the same CPxxx aliases list
+       as under WIN32.
+       (locale_charset) [CYGWIN]: Try to retrieve the encoding from the
+       environment variables. Fall back to GetACP().
+
 2006-05-15  Bruno Haible  <bruno@clisp.org>
 
        * Makefile.in (LDFLAGS, libgnuintl.h): Treat mingw like Cygwin.
index 6c1d29398b3560365ee8691c6e17fb2d44f06f8f..e4e81ca3c040fc5bc15d74cc334bd2f3ad4b45e1 100644 (file)
 #   include <locale.h>
 #  endif
 # endif
+# ifdef __CYGWIN__
+#  define WIN32_LEAN_AND_MEAN
+#  include <windows.h>
+# endif
 #elif defined WIN32
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
@@ -114,7 +118,7 @@ get_charset_aliases (void)
   cp = charset_aliases;
   if (cp == NULL)
     {
-#if !(defined VMS || defined WIN32)
+#if !(defined VMS || defined WIN32 || defined __CYGWIN__)
       FILE *fp;
       const char *dir;
       const char *base = "charset.alias";
@@ -240,7 +244,7 @@ get_charset_aliases (void)
           "DECKOREAN" "\0" "EUC-KR" "\0";
 # endif
 
-# if defined WIN32
+# if defined WIN32 || 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.  */
@@ -299,6 +303,53 @@ locale_charset (void)
   /* Most systems support nl_langinfo (CODESET) nowadays.  */
   codeset = nl_langinfo (CODESET);
 
+#  ifdef __CYGWIN__
+  /* Cygwin 2006 does not have locales.  nl_langinfo (CODESET) always
+     returns "US-ASCII".  As long as this is not fixed, return the suffix
+     of the locale name from the environment variables (if present) or
+     the codepage as a number.  */
+  if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
+    {
+      const char *locale;
+      static char buf[2 + 10 + 1];
+
+      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[0] != '\0')
+       {
+         /* If the locale name contains an encoding after the dot, return
+            it.  */
+         const char *dot = strchr (locale, '.');
+
+         if (dot != NULL)
+           {
+             const char *modifier;
+
+             dot++;
+             /* Look for the possible @... trailer and remove it, if any.  */
+             modifier = strchr (dot, '@');
+             if (modifier == NULL)
+               return dot;
+             if (modifier - dot < sizeof (buf))
+               {
+                 memcpy (buf, dot, modifier - dot);
+                 buf [modifier - dot] = '\0';
+                 return buf;
+               }
+           }
+       }
+
+      /* Woe32 has a function returning the locale's codepage as a number.  */
+      sprintf (buf, "CP%u", GetACP ());
+      codeset = buf;
+    }
+#  endif
+
 # else
 
   /* On old systems which lack it, use setlocale or getenv.  */
index 57b97b730203e25c47a273446a6136708fe540b5..40420947e63f8d422bdbaad17c8bfb4234b3a95f 100644 (file)
@@ -1,3 +1,11 @@
+2006-05-16  Bruno Haible  <bruno@clisp.org>
+
+       * localcharset.c [CYGWIN]: Include <windows.h>.
+       (get_charset_aliases): For Cygwin, return the same CPxxx aliases list
+       as under WIN32.
+       (locale_charset) [CYGWIN]: Try to retrieve the encoding from the
+       environment variables. Fall back to GetACP().
+
 2006-05-16  Bruno Haible  <bruno@clisp.org>
 
        * javacomp.c (is_envjavac_gcj_14_14_usable,
index 6c1d29398b3560365ee8691c6e17fb2d44f06f8f..e4e81ca3c040fc5bc15d74cc334bd2f3ad4b45e1 100644 (file)
 #   include <locale.h>
 #  endif
 # endif
+# ifdef __CYGWIN__
+#  define WIN32_LEAN_AND_MEAN
+#  include <windows.h>
+# endif
 #elif defined WIN32
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
@@ -114,7 +118,7 @@ get_charset_aliases (void)
   cp = charset_aliases;
   if (cp == NULL)
     {
-#if !(defined VMS || defined WIN32)
+#if !(defined VMS || defined WIN32 || defined __CYGWIN__)
       FILE *fp;
       const char *dir;
       const char *base = "charset.alias";
@@ -240,7 +244,7 @@ get_charset_aliases (void)
           "DECKOREAN" "\0" "EUC-KR" "\0";
 # endif
 
-# if defined WIN32
+# if defined WIN32 || 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.  */
@@ -299,6 +303,53 @@ locale_charset (void)
   /* Most systems support nl_langinfo (CODESET) nowadays.  */
   codeset = nl_langinfo (CODESET);
 
+#  ifdef __CYGWIN__
+  /* Cygwin 2006 does not have locales.  nl_langinfo (CODESET) always
+     returns "US-ASCII".  As long as this is not fixed, return the suffix
+     of the locale name from the environment variables (if present) or
+     the codepage as a number.  */
+  if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
+    {
+      const char *locale;
+      static char buf[2 + 10 + 1];
+
+      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[0] != '\0')
+       {
+         /* If the locale name contains an encoding after the dot, return
+            it.  */
+         const char *dot = strchr (locale, '.');
+
+         if (dot != NULL)
+           {
+             const char *modifier;
+
+             dot++;
+             /* Look for the possible @... trailer and remove it, if any.  */
+             modifier = strchr (dot, '@');
+             if (modifier == NULL)
+               return dot;
+             if (modifier - dot < sizeof (buf))
+               {
+                 memcpy (buf, dot, modifier - dot);
+                 buf [modifier - dot] = '\0';
+                 return buf;
+               }
+           }
+       }
+
+      /* Woe32 has a function returning the locale's codepage as a number.  */
+      sprintf (buf, "CP%u", GetACP ());
+      codeset = buf;
+    }
+#  endif
+
 # else
 
   /* On old systems which lack it, use setlocale or getenv.  */