This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

locale_t aware gettext() functions


Hi,

Multithread-safe dcgettext() is still not sufficient for all usecases. In
web-server environments, typically a single thread handles multiple sessions,
and the locale to be used for translations is session dependent. Doing
uselocale() each time the thread switches to a different session is more a
hack than an object-oriented implementation. Here, a dcgettext_l() function
taking as argument a locale (which would be stored in the session object)
is more welcome.

Here is a patch to introduce 4 new functions d[c][n]gettext_l. Functions
gettext_l and ngettext_l are not useful, IMO, since they implicitly refer
to a global domain; typically a web-server application will need different
domains in different sessions.


2005-03-28  Bruno Haible  <bruno@clisp.org>

	* intl/Versions: Add dcgettext_l, dgettext_l, dcngettext_l, dngettext_l
	for version GLIBC_2.4.
	* intl/gettextP.h (_nl_find_msg) [_LIBC]: Add locale argument.
	(__dcigettext): Add locale argument.
	* intl/dcigettext.c (LOCALE_PARAM_PROTO, LOCALE_PARAM,
	LOCALE_PARAM_DECL, LOCALE_ARG): New macros.
	(DCIGETTEXT) [_LIBC]: Add locale argument. Replace
	__current_locale_name call with direct access. Pass locale down to
	_nl_find_msg.
	(_nl_find_msg) [_LIBC]: Add locale argument. Pass it down to
	get_output_charset.
	(guess_category_value) [_LIBC]: Add locale argument. Replace
	__current_locale_name call with direct access.
	(get_output_charset) [_LIBC]: Add locale argument.
	* intl/loadmsgcat.c (_nl_load_domain): Update _nl_find_msg call.
	* intl/dcgettext_l.c: New file.
	* intl/dcgettext.c: Include localeinfo.h. Add support for
	USE_IN_EXTENDED_LOCALE_MODEL.
	(DCGETTEXT) [!USE_IN_EXTENDED_LOCALE_MODEL]: Fetch _NL_CURRENT_LOCALE
	and pass it to __dcigettext.
	* intl/dgettext_l.c: New file.
	* intl/dgettext.c: Include localeinfo.h. Add support for
	USE_IN_EXTENDED_LOCALE_MODEL.
	* intl/dcngettext_l.c: New file.
	* intl/dcngettext.c: Include localeinfo.h. Add support for
	USE_IN_EXTENDED_LOCALE_MODEL.
	(DCNGETTEXT) [!USE_IN_EXTENDED_LOCALE_MODEL]: Fetch _NL_CURRENT_LOCALE
	and pass it to __dcigettext.
	* intl/dngettext_l.c: New file.
	* intl/dngettext.c: Include localeinfo.h. Add support for
	USE_IN_EXTENDED_LOCALE_MODEL.
	* intl/libintl.h (dgettext_l, dcgettext_l, dngettext_l, dcngettext_l)
	[__USE_GNU]: New function declarations.
	(dgettext_l, dngettext_l) [__USE_GNU && __OPTIMIZE__]: New macros.
	* include/libintl.h (__dcgettext_l, __dcngettext_l): New declarations.
	* intl/Makefile (routines): Add dcgettext_l, dgettext_l, dcngettext_l,
	dngettext_l.

--- glibc-20050322/intl/Versions.bak	Fri Sep 20 15:30:20 2002
+++ glibc-20050322/intl/Versions	Mon Mar 28 16:32:08 2005
@@ -28,4 +28,8 @@
     # n*
     ngettext;
   }
+  GLIBC_2.4 {
+    # d*
+    dcgettext_l; dgettext_l; dcngettext_l; dngettext_l;
+  }
 }
--- glibc-20050322/intl/gettextP.h.bak3	2005-03-28 01:42:08.000000000 +0200
+++ glibc-20050322/intl/gettextP.h	2005-03-28 22:57:05.000000000 +0200
@@ -187,10 +187,17 @@
 			      struct binding *__domainbinding))
      internal_function;
 
