aboutsummaryrefslogtreecommitdiff
path: root/intl/dcigettext.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-11-28 00:09:26 +0000
committerUlrich Drepper <drepper@redhat.com>2001-11-28 00:09:26 +0000
commit0555fccea74d63cce35ca7121688a4a6dce610ca (patch)
tree2b29fafa424bd97c187d21457e3c4c70f73e32cb /intl/dcigettext.c
parent8a2072042b2b77e4e160d8ebcf99cdde370737ab (diff)
downloadglibc-0555fccea74d63cce35ca7121688a4a6dce610ca.tar
glibc-0555fccea74d63cce35ca7121688a4a6dce610ca.tar.gz
glibc-0555fccea74d63cce35ca7121688a4a6dce610ca.tar.bz2
glibc-0555fccea74d63cce35ca7121688a4a6dce610ca.zip
Update.
2001-03-04 Bruno Haible <bruno@clisp.org> * intl/dcigettext.c (DCIGETTEXT): Increment path_max proportionally. 2001-10-31 Bruno Haible <bruno@clisp.org> * intl/plural.y: Include <stddef.h>, needed for NULL with SunOS 4 cc. 2001-03-21 Bruno Haible <bruno@clisp.org> * intl/dcigettext.c (_nl_state_lock): Mark as #ifdef _LIBC. AIX 3 xlc chokes on empty macro arguments. * intl/plural.y: Add #pragma for alloca on AIX 3. 2001-11-27 Ulrich Drepper <drepper@redhat.com> * intl/dcigettext.c (guess_category_value): Only implement for glibc. Otherwise rely on function _nl_locale_name which isn't present in the glibc sources. 2001-09-24 Bruno Haible <bruno@clisp.org> * intl/loadmsgcat.c (_nl_init_domain_conv): Also enable transliteration when building on a glibc system but outside glibc. 2001-09-22 Bruno Haible <bruno@clisp.org> * intl/plural-eval.c: New file, extracted from dcigettext.c. * intl/dcigettext.c (plural_eval): Remove function, moved to intl/plural-eval.c. (plural_lookup): Call PLURAL_EVAL instead of plural_eval. Include plural-eval.c. 2001-09-22 Bruno Haible <bruno@clisp.org> * intl/plural-exp.c (EXTRACT_PLURAL_EXPRESSION): Reject numbers that don't start with a digit; nplurals must be positive. 2001-09-02 Bruno Haible <bruno@clisp.org> * intl/plural-exp.h: New file, extracted from gettextP.h. * intl/plural-exp.c: New file, extracted from loadmsgcat.c. * intl/gettextP.h (struct expression, struct parse_args, __gettext_free_exp, __gettextparse): Move to plural-exp.h. * intl/loadmsgcat.c: Include plural-exp.h. (PLURAL_PARSE): Move macro to plural-exp.h. (plvar, plone, germanic_plural, INIT_GERMANIC_PLURAL): Move to plural-exp.c. (_nl_load_domain): Move plural handling code to plural-exp.c. Call EXTRACT_PLURAL_EXPRESSION. (_nl_unload_domain): Update. * intl/dcigettext.c: Include plural-exp.h. * intl/plural.y: Include plural-exp.h, not gettextP.h. (FREE_EXPRESSION): Move macro to plural-exp.h. * intl/Makefile (routines): Add plural-exp. (distribute): Add plural-exp.h. 2001-07-28 Bruno Haible <bruno@clisp.org> * intl/l10nflist.c (_nl_normalize_codeset): Cast isalnum, isalpha, isdigit, tolower argument to 'unsigned char'. * intl/loadmsgcat.c (_nl_load_domain): Cast isspace argument to 'unsigned char'. * intl/localealias.c (read_alias_file): Cast isspace argument to 'unsigned char'. 2001-10-20 Bruno Haible <bruno@clisp.org> Assume strchr() exists. (Without it, intl/explodename.c wouldn't link anyway.) * intl/dcigettext.c (strchr): Remove fallback definition; it conflicts with the variable 'index' in plural_lookup. * intl/l10nflist.c (strchr): Likewise. * intl/localealias.c (strchr): Likewise. Assume <stddef.h>, <stdlib.h>, <string.h>, <locale.h> exist. * intl/bindtextdom.c: Likewise. * intl/dcigettext.c: Likewise. * intl/dgettext.c: Likewise. * intl/dngettext.c: Likewise. * intl/explodename.c: Likewise. * intl/finddomain.c: Likewise. * intl/gettext.c: Likewise. * intl/l10nflist.c: Likewise. * intl/loadmsgcat.c: Likewise. * intl/localealias.c: Likewise. * intl/ngettext.c: Likewise. * intl/textdomain.c: Likewise. * intl/gettext.h: Assume <limits.h> exists.
Diffstat (limited to 'intl/dcigettext.c')
-rw-r--r--intl/dcigettext.c166
1 files changed, 22 insertions, 144 deletions
diff --git a/intl/dcigettext.c b/intl/dcigettext.c
index d5208e41f8..f274de81d8 100644
--- a/intl/dcigettext.c
+++ b/intl/dcigettext.c
@@ -30,11 +30,11 @@
#include <sys/types.h>
-#if defined __GNUC__ && !defined C_ALLOCA
+#ifdef __GNUC__
# define alloca __builtin_alloca
# define HAVE_ALLOCA 1
#else
-# if (defined HAVE_ALLOCA_H || defined _LIBC) && !defined C_ALLOCA
+# if defined HAVE_ALLOCA_H || defined _LIBC
# include <alloca.h>
# else
# ifdef _AIX
@@ -55,42 +55,22 @@ extern int errno;
# define __set_errno(val) errno = (val)
#endif
-#if defined STDC_HEADERS || defined _LIBC
-# include <stddef.h>
-# include <stdlib.h>
-#else
-char *getenv ();
-# ifdef HAVE_MALLOC_H
-# include <malloc.h>
-# else
-void free ();
-# endif
-#endif
-
-#if defined HAVE_STRING_H || defined _LIBC
-# include <string.h>
-#else
-# include <strings.h>
-#endif
-#if !HAVE_STRCHR && !defined _LIBC
-# ifndef strchr
-# define strchr index
-# endif
-#endif
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
#if defined HAVE_UNISTD_H || defined _LIBC
# include <unistd.h>
#endif
-#if defined HAVE_LOCALE_H || defined _LIBC
-# include <locale.h>
-#endif
+#include <locale.h>
#if defined HAVE_SYS_PARAM_H || defined _LIBC
# include <sys/param.h>
#endif
#include "gettextP.h"
+#include "plural-exp.h"
#ifdef _LIBC
# include <libintl.h>
#else
@@ -192,16 +172,6 @@ static void *mempcpy PARAMS ((void *dest, const void *src, size_t n));
# 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
@@ -286,9 +256,6 @@ static char *plural_lookup PARAMS ((struct loaded_l10nfile *domain,
const char *translation,
size_t translation_len))
internal_function;
-static unsigned long int plural_eval PARAMS ((struct expression *pexp,
- unsigned long int n))
- internal_function;
static const char *category_to_name PARAMS ((int category)) internal_function;
static const char *guess_category_value PARAMS ((int category,
const char *categoryname))
@@ -355,7 +322,9 @@ typedef unsigned char transmem_block_t;
#endif
/* Lock variable to protect the global data in the gettext implementation. */
+#ifdef _LIBC
__libc_rwlock_define_initialized (, _nl_state_lock)
+#endif
/* Checking whether the binaries runs SUID must be done and glibc provides
easier methods therefore we make a difference here. */
@@ -375,6 +344,9 @@ static int enable_secure;
}
#endif
+/* Get the function to evaluate the plural expression. */
+#include "plural-eval.c"
+
/* Look up MSGID in the DOMAINNAME message catalog for the current
CATEGORY locale and, if PLURAL is nonzero, search over string
depending on the plural form determined by N. */
@@ -479,16 +451,18 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category)
path_max = (unsigned int) PATH_MAX;
path_max += 2; /* The getcwd docs say to do this. */
- dirname = (char *) alloca (path_max + dirname_len);
- ADD_BLOCK (block_list, dirname);
-
- __set_errno (0);
- while ((ret = getcwd (dirname, path_max)) == NULL && errno == ERANGE)
+ for (;;)
{
- path_max += PATH_INCR;
dirname = (char *) alloca (path_max + dirname_len);
ADD_BLOCK (block_list, dirname);
+
__set_errno (0);
+ ret = getcwd (dirname, path_max);
+ if (ret != NULL || errno != ERANGE)
+ break;
+
+ path_max += path_max / 2;
+ path_max += PATH_INCR;
}
if (ret == NULL)
@@ -983,87 +957,6 @@ plural_lookup (domain, n, translation, translation_len)
}
-/* Function to evaluate the plural expression and return an index value. */
-static unsigned long int
-internal_function
-plural_eval (pexp, n)
- struct expression *pexp;
- unsigned long int n;
-{
- switch (pexp->nargs)
- {
- case 0:
- switch (pexp->operation)
- {
- case var:
- return n;
- case num:
- return pexp->val.num;
- default:
- break;
- }
- /* NOTREACHED */
- break;
- case 1:
- {
- /* pexp->operation must be lnot. */
- unsigned long int arg = plural_eval (pexp->val.args[0], n);
- return ! arg;
- }
- case 2:
- {
- unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
- if (pexp->operation == lor)
- return leftarg || plural_eval (pexp->val.args[1], n);
- else if (pexp->operation == land)
- return leftarg && plural_eval (pexp->val.args[1], n);
- else
- {
- unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
-
- switch (pexp->operation)
- {
- case mult:
- return leftarg * rightarg;
- case divide:
- return leftarg / rightarg;
- case module:
- return leftarg % rightarg;
- case plus:
- return leftarg + rightarg;
- case minus:
- return leftarg - rightarg;
- case less_than:
- return leftarg < rightarg;
- case greater_than:
- return leftarg > rightarg;
- case less_or_equal:
- return leftarg <= rightarg;
- case greater_or_equal:
- return leftarg >= rightarg;
- case equal:
- return leftarg == rightarg;
- case not_equal:
- return leftarg != rightarg;
- default:
- break;
- }
- }
- /* NOTREACHED */
- break;
- }
- case 3:
- {
- /* pexp->operation must be qmop. */
- unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
- return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
- }
- }
- /* NOTREACHED */
- return 0;
-}
-
-
/* Return string representation of locale CATEGORY. */
static const char *
internal_function
@@ -1144,25 +1037,10 @@ guess_category_value (category, categoryname)
/* 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)
+#ifdef _LIBC
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";
- }
- }
+ retval = _nl_locale_name (category, categoryname);
#endif
return language != NULL && strcmp (retval, "C") != 0 ? language : retval;