Import locale tools and ressource files

This commit requires special steps, please checkout docs/UPDATING.

Tools:
 - gencat
 - locale
 - mkcsmapper
 - mkesdb
 - mklocale

Libs:
 - i18n_module
 - libintl

Ressources:
 - i18n
 - locale

Change-Id: I559d0399d8e98bcee15225cab786e43f31506207
This commit is contained in:
2016-06-20 18:30:51 +02:00
parent 733a844ac6
commit 36dcc4a4a9
1369 changed files with 623024 additions and 9 deletions

View File

@@ -73,12 +73,12 @@ SUBDIR+= ../minix/lib/libmagicrt
# below will depend on versions from DESTDIR only.
#
#SUBDIR+= i18n_module
SUBDIR+= i18n_module
SUBDIR+= \
libbz2 \
libcrypt \
libkvm libm \
libintl libkvm libm \
libpci libprop \
libpuffs librmt \
libterminfo \

View File

@@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.2 2006/11/22 23:38:27 tnozaki Exp $
SRCS= citrus_big5.c citrus_prop.c
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2007/04/01 18:52:31 tnozaki Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2002/03/17 22:14:15 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2002/03/17 22:14:15 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.1 2003/03/25 18:26:54 tshiozak Exp $
SRCPRE=citrus_
#CFLAGS+=-g
.include <bsd.lib.mk>

View File

@@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.1 2006/11/22 23:38:27 tnozaki Exp $
SRCS= citrus_hz.c citrus_prop.c
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2002/03/17 22:14:16 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2006/10/18 17:54:55 tnozaki Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2002/03/17 22:14:16 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

8
lib/i18n_module/Makefile Normal file
View File

@@ -0,0 +1,8 @@
# $NetBSD: Makefile,v 1.8 2007/04/01 18:52:31 tnozaki Exp $
SUBDIR= BIG5 DECHanyu EUC EUCTW GBK2K HZ ISO2022 JOHAB MSKanji UES UTF1632 UTF8 UTF7 VIQR ZW
SUBDIR+=iconv_none iconv_std
SUBDIR+=mapper_646 mapper_none mapper_serial mapper_parallel mapper_std \
mapper_zone
.include <bsd.subdir.mk>

View File

@@ -0,0 +1,28 @@
# $NetBSD: Makefile.inc,v 1.14 2012/08/23 21:21:15 joerg Exp $
NOLINT= # defined
NOPICINSTALL= # defined
NOPROFILE= # defined
NOCLANGERROR= # defined
.include <bsd.own.mk>
SHLIB_VERSION_FILE= ${NETBSDSRCDIR}/lib/i18n_module/shlib_version
.if defined(MLIBDIR)
LIBDIR= /usr/lib/${MLIBDIR}/i18n
SHLIBDIR= /usr/lib/${MLIBDIR}/i18n
SHLIBINSTALLDIR=/usr/lib/${MLIBDIR}/i18n
.else
LIBDIR= /usr/lib/i18n
SHLIBDIR= /usr/lib/i18n
SHLIBINSTALLDIR=/usr/lib/i18n
.endif
CPPFLAGS+= -I${NETBSDSRCDIR}/lib/libc/citrus
CPPFLAGS+= -DLOCALEMOD_MAJOR=${SHLIB_MAJOR}
CPPFLAGS+= -DLIBC_SCCS
BASENAME= ${.CURDIR:T}
LIB= ${BASENAME}
SRCS?= ${SRCPRE:tl}${BASENAME:tl}.c
.PATH: ${NETBSDSRCDIR}/lib/libc/citrus ${NETBSDSRCDIR}/lib/libc/citrus/modules

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2006/11/13 15:16:31 tnozaki Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2003/06/25 10:38:03 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,8 @@
# $NetBSD: Makefile,v 1.4 2011/06/20 06:52:36 mrg Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>
.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
COPTS.citrus_utf7.c+= -O0
.endif

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2002/03/17 22:14:17 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2006/11/13 15:16:31 tnozaki Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2006/11/22 23:38:27 tnozaki Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2003/06/25 10:38:04 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2003/06/25 10:38:04 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2003/06/25 10:38:04 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2003/06/25 10:38:05 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2003/06/25 10:38:05 tshiozak Exp $
SRCS=citrus_mapper_serial.c
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2003/06/25 10:38:05 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2003/06/25 10:38:06 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.1 2003/06/25 10:38:06 tshiozak Exp $
SRCPRE=citrus_
.include <bsd.lib.mk>

View File

@@ -0,0 +1,5 @@
# $NetBSD: shlib_version,v 1.6 2009/01/11 03:07:47 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=5
minor=0

20
lib/libintl/Makefile Normal file
View File

