From: Bruno Haible Date: Tue, 16 May 2006 16:42:39 +0000 (+0000) Subject: Improved support for Cygwin. X-Git-Tag: v0.15~130 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2b5b897c3d66e728470946e6fe7f7033b7d96c2;p=thirdparty%2Fgettext.git Improved support for Cygwin. --- diff --git a/gettext-runtime/intl/ChangeLog b/gettext-runtime/intl/ChangeLog index 452c29a65..b0e4930fe 100644 --- a/gettext-runtime/intl/ChangeLog +++ b/gettext-runtime/intl/ChangeLog @@ -1,3 +1,11 @@ +2006-05-16 Bruno Haible + + * localcharset.c [CYGWIN]: Include . + (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 * Makefile.in (LDFLAGS, libgnuintl.h): Treat mingw like Cygwin. diff --git a/gettext-runtime/intl/localcharset.c b/gettext-runtime/intl/localcharset.c index 6c1d29398..e4e81ca3c 100644 --- a/gettext-runtime/intl/localcharset.c +++ b/gettext-runtime/intl/localcharset.c @@ -58,6 +58,10 @@ # include # endif # endif +# ifdef __CYGWIN__ +# define WIN32_LEAN_AND_MEAN +# include +# endif #elif defined WIN32 # define WIN32_LEAN_AND_MEAN # include @@ -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. */ diff --git a/gettext-tools/lib/ChangeLog b/gettext-tools/lib/ChangeLog index 57b97b730..40420947e 100644 --- a/gettext-tools/lib/ChangeLog +++ b/gettext-tools/lib/ChangeLog @@ -1,3 +1,11 @@ +2006-05-16 Bruno Haible + + * localcharset.c [CYGWIN]: Include . + (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 * javacomp.c (is_envjavac_gcj_14_14_usable, diff --git a/gettext-tools/lib/localcharset.c b/gettext-tools/lib/localcharset.c index 6c1d29398..e4e81ca3c 100644 --- a/gettext-tools/lib/localcharset.c +++ b/gettext-tools/lib/localcharset.c @@ -58,6 +58,10 @@ # include # endif # endif +# ifdef __CYGWIN__ +# define WIN32_LEAN_AND_MEAN +# include +# endif #elif defined WIN32 # define WIN32_LEAN_AND_MEAN # include @@ -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. */