diff options
author | Eli Zaretskii <eliz@gnu.org> | 2018-08-04 20:14:51 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2018-08-04 20:14:51 +0300 |
commit | a9e991ea8292ab72e452688577e179e62c0e0b1b (patch) | |
tree | 8bb6e6fa61c53eee406d590b6866bfc54204ce57 | |
parent | a09917ecd6bc47fc6c9b17beda87d9205a985a0e (diff) | |
download | egawk-a9e991ea8292ab72e452688577e179e62c0e0b1b.tar.gz egawk-a9e991ea8292ab72e452688577e179e62c0e0b1b.tar.bz2 egawk-a9e991ea8292ab72e452688577e179e62c0e0b1b.zip |
Emulate nl_langinfo(CODESET) for MinGW.
-rw-r--r-- | pc/ChangeLog | 10 | ||||
-rw-r--r-- | pc/config.h | 4 | ||||
-rw-r--r-- | pc/config.sed | 4 | ||||
-rw-r--r-- | pc/gawkmisc.pc | 65 | ||||
-rw-r--r-- | pc/langinfo.h | 9 |
5 files changed, 91 insertions, 1 deletions
diff --git a/pc/ChangeLog b/pc/ChangeLog index e62150a1..834aede5 100644 --- a/pc/ChangeLog +++ b/pc/ChangeLog @@ -1,3 +1,13 @@ +2018-08-04 Eli Zaretskii <eliz@gnu.org> + + * gawkmisc.pc (nl_langinfo) [__MINGW32__]: New function + [DYNAMIC]: Include winerror.h, for MinGW runtime 5.1.0. + + * langinfo.h: New file. + + * config.sed: + * config.h (HAVE_LANGINFO_CODESET): Define for MinGW. + 2018-05-12 Eli Zaretskii <eliz@gnu.org> * Makefile.tst (readfile): Fix a typo. diff --git a/pc/config.h b/pc/config.h index 62c13f22..64ad9f97 100644 --- a/pc/config.h +++ b/pc/config.h @@ -115,7 +115,9 @@ #endif /* Define if you have <langinfo.h> and nl_langinfo(CODESET). */ -#undef HAVE_LANGINFO_CODESET +#ifdef __MINGW32__ +#define HAVE_LANGINFO_CODESET 1 +#endif /* Define if your <locale.h> file defines LC_MESSAGES. */ #undef HAVE_LC_MESSAGES diff --git a/pc/config.sed b/pc/config.sed index 315c9cad..75ad0890 100644 --- a/pc/config.sed +++ b/pc/config.sed @@ -82,6 +82,10 @@ s/^#undef HAVE_FMOD *$/#define HAVE_FMOD 1/ #ifdef __MINGW32__\ #define HAVE_ISWUPPER 1\ #endif +/^#undef HAVE_LANGINFO_CODESET *$/c\ +#ifdef __MINGW32__\ +#define HAVE_LANGINFO_CODESET 1\ +#endif s/^#undef HAVE_LIBM *$/#define HAVE_LIBM 1/ /^#undef HAVE_LIBREADLINE *$/c\ /* #undef HAVE_LIBREADLINE */ diff --git a/pc/gawkmisc.pc b/pc/gawkmisc.pc index f3d6d7fa..7c4436ef 100644 --- a/pc/gawkmisc.pc +++ b/pc/gawkmisc.pc @@ -724,6 +724,70 @@ w32_setlocale (int category, const char *value) return setlocale (category, new_locale); } +/* Replacement for the missing nl_langinfo. Only CODESET is currently + supported. */ +#include <langinfo.h> + +char * +nl_langinfo (int item) +{ + switch (item) + { + case CODESET: + { + /* Shamelessly stolen from Gnulib's nl_langinfo.c. */ + static char buf[2 + 10 + 1]; + char const *locale = setlocale (LC_CTYPE, NULL); + char *codeset = buf; + size_t codesetlen; + codeset[0] = '\0'; + + if (locale && locale[0]) + { + /* If the locale name contains an encoding after the + dot, return it. */ + char *dot = strchr (locale, '.'); + + if (dot) + { + /* Look for the possible @... trailer and remove it, + if any. */ + char *codeset_start = dot + 1; + char const *modifier = strchr (codeset_start, '@'); + + if (! modifier) + codeset = codeset_start; + else + { + codesetlen = modifier - codeset_start; + if (codesetlen < sizeof buf) + { + codeset = memcpy (buf, codeset_start, codesetlen); + codeset[codesetlen] = '\0'; + } + } + } + } + /* If setlocale is successful, it returns the number of the + codepage, as a string. Otherwise, fall back on Windows + API GetACP, which returns the locale's codepage as a + number (although this doesn't change according to what + the 'setlocale' call specified). Either way, prepend + "CP" to make it a valid codeset name. */ + codesetlen = strlen (codeset); + if (0 < codesetlen && codesetlen < sizeof buf - 2) + memmove (buf + 2, codeset, codesetlen + 1); + else + sprintf (buf + 2, "%u", GetACP ()); + codeset = memcpy (buf, "CP", 2); + + return codeset; + } + default: + return (char *) ""; + } +} + /* * On MS-Windows with MinGW, execvp causes the shell and the re-exec'ed * dgawk to compete for the keyboard input. @@ -740,6 +804,7 @@ int execvp(const char *file, const char *const *argv) #ifdef DYNAMIC +#include <winerror.h> #include <dlfcn.h> static DWORD last_err; diff --git a/pc/langinfo.h b/pc/langinfo.h new file mode 100644 index 00000000..2d220968 --- /dev/null +++ b/pc/langinfo.h @@ -0,0 +1,9 @@ +/* langinfo.h replacement for MS-Windows build. */ +#ifndef LANGINFO_H +#define LANGINFO_H + +#define CODESET 1 + +extern char *nl_langinfo (int); + +#endif |