@@ -0,0 +1,20 @@
# $NetBSD: Makefile,v 1.6 2005/05/14 17:58:56 tshiozak Exp $
.include <bsd.own.mk>
LIB= intl
SRCS= gettext.c textdomain.c gettext_iconv.c gettext_dummy.c strhash.c \
sysdep.c plural_parser.c
INCS= libintl.h
INCSDIR=/usr/include
#CFLAGS+=-g
CPPFLAGS+=-I${.CURDIR} -I${.CURDIR}/../libc
MAN= gettext.3
MLINKS= gettext.3 dgettext.3 gettext.3 dcgettext.3 \
gettext.3 ngettext.3 gettext.3 dngettext.3 \
gettext.3 dcngettext.3 gettext.3 textdomain.3 \
gettext.3 bindtextdomain.3 gettext.3 bind_textdomain_codeset.3
.include <bsd.lib.mk>

407
lib/libintl/gettext.3 Normal file
View File

@@ -0,0 +1,407 @@
.\" $NetBSD: gettext.3,v 1.12 2009/11/12 00:43:52 joerg Exp $
.\"
.\" Copyright (c) 2000 Citrus Project,
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd November 10, 2004
.Dt GETTEXT 3
.Os
.Sh NAME
.Nm gettext ,
.Nm dgettext ,
.Nm ngettext ,
.Nm dngettext ,
.Nm textdomain ,
.Nm bindtextdomain ,
.Nm bind_textdomain_codeset ,
.Nm dcgettext ,
.Nm dcngettext
.Nd message handling functions
.Sh LIBRARY
.Lb libintl
.Sh SYNOPSIS
.In libintl.h
.Ft char *
.Fn gettext "const char *msgid"
.Ft char *
.Fn dgettext "const char *domainname" "const char *msgid"
.Ft char *
.Fn ngettext "const char *msgid1" "const char *msgid2" "unsigned long int n"
.Ft char *
.Fn dngettext "const char *domainname" "const char *msgid1" "const char *msgid2" "unsigned long int n"
.Ft char *
.Fn textdomain "const char *domainname"
.Ft char *
.Fn bindtextdomain "const char *domainname" "const char *dirname"
.Ft char *
.Fn bind_textdomain_codeset "const char *domainname" "const char *codeset"
.In libintl.h
.In locale.h
.Ft char *
.Fn dcgettext "const char *domainname" "const char *msgid" "int category"
.Ft char *
.Fn dcngettext "const char *domainname" "const char *msgid1" "const char *msgid2" "unsigned long int n" "int category"
.Sh DESCRIPTION
The
.Fn gettext ,
.Fn dgettext ,
and
.Fn dcgettext
functions attempt to retrieve a
target string based on the specified
.Fa msgid
argument within the context of a
specific domain and the current locale.
The length of strings returned by
.Fn gettext ,
.Fn dgettext ,
and
.Fn dcgettext
is undetermined until the function is
called.
The
.Fa msgid
argument is a nul-terminated string.
.Pp
The
.Fn ngettext ,
.Fn dngettext ,
and
.Fn dcngettext
functions are equivalent to
.Fn gettext ,
.Fn dgettext ,
and
.Fn dcgettext ,
respectively, except for the handling of
plural forms.
The
.Fn ngettext ,
.Fn dngettext ,
and
.Fn dcngettext
functions search for the
message string using the
.Fa msgid1
argument as the key, using the argument
.Fa n
to
determine the plural form.
If no message catalogs are found,
.Fa msgid1
is returned
if
.Fa n Li == 1 ,
otherwise
.Fa msgid2
is returned.
.Pp
The
.Dv LANGUAGE
environment variable is examined first to determine the message
catalogs to be used.
The value of the
.Dv LANGUAGE
environment variable is a list
of locale names separated by colon (:) character.
If the
.Dv LANGUAGE
environment
variable is defined, each locale name is tried in the specified order and if a
message catalog containing the requested message is found, the message is
returned.
If the
.Dv LANGUAGE
environment variable is defined but failed to locate
a message catalog, the
.Fa msgid
string will be returned.
.Pp
If the
.Dv LANGUAGE
environment variable is not defined,
.Dv LC_ALL ,
.Dv LC_xxx ,
and
.Dv LANG
environment variables are examined to locate the message catalog,
following the convention used by the
.Xr setlocale 3
function.
.Pp
The pathname used to locate the message catalog is
.Pa dirname/locale/category/domainname.mo ,
where dirname is the directory specified by
.Fn bindtextdomain ,
locale is a locale name determined by the definition of environment variables,
.Fa category
is
.Dv LC_MESSAGES
if
.Fn gettext ,
.Fn ngettext ,
.Fn dgettext ,
or
.Fn dngettext
is
called, otherwise
.Dv LC_xxx
where the name is the same as the locale category name
specified by the
.Fa category
argument of
.Fn dcgettext
or
.Fn dcngettext .
.Fa domainname
is the name of the domain specified by
.Fn textdomain
or the
.Fa domainname
argument of
.Fn dgettext ,
.Fn dngettext ,
.Fn dcgettext ,
or
.Fn dcngettext .
.Pp
For
.Fn gettext
and
.Fn ngettext ,
the domain used is set by the last valid call to
.Fn textdomain .
If a valid call to
.Fn textdomain
has not been made, the default
domain (called messages) is used.
.Pp
For
.Fn dgettext ,
.Fn dngettext ,
.Fn dcgettext ,
and
.Fn dcngettext ,
the domain used is
specified by the
.Fa domainname
argument.
The
.Fa domainname
argument is equivalent in
syntax and meaning to the
.Fa domainname
argument to
.Fn textdomain ,
except that the
selection of the domain is valid only for the duration of the
.Fn dgettext ,
.Fn dngettext ,
.Fn dcgettext ,
or
.Fn dcngettext
function call.
.Pp
The
.Fn dcgettext
and
.Fn dcngettext
functions require additional argument
.Fa category
for retrieving message string for other than
.Dv LC_MESSAGES
category.
Available value for the
.Fa category
argument are
.Dv LC_CTYPE ,
.Dv LC_COLLATE ,
.Dv LC_MESSAGES ,
.Dv LC_MONETARY ,
.Dv LC_NUMERIC ,
and
.Dv LC_TIME .
The call of
.Fn dcgettext "domainname" "msgid" "LC_MESSAGES"
is equivalent to
.Fn dgettext "domainname" "msgid" .
Note that
.Dv LC_ALL
must not be used.
.Pp
The
.Fn textdomain
function sets or queries the name of the current domain of the
active
.Dv LC_MESSAGES
locale category.
The
.Fa domainname
argument is a
nul-terminated string that can contain only the characters allowed in legal
filenames.
.Pp
The
.Fa domainname
argument is the unique name of a domain on the system.
If there
are multiple versions of the same domain on one system, namespace collisions
can be avoided by using
.Fn bindtextdomain .
If
.Fn textdomain
is not called, a
default domain is selected.
The setting of domain made by the last valid call
to
.Fn textdomain
remains valid across subsequent calls to
.Xr setlocale 3 ,
and
.Fn gettext .
.Pp
The
.Fa domainname
argument is applied to the currently active LC_MESSAGES locale.
.Pp
The current setting of the domain can be queried without affecting the current
state of the domain by calling
.Fn textdomain
with
.Fa domainname
set to the
.Dv NULL
pointer.
Calling
.Fn textdomain
with a
.Fa domainname
argument of a
.Dv NULL
string sets
the domain to the default domain
.Pq messages .
.Pp
The
.Fn bindtextdomain
function binds the path predicate for a message domain
.Fa domainname
to the value contained in dirname.
If
.Fa domainname
is a non-empty
string and has not been bound previously,
.Fn bindtextdomain
binds
.Fa domainname
with
.Fa dirname .
.Pp
If
.Fa domainname
is a non-empty string and has been bound previously,
.Fn bindtextdomain
replaces the old binding with dirname.
The dirname argument
can be an absolute pathname being resolved when
.Fn gettext ,
.Fn ngettext ,
.Fn dgettext ,
.Fn dngettext ,
.Fn dcgettext ,
or
.Fn dcngettext
are called.
If
.Fa domainname
is a
.Dv NULL
pointer or an empty string,
.Fn bindtextdomain
returns a
.Dv NULL
pointer.
If
.Fn bindtextdomain
is not called, implementation-defined default directory is used.
.Pp
The
.Fn bind_textdomain_codeset
function can be used to specify the output
.Fa codeset
for message catalogs for domain
.Fa domainname .
The
.Fa codeset
argument must
be a valid codeset name which can be used for the
.Xr iconv_open 3
function.
.Pp
If the
.Fa codeset
argument is the
.Dv NULL
pointer,
.Fn bind_textdomain_codeset
returns the currently selected
.Fa codeset
for the domain with the name
.Fa domainname .
It returns a
.Dv NULL
pointer if no
.Fa codeset
has yet been selected.
.Pp
The
.Fn bind_textdomain_codeset
function can be used several times.
If used multiple times, with the same
.Fa domainname
argument,
the later call overrides the
settings made by the earlier one.
.Pp
The
.Fn bind_textdomain_codeset
function returns a pointer to a string containing
the name of the selected
.Fa codeset .
.\".Sh "RETURN VALUES"
.\".Sh EXAMPLES
.Sh SEE ALSO
.Xr setlocale 3 ,
.Xr nls 7
.\".Sh STANDARDS
.Sh HISTORY
The functions are implemented by Citrus project,
based on the documentations for GNU gettext.
.Sh BUGS
.\" The text was ripped off from Annex C of
.\" .Dq LI18NUX 2000 Globalization Specification Version 1.0 .
.\" .Pp
.Fn bind_textdomain_codeset
does not work at this moment
.Pq it always fails .

