summaryrefslogtreecommitdiff
path: root/gnulib-local/lib
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2011-12-15 01:31:16 +0100
committerLudovic Courtès <ludo@gnu.org>2011-12-15 01:31:16 +0100
commitc2c2b5a49b1ce37a42417037c3515864a808e53b (patch)
tree2fd5ace5f7ac7d306b53c7b81dd075241e8d43f4 /gnulib-local/lib
parenta00c31bc46b639828d0decc33380c16d256f7986 (diff)
downloadguile-c2c2b5a49b1ce37a42417037c3515864a808e53b.tar.gz
Use Gnulib's `localcharset', with local patches.
This follows Bruno Haible's suggestion at <http://lists.gnu.org/archive/html/guile-devel/2011-11/msg00055.html>. * m4/gnulib-cache.m4: Add `gl_LOCAL_DIR'; use `localcharset'. * Makefile.am (EXTRA_DIST): Add gnulib-local/lib/localcharset.[ch].diff. (TESTS_ENVIRONMENT): New variable. * gnulib-local/lib/localcharset.c.diff, gnulib-local/lib/localcharset.h.diff: New files. * test-suite/Makefile.am (TESTS_ENVIRONMENT): Add @LOCALCHARSET_TESTS_ENVIRONMENT@. * test-suite/standalone/Makefile.am (TESTS_ENVIRONMENT): Likewise.
Diffstat (limited to 'gnulib-local/lib')
-rw-r--r--gnulib-local/lib/localcharset.c.diff84
-rw-r--r--gnulib-local/lib/localcharset.h.diff22
2 files changed, 106 insertions, 0 deletions
diff --git a/gnulib-local/lib/localcharset.c.diff b/gnulib-local/lib/localcharset.c.diff
new file mode 100644
index 000000000..2b27ee479
--- /dev/null
+++ b/gnulib-local/lib/localcharset.c.diff
@@ -0,0 +1,84 @@
+Add a variant of `locale_charset' that returns its result based solely on
+information from the environment. See
+http://lists.gnu.org/archive/html/guile-devel/2011-11/msg00040.html for the
+rationale.
+
+--- a/lib/localcharset.c 2011-12-14 23:10:58.000000000 +0100
++++ b/lib/localcharset.c 2011-12-15 00:45:12.000000000 +0100
+@@ -527,6 +527,76 @@ locale_charset (void)
+ codeset = "";
+
+ /* Resolve alias. */
++ for (aliases = get_charset_aliases ();
++ *aliases != '\0';
++ aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
++ if (strcmp (codeset, aliases) == 0
++ || (aliases[0] == '*' && aliases[1] == '\0'))
++ {
++ codeset = aliases + strlen (aliases) + 1;
++ break;
++ }
++
++ /* Don't return an empty string. GNU libc and GNU libiconv interpret
++ the empty string as denoting "the locale's character encoding",
++ thus GNU libiconv would call this function a second time. */
++ if (codeset[0] == '\0')
++ codeset = "ASCII";
++
++ return codeset;
++}
++
++/* A variant of the above, without calls to `setlocale', `nl_langinfo',
++ etc. */
++const char *
++environ_locale_charset (void)
++{
++ static char buf[2 + 10 + 1];
++ const char *codeset, *aliases;
++ const char *locale = NULL;
++
++ 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;
++ }
++ }
++ else if (strcmp (locale, "C") == 0)
++ {
++ strcpy (buf, "ASCII");
++ return buf;
++ }
++
++ /* Resolve through the charset.alias file. */
++ codeset = locale;
++ }
++ else
++ codeset = "";
++
++ /* Resolve alias. */
+ for (aliases = get_charset_aliases ();
+ *aliases != '\0';
+ aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
diff --git a/gnulib-local/lib/localcharset.h.diff b/gnulib-local/lib/localcharset.h.diff
new file mode 100644
index 000000000..9e0b74b69
--- /dev/null
+++ b/gnulib-local/lib/localcharset.h.diff
@@ -0,0 +1,22 @@
+Add a variant of `locale_charset' that returns its result based solely on
+information from the environment. See
+http://lists.gnu.org/archive/html/guile-devel/2011-11/msg00040.html for the
+rationale.
+
+diff --git a/lib/localcharset.h b/lib/localcharset.h
+index 8907ccd..43e976f 100644
+--- a/lib/localcharset.h
++++ b/lib/localcharset.h
+@@ -32,6 +32,12 @@ extern "C" {
+ name. */
+ extern const char * locale_charset (void);
+
++/* Same as above, but only look at environment variables, avoiding calls to
++ `setlocale', `nl_langinfo', etc. See
++ <http://lists.gnu.org/archive/html/guile-devel/2011-11/msg00040.html> for
++ the rationale. */
++extern const char * environ_locale_charset (void);
++
+
+ #ifdef __cplusplus
+ }