+#ifdef _LIBC
+char *_nl_find_msg PARAMS ((struct loaded_l10nfile *domain_file,
+			    struct binding *domainbinding, const char *msgid,
+			    int convert, size_t *lengthp, __locale_t locale))
+     internal_function;
+#else
 char *_nl_find_msg PARAMS ((struct loaded_l10nfile *domain_file,
 			    struct binding *domainbinding, const char *msgid,
 			    int convert, size_t *lengthp))
      internal_function;
+#endif
 
 #ifdef _LIBC
 extern char *__gettext PARAMS ((const char *__msgid));
@@ -209,7 +216,7 @@
 extern char *__dcigettext PARAMS ((const char *__domainname,
 				   const char *__msgid1, const char *__msgid2,
 				   int __plural, unsigned long int __n,
-				   int __category));
+				   int __category, __locale_t __locale));
 extern char *__textdomain PARAMS ((const char *__domainname));
 extern char *__bindtextdomain PARAMS ((const char *__domainname,
 				       const char *__dirname));
--- glibc-20050322/intl/dcigettext.c.bak4	2005-03-28 04:30:06.000000000 +0200
+++ glibc-20050322/intl/dcigettext.c	2005-03-28 23:11:03.000000000 +0200
@@ -172,6 +172,19 @@
 # define PATH_MAX _POSIX_PATH_MAX
 #endif
 
+/* How to pass around a locale object.  */
+#ifdef _LIBC
+# define LOCALE_PARAM_PROTO , __locale_t locale
+# define LOCALE_PARAM , locale
+# define LOCALE_PARAM_DECL  __locale_t locale;
+# define LOCALE_ARG , locale
+#else
+# define LOCALE_PARAM_PROTO
+# define LOCALE_PARAM
+# define LOCALE_PARAM_DECL
+# define LOCALE_ARG
+#endif
+
 /* Whether to support different locales in different threads.  */
 #if defined _LIBC || HAVE_NL_LOCALE
 # define HAVE_PER_THREAD_LOCALE
@@ -282,7 +295,8 @@
 				    size_t translation_len))
      internal_function;
 static const char *guess_category_value PARAMS ((int category,
-						 const char *categoryname))
+						 const char *categoryname
+						 LOCALE_PARAM_PROTO))
      internal_function;
 #ifdef _LIBC
 # include "../locale/localeinfo.h"
@@ -343,7 +357,8 @@
 typedef unsigned char transmem_block_t;
 #endif
 #if defined _LIBC || HAVE_ICONV
-static const char *get_output_charset PARAMS ((struct binding *domainbinding))
+static const char *get_output_charset PARAMS ((struct binding *domainbinding
+					       LOCALE_PARAM_PROTO))
      internal_function;
 #endif
 
@@ -400,13 +415,14 @@
    CATEGORY locale and, if PLURAL is nonzero, search over string
    depending on the plural form determined by N.  */
 char *
-DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category)
+DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category LOCALE_PARAM)
      const char *domainname;
      const char *msgid1;
      const char *msgid2;
      int plural;
      unsigned long int n;
      int category;