1054
lib/libintl/gettext.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,44 @@
/* $NetBSD: gettext_dummy.c,v 1.3 2007/09/25 08:16:08 junyoung Exp $ */
/*-
* Copyright (c) 2000 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: gettext_dummy.c,v 1.3 2007/09/25 08:16:08 junyoung Exp $");
/*
* The symbol is referenced by gettext.m4 (autoconf m4 macro fragment
* that ships with GNU gettext), to check if libintl is GNU origin or not.
* Since we are trying to mimic GNU gettext, we supply the symbol just to
* make gettext.m4 happy.
*
* If we do not provide this symbol, as a result of gettext.m4, *.mo will be
* installed into /usr/lib/locale, not /usr/share/locale. It is not desirable.
*
* Yes, I understand this is a dirty hack. gettext.m4 is doing something
* very wrong here and I have no other choice.
*/
int _nl_msg_cat_cntr;

224
lib/libintl/gettext_iconv.c Normal file
View File

@@ -0,0 +1,224 @@
/* $NetBSD: gettext_iconv.c,v 1.8 2009/02/18 13:08:22 yamt Exp $ */
/*-
* Copyright (c) 2004 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Citrus$
*/
#include <sys/types.h>
#include <sys/param.h>
#include <errno.h>
#include <iconv.h>
#include <libintl.h>
#include <langinfo.h>
#include <search.h>
#include <stdlib.h>
#include <string.h>
#include "libintl_local.h"
struct cache {
const char *c_origmsg;
const char *c_resultmsg;
};
static const struct cache *cache_find(const char *, struct domainbinding *);
static int cache_enter(const char *, const char *);
static int cache_cmp(const void *, const void *);
static void *cacheroot;
/* ARGSUSED1 */
static const struct cache *
cache_find(const char *msg, struct domainbinding *db)
{
struct cache key;
struct cache **c;
key.c_origmsg = msg;
c = tfind(&key, &cacheroot, cache_cmp);
return c ? *c : NULL;
}
static int
cache_enter(const char *origmsg, const char *resultmsg)
{
struct cache *c;
c = malloc(sizeof(*c));
if (c == NULL)
return -1;
c->c_origmsg = origmsg;
c->c_resultmsg = resultmsg;
if (tsearch(c, &cacheroot, cache_cmp) == NULL) {
free(c);
return -1;
}
return 0;
}
static int
cache_cmp(const void *va, const void *vb)
{
const struct cache *a = va;
const struct cache *b = vb;
int result;
if (a->c_origmsg > b->c_origmsg) {
result = 1;
} else if (a->c_origmsg < b->c_origmsg) {
result = -1;
} else {
result = 0;
}
return result;
}
#define GETTEXT_ICONV_MALLOC_CHUNK (16 * 1024)
const char *
__gettext_iconv(const char *origmsg, struct domainbinding *db)
{
const char *tocode;
const char *fromcode = db->mohandle.mo.mo_charset;
const struct cache *cache;
const char *result;
iconv_t cd;
const char *src;
char *dst;
size_t origlen;
size_t srclen;
size_t dstlen;
size_t nvalid;
int savederrno = errno;
/*
* static buffer for converted texts.
*
* note:
* we never free buffers once returned to callers.
* because of interface design of gettext, we can't know
* the lifetime of them.
*/
static char *buffer;
static size_t bufferlen;
/*
* don't convert message if *.mo doesn't specify codeset.
*/
if (fromcode == NULL)
return origmsg;
tocode = db->codeset;
if (tocode == NULL) {
/*
* codeset isn't specified explicitly by
* bind_textdomain_codeset().
* use current locale(LC_CTYPE)'s codeset.
*
* XXX maybe wrong; it can mismatch with
* environment variable setting.
*/
tocode = nl_langinfo(CODESET);
}
/*
* shortcut if possible.
* XXX should handle aliases
*/
if (!strcasecmp(tocode, fromcode))
return origmsg;
/* XXX LOCK */
/* XXX should detect change of tocode and purge caches? */
/*
* see if we have already converted this message.
*/
cache = cache_find(origmsg, db);
if (cache) {
result = cache->c_resultmsg;
goto out;
}
origlen = strlen(origmsg) + 1;
again:
cd = iconv_open(tocode, fromcode);
if (cd == (iconv_t)-1) {
result = origmsg;
goto out;
}
src = origmsg;
srclen = origlen;
dst = buffer;
dstlen = bufferlen;
nvalid = iconv(cd, &src, &srclen, &dst, &dstlen);
iconv_close(cd);
if (nvalid == (size_t)-1) {
/*
* try to allocate a new buffer.
*
* just give up if GETTEXT_ICONV_MALLOC_CHUNK was not enough.
*/
if (errno == E2BIG &&
bufferlen != GETTEXT_ICONV_MALLOC_CHUNK) {
buffer = malloc(GETTEXT_ICONV_MALLOC_CHUNK);
if (buffer) {
bufferlen = GETTEXT_ICONV_MALLOC_CHUNK;
goto again;
}
}
result = origmsg;
} else if (cache_enter(origmsg, buffer)) {
/*
* failed to enter cache. give up.
*/
result = origmsg;
} else {
size_t resultlen = dst - buffer;
result = buffer;
bufferlen -= resultlen;
buffer += resultlen;
}
out:
/* XXX UNLOCK */
errno = savederrno;
return result;
}

