/* Implementation of the internal dcigettext function.
- Copyright (C) 1995-1999, 2000-2002 Free Software Foundation, Inc.
+ Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA. */
/* Tell glibc's <string.h> to provide a prototype for mempcpy().
# define alloca __builtin_alloca
# define HAVE_ALLOCA 1
#else
-# if defined HAVE_ALLOCA_H || defined _LIBC
-# include <alloca.h>
+# ifdef _MSC_VER
+# include <malloc.h>
+# define alloca _alloca
# else
-# ifdef _AIX
- #pragma alloca
+# if defined HAVE_ALLOCA_H || defined _LIBC
+# include <alloca.h>
# else
-# ifndef alloca
+# ifdef _AIX
+ #pragma alloca
+# else
+# ifndef alloca
char *alloca ();
+# endif
# endif
# endif
# endif
char *getwd ();
# define getcwd(buf, max) getwd (buf)
# else
+# if VMS
+# define getcwd(buf, max) (getcwd) (buf, max, 0)
+# else
char *getcwd ();
+# endif
# endif
# ifndef HAVE_STPCPY
-static char *stpcpy PARAMS ((char *dest, const char *src));
+#define stpcpy(dest, src) my_stpcpy(dest, src)
+static char *stpcpy (char *dest, const char *src);
# endif
# ifndef HAVE_MEMPCPY
-static void *mempcpy PARAMS ((void *dest, const void *src, size_t n));
+static void *mempcpy (void *dest, const void *src, size_t n);
# endif
#endif
# endif
/* Function to compare two entries in the table of known translations. */
-static int transcmp PARAMS ((const void *p1, const void *p2));
static int
-transcmp (p1, p2)
- const void *p1;
- const void *p2;
+transcmp (const void *p1, const void *p2)
{
const struct known_translation_t *s1;
const struct known_translation_t *s2;
}
#endif
+#ifndef INTVARDEF
+# define INTVARDEF(name)
+#endif
+#ifndef INTUSE
+# define INTUSE(name) name
+#endif
+
/* Name of the default domain used for gettext(3) prior any call to
textdomain(3). The default value for this is "messages". */
const char _nl_default_default_domain[] attribute_hidden = "messages";
extern const char _nl_default_dirname[];
#else
const char _nl_default_dirname[] = LOCALEDIR;
+INTVARDEF (_nl_default_dirname)
#endif
/* List with bindings of specific domains created by bindtextdomain()
struct binding *_nl_domain_bindings;
/* Prototypes for local functions. */
-static char *plural_lookup PARAMS ((struct loaded_l10nfile *domain,
- unsigned long int n,
- const char *translation,
- size_t translation_len))
+static char *plural_lookup (struct loaded_l10nfile *domain,
+ unsigned long int n,
+ const char *translation, size_t translation_len)
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))
+static const char *guess_category_value (int category,
+ const char *categoryname)
internal_function;
+#ifdef _LIBC
+# include "../locale/localeinfo.h"
+# define category_to_name(category) _nl_category_names[category]
+#else
+static const char *category_to_name (int category) internal_function;
+#endif
/* For those loosing systems which don't have `alloca' we have to add
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)
- const char *domainname;
- const char *msgid1;
- const char *msgid2;
- int plural;
- unsigned long int n;
- int category;
+DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2,
+ int plural, unsigned long int n, int category)
{
#ifndef HAVE_ALLOCA
struct block_list *block_list = NULL;
if (msgid1 == NULL)
return NULL;
+#ifdef _LIBC
+ if (category < 0 || category >= __LC_LAST || category == LC_ALL)
+ /* Bogus. */
+ return (plural == 0
+ ? (char *) msgid1
+ /* Use the Germanic plural rule. */
+ : n == 1 ? (char *) msgid1 : (char *) msgid2);
+#endif
+
__libc_rwlock_rdlock (_nl_state_lock);
/* If DOMAINNAME is NULL, we are interested in the default domain. If
}
if (binding == NULL)
- dirname = (char *) _nl_default_dirname;
+ dirname = (char *) INTUSE(_nl_default_dirname);
else if (IS_ABSOLUTE_PATH (binding->dirname))
dirname = binding->dirname;
else
}
if (ret == NULL)
- {
- /* We cannot get the current working directory. Don't signal an
- error but simply return the default string. */
- FREE_BLOCKS (block_list);
- __libc_rwlock_unlock (_nl_state_lock);
- __set_errno (saved_errno);
- return (plural == 0
- ? (char *) msgid1
- /* Use the Germanic plural rule. */
- : n == 1 ? (char *) msgid1 : (char *) msgid2);
- }
+ /* We cannot get the current working directory. Don't signal an
+ error but simply return the default string. */
+ goto return_untranslated;
stpcpy (stpcpy (strchr (dirname, '\0'), "/"), binding->dirname);
}
/* When this is a SUID binary we must not allow accessing files
outside the dedicated directories. */
if (ENABLE_SECURE && IS_PATH_WITH_DIR (single_locale))
- /* Ingore this entry. */
+ /* Ignore this entry. */
continue;
}
domain. Return the MSGID. */
if (strcmp (single_locale, "C") == 0
|| strcmp (single_locale, "POSIX") == 0)
- {
- FREE_BLOCKS (block_list);
- __libc_rwlock_unlock (_nl_state_lock);
- __set_errno (saved_errno);
- return (plural == 0
- ? (char *) msgid1
- /* Use the Germanic plural rule. */
- : n == 1 ? (char *) msgid1 : (char *) msgid2);
- }
-
+ break;
/* Find structure describing the message catalog matching the
DOMAINNAME and CATEGORY. */
/* Found the translation of MSGID1 in domain DOMAIN:
starting at RETVAL, RETLEN bytes. */
FREE_BLOCKS (block_list);
- __set_errno (saved_errno);
#if defined HAVE_TSEARCH || defined _LIBC
if (foundp == NULL)
{
(*foundp)->translation_length = retlen;
}
#endif
+ __set_errno (saved_errno);
+
/* Now deal with plural. */
if (plural)
retval = plural_lookup (domain, n, retval, retlen);
}
}
}
- /* NOTREACHED */
+
+ return_untranslated:
+ /* Return the untranslated MSGID. */
+ FREE_BLOCKS (block_list);
+ __libc_rwlock_unlock (_nl_state_lock);
+#if 0 /* Doesn't work with diet libc -- TYT */
+#ifndef _LIBC
+ if (!ENABLE_SECURE)
+ {
+ extern void _nl_log_untranslated (const char *logfilename,
+ const char *domainname,
+ const char *msgid1, const char *msgid2,
+ int plural);
+ const char *logfilename = getenv ("GETTEXT_LOG_UNTRANSLATED");
+
+ if (logfilename != NULL && logfilename[0] != '\0')
+ _nl_log_untranslated (logfilename, domainname, msgid1, msgid2, plural);
+ }
+#endif
+#endif
+ __set_errno (saved_errno);
+ return (plural == 0
+ ? (char *) msgid1
+ /* Use the Germanic plural rule. */
+ : n == 1 ? (char *) msgid1 : (char *) msgid2);
}
char *
internal_function
-_nl_find_msg (domain_file, domainbinding, msgid, lengthp)
- struct loaded_l10nfile *domain_file;
- struct binding *domainbinding;
- const char *msgid;
- size_t *lengthp;
+_nl_find_msg (struct loaded_l10nfile *domain_file,
+ struct binding *domainbinding, const char *msgid,
+ size_t *lengthp)
{
struct loaded_domain *domain;
nls_uint32 nstrings;
/* Look up a plural variant. */
static char *
internal_function
-plural_lookup (domain, n, translation, translation_len)
- struct loaded_l10nfile *domain;
- unsigned long int n;
- const char *translation;
- size_t translation_len;
+plural_lookup (struct loaded_l10nfile *domain, unsigned long int n,
+ const char *translation, size_t translation_len)
{
struct loaded_domain *domaindata = (struct loaded_domain *) domain->data;
unsigned long int index;
return (char *) p;
}
-
+#ifndef _LIBC
/* Return string representation of locale CATEGORY. */
static const char *
internal_function
-category_to_name (category)
- int category;
+category_to_name (int category)
{
const char *retval;
return retval;
}
+#endif
/* Guess value of current locale from value of the environment variables. */
static const char *
internal_function
-guess_category_value (category, categoryname)
- int category;
- const char *categoryname;
+guess_category_value (int category, const char *categoryname)
{
const char *language;
const char *retval;
`LC_xxx', and `LANG'. On some systems this can be done by the
`setlocale' function itself. */
#ifdef _LIBC
- retval = setlocale (category, NULL);
+ retval = __current_locale_name (category);
#else
retval = _nl_locale_name (category, categoryname);
#endif
to be defined. */
#if !_LIBC && !HAVE_STPCPY
static char *
-stpcpy (dest, src)
- char *dest;
- const char *src;
+stpcpy (char *dest, const char *src)
{
while ((*dest++ = *src++) != '\0')
/* Do nothing. */ ;
#if !_LIBC && !HAVE_MEMPCPY
static void *
-mempcpy (dest, src, n)
- void *dest;
- const void *src;
- size_t n;
+mempcpy (void *dest, const void *src, size_t n)
{
return (void *) ((char *) memcpy (dest, src, n) + n);
}
#ifdef _LIBC
/* If we want to free all resources we have to do some work at
program's end. */
-static void __attribute__ ((unused))
-free_mem (void)
+libc_freeres_fn (free_mem)
{
void *old;
{
struct binding *oldp = _nl_domain_bindings;
_nl_domain_bindings = _nl_domain_bindings->next;
- if (oldp->dirname != _nl_default_dirname)
+ if (oldp->dirname != INTUSE(_nl_default_dirname))
/* Yes, this is a pointer comparison. */
free (oldp->dirname);
free (oldp->codeset);
free (old);
}
}
-
-text_set_element (__libc_subfreeres, free_mem);
#endif