This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
intl patches (28)
- From: Bruno Haible <haible at ilog dot fr>
- To: libc-alpha at sources dot redhat dot com
- Date: Thu, 22 Nov 2001 15:03:26 +0100 (CET)
- Subject: intl patches (28)
Here is a patch which moves the locale determination code to a separate file.
On POSIX systems this is only 20 lines, but the code for other systems makes
up more than 600 lines of code; there is no room for it in dcigettext.c.
Support for these non-POSIX systems has been added to gettext's libintl
because it is important for projects like GNOME. Trying to be polite,
I present for inclusion into glibc only the POSIX code.
Inside glibc, the effect of the patch is minimal: it adds a function call
for code that was inlined before.
The newly created function is also used for a similar purpose by the
'msginit' program.
2001-09-24 Bruno Haible <bruno@clisp.org>
* intl/localename.c: New file, extracted from intl/dcigettext.c.
* intl/gettextP.h (_nl_locale_name): New declaration.
* intl/dcigettext.c (guess_category_value): Call _nl_locale_name.
* Makefile (routines): Add localename.
--- glibc-20011110/intl/localename.c.bak Tue Nov 20 01:09:29 2001
+++ glibc-20011110/intl/localename.c Tue Nov 20 01:08:53 2001
@@ -0,0 +1,76 @@
+/* Determine the current selected locale.
+ Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* Written by Ulrich Drepper <drepper@gnu.org>, 1995. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <locale.h>
+
+/* XPG3 defines the result of 'setlocale (category, NULL)' as:
+ "Directs 'setlocale()' to query 'category' and return the current
+ setting of 'local'."
+ However it does not specify the exact format. Neither do SUSV2 and
+ ISO C 99. So we can use this feature only on selected systems (e.g.
+ those using GNU C Library). */
+#if defined _LIBC || (defined __GNU_LIBRARY__ && __GNU_LIBRARY__ >= 2)
+# define HAVE_LOCALE_NULL
+#endif
+
+/* Determine the current locale's name, and canonicalize it into XPG syntax
+ language[_territory[.codeset]][@modifier]
+ The codeset part in the result is not reliable; the locale_charset()
+ should be used for codeset information instead.
+ The result must not be freed; it is statically allocated. */
+
+const char *
+_nl_locale_name (category, categoryname)
+ int category;
+ const char *categoryname;
+{
+ const char *retval;
+
+ /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
+ On some systems this can be done by the 'setlocale' function itself. */
+# if defined _LIBC || (defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL)
+ retval = setlocale (category, NULL);
+# else
+ /* Setting of LC_ALL overwrites all other. */
+ retval = getenv ("LC_ALL");
+ if (retval == NULL || retval[0] == '\0')
+ {
+ /* Next comes the name of the desired category. */
+ retval = getenv (categoryname);
+ if (retval == NULL || retval[0] == '\0')
+ {
+ /* Last possibility is the LANG environment variable. */
+ retval = getenv ("LANG");
+ if (retval == NULL || retval[0] == '\0')
+ /* We use C as the default domain. POSIX says this is
+ implementation defined. */
+ retval = "C";
+ }
+ }
+# endif
+
+ return retval;
+}
--- glibc-20011110/intl/gettextP.h.bak Wed Nov 21 12:35:53 2001
+++ glibc-20011110/intl/gettextP.h Tue Nov 20 01:00:00 2001
@@ -125,6 +125,7 @@
This variable is part of the external ABI of the GNU libintl. */
extern int _nl_msg_cat_cntr;
+const char *_nl_locale_name PARAMS ((int category, const char *categoryname));
struct loaded_l10nfile *_nl_find_domain PARAMS ((const char *__dirname,
char *__locale,
const char *__domainname,
--- glibc-20011110/intl/dcigettext.c.bak Wed Nov 21 12:35:53 2001
+++ glibc-20011110/intl/dcigettext.c Tue Nov 20 01:00:00 2001
@@ -172,16 +172,6 @@
# define PATH_MAX _POSIX_PATH_MAX
#endif
-/* XPG3 defines the result of `setlocale (category, NULL)' as:
- ``Directs `setlocale()' to query `category' and return the current
- setting of `local'.''
- However it does not specify the exact format. Neither do SUSV2 and
- ISO C 99. So we can use this feature only on selected systems (e.g.
- those using GNU C Library). */
-#ifdef _LIBC
-# define HAVE_LOCALE_NULL
-#endif
-
/* This is the type used for the search tree where known translations
are stored. */
struct known_translation_t
@@ -1121,30 +1043,19 @@
if (language != NULL && language[0] == '\0')
language = NULL;
- /* We have to proceed with the POSIX methods of looking to `LC_ALL',
- `LC_xxx', and `LANG'. On some systems this can be done by the
- `setlocale' function itself. */
-#if defined _LIBC || (defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL)
- retval = setlocale (category, NULL);
-#else
- /* Setting of LC_ALL overwrites all other. */
- retval = getenv ("LC_ALL");
- if (retval == NULL || retval[0] == '\0')
- {
- /* Next comes the name of the desired category. */
- retval = getenv (categoryname);
- if (retval == NULL || retval[0] == '\0')
- {
- /* Last possibility is the LANG environment variable. */
- retval = getenv ("LANG");
- if (retval == NULL || retval[0] == '\0')
- /* We use C as the default domain. POSIX says this is
- implementation defined. */
- return "C";
- }
- }
-#endif
-
+ /* Proceed with the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and
+ 'LANG'. */
+ retval = _nl_locale_name (category, categoryname);
+
+ /* Ignore LANGUAGE if the locale is set to "C" because
+ 1. "C" locale usually uses the ASCII encoding, and most international
+ messages use non-ASCII characters. These characters get displayed
+ as question marks (if using glibc's iconv()) or as invalid 8-bit
+ characters (because other iconv()s refuse to convert most non-ASCII
+ characters to ASCII). In any case, the output is ugly.
+ 2. The precise output of some programs in the "C" locale is specified
+ by POSIX and should not depend on environment variables like
+ "LANGUAGE". We allow such programs to use gettext(). */
return language != NULL && strcmp (retval, "C") != 0 ? language : retval;
}
--- glibc-20011110/intl/Makefile.bak Thu Nov 22 01:25:50 2001
+++ glibc-20011110/intl/Makefile Thu Nov 22 01:08:13 2001
@@ -22,7 +22,7 @@
headers = libintl.h
routines = bindtextdom dcgettext dgettext gettext \
dcigettext dcngettext dngettext ngettext \
- finddomain loadmsgcat localealias textdomain \
+ finddomain loadmsgcat localealias localename textdomain \
l10nflist explodename plural plural-exp plural-eval
distribute = gettext.h gettextP.h hash-string.h loadinfo.h locale.alias \
plural.y plural-exp.h po2test.sed tst-gettext.sh tst-translit.sh \