83
lib/libintl/libintl.h Normal file
View File

@@ -0,0 +1,83 @@
/* $NetBSD: libintl.h,v 1.8 2015/06/08 15:04:20 christos Exp $ */
/*-
* Copyright (c) 2000 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _LIBINTL_H_
#define _LIBINTL_H_
#include <sys/cdefs.h>
#ifndef _LIBGETTEXT_H
/*
* Avoid defining these if the GNU gettext compatibility header includes
* us, since it re-defines those unconditionally and creates inline functions
* for some of them. This is horrible.
*/
#define pgettext_expr(msgctxt, msgid) pgettext((msgctxt), (msgid))
#define dpgettext_expr(domainname, msgctxt, msgid) \
dpgettext((domainname), (msgctxt), (msgid))
#define dcpgettext_expr(domainname, msgctxt, msgid, category) \
dcpgettext((domainname), (msgctxt), (msgid), (category))
#define npgettext_expr(msgctxt, msgid1, msgid2, n) \
npgettext((msgctxt), (msgid1), (msgid2), (n))
#define dnpgettext_expr(domainname, msgctxt, msgid1, n) \
dnpgettext((domainname), (msgctxt), (msgid1), (msgid2), (n))
#define dcnpgettext_expr(domainname, msgctxt, msgid1, msgid2, n, category) \
dcnpgettext((domainname), (msgctxt), (msgid1), (msgid2), (n), (category))
#endif
__BEGIN_DECLS
char *gettext(const char *) __format_arg(1);
char *dgettext(const char *, const char *) __format_arg(2);
char *dcgettext(const char *, const char *, int) __format_arg(2);
char *ngettext(const char *, const char *, unsigned long int)
__format_arg(1) __format_arg(2);
char *dngettext(const char *, const char *, const char *, unsigned long int)
__format_arg(2) __format_arg(3);
char *dcngettext(const char *, const char *, const char *, unsigned long int,
int) __format_arg(2) __format_arg(3);
const char *pgettext(const char *, const char *) __format_arg(2);
const char *dpgettext(const char *, const char *, const char *)
__format_arg(3);
const char *dcpgettext(const char *, const char *, const char *, int)
__format_arg(3);
const char *npgettext(const char *, const char *, const char *,
unsigned long int) __format_arg(2) __format_arg(3);
const char *dnpgettext(const char *, const char *, const char *,
const char *, unsigned long int) __format_arg(3)
__format_arg(4);
const char *dcnpgettext(const char *, const char *, const char *,
const char *, unsigned long int, int) __format_arg(3)
__format_arg(4);
char *textdomain(const char *);
char *bindtextdomain(const char *, const char *);
char *bind_textdomain_codeset(const char *, const char *);
__END_DECLS
#endif /* _LIBINTL_H_ */

