+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.
# 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>
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";
"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. */
/* 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. */
+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,
# 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>
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";
"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. */
/* 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. */