mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-08 14:20:07 +00:00
6d24885784
This patch merges the latest release of gettext into the intl subdirectory. The initial motivation was to include the plural.y changes which enable building with bison 3.0, but the majority of the other changes are merely cosmetic so it seemed like merging the whole directory was simpler than trying to take it piecemeal. The merge was done by copying across the latext gettext code and adding in a few small glibc changes that have been added over the years that seemed beneficial, as well as a couple of small build fixes that should be merged back to gettext. I also reverted the gettext commit: commit 279b57fc367251666f00e8e2b599b83703451afb Author: Bruno Haible <bruno@clisp.org> Date: Fri Jun 14 12:03:49 2002 +0000 Make absolute pathnames inside $LANGUAGE work. As it caused localedata/tst-setlocale3 to fail and it wasn't clear that glibc wanted that behaviour. The merge has dropped many uses of __glibc_likely/unlikely. This is intentional given that it eases merging. It seems to me that the cost of continually rewriting these lines when merging and the risk of adding bugs when doing so outweighs the benefits of using these macros when code is shared with another project. Tested with make check on x86_64. ChangeLog: 2014-12-11 Will Newton <will.newton@linaro.org> Merge gettext 0.19.3 into intl/. This involves a number of cosmetic changes to comments and ANSI function definitions and prototypes throughout all the files. The gettext copyright header is used but with the date ranges taken from the glibc copy. * NEWS: Add gettext merge to 2.21. * intl/bindtextdom.c: Switch to gettext copyright. Use ANSI definitions and prototypes. Use gl_* locking primitives rather than __libc_* ones. Use __builtin_expect rather than __glibc_likely/unlikely. * intl/dcgettext.c: Switch to gettext copyright. Use ANSI definitions and prototypes. * intl/dcigettext.c: Switch to gettext copyright. Use ANSI definitions and prototypes. (INTDIV0_RAISES_SIGFPE): New define. Use gl_* locking primitives rather than __libc_* ones. Include eval-plural.h instead of plural-eval.c. Use __builtin_expect rather than __glibc_likely/unlikely. * intl/dcngettext.c: Switch to gettext copyright. Use ANSI definitions and prototypes. * intl/dgettext.c: Likewise. * intl/dngettext.c: Likewise. * intl/plural-eval.c: Renamed to... * intl/eval-plural.h: ...this. * intl/explodename.c: Switch to gettext copyright. Use ANSI definitions and prototypes. (_nl_explode_name): Use strchr instead of __rawmemchr. * intl/finddomain.c: Switch to gettext copyright. Use ANSI definitions and prototypes. Use gl_* locking primitives rather than __libc_* ones. (_nl_find_domain): Use malloc rather than alloca for allocation of temporary locale name. * intl/gettext.c: Switch to gettext copyright. Use ANSI definitions and prototypes. * intl/gettextP.h: Switch to gettext copyright. Use ANSI definitions and prototypes. Use gl_* locking primitives rather than __libc_* ones. * intl/gmo.h: Switch to gettext copyright. (struct sysdep_string): Move struct segment_pair outside of struct definition. * intl/hash-string.c: Use ANSI definitions and prototypes. * intl/hash-string.h: Switch to gettext copyright. Use ANSI definitions and prototypes. * intl/l10nflist.c: Switch to gettext copyright. Use ANSI definitions and prototypes. (_nl_normalize_codeset): Avoid integer overflow. * intl/loadinfo.h: Switch to gettext copyright. Use ANSI definitions and prototypes. (LIBINTL_DLL_EXPORTED): New define. (PATH_SEPARATOR): New define. * intl/loadmsgcat.c: Switch to gettext copyright. * intl/localealias.c: Switch to gettext copyright. Use ANSI definitions and prototypes. (_nl_expand_alias): Use PATH_SEPARATOR. * intl/ngettext.c: Switch to gettext copyright. Use ANSI definitions and prototypes. * intl/plural-exp.c: Likewise. * intl/plural-exp.h: Switch to gettext copyright. Use ANSI definitions and prototypes. (struct expression): Move definition of enum operator outside of struct definition. * intl/plural.c: Regenerate. * intl/plural.y: Switch to gettext copyright. Use ANSI definitions and prototypes. Port to bison 3.0. * intl/textdomain.c: Switch to gettext copyright. Use ANSI definitions and prototypes. Use gl_* locking primitives rather than __libc_* ones.
358 lines
9.0 KiB
C
358 lines
9.0 KiB
C
/* Copyright (C) 1995-2014 Free Software Foundation, Inc.
|
||
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
|
||
|
||
This program 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.
|
||
|
||
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||
|
||
/* Tell glibc's <string.h> to provide a prototype for stpcpy().
|
||
This must come before <config.h> because <config.h> may include
|
||
<features.h>, and once <features.h> has been included, it's too late. */
|
||
#ifndef _GNU_SOURCE
|
||
# define _GNU_SOURCE 1
|
||
#endif
|
||
|
||
#ifdef HAVE_CONFIG_H
|
||
# include <config.h>
|
||
#endif
|
||
|
||
#include <string.h>
|
||
|
||
#if defined _LIBC || defined HAVE_ARGZ_H
|
||
# include <argz.h>
|
||
#endif
|
||
#include <ctype.h>
|
||
#include <sys/types.h>
|
||
#include <stdlib.h>
|
||
|
||
#include "loadinfo.h"
|
||
|
||
/* On some strange systems still no definition of NULL is found. Sigh! */
|
||
#ifndef NULL
|
||
# if defined __STDC__ && __STDC__
|
||
# define NULL ((void *) 0)
|
||
# else
|
||
# define NULL 0
|
||
# endif
|
||
#endif
|
||
|
||
/* @@ end of prolog @@ */
|
||
|
||
#ifdef _LIBC
|
||
/* Rename the non ANSI C functions. This is required by the standard
|
||
because some ANSI C functions will require linking with this object
|
||
file and the name space must not be polluted. */
|
||
# ifndef stpcpy
|
||
# define stpcpy(dest, src) __stpcpy(dest, src)
|
||
# endif
|
||
#else
|
||
# ifndef HAVE_STPCPY
|
||
static char *stpcpy (char *dest, const char *src);
|
||
# endif
|
||
#endif
|
||
|
||
/* Define function which are usually not available. */
|
||
|
||
#if defined HAVE_ARGZ_COUNT
|
||
# undef __argz_count
|
||
# define __argz_count argz_count
|
||
#else
|
||
/* Returns the number of strings in ARGZ. */
|
||
static size_t
|
||
argz_count__ (const char *argz, size_t len)
|
||
{
|
||
size_t count = 0;
|
||
while (len > 0)
|
||
{
|
||
size_t part_len = strlen (argz);
|
||
argz += part_len + 1;
|
||
len -= part_len + 1;
|
||
count++;
|
||
}
|
||
return count;
|
||
}
|
||
# undef __argz_count
|
||
# define __argz_count(argz, len) argz_count__ (argz, len)
|
||
#endif /* !_LIBC && !HAVE_ARGZ_COUNT */
|
||
|
||
#if defined HAVE_ARGZ_STRINGIFY
|
||
# undef __argz_stringify
|
||
# define __argz_stringify argz_stringify
|
||
#else
|
||
/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
|
||
except the last into the character SEP. */
|
||
static void
|
||
argz_stringify__ (char *argz, size_t len, int sep)
|
||
{
|
||
while (len > 0)
|
||
{
|
||
size_t part_len = strlen (argz);
|
||
argz += part_len;
|
||
len -= part_len + 1;
|
||
if (len > 0)
|
||
*argz++ = sep;
|
||
}
|
||
}
|
||
# undef __argz_stringify
|
||
# define __argz_stringify(argz, len, sep) argz_stringify__ (argz, len, sep)
|
||
#endif /* !_LIBC && !HAVE_ARGZ_STRINGIFY */
|
||
|
||
#ifdef _LIBC
|
||
#elif defined HAVE_ARGZ_NEXT
|
||
# undef __argz_next
|
||
# define __argz_next argz_next
|
||
#else
|
||
static char *
|
||
argz_next__ (char *argz, size_t argz_len, const char *entry)
|
||
{
|
||
if (entry)
|
||
{
|
||
if (entry < argz + argz_len)
|
||
entry = strchr (entry, '\0') + 1;
|
||
|
||
return entry >= argz + argz_len ? NULL : (char *) entry;
|
||
}
|
||
else
|
||
if (argz_len > 0)
|
||
return argz;
|
||
else
|
||
return 0;
|
||
}
|
||
# undef __argz_next
|
||
# define __argz_next(argz, len, entry) argz_next__ (argz, len, entry)
|
||
#endif /* !_LIBC && !HAVE_ARGZ_NEXT */
|
||
|
||
/* Return number of bits set in X. */
|
||
#ifndef ARCH_POP
|
||
static inline int
|
||
pop (int x)
|
||
{
|
||
/* We assume that no more than 16 bits are used. */
|
||
x = ((x & ~0x5555) >> 1) + (x & 0x5555);
|
||
x = ((x & ~0x3333) >> 2) + (x & 0x3333);
|
||
x = ((x >> 4) + x) & 0x0f0f;
|
||
x = ((x >> 8) + x) & 0xff;
|
||
|
||
return x;
|
||
}
|
||
#endif
|
||
|
||
|
||
struct loaded_l10nfile *
|
||
_nl_make_l10nflist (struct loaded_l10nfile **l10nfile_list,
|
||
const char *dirlist, size_t dirlist_len,
|
||
int mask, const char *language, const char *territory,
|
||
const char *codeset, const char *normalized_codeset,
|
||
const char *modifier,
|
||
const char *filename, int do_allocate)
|
||
{
|
||
char *abs_filename;
|
||
struct loaded_l10nfile *last = NULL;
|
||
struct loaded_l10nfile *retval;
|
||
char *cp;
|
||
size_t entries;
|
||
int cnt;
|
||
|
||
/* Allocate room for the full file name. */
|
||
abs_filename = (char *) malloc (dirlist_len
|
||
+ strlen (language)
|
||
+ ((mask & XPG_TERRITORY) != 0
|
||
? strlen (territory) + 1 : 0)
|
||
+ ((mask & XPG_CODESET) != 0
|
||
? strlen (codeset) + 1 : 0)
|
||
+ ((mask & XPG_NORM_CODESET) != 0
|
||
? strlen (normalized_codeset) + 1 : 0)
|
||
+ ((mask & XPG_MODIFIER) != 0
|
||
? strlen (modifier) + 1 : 0)
|
||
+ 1 + strlen (filename) + 1);
|
||
|
||
if (abs_filename == NULL)
|
||
return NULL;
|
||
|
||
retval = NULL;
|
||
last = NULL;
|
||
|
||
/* Construct file name. */
|
||
memcpy (abs_filename, dirlist, dirlist_len);
|
||
__argz_stringify (abs_filename, dirlist_len, ':');
|
||
cp = abs_filename + (dirlist_len - 1);
|
||
*cp++ = '/';
|
||
cp = stpcpy (cp, language);
|
||
|
||
if ((mask & XPG_TERRITORY) != 0)
|
||
{
|
||
*cp++ = '_';
|
||
cp = stpcpy (cp, territory);
|
||
}
|
||
if ((mask & XPG_CODESET) != 0)
|
||
{
|
||
*cp++ = '.';
|
||
cp = stpcpy (cp, codeset);
|
||
}
|
||
if ((mask & XPG_NORM_CODESET) != 0)
|
||
{
|
||
*cp++ = '.';
|
||
cp = stpcpy (cp, normalized_codeset);
|
||
}
|
||
if ((mask & XPG_MODIFIER) != 0)
|
||
{
|
||
*cp++ = '@';
|
||
cp = stpcpy (cp, modifier);
|
||
}
|
||
|
||
*cp++ = '/';
|
||
stpcpy (cp, filename);
|
||
|
||
/* Look in list of already loaded domains whether it is already
|
||
available. */
|
||
last = NULL;
|
||
for (retval = *l10nfile_list; retval != NULL; retval = retval->next)
|
||
if (retval->filename != NULL)
|
||
{
|
||
int compare = strcmp (retval->filename, abs_filename);
|
||
if (compare == 0)
|
||
/* We found it! */
|
||
break;
|
||
if (compare < 0)
|
||
{
|
||
/* It's not in the list. */
|
||
retval = NULL;
|
||
break;
|
||
}
|
||
|
||
last = retval;
|
||
}
|
||
|
||
if (retval != NULL || do_allocate == 0)
|
||
{
|
||
free (abs_filename);
|
||
return retval;
|
||
}
|
||
|
||
retval = (struct loaded_l10nfile *)
|
||
malloc (sizeof (*retval) + (__argz_count (dirlist, dirlist_len)
|
||
* (1 << pop (mask))
|
||
* sizeof (struct loaded_l10nfile *)));
|
||
if (retval == NULL)
|
||
{
|
||
free (abs_filename);
|
||
return NULL;
|
||
}
|
||
|
||
retval->filename = abs_filename;
|
||
/* If more than one directory is in the list this is a pseudo-entry
|
||
which just references others. We do not try to load data for it,
|
||
ever. */
|
||
retval->decided = (__argz_count (dirlist, dirlist_len) != 1
|
||
|| ((mask & XPG_CODESET) != 0
|
||
&& (mask & XPG_NORM_CODESET) != 0));
|
||
retval->data = NULL;
|
||
|
||
if (last == NULL)
|
||
{
|
||
retval->next = *l10nfile_list;
|
||
*l10nfile_list = retval;
|
||
}
|
||
else
|
||
{
|
||
retval->next = last->next;
|
||
last->next = retval;
|
||
}
|
||
|
||
entries = 0;
|
||
/* If the DIRLIST is a real list the RETVAL entry corresponds not to
|
||
a real file. So we have to use the DIRLIST separation mechanism
|
||
of the inner loop. */
|
||
cnt = __argz_count (dirlist, dirlist_len) == 1 ? mask - 1 : mask;
|
||
for (; cnt >= 0; --cnt)
|
||
if ((cnt & ~mask) == 0)
|
||
{
|
||
/* Iterate over all elements of the DIRLIST. */
|
||
char *dir = NULL;
|
||
|
||
while ((dir = __argz_next ((char *) dirlist, dirlist_len, dir))
|
||
!= NULL)
|
||
retval->successor[entries++]
|
||
= _nl_make_l10nflist (l10nfile_list, dir, strlen (dir) + 1, cnt,
|
||
language, territory, codeset,
|
||
normalized_codeset, modifier, filename, 1);
|
||
}
|
||
retval->successor[entries] = NULL;
|
||
|
||
return retval;
|
||
}
|
||
|
||
/* Normalize codeset name. There is no standard for the codeset
|
||
names. Normalization allows the user to use any of the common
|
||
names. The return value is dynamically allocated and has to be
|
||
freed by the caller. */
|
||
const char *
|
||
_nl_normalize_codeset (const char *codeset, size_t name_len)
|
||
{
|
||
size_t len = 0;
|
||
int only_digit = 1;
|
||
char *retval;
|
||
char *wp;
|
||
size_t cnt;
|
||
#if !IS_IN (libc)
|
||
locale_t locale = newlocale (0, "C", NULL);
|
||
#else
|
||
# define locale _nl_C_locobj_ptr
|
||
#endif
|
||
|
||
for (cnt = 0; cnt < name_len; ++cnt)
|
||
if (__isalnum_l ((unsigned char) codeset[cnt], locale))
|
||
{
|
||
++len;
|
||
|
||
if (! __isdigit_l ((unsigned char) codeset[cnt], locale))
|
||
only_digit = 0;
|
||
}
|
||
|
||
retval = (char *) malloc ((only_digit ? 3 : 0) + len + 1);
|
||
|
||
if (retval != NULL)
|
||
{
|
||
if (only_digit)
|
||
wp = stpcpy (retval, "iso");
|
||
else
|
||
wp = retval;
|
||
|
||
for (cnt = 0; cnt < name_len; ++cnt)
|
||
if (__isalpha_l ((unsigned char) codeset[cnt], locale))
|
||
*wp++ = __tolower_l ((unsigned char) codeset[cnt], locale);
|
||
else if (__isdigit_l ((unsigned char) codeset[cnt], locale))
|
||
*wp++ = codeset[cnt];
|
||
|
||
*wp = '\0';
|
||
}
|
||
|
||
return (const char *) retval;
|
||
}
|
||
|
||
|
||
/* @@ begin of epilog @@ */
|
||
|
||
/* We don't want libintl.a to depend on any other library. So we
|
||
avoid the non-standard function stpcpy. In GNU C Library this
|
||
function is available, though. Also allow the symbol HAVE_STPCPY
|
||
to be defined. */
|
||
#if !_LIBC && !HAVE_STPCPY
|
||
static char *
|
||
stpcpy (char *dest, const char *src)
|
||
{
|
||
while ((*dest++ = *src++) != '\0')
|
||
/* Do nothing. */ ;
|
||
return dest - 1;
|
||
}
|
||
#endif
|