148
lib/libintl/libintl_local.h Normal file
View File

@@ -0,0 +1,148 @@
/* $NetBSD: libintl_local.h,v 1.12 2007/09/25 08:22:44 junyoung Exp $ */
/*-
* Copyright (c) 2000, 2001 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Citrus: xpg4dl/FreeBSD/lib/libintl/libintl_local.h,v 1.13 2001/09/27 15:18:45 yamt Exp $
*/
#define MO_MAGIC 0x950412de
#define MO_MAGIC_SWAPPED 0xde120495
#define MO_GET_REV_MAJOR(r) (((r) >> 16) & 0xFFFF)
#define MO_GET_REV_MINOR(r) ((r) & 0xFFFF)
#define MO_MAKE_REV(maj, min) (((maj) << 16) | (min))
#define GETTEXT_MMAP_MAX (1024 * 1024) /*XXX*/
#define DEFAULT_DOMAINNAME "messages"
/* *.mo file format */
struct mo {
uint32_t mo_magic; /* determines endian */
uint32_t mo_revision; /* file format revision: 0 */
uint32_t mo_nstring; /* N: number of strings */
uint32_t mo_otable; /* O: original text table offset */
uint32_t mo_ttable; /* T: translated text table offset */
uint32_t mo_hsize; /* S: size of hashing table */
uint32_t mo_hoffset; /* H: offset of hashing table */
/* rev 0.1 / 1.1 */
/* system dependent string support */
uint32_t mo_sysdep_nsegs; /* number of sysdep segments */
uint32_t mo_sysdep_segoff; /* offset of sysdep segment table */
uint32_t mo_sysdep_nstring; /* number of strings */
uint32_t mo_sysdep_otable; /* offset of original text table */
uint32_t mo_sysdep_ttable; /* offset of translated text table */
} __packed;
struct moentry {
uint32_t len; /* strlen(str), so region will be len + 1 */
uint32_t off; /* offset of \0-terminated string */
} __packed;
struct mosysdepsegentry {
uint32_t len; /* length of this part */
uint32_t ref; /* reference number of the sysdep string,
* concatenated just after this segment.
*/
} __packed;
#define MO_LASTSEG (0xFFFFFFFF)
struct mosysdepstr {
uint32_t off; /* offset of seed text */
struct mosysdepsegentry segs[1]; /* text segments */
} __packed;
/* libintl internal data format */
struct moentry_h {
size_t len; /* strlen(str), so region will be len + 1 */
char *off; /* offset of \0-terminated string */
};
struct mosysdepsegs_h {
const char *str;
size_t len;
};
struct mosysdepsegentry_h {
uint32_t len;
uint32_t ref;
};
struct mosysdepstr_h {
const char *off; /* offset of the base string */
char *expanded; /* expanded string */
size_t expanded_len; /* length of expanded string */
struct mosysdepsegentry_h segs[1]; /* text segments */
};
struct gettext_plural;
struct mo_h {
uint32_t mo_magic; /* determines endian */
uint32_t mo_revision; /* file format revision: 0 */
uint32_t mo_nstring; /* N: number of strings */
struct moentry_h *mo_otable; /* O: original text table offset */
struct moentry_h *mo_ttable; /* T: translated text table offset */
const char *mo_header;
struct gettext_plural *mo_plural;
unsigned long mo_nplurals;
char *mo_charset;
uint32_t mo_hsize; /* S: size of hashing table */
uint32_t *mo_htable; /* H: hashing table */
#define MO_HASH_SYSDEP_MASK 0x80000000 /* means sysdep entry */
uint32_t mo_flags;
#define MO_F_SYSDEP 0x00000001 /* enable sysdep string support */
/* system dependent string support */
uint32_t mo_sysdep_nsegs; /* number of sysdep segments */
uint32_t mo_sysdep_nstring; /* number of sysdep strings */
struct mosysdepsegs_h *mo_sysdep_segs; /* sysdep segment table */
struct mosysdepstr_h **mo_sysdep_otable; /* original text */
struct mosysdepstr_h **mo_sysdep_ttable; /* translated text */
};
struct mohandle {
void *addr; /* mmap'ed region */
size_t len;
struct mo_h mo; /* endian-flipped mo file header */
};
struct domainbinding {
struct domainbinding *next;
char domainname[PATH_MAX];
char path[PATH_MAX];
char *codeset;
struct mohandle mohandle;
};
extern struct domainbinding *__bindings;
extern char __current_domainname[PATH_MAX];
__BEGIN_DECLS
const char *__gettext_iconv(const char *, struct domainbinding *);
uint32_t __intl_string_hash(const char *);
const char *__intl_sysdep_get_string_by_tag(const char *, size_t *);
__END_DECLS

29
lib/libintl/pathnames.h Normal file
View File

@@ -0,0 +1,29 @@
/* $NetBSD: pathnames.h,v 1.1.1.1 2000/10/31 10:45:04 itojun Exp $ */
/*-
* Copyright (c) 2000 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#define _PATH_TEXTDOMAIN "/usr/share/locale"

1119
lib/libintl/plural_parser.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
/* $NetBSD: plural_parser.h,v 1.2 2007/09/25 08:19:09 junyoung Exp $ */
/*-
* Copyright (c) 2005 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef PLURAL_PARSER_H_
#define PLURAL_PARSER_H_
struct gettext_plural;
__BEGIN_DECLS
int _gettext_parse_plural(struct gettext_plural **, unsigned long *,
const char *, size_t);
unsigned long _gettext_calculate_plural(const struct gettext_plural *,
unsigned long);
void _gettext_free_plural(struct gettext_plural *);
__END_DECLS
#endif

View File

@@ -0,0 +1,5 @@
# $NetBSD: shlib_version,v 1.3 2015/05/29 12:27:03 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=1
minor=1

60
lib/libintl/strhash.c Normal file
View File

@@ -0,0 +1,60 @@
/* $NetBSD: strhash.c,v 1.3 2007/09/25 08:19:09 junyoung Exp $ */
/*-
* Copyright (c)2003, 2004 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: strhash.c,v 1.3 2007/09/25 08:19:09 junyoung Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
#include <sys/types.h>
#include "libintl_local.h"
/*
* string hash function by P.J.Weinberger.
* this implementation is derived from src/lib/libc/citrus/citrus_db_hash.c.
*/
uint32_t
/*ARGSUSED*/
__intl_string_hash(const char *str)
{
const uint8_t *p;
uint32_t hash = 0, tmp;
for (p = (const uint8_t *)str; *p; p++) {
hash <<= 4;
hash += *p;
tmp = hash & 0xF0000000;
if (tmp != 0) {
hash ^= tmp;
hash ^= tmp >> 24;
}
}
return hash;
}