+     LOCALE_PARAM_DECL
 {
 #ifndef HAVE_ALLOCA
   struct block_list *block_list = NULL;
@@ -463,7 +479,7 @@
   search->category = category;
 # ifdef HAVE_PER_THREAD_LOCALE
 #  ifdef _LIBC
-  localename = __current_locale_name (category);
+  localename = locale->__names[category];
 #  endif
   search->localename = localename;
 # endif
@@ -559,7 +575,7 @@
 
   /* Now determine the symbolic name of CATEGORY and its value.  */
   categoryname = category_to_name (category);
-  categoryvalue = guess_category_value (category, categoryname);
+  categoryvalue = guess_category_value (category, categoryname LOCALE_ARG);
 
   domainname_len = strlen (domainname);
   xdomainname = (char *) alloca (strlen (categoryname)
@@ -626,7 +642,8 @@
 
       if (domain != NULL)
 	{
-	  retval = _nl_find_msg (domain, binding, msgid1, 1, &retlen);
+	  retval = _nl_find_msg (domain, binding,
+				 msgid1, 1, &retlen LOCALE_ARG);
 
 	  if (retval == NULL)
 	    {
@@ -635,7 +652,7 @@
 	      for (cnt = 0; domain->successor[cnt] != NULL; ++cnt)
 		{
 		  retval = _nl_find_msg (domain->successor[cnt], binding,
-					 msgid1, 1, &retlen);
+					 msgid1, 1, &retlen LOCALE_ARG);
 
 		  if (retval != NULL)
 		    {
@@ -726,12 +743,13 @@
 
 char *
 internal_function
-_nl_find_msg (domain_file, domainbinding, msgid, convert, lengthp)
+_nl_find_msg (domain_file, domainbinding, msgid, convert, lengthp LOCALE_PARAM)
      struct loaded_l10nfile *domain_file;
      struct binding *domainbinding;
      const char *msgid;
      int convert;
      size_t *lengthp;
+     LOCALE_PARAM_DECL
 {
   struct loaded_domain *domain;
   nls_uint32 nstrings;
@@ -840,7 +858,7 @@
   if (convert)
     {
       /* We are supposed to do a conversion.  */
-      const char *encoding = get_output_charset (domainbinding);
+      const char *encoding = get_output_charset (domainbinding LOCALE_ARG);
 
       /* Search whether a table with converted translations for this
 	 encoding has already been allocated.  */
@@ -902,7 +920,8 @@
 	    /* Get the header entry.  This is a recursion, but it doesn't
 	       reallocate domain->conversions because we pass convert = 0.  */
 	    nullentry =
-	      _nl_find_msg (domain_file, domainbinding, "", 0, &nullentrylen);
+	      _nl_find_msg (domain_file, domainbinding, "", 0,
+			    &nullentrylen LOCALE_ARG);
 
 	    if (nullentry != NULL)
 	      {
@@ -1265,9 +1284,10 @@
 /* Guess value of current locale from value of the environment variables.  */
 static const char *
 internal_function
-guess_category_value (category, categoryname)
+guess_category_value (category, categoryname LOCALE_PARAM)
      int category;
      const char *categoryname;
+     LOCALE_PARAM_DECL
 {
   const char *language;
   const char *retval;
@@ -1283,7 +1303,7 @@
      `LC_xxx', and `LANG'.  On some systems this can be done by the
      `setlocale' function itself.  */
 #ifdef _LIBC
-  retval = __current_locale_name (category);
+  retval = locale->__names[category];
 #else
   retval = _nl_locale_name (category, categoryname);
 #endif
@@ -1295,8 +1315,9 @@
 /* Returns the output charset.  */
 static const char *
 internal_function
-get_output_charset (domainbinding)
+get_output_charset (domainbinding LOCALE_PARAM)
      struct binding *domainbinding;
+     LOCALE_PARAM_DECL
 {
   /* The output charset should normally be determined by the locale.  But
      sometimes the locale is not used or not correctly set up, so we provide
@@ -1334,7 +1355,7 @@
       else
 	{
 # ifdef _LIBC
-	  return _NL_CURRENT (LC_CTYPE, CODESET);
+	  return locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (CODESET)].string;
 # else
 #  if HAVE_ICONV
 	  extern const char *locale_charset PARAMS ((void);
--- glibc-20050322/intl/loadmsgcat.c.bak2	2005-03-28 22:58:11.000000000 +0200
+++ glibc-20050322/intl/loadmsgcat.c	2005-03-28 22:58:21.000000000 +0200
@@ -1254,7 +1254,12 @@
   domain->nconversions = 0;
 
   /* Get the header entry and look for a plural specification.  */
+#ifdef _LIBC
+  nullentry = _nl_find_msg (domain_file, domainbinding, "", 0, &nullentrylen,
+			    &_nl_C_locobj);
+#else
   nullentry = _nl_find_msg (domain_file, domainbinding, "", 0, &nullentrylen);
+#endif
   EXTRACT_PLURAL_EXPRESSION (nullentry, &domain->plural, &domain->nplurals);
 
  out:
--- /dev/null	Tue Sep 23 19:59:22 2003
+++ glibc-20050322/intl/dcgettext_l.c	Mon Mar 28 15:51:28 2005
@@ -0,0 +1,20 @@
+/* Copyright (C) 2005 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.  */
+
+#define USE_IN_EXTENDED_LOCALE_MODEL 1
+#include <dcgettext.c>
--- glibc-20050322/intl/dcgettext.c.bak	Mon Dec 16 12:45:52 2002
+++ glibc-20050322/intl/dcgettext.c	Mon Mar 28 18:14:52 2005
@@ -1,5 +1,5 @@
 /* Implementation of the dcgettext(3) function.
-   Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1995-1999, 2000, 2001, 2002, 2005 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
@@ -35,26 +35,56 @@
    code is also used in GNU C Library where the names have a __
    prefix.  So we have to make a difference here.  */
 #ifdef _LIBC
-# define DCGETTEXT __dcgettext
+# ifdef USE_IN_EXTENDED_LOCALE_MODEL
+/* We use this code also for the extended locale handling where the
+   function gets as an additional argument the locale which has to be
+   used.  */
+#  define DCGETTEXT __dcgettext_l
+#  define CONST const
+#  define LOCALE_PARAM_PROTO , __locale_t locale
+#  define LOCALE_PARAM , locale
+#  define LOCALE_PARAM_DECL  __locale_t locale;
+# else
+#  define DCGETTEXT __dcgettext
+#  define CONST
+#  define LOCALE_PARAM_PROTO
+#  define LOCALE_PARAM
+#  define LOCALE_PARAM_DECL
+#  include "../locale/localeinfo.h"
+# endif
 # define DCIGETTEXT __dcigettext
+# define LOCALE_ARG , locale
 #else
 # define DCGETTEXT libintl_dcgettext
+# define CONST
+# define LOCALE_PARAM_PROTO
+# define LOCALE_PARAM
+# define LOCALE_PARAM_DECL
 # define DCIGETTEXT libintl_dcigettext
+# define LOCALE_ARG
 #endif
 
 /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
    locale.  */
-char *
-DCGETTEXT (domainname, msgid, category)
+CONST char *
+DCGETTEXT (domainname, msgid, category LOCALE_PARAM)
      const char *domainname;
      const char *msgid;
      int category;
+     LOCALE_PARAM_DECL
 {
-  return DCIGETTEXT (domainname, msgid, NULL, 0, 0, category);
+#if defined _LIBC && !defined USE_IN_EXTENDED_LOCALE_MODEL
+  __locale_t locale = _NL_CURRENT_LOCALE;
+#endif
+  return DCIGETTEXT (domainname, msgid, NULL, 0, 0, category LOCALE_ARG);
 }
 
 #ifdef _LIBC
 /* Alias for function name in GNU C Library.  */
+# ifdef USE_IN_EXTENDED_LOCALE_MODEL
+weak_alias (__dcgettext_l, dcgettext_l);
+# else
 INTDEF(__dcgettext)
 weak_alias (__dcgettext, dcgettext);
+# endif
 #endif
--- /dev/null	Tue Sep 23 19:59:22 2003
+++ glibc-20050322/intl/dgettext_l.c	Mon Mar 28 15:51:28 2005
@@ -0,0 +1,20 @@
+/* Copyright (C) 2005 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.  */
+
+#define USE_IN_EXTENDED_LOCALE_MODEL 1
+#include <dgettext.c>
--- glibc-20050322/intl/dgettext.c.bak	Mon Dec 16 12:45:53 2002
+++ glibc-20050322/intl/dgettext.c	Mon Mar 28 18:14:52 2005
@@ -1,5 +1,5 @@
 /* Implementation of the dgettext(3) function.
-   Copyright (C) 1995-1997, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1995-1997, 2000, 2001, 2002, 2005 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
@@ -37,24 +37,49 @@
    code is also used in GNU C Library where the names have a __
    prefix.  So we have to make a difference here.  */
 #ifdef _LIBC
-# define DGETTEXT __dgettext
-# define DCGETTEXT INTUSE(__dcgettext)
+# ifdef USE_IN_EXTENDED_LOCALE_MODEL
+#  define DGETTEXT dgettext_l
+#  define DCGETTEXT __dcgettext_l
+#  undef dgettext_l
+#  define CONST const
+# else
+#  define DGETTEXT __dgettext
+#  define DCGETTEXT INTUSE(__dcgettext)
+#  define CONST
+# endif
 #else
 # define DGETTEXT libintl_dgettext
 # define DCGETTEXT libintl_dcgettext
+# define CONST
+#endif
+
+#ifdef USE_IN_EXTENDED_LOCALE_MODEL
+/* We use this code also for the extended locale handling where the
+   function gets as an additional argument the locale which has to be
+   used.  */
+# define LOCALE_PARAM_PROTO , __locale_t locale
+# define LOCALE_PARAM , locale
+# define LOCALE_PARAM_DECL  __locale_t locale;
+# define LOCALE_ARG , locale
+#else
+# define LOCALE_PARAM_PROTO
+# define LOCALE_PARAM
+# define LOCALE_PARAM_DECL
+# define LOCALE_ARG
 #endif
 
 /* Look up MSGID in the DOMAINNAME message catalog of the current
    LC_MESSAGES locale.  */
-char *
-DGETTEXT (domainname, msgid)
+CONST char *
+DGETTEXT (domainname, msgid LOCALE_PARAM)
      const char *domainname;
      const char *msgid;
+     LOCALE_PARAM_DECL
 {
-  return DCGETTEXT (domainname, msgid, LC_MESSAGES);
+  return DCGETTEXT (domainname, msgid, LC_MESSAGES LOCALE_ARG);
 }
 
-#ifdef _LIBC
+#if defined _LIBC && !defined USE_IN_EXTENDED_LOCALE_MODEL
 /* Alias for function name in GNU C Library.  */
 weak_alias (__dgettext, dgettext);
 #endif
--- /dev/null	Tue Sep 23 19:59:22 2003
+++ glibc-20050322/intl/dcngettext_l.c	Mon Mar 28 15:51:28 2005
@@ -0,0 +1,20 @@
+/* Copyright (C) 2005 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.  */
+
+#define USE_IN_EXTENDED_LOCALE_MODEL 1
+#include <dcngettext.c>
--- glibc-20050322/intl/dcngettext.c.bak	Mon Dec 16 12:45:53 2002
+++ glibc-20050322/intl/dcngettext.c	Mon Mar 28 18:14:52 2005
@@ -1,5 +1,5 @@
 /* Implementation of the dcngettext(3) function.
-   Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1995-1999, 2000, 2001, 2002, 2005 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
@@ -35,27 +35,57 @@
    code is also used in GNU C Library where the names have a __
    prefix.  So we have to make a difference here.  */
 #ifdef _LIBC
-# define DCNGETTEXT __dcngettext
+# ifdef USE_IN_EXTENDED_LOCALE_MODEL
+/* We use this code also for the extended locale handling where the
+   function gets as an additional argument the locale which has to be
+   used.  */
+#  define DCNGETTEXT __dcngettext_l
+#  define CONST const
+#  define LOCALE_PARAM_PROTO , __locale_t locale
+#  define LOCALE_PARAM , locale
+#  define LOCALE_PARAM_DECL  __locale_t locale;
+# else
+#  define DCNGETTEXT __dcngettext
+#  define CONST
+#  define LOCALE_PARAM_PROTO
+#  define LOCALE_PARAM
+#  define LOCALE_PARAM_DECL
+#  include "../locale/localeinfo.h"
+# endif
 # define DCIGETTEXT __dcigettext
+# define LOCALE_ARG , locale
 #else
 # define DCNGETTEXT libintl_dcngettext
+# define CONST
+# define LOCALE_PARAM_PROTO
+# define LOCALE_PARAM
+# define LOCALE_PARAM_DECL
 # define DCIGETTEXT libintl_dcigettext
+# define LOCALE_ARG
 #endif
 
 /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
    locale.  */
-char *
-DCNGETTEXT (domainname, msgid1, msgid2, n, category)
+CONST char *
+DCNGETTEXT (domainname, msgid1, msgid2, n, category LOCALE_PARAM)
      const char *domainname;
      const char *msgid1;
      const char *msgid2;
      unsigned long int n;
      int category;
+     LOCALE_PARAM_DECL
 {
-  return DCIGETTEXT (domainname, msgid1, msgid2, 1, n, category);
+#if defined _LIBC && !defined USE_IN_EXTENDED_LOCALE_MODEL
+  __locale_t locale = _NL_CURRENT_LOCALE;
+#endif
+  return DCIGETTEXT (domainname, msgid1, msgid2, 1, n, category LOCALE_ARG);
 }
 
 #ifdef _LIBC
 /* Alias for function name in GNU C Library.  */
+# ifdef USE_IN_EXTENDED_LOCALE_MODEL
+weak_alias (__dcngettext_l, dcngettext_l);
+# else
 weak_alias (__dcngettext, dcngettext);
+# endif
 #endif
--- /dev/null	Tue Sep 23 19:59:22 2003
+++ glibc-20050322/intl/dngettext_l.c	Mon Mar 28 15:51:28 2005
@@ -0,0 +1,20 @@
+/* Copyright (C) 2005 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.  */
+
+#define USE_IN_EXTENDED_LOCALE_MODEL 1
+#include <dngettext.c>
--- glibc-20050322/intl/dngettext.c.bak	Mon Dec 16 12:45:53 2002
+++ glibc-20050322/intl/dngettext.c	Mon Mar 28 18:14:52 2005
@@ -1,5 +1,5 @@
 /* Implementation of the dngettext(3) function.
-   Copyright (C) 1995-1997, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1995-1997, 2000, 2001, 2002, 2005 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
@@ -37,26 +37,51 @@
    code is also used in GNU C Library where the names have a __
    prefix.  So we have to make a difference here.  */
 #ifdef _LIBC
-# define DNGETTEXT __dngettext
-# define DCNGETTEXT __dcngettext
+# ifdef USE_IN_EXTENDED_LOCALE_MODEL
+#  define DNGETTEXT dngettext_l
+#  define DCNGETTEXT __dcngettext_l
+#  undef dngettext_l
+#  define CONST const
+# else
+#  define DNGETTEXT __dngettext
+#  define DCNGETTEXT __dcngettext
+#  define CONST
+# endif
 #else
 # define DNGETTEXT libintl_dngettext
 # define DCNGETTEXT libintl_dcngettext
+# define CONST
+#endif
+
+#ifdef USE_IN_EXTENDED_LOCALE_MODEL
+/* We use this code also for the extended locale handling where the
+   function gets as an additional argument the locale which has to be
+   used.  */
+# define LOCALE_PARAM_PROTO , __locale_t locale
+# define LOCALE_PARAM , locale
+# define LOCALE_PARAM_DECL  __locale_t locale;
+# define LOCALE_ARG , locale
+#else
+# define LOCALE_PARAM_PROTO
+# define LOCALE_PARAM
+# define LOCALE_PARAM_DECL
+# define LOCALE_ARG
 #endif
 
 /* Look up MSGID in the DOMAINNAME message catalog of the current
    LC_MESSAGES locale and skip message according to the plural form.  */
-char *
-DNGETTEXT (domainname, msgid1, msgid2, n)
+CONST char *
+DNGETTEXT (domainname, msgid1, msgid2, n LOCALE_PARAM)
      const char *domainname;
      const char *msgid1;
      const char *msgid2;
      unsigned long int n;
+     LOCALE_PARAM_DECL
 {
-  return DCNGETTEXT (domainname, msgid1, msgid2, n, LC_MESSAGES);
+  return DCNGETTEXT (domainname, msgid1, msgid2, n, LC_MESSAGES LOCALE_ARG);
 }
 
-#ifdef _LIBC
+#if defined _LIBC && !defined USE_IN_EXTENDED_LOCALE_MODEL
 /* Alias for function name in GNU C Library.  */
 weak_alias (__dngettext, dngettext);
 #endif
--- glibc-20050322/intl/libintl.h.bak	Wed Jul 21 19:52:01 2004
+++ glibc-20050322/intl/libintl.h	Mon Mar 28 18:09:38 2005
@@ -1,5 +1,5 @@
 /* Message catalogs for internationalization.
-   Copyright (C) 1995-1999, 2000-2002, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1995-1999, 2000-2002, 2004-2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    This file is derived from the file libgettext.h in the GNU gettext package.
 
@@ -75,6 +75,49 @@
      __THROW __attribute_format_arg__ (2) __attribute_format_arg__ (3);
 
 
+#ifdef __USE_GNU
+
+/* This interface is for the extended locale model.  The __locale_t type
+   can be accessed as locale_t once <locale.h> has been included.  See
+   <locale.h> for more information.  */
+
+/* Get locale datatype definition.  */
+# include <xlocale.h>
+
+/* Look up MSGID in the DOMAINNAME message catalog for the LC_MESSAGES facet
+   of LOCALE.  */
+extern const char *dgettext_l (__const char *__domainname,
+			       __const char *__msgid,
+			       __locale_t __locale)
+     __THROW __attribute_format_arg__ (2);
+
+/* Look up MSGID in the DOMAINNAME message catalog for the CATEGORY facet
+   of LOCALE.  */
+extern const char *dcgettext_l (__const char *__domainname,
+				__const char *__msgid,
+				int __category, __locale_t __locale)
+     __THROW __attribute_format_arg__ (2);
+
+
+/* Similar to 'dgettext_l' but select the plural form corresponding to the
+   number N.  */
+extern const char *dngettext_l (__const char *__domainname,
+				__const char *__msgid1,
+				__const char *__msgid2, unsigned long int __n,
+				__locale_t __locale)
+     __THROW __attribute_format_arg__ (2) __attribute_format_arg__ (3);
+
+/* Similar to 'dcgettext_l' but select the plural form corresponding to the
+   number N.  */
+extern const char *dcngettext_l (__const char *__domainname,
+				 __const char *__msgid1,
+				 __const char *__msgid2, unsigned long int __n,
+				 int __category, __locale_t __locale)
+     __THROW __attribute_format_arg__ (2) __attribute_format_arg__ (3);
+
+#endif
+
+
 /* Set the current default message catalog to DOMAINNAME.
    If DOMAINNAME is null, return the current default.
    If DOMAINNAME is "", reset to the default of "messages".  */
@@ -115,6 +158,16 @@
 # define dngettext(domainname, msgid1, msgid2, n) \
   dcngettext (domainname, msgid1, msgid2, n, LC_MESSAGES)
 
+# ifdef __USE_GNU
+
+#  define dgettext_l(domainname, msgid, locale) \
+  dcgettext_l (domainname, msgid, LC_MESSAGES, locale)
+
+#  define dngettext_l(domainname, msgid1, msgid2, n, locale) \
+  dcngettext_l (domainname, msgid1, msgid2, n, LC_MESSAGES, locale)
+
+# endif
+
 #endif	/* Optimizing.  */
 
 __END_DECLS
--- glibc-20050322/include/libintl.h.bak	Tue Feb 22 22:16:39 2005
+++ glibc-20050322/include/libintl.h	Mon Mar 28 18:07:51 2005
@@ -34,6 +34,18 @@
      __attribute_format_arg__ (2) __attribute_format_arg__ (3)
      attribute_hidden;
 
+extern const char *__dcgettext_l (__const char *__domainname,
+				  __const char *__msgid,
+				  int __category, __locale_t __locale)
+     __THROW __attribute_format_arg__ (2);
+
+extern const char *__dcngettext_l (__const char *__domainname,
+				   __const char *__msgid1,
+				   __const char *__msgid2,
+				   unsigned long int __n,
+				   int __category, __locale_t __locale)
+     __THROW __attribute_format_arg__ (2) __attribute_format_arg__ (3);
+
 extern char *__textdomain (__const char *__domainname);
 extern char *__bindtextdomain (__const char *__domainname,
 			       __const char *__dirname);
--- glibc-20050322/intl/Makefile.bak3	Mon Mar 28 04:14:44 2005
+++ glibc-20050322/intl/Makefile	Mon Mar 28 16:49:36 2005
@@ -20,8 +20,8 @@
 
 subdir = intl
 headers = libintl.h
-routines = bindtextdom dcgettext dgettext gettext	\
-	   dcigettext dcngettext dngettext ngettext \
+routines = bindtextdom dcgettext dcgettext_l dgettext dgettext_l gettext \
+	   dcigettext dcngettext dcngettext_l dngettext dngettext_l ngettext \
 	   finddomain loadmsgcat localealias textdomain
 aux =	   l10nflist explodename plural plural-exp hash-string
 distribute = gmo.h gettextP.h hash-string.h loadinfo.h locale.alias \


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]