236
lib/libintl/sysdep.c Normal file
View File

@@ -0,0 +1,236 @@
/* $NetBSD: sysdep.c,v 1.2 2005/04/27 09:50:26 yamt Exp $ */
/*-
* Copyright (c)2004 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: sysdep.c,v 1.2 2005/04/27 09:50:26 yamt Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
#include <sys/types.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include "libintl_local.h"
struct sysdep_pair
{
const char *tag;
const char *string;
size_t len;
};
#define T_(tag) { #tag, tag, sizeof (tag)-1 }
#define numof(a) (sizeof (a) / sizeof ((a)[0]))
const struct sysdep_pair sysdep_pair_table[] = {
/* this table must be sorted in the dictionary order. */
T_(PRIX16),
T_(PRIX32),
T_(PRIX64),
T_(PRIX8),
T_(PRIXFAST16),
T_(PRIXFAST32),
T_(PRIXFAST64),
T_(PRIXFAST8),
T_(PRIXLEAST16),
T_(PRIXLEAST32),
T_(PRIXLEAST64),
T_(PRIXLEAST8),
T_(PRIXMAX),
T_(PRIXPTR),
T_(PRId16),
T_(PRId32),
T_(PRId64),
T_(PRId8),
T_(PRIdFAST16),
T_(PRIdFAST32),
T_(PRIdFAST64),
T_(PRIdFAST8),
T_(PRIdLEAST16),
T_(PRIdLEAST32),
T_(PRIdLEAST64),
T_(PRIdLEAST8),
T_(PRIdMAX),
T_(PRIdPTR),
T_(PRIi16),
T_(PRIi32),
T_(PRIi64),
T_(PRIi8),
T_(PRIiFAST16),
T_(PRIiFAST32),
T_(PRIiFAST64),
T_(PRIiFAST8),
T_(PRIiLEAST16),
T_(PRIiLEAST32),
T_(PRIiLEAST64),
T_(PRIiLEAST8),
T_(PRIiMAX),
T_(PRIiPTR),
T_(PRIo16),
T_(PRIo32),
T_(PRIo64),
T_(PRIo8),
T_(PRIoFAST16),
T_(PRIoFAST32),
T_(PRIoFAST64),
T_(PRIoFAST8),
T_(PRIoLEAST16),
T_(PRIoLEAST32),
T_(PRIoLEAST64),
T_(PRIoLEAST8),
T_(PRIoMAX),
T_(PRIoPTR),
T_(PRIu16),
T_(PRIu32),
T_(PRIu64),
T_(PRIu8),
T_(PRIuFAST16),
T_(PRIuFAST32),
T_(PRIuFAST64),
T_(PRIuFAST8),
T_(PRIuLEAST16),
T_(PRIuLEAST32),
T_(PRIuLEAST64),
T_(PRIuLEAST8),
T_(PRIuMAX),
T_(PRIuPTR),
T_(PRIx16),
T_(PRIx32),
T_(PRIx64),
T_(PRIx8),
T_(PRIxFAST16),
T_(PRIxFAST32),
T_(PRIxFAST64),
T_(PRIxFAST8),
T_(PRIxLEAST16),
T_(PRIxLEAST32),
T_(PRIxLEAST64),
T_(PRIxLEAST8),
T_(PRIxMAX),
T_(PRIxPTR),
T_(SCNd16),
T_(SCNd32),
T_(SCNd64),
T_(SCNd8),
T_(SCNdFAST16),
T_(SCNdFAST32),
T_(SCNdFAST64),
T_(SCNdFAST8),
T_(SCNdLEAST16),
T_(SCNdLEAST32),
T_(SCNdLEAST64),
T_(SCNdLEAST8),
T_(SCNdMAX),
T_(SCNdPTR),
T_(SCNi16),
T_(SCNi32),
T_(SCNi64),
T_(SCNi8),
T_(SCNiFAST16),
T_(SCNiFAST32),
T_(SCNiFAST64),
T_(SCNiFAST8),
T_(SCNiLEAST16),
T_(SCNiLEAST32),
T_(SCNiLEAST64),
T_(SCNiLEAST8),
T_(SCNiMAX),
T_(SCNiPTR),
T_(SCNo16),
T_(SCNo32),
T_(SCNo64),
T_(SCNo8),
T_(SCNoFAST16),
T_(SCNoFAST32),
T_(SCNoFAST64),
T_(SCNoFAST8),
T_(SCNoLEAST16),
T_(SCNoLEAST32),
T_(SCNoLEAST64),
T_(SCNoLEAST8),
T_(SCNoMAX),
T_(SCNoPTR),
T_(SCNu16),
T_(SCNu32),
T_(SCNu64),
T_(SCNu8),
T_(SCNuFAST16),
T_(SCNuFAST32),
T_(SCNuFAST64),
T_(SCNuFAST8),
T_(SCNuLEAST16),
T_(SCNuLEAST32),
T_(SCNuLEAST64),
T_(SCNuLEAST8),
T_(SCNuMAX),
T_(SCNuPTR),
T_(SCNx16),
T_(SCNx32),
T_(SCNx64),
T_(SCNx8),
T_(SCNxFAST16),
T_(SCNxFAST32),
T_(SCNxFAST64),
T_(SCNxFAST8),
T_(SCNxLEAST16),
T_(SCNxLEAST32),
T_(SCNxLEAST64),
T_(SCNxLEAST8),
T_(SCNxMAX),
T_(SCNxPTR)
};
static int
cmp_sysdep_tag(const void *tag, const void *elem)
{
const struct sysdep_pair *pair = elem;
return strcmp(tag, pair->tag);
}
const char *
__intl_sysdep_get_string_by_tag(const char *tag, size_t *rlen)
{
const struct sysdep_pair *found;
found = bsearch(tag, sysdep_pair_table, numof(sysdep_pair_table),
sizeof(sysdep_pair_table[0]), &cmp_sysdep_tag);
if (found) {
if (rlen)
*rlen = found->len;
return found->string;
}
if (rlen)
*rlen = 0;
return "";
}

148
lib/libintl/textdomain.c Normal file
View File

@@ -0,0 +1,148 @@
/* $NetBSD: textdomain.c,v 1.14 2015/05/29 12:26:28 christos Exp $ */
/*-
* Copyright (c) 2000, 2001 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: textdomain.c,v 1.14 2015/05/29 12:26:28 christos Exp $");
#include <sys/param.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libintl.h>
#include "libintl_local.h"
#include "pathnames.h"
static struct domainbinding __default_binding = {
.path = { _PATH_TEXTDOMAIN },
.domainname = { DEFAULT_DOMAINNAME },
};
struct domainbinding *__bindings = &__default_binding;
char __current_domainname[PATH_MAX] = DEFAULT_DOMAINNAME;
static struct domainbinding *domainbinding_lookup(const char *, int);
/*
* set the default domainname for dcngettext() and friends.
*/
char *
textdomain(const char *domainname)
{
/* NULL pointer gives the current setting */
if (!domainname)
return __current_domainname;
/* empty string sets the value back to the default */
if (!*domainname) {
strlcpy(__current_domainname, DEFAULT_DOMAINNAME,
sizeof(__current_domainname));
} else {
strlcpy(__current_domainname, domainname,
sizeof(__current_domainname));
}
return __current_domainname;
}
char *
bindtextdomain(const char *domainname, const char *dirname)
{
struct domainbinding *p;
/* NULL pointer or empty string returns NULL with no operation */
if (!domainname || !*domainname)
return NULL;
if (dirname && (strlen(dirname) + 1 > sizeof(p->path)))
return NULL;
#if 0
/* disallow relative path */
if (dirname[0] != '/')
return NULL;
#endif
if (strlen(domainname) + 1 > sizeof(p->domainname))
return NULL;
p = domainbinding_lookup(domainname, (dirname != NULL));
if (!dirname) {
if (p)
return (p->path);
else
return (char *)__UNCONST(_PATH_TEXTDOMAIN);
}
strlcpy(p->path, dirname, sizeof(p->path));
p->mohandle.mo.mo_magic = 0; /* invalidate current mapping */
return (p->path);
}
char *
bind_textdomain_codeset(const char *domainname, const char *codeset)
{
struct domainbinding *p;
p = domainbinding_lookup(domainname, (codeset != NULL));
if (p == NULL)
return NULL;
if (codeset) {
free(p->codeset);
p->codeset = strdup(codeset);
}
return p->codeset;
}
/*
* lookup binding for the domainname
*/
static struct domainbinding *
domainbinding_lookup(const char *domainname, int alloc)
{
struct domainbinding *p;
for (p = __bindings; p; p = p->next)
if (strcmp(p->domainname, domainname) == 0)
break;
if (!p && alloc) {
p = (struct domainbinding *)malloc(sizeof(*p));
if (!p)
return NULL;
memset(p, 0, sizeof(*p));
p->next = __bindings;
strlcpy(p->domainname, domainname, sizeof(p->domainname));
__bindings = p;
}
return p;
}