diff options
| author | tnozaki <tnozaki@NetBSD.org> | 2009-01-02 00:20:18 +0000 |
|---|---|---|
| committer | tnozaki <tnozaki@NetBSD.org> | 2009-01-02 00:20:18 +0000 |
| commit | 52ed7b035ff6e5fc73eada9c5ce08f7fa154eb8c (patch) | |
| tree | 9f1f04551051a7947bc39a09f744c2530039cbf3 /lib/libc | |
| parent | 2577e51e90a539fb95d67e7acc4c3a378da404d8 (diff) | |
Fixes PR lib/39662, shortcomings in LC_{MONETARY,NUMERIC,TIME,MESSAGES} db format.
ok'ed by core and releng.
(thanks for agc@, snj@ and i'm sorry for long time patience).
[libc]
- localeio.[ch] and lc*.[ch] in src/lib/libc/locale was replaced by
new locale-db implementation using citrus_db backend,
see src/lib/libc/citrus/citrus_lc_*.[ch].
- add citrus_bcs_strtou?l.c. don't use strtou?l locale implementation
internally, because they're locale-aware function.
- add some stubs for multi-locale issue, see {current,global}_locale.c.
- remove some obsolete file, setrunelocale.c, ___runetype_mb.c.
- remove __savectype() from ctypeio.[ch].
[tools]
- mklocale(1): add new option ``-t'' that generates new style
LC_{MONETARY,NUMERIC,TIME,MESSAGES} locale-db format.
- chrtbl(1): added ctypeio.[ch] for __savectype().
[locale-db]
- added en_US.US-ASCII locale.
- removed some shareable locale definition file:
en_US.US-ASCII -> en_US.ISO8859-1, en_US.UTF-8
zh_CN.eucCN -> zh_CN.GB18030
and more...see src/share/locale/*/Makefile.
- remove obsoleted locale sr_YU, added new locale sr_ME, sr_RS.
- change locale name ja_JP.ISO2022-JP* -> ja_JP.ISO-2022-JP*
for X11's locale.alias file alignments.
- fix regression test, wrong wcs?width(3), NAN/INF usage.
i tested release-build following arch:
i386, amd64, hpc{mips,arm,sh}, sparc64, vax.
citrus_lc_*.[ch] also can read old-plain-text style locale-db.
so that backward compatibility is keeped, but lc*.[ch] can't read
new citrus_db'ed locale-db and localeio.c never check sanity,
so forward compatibility is broken ;-<
old mklocale(1) doesn't know -t option, so you have to rebuild toolchain.
Diffstat (limited to 'lib/libc')
87 files changed, 4178 insertions, 2047 deletions
diff --git a/lib/libc/citrus/Makefile.inc b/lib/libc/citrus/Makefile.inc index 68adff547fa..e7ffe9dbf56 100644 --- a/lib/libc/citrus/Makefile.inc +++ b/lib/libc/citrus/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.5 2004/07/21 20:27:46 tshiozak Exp $ +# $NetBSD: Makefile.inc,v 1.6 2009/01/02 00:20:19 tnozaki Exp $ # sources .PATH: ${ARCHDIR}/citrus ${.CURDIR}/citrus @@ -7,12 +7,23 @@ CITRUS?= yes .if ${CITRUS} == "yes" MODULE_SHLIB_MAJOR!= . ${NETBSDSRCDIR}/lib/i18n_module/shlib_version ; echo $$major -CPPFLAGS+= -DI18NMODULE_MAJOR=${MODULE_SHLIB_MAJOR} -DCITRUS - -SRCS+= citrus_bcs.c citrus_csmapper.c citrus_ctype.c citrus_ctype_fallback.c \ +CPPFLAGS.citrus_module.c+=-DI18NMODULE_MAJOR=${MODULE_SHLIB_MAJOR} +SRCS+= citrus_bcs.c citrus_bcs_strtol.c citrus_bcs_strtoul.c \ + citrus_csmapper.c citrus_ctype.c citrus_ctype_fallback.c \ citrus_db.c citrus_db_hash.c citrus_esdb.c citrus_hash.c \ citrus_iconv.c citrus_lookup.c \ citrus_mapper.c citrus_memstream.c citrus_mmap.c citrus_module.c \ citrus_none.c citrus_stdenc.c - +SRCS+= citrus_lc_ctype.c \ + citrus_lc_monetary.c \ + citrus_lc_numeric.c \ + citrus_lc_time.c \ + citrus_lc_messages.c +CPPFLAGS.citrus_bcs_strtol.c+= -I${LIBCDIR}/../../common/lib/libc/stdlib +CPPFLAGS.citrus_bcs_strtoul.c+= -I${LIBCDIR}/../../common/lib/libc/stdlib +CPPFLAGS.citrus_lc_ctype.c+= -I${LIBCDIR}/locale +CPPFLAGS.citrus_lc_monetary.c+= -I${LIBCDIR}/locale +CPPFLAGS.citrus_lc_numeric.c+= -I${LIBCDIR}/locale +CPPFLAGS.citrus_lc_time.c+= -I${LIBCDIR}/locale +CPPFLAGS.citrus_lc_messages.c+= -I${LIBCDIR}/locale .endif diff --git a/lib/libc/citrus/citrus_aliasname_local.h b/lib/libc/citrus/citrus_aliasname_local.h new file mode 100644 index 00000000000..298f8c22dca --- /dev/null +++ b/lib/libc/citrus/citrus_aliasname_local.h @@ -0,0 +1,48 @@ +/* $NetBSD: citrus_aliasname_local.h,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _CITRUS_ALIASNAME_LOCAL_H_ +#define _CITRUS_ALIASNAME_LOCAL_H_ + +static __inline const char * +__unaliasname(const char *dbname, const char *alias, + void *buf, size_t bufsize) +{ + return _lookup_simple(dbname, alias, + buf, bufsize, _LOOKUP_CASE_SENSITIVE); +} + +static __inline int +__isforcemapping(const char *name) +{ + _DIAGASSERT(name != NULL); + + return _bcs_strcasecmp("/force", name); +} + +#endif /*_CITRUS_ALIASNAME_LOCAL_H_*/ diff --git a/lib/libc/citrus/citrus_bcs.h b/lib/libc/citrus/citrus_bcs.h index 05296483e05..d31ea1c2fe9 100644 --- a/lib/libc/citrus/citrus_bcs.h +++ b/lib/libc/citrus/citrus_bcs.h @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_bcs.h,v 1.4 2008/02/09 14:56:20 junyoung Exp $ */ +/* $NetBSD: citrus_bcs.h,v 1.5 2009/01/02 00:20:19 tnozaki Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -87,6 +87,12 @@ const char *_citrus_bcs_skip_nonws_len(const char * __restrict, void _citrus_bcs_trunc_rws_len(const char * __restrict, size_t * __restrict); void _citrus_bcs_convert_to_lower(char *); void _citrus_bcs_convert_to_upper(char *); + +long int _citrus_bcs_strtol( + const char * __restrict, char ** __restrict, int); +unsigned long int _citrus_bcs_strtoul( + const char * __restrict, char ** __restrict, int); + __END_DECLS #endif diff --git a/lib/libc/citrus/citrus_bcs_strtol.c b/lib/libc/citrus/citrus_bcs_strtol.c new file mode 100644 index 00000000000..ca4d7909367 --- /dev/null +++ b/lib/libc/citrus/citrus_bcs_strtol.c @@ -0,0 +1,59 @@ +/* $NetBSD: citrus_bcs_strtol.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c) 2005 The DragonFly Project. All rights reserved. + * Copyright (c) 2003, 2008 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: citrus_bcs_strtol.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $"); + +#include <assert.h> +#include <errno.h> +#include <limits.h> +#include <stdint.h> +#include <stdlib.h> + +#include "citrus_namespace.h" +#include "citrus_bcs.h" + +#define _FUNCNAME _bcs_strtol +#define __INT long int +#define __INT_MIN LONG_MIN +#define __INT_MAX LONG_MAX + +#undef isspace +#define isspace(c) _bcs_isspace(c) + +#undef isdigit +#define isdigit(c) _bcs_isdigit(c) + +#undef isalpha +#define isalpha(c) _bcs_isalpha(c) + +#undef isupper +#define isupper(c) _bcs_isupper(c) + +#include "_strtol.h" diff --git a/lib/libc/citrus/citrus_bcs_strtoul.c b/lib/libc/citrus/citrus_bcs_strtoul.c new file mode 100644 index 00000000000..863c32094a2 --- /dev/null +++ b/lib/libc/citrus/citrus_bcs_strtoul.c @@ -0,0 +1,64 @@ +/* $NetBSD: citrus_bcs_strtoul.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c) 2005 The DragonFly Project. All rights reserved. + * Copyright (c) 2003, 2008 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(lint) +__RCSID("$NetBSD: citrus_bcs_strtoul.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $"); +#endif /* not lint */ + +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif + +#include <assert.h> +#include <errno.h> +#include <limits.h> +#include <stdint.h> +#include <stdlib.h> + +#include "citrus_namespace.h" +#include "citrus_bcs.h" + +#define _FUNCNAME _bcs_strtoul +#define __UINT unsigned long int +#define __UINT_MAX ULONG_MAX + +#undef isspace +#define isspace(c) _bcs_isspace(c) + +#undef isdigit +#define isdigit(c) _bcs_isdigit(c) + +#undef isalpha +#define isalpha(c) _bcs_isalpha(c) + +#undef isupper +#define isupper(c) _bcs_isupper(c) + +#include "_strtoul.h" diff --git a/lib/libc/citrus/citrus_csmapper.c b/lib/libc/citrus/citrus_csmapper.c index e96fd4763c1..161c5e12f28 100644 --- a/lib/libc/citrus/citrus_csmapper.c +++ b/lib/libc/citrus/citrus_csmapper.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_csmapper.c,v 1.8 2008/02/09 14:56:20 junyoung Exp $ */ +/* $NetBSD: citrus_csmapper.c,v 1.9 2009/01/02 00:20:19 tnozaki Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_csmapper.c,v 1.8 2008/02/09 14:56:20 junyoung Exp $"); +__RCSID("$NetBSD: citrus_csmapper.c,v 1.9 2009/01/02 00:20:19 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -208,7 +208,7 @@ parse_line(struct parse_arg *pa, struct _region *r) "%.*s", (int)(z1.end-z1.begin), z1.begin); snprintf(buf, sizeof(buf), "%.*s", (int)(z2.end-z2.begin), z2.begin); - pa->norm = strtoul(buf, NULL, 0); + pa->norm = _bcs_strtoul(buf, NULL, 0); return 0; } diff --git a/lib/libc/citrus/citrus_fix_grouping.h b/lib/libc/citrus/citrus_fix_grouping.h new file mode 100644 index 00000000000..7c461d5114c --- /dev/null +++ b/lib/libc/citrus/citrus_fix_grouping.h @@ -0,0 +1,55 @@ +/* $NetBSD: citrus_fix_grouping.h,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _CITRUS_FIX_GROUPING_H_ +#define _CITRUS_FIX_GROUPING_H_ + +#define _CITRUS_LC_GROUPING_VALUE_MIN 0 +#define _CITRUS_LC_GROUPING_VALUE_MAX 126 +#define _CITRUS_LC_GROUPING_VALUE_NO_FUTHER 127 + +#if CHAR_MAX != _CITRUS_LC_GROUPING_VALUE_NO_FUTHER +static __inline void +_citrus_fixup_char_max_md(char *grouping) +{ + char *p; + + _DIAGASSERT(grouping != NULL); + + for (p = grouping; *p != '\0'; ++p) { + if (*p == _CITRUS_LC_GROUPING_VALUE_NO_FUTHER) + *p = (char)CHAR_MAX; + } +} +#define _CITRUS_FIXUP_CHAR_MAX_MD(grouping) \ + _citrus_fixup_char_max_md(__UNCONST(grouping)) +#else +#define _CITRUS_FIXUP_CHAR_MAX_MD(grouping) /* nothing to do */ +#endif + +#endif /*_CITRUS_FIX_GROUPING_H_*/ diff --git a/lib/libc/citrus/citrus_lc_ctype.c b/lib/libc/citrus/citrus_lc_ctype.c new file mode 100644 index 00000000000..158491ab2fe --- /dev/null +++ b/lib/libc/citrus/citrus_lc_ctype.c @@ -0,0 +1,150 @@ +/* $NetBSD: citrus_lc_ctype.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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: citrus_lc_ctype.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "reentrant.h" +#include <sys/types.h> +#include <sys/queue.h> +#include <assert.h> +#include <ctype.h> +#include <errno.h> +#include <langinfo.h> +#include <limits.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <wchar.h> + +#include "setlocale_local.h" + +#include "citrus_namespace.h" +#include "citrus_bcs.h" +#include "citrus_region.h" +#include "citrus_lookup.h" +#include "citrus_aliasname_local.h" +#include "citrus_module.h" +#include "citrus_ctype.h" + +#include "rune.h" +#include "rune_local.h" +#include "multibyte.h" + +/* + * macro required by all template headers + */ +#define _PREFIX(name) __CONCAT(_citrus_LC_CTYPE_, name) + +/* + * macro required by nb_lc_template(_decl).h + */ +#define _CATEGORY_TYPE _RuneLocale + +#include "nb_lc_template_decl.h" + +static int +_citrus_LC_CTYPE_create_impl(const char * __restrict root, + const char * __restrict name, _RuneLocale ** __restrict pdata) +{ + char path[PATH_MAX + 1]; + FILE *fp; + _RuneLocale *data; + int ret; + + _DIAGASSERT(root != NULL); + _DIAGASSERT(name != NULL); + _DIAGASSERT(pdata != NULL); + + snprintf(path, sizeof(path), + "%s/%s/LC_CTYPE", root, name); + fp = fopen(path, "r"); + if (fp == NULL) + return ENOENT; + data = _Read_RuneMagi(fp); + if (data == NULL) { + data = _Read_CTypeAsRune(fp); + if (data == NULL) { + fclose(fp); + return EFTYPE; + } + } + fclose(fp); + ret = _citrus_ctype_open(&data->rl_citrus_ctype, data->rl_encoding, + data->rl_variable, data->rl_variable_len, _PRIVSIZE); + if (!ret) + ret = __runetable_to_netbsd_ctype(data); + if (ret || __MB_LEN_MAX_RUNTIME < + _citrus_ctype_get_mb_cur_max(data->rl_citrus_ctype)) { + _NukeRune(data); + return EINVAL; + } + *pdata = data; + return 0; +} + +static __inline void +_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache, + _RuneLocale * __restrict data) +{ + _DIAGASSERT(cache != NULL); + _DIAGASSERT(data != NULL); + + cache->ctype_tab = data->rl_ctype_tab; + cache->tolower_tab = data->rl_tolower_tab; + cache->toupper_tab = data->rl_toupper_tab; + cache->mb_cur_max = _citrus_ctype_get_mb_cur_max(data->rl_citrus_ctype); + cache->items[(size_t)CODESET] = data->rl_codeset; +} + +static __inline void +_PREFIX(fixup)(_RuneLocale *data) +{ + _DIAGASSERT(data != NULL); + + __mb_cur_max = _citrus_ctype_get_mb_cur_max(data->rl_citrus_ctype); + _ctype_ = data->rl_ctype_tab; + _tolower_tab_ = data->rl_tolower_tab; + _toupper_tab_ = data->rl_toupper_tab; + _CurrentRuneLocale = data; +} + +/* + * macro required by nb_lc_template.h + */ +#define _CATEGORY_ID LC_CTYPE +#define _CATEGORY_NAME "LC_CTYPE" +#define _CATEGORY_DEFAULT _DefaultRuneLocale + +#include "nb_lc_template.h" +_LOCALE_CATEGORY_ENTRY(_citrus_LC_CTYPE_); diff --git a/lib/libc/citrus/citrus_lc_messages.c b/lib/libc/citrus/citrus_lc_messages.c new file mode 100644 index 00000000000..8a941322cba --- /dev/null +++ b/lib/libc/citrus/citrus_lc_messages.c @@ -0,0 +1,163 @@ +/* $NetBSD: citrus_lc_messages.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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: citrus_lc_messages.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include "reentrant.h" +#include <sys/types.h> +#include <sys/localedef.h> +#include <sys/queue.h> +#include <assert.h> +#include <errno.h> +#include <langinfo.h> +#include <limits.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "setlocale_local.h" + +#include "citrus_namespace.h" +#include "citrus_types.h" +#include "citrus_bcs.h" +#include "citrus_region.h" +#include "citrus_lookup.h" +#include "citrus_aliasname_local.h" +#include "citrus_module.h" +#include "citrus_mmap.h" +#include "citrus_hash.h" +#include "citrus_db.h" +#include "citrus_db_hash.h" +#include "citrus_memstream.h" +#include "rune.h" + +/* + * macro required by all template headers + */ +#define _PREFIX(name) __CONCAT(_citrus_LC_MESSAGES_, name) + +#include "nb_lc_messages_misc.h" +#include "citrus_lc_template_decl.h" + +static __inline void +_citrus_LC_MESSAGES_uninit(_MessagesLocale *data) +{ + free(__UNCONST(data->yesexpr)); + free(__UNCONST(data->noexpr)); + free(__UNCONST(data->yesstr)); + free(__UNCONST(data->nostr)); +} + +#include "citrus_lc_messages.h" + +struct _citrus_LC_MESSAGES_key { + const char *name; + size_t offset; +}; + +#define OFFSET(field) (offsetof(_MessagesLocale, field)) +static const struct _citrus_LC_MESSAGES_key keys[] = { + { _CITRUS_LC_MESSAGES_SYM_YESEXPR, OFFSET(yesexpr) }, + { _CITRUS_LC_MESSAGES_SYM_NOEXPR, OFFSET(noexpr ) }, + { _CITRUS_LC_MESSAGES_SYM_YESSTR, OFFSET(yesstr ) }, + { _CITRUS_LC_MESSAGES_SYM_NOSTR, OFFSET(nostr ) }, + { NULL, 0 } +}; + +static __inline int +_citrus_LC_MESSAGES_init_normal(_MessagesLocale * __restrict data, + struct _citrus_db * __restrict db) +{ + const struct _citrus_LC_MESSAGES_key *key; + char **p; + const char *s; + + _DIAGASSERT(data != NULL); + _DIAGASSERT(db != NULL); + + memset(data, 0, sizeof(*data)); + for (key = &keys[0]; key->name != NULL; ++key) { + if (_db_lookupstr_by_s(db, key->name, &s, NULL)) + goto fatal; + p = (char **)(void *) + (((char *)(void *)data) + key->offset); + *p = strdup(s); + if (*p == NULL) + goto fatal; + } + return 0; + +fatal: + _citrus_LC_MESSAGES_uninit(data); + return EFTYPE; +} + +static __inline int +_citrus_LC_MESSAGES_init_fallback(_MessagesLocale * __restrict data, + struct _memstream * __restrict ms) +{ + const struct _citrus_LC_MESSAGES_key *key; + char **p; + const char *s; + size_t n; + + _DIAGASSERT(data != NULL); + _DIAGASSERT(ms != NULL); + + memset(data, 0, sizeof(*data)); + for (key = &keys[0]; key->name != NULL; ++key) { + if ((s = _memstream_getln(ms, &n)) == NULL) + goto fatal; + p = (char **)(void *) + (((char *)(void *)data) + key->offset); + *p = strndup(s, n - 1); + if (*p == NULL) + goto fatal; + } + return 0; + +fatal: + _citrus_LC_MESSAGES_uninit(data); + return EFTYPE; +} + +/* + * macro required by citrus_lc_template.h + */ +#define _CATEGORY_DB "LC_MESSAGES/SYS_LC_MESSAGES" +#define _CATEGORY_MAGIC _CITRUS_LC_MESSAGES_MAGIC_1 + +#include "citrus_lc_template.h" +_LOCALE_CATEGORY_ENTRY(_citrus_LC_MESSAGES_); diff --git a/lib/libc/citrus/citrus_lc_messages.h b/lib/libc/citrus/citrus_lc_messages.h new file mode 100644 index 00000000000..cc384299412 --- /dev/null +++ b/lib/libc/citrus/citrus_lc_messages.h @@ -0,0 +1,47 @@ +/* $NetBSD: citrus_lc_messages.h,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _CITRUS_LC_MESSAGES_H_ +#define _CITRUS_LC_MESSAGES_H_ + +/* + * + */ +#define _CITRUS_LC_MESSAGES_MAGIC_1 "CtrsME10" +#define _CITRUS_LC_MESSAGES_SYM_VERSION "version" +#define _CITRUS_LC_MESSAGES_VERSION 0x00000001 + +/* + * + */ +#define _CITRUS_LC_MESSAGES_SYM_YESEXPR "yesexpr" +#define _CITRUS_LC_MESSAGES_SYM_NOEXPR "noexpr" +#define _CITRUS_LC_MESSAGES_SYM_YESSTR "yesstr" +#define _CITRUS_LC_MESSAGES_SYM_NOSTR "nostr" + +#endif /*_CITRUS_LC_MESSAGES_H_*/ diff --git a/lib/libc/citrus/citrus_lc_monetary.c b/lib/libc/citrus/citrus_lc_monetary.c new file mode 100644 index 00000000000..c01708ed1c5 --- /dev/null +++ b/lib/libc/citrus/citrus_lc_monetary.c @@ -0,0 +1,220 @@ +/* $NetBSD: citrus_lc_monetary.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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: citrus_lc_monetary.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include "reentrant.h" +#include <sys/types.h> +#include <sys/localedef.h> +#include <sys/queue.h> +#include <assert.h> +#include <errno.h> +#include <langinfo.h> +#include <limits.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "setlocale_local.h" + +#include "citrus_namespace.h" +#include "citrus_types.h" +#include "citrus_bcs.h" +#include "citrus_region.h" +#include "citrus_lookup.h" +#include "citrus_aliasname_local.h" +#include "citrus_module.h" +#include "citrus_mmap.h" +#include "citrus_hash.h" +#include "citrus_db.h" +#include "citrus_db_hash.h" +#include "citrus_memstream.h" +#include "rune.h" + +#include "fix_grouping.h" +#include "citrus_fix_grouping.h" + +/* + * macro required by all template headers + */ +#define _PREFIX(name) __CONCAT(_citrus_LC_MONETARY_, name) + +#include "nb_lc_monetary_misc.h" +#include "citrus_lc_template_decl.h" + +static __inline void +_citrus_LC_MONETARY_uninit(_MonetaryLocale *data) +{ + _DIAGASSERT(data != NULL); + + free(__UNCONST(data->int_curr_symbol)); + free(__UNCONST(data->currency_symbol)); + free(__UNCONST(data->mon_decimal_point)); + free(__UNCONST(data->mon_thousands_sep)); + free(__UNCONST(data->mon_grouping)); + free(__UNCONST(data->positive_sign)); + free(__UNCONST(data->negative_sign)); +} + +#include "citrus_lc_monetary.h" + +struct _citrus_LC_MONETARY_key { + const char *name; + size_t offset; +}; + +#define OFFSET(field) (offsetof(_MonetaryLocale, field)) +static const struct _citrus_LC_MONETARY_key keys_string[] = { + { _CITRUS_LC_MONETARY_SYM_INT_CURR_SYMBOL, OFFSET(int_curr_symbol ) }, + { _CITRUS_LC_MONETARY_SYM_CURRENCY_SYMBOL, OFFSET(currency_symbol ) }, + { _CITRUS_LC_MONETARY_SYM_MON_DECIMAL_POINT, OFFSET(mon_decimal_point ) }, + { _CITRUS_LC_MONETARY_SYM_MON_THOUSANDS_SEP, OFFSET(mon_thousands_sep ) }, + { _CITRUS_LC_MONETARY_SYM_MON_GROUPING, OFFSET(mon_grouping ) }, + { _CITRUS_LC_MONETARY_SYM_POSITIVE_SIGN, OFFSET(positive_sign ) }, + { _CITRUS_LC_MONETARY_SYM_NEGATIVE_SIGN, OFFSET(negative_sign ) }, + { NULL, (size_t)0 } +}; +static const struct _citrus_LC_MONETARY_key keys_char[] = { + { _CITRUS_LC_MONETARY_SYM_INT_FRAC_DIGITS, OFFSET(int_frac_digits ) }, + { _CITRUS_LC_MONETARY_SYM_FRAC_DIGITS, OFFSET(frac_digits ) }, + { _CITRUS_LC_MONETARY_SYM_P_CS_PRECEDES, OFFSET(p_cs_precedes ) }, + { _CITRUS_LC_MONETARY_SYM_P_SEP_BY_SPACE, OFFSET(p_sep_by_space ) }, + { _CITRUS_LC_MONETARY_SYM_N_CS_PRECEDES, OFFSET(n_cs_precedes ) }, + { _CITRUS_LC_MONETARY_SYM_N_SEP_BY_SPACE, OFFSET(n_sep_by_space ) }, + { _CITRUS_LC_MONETARY_SYM_P_SIGN_POSN, OFFSET(p_sign_posn ) }, + { _CITRUS_LC_MONETARY_SYM_N_SIGN_POSN, OFFSET(n_sign_posn ) }, + { _CITRUS_LC_MONETARY_SYM_INT_P_CS_PRECEDES, OFFSET(int_p_cs_precedes ) }, + { _CITRUS_LC_MONETARY_SYM_INT_N_CS_PRECEDES, OFFSET(int_n_cs_precedes ) }, + { _CITRUS_LC_MONETARY_SYM_INT_P_SEP_BY_SPACE, OFFSET(int_p_sep_by_space) }, + { _CITRUS_LC_MONETARY_SYM_INT_N_SEP_BY_SPACE, OFFSET(int_n_sep_by_space) }, + { _CITRUS_LC_MONETARY_SYM_INT_P_SIGN_POSN, OFFSET(int_p_sign_posn ) }, + { _CITRUS_LC_MONETARY_SYM_INT_N_SIGN_POSN, OFFSET(int_n_sign_posn ) }, + { NULL, (size_t)0 } +}; + +static __inline int +_citrus_LC_MONETARY_init_normal(_MonetaryLocale * __restrict data, + struct _citrus_db * __restrict db) +{ + const struct _citrus_LC_MONETARY_key *key; + char **p_string, *p_char; + const char *s; + uint8_t u8; + + _DIAGASSERT(data != NULL); + _DIAGASSERT(db != NULL); + + memset(data, 0, sizeof(*data)); + for (key = &keys_string[0]; key->name != NULL; ++key) { + if (_db_lookupstr_by_s(db, key->name, &s, NULL)) + goto fatal; + p_string = (char **)(void *) + (((char *)(void *)data) + key->offset); + *p_string = strdup(s); + if (*p_string == NULL) + goto fatal; + } + for (key = &keys_char[0]; key->name != NULL; ++key) { + if (_db_lookup8_by_s(db, key->name, &u8, NULL)) + goto fatal; + p_char = ((char *)(void *)data) + key->offset; + *p_char = (char)(unsigned char)u8; + } + _CITRUS_FIXUP_CHAR_MAX_MD(data->mon_grouping); + + return 0; + +fatal: + _citrus_LC_MONETARY_uninit(data); + return EFTYPE; +} + +static __inline int +_citrus_LC_MONETARY_init_fallback(_MonetaryLocale * __restrict data, + struct _memstream * __restrict ms) +{ + const struct _citrus_LC_MONETARY_key *key; + char **p_string, *p_char; + const char *s; + size_t n; + char *t; + long int l; + + _DIAGASSERT(data != NULL); + _DIAGASSERT(ms != NULL); + + memset(data, 0, sizeof(*data)); + for (key = &keys_string[0]; key->name != NULL; ++key) { + if ((s = _memstream_getln(ms, &n)) == NULL) + goto fatal; + p_string = (char **)(void *) + (((char *)(void *)data) + key->offset); + *p_string = strndup(s, n - 1); + if (*p_string == NULL) + goto fatal; + } + for (key = &keys_char[0]; key->name != NULL; ++key) { + if ((s = _memstream_getln(ms, &n)) == NULL) + goto fatal; + t = strndup(s, n - 1); + if (t == NULL) + goto fatal; + s = (const char *)t; + l = _bcs_strtol(s, &t, 0); + if (s == t || l < 0 || l > 0x7fL) { + free(t); + goto fatal; + } + free(t); + p_char = ((char *)(void *)data) + key->offset; + *p_char = (char)(l & 0x7fL); + } + data->mon_grouping = + __fix_locale_grouping_str(data->mon_grouping); + return 0; + +fatal: + _citrus_LC_MONETARY_uninit(data); + return EFTYPE; +} + +/* + * macro required by citrus_lc_template.h + */ +#define _CATEGORY_DB "LC_MONETARY" +#define _CATEGORY_MAGIC _CITRUS_LC_MONETARY_MAGIC_1 + +#include "citrus_lc_template.h" +_LOCALE_CATEGORY_ENTRY(_citrus_LC_MONETARY_); diff --git a/lib/libc/citrus/citrus_lc_monetary.h b/lib/libc/citrus/citrus_lc_monetary.h new file mode 100644 index 00000000000..5cd67f896a1 --- /dev/null +++ b/lib/libc/citrus/citrus_lc_monetary.h @@ -0,0 +1,64 @@ +/* $NetBSD: citrus_lc_monetary.h,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _CITRUS_LC_MONETARY_H_ +#define _CITRUS_LC_MONETARY_H_ + +/* + * + */ +#define _CITRUS_LC_MONETARY_MAGIC_1 "CtrsMO10" +#define _CITRUS_LC_MONETARY_SYM_VERSION "version" +#define _CITRUS_LC_MONETARY_VERSION 0x00000001 + +/* + * + */ +#define _CITRUS_LC_MONETARY_SYM_INT_CURR_SYMBOL "int_curr_symbol" +#define _CITRUS_LC_MONETARY_SYM_CURRENCY_SYMBOL "currency_symbol" +#define _CITRUS_LC_MONETARY_SYM_MON_DECIMAL_POINT "mon_decimal_point" +#define _CITRUS_LC_MONETARY_SYM_MON_THOUSANDS_SEP "mon_thousands_sep" +#define _CITRUS_LC_MONETARY_SYM_MON_GROUPING "mon_grouping" +#define _CITRUS_LC_MONETARY_SYM_POSITIVE_SIGN "positive_sign" +#define _CITRUS_LC_MONETARY_SYM_NEGATIVE_SIGN "negative_sign" +#define _CITRUS_LC_MONETARY_SYM_INT_FRAC_DIGITS "int_frac_digits" +#define _CITRUS_LC_MONETARY_SYM_FRAC_DIGITS "frac_digits" +#define _CITRUS_LC_MONETARY_SYM_P_CS_PRECEDES "p_cs_precedes" +#define _CITRUS_LC_MONETARY_SYM_P_SEP_BY_SPACE "p_sep_by_space" +#define _CITRUS_LC_MONETARY_SYM_N_CS_PRECEDES "n_cs_precedes" +#define _CITRUS_LC_MONETARY_SYM_N_SEP_BY_SPACE "n_sep_by_space" +#define _CITRUS_LC_MONETARY_SYM_P_SIGN_POSN "p_sign_posn" +#define _CITRUS_LC_MONETARY_SYM_N_SIGN_POSN "n_sign_posn" +#define _CITRUS_LC_MONETARY_SYM_INT_P_CS_PRECEDES "int_p_cs_precedes" +#define _CITRUS_LC_MONETARY_SYM_INT_N_CS_PRECEDES "int_n_cs_precedes" +#define _CITRUS_LC_MONETARY_SYM_INT_P_SEP_BY_SPACE "int_p_sep_by_space" +#define _CITRUS_LC_MONETARY_SYM_INT_N_SEP_BY_SPACE "int_n_sep_by_space" +#define _CITRUS_LC_MONETARY_SYM_INT_P_SIGN_POSN "int_p_sign_posn" +#define _CITRUS_LC_MONETARY_SYM_INT_N_SIGN_POSN "int_n_sign_posn" + +#endif /*_CITRUS_LC_MONETARY_H_*/ diff --git a/lib/libc/citrus/citrus_lc_numeric.c b/lib/libc/citrus/citrus_lc_numeric.c new file mode 100644 index 00000000000..3447df51b53 --- /dev/null +++ b/lib/libc/citrus/citrus_lc_numeric.c @@ -0,0 +1,169 @@ +/* $NetBSD: citrus_lc_numeric.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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: citrus_lc_numeric.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include "reentrant.h" +#include <sys/types.h> +#include <sys/localedef.h> +#include <sys/queue.h> +#include <assert.h> +#include <errno.h> +#include <langinfo.h> +#include <limits.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "setlocale_local.h" + +#include "citrus_namespace.h" +#include "citrus_types.h" +#include "citrus_bcs.h" +#include "citrus_region.h" +#include "citrus_lookup.h" +#include "citrus_aliasname_local.h" +#include "citrus_module.h" +#include "citrus_mmap.h" +#include "citrus_hash.h" +#include "citrus_db.h" +#include "citrus_db_hash.h" +#include "citrus_memstream.h" +#include "rune.h" + +#include "fix_grouping.h" +#include "citrus_fix_grouping.h" + +/* + * macro required by all template headers + */ +#define _PREFIX(name) __CONCAT(_citrus_LC_NUMERIC_, name) + +#include "nb_lc_numeric_misc.h" +#include "citrus_lc_template_decl.h" + +static __inline void +_citrus_LC_NUMERIC_uninit(_NumericLocale *data) +{ + free(__UNCONST(data->decimal_point)); + free(__UNCONST(data->thousands_sep)); + free(__UNCONST(data->grouping)); +} + +#include "citrus_lc_numeric.h" + +struct _citrus_LC_NUMERIC_key { + const char *name; + size_t offset; +}; + +#define OFFSET(field) (offsetof(_NumericLocale, field)) +static const struct _citrus_LC_NUMERIC_key keys[] = { + { _CITRUS_LC_NUMERIC_SYM_DECIMAL_POINT, OFFSET(decimal_point) }, + { _CITRUS_LC_NUMERIC_SYM_THOUSANDS_SEP, OFFSET(thousands_sep) }, + { _CITRUS_LC_NUMERIC_SYM_GROUPING, OFFSET(grouping ) }, + { NULL, 0 } +}; + +static __inline int +_citrus_LC_NUMERIC_init_normal(_NumericLocale * __restrict data, + struct _citrus_db * __restrict db) +{ + const struct _citrus_LC_NUMERIC_key *key; + char **p; + const char *s; + + _DIAGASSERT(data != NULL); + _DIAGASSERT(db != NULL); + + memset(data, 0, sizeof(*data)); + for (key = &keys[0]; key->name != NULL; ++key) { + if (_db_lookupstr_by_s(db, key->name, &s, NULL)) + goto fatal; + p = (char **)(void *) + (((char *)(void *)data) + key->offset); + *p = strdup(s); + if (*p == NULL) + goto fatal; + } + _CITRUS_FIXUP_CHAR_MAX_MD(data->grouping); + + return 0; + +fatal: + _citrus_LC_NUMERIC_uninit(data); + return EFTYPE; +} + +static __inline int +_citrus_LC_NUMERIC_init_fallback(_NumericLocale * __restrict data, + struct _memstream * __restrict ms) +{ + const struct _citrus_LC_NUMERIC_key *key; + char **p; + const char *s; + size_t n; + + _DIAGASSERT(data != NULL); + _DIAGASSERT(ms != NULL); + + memset(data, 0, sizeof(*data)); + for (key = &keys[0]; key->name != NULL; ++key) { + if ((s = _memstream_getln(ms, &n)) == NULL) + goto fatal; + p = (char **)(void *) + (((char *)(void *)data) + key->offset); + *p = strndup(s, n - 1); + if (*p == NULL) + goto fatal; + } + data->grouping = + __fix_locale_grouping_str(data->grouping); + + return 0; + +fatal: + _citrus_LC_NUMERIC_uninit(data); + return EFTYPE; +} + +/* + * macro required by citrus_lc_template.h + */ +#define _CATEGORY_DB "LC_NUMERIC" +#define _CATEGORY_MAGIC _CITRUS_LC_NUMERIC_MAGIC_1 + +#include "citrus_lc_template.h" +_LOCALE_CATEGORY_ENTRY(_citrus_LC_NUMERIC_); diff --git a/lib/libc/citrus/citrus_lc_numeric.h b/lib/libc/citrus/citrus_lc_numeric.h new file mode 100644 index 00000000000..9197ec14944 --- /dev/null +++ b/lib/libc/citrus/citrus_lc_numeric.h @@ -0,0 +1,46 @@ +/* $NetBSD: citrus_lc_numeric.h,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _CITRUS_LC_NUMERIC_H_ +#define _CITRUS_LC_NUMERIC_H_ + +/* + * + */ +#define _CITRUS_LC_NUMERIC_MAGIC_1 "CtrsNU10" +#define _CITRUS_LC_NUMERIC_SYM_VERSION "version" +#define _CITRUS_LC_NUMERIC_VERSION 0x00000001 + +/* + * + */ +#define _CITRUS_LC_NUMERIC_SYM_DECIMAL_POINT "decimal_point" +#define _CITRUS_LC_NUMERIC_SYM_THOUSANDS_SEP "thousands_sep" +#define _CITRUS_LC_NUMERIC_SYM_GROUPING "grouping" + +#endif /*_CITRUS_LC_NUMERIC_H_*/ diff --git a/lib/libc/citrus/citrus_lc_template.h b/lib/libc/citrus/citrus_lc_template.h new file mode 100644 index 00000000000..363f5ce3680 --- /dev/null +++ b/lib/libc/citrus/citrus_lc_template.h @@ -0,0 +1,74 @@ +/* $NetBSD: citrus_lc_template.h,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _CITRUS_LC_TEMPLATE_H_ +#define _CITRUS_LC_TEMPLATE_H_ + +static __inline int +_PREFIX(create_impl)(const char * __restrict root, + const char * __restrict name, _CATEGORY_TYPE ** __restrict pdata) +{ + char path[PATH_MAX + 1]; + int ret; + struct _region file; + struct _citrus_db *db; + struct _memstream ms; + _CATEGORY_TYPE *data; + + snprintf(path, sizeof(path), + "%s/%s/" _CATEGORY_DB, root, name); + ret = _map_file(&file, path); + if (ret) { + ret = ENOENT; + } else { + data = malloc(sizeof(*data)); + if (!data) { + ret = ENOMEM; + } else { + ret = _db_open(&db, &file, _CATEGORY_MAGIC, + &_db_hash_std, NULL); + if (!ret) { + ret = _PREFIX(init_normal)(data, db); + _db_close(db); + } else { + _memstream_bind(&ms, &file); + ret = _PREFIX(init_fallback)(data, &ms); + } + if (!ret) + *pdata = data; + else + free(data); + } + _unmap_file(&file); + } + return ret; +} + +#include "nb_lc_template.h" + +#endif /* _CITRUS_LC_TEMPLATE_H_ */ diff --git a/lib/libc/citrus/citrus_lc_template_decl.h b/lib/libc/citrus/citrus_lc_template_decl.h new file mode 100644 index 00000000000..e4abbfdb8ea --- /dev/null +++ b/lib/libc/citrus/citrus_lc_template_decl.h @@ -0,0 +1,42 @@ +/* $NetBSD: citrus_lc_template_decl.h,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _CITRUS_LC_TEMPLATE_DECL_H_ +#define _CITRUS_LC_TEMPLATE_DECL_H_ + +#include "nb_lc_template_decl.h" + +static __inline int +_PREFIX(init_normal)(_CATEGORY_TYPE * __restrict, + struct _citrus_db * __restrict db); + +static __inline int +_PREFIX(init_fallback)(_CATEGORY_TYPE * __restrict, + struct _memstream * __restrict); + +#endif /*_CITRUS_LC_TEMPLATE_DECL_H_*/ diff --git a/lib/libc/citrus/citrus_lc_time.c b/lib/libc/citrus/citrus_lc_time.c new file mode 100644 index 00000000000..134b9d16a15 --- /dev/null +++ b/lib/libc/citrus/citrus_lc_time.c @@ -0,0 +1,214 @@ +/* $NetBSD: citrus_lc_time.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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: citrus_lc_time.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include "reentrant.h" +#include <sys/types.h> +#include <sys/localedef.h> +#include <sys/queue.h> +#include <assert.h> +#include <errno.h> +#include <langinfo.h> +#include <limits.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "setlocale_local.h" + +#include "citrus_namespace.h" +#include "citrus_types.h" +#include "citrus_bcs.h" +#include "citrus_region.h" +#include "citrus_lookup.h" +#include "citrus_aliasname_local.h" +#include "citrus_module.h" +#include "citrus_mmap.h" +#include "citrus_hash.h" +#include "citrus_db.h" +#include "citrus_db_hash.h" +#include "citrus_memstream.h" +#include "rune.h" + +/* + * macro required by all template headers + */ +#define _PREFIX(name) __CONCAT(_citrus_LC_TIME_, name) + +#include "nb_lc_time_misc.h" +#include "citrus_lc_template_decl.h" + +static __inline void +_citrus_LC_TIME_uninit(_TimeLocale *data) +{ + size_t i, j; + + _DIAGASSERT(data != NULL); + + for (i = ABDAY_IDX(ABDAY_1), j = ABDAY_IDX(ABDAY_7); i <= j; ++i) + free(__UNCONST(data->abday[i])); + for (i = DAY_IDX(DAY_1), j = DAY_IDX(DAY_7); i <= j; ++i) + free(__UNCONST(data->day[i])); + for (i = ABMON_IDX(ABMON_1), j = ABMON_IDX(ABMON_12); i <= j; ++i) + free(__UNCONST(data->abmon[i])); + for (i = MON_IDX(MON_1), j = MON_IDX(MON_12); i <= j; ++i) + free(__UNCONST(data->mon[i])); + for (i = AM_PM_IDX(AM_STR), j = AM_PM_IDX(PM_STR); i <= j; ++i) + free(__UNCONST(data->am_pm[i])); + free(__UNCONST(data->d_t_fmt)); + free(__UNCONST(data->d_fmt)); + free(__UNCONST(data->t_fmt)); + free(__UNCONST(data->t_fmt_ampm)); +} + +#include "citrus_lc_time.h" + +struct _citrus_LC_TIME_key { + const char *name; + size_t offset; +}; + +#define OFFSET(field) offsetof(_TimeLocale, field) +static const struct _citrus_LC_TIME_key keys[] = { + { _CITRUS_LC_TIME_SYM_ABDAY_1, OFFSET(abday[ABDAY_IDX(ABDAY_1)] ) }, + { _CITRUS_LC_TIME_SYM_ABDAY_2, OFFSET(abday[ABDAY_IDX(ABDAY_2)] ) }, + { _CITRUS_LC_TIME_SYM_ABDAY_3, OFFSET(abday[ABDAY_IDX(ABDAY_3)] ) }, + { _CITRUS_LC_TIME_SYM_ABDAY_4, OFFSET(abday[ABDAY_IDX(ABDAY_4)] ) }, + { _CITRUS_LC_TIME_SYM_ABDAY_5, OFFSET(abday[ABDAY_IDX(ABDAY_5)] ) }, + { _CITRUS_LC_TIME_SYM_ABDAY_6, OFFSET(abday[ABDAY_IDX(ABDAY_6)] ) }, + { _CITRUS_LC_TIME_SYM_ABDAY_7, OFFSET(abday[ABDAY_IDX(ABDAY_7)] ) }, + { _CITRUS_LC_TIME_SYM_DAY_1, OFFSET(day[DAY_IDX(DAY_1)] ) }, + { _CITRUS_LC_TIME_SYM_DAY_2, OFFSET(day[DAY_IDX(DAY_2)] ) }, + { _CITRUS_LC_TIME_SYM_DAY_3, OFFSET(day[DAY_IDX(DAY_3)] ) }, + { _CITRUS_LC_TIME_SYM_DAY_4, OFFSET(day[DAY_IDX(DAY_4)] ) }, + { _CITRUS_LC_TIME_SYM_DAY_5, OFFSET(day[DAY_IDX(DAY_5)] ) }, + { _CITRUS_LC_TIME_SYM_DAY_6, OFFSET(day[DAY_IDX(DAY_6)] ) }, + { _CITRUS_LC_TIME_SYM_DAY_7, OFFSET(day[DAY_IDX(DAY_7)] ) }, + { _CITRUS_LC_TIME_SYM_ABMON_1, OFFSET(abmon[ABMON_IDX(ABMON_1)] ) }, + { _CITRUS_LC_TIME_SYM_ABMON_2, OFFSET(abmon[ABMON_IDX(ABMON_2)] ) }, + { _CITRUS_LC_TIME_SYM_ABMON_3, OFFSET(abmon[ABMON_IDX(ABMON_3)] ) }, + { _CITRUS_LC_TIME_SYM_ABMON_4, OFFSET(abmon[ABMON_IDX(ABMON_4)] ) }, + { _CITRUS_LC_TIME_SYM_ABMON_5, OFFSET(abmon[ABMON_IDX(ABMON_5)] ) }, + { _CITRUS_LC_TIME_SYM_ABMON_6, OFFSET(abmon[ABMON_IDX(ABMON_6)] ) }, + { _CITRUS_LC_TIME_SYM_ABMON_7, OFFSET(abmon[ABMON_IDX(ABMON_7)] ) }, + { _CITRUS_LC_TIME_SYM_ABMON_8, OFFSET(abmon[ABMON_IDX(ABMON_8)] ) }, + { _CITRUS_LC_TIME_SYM_ABMON_9, OFFSET(abmon[ABMON_IDX(ABMON_9)] ) }, + { _CITRUS_LC_TIME_SYM_ABMON_10, OFFSET(abmon[ABMON_IDX(ABMON_10)]) }, + { _CITRUS_LC_TIME_SYM_ABMON_11, OFFSET(abmon[ABMON_IDX(ABMON_11)]) }, + { _CITRUS_LC_TIME_SYM_ABMON_12, OFFSET(abmon[ABMON_IDX(ABMON_12)]) }, + { _CITRUS_LC_TIME_SYM_MON_1, OFFSET(mon[MON_IDX(MON_1)] ) }, + { _CITRUS_LC_TIME_SYM_MON_2, OFFSET(mon[MON_IDX(MON_2)] ) }, + { _CITRUS_LC_TIME_SYM_MON_3, OFFSET(mon[MON_IDX(MON_3)] ) }, + { _CITRUS_LC_TIME_SYM_MON_4, OFFSET(mon[MON_IDX(MON_4)] ) }, + { _CITRUS_LC_TIME_SYM_MON_5, OFFSET(mon[MON_IDX(MON_5)] ) }, + { _CITRUS_LC_TIME_SYM_MON_6, OFFSET(mon[MON_IDX(MON_6)] ) }, + { _CITRUS_LC_TIME_SYM_MON_7, OFFSET(mon[MON_IDX(MON_7)] ) }, + { _CITRUS_LC_TIME_SYM_MON_8, OFFSET(mon[MON_IDX(MON_8)] ) }, + { _CITRUS_LC_TIME_SYM_MON_9, OFFSET(mon[MON_IDX(MON_9)] ) }, + { _CITRUS_LC_TIME_SYM_MON_10, OFFSET(mon[MON_IDX(MON_10)] ) }, + { _CITRUS_LC_TIME_SYM_MON_11, OFFSET(mon[MON_IDX(MON_11)] ) }, + { _CITRUS_LC_TIME_SYM_MON_12, OFFSET(mon[MON_IDX(MON_12)] ) }, + { _CITRUS_LC_TIME_SYM_AM_STR, OFFSET(am_pm[AM_PM_IDX(AM_STR)] ) }, + { _CITRUS_LC_TIME_SYM_PM_STR, OFFSET(am_pm[AM_PM_IDX(PM_STR)] ) }, + { _CITRUS_LC_TIME_SYM_D_T_FMT, OFFSET(d_t_fmt ) }, + { _CITRUS_LC_TIME_SYM_D_FMT, OFFSET(d_fmt ) }, + { _CITRUS_LC_TIME_SYM_T_FMT, OFFSET(t_fmt ) }, + { _CITRUS_LC_TIME_SYM_T_FMT, OFFSET(t_fmt_ampm ) }, + { NULL, 0 } +}; + +static __inline int +_citrus_LC_TIME_init_normal(_TimeLocale * __restrict data, + struct _citrus_db * __restrict db) +{ + const struct _citrus_LC_TIME_key *key; + char **p; + const char *s; + + _DIAGASSERT(data != NULL); + _DIAGASSERT(db != NULL); + + memset(data, 0, sizeof(*data)); + for (key = &keys[0]; key->name != NULL; ++key) { + if (_db_lookupstr_by_s(db, key->name, &s, NULL)) + goto fatal; + p = (char **)(void *) + (((char *)(void *)data) + key->offset); + *p = strdup(s); + if (*p == NULL) + goto fatal; + } + return 0; + +fatal: + _citrus_LC_TIME_uninit(data); + return EFTYPE; +} + +static __inline int +_citrus_LC_TIME_init_fallback(_TimeLocale * __restrict data, + struct _memstream * __restrict ms) +{ + const struct _citrus_LC_TIME_key *key; + char **p; + const char *s; + size_t n; + + memset(data, 0, sizeof(*data)); + for (key = &keys[0]; key->name != NULL; ++key) { + if ((s = _memstream_getln(ms, &n)) == NULL) + goto fatal; + p = (char **)(void *) + (((char *)(void *)data) + key->offset); + *p = strndup(s, n - 1); + if (*p == NULL) + goto fatal; + } + return 0; + +fatal: + _citrus_LC_TIME_uninit(data); + return EFTYPE; +} + +/* + * macro required by citrus_lc_template.h + */ +#define _CATEGORY_DB "LC_TIME" +#define _CATEGORY_MAGIC _CITRUS_LC_TIME_MAGIC_1 + +#include "citrus_lc_template.h" +_LOCALE_CATEGORY_ENTRY(_citrus_LC_TIME_); diff --git a/lib/libc/citrus/citrus_lc_time.h b/lib/libc/citrus/citrus_lc_time.h new file mode 100644 index 00000000000..a750d6f74d3 --- /dev/null +++ b/lib/libc/citrus/citrus_lc_time.h @@ -0,0 +1,87 @@ +/* $NetBSD: citrus_lc_time.h,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _CITRUS_LC_TIME_H_ +#define _CITRUS_LC_TIME_H_ + +/* + * + */ +#define _CITRUS_LC_TIME_MAGIC_1 "CtrsTI10" +#define _CITRUS_LC_TIME_SYM_VERSION "version" +#define _CITRUS_LC_TIME_VERSION 0x00000001 + +/* + * + */ +#define _CITRUS_LC_TIME_SYM_ABDAY_1 "abday1" +#define _CITRUS_LC_TIME_SYM_ABDAY_2 "abday2" +#define _CITRUS_LC_TIME_SYM_ABDAY_3 "abday3" +#define _CITRUS_LC_TIME_SYM_ABDAY_4 "abday4" +#define _CITRUS_LC_TIME_SYM_ABDAY_5 "abday5" +#define _CITRUS_LC_TIME_SYM_ABDAY_6 "abday6" +#define _CITRUS_LC_TIME_SYM_ABDAY_7 "abday7" +#define _CITRUS_LC_TIME_SYM_DAY_1 "day1" +#define _CITRUS_LC_TIME_SYM_DAY_2 "day2" +#define _CITRUS_LC_TIME_SYM_DAY_3 "day3" +#define _CITRUS_LC_TIME_SYM_DAY_4 "day4" +#define _CITRUS_LC_TIME_SYM_DAY_5 "day5" +#define _CITRUS_LC_TIME_SYM_DAY_6 "day6" +#define _CITRUS_LC_TIME_SYM_DAY_7 "day7" +#define _CITRUS_LC_TIME_SYM_ABMON_1 "abmon_1" +#define _CITRUS_LC_TIME_SYM_ABMON_2 "abmon_2" +#define _CITRUS_LC_TIME_SYM_ABMON_3 "abmon_3" +#define _CITRUS_LC_TIME_SYM_ABMON_4 "abmon_4" +#define _CITRUS_LC_TIME_SYM_ABMON_5 "abmon_5" +#define _CITRUS_LC_TIME_SYM_ABMON_6 "abmon_6" +#define _CITRUS_LC_TIME_SYM_ABMON_7 "abmon_7" +#define _CITRUS_LC_TIME_SYM_ABMON_8 "abmon_8" +#define _CITRUS_LC_TIME_SYM_ABMON_9 "abmon_9" +#define _CITRUS_LC_TIME_SYM_ABMON_10 "abmon_10" +#define _CITRUS_LC_TIME_SYM_ABMON_11 "abmon_11" +#define _CITRUS_LC_TIME_SYM_ABMON_12 "abmon_12" +#define _CITRUS_LC_TIME_SYM_MON_1 "mon_1" +#define _CITRUS_LC_TIME_SYM_MON_2 "mon_2" +#define _CITRUS_LC_TIME_SYM_MON_3 "mon_3" +#define _CITRUS_LC_TIME_SYM_MON_4 "mon_4" +#define _CITRUS_LC_TIME_SYM_MON_5 "mon_5" +#define _CITRUS_LC_TIME_SYM_MON_6 "mon_6" +#define _CITRUS_LC_TIME_SYM_MON_7 "mon_7" +#define _CITRUS_LC_TIME_SYM_MON_8 "mon_8" +#define _CITRUS_LC_TIME_SYM_MON_9 "mon_9" +#define _CITRUS_LC_TIME_SYM_MON_10 "mon_10" +#define _CITRUS_LC_TIME_SYM_MON_11 "mon_11" +#define _CITRUS_LC_TIME_SYM_MON_12 "mon_12" +#define _CITRUS_LC_TIME_SYM_AM_STR "am_str" +#define _CITRUS_LC_TIME_SYM_PM_STR "pm_str" +#define _CITRUS_LC_TIME_SYM_D_T_FMT "d_t_fmt" +#define _CITRUS_LC_TIME_SYM_D_FMT "d_fmt" +#define _CITRUS_LC_TIME_SYM_T_FMT "t_fmt" +#define _CITRUS_LC_TIME_SYM_T_FMT_AMPM "t_fmt_ampm" + +#endif /*_CITRUS_LC_TIME_H_*/ diff --git a/lib/libc/citrus/citrus_module.c b/lib/libc/citrus/citrus_module.c index c629b889c9c..a09b6e8583f 100644 --- a/lib/libc/citrus/citrus_module.c +++ b/lib/libc/citrus/citrus_module.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_module.c,v 1.7 2008/06/14 16:01:07 tnozaki Exp $ */ +/* $NetBSD: citrus_module.c,v 1.8 2009/01/02 00:20:19 tnozaki Exp $ */ /*- * Copyright (c)1999, 2000, 2001, 2002 Citrus Project, @@ -89,7 +89,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_module.c,v 1.7 2008/06/14 16:01:07 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_module.c,v 1.8 2009/01/02 00:20:19 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include <assert.h> @@ -101,6 +101,8 @@ __RCSID("$NetBSD: citrus_module.c,v 1.7 2008/06/14 16:01:07 tnozaki Exp $"); #include <unistd.h> #include <stddef.h> #include <paths.h> +#include "citrus_namespace.h" +#include "citrus_bcs.h" #include "citrus_module.h" #include <sys/types.h> @@ -136,7 +138,7 @@ _getdewey(int dewey[], char *cp) if (*cp < '0' || '9' < *cp) return 0; - dewey[n++] = (int)strtol(cp, &cp, 10); + dewey[n++] = (int)_bcs_strtol(cp, &cp, 10); } return n; diff --git a/lib/libc/citrus/citrus_namespace.h b/lib/libc/citrus/citrus_namespace.h index 7686791f8ea..5747e6685e2 100644 --- a/lib/libc/citrus/citrus_namespace.h +++ b/lib/libc/citrus/citrus_namespace.h @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_namespace.h,v 1.6 2005/10/29 18:02:04 tshiozak Exp $ */ +/* $NetBSD: citrus_namespace.h,v 1.7 2009/01/02 00:20:19 tnozaki Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -56,6 +56,8 @@ #define _bcs_trunc_rws_len _citrus_bcs_trunc_rws_len #define _bcs_convert_to_lower _citrus_bcs_convert_to_lower #define _bcs_convert_to_upper _citrus_bcs_convert_to_upper +#define _bcs_strtol _citrus_bcs_strtol +#define _bcs_strtoul _citrus_bcs_strtoul #endif /* _CITRUS_BCS_NO_NAMESPACE */ /* citrus_csmapper */ diff --git a/lib/libc/citrus/modules/citrus_euc.c b/lib/libc/citrus/modules/citrus_euc.c index f44473749d2..3b935982929 100644 --- a/lib/libc/citrus/modules/citrus_euc.c +++ b/lib/libc/citrus/modules/citrus_euc.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_euc.c,v 1.12 2008/06/14 16:01:07 tnozaki Exp $ */ +/* $NetBSD: citrus_euc.c,v 1.13 2009/01/02 00:20:19 tnozaki Exp $ */ /*- * Copyright (c)2002 Citrus Project, @@ -60,7 +60,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_euc.c,v 1.12 2008/06/14 16:01:07 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_euc.c,v 1.13 2009/01/02 00:20:19 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include <assert.h> @@ -74,6 +74,7 @@ __RCSID("$NetBSD: citrus_euc.c,v 1.12 2008/06/14 16:01:07 tnozaki Exp $"); #include <limits.h> #include "citrus_namespace.h" +#include "citrus_bcs.h" #include "citrus_types.h" #include "citrus_module.h" #include "citrus_ctype.h" @@ -153,7 +154,7 @@ _citrus_EUC_parse_variable(_EUCEncodingInfo *ei, ei->mb_cur_max = 1; for (x = 0; x < 4; ++x) { - ei->count[x] = (int) strtol(v, (char **)&e, 0); + ei->count[x] = (int)_bcs_strtol(v, (char **)&e, 0); if (v == e || !(v = e) || ei->count[x]<1 || ei->count[x]>4) { return (EFTYPE); } @@ -161,14 +162,14 @@ _citrus_EUC_parse_variable(_EUCEncodingInfo *ei, ei->mb_cur_max = ei->count[x]; while (*v == ' ' || *v == '\t') ++v; - ei->bits[x] = (int) strtol(v, (char **)&e, 0); + ei->bits[x] = (int)_bcs_strtol(v, (char **)&e, 0); if (v == e || !(v = e)) { return (EFTYPE); } while (*v == ' ' || *v == '\t') ++v; } - ei->mask = (int)strtol(v, (char **)&e, 0); + ei->mask = (int)_bcs_strtol(v, (char **)&e, 0); if (v == e || !(v = e)) { return (EFTYPE); } diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 5cd12a37b2d..a986928942a 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.165 2008/12/05 13:08:53 ad Exp $ +# $NetBSD: Makefile.inc,v 1.166 2009/01/02 00:20:19 tnozaki Exp $ # from: @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 # gen sources @@ -154,3 +154,5 @@ MLINKS+=ttyname.3 isatty.3 ttyname.3 ttyslot.3 ttyname.3 ttyname_r.3 MLINKS+=unvis.3 strunvis.3 unvis.3 strunvisx.3 MLINKS+=vis.3 svis.3 vis.3 strvis.3 vis.3 strvisx.3 vis.3 strsvis.3 \ vis.3 strsvisx.3 + +CPPFLAGS.isctype.c+= -I${LIBCDIR}/locale diff --git a/lib/libc/gen/isctype.c b/lib/libc/gen/isctype.c index d135bf60687..88c4a9de4b6 100644 --- a/lib/libc/gen/isctype.c +++ b/lib/libc/gen/isctype.c @@ -1,13 +1,8 @@ -/* $NetBSD: isctype.c,v 1.16 2003/08/07 16:42:52 agc Exp $ */ +/* $NetBSD: isctype.c,v 1.17 2009/01/02 00:20:19 tnozaki Exp $ */ -/* - * Copyright (c) 1989 The Regents of the University of California. +/*- + * Copyright (c)2008 Citrus Project, * All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -17,14 +12,11 @@ * 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * 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 REGENTS OR CONTRIBUTORS BE LIABLE + * 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) @@ -36,124 +28,88 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)isctype.c 5.2 (Berkeley) 6/1/90"; -#else -__RCSID("$NetBSD: isctype.c,v 1.16 2003/08/07 16:42:52 agc Exp $"); -#endif +__RCSID("$NetBSD: isctype.c,v 1.17 2009/01/02 00:20:19 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ -#define _ANSI_LIBRARY +#include "namespace.h" +#include <sys/types.h> #include <ctype.h> +#include <langinfo.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stdio.h> +#if EOF != -1 +#error "EOF != -1" +#endif -#undef isalnum -int -isalnum(c) - int c; -{ - return((_ctype_ + 1)[c] & (_U|_L|_N)); -} - -#undef isalpha -int -isalpha(c) - int c; -{ - return((_ctype_ + 1)[c] & (_U|_L)); -} +#include "setlocale_local.h" -#undef isblank -int -isblank(c) - int c; -{ - return(c == ' ' || c == '\t'); -} +#define _CTYPE_TAB(table, i) \ + (((*_current_locale())->cache.table + 1)[i]) +#undef isalnum +#undef isalpha #undef iscntrl -int -iscntrl(c) - int c; -{ - return((_ctype_ + 1)[c] & _C); -} - #undef isdigit -int -isdigit(c) - int c; -{ - return((_ctype_ + 1)[c] & _N); -} - #undef isgraph -int -isgraph(c) - int c; -{ - return((_ctype_ + 1)[c] & (_P|_U|_L|_N)); -} - #undef islower -int -islower(c) - int c; -{ - return((_ctype_ + 1)[c] & _L); -} - #undef isprint -int -isprint(c) - int c; -{ - return((_ctype_ + 1)[c] & (_P|_U|_L|_N|_B)); -} - #undef ispunct -int -ispunct(c) - int c; -{ - return((_ctype_ + 1)[c] & _P); +#undef isspace +#undef isupper +#undef isxdigit + +#define _ISCTYPE_FUNC(name, bit) \ +int \ +is##name(int c) \ +{ \ + return (int)(_CTYPE_TAB(ctype_tab, c) & (bit)); \ } -#undef isspace +_ISCTYPE_FUNC(alnum, _U|_L|_N ) +_ISCTYPE_FUNC(alpha, _U|_L ) +_ISCTYPE_FUNC(cntrl, _C ) +_ISCTYPE_FUNC(digit, _N ) +_ISCTYPE_FUNC(graph, _P|_U|_L|_N ) +_ISCTYPE_FUNC(lower, _L ) +_ISCTYPE_FUNC(print, _P|_U|_L|_N|_B) +_ISCTYPE_FUNC(punct, _P ) +_ISCTYPE_FUNC(space, _S ) +_ISCTYPE_FUNC(upper, _U ) +_ISCTYPE_FUNC(xdigit, _N|_X ) + +#undef isblank int -isspace(c) - int c; +isblank(int c) { - return((_ctype_ + 1)[c] & _S); + /* XXX: FIXME */ + return c == ' ' || c == '\t'; } -#undef isupper +#undef toupper int -isupper(c) - int c; +toupper(int c) { - return((_ctype_ + 1)[c] & _U); + return (int)_CTYPE_TAB(toupper_tab, c); } -#undef isxdigit +#undef tolower int -isxdigit(c) - int c; +tolower(int c) { - return((_ctype_ + 1)[c] & (_N|_X)); + return (int)_CTYPE_TAB(tolower_tab, c); } #undef _toupper int -_toupper(c) - int c; +_toupper(int c) { return (c - 'a' + 'A'); } #undef _tolower int -_tolower(c) - int c; +_tolower(int c) { return (c - 'A' + 'a'); } diff --git a/lib/libc/gen/tolower_.c b/lib/libc/gen/tolower_.c index 8d09890eba6..5de11c29ff1 100644 --- a/lib/libc/gen/tolower_.c +++ b/lib/libc/gen/tolower_.c @@ -1,4 +1,4 @@ -/* $NetBSD: tolower_.c,v 1.9 2003/07/26 19:24:45 salo Exp $ */ +/* $NetBSD: tolower_.c,v 1.10 2009/01/02 00:20:19 tnozaki Exp $ */ /* * Written by J.T. Conklin <jtc@NetBSD.org>. @@ -7,7 +7,7 @@ #include <sys/cdefs.h> #if defined(LIBC_RCS) && !defined(lint) -__RCSID("$NetBSD: tolower_.c,v 1.9 2003/07/26 19:24:45 salo Exp $"); +__RCSID("$NetBSD: tolower_.c,v 1.10 2009/01/02 00:20:19 tnozaki Exp $"); #endif /* LIBC_RCS and not lint */ #include <stdio.h> @@ -54,11 +54,3 @@ const short _C_tolower_[1 + 256] = { }; const short *_tolower_tab_ = _C_tolower_; - -#undef tolower -int -tolower(c) - int c; -{ - return((_tolower_tab_ + 1)[c]); -} diff --git a/lib/libc/gen/toupper_.c b/lib/libc/gen/toupper_.c index fbac8e759af..108da36f769 100644 --- a/lib/libc/gen/toupper_.c +++ b/lib/libc/gen/toupper_.c @@ -1,4 +1,4 @@ -/* $NetBSD: toupper_.c,v 1.9 2003/07/26 19:24:45 salo Exp $ */ +/* $NetBSD: toupper_.c,v 1.10 2009/01/02 00:20:19 tnozaki Exp $ */ /* * Written by J.T. Conklin <jtc@NetBSD.org>. @@ -7,7 +7,7 @@ #include <sys/cdefs.h> #if defined(LIBC_RCS) && !defined(lint) -__RCSID("$NetBSD: toupper_.c,v 1.9 2003/07/26 19:24:45 salo Exp $"); +__RCSID("$NetBSD: toupper_.c,v 1.10 2009/01/02 00:20:19 tnozaki Exp $"); #endif /* LIBC_RCS and not lint */ #include <stdio.h> @@ -54,11 +54,3 @@ const short _C_toupper_[1 + 256] = { }; const short *_toupper_tab_ = _C_toupper_; - -#undef toupper -int -toupper(c) - int c; -{ - return((_toupper_tab_ + 1)[c]); -} diff --git a/lib/libc/iconv/Makefile.inc b/lib/libc/iconv/Makefile.inc index 197e9b6305a..27694f5b9b8 100644 --- a/lib/libc/iconv/Makefile.inc +++ b/lib/libc/iconv/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.2 2003/07/04 06:05:30 tshiozak Exp $ +# $NetBSD: Makefile.inc,v 1.3 2009/01/02 00:20:19 tnozaki Exp $ .PATH: ${ARCHDIR}/iconv ${.CURDIR}/iconv @@ -7,5 +7,7 @@ MAN+= iconv.3 MLINKS+=iconv.3 iconv_open.3 iconv.3 iconv_close.3 .if ${CITRUS} == "yes" -CPPFLAGS+= -DCITRUS_ICONV +CPPFLAGS.iconv.c+= -DHAVE_CITRUS -I${LIBCDIR}/citrus +.else +CPPFLAGS.iconv.c+= -UHAVE_CITRUS .endif diff --git a/lib/libc/iconv/iconv.c b/lib/libc/iconv/iconv.c index 8d5696191c5..771ec89b8fe 100644 --- a/lib/libc/iconv/iconv.c +++ b/lib/libc/iconv/iconv.c @@ -1,4 +1,4 @@ -/* $NetBSD: iconv.c,v 1.6 2006/11/03 20:16:28 christos Exp $ */ +/* $NetBSD: iconv.c,v 1.7 2009/01/02 00:20:19 tnozaki Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: iconv.c,v 1.6 2006/11/03 20:16:28 christos Exp $"); +__RCSID("$NetBSD: iconv.c,v 1.7 2009/01/02 00:20:19 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -45,13 +45,13 @@ __weak_alias(iconv_open, _iconv_open) __weak_alias(iconv_close, _iconv_close) #endif -#ifdef CITRUS_ICONV +#ifdef HAVE_CITRUS #include <sys/types.h> -#include <citrus/citrus_types.h> -#include <citrus/citrus_module.h> -#include <citrus/citrus_esdb.h> -#include <citrus/citrus_hash.h> -#include <citrus/citrus_iconv.h> +#include "citrus_types.h" +#include "citrus_module.h" +#include "citrus_esdb.h" +#include "citrus_hash.h" +#include "citrus_iconv.h" #define ISBADF(_h_) (!(_h_) || (_h_) == (iconv_t)-1) diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc index 43429a2e01a..9a66ee83c92 100644 --- a/lib/libc/locale/Makefile.inc +++ b/lib/libc/locale/Makefile.inc @@ -1,21 +1,16 @@ # from: @(#)Makefile.inc 5.1 (Berkeley) 2/18/91 -# $NetBSD: Makefile.inc,v 1.52 2008/05/17 03:49:54 ginsbach Exp $ +# $NetBSD: Makefile.inc,v 1.53 2009/01/02 00:20:19 tnozaki Exp $ # locale sources .PATH: ${ARCHDIR}/locale ${.CURDIR}/locale SRCS+= _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \ - ctypeio.c lcmessages.c lcmonetary.c lcnumeric.c lctime.c \ - localeconv.c localeio.c nl_langinfo.c setlocale.c setlocale1.c \ - setlocale32.c __mb_cur_max.c wcscoll.c wcsftime.c \ + setlocale.c setlocale1.c setlocale32.c __mb_cur_max.c \ + current_locale.c global_locale.c fix_grouping.c \ + localeconv.c nl_langinfo.c \ + generic_lc_all.c dummy_lc_collate.c \ wcstol.c wcstoll.c wcstoimax.c wcstoul.c wcstoull.c wcstoumax.c \ - wcsxfrm.c aliasname.c -MAN+= nl_langinfo.3 setlocale.3 wcstol.3 wcscoll.3 wcsxfrm.3 - -SRCS+= wcstod.c wcstof.c wcstold.c -MAN+= wcstod.3 - -MLINKS+=setlocale.3 localeconv.3 + wcstod.c wcstof.c wcstold.c wcscoll.c wcsxfrm.c wcsftime.c .if ${CITRUS} == "no" RUNE= no @@ -25,19 +20,41 @@ RUNE?= yes .if ${RUNE} == "no" # singlebyte locale - dummy -SRCS+= multibyte_sb.c iswctype_sb.c -CPPFLAGS+=-UWITH_RUNE +CPPFLAGS+= -UWITH_RUNE +SRCS+= aliasname.c bsdctype.c localeio.c \ + multibyte_sb.c iswctype_sb.c \ + localeio_lc_ctype.c localeio_lc_monetary.c \ + localeio_lc_numeric.c localeio_lc_time.c .else # citrus multibyte locale support # we have quirk for libc.a - see the last part of lib/libc/Makefile -CPPFLAGS+=-DWITH_RUNE -I${.CURDIR} -SRCS+= ___runetype_mb.c _wctrans.c iswctype.c multibyte_c90.c \ - multibyte_amd1.c rune.c runeglue.c runetable.c setrunelocale.c +CPPFLAGS+= -DWITH_RUNE -I${.CURDIR} +SRCS+= _wctrans.c _wctype.c rune.c runeglue.c runetable.c \ + multibyte_c90.c multibyte_amd1.c iswctype_mb.c +CPPFLAGS.rune.c+= -I${LIBCDIR}/citrus +CPPFLAGS.runeglue.c+= -I${LIBCDIR}/citrus +CPPFLAGS.runetable.c+= -I${LIBCDIR}/citrus +CPPFLAGS.multibyte_c90.c+= -I${LIBCDIR}/citrus +CPPFLAGS.multibyte_amd1.c+= -I${LIBCDIR}/citrus .endif -MAN+= btowc.3 iswalnum.3 iswctype.3 towlower.3 towctrans.3 mblen.3 mbrlen.3 \ - mbrtowc.3 mbsinit.3 mbsrtowcs.3 mbstowcs.3 mbtowc.3 wcrtomb.3 wcwidth.3 \ - wcsftime.3 wcsrtombs.3 wcstombs.3 wctob.3 wctomb.3 wctrans.3 wctype.3 +MAN+= setlocale.3 nl_langinfo.3 + +MAN+= mbtowc.3 mbstowcs.3 wctomb.3 wcstombs.3 mblen.3 \ + +MAN+= btowc.3 mbrtowc.3 mbsrtowcs.3 \ + wctob.3 wcrtomb.3 wcsrtombs.3 \ + mbrlen.3 mbsinit.3 + +MAN+= iswalnum.3 wctype.3 iswctype.3 \ + towlower.3 wctrans.3 towctrans.3 \ + wcwidth.3 + +MAN+= wcstol.3 wcstod.3 \ + wcscoll.3 wcsxfrm.3 \ + wcsftime.3 + +MLINKS+=setlocale.3 localeconv.3 MLINKS+=iswalnum.3 iswalpha.3 iswalnum.3 iswblank.3 \ iswalnum.3 iswcntrl.3 iswalnum.3 iswdigit.3 \ @@ -45,7 +62,9 @@ MLINKS+=iswalnum.3 iswalpha.3 iswalnum.3 iswblank.3 \ iswalnum.3 iswprint.3 iswalnum.3 iswpunct.3 \ iswalnum.3 iswspace.3 iswalnum.3 iswupper.3 \ iswalnum.3 iswxdigit.3 + MLINKS+=towlower.3 towupper.3 + MLINKS+=wcstod.3 wcstof.3 wcstod.3 wcstold.3 MLINKS+=wcstol.3 wcstoll.3 wcstol.3 wcstoimax.3 \ wcstol.3 wcstoul.3 wcstol.3 wcstoull.3 wcstol.3 wcstoumax.3 diff --git a/lib/libc/locale/___runetype_mb.c b/lib/libc/locale/___runetype_mb.c deleted file mode 100644 index 310b37e606f..00000000000 --- a/lib/libc/locale/___runetype_mb.c +++ /dev/null @@ -1,73 +0,0 @@ -/* $NetBSD: ___runetype_mb.c,v 1.10 2005/02/10 19:19:57 tnozaki Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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: ___runetype_mb.c,v 1.10 2005/02/10 19:19:57 tnozaki Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include <wctype.h> -#include "rune.h" -#include "rune_local.h" - -_RuneType -___runetype_mb(c) - wint_t c; -{ - __nbrune_t c0; - uint32_t x; - _RuneRange *rr; - _RuneEntry *base, *re; - - if (c == WEOF) - return (0U); - - c0 = (__nbrune_t)c; /* XXX assumes wint_t = int */ - rr = &_CurrentRuneLocale->rl_runetype_ext; - base = rr->rr_rune_ranges; - for (x = rr->rr_nranges; x; x >>= 1) { - re = base + (x >> 1); - if (re->re_min <= c0 && re->re_max >= c0) { - if (re->re_rune_types) - return (re->re_rune_types[c0 - re->re_min]); - else - return (re->re_map); - } else if (c0 > re->re_max) { - base = re + 1; - x--; - } - } - - return (0U); -} diff --git a/lib/libc/locale/_wctrans.c b/lib/libc/locale/_wctrans.c index 97e800f1e81..a22ad9c8ccc 100644 --- a/lib/libc/locale/_wctrans.c +++ b/lib/libc/locale/_wctrans.c @@ -1,4 +1,4 @@ -/* $NetBSD: _wctrans.c,v 1.6 2005/02/10 19:19:57 tnozaki Exp $ */ +/* $NetBSD: _wctrans.c,v 1.7 2009/01/02 00:20:19 tnozaki Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -60,7 +60,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _wctrans.c,v 1.6 2005/02/10 19:19:57 tnozaki Exp $"); +__RCSID("$NetBSD: _wctrans.c,v 1.7 2009/01/02 00:20:19 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -88,7 +88,7 @@ _wctrans_init(_RuneLocale *rl) } /* - * _wctrans_ext: + * _towctrans_ext: * translate a character (extended part) */ wint_t diff --git a/lib/libc/locale/_wctrans_local.h b/lib/libc/locale/_wctrans_local.h index d851088a029..9fe7bf0d1df 100644 --- a/lib/libc/locale/_wctrans_local.h +++ b/lib/libc/locale/_wctrans_local.h @@ -1,4 +1,4 @@ -/* $NetBSD: _wctrans_local.h,v 1.2 2003/04/06 18:33:23 tshiozak Exp $ */ +/* $NetBSD: _wctrans_local.h,v 1.3 2009/01/02 00:20:19 tnozaki Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -29,8 +29,10 @@ #ifndef _WCTRANS_LOCAL_H_ #define _WCTRANS_LOCAL_H_ +__BEGIN_DECLS wint_t _towctrans_ext(wint_t, _WCTransEntry *); void _wctrans_init(_RuneLocale *); +__END_DECLS static __inline wint_t _towctrans(wint_t c, _WCTransEntry *te) @@ -55,4 +57,4 @@ _wctrans_upper(_RuneLocale *rl) return (&rl->rl_wctrans[_WCTRANS_INDEX_UPPER]); } -#endif +#endif /*_WCTRANS_LOCAL_H_*/ diff --git a/lib/libc/locale/_wctype.c b/lib/libc/locale/_wctype.c new file mode 100644 index 00000000000..df851cfb266 --- /dev/null +++ b/lib/libc/locale/_wctype.c @@ -0,0 +1,147 @@ +/* $NetBSD: _wctype.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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. + */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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: _wctype.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include <assert.h> +#include <ctype.h> +#include <errno.h> +#include <string.h> + +#include "rune.h" +#include "_wctrans_local.h" +#include "_wctype_local.h" + +_RuneType +_runetype_priv(_RuneLocale const *rl, wint_t wc) +{ + __nbrune_t wc0; + _RuneRange const *rr; + _RuneEntry *base, *re; + uint32_t x; + + _DIAGASSERT(rl != NULL); + + if (wc == WEOF) + return 0U; + if (_RUNE_ISCACHED(wc)) + return rl->rl_runetype[(size_t)wc]; + wc0 = (__nbrune_t)wc; + rr = &rl->rl_runetype_ext; + _DIAGASSERT(rr != NULL); + base = rr->rr_rune_ranges; + for (x = rr->rr_nranges; x != (uint32_t)0; x >>= 1) { + re = base + (x >> 1); + if (re->re_min <= wc0 && re->re_max >= wc0) { + if (re->re_rune_types) + return re->re_rune_types[wc0 - re->re_min]; + else + return re->re_map; + } else if (wc0 > re->re_max) { + base = re + 1; + --x; + } + } + return (_RuneType)0U; +} + +int +_iswctype_priv(_RuneLocale const *rl, + wint_t wc, _WCTypeEntry const *te) +{ + return !!(_runetype_priv(rl, wc) & te->te_mask); +} + +wint_t +_towctrans_priv(_RuneLocale const *rl, + wint_t wc, _WCTransEntry const *te) +{ + __nbrune_t wc0; + _RuneRange *rr; + _RuneEntry *base, *re; + uint32_t x; + + _DIAGASSERT(rl != NULL); + _DIAGASSERT(te != NULL); + + if (wc == WEOF) + return wc; + if (te->te_name == NULL) + _wctrans_init(__UNCONST(rl)); + if (_RUNE_ISCACHED(wc)) + return te->te_cached[(size_t)wc]; + wc0 = (__nbrune_t)wc; + rr = te->te_extmap; + _DIAGASSERT(rr != NULL); + base = rr->rr_rune_ranges; + for (x = rr->rr_nranges; x != (uint32_t)0; x >>= 1) { + re = base + (x >> 1); + if (re->re_min <= wc0 && re->re_max >= wc0) { + return re->re_map + wc0 - re->re_min; + } else if (wc0 >= re->re_max) { + base = re + 1; + --x; + } + } + return wc; +} diff --git a/lib/libc/locale/_wctype_local.h b/lib/libc/locale/_wctype_local.h new file mode 100644 index 00000000000..76adb7390f7 --- /dev/null +++ b/lib/libc/locale/_wctype_local.h @@ -0,0 +1,38 @@ +/* $NetBSD: _wctype_local.h,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ + +/*- + * Copyright (c) 2008 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 _WCTYPE_LOCAL_H_ +#define _WCTYPE_LOCAL_H_ + +__BEGIN_DECLS +_RuneType _runetype_priv(_RuneLocale const *, wint_t); +int _iswctype_priv(_RuneLocale const *, wint_t, _WCTypeEntry const *); +wint_t _towctrans_priv(_RuneLocale const *, wint_t, _WCTransEntry const *); +__END_DECLS + +#endif /*_WCTYPE_LOCAL_H_*/ diff --git a/lib/libc/locale/aliasname.c b/lib/libc/locale/aliasname.c index 9e8f4c3dee5..a2ba27d5990 100644 --- a/lib/libc/locale/aliasname.c +++ b/lib/libc/locale/aliasname.c @@ -1,4 +1,4 @@ -/* $NetBSD: aliasname.c,v 1.2 2005/02/09 21:35:46 kleink Exp $ */ +/* $NetBSD: aliasname.c,v 1.3 2009/01/02 00:20:19 tnozaki Exp $ */ /*- * Copyright (c)2002 YAMAMOTO Takashi, @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: aliasname.c,v 1.2 2005/02/09 21:35:46 kleink Exp $"); +__RCSID("$NetBSD: aliasname.c,v 1.3 2009/01/02 00:20:19 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -50,7 +50,7 @@ const char * __unaliasname(const char *dbname, const char *alias, void *buf, size_t bufsize) { FILE *fp = NULL; - const char *result = alias; + const char *result = NULL; size_t resultlen; size_t aliaslen; const char *p; diff --git a/lib/libc/locale/aliasname_local.h b/lib/libc/locale/aliasname_local.h index 19abcf1ef4a..359674a1a7a 100644 --- a/lib/libc/locale/aliasname_local.h +++ b/lib/libc/locale/aliasname_local.h @@ -1,4 +1,4 @@ -/* $NetBSD: aliasname_local.h,v 1.1 2002/02/13 07:45:52 yamt Exp $ */ +/* $NetBSD: aliasname_local.h,v 1.2 2009/01/02 00:20:19 tnozaki Exp $ */ /*- * Copyright (c)2002 YAMAMOTO Takashi, @@ -26,4 +26,49 @@ * SUCH DAMAGE. */ +/*- + * Copyright (c)2008 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 _ALIASNAME_LOCAL_H_ +#define _ALIASNAME_LOCAL_H_ + const char *__unaliasname(const char *, const char *, void *, size_t); + +static __inline int +__isforcemapping(const char *name) +{ + /* don't use strcasecmp, it owes locale. */ + return + name[0] == '/' && + (name[1] == 'F' || name[1] == 'f') && + (name[2] == 'O' || name[2] == 'o') && + (name[3] == 'R' || name[3] == 'r') && + (name[4] == 'C' || name[4] == 'c') && + (name[5] == 'E' || name[5] == 'e') && + name[6] == '\0'; +} + +#endif /*_ALIASNAME_LOCAL_H_*/ diff --git a/lib/libc/string/wcswidth.c b/lib/libc/locale/bsdctype.c index 801089ef07f..0b9a0d39dad 100644 --- a/lib/libc/string/wcswidth.c +++ b/lib/libc/locale/bsdctype.c @@ -1,7 +1,7 @@ -/* $NetBSD: wcswidth.c,v 1.5 2008/08/12 21:59:27 tnozaki Exp $ */ +/* $NetBSD: bsdctype.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $ */ /*- - * Copyright (c)1999 Citrus Project, + * Copyright (c)2008 Citrus Project, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,37 +24,23 @@ * 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 Id: wcswidth.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp */ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcswidth.c,v 1.5 2008/08/12 21:59:27 tnozaki Exp $"); +__RCSID("$NetBSD: bsdctype.c,v 1.1 2009/01/02 00:20:19 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ -#include "namespace.h" -#include <assert.h> -#include <wchar.h> - -int -wcswidth(s, n) - const wchar_t *s; - size_t n; -{ - int w, x; +#include <sys/types.h> +#define _CTYPE_PRIVATE +#include <ctype.h> - _DIAGASSERT(s != NULL); +#include "bsdctype.h" - w = 0; - while (n && *s) { - x = wcwidth(*s); - if (x < 0) - return -1; - w += x; - s++; - n--; - } +const _BSDCTypeLocale _DefaultBSDCTypeLocale = { + _C_ctype_, + _C_tolower_, + _C_toupper_ +}; - return w; -} +const _BSDCTypeLocale *_CurrentBSDCTypeLocale = &_DefaultBSDCTypeLocale; diff --git a/lib/libc/locale/bsdctype.h b/lib/libc/locale/bsdctype.h new file mode 100644 index 00000000000..6e9659c044d --- /dev/null +++ b/lib/libc/locale/bsdctype.h @@ -0,0 +1,41 @@ +/* $NetBSD: bsdctype.h,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _BSDCTYPE_H_ +#define _BSDCTYPE_H_ + +typedef struct _BSDCTypeLocale { + const unsigned char *ctype_tab; + const short *tolower_tab; + const short *toupper_tab; +} _BSDCTypeLocale; + +extern const _BSDCTypeLocale _DefaultBSDCTypeLocale; +extern const _BSDCTypeLocale *_CurrentBSDCTypeLocale; + +#endif /*_BSDCTYPE_H_*/ diff --git a/lib/libc/locale/ctypeio.c b/lib/libc/locale/ctypeio.c index e92bb2dacfb..d7df2e14b22 100644 --- a/lib/libc/locale/ctypeio.c +++ b/lib/libc/locale/ctypeio.c @@ -1,4 +1,4 @@ -/* $NetBSD: ctypeio.c,v 1.7 2005/11/29 03:11:59 christos Exp $ */ +/* $NetBSD: ctypeio.c,v 1.8 2009/01/02 00:20:20 tnozaki Exp $ */ /* * Copyright (c) 1997 Christos Zoulas. All rights reserved. @@ -31,72 +31,76 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: ctypeio.c,v 1.7 2005/11/29 03:11:59 christos Exp $"); +__RCSID("$NetBSD: ctypeio.c,v 1.8 2009/01/02 00:20:20 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> - #include <assert.h> +#define _CTYPE_PRIVATE +#include <ctype.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#define _CTYPE_PRIVATE -#include <ctype.h> +#include <unistd.h> + +#include "bsdctype.h" #include "ctypeio.h" int -__loadctype(name) - const char *name; +__loadctype(const char * __restrict path, _BSDCTypeLocale ** __restrict pdata) { FILE *fp; char id[sizeof(_CTYPE_ID) - 1]; - u_int32_t i, len; - unsigned char *new_ctype = NULL; - short *new_toupper = NULL, *new_tolower = NULL; - - _DIAGASSERT(name != NULL); - - if ((fp = fopen(name, "r")) == NULL) - return 0; - - if (fread(id, sizeof(id), 1, fp) != 1) - goto bad; - - if (memcmp(id, _CTYPE_ID, sizeof(id)) != 0) - goto bad; - - if (fread(&i, sizeof(u_int32_t), 1, fp) != 1) - goto bad; - - if ((i = ntohl(i)) != _CTYPE_REV) - goto bad; - - if (fread(&len, sizeof(u_int32_t), 1, fp) != 1) - goto bad; - - if ((len = ntohl(len)) != _CTYPE_NUM_CHARS) - goto bad; - - if ((new_ctype = malloc(sizeof(u_int8_t) * (1 + len))) == NULL) - goto bad; - - new_ctype[0] = 0; - if (fread(&new_ctype[1], sizeof(u_int8_t), len, fp) != len) - goto bad; - - if ((new_toupper = malloc(sizeof(int16_t) * (1 + len))) == NULL) - goto bad; - - new_toupper[0] = EOF; - if (fread(&new_toupper[1], sizeof(int16_t), len, fp) != len) - goto bad; - - if ((new_tolower = malloc(sizeof(int16_t) * (1 + len))) == NULL) - goto bad; - - new_tolower[0] = EOF; - if (fread(&new_tolower[1], sizeof(int16_t), len, fp) != len) - goto bad; + uint32_t i, len; + char *ptr; + uint8_t *new_ctype; + int16_t *new_tolower, *new_toupper; + _BSDCTypeLocale *data; + + _DIAGASSERT(path != NULL); + _DIAGASSERT(pdata != NULL); + + fp = fopen(path, "r"); + if (fp == NULL) + return ENOENT; + + if (fread(id, sizeof(id), 1, fp) != 1 || + memcmp(id, _CTYPE_ID, sizeof(id)) != 0) + goto bad0; + + if (fread(&i, sizeof(uint32_t), 1, fp) != 1 || + (i = ntohl(i)) != _CTYPE_REV) + goto bad0; + + if (fread(&len, sizeof(uint32_t), 1, fp) != 1 || + (len = ntohl(len)) != _CTYPE_NUM_CHARS) + goto bad0; + + ptr = malloc(sizeof(*data) + ((sizeof(uint8_t) + + sizeof(int16_t) + sizeof(int16_t)) * (len + 1))); + if (ptr == NULL) + return ENOMEM; + + data = (_BSDCTypeLocale *)(void *)ptr; + ptr += sizeof(*data); + + (new_ctype = (void *)ptr)[0] = (uint8_t)0; + ptr += sizeof(uint8_t); + if (fread((void *)ptr, sizeof(uint8_t), len, fp) != len) + goto bad1; + ptr += sizeof(uint8_t) * len; + + (new_toupper = (void *)ptr)[0] = (int16_t)EOF; + ptr += sizeof(int16_t); + if (fread((void *)ptr, sizeof(int16_t), len, fp) != len) + goto bad1; + ptr += sizeof(int16_t) * len; + + (new_tolower = (void *)ptr)[0] = (int16_t)EOF; + ptr += sizeof(int16_t); + if (fread((void *)ptr, sizeof(int16_t), len, fp) != len) + goto bad1; #if BYTE_ORDER == LITTLE_ENDIAN for (i = 1; i <= len; i++) { @@ -105,73 +109,18 @@ __loadctype(name) } #endif - (void) fclose(fp); - if (_ctype_ != _C_ctype_) - free(__UNCONST(_ctype_)); - _ctype_ = new_ctype; - if (_toupper_tab_ != _C_toupper_) - free(__UNCONST(_toupper_tab_)); - _toupper_tab_ = new_toupper; - if (_tolower_tab_ != _C_tolower_) - free(__UNCONST(_tolower_tab_)); - _tolower_tab_ = new_tolower; - - return 1; -bad: - free(new_tolower); - free(new_toupper); - free(new_ctype); - (void) fclose(fp); - return 0; -} + fclose(fp); -int -__savectype(name, new_ctype, new_toupper, new_tolower) - const char *name; - unsigned char *new_ctype; - short *new_toupper, *new_tolower; -{ - FILE *fp; - u_int32_t i, len = _CTYPE_NUM_CHARS; + data->ctype_tab = (const unsigned char *)new_ctype; + data->toupper_tab = (const short *)new_toupper; + data->tolower_tab = (const short *)new_tolower; - _DIAGASSERT(name != NULL); - _DIAGASSERT(new_ctype != NULL); - _DIAGASSERT(new_toupper != NULL); - _DIAGASSERT(new_tolower != NULL); + *pdata = data; - if ((fp = fopen(name, "w")) == NULL) return 0; - if (fwrite(_CTYPE_ID, sizeof(_CTYPE_ID) - 1, 1, fp) != 1) - goto bad; - - i = htonl(_CTYPE_REV); - if (fwrite(&i, sizeof(u_int32_t), 1, fp) != 1) - goto bad; - - i = htonl(len); - if (fwrite(&i, sizeof(u_int32_t), 1, fp) != 1) - goto bad; - - if (fwrite(&new_ctype[1], sizeof(u_int8_t), len, fp) != len) - goto bad; - -#if BYTE_ORDER == LITTLE_ENDIAN - for (i = 1; i <= len; i++) { - new_toupper[i] = htons(new_toupper[i]); - new_tolower[i] = htons(new_tolower[i]); - } -#endif - if (fwrite(&new_toupper[1], sizeof(int16_t), len, fp) != len) - goto bad; - - if (fwrite(&new_tolower[1], sizeof(int16_t), len, fp) != len) - goto bad; - - - (void) fclose(fp); - return 1; -bad: - (void) fclose(fp); - return 0; +bad1: + free(data); +bad0: + return EFTYPE; } diff --git a/lib/libc/locale/ctypeio.h b/lib/libc/locale/ctypeio.h index 15e272d6bf8..dde10bbe1c2 100644 --- a/lib/libc/locale/ctypeio.h +++ b/lib/libc/locale/ctypeio.h @@ -1,4 +1,4 @@ -/* $NetBSD: ctypeio.h,v 1.1 1997/06/02 09:52:48 kleink Exp $ */ +/* $NetBSD: ctypeio.h,v 1.2 2009/01/02 00:20:20 tnozaki Exp $ */ /* * Copyright (c) 1997 Christos Zoulas. All rights reserved. @@ -30,6 +30,5 @@ */ __BEGIN_DECLS -int __loadctype __P((const char *)); -int __savectype __P((const char *, unsigned char *, short *, short *)); +int __loadctype(const char * __restrict, _BSDCTypeLocale ** __restrict pdata); __END_DECLS diff --git a/lib/libc/locale/current_locale.c b/lib/libc/locale/current_locale.c new file mode 100644 index 00000000000..516cd7ae5c5 --- /dev/null +++ b/lib/libc/locale/current_locale.c @@ -0,0 +1,49 @@ +/* $NetBSD: current_locale.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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: current_locale.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include <sys/cdefs.h> +#include <sys/types.h> +#include <langinfo.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stdlib.h> + +#include "setlocale_local.h" + +static struct _locale_impl_t *__current_locale = &_global_locale; + +struct _locale_impl_t ** +_current_locale() +{ + return &__current_locale; +} diff --git a/lib/libc/locale/dummy_lc_collate.c b/lib/libc/locale/dummy_lc_collate.c new file mode 100644 index 00000000000..3963cb4b40f --- /dev/null +++ b/lib/libc/locale/dummy_lc_collate.c @@ -0,0 +1,54 @@ +/* $NetBSD: dummy_lc_collate.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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: dummy_lc_collate.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <assert.h> +#include <langinfo.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "setlocale_local.h" + +/* + * macro required by dummy_lc_template.h + */ +#define _PREFIX(name) __CONCAT(_dummy_LC_COLLATE_,name) + +#define _CATEGORY_ID LC_COLLATE +#define _CATEGORY_NAME "LC_COLLATE" + +#include "dummy_lc_template.h" +_LOCALE_CATEGORY_ENTRY(_dummy_LC_COLLATE_); diff --git a/lib/libc/locale/dummy_lc_template.h b/lib/libc/locale/dummy_lc_template.h new file mode 100644 index 00000000000..3a64490e82a --- /dev/null +++ b/lib/libc/locale/dummy_lc_template.h @@ -0,0 +1,56 @@ +/* $NetBSD: dummy_lc_template.h,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _DUMMY_LC_TEMPLATE_H_ +#define _DUMMY_LC_TEMPLATE_H_ + +#include "generic_lc_template_decl.h" + +static const char * +_PREFIX(setlocale)(const char * __restrict name, + struct _locale_impl_t * __restrict locale) +{ + if (name != NULL) { + if (*name == '\0') + name = _get_locale_env(_CATEGORY_NAME); + if (strcmp(name, locale->part_name[(size_t)_CATEGORY_ID])) { + if (!strcmp(_C_LOCALE, name)) + name = _C_LOCALE; + else if (!strcmp(_POSIX_LOCALE, name)) + name = _POSIX_LOCALE; + else + return NULL; + locale->part_name[(size_t)_CATEGORY_ID] = name; + } + } + return locale->part_name[(size_t)_CATEGORY_ID]; +} + +#include "generic_lc_template.h" + +#endif /*_DUMMY_LC_TEMPLATE_H_*/ diff --git a/lib/libc/locale/fix_grouping.c b/lib/libc/locale/fix_grouping.c new file mode 100644 index 00000000000..05b8351d7ec --- /dev/null +++ b/lib/libc/locale/fix_grouping.c @@ -0,0 +1,103 @@ +/* $NetBSD: fix_grouping.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/* + * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org> + * 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. + * + * Original version ID: + * FreeBSD: fix_grouping.c,v 1.8 2003/06/26 10:46:16 phantom Exp + */ + +#include <sys/cdefs.h> +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: fix_grouping.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include <ctype.h> +#include <limits.h> +#include <stddef.h> + +#include "fix_grouping.h" + +#ifndef NBCHAR_MAX +#define NBCHAR_MAX CHAR_MAX +#endif + +static const char nogrouping[] = { NBCHAR_MAX, '\0' }; + +/* don't use libc's isdigit, it owes locale. */ +#undef isdigit +#define isdigit(c) (c >= '0' && c <= '9') + +/* + * Internal helper used to convert grouping sequences from string + * representation into POSIX specified form, i.e. + * + * "3;3;-1" -> "\003\003\177\000" + */ + +const char * +__fix_locale_grouping_str(const char *str) +{ + char *src, *dst; + char n; + + if (str == NULL || *str == '\0') { + return nogrouping; + } + + for (src = __UNCONST(str), dst = __UNCONST(str); *src != '\0'; src++) { + + /* input string examples: "3;3", "3;2;-1" */ + if (*src == ';') + continue; + + if (*src == '-' && *(src+1) == '1') { + *dst++ = NBCHAR_MAX; + src++; + continue; + } + + if (!isdigit((unsigned char)*src)) { + /* broken grouping string */ + return nogrouping; + } + + /* assume all numbers <= 99 */ + n = *src - '0'; + if (isdigit((unsigned char)*(src+1))) { + src++; + n *= 10; + n += *src - '0'; + } + + *dst = n; + /* NOTE: assume all input started with "0" as 'no grouping' */ + if (*dst == '\0') + return (dst == __UNCONST(str)) ? nogrouping : str; + dst++; + } + *dst = '\0'; + return str; +} diff --git a/lib/libc/locale/fix_grouping.h b/lib/libc/locale/fix_grouping.h new file mode 100644 index 00000000000..b865d0e19b2 --- /dev/null +++ b/lib/libc/locale/fix_grouping.h @@ -0,0 +1,36 @@ +/* $NetBSD: fix_grouping.h,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c) 2008 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 _FIX_GROUPING_H_ +#define _FIX_GROUPING_H_ + +__BEGIN_DECLS +const char *__fix_locale_grouping_str(const char *); +__END_DECLS + +#endif /*_FIX_GROUPING_H_*/ diff --git a/lib/libc/locale/generic_lc_all.c b/lib/libc/locale/generic_lc_all.c new file mode 100644 index 00000000000..58ac2ae3da1 --- /dev/null +++ b/lib/libc/locale/generic_lc_all.c @@ -0,0 +1,118 @@ +/* $NetBSD: generic_lc_all.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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: generic_lc_all.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <assert.h> +#include <langinfo.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "setlocale_local.h" + +/* + * macro required by all template headers + */ +#define _PREFIX(name) __CONCAT(_generic_LC_ALL_, name) + +#include "generic_lc_template_decl.h" + +const char * +_generic_LC_ALL_setlocale(const char * __restrict name, + struct _locale_impl_t * __restrict locale) +{ + _locale_category_t *l; + char head[_LOCALENAME_LEN_MAX * (_LC_LAST - 1)], *tail; + const char *tokens[_LC_LAST], *s, *t; + int i, j; + + l = _find_category(1); + _DIAGASSERT(l != NULL); + if (name != NULL) { + strlcpy(&head[0], name, sizeof(head)); + tokens[1] = &head[0]; + tail = strchr(tokens[1], '/'); + if (tail == NULL) { + for (i = 2; i < _LC_LAST; ++i) + tokens[i] = tokens[1]; + } else { + *tail++ = '\0'; + for (i = 2; i < _LC_LAST - 1; ++i) { + tokens[i] = (const char *)tail; + tail = strchr(tokens[i], '/'); + if (tail == NULL) + return NULL; + *tail++ = '\0'; + } + tokens[_LC_LAST - 1] = (const char *)tail; + tail = strchr(tokens[i], '/'); + if (tail == NULL) + return NULL; + } + (*l->setlocale)(tokens[1], locale); + } + s = (*l->setlocale)(NULL, locale); + _DIAGASSERT(s != NULL); + strlcpy(&locale->query[0], s, sizeof(locale->query)); + for (i = 2, j = 0; i < _LC_LAST; ++i) { + l = _find_category(i); + _DIAGASSERT(l != NULL); + if (name != NULL) + (*l->setlocale)(tokens[1], locale); + t = (*l->setlocale)(NULL, locale); + _DIAGASSERT(t != NULL); + if (j == 0) { + if (!strcmp(s, t)) + continue; + for (j = 2; j < i; ++j) { + strlcat(&locale->query[0], "/", + sizeof(locale->query)); + strlcat(&locale->query[0], s, + sizeof(locale->query)); + } + } + strlcat(&locale->query[0], "/", sizeof(locale->query)); + strlcat(&locale->query[0], t, sizeof(locale->query)); + } + return (const char *)&locale->query[0]; +} + +/* + * macro requrired by generic_lc_template.h + */ +#define _CATEGORY_ID LC_ALL + +#include "generic_lc_template.h" +_LOCALE_CATEGORY_ENTRY(_generic_LC_ALL_); diff --git a/lib/libc/locale/generic_lc_template.h b/lib/libc/locale/generic_lc_template.h new file mode 100644 index 00000000000..3d2f1cb7935 --- /dev/null +++ b/lib/libc/locale/generic_lc_template.h @@ -0,0 +1,45 @@ +/* $NetBSD: generic_lc_template.h,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _GENERIC_LC_TEMPLATE_H_ +#define _GENERIC_LC_TEMPLATE_H_ + +#ifdef __lint__ +#define STATIC /**/ +#else +#define STATIC static +#endif + +#define _LOCALE_CATEGORY_ENTRY(name) \ +STATIC const _locale_category_t name##desc = { \ + .category = _CATEGORY_ID, \ + .setlocale = &name##setlocale, \ +}; \ +__link_set_add_data(all_categories, name##desc) + +#endif /*_GENERIC_LC_TEMPLATE_H_*/ diff --git a/lib/libc/locale/generic_lc_template_decl.h b/lib/libc/locale/generic_lc_template_decl.h new file mode 100644 index 00000000000..a03f48b404f --- /dev/null +++ b/lib/libc/locale/generic_lc_template_decl.h @@ -0,0 +1,35 @@ +/* $NetBSD: generic_lc_template_decl.h,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _GENERIC_LC_TEMPLATE_DECL_H_ +#define _GENERIC_LC_TEMPLATE_DECL_H_ + +static const char * _PREFIX(setlocale)(const char * __restrict, + struct _locale_impl_t * __restrict); + +#endif /*_GENERIC_LC_TEMPLATE_DECL_H_*/ diff --git a/lib/libc/locale/global_locale.c b/lib/libc/locale/global_locale.c new file mode 100644 index 00000000000..4dae10a099e --- /dev/null +++ b/lib/libc/locale/global_locale.c @@ -0,0 +1,170 @@ +/* $NetBSD: global_locale.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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: global_locale.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <sys/localedef.h> +#define _CTYPE_PRIVATE +#include <ctype.h> +#include <langinfo.h> +#include <limits.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stdlib.h> +#ifdef WITH_RUNE +#include "rune.h" +#else +#include "bsdctype.h" +#endif + +#include "setlocale_local.h" + +struct _locale_impl_t _global_locale = +{ + .cache = { + .ctype_tab = (const unsigned char *)&_C_ctype_[0], + .tolower_tab = (const short *)&_C_tolower_[0], + .toupper_tab = (const short *)&_C_toupper_[0], + .mb_cur_max = (size_t)1, + .ldata = { + .decimal_point = __UNCONST("."), + .thousands_sep = __UNCONST(""), + .grouping = __UNCONST(""), + .int_curr_symbol = __UNCONST(""), + .currency_symbol = __UNCONST(""), + .mon_decimal_point = __UNCONST(""), + .mon_thousands_sep = __UNCONST(""), + .mon_grouping = __UNCONST(""), + .positive_sign = __UNCONST(""), + .negative_sign = __UNCONST(""), + .int_frac_digits = CHAR_MAX, + .frac_digits = CHAR_MAX, + .p_cs_precedes = CHAR_MAX, + .p_sep_by_space = CHAR_MAX, + .n_cs_precedes = CHAR_MAX, + .n_sep_by_space = CHAR_MAX, + .p_sign_posn = CHAR_MAX, + .n_sign_posn = CHAR_MAX, + .int_p_cs_precedes = CHAR_MAX, + .int_n_cs_precedes = CHAR_MAX, + .int_p_sep_by_space = CHAR_MAX, + .int_n_sep_by_space = CHAR_MAX, + .int_p_sign_posn = CHAR_MAX, + .int_n_sign_posn = CHAR_MAX, + }, + .items = { + [(size_t)D_T_FMT ] = "%a %b %e %H:%M:%S %Y", + [(size_t)D_FMT ] = "%m/%d/%y", + [(size_t)T_FMT ] = "%H:%M:%S", + [(size_t)T_FMT_AMPM ] = "%I:%M:%S %p", + [(size_t)AM_STR ] = "AM", + [(size_t)PM_STR ] = "PM", + [(size_t)DAY_1 ] = "Sun", + [(size_t)DAY_2 ] = "Mon", + [(size_t)DAY_3 ] = "Tue", + [(size_t)DAY_4 ] = "Wed", + [(size_t)DAY_5 ] = "Thu", + [(size_t)DAY_6 ] = "Fri", + [(size_t)DAY_7 ] = "Sat", + [(size_t)ABDAY_1 ] = "Sunday", + [(size_t)ABDAY_2 ] = "Monday", + [(size_t)ABDAY_3 ] = "Tuesday", + [(size_t)ABDAY_4 ] = "Wednesday", + [(size_t)ABDAY_5 ] = "Thursday", + [(size_t)ABDAY_6 ] = "Friday", + [(size_t)ABDAY_7 ] = "Saturday", + [(size_t)MON_1 ] = "Jan", + [(size_t)MON_2 ] = "Feb", + [(size_t)MON_3 ] = "Mar", + [(size_t)MON_4 ] = "Apr", + [(size_t)MON_5 ] = "May", + [(size_t)MON_6 ] = "Jun", + [(size_t)MON_7 ] = "Jul", + [(size_t)MON_8 ] = "Aug", + [(size_t)MON_9 ] = "Sep", + [(size_t)MON_10 ] = "Oct", + [(size_t)MON_11 ] = "Nov", + [(size_t)MON_12 ] = "Dec", + [(size_t)ABMON_1 ] = "January", + [(size_t)ABMON_2 ] = "February", + [(size_t)ABMON_3 ] = "March", + [(size_t)ABMON_4 ] = "April", + [(size_t)ABMON_5 ] = "May", + [(size_t)ABMON_6 ] = "June", + [(size_t)ABMON_7 ] = "July", + [(size_t)ABMON_8 ] = "Augst", + [(size_t)ABMON_9 ] = "September", + [(size_t)ABMON_10 ] = "October", + [(size_t)ABMON_11 ] = "November", + [(size_t)ABMON_12 ] = "December", + [(size_t)RADIXCHAR ] = ".", + [(size_t)THOUSEP ] = "", + [(size_t)YESSTR ] = "yes", + [(size_t)YESEXPR ] = "^[Yy]", + [(size_t)NOSTR ] = "no", + [(size_t)NOEXPR ] = "^[Nn]", + [(size_t)CRNCYSTR ] = NULL, + [(size_t)CODESET ] = "646", + [(size_t)ERA ] = NULL, + [(size_t)ERA_D_FMT ] = NULL, + [(size_t)ERA_D_T_FMT] = NULL, + [(size_t)ERA_T_FMT ] = NULL, + [(size_t)ALT_DIGITS ] = NULL, + }, + }, + .query = /*_C_LOCALE*/ { 'C', '\0' }, + .part_name = { + [(size_t)LC_ALL ] = _C_LOCALE, + [(size_t)LC_COLLATE ] = _C_LOCALE, + [(size_t)LC_CTYPE ] = _C_LOCALE, + [(size_t)LC_MONETARY] = _C_LOCALE, + [(size_t)LC_NUMERIC ] = _C_LOCALE, + [(size_t)LC_TIME ] = _C_LOCALE, + [(size_t)LC_MESSAGES] = _C_LOCALE, + }, + .part_impl = { + [(size_t)LC_ALL ] = (_locale_part_t)NULL, + [(size_t)LC_COLLATE ] = (_locale_part_t)NULL, + [(size_t)LC_CTYPE ] = (_locale_part_t) +#ifdef WITH_RUNE + __UNCONST(&_DefaultRuneLocale), +#else + __UNCONST(&_DefaultBSDCTypeLocale), +#endif + [(size_t)LC_MONETARY] = (_locale_part_t) + __UNCONST(&_DefaultMonetaryLocale), + [(size_t)LC_NUMERIC ] = (_locale_part_t) + __UNCONST(&_DefaultNumericLocale), + [(size_t)LC_MESSAGES] = (_locale_part_t) + __UNCONST(&_DefaultMessagesLocale), + }, +}; diff --git a/lib/libc/locale/iswctype.c b/lib/libc/locale/iswctype.c deleted file mode 100644 index 27c53ba6898..00000000000 --- a/lib/libc/locale/iswctype.c +++ /dev/null @@ -1,282 +0,0 @@ -/* $NetBSD: iswctype.c,v 1.16 2008/08/12 20:51:25 tnozaki Exp $ */ - -/* - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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: iswctype.c,v 1.16 2008/08/12 20:51:25 tnozaki Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" - -#include <wchar.h> -#include <wctype.h> -#include <ctype.h> -#include <errno.h> -#include <string.h> -#include "rune.h" -#include "runetype.h" -#include "rune_local.h" -#include "_wctrans_local.h" - -#ifdef __weak_alias -__weak_alias(wcwidth,_wcwidth) -#endif - -#ifdef lint -#define __inline -#endif - -static __inline _RuneType __runetype_w __P((wint_t)); -static __inline int __isctype_w __P((wint_t, _RuneType)); -static __inline wint_t __toupper_w __P((wint_t)); -static __inline wint_t __tolower_w __P((wint_t)); - -static __inline _RuneType -__runetype_w(c) - wint_t c; -{ - _RuneLocale *rl = _CurrentRuneLocale; - - return (_RUNE_ISCACHED(c) ? - rl->rl_runetype[c] : ___runetype_mb(c)); -} - -static __inline int -__isctype_w(c, f) - wint_t c; - _RuneType f; -{ - return (!!(__runetype_w(c) & f)); -} - -static __inline wint_t -__toupper_w(c) - wint_t c; -{ - return (_towctrans(c, _wctrans_upper(_CurrentRuneLocale))); -} - -static __inline wint_t -__tolower_w(c) - wint_t c; -{ - return (_towctrans(c, _wctrans_lower(_CurrentRuneLocale))); -} - -#undef iswalnum -int -iswalnum(c) - wint_t c; -{ - return (__isctype_w((c), _CTYPE_A|_CTYPE_D)); -} - -#undef iswalpha -int -iswalpha(c) - wint_t c; -{ - return (__isctype_w((c), _CTYPE_A)); -} - -#undef iswblank -int -iswblank(c) - wint_t c; -{ - return (__isctype_w((c), _CTYPE_B)); -} - -#undef iswcntrl -int -iswcntrl(c) - wint_t c; -{ - return (__isctype_w((c), _CTYPE_C)); -} - -#undef iswdigit -int -iswdigit(c) - wint_t c; -{ - return (__isctype_w((c), _CTYPE_D)); -} - -#undef iswgraph -int -iswgraph(c) - wint_t c; -{ - return (__isctype_w((c), _CTYPE_G)); -} - -#undef iswlower -int -iswlower(c) - wint_t c; -{ - return (__isctype_w((c), _CTYPE_L)); -} - -#undef iswprint -int -iswprint(c) - wint_t c; -{ - return (__isctype_w((c), _CTYPE_R)); -} - -#undef iswpunct -int -iswpunct(c) - wint_t c; -{ - return (__isctype_w((c), _CTYPE_P)); -} - -#undef iswspace -int -iswspace(c) - wint_t c; -{ - return (__isctype_w((c), _CTYPE_S)); -} - -#undef iswupper -int -iswupper(c) - wint_t c; -{ - return (__isctype_w((c), _CTYPE_U)); -} - -#undef iswxdigit -int -iswxdigit(c) - wint_t c; -{ - return (__isctype_w((c), _CTYPE_X)); -} - -#undef towupper -wint_t -towupper(c) - wint_t c; -{ - return (__toupper_w(c)); -} - -#undef towlower -wint_t -towlower(c) - wint_t c; -{ - return (__tolower_w(c)); -} - -int -wcwidth(c) - wchar_t c; -{ - _RuneType x; - - if (c == L'\0') - return 0; - x = __runetype_w(c); - if (x & _CTYPE_R) - return ((unsigned)x & _CTYPE_SWM) >> _CTYPE_SWS; - return -1; -} - -#undef wctrans -wctrans_t -wctrans(charclass) - const char *charclass; -{ - int i; - _RuneLocale *rl = _CurrentRuneLocale; - - if (rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name==NULL) - _wctrans_init(rl); - - for (i=0; i<_WCTRANS_NINDEXES; i++) - if (!strcmp(rl->rl_wctrans[i].te_name, charclass)) - return ((wctrans_t)&rl->rl_wctrans[i]); - - return ((wctrans_t)NULL); -} - -#undef towctrans -wint_t -towctrans(c, desc) - wint_t c; - wctrans_t desc; -{ - if (desc==NULL) { - errno = EINVAL; - return (c); - } - return (_towctrans(c, (_WCTransEntry *)desc)); -} - -#undef wctype -wctype_t -wctype(const char *property) -{ - int i; - _RuneLocale *rl = _CurrentRuneLocale; - - for (i=0; i<_WCTYPE_NINDEXES; i++) - if (!strcmp(rl->rl_wctype[i].te_name, property)) - return ((wctype_t)&rl->rl_wctype[i]); - return ((wctype_t)NULL); -} - -#undef iswctype -int -iswctype(wint_t c, wctype_t charclass) -{ - - /* - * SUSv3: If charclass is 0, iswctype() shall return 0. - */ - if (charclass == (wctype_t)0) { - return 0; - } - - return (__isctype_w(c, ((_WCTypeEntry *)charclass)->te_mask)); -} diff --git a/lib/libc/locale/iswctype_mb.c b/lib/libc/locale/iswctype_mb.c new file mode 100644 index 00000000000..f691fd15d25 --- /dev/null +++ b/lib/libc/locale/iswctype_mb.c @@ -0,0 +1,189 @@ +/* $NetBSD: iswctype_mb.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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: iswctype_mb.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#include <sys/types.h> +#include <assert.h> +#include <ctype.h> +#include <errno.h> +#include <langinfo.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stdlib.h> +#include <string.h> +#include <wctype.h> + +#include "setlocale_local.h" + +#include "rune.h" +#include "_wctype_local.h" +#include "_wctrans_local.h" + +#define _RUNE_LOCALE() ((_RuneLocale const *) \ + (*_current_locale())->part_impl[(size_t)LC_CTYPE]) + +#define _ISWCTYPE_FUNC(name, index) \ +int \ +isw##name(wint_t wc) \ +{ \ + _RuneLocale const *rl; \ + _WCTypeEntry const *te; \ + \ + rl = _RUNE_LOCALE(); \ + te = &rl->rl_wctype[index]; \ + return _iswctype_priv(rl, wc, te); \ +} +_ISWCTYPE_FUNC(alnum, _WCTYPE_INDEX_ALNUM) +_ISWCTYPE_FUNC(alpha, _WCTYPE_INDEX_ALPHA) +_ISWCTYPE_FUNC(blank, _WCTYPE_INDEX_BLANK) +_ISWCTYPE_FUNC(cntrl, _WCTYPE_INDEX_CNTRL) +_ISWCTYPE_FUNC(digit, _WCTYPE_INDEX_DIGIT) +_ISWCTYPE_FUNC(graph, _WCTYPE_INDEX_GRAPH) +_ISWCTYPE_FUNC(lower, _WCTYPE_INDEX_LOWER) +_ISWCTYPE_FUNC(print, _WCTYPE_INDEX_PRINT) +_ISWCTYPE_FUNC(punct, _WCTYPE_INDEX_PUNCT) +_ISWCTYPE_FUNC(space, _WCTYPE_INDEX_SPACE) +_ISWCTYPE_FUNC(upper, _WCTYPE_INDEX_UPPER) +_ISWCTYPE_FUNC(xdigit, _WCTYPE_INDEX_XDIGIT) + +#define _TOWCTRANS_FUNC(name, index) \ +wint_t \ +tow##name(wint_t wc) \ +{ \ + _RuneLocale const *rl; \ + _WCTransEntry const *te; \ + \ + rl = _RUNE_LOCALE(); \ + te = &rl->rl_wctrans[index]; \ + return _towctrans_priv(rl, wc, te); \ +} +_TOWCTRANS_FUNC(upper, _WCTRANS_INDEX_UPPER) +_TOWCTRANS_FUNC(lower, _WCTRANS_INDEX_LOWER) + +wctype_t +wctype(const char *charclass) +{ + _RuneLocale const *rl; + size_t i; + + rl = _RUNE_LOCALE(); + for (i = 0; i < _WCTYPE_NINDEXES; ++i) { + if (!strcmp(rl->rl_wctype[i].te_name, charclass)) + return (wctype_t)__UNCONST(&rl->rl_wctype[i]); + } + return (wctype_t)NULL; +} + +wctrans_t +wctrans(const char *charmap) +{ + _RuneLocale const *rl; + size_t i; + + rl = _RUNE_LOCALE(); + if (rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name == NULL) + _wctrans_init(__UNCONST(rl)); + for (i = 0; i < _WCTRANS_NINDEXES; ++i) { + if (!strcmp(rl->rl_wctrans[i].te_name, charmap)) + return (wctrans_t)__UNCONST(&rl->rl_wctype[i]); + } + return (wctrans_t)NULL; +} + +int +iswctype(wint_t wc, wctype_t charclass) +{ + _RuneLocale const *rl; + _WCTypeEntry const *te; + + if (charclass == NULL) { + errno = EINVAL; + return 0; + } + rl = _RUNE_LOCALE(); + te = (_WCTypeEntry const *)charclass; + return _iswctype_priv(rl, wc, te); +} + +wint_t +towctrans(wint_t wc, wctrans_t charmap) +{ + _RuneLocale const *rl; + _WCTransEntry const *te; + + if (charmap == NULL) { + errno = EINVAL; + return wc; + } + rl = _RUNE_LOCALE(); + te = (_WCTransEntry const *)charmap; + return _towctrans_priv(rl, wc, te); +} + +__weak_alias(wcwidth,_wcwidth) + +int +wcwidth(wchar_t wc) +{ + _RuneLocale const *rl; + _RuneType x; + + if (wc == L'\0') + return 0; + rl = _RUNE_LOCALE(); + x = _runetype_priv(rl, wc); + if (x & _CTYPE_R) + return ((unsigned)x & _CTYPE_SWM) >> _CTYPE_SWS; + return -1; +} + +int +wcswidth(const wchar_t * __restrict ws, size_t wn) +{ + _RuneLocale const *rl; + _RuneType x; + int width; + + _DIAGASSERT(ws != NULL); + + rl = _RUNE_LOCALE(); + width = 0; + while (wn > 0 && *ws != L'\0') { + x = _runetype_priv(rl, *ws); + if ((x & _CTYPE_R) == 0) + return -1; + width += ((unsigned)x & _CTYPE_SWM) >> _CTYPE_SWS; + ++ws, --wn; + } + return width; +} diff --git a/lib/libc/locale/iswctype_sb.c b/lib/libc/locale/iswctype_sb.c index f0179e96b29..f29c4c5a3bf 100644 --- a/lib/libc/locale/iswctype_sb.c +++ b/lib/libc/locale/iswctype_sb.c @@ -1,13 +1,8 @@ -/* $NetBSD: iswctype_sb.c,v 1.5 2008/08/12 20:51:25 tnozaki Exp $ */ +/* $NetBSD: iswctype_sb.c,v 1.6 2009/01/02 00:20:20 tnozaki Exp $ */ -/* - * Copyright (c) 1989 The Regents of the University of California. +/*- + * Copyright (c)2008 Citrus Project, * All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -17,14 +12,11 @@ * 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * 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 REGENTS OR CONTRIBUTORS BE LIABLE + * 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) @@ -36,134 +28,171 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: iswctype_sb.c,v 1.5 2008/08/12 20:51:25 tnozaki Exp $"); +__RCSID("$NetBSD: iswctype_sb.c,v 1.6 2009/01/02 00:20:20 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ -#include <wchar.h> -#include <wctype.h> +#include "namespace.h" +#include <assert.h> #include <ctype.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <wctype.h> +#include <wchar.h> -#undef iswalnum -int -iswalnum(c) - wint_t c; -{ - return isalnum((int)c); +#define _ISWCTYPE_FUNC(name) \ +int \ +isw##name(wint_t wc) \ +{ \ + int c; \ + \ + c = (wc == WEOF) ? EOF : (unsigned char)wc; \ + return is##name(c); \ } - -#undef iswalpha -int -iswalpha(c) - wint_t c; -{ - return isalpha((int)c); +_ISWCTYPE_FUNC(alnum) +_ISWCTYPE_FUNC(alpha) +_ISWCTYPE_FUNC(blank) +_ISWCTYPE_FUNC(cntrl) +_ISWCTYPE_FUNC(digit) +_ISWCTYPE_FUNC(graph) +_ISWCTYPE_FUNC(lower) +_ISWCTYPE_FUNC(print) +_ISWCTYPE_FUNC(punct) +_ISWCTYPE_FUNC(space) +_ISWCTYPE_FUNC(upper) +_ISWCTYPE_FUNC(xdigit) + +#define _TOWCTRANS_FUNC(name) \ +wint_t \ +tow##name(wint_t wc) \ +{ \ + c = (wc == WEOF) ? EOF : (unsigned char)wc; \ + return to##name(c); \ } - -#undef iswblank -int -iswblank(c) - wint_t c; +_TOWCTRANS_FUNC(upper) +_TOWCTRANS_FUNC(lower) + +struct _wctype_priv_t { + const char *name; + int (*iswctype)(wint_t); +}; + +static const struct _wctype_priv_t _wctype_decl[] = { + { "alnum", &iswalnum }, + { "alpha", &iswalpha }, + { "blank", &iswblank }, + { "cntrl", &iswcntrl }, + { "digit", &iswdigit }, + { "graph", &iswgraph }, + { "lower", &iswlower }, + { "print", &iswprint }, + { "punct", &iswpunct }, + { "space", &iswspace }, + { "upper", &iswupper }, + { "xdigit", &iswxdigit }, +}; +static const size_t _wctype_decl_size = + sizeof(_wctype_decl) / sizeof(struct _wctype_priv_t); + +wctype_t +wctype(const char *charclass) { - return isblank((int)c); -} + size_t i; -#undef iswcntrl -int -iswcntrl(c) - wint_t c; -{ - return iscntrl((int)c); -} - -#undef iswdigit -int -iswdigit(c) - wint_t c; -{ - return isdigit((int)c); + for (i = 0; i < _wctype_decl_size; ++i) { + if (!strcmp(charclass, _wctype_decl[i].name)) + return (wctype_t)__UNCONST(&_wctype_decl[i]); + } + return (wctrans_t)NULL; } -#undef iswgraph -int -iswgraph(c) - wint_t c; -{ - return isgraph((int)c); -} +struct _wctrans_priv_t { + const char *name; + wint_t (*towctrans)(wint_t); +}; -#undef iswlower -int -iswlower(c) - wint_t c; -{ - return islower((int)c); -} +static const struct _wctrans_priv_t _wctrans_decl[] = { + { "upper", &towupper }, + { "lower", &towlower }, +}; +static const size_t _wctrans_decl_size = + sizeof(_wctrans_decl) / sizeof(struct _wctrans_priv_t); -#undef iswprint -int -iswprint(c) - wint_t c; -{ - return isprint((int)c); -} - -#undef iswpunct -int -iswpunct(c) - wint_t c; +wctrans_t +/*ARGSUSED*/ +wctrans(const char *charmap) { - return ispunct((int)c); -} + size_t i; -#undef iswspace -int -iswspace(c) - wint_t c; -{ - return isspace((int)c); + for (i = 0; i < _wctrans_decl_size; ++i) { + if (!strcmp(charmap, _wctrans_decl[i].name)) + return (wctrans_t)__UNCONST(&_wctrans_decl[i]); + } + return (wctrans_t)NULL; } -#undef iswupper int -iswupper(c) - wint_t c; +/*ARGSUSED*/ +iswctype(wint_t wc, wctype_t charclass) { - return isupper((int)c); -} + const struct _wctype_priv_t *p; -#undef iswxdigit -int -iswxdigit(c) - wint_t c; -{ - return isxdigit((int)c); + p = (const struct _wctype_priv_t *)(void *)charclass; + if (p < &_wctype_decl[0] || p > &_wctype_decl[_wctype_decl_size - 1]) { + errno = EINVAL; + return 0; + } + return (*p->iswctype)(wc); } -#undef towupper wint_t -towupper(c) - wint_t c; +/*ARGSUSED*/ +towctrans(wint_t wc, wctrans_t charmap) { - return toupper((int)c); + const struct _wctrans_priv_t *p; + + p = (const struct _wctrans_priv_t *)(void *)charmap; + if (p < &_wctrans_decl[0] || p > &_wctrans_decl[_wctrans_decl_size - 1]) { + errno = EINVAL; + return wc; + } + return (*p->towctrans)(wc); } -#undef towlower -wint_t -towlower(c) - wint_t c; -{ - return tolower((int)c); -} +__weak_alias(wcwidth,_wcwidth) -#undef wcwidth int -/*ARGSUSED*/ -wcwidth(c) - wchar_t c; -{ - if (c == L'\0') +wcwidth(wchar_t wc) +{ + int c; + + switch (wc) { + case L'\0': return 0; - if (isprint((int)c)) + case WEOF: + c = EOF; + break; + default: + c = (unsigned char)wc; + } + if (isprint(c)) return 1; return -1; } + +int +wcswidth(const wchar_t * __restrict ws, size_t wn) +{ + const wchar_t *pws; + int c; + + pws = ws; + while (wn > 0 && *ws != L'\0') { + c = (*ws == WEOF) ? EOF : (unsigned char)*ws; + if (!isprint(c)) + return -1; + ++ws, --wn; + } + return (int)(ws - pws); +} diff --git a/lib/libc/locale/lcmessages.h b/lib/libc/locale/lcmessages.h deleted file mode 100644 index dd8a76a64a0..00000000000 --- a/lib/libc/locale/lcmessages.h +++ /dev/null @@ -1,33 +0,0 @@ -/* $NetBSD: lcmessages.h,v 1.1 2008/05/17 03:49:54 ginsbach Exp $ */ -/* - * Copyright (c) 2008 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Brian Ginsbach. - * - * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -__BEGIN_DECLS -int __loadmessages(const char *); -__END_DECLS diff --git a/lib/libc/locale/lcmonetary.c b/lib/libc/locale/lcmonetary.c deleted file mode 100644 index 4b4c706dc86..00000000000 --- a/lib/libc/locale/lcmonetary.c +++ /dev/null @@ -1,130 +0,0 @@ -/* $NetBSD: lcmonetary.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $ */ -/* - * Copyright (c) 2008, The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Brian Ginsbach. - * - * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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: lcmonetary.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/localedef.h> - -#include <assert.h> -#include <limits.h> -#include <stddef.h> -#include <stdlib.h> - -#include "localeio.h" -#include "lcmonetary.h" - -#define NSTRINGS \ - (offsetof(_MonetaryLocale, int_frac_digits)/sizeof(const char **)) -#define NCHARS \ - (offsetof(_MonetaryLocale, int_n_sign_posn) - \ - offsetof(_MonetaryLocale, int_frac_digits) + 1) - -int -__loadmonetary(const char *filename) -{ - const char **gpp; - - _DIAGASSERT(filename != NULL); - - if (!__loadlocale(filename, NSTRINGS, NCHARS, sizeof(_MonetaryLocale), - &_CurrentMonetaryLocale, &_DefaultMonetaryLocale)) { - return 0; - } - - gpp = __UNCONST(&_CurrentMonetaryLocale->mon_grouping); - *gpp = __convertgrouping(_CurrentMonetaryLocale->mon_grouping); - - return 1; -} - -#ifdef LOCALE_DEBUG - -#include "namespace.h" - -#include <stdio.h> - -void -__dumpmonetarylocale() -{ - const char *gp; - - (void)printf("int_curr_symbol = \"%s\"\n", - _CurrentMonetaryLocale->int_curr_symbol); - (void)printf("currency_symbol = \"%s\"\n", - _CurrentMonetaryLocale->currency_symbol); - (void)printf("mon_decimal_point = \"%s\"\n", - _CurrentMonetaryLocale->mon_decimal_point); - (void)printf("mon_thousands_sep = \"%s\"\n", - _CurrentMonetaryLocale->mon_thousands_sep); - (void)printf("mon_grouping = "); - for (gp = _CurrentMonetaryLocale->mon_grouping; *gp != '\0'; gp++) { - if (gp != _CurrentMonetaryLocale->mon_grouping) - (void)fputc(';', stdout); - (void)printf("%d", *gp); - } - (void)fputc('\n', stdout); - (void)printf("positive_sign = \"%s\"\n", - _CurrentMonetaryLocale->positive_sign); - (void)printf("negative_sign = \"%s\"\n", - _CurrentMonetaryLocale->negative_sign); - (void)printf("int_frac_digits = %d\n", - _CurrentMonetaryLocale->int_frac_digits); - (void)printf("frac_digits = %d\n", - _CurrentMonetaryLocale->frac_digits); - (void)printf("p_cs_precedes = %d\n", - _CurrentMonetaryLocale->p_cs_precedes); - (void)printf("p_sep_by_space = %d\n", - _CurrentMonetaryLocale->p_sep_by_space); - (void)printf("n_cs_precedes = %d\n", - _CurrentMonetaryLocale->n_cs_precedes); - (void)printf("n_sep_by_space = %d\n", - _CurrentMonetaryLocale->n_sep_by_space); - (void)printf("p_sign_posn = %d\n", - _CurrentMonetaryLocale->p_sign_posn); - (void)printf("n_sign_posn = %d\n", - _CurrentMonetaryLocale->n_sign_posn); - (void)printf("int_p_cs_precedes = %d\n", - _CurrentMonetaryLocale->int_p_cs_precedes); - (void)printf("int_n_cs_precedes = %d\n", - _CurrentMonetaryLocale->int_n_cs_precedes); - (void)printf("int_p_sep_by_space = %d\n", - _CurrentMonetaryLocale->int_p_sep_by_space); - (void)printf("int_n_sep_by_space = %d\n", - _CurrentMonetaryLocale->int_n_sep_by_space); - (void)printf("int_p_sign_posn = %d\n", - _CurrentMonetaryLocale->int_p_sign_posn); - (void)printf("int_n_sign_posn = %d\n", - _CurrentMonetaryLocale->int_n_sign_posn); -} -#endif diff --git a/lib/libc/locale/lcmonetary.h b/lib/libc/locale/lcmonetary.h deleted file mode 100644 index 041c39628a0..00000000000 --- a/lib/libc/locale/lcmonetary.h +++ /dev/null @@ -1,33 +0,0 @@ -/* $NetBSD: lcmonetary.h,v 1.1 2008/05/17 03:49:54 ginsbach Exp $ */ -/* - * Copyright (c) 2008 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Brian Ginsbach. - * - * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -__BEGIN_DECLS -int __loadmonetary(const char *); -__END_DECLS diff --git a/lib/libc/locale/lcnumeric.h b/lib/libc/locale/lcnumeric.h deleted file mode 100644 index f9f60996626..00000000000 --- a/lib/libc/locale/lcnumeric.h +++ /dev/null @@ -1,30 +0,0 @@ -/* $NetBSD: lcnumeric.h,v 1.1 2008/05/17 03:49:54 ginsbach Exp $ */ -/* - * Copyright (c) 2008, The NetBSD Foundation. - * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -__BEGIN_DECLS -int __loadnumeric(const char *); -__END_DECLS diff --git a/lib/libc/locale/lctime.h b/lib/libc/locale/lctime.h deleted file mode 100644 index e2f31cee5a0..00000000000 --- a/lib/libc/locale/lctime.h +++ /dev/null @@ -1,33 +0,0 @@ -/* $NetBSD: lctime.h,v 1.1 2008/05/17 03:49:54 ginsbach Exp $ */ -/* - * Copyright (c) 2008 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by - * - * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -__BEGIN_DECLS -int __loadtime(const char *); -__END_DECLS diff --git a/lib/libc/locale/localeconv.c b/lib/libc/locale/localeconv.c index cc2f9ab7f35..45d2702f6dc 100644 --- a/lib/libc/locale/localeconv.c +++ b/lib/libc/locale/localeconv.c @@ -1,85 +1,48 @@ -/* $NetBSD: localeconv.c,v 1.14 2007/05/26 13:14:13 tnozaki Exp $ */ +/* $NetBSD: localeconv.c,v 1.15 2009/01/02 00:20:20 tnozaki Exp $ */ -/* - * Written by J.T. Conklin <jtc@NetBSD.org>. - * Public domain. +/*- + * Copyright (c)2008 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: localeconv.c,v 1.14 2007/05/26 13:14:13 tnozaki Exp $"); +__RCSID("$NetBSD: localeconv.c,v 1.15 2009/01/02 00:20:20 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ -#include <sys/localedef.h> +#include <sys/types.h> +#include <langinfo.h> +#define __SETLOCALE_SOURCE__ #include <locale.h> -/* - * The localeconv() function constructs a struct lconv from the current - * monetary and numeric locales. - * - * Because localeconv() may be called many times (especially by library - * routines like printf() & strtod()), the appropriate members of the - * lconv structure are computed only when the monetary or numeric - * locale has been changed. - */ -int __mlocale_changed = 1; -int __nlocale_changed = 1; +#include "setlocale_local.h" -/* - * Return the current locale conversion. - */ struct lconv * localeconv() { - static struct lconv ret; - - if (__mlocale_changed) { - /* LC_MONETARY */ - ret.int_curr_symbol = - __UNCONST(_CurrentMonetaryLocale->int_curr_symbol); - ret.currency_symbol = - __UNCONST(_CurrentMonetaryLocale->currency_symbol); - ret.mon_decimal_point = - __UNCONST(_CurrentMonetaryLocale->mon_decimal_point); - ret.mon_thousands_sep = - __UNCONST(_CurrentMonetaryLocale->mon_thousands_sep); - ret.mon_grouping = - __UNCONST(_CurrentMonetaryLocale->mon_grouping); - ret.positive_sign = - __UNCONST(_CurrentMonetaryLocale->positive_sign); - ret.negative_sign = - __UNCONST(_CurrentMonetaryLocale->negative_sign); - ret.int_frac_digits = _CurrentMonetaryLocale->int_frac_digits; - ret.frac_digits = _CurrentMonetaryLocale->frac_digits; - ret.p_cs_precedes = _CurrentMonetaryLocale->p_cs_precedes; - ret.p_sep_by_space = _CurrentMonetaryLocale->p_sep_by_space; - ret.n_cs_precedes = _CurrentMonetaryLocale->n_cs_precedes; - ret.n_sep_by_space = _CurrentMonetaryLocale->n_sep_by_space; - ret.p_sign_posn = _CurrentMonetaryLocale->p_sign_posn; - ret.n_sign_posn = _CurrentMonetaryLocale->n_sign_posn; - ret.int_p_cs_precedes = - _CurrentMonetaryLocale->int_p_cs_precedes; - ret.int_n_cs_precedes = - _CurrentMonetaryLocale->int_n_cs_precedes; - ret.int_p_sep_by_space = - _CurrentMonetaryLocale->int_p_sep_by_space; - ret.int_n_sep_by_space = - _CurrentMonetaryLocale->int_n_sep_by_space; - ret.int_p_sign_posn = _CurrentMonetaryLocale->int_p_sign_posn; - ret.int_n_sign_posn = _CurrentMonetaryLocale->int_n_sign_posn; - __mlocale_changed = 0; - } - - if (__nlocale_changed) { - /* LC_NUMERIC */ - ret.decimal_point = - __UNCONST(_CurrentNumericLocale->decimal_point); - ret.thousands_sep = - __UNCONST(_CurrentNumericLocale->thousands_sep); - ret.grouping = - __UNCONST(_CurrentNumericLocale->grouping); - __nlocale_changed = 0; - } + struct _locale_impl_t *impl; - return (&ret); + impl = *_current_locale(); + return &impl->cache.ldata; } diff --git a/lib/libc/locale/localeio.c b/lib/libc/locale/localeio.c index 68fd09829c8..6885bb94fed 100644 --- a/lib/libc/locale/localeio.c +++ b/lib/libc/locale/localeio.c @@ -1,4 +1,4 @@ -/* $NetBSD: localeio.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $ */ +/* $NetBSD: localeio.c,v 1.2 2009/01/02 00:20:20 tnozaki Exp $ */ /* * Copyright (c) 2008, The NetBSD Foundation, Inc. * All rights reserved. @@ -30,16 +30,16 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: localeio.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $"); +__RCSID("$NetBSD: localeio.c,v 1.2 2009/01/02 00:20:20 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" -#include <sys/localedef.h> #include <sys/types.h> #include <sys/stat.h> #include <assert.h> +#include <errno.h> #include <fcntl.h> #include <limits.h> #include <locale.h> @@ -51,10 +51,10 @@ __RCSID("$NetBSD: localeio.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $"); #include "localeio.h" int -__loadlocale(const char *name, size_t nstr, size_t nbytes, size_t localesize, - void *currentlocale, const void *defaultlocale) +__loadlocale(const char *name, size_t nstr, size_t nbytes, + size_t localesize, void *currentlocale) { - int fd, i; + int fd, i, ret; unsigned char **ap, *buf, *bp, *cp, *cbp, *ebp; unsigned char ***locale; struct stat st; @@ -63,29 +63,37 @@ __loadlocale(const char *name, size_t nstr, size_t nbytes, size_t localesize, _DIAGASSERT(name != NULL); _DIAGASSERT(localesize != 0); _DIAGASSERT(currentlocale != NULL); - _DIAGASSERT(defaultlocale != NULL); if ((fd = open(name, O_RDONLY)) == -1) - return 0; + return ENOENT; - if ((fstat(fd, &st) == -1) || (st.st_size <= 0)) + if ((fstat(fd, &st) == -1) || !S_ISREG(st.st_mode) || + (st.st_size <= 0)) { + ret = EFTYPE; goto error1; + } bufsize = localesize + (size_t)st.st_size; - if ((buf = malloc(bufsize)) == NULL) + if ((buf = malloc(bufsize)) == NULL) { + ret = ENOMEM; goto error1; + } bp = buf + localesize; - if (read(fd, bp, (size_t)st.st_size) != st.st_size) + if (read(fd, bp, (size_t)st.st_size) != st.st_size) { + ret = EFTYPE; goto error2; + } ap = (unsigned char **)(void *)buf; for (i = 0, ebp = buf + bufsize; i < nstr; i++) { ap[i] = bp; while (bp != ebp && *bp != '\n') bp++; - if (bp == ebp) + if (bp == ebp) { + ret = EFTYPE; goto error2; + } *bp++ = '\0'; } @@ -95,8 +103,10 @@ __loadlocale(const char *name, size_t nstr, size_t nbytes, size_t localesize, while (bp != ebp && *bp != '\n') bp++; - if (bp == ebp) + if (bp == ebp) { + ret = EFTYPE; goto error2; + } /* ignore overflow/underflow and bad characters */ n = (unsigned char)strtol((char *)cbp, NULL, 0); cp[i] = (unsigned char)(n & CHAR_MAX); @@ -104,51 +114,15 @@ __loadlocale(const char *name, size_t nstr, size_t nbytes, size_t localesize, } locale = currentlocale; - if (*locale != defaultlocale) - free(*locale); *locale = (unsigned char **)(void *)buf; (void)close(fd); - return 1; + return 0; error2: free(buf); + error1: (void)close(fd); - - return 0; -} - -/* - * Convert a grouping sequence string into POSIX form. - * - * Examples: "3;3;-1" -> "\003\003\177\000" - * "3" -> "\003\000" - */ - -static const char nogrouping[] = { CHAR_MAX, '\0' }; - -const char * -__convertgrouping(const char *str) -{ - char *src, *dst; - - _DIAGASSERT(str != NULL); - - src = dst = __UNCONST(str); - - while (*src != '\0') { - char *ep; - int n; - - if ((n = strtol(src, &ep, 0)) >= CHAR_MAX || - ((*ep != ';') && (*ep != '\0'))) - return nogrouping; /* invalid grouping string */ - - *dst++ = n & CHAR_MAX; - src = (*ep == ';')? ep + 1 : ep; - } - *dst = '\0'; - - return (dst == str)? nogrouping : str; + return ret; } diff --git a/lib/libc/locale/localeio.h b/lib/libc/locale/localeio.h index d5d3fa8d17c..1b0a2fb8896 100644 --- a/lib/libc/locale/localeio.h +++ b/lib/libc/locale/localeio.h @@ -1,4 +1,4 @@ -/* $NetBSD: localeio.h,v 1.1 2008/05/17 03:49:54 ginsbach Exp $ */ +/* $NetBSD: localeio.h,v 1.2 2009/01/02 00:20:20 tnozaki Exp $ */ /* * Copyright (c) 2008, The NetBSD Foundation, Inc. * All rights reserved. @@ -29,6 +29,5 @@ */ __BEGIN_DECLS -int __loadlocale(const char *, size_t, size_t, size_t, void *, const void *); -const char * __convertgrouping(const char *); +int __loadlocale(const char *, size_t, size_t, size_t, void *); __END_DECLS diff --git a/lib/libc/locale/localeio_lc_ctype.c b/lib/libc/locale/localeio_lc_ctype.c new file mode 100644 index 00000000000..831b22a26a9 --- /dev/null +++ b/lib/libc/locale/localeio_lc_ctype.c @@ -0,0 +1,114 @@ +/* $NetBSD: localeio_lc_ctype.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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: localeio_lc_ctype.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "reentrant.h" +#include <sys/types.h> +#include <sys/queue.h> +#include <assert.h> +#include <ctype.h> +#include <errno.h> +#include <langinfo.h> +#include <limits.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "setlocale_local.h" + +#include "aliasname_local.h" +#include "bsdctype.h" +#include "ctypeio.h" + +/* + * macro required by all template headers + */ +#define _PREFIX(name) __CONCAT(_localeio_LC_CTYPE_, name) + +/* + * macro required by nb_lc_template(_decl).h + */ +#define _CATEGORY_TYPE _BSDCTypeLocale + +#include "nb_lc_template_decl.h" + +static int +/*ARGSUSED*/ +_localeio_LC_CTYPE_create_impl(const char * __restrict root, + const char * __restrict name, _BSDCTypeLocale ** __restrict pdata) +{ + char path[PATH_MAX + 1]; + + _DIAGASSERT(root != NULL); + _DIAGASSERT(name != NULL); + _DIAGASSERT(pdata != NULL); + + snprintf(path, sizeof(path), + "%s/%s/LC_CTYPE", root, name); + return __loadctype(path, pdata); +} + +static __inline void +_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache, + _BSDCTypeLocale * __restrict data) +{ + _DIAGASSERT(cache != NULL); + _DIAGASSERT(data != NULL); + + cache->ctype_tab = data->ctype_tab; + cache->tolower_tab = data->tolower_tab; + cache->toupper_tab = data->toupper_tab; + cache->mb_cur_max = (size_t)1; +} + +static __inline void +_PREFIX(fixup)(_BSDCTypeLocale *data) +{ + _DIAGASSERT(data != NULL); + + _ctype_ = data->ctype_tab; + _tolower_tab_ = data->tolower_tab; + _toupper_tab_ = data->toupper_tab; +} + +/* + * macro required by nb_lc_template.h + */ +#define _CATEGORY_ID LC_CTYPE +#define _CATEGORY_NAME "LC_CTYPE" +#define _CATEGORY_DEFAULT _DefaultBSDCTypeLocale + +#include "nb_lc_template.h" +#include "generic_lc_template.h" +_LOCALE_CATEGORY_ENTRY(_localeio_LC_CTYPE_); diff --git a/lib/libc/locale/lcmessages.c b/lib/libc/locale/localeio_lc_messages.c index 0b450c8f51d..a76c0690770 100644 --- a/lib/libc/locale/lcmessages.c +++ b/lib/libc/locale/localeio_lc_messages.c @@ -1,4 +1,5 @@ -/* $NetBSD: lcmessages.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $ */ +/* $NetBSD: localeio_lc_messages.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + /* * Copyright (c) 2008, The NetBSD Foundation, Inc. * All rights reserved. @@ -30,42 +31,53 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: lcmessages.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $"); +__RCSID("$NetBSD: localeio_lc_messages.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ +#include "reentrant.h" #include <sys/types.h> #include <sys/localedef.h> - +#include <sys/queue.h> #include <assert.h> +#include <errno.h> +#include <langinfo.h> +#include <limits.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "setlocale_local.h" +#include "aliasname_local.h" #include "localeio.h" -#include "lcmessages.h" + +/* + * macro required by all template headers + */ +#define _PREFIX(name) __CONCAT(_localeio_LC_MESSAGES_, name) + +#include "nb_lc_messages_misc.h" +#include "nb_lc_template_decl.h" #define NSTRINGS (sizeof(_MessagesLocale)/sizeof(const char **)) -int -__loadmessages(const char *filename) +static int +_localeio_LC_MESSAGES_create_impl(const char * __restrict root, + const char * __restrict name, _MessagesLocale ** __restrict pdata) { + char path[PATH_MAX + 1]; - _DIAGASSERT(filename != NULL); + _DIAGASSERT(root != NULL); + _DIAGASSERT(name != NULL); + _DIAGASSERT(pdata != NULL); - return __loadlocale(filename, NSTRINGS, 0, sizeof(_MessagesLocale), - &_CurrentMessagesLocale, &_DefaultMessagesLocale); + snprintf(path, sizeof(path), + "%s/%s/LC_MESSAGES/SYS_LC_MESSAGES", root, name); + return __loadlocale(path, NSTRINGS, 0, sizeof(_MessagesLocale), + (void *)pdata); } -#ifdef LOCALE_DEBUG - -#include "namespace.h" - -#include <stdio.h> - -void -__dumptimelocale() -{ - - (void)printf("yesexpr = \"%s\"\n", _CurrentMessagesLocale->yesexpr); - (void)printf("noexpr = \"%s\"\n", _CurrentMessagesLocale->noexpr); - (void)printf("yesstr = \"%s\"\n", _CurrentMessagesLocale->yesstr); - (void)printf("nostr = \"%s\"\n", _CurrentMessagesLocale->nostr); -} -#endif /* LOCALE_DEBUG */ +#include "nb_lc_template.h" +_LOCALE_CATEGORY_ENTRY(_localeio_LC_MESSAGES_); diff --git a/lib/libc/locale/localeio_lc_monetary.c b/lib/libc/locale/localeio_lc_monetary.c new file mode 100644 index 00000000000..6d8a3d59bc9 --- /dev/null +++ b/lib/libc/locale/localeio_lc_monetary.c @@ -0,0 +1,95 @@ +/* $NetBSD: localeio_lc_monetary.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/* + * Copyright (c) 2008, The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Brian Ginsbach. + * + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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: localeio_lc_monetary.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "reentrant.h" +#include <sys/types.h> +#include <sys/localedef.h> +#include <sys/queue.h> +#include <assert.h> +#include <errno.h> +#include <langinfo.h> +#include <limits.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "setlocale_local.h" + +#include "aliasname_local.h" +#include "fix_grouping.h" +#include "localeio.h" + +/* + * macro required by all template headers + */ +#define _PREFIX(name) __CONCAT(_localeio_LC_MONETARY_, name) + +#include "nb_lc_monetary_misc.h" +#include "nb_lc_template_decl.h" + +#define NSTRINGS \ + (offsetof(_MonetaryLocale, int_frac_digits)/sizeof(const char **)) +#define NCHARS \ + (offsetof(_MonetaryLocale, int_n_sign_posn) - \ + offsetof(_MonetaryLocale, int_frac_digits) + 1) + +static int +_localeio_LC_MONETARY_create_impl(const char * __restrict root, + const char * __restrict name, _MonetaryLocale ** __restrict pdata) +{ + char path[PATH_MAX + 1]; + int ret; + + _DIAGASSERT(root != NULL); + _DIAGASSERT(name != NULL); + _DIAGASSERT(pdata != NULL); + + snprintf(path, sizeof(path), + "%s/%s/LC_MONETARY", root, name); + ret = __loadlocale(path, NSTRINGS, NCHARS, sizeof(_MonetaryLocale), + (void *)pdata); + if (!ret) { + (*pdata)->mon_grouping = + __fix_locale_grouping_str((*pdata)->mon_grouping); + } + return ret; +} + +#include "nb_lc_template.h" +_LOCALE_CATEGORY_ENTRY(_localeio_LC_MONETARY_); diff --git a/lib/libc/locale/lctime.c b/lib/libc/locale/localeio_lc_numeric.c index 3398d46fed1..121e2ec8d7d 100644 --- a/lib/libc/locale/lctime.c +++ b/lib/libc/locale/localeio_lc_numeric.c @@ -1,4 +1,5 @@ -/* $NetBSD: lctime.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $ */ +/* $NetBSD: localeio_lc_numeric.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + /* * Copyright (c) 2008, The NetBSD Foundation, Inc. * All rights reserved. @@ -30,63 +31,60 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: lctime.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $"); +__RCSID("$NetBSD: localeio_lc_numeric.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ +#include "reentrant.h" #include <sys/types.h> #include <sys/localedef.h> - +#include <sys/queue.h> #include <assert.h> - -#include "localeio.h" -#include "lctime.h" - -#define NSTRINGS (sizeof(_TimeLocale)/sizeof(const char **)) - -int -__loadtime(const char *filename) -{ - - _DIAGASSERT(filename != NULL); - - return (__loadlocale(filename, NSTRINGS, 0, sizeof(_TimeLocale), - &_CurrentTimeLocale, &_DefaultTimeLocale)); -} - -#ifdef LOCALE_DEBUG - -#include "namespace.h" - +#include <errno.h> +#include <langinfo.h> +#include <limits.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> -void -__dumptimelocale() -{ - int i; - - for (i = 0; i < 7; i++) - (void)printf("abday[%d] = \"%s\"\n", - i, _CurrentTimeLocale->abday[i]); +#include "setlocale_local.h" - for (i = 0; i < 7; i++) - (void)printf("day[%d] = \"%s\"\n", - i, _CurrentTimeLocale->day[i]); +#include "aliasname_local.h" +#include "fix_grouping.h" +#include "localeio.h" - for (i = 0; i < 12; i++) - (void)printf("abmon[%d] = \"%s\"\n", - i, _CurrentTimeLocale->abmon[i]); +/* + * macro required by all template headers + */ +#define _PREFIX(name) __CONCAT(_localeio_LC_NUMERIC_, name) - for (i = 0; i < 12; i++) - (void)printf("mon[%d] = \"%s\"\n", - i, _CurrentTimeLocale->mon[i]); +#include "nb_lc_numeric_misc.h" +#include "nb_lc_template_decl.h" - for (i = 0; i < 2; i++) - (void)printf("am_pm[%d] = \"%s\"\n", - i, _CurrentTimeLocale->am_pm[i]); +#define NSTRINGS (sizeof(_NumericLocale)/sizeof(const char **)) - (void)printf("d_t_fmt = \"%s\"\n", _CurrentTimeLocale->d_t_fmt); - (void)printf("d_fmt = \"%s\"\n", _CurrentTimeLocale->d_fmt); - (void)printf("t_fmt = \"%s\"\n", _CurrentTimeLocale->t_fmt); - (void)printf("t_fmt_ampm = \"%s\"\n", _CurrentTimeLocale->t_fmt_ampm); +static int +_localeio_LC_NUMERIC_create_impl(const char * __restrict root, + const char * __restrict name, _NumericLocale ** __restrict pdata) +{ + char path[PATH_MAX + 1]; + int ret; + + _DIAGASSERT(root != NULL); + _DIAGASSERT(name != NULL); + _DIAGASSERT(pdata != NULL); + + snprintf(path, sizeof(path), + "%s/%s/LC_NUMERIC", root, name); + ret = __loadlocale(path, NSTRINGS, 0, sizeof(_NumericLocale), + (void *)pdata); + if (!ret) { + (*pdata)->grouping = + __fix_locale_grouping_str((*pdata)->grouping); + } + return ret; } -#endif /* LOCALE_DEBUG */ + +#include "nb_lc_template.h" +_LOCALE_CATEGORY_ENTRY(_localeio_LC_NUMERIC_); diff --git a/lib/libc/locale/lcnumeric.c b/lib/libc/locale/localeio_lc_time.c index c15fb856602..bf3e13e2a04 100644 --- a/lib/libc/locale/lcnumeric.c +++ b/lib/libc/locale/localeio_lc_time.c @@ -1,4 +1,5 @@ -/* $NetBSD: lcnumeric.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $ */ +/* $NetBSD: localeio_lc_time.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + /* * Copyright (c) 2008, The NetBSD Foundation, Inc. * All rights reserved. @@ -30,57 +31,54 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: lcnumeric.c,v 1.1 2008/05/17 03:49:54 ginsbach Exp $"); +__RCSID("$NetBSD: localeio_lc_time.c,v 1.1 2009/01/02 00:20:20 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ +#include "reentrant.h" #include <sys/types.h> #include <sys/localedef.h> - +#include <sys/queue.h> #include <assert.h> +#include <errno.h> +#include <langinfo.h> +#include <limits.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "setlocale_local.h" +#include "aliasname_local.h" +#include "fix_grouping.h" #include "localeio.h" -#include "lcnumeric.h" -#define NSTRINGS (sizeof(_NumericLocale)/sizeof(const char **)) +/* + * macro required by all template headers + */ +#define _PREFIX(name) __CONCAT(_localeio_LC_TIME_, name) -int -__loadnumeric(const char *filename) -{ - const char **gpp; +#include "nb_lc_time_misc.h" +#include "nb_lc_template_decl.h" - _DIAGASSERT(filename != NULL); +#define NSTRINGS (sizeof(_TimeLocale)/sizeof(const char **)) - if (!__loadlocale(filename, NSTRINGS, 0, sizeof(_NumericLocale), - &_CurrentNumericLocale, &_DefaultNumericLocale)) { - return 0; - } +static int +_localeio_LC_TIME_create_impl(const char * __restrict root, + const char * __restrict name, _TimeLocale ** __restrict pdata) +{ + char path[PATH_MAX + 1]; - gpp = __UNCONST(&_CurrentNumericLocale->grouping); - *gpp = __convertgrouping(_CurrentNumericLocale->grouping); + _DIAGASSERT(root != NULL); + _DIAGASSERT(name != NULL); + _DIAGASSERT(pdata != NULL); - return 1; + snprintf(path, sizeof(path), + "%s/%s/LC_TIME", root, name); + return __loadlocale(path, NSTRINGS, 0, sizeof(_TimeLocale), + (void *)pdata); } -#ifdef LOCALE_DEBUG - -#include "namespace.h" - -#include <stdio.h> - -void -__dumpnumericlocale() -{ - const char *gp; - - (void)printf("decimal_point = \"%s\"\n", - _CurrentNumericLocale->decimal_point); - (void)printf("thousands_sep = \"%s\"\n", - _CurrentNumericLocale->thousands_sep); - (void)printf("grouping = "); - for (gp = _CurrentNumericLocale->grouping; *gp != '\0'; gp++) { - if (gp != _CurrentNumericLocale->grouping) - (void)fputc(';', stdout); - (void)printf("\\%03o", *gp); - } -} -#endif /* LOCALE_DEBUG */ +#include "nb_lc_template.h" +_LOCALE_CATEGORY_ENTRY(_localeio_LC_TIME_); diff --git a/lib/libc/locale/multibyte.h b/lib/libc/locale/multibyte.h index fb4d5527272..55d4b38696c 100644 --- a/lib/libc/locale/multibyte.h +++ b/lib/libc/locale/multibyte.h @@ -1,4 +1,4 @@ -/* $NetBSD: multibyte.h,v 1.3 2003/04/29 14:53:12 scw Exp $ */ +/* $NetBSD: multibyte.h,v 1.4 2009/01/02 00:20:20 tnozaki Exp $ */ /*- * Copyright (c)2002 Citrus Project, @@ -123,4 +123,4 @@ _fixup_ps(_RuneLocale *rl, mbstate_t *ps, int forceinit) } } -#endif +#endif /*_MULTIBYTE_H_*/ diff --git a/lib/libc/locale/multibyte_amd1.c b/lib/libc/locale/multibyte_amd1.c index 068f4c42461..0658c1fa0c6 100644 --- a/lib/libc/locale/multibyte_amd1.c +++ b/lib/libc/locale/multibyte_amd1.c @@ -1,7 +1,7 @@ -/* $NetBSD: multibyte_amd1.c,v 1.5 2003/03/05 20:18:16 tshiozak Exp $ */ +/* $NetBSD: multibyte_amd1.c,v 1.6 2009/01/02 00:20:20 tnozaki Exp $ */ /*- - * Copyright (c)2002 Citrus Project, + * Copyright (c)2002, 2008 Citrus Project, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,25 +28,37 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: multibyte_amd1.c,v 1.5 2003/03/05 20:18:16 tshiozak Exp $"); +__RCSID("$NetBSD: multibyte_amd1.c,v 1.6 2009/01/02 00:20:20 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ +#include <sys/types.h> #include <assert.h> -#include <wchar.h> #include <errno.h> -#include <sys/types.h> -#include <citrus/citrus_module.h> -#include <citrus/citrus_ctype.h> +#include <langinfo.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <wchar.h> + +#include "setlocale_local.h" + +#include "citrus_module.h" +#include "citrus_ctype.h" #include "rune.h" #include "multibyte.h" +#define _RUNE_LOCALE() \ + ((_RuneLocale *)(*_current_locale())->part_impl[(size_t)LC_CTYPE]) + +#define _CITRUS_CTYPE() \ + (_RUNE_LOCALE()->rl_citrus_ctype) + size_t mbrlen(const char *s, size_t n, mbstate_t *ps) { size_t ret; int err0; - _fixup_ps(_CurrentRuneLocale, ps, s==NULL); + _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); err0 = _citrus_ctype_mbrlen(_ps_to_ctype(ps), s, n, _ps_to_private(ps), &ret); @@ -67,7 +79,7 @@ mbsinit(const mbstate_t *ps) return 1; if (_ps_to_runelocale(ps) == NULL) - rl = _CurrentRuneLocale; + rl = _RUNE_LOCALE(); else rl = _ps_to_runelocale(ps); @@ -86,7 +98,7 @@ mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) size_t ret; int err0; - _fixup_ps(_CurrentRuneLocale, ps, s==NULL); + _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); err0 = _citrus_ctype_mbrtowc(_ps_to_ctype(ps), pwc, s, n, _ps_to_private(ps), &ret); @@ -102,7 +114,7 @@ mbsrtowcs(wchar_t *pwcs, const char **s, size_t n, mbstate_t *ps) size_t ret; int err0; - _fixup_ps(_CurrentRuneLocale, ps, s==NULL); + _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); err0 = _citrus_ctype_mbsrtowcs(_ps_to_ctype(ps), pwcs, s, n, _ps_to_private(ps), &ret); @@ -118,7 +130,7 @@ wcrtomb(char *s, wchar_t wc, mbstate_t *ps) size_t ret; int err0; - _fixup_ps(_CurrentRuneLocale, ps, s==NULL); + _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); err0 = _citrus_ctype_wcrtomb(_ps_to_ctype(ps), s, wc, _ps_to_private(ps), &ret); @@ -134,7 +146,7 @@ wcsrtombs(char *s, const wchar_t **ppwcs, size_t n, mbstate_t *ps) size_t ret; int err0; - _fixup_ps(_CurrentRuneLocale, ps, s==NULL); + _fixup_ps(_RUNE_LOCALE(), ps, s == NULL); err0 = _citrus_ctype_wcsrtombs(_ps_to_ctype(ps), s, ppwcs, n, _ps_to_private(ps), &ret); @@ -150,7 +162,7 @@ btowc(int c) wint_t ret; int err0; - err0 = _citrus_ctype_btowc(_to_cur_ctype(), c, &ret); + err0 = _citrus_ctype_btowc(_CITRUS_CTYPE(), c, &ret); if (err0) errno = err0; @@ -163,7 +175,7 @@ wctob(wint_t wc) int ret; int err0; - err0 = _citrus_ctype_wctob(_to_cur_ctype(), wc, &ret); + err0 = _citrus_ctype_wctob(_CITRUS_CTYPE(), wc, &ret); if (err0) errno = err0; diff --git a/lib/libc/locale/multibyte_c90.c b/lib/libc/locale/multibyte_c90.c index a3d3524af8d..d2da1875ef7 100644 --- a/lib/libc/locale/multibyte_c90.c +++ b/lib/libc/locale/multibyte_c90.c @@ -1,7 +1,7 @@ -/* $NetBSD: multibyte_c90.c,v 1.4 2003/03/05 20:18:16 tshiozak Exp $ */ +/* $NetBSD: multibyte_c90.c,v 1.5 2009/01/02 00:20:20 tnozaki Exp $ */ /*- - * Copyright (c)2002 Citrus Project, + * Copyright (c)2002, 2008 Citrus Project, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,18 +28,29 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: multibyte_c90.c,v 1.4 2003/03/05 20:18:16 tshiozak Exp $"); +__RCSID("$NetBSD: multibyte_c90.c,v 1.5 2009/01/02 00:20:20 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> #include <assert.h> -#include <stdlib.h> #include <errno.h> +#include <langinfo.h> +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stdlib.h> #include <wchar.h> -#include <citrus/citrus_module.h> -#include <citrus/citrus_ctype.h> + +#include "setlocale_local.h" + +#include "citrus_module.h" +#include "citrus_ctype.h" #include "rune.h" -#include "multibyte.h" + +#define _RUNE_LOCALE() \ + ((_RuneLocale *)(*_current_locale())->part_impl[(size_t)LC_CTYPE]) + +#define _CITRUS_CTYPE() \ + (_RUNE_LOCALE()->rl_citrus_ctype) int mblen(const char *s, size_t n) @@ -47,7 +58,7 @@ mblen(const char *s, size_t n) int ret; int err0; - err0 = _citrus_ctype_mblen(_to_cur_ctype(), s, n, &ret); + err0 = _citrus_ctype_mblen(_CITRUS_CTYPE(), s, n, &ret); if (err0) errno = err0; @@ -60,7 +71,7 @@ mbstowcs(wchar_t *pwcs, const char *s, size_t n) size_t ret; int err0; - err0 = _citrus_ctype_mbstowcs(_to_cur_ctype(), pwcs, s, n, &ret); + err0 = _citrus_ctype_mbstowcs(_CITRUS_CTYPE(), pwcs, s, n, &ret); if (err0) errno = err0; @@ -73,7 +84,7 @@ mbtowc(wchar_t *pw, const char *s, size_t n) int ret; int err0; - err0 = _citrus_ctype_mbtowc(_to_cur_ctype(), pw, s, n, &ret); + err0 = _citrus_ctype_mbtowc(_CITRUS_CTYPE(), pw, s, n, &ret); if (err0) errno = err0; @@ -86,7 +97,7 @@ wcstombs(char *s, const wchar_t *wcs, size_t n) size_t ret; int err0; - err0 = _citrus_ctype_wcstombs(_to_cur_ctype(), s, wcs, n, &ret); + err0 = _citrus_ctype_wcstombs(_CITRUS_CTYPE(), s, wcs, n, &ret); if (err0) errno = err0; @@ -99,7 +110,7 @@ wctomb(char *s, wchar_t wc) int ret; int err0; - err0 = _citrus_ctype_wctomb(_to_cur_ctype(), s, wc, &ret); + err0 = _citrus_ctype_wctomb(_CITRUS_CTYPE(), s, wc, &ret); if (err0) errno = err0; diff --git a/lib/libc/locale/nb_lc_messages_misc.h b/lib/libc/locale/nb_lc_messages_misc.h new file mode 100644 index 00000000000..7dff6d79502 --- /dev/null +++ b/lib/libc/locale/nb_lc_messages_misc.h @@ -0,0 +1,65 @@ +/* $NetBSD: nb_lc_messages_misc.h,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _NB_LC_MESSAGES_MISC_H_ +#define _NB_LC_MESSAGES_MISC_H_ + +/* + * macro required by nb_lc_template(_decl).h + */ +#define _CATEGORY_TYPE _MessagesLocale + +static __inline void +_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache, + _MessagesLocale * __restrict data) +{ + _DIAGASSERT(cache != NULL); + _DIAGASSERT(data != NULL); + + cache->items[(size_t)YESSTR ] = data->yesstr; + cache->items[(size_t)YESEXPR] = data->yesexpr; + cache->items[(size_t)NOSTR ] = data->nostr; + cache->items[(size_t)NOEXPR ] = data->noexpr; +} + +static __inline void +_PREFIX(fixup)(_MessagesLocale *data) +{ + _DIAGASSERT(data != NULL); + + _CurrentMessagesLocale = data; +} + +/* + * macro required by nb_lc_template.h + */ +#define _CATEGORY_ID LC_MESSAGES +#define _CATEGORY_NAME "LC_MESSAGES" +#define _CATEGORY_DEFAULT _DefaultMessagesLocale + +#endif /*_NB_LC_MESSAGES_MISC_H_*/ diff --git a/lib/libc/locale/nb_lc_monetary_misc.h b/lib/libc/locale/nb_lc_monetary_misc.h new file mode 100644 index 00000000000..9c0a22b130a --- /dev/null +++ b/lib/libc/locale/nb_lc_monetary_misc.h @@ -0,0 +1,85 @@ +/* $NetBSD: nb_lc_monetary_misc.h,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _NB_LC_MONETARY_MISC_H_ +#define _NB_LC_MONETARY_MISC_H_ + +/* + * macro required by nb_lc_template(_decl).h + */ +#define _CATEGORY_TYPE _MonetaryLocale + +static __inline void +_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache, + _MonetaryLocale * __restrict data) +{ + _DIAGASSERT(cache != NULL); + _DIAGASSERT(data != NULL); + + cache->ldata.int_curr_symbol = __UNCONST(data->int_curr_symbol); + cache->ldata.currency_symbol = __UNCONST(data->currency_symbol); + cache->ldata.mon_decimal_point = __UNCONST(data->mon_decimal_point); + cache->ldata.mon_thousands_sep = __UNCONST(data->mon_thousands_sep); + cache->ldata.mon_grouping = __UNCONST(data->mon_grouping); + cache->ldata.positive_sign = __UNCONST(data->positive_sign); + cache->ldata.negative_sign = __UNCONST(data->negative_sign); + + cache->ldata.int_frac_digits = data->int_frac_digits; + cache->ldata.frac_digits = data->frac_digits; + cache->ldata.p_cs_precedes = data->p_cs_precedes; + cache->ldata.p_sep_by_space = data->p_sep_by_space; + cache->ldata.n_cs_precedes = data->n_cs_precedes; + cache->ldata.n_sep_by_space = data->n_sep_by_space; + cache->ldata.p_sign_posn = data->p_sign_posn; + cache->ldata.n_sign_posn = data->n_sign_posn; + cache->ldata.int_p_cs_precedes = data->int_p_cs_precedes; + cache->ldata.int_n_cs_precedes = data->int_n_cs_precedes; + cache->ldata.int_p_sep_by_space = data-> int_p_sep_by_space; + cache->ldata.int_n_sep_by_space = data->int_n_sep_by_space; + cache->ldata.int_p_sign_posn = data->int_p_sign_posn; + cache->ldata.int_n_sign_posn = data->int_n_sign_posn; + + cache->items[(size_t)CRNCYSTR] = NULL; /* NOT IMPLEMENTED YET */ +} + +static __inline void +_PREFIX(fixup)(_MonetaryLocale *data) +{ + _DIAGASSERT(data != NULL); + + _CurrentMonetaryLocale = data; +} + +/* + * macro required by nb_lc_template.h + */ +#define _CATEGORY_ID LC_MONETARY +#define _CATEGORY_NAME "LC_MONETARY" +#define _CATEGORY_DEFAULT _DefaultMonetaryLocale + +#endif /*_RUNE_LC_MONETARY_MISC_H_*/ diff --git a/lib/libc/locale/nb_lc_numeric_misc.h b/lib/libc/locale/nb_lc_numeric_misc.h new file mode 100644 index 00000000000..d3f02658dac --- /dev/null +++ b/lib/libc/locale/nb_lc_numeric_misc.h @@ -0,0 +1,67 @@ +/* $NetBSD: nb_lc_numeric_misc.h,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _NB_LC_NUMERIC_MISC_H_ +#define _NB_LC_NUMERIC_MISC_H_ + +/* + * macro required by nb_lc_template(_decl).h + */ +#define _CATEGORY_TYPE _NumericLocale + +static __inline void +_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache, + _NumericLocale * __restrict data) +{ + _DIAGASSERT(cache != NULL); + _DIAGASSERT(data != NULL); + + cache->ldata.decimal_point = __UNCONST(data->decimal_point); + cache->ldata.thousands_sep = __UNCONST(data->thousands_sep); + cache->ldata.grouping = __UNCONST(data->grouping); + + cache->items[(size_t)RADIXCHAR] = data->decimal_point; + cache->items[(size_t)THOUSEP ] = data->thousands_sep; +} + +static __inline void +_PREFIX(fixup)(_NumericLocale *data) +{ + _DIAGASSERT(data != NULL); + + _CurrentNumericLocale = data; +} + +/* + * macro required by nb_lc_template.h + */ +#define _CATEGORY_ID LC_NUMERIC +#define _CATEGORY_NAME "LC_NUMERIC" +#define _CATEGORY_DEFAULT _DefaultNumericLocale + +#endif /*_NB_LC_NUMERIC_MISC_H_*/ diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/nb_lc_template.h index 852781b04ba..ba3df6f9a3b 100644 --- a/lib/libc/locale/setrunelocale.c +++ b/lib/libc/locale/nb_lc_template.h @@ -1,7 +1,7 @@ -/* $NetBSD: setrunelocale.c,v 1.18 2008/04/28 20:23:00 martin Exp $ */ +/* $NetBSD: nb_lc_template.h,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ /*- - * Copyright (c)1999 Citrus Project, + * Copyright (c)1999, 2008 Citrus Project, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -87,180 +87,162 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: setrunelocale.c,v 1.18 2008/04/28 20:23:00 martin Exp $"); -#endif /* LIBC_SCCS and not lint */ +#ifndef _NB_LC_TEMPLATE_H_ +#define _NB_LC_TEMPLATE_H_ -#include "namespace.h" +#define _nb_part_t _PREFIX(part_t) +#define _nb_part_cache _PREFIX(part_cache) +#define _nb_default_c _PREFIX(default_c) +#define _nb_default_posix _PREFIX(default_posix) +#define _nb_mutex _PREFIX(mutex) -#include "rune.h" -#include <assert.h> -#include <ctype.h> -#include <errno.h> -#include <limits.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <stddef.h> -#include <unistd.h> -#include <locale.h> -#include <citrus/citrus_module.h> -#include <citrus/citrus_ctype.h> -#include "rune_local.h" -#include "multibyte.h" +typedef struct _nb_part_t { + char name[_LOCALENAME_LEN_MAX]; + _CATEGORY_TYPE *impl; + SIMPLEQ_ENTRY(_nb_part_t) entry; +} _nb_part_t; -struct localetable { - char path[PATH_MAX]; - _RuneLocale *runelocale; - struct localetable *next; -}; -static struct localetable *localetable_head; - -_RuneLocale * -_findrunelocale(path) - char *path; -{ - struct localetable *lt; +static SIMPLEQ_HEAD(, _nb_part_t) _nb_part_cache = + SIMPLEQ_HEAD_INITIALIZER(_nb_part_cache); - _DIAGASSERT(path != NULL); +static const _nb_part_t _nb_default_c = { + _C_LOCALE, + __UNCONST(&_CATEGORY_DEFAULT), + { NULL }, +}; - /* ones which we have seen already */ - for (lt = localetable_head; lt; lt = lt->next) - if (strcmp(path, lt->path) == 0) - return lt->runelocale; +static const _nb_part_t _nb_default_posix = { + _POSIX_LOCALE, + __UNCONST(&_CATEGORY_DEFAULT), + { NULL }, +}; - return NULL; -} +#ifdef _REENTRANT +static mutex_t _nb_mutex = MUTEX_INITIALIZER; +#endif -int -_newrunelocale(path) - char *path; +static int +_PREFIX(load_sub)(const char * __restrict name, const char * __restrict real, + _nb_part_t ** __restrict part, int force) { - struct localetable *lt; - FILE *fp; - _RuneLocale *rl; + _nb_part_t *p, *q; int ret; - _DIAGASSERT(path != NULL); - - if (strlen(path) + 1 > sizeof(lt->path)) - return EINVAL; - - rl = _findrunelocale(path); - if (rl) - return 0; - - if ((fp = fopen(path, "r")) == NULL) - return ENOENT; - - if ((rl = _Read_RuneMagi(fp)) != NULL) - goto found; - /* necessary for backward compatibility */ - if ((rl = _Read_CTypeAsRune(fp)) != NULL) - goto found; - - fclose(fp); - return EFTYPE; - -found: - fclose(fp); - - rl->rl_citrus_ctype = NULL; - ret = _citrus_ctype_open(&rl->rl_citrus_ctype, rl->rl_encoding, - rl->rl_variable, rl->rl_variable_len, - _PRIVSIZE); - if (!ret) - ret = __runetable_to_netbsd_ctype(rl); - if (ret) { - _NukeRune(rl); - return ret; + _DIAGASSERT(name != NULL); + _DIAGASSERT(part != NULL); + + if (!strcmp(_C_LOCALE, name)) { + p = __UNCONST(&_nb_default_c); + } else if (!strcmp(_POSIX_LOCALE, name)) { + p = __UNCONST(&_nb_default_posix); + } else { + SIMPLEQ_FOREACH(p, &_nb_part_cache, entry) { + if (!strcmp((const char *)&p->name[0], name)) + goto found; + } + p = malloc(sizeof(*p)); + if (p == NULL) + return ENOMEM; + if (force) { + p->impl = __UNCONST(&_CATEGORY_DEFAULT); + } else { + _DIAGASSERT(_PathLocale != NULL); + ret = _PREFIX(create_impl)((const char *)_PathLocale, + name, &p->impl); + if (ret) { + free(p); + return ret; + } + } + strlcpy(&p->name[0], name, sizeof(p->name)); + SIMPLEQ_INSERT_TAIL(&_nb_part_cache, p, entry); } - if (__MB_LEN_MAX_RUNTIME < - _citrus_ctype_get_mb_cur_max(rl->rl_citrus_ctype)) { - _NukeRune(rl); - return EINVAL; - } - - /* register it */ - lt = malloc(sizeof(struct localetable)); - if (lt == NULL) { - _NukeRune(rl); - return ENOMEM; +found: + if (real != NULL) { + q = malloc(sizeof(*q)); + if (q == NULL) + return ENOMEM; + strlcpy(&q->name[0], real, sizeof(p->name)); + q->impl = p->impl; + SIMPLEQ_INSERT_TAIL(&_nb_part_cache, q, entry); + p = q; } - strlcpy(lt->path, path, sizeof(lt->path)); - lt->runelocale = rl; - lt->next = localetable_head; - localetable_head = lt; - + *part = p; return 0; } -#if 0 -static int -delrunelocale(path) - char *path; +static __inline int +_PREFIX(load)(const char * __restrict name, + _nb_part_t ** __restrict part) { - struct localetable *lt, *prev; - _RuneLocale *rl; - - _DIAGASSERT(path != NULL); - - prev = NULL; - for (lt = localetable_head; lt; prev = lt, lt = prev->next) - if (strcmp(path, lt->path) == 0) - break; - if (!lt) - return ENOENT; - - /* remove runelocale registeration */ - if (prev) - prev->next = lt->next; - else - localetable_head = lt->next; - lt->next = NULL; - free(lt); - - /* cleanup everything */ - rl = lt->runelocale; - dlclose(rl->rl_rune_RuneModule); - rl->rl_rune_RuneModule = NULL; - _NukeRune(rl); - - return 0; + int ret, force; + char path[PATH_MAX + 1], loccat[PATH_MAX + 1], buf[PATH_MAX + 1]; + const char *aliaspath, *alias; + +#define _LOAD_SUB_ALIAS(key) \ +do { \ + alias = __unaliasname(aliaspath, key, &buf[0], sizeof(buf)); \ + if (alias != NULL) { \ + ret = (force = !__isforcemapping(alias)) \ + ? _PREFIX(load_sub)(name, NULL, part, force) \ + : _PREFIX(load_sub)(alias, name, part, force); \ + _DIAGASSERT(!ret || !force); \ + goto done; \ + } \ +} while (/*CONSTCOND*/0) + + /* (1) non-aliased file */ + mutex_lock(&_nb_mutex); + ret = _PREFIX(load_sub)(name, NULL, part, 0); + if (ret != ENOENT) + goto done; + + /* (2) lookup locname/catname type alias */ + _DIAGASSERT(_PathLocale != NULL); + snprintf(&path[0], sizeof(path), + "%s/" _LOCALE_ALIAS_NAME, _PathLocale); + aliaspath = (const char *)&path[0]; + snprintf(&loccat[0], sizeof(loccat), + "%s/" _CATEGORY_NAME, name); + _LOAD_SUB_ALIAS((const char *)&loccat[0]); + + /* (3) lookup locname type alias */ + _LOAD_SUB_ALIAS(name); + +done: + mutex_unlock(&_nb_mutex); + return ret; } -#endif -int -_xpg4_setrunelocale(encoding) - const char *encoding; +static const char * +_PREFIX(setlocale)(const char * __restrict name, + struct _locale_impl_t * __restrict locale) { - char path[PATH_MAX]; - _RuneLocale *rl; - int error; - - _DIAGASSERT(encoding != NULL); - - if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) { - rl = &_DefaultRuneLocale; - goto found; + _nb_part_t *part; + + /* name may be NULL */ + _DIAGASSERT(locale != NULL); + + if (name != NULL) { + if (*name == '\0') + name = _get_locale_env(_CATEGORY_NAME); + _DIAGASSERT(name != NULL); + _DIAGASSERT(locale->part_name[(size_t)_CATEGORY_ID] != NULL); + if (strcmp(name, locale->part_name[(size_t)_CATEGORY_ID])) { + if (_PREFIX(load)(name, &part)) + return NULL; + locale->part_name[(size_t)_CATEGORY_ID] + = &part->name[0]; + locale->part_impl[(size_t)_CATEGORY_ID] + = part->impl; + _PREFIX(build_cache)(&locale->cache, part->impl); + if (locale == &_global_locale) + _PREFIX(fixup)(part->impl); + } } + return locale->part_name[(size_t)_CATEGORY_ID]; +} - snprintf(path, sizeof(path), "%s/%s/LC_CTYPE", _PathLocale, encoding); - - error = _newrunelocale(path); - if (error) - return error; - rl = _findrunelocale(path); - if (!rl) - return ENOENT; - -found: - _ctype_ = rl->rl_ctype_tab; - _tolower_tab_ = rl->rl_tolower_tab; - _toupper_tab_ = rl->rl_toupper_tab; - _CurrentRuneLocale = rl; - __mb_cur_max = _citrus_ctype_get_mb_cur_max(rl->rl_citrus_ctype); +#include "generic_lc_template.h" - return 0; -} +#endif /*_NB_LC_TEMPLATE_H_*/ diff --git a/lib/libc/locale/nb_lc_template_decl.h b/lib/libc/locale/nb_lc_template_decl.h new file mode 100644 index 00000000000..5d2c3d0cf4f --- /dev/null +++ b/lib/libc/locale/nb_lc_template_decl.h @@ -0,0 +1,45 @@ +/* $NetBSD: nb_lc_template_decl.h,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _NB_LC_TEMPLATE_DECL_H_ +#define _NB_LC_TEMPLATE_DECL_H_ + +#include "generic_lc_template_decl.h" + +static __inline int +_PREFIX(create_impl)(const char * __restrict, + const char * __restrict, _CATEGORY_TYPE ** __restrict); + +static __inline void +_PREFIX(build_cache)(struct _locale_cache_t * __restrict, + _CATEGORY_TYPE * __restrict); + +static __inline void +_PREFIX(fixup)(_CATEGORY_TYPE *); + +#endif /*_NB_LC_TEMPLATE_DECL_H_*/ diff --git a/lib/libc/locale/nb_lc_time_misc.h b/lib/libc/locale/nb_lc_time_misc.h new file mode 100644 index 00000000000..8dc32d6eed4 --- /dev/null +++ b/lib/libc/locale/nb_lc_time_misc.h @@ -0,0 +1,91 @@ +/* $NetBSD: nb_lc_time_misc.h,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _NB_LC_TIME_MISC_H_ +#define _NB_LC_TIME_MISC_H_ + +/* + * macro required by nb_lc_template(_decl).h + */ +#define _CATEGORY_TYPE _TimeLocale + +#define ABDAY_IDX(idx) ((size_t)idx - (size_t)ABDAY_1) +#define DAY_IDX(idx) ((size_t)idx - (size_t)DAY_1) +#define ABMON_IDX(idx) ((size_t)idx - (size_t)ABMON_1) +#define MON_IDX(idx) ((size_t)idx - (size_t)MON_1) +#define AM_PM_IDX(idx) ((size_t)idx - (size_t)AM_STR) + +static __inline void +/*ARGSUSED*/ +_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache, + _TimeLocale * __restrict data) +{ + size_t i; + + _DIAGASSERT(cache != NULL); + _DIAGASSERT(data != NULL); + + for (i = (size_t)ABDAY_1; i <= ABDAY_7; ++i) + cache->items[i] = data->abday[ABDAY_IDX(i)]; + for (i = (size_t)DAY_1; i <= DAY_7; ++i) + cache->items[i] = data->day[DAY_IDX(i)]; + for (i = (size_t)ABMON_1; i <= ABMON_12; ++i) + cache->items[i] = data->abmon[ABMON_IDX(i)]; + for (i = (size_t)MON_1; i <= MON_12; ++i) + cache->items[i] = data->mon[MON_IDX(i)]; + for (i = (size_t)AM_STR; i <= PM_STR; ++i) + cache->items[i] = data->am_pm[AM_PM_IDX(i)]; + cache->items[(size_t)D_T_FMT ] = data->d_t_fmt; + cache->items[(size_t)D_FMT ] = data->d_fmt; + cache->items[(size_t)T_FMT ] = data->t_fmt; + cache->items[(size_t)T_FMT_AMPM ] = data->t_fmt_ampm; + + /* NOT IMPLEMENTED YET */ + cache->items[(size_t)ERA ] = NULL; + cache->items[(size_t)ERA_D_FMT ] = NULL; + cache->items[(size_t)ERA_D_T_FMT] = NULL; + cache->items[(size_t)ERA_T_FMT ] = NULL; + cache->items[(size_t)ALT_DIGITS ] = NULL; +} + +static __inline void +_PREFIX(fixup)(_TimeLocale *data) +{ + _DIAGASSERT(data != NULL); + + _CurrentTimeLocale = data; +} + +/* + * macro required by nb_lc_template.h + */ +#define _CATEGORY_ID LC_TIME +#define _CATEGORY_NAME "LC_TIME" +#define _CATEGORY_DEFAULT _DefaultTimeLocale + +#endif /*_NB_LC_TIME_MISC_H_*/ diff --git a/lib/libc/locale/nl_langinfo.c b/lib/libc/locale/nl_langinfo.c index 97312bbaf94..4ee08338bd8 100644 --- a/lib/libc/locale/nl_langinfo.c +++ b/lib/libc/locale/nl_langinfo.c @@ -1,126 +1,56 @@ -/* $NetBSD: nl_langinfo.c,v 1.11 2005/11/29 03:11:59 christos Exp $ */ +/* $NetBSD: nl_langinfo.c,v 1.12 2009/01/02 00:20:20 tnozaki Exp $ */ -/* - * Written by J.T. Conklin <jtc@NetBSD.org>. - * Public domain. +/*- + * Copyright (c)2008 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: nl_langinfo.c,v 1.11 2005/11/29 03:11:59 christos Exp $"); +__RCSID("$NetBSD: nl_langinfo.c,v 1.12 2009/01/02 00:20:20 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ -#include <sys/localedef.h> -#include <locale.h> -#include <nl_types.h> +#include <sys/types.h> #include <langinfo.h> -#include "rune.h" -#include "runetype.h" +#define __SETLOCALE_SOURCE__ +#include <locale.h> +#include <stdlib.h> + +#include "setlocale_local.h" char * -nl_langinfo(item) - nl_item item; +nl_langinfo(nl_item item) { const char *s; + struct _locale_impl_t *impl; - switch (item) { - case D_T_FMT: - s = _CurrentTimeLocale->d_t_fmt; - break; - case D_FMT: - s = _CurrentTimeLocale->d_fmt; - break; - case T_FMT: - s = _CurrentTimeLocale->t_fmt; - break; - case T_FMT_AMPM: - s = _CurrentTimeLocale->t_fmt_ampm; - break; - case AM_STR: - case PM_STR: - s = _CurrentTimeLocale->am_pm[(size_t)(item - AM_STR)]; - break; - case DAY_1: - case DAY_2: - case DAY_3: - case DAY_4: - case DAY_5: - case DAY_6: - case DAY_7: - s = _CurrentTimeLocale->day[(size_t)(item - DAY_1)]; - break; - case ABDAY_1: - case ABDAY_2: - case ABDAY_3: - case ABDAY_4: - case ABDAY_5: - case ABDAY_6: - case ABDAY_7: - s = _CurrentTimeLocale->abday[(size_t)(item - ABDAY_1)]; - break; - case MON_1: - case MON_2: - case MON_3: - case MON_4: - case MON_5: - case MON_6: - case MON_7: - case MON_8: - case MON_9: - case MON_10: - case MON_11: - case MON_12: - s = _CurrentTimeLocale->mon[(size_t)(item - MON_1)]; - break; - case ABMON_1: - case ABMON_2: - case ABMON_3: - case ABMON_4: - case ABMON_5: - case ABMON_6: - case ABMON_7: - case ABMON_8: - case ABMON_9: - case ABMON_10: - case ABMON_11: - case ABMON_12: - s = _CurrentTimeLocale->abmon[(size_t)(item - ABMON_1)]; - break; - case RADIXCHAR: - s = _CurrentNumericLocale->decimal_point; - break; - case THOUSEP: - s = _CurrentNumericLocale->thousands_sep; - break; - case YESSTR: - s = _CurrentMessagesLocale->yesstr; - break; - case YESEXPR: - s = _CurrentMessagesLocale->yesexpr; - break; - case NOSTR: - s = _CurrentMessagesLocale->nostr; - break; - case NOEXPR: - s = _CurrentMessagesLocale->noexpr; - break; - case CRNCYSTR: /* XXX */ - s = ""; - break; - case CODESET: -#ifdef WITH_RUNE - s = _CurrentRuneLocale->rl_codeset; -#else s = NULL; -#endif - if (!s) - s = ""; - break; - default: - s = ""; - break; + if (item >= D_T_FMT && item <= ALT_DIGITS) { + impl = *_current_locale(); + s = impl->cache.items[(size_t)item]; } - - /* The return value should be really const, but the interface says OW */ + if (s == NULL) + s = ""; return __UNCONST(s); } diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c index 3181ba40ef8..4897d700b87 100644 --- a/lib/libc/locale/rune.c +++ b/lib/libc/locale/rune.c @@ -1,4 +1,4 @@ -/* $NetBSD: rune.c,v 1.30 2007/09/29 07:55:45 tnozaki Exp $ */ +/* $NetBSD: rune.c,v 1.31 2009/01/02 00:20:20 tnozaki Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -63,7 +63,7 @@ #if 0 static char sccsid[] = "@(#)rune.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: rune.c,v 1.30 2007/09/29 07:55:45 tnozaki Exp $"); +__RCSID("$NetBSD: rune.c,v 1.31 2009/01/02 00:20:20 tnozaki Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -76,8 +76,11 @@ __RCSID("$NetBSD: rune.c,v 1.30 2007/09/29 07:55:45 tnozaki Exp $"); #include <wchar.h> #include <sys/types.h> #include <sys/stat.h> -#include <citrus/citrus_module.h> -#include <citrus/citrus_ctype.h> + +#include "citrus_module.h" +#include "citrus_ctype.h" + +#include "bsdctype.h" #include "rune.h" #include "rune_local.h" diff --git a/lib/libc/locale/rune.h b/lib/libc/locale/rune.h index e9f6124c60a..fd7a186048e 100644 --- a/lib/libc/locale/rune.h +++ b/lib/libc/locale/rune.h @@ -1,4 +1,4 @@ -/* $NetBSD: rune.h,v 1.12 2007/09/03 20:31:56 drochner Exp $ */ +/* $NetBSD: rune.h,v 1.13 2009/01/02 00:20:20 tnozaki Exp $ */ /*- * Copyright (c) 1993 @@ -89,10 +89,7 @@ extern size_t __mb_len_max_runtime; #define __MB_LEN_MAX_RUNTIME __mb_len_max_runtime -extern _RuneLocale _DefaultRuneLocale; -extern _RuneLocale *_CurrentRuneLocale; -extern const char *_PathLocale; - -#define _LOCALE_ALIAS_NAME "locale.alias" +extern const _RuneLocale _DefaultRuneLocale; +extern const _RuneLocale *_CurrentRuneLocale; #endif /*! _RUNE_H_ */ diff --git a/lib/libc/locale/rune_local.h b/lib/libc/locale/rune_local.h index aa217e65100..d9e1d449288 100644 --- a/lib/libc/locale/rune_local.h +++ b/lib/libc/locale/rune_local.h @@ -1,4 +1,4 @@ -/* $NetBSD: rune_local.h,v 1.10 2008/04/01 19:19:33 drochner Exp $ */ +/* $NetBSD: rune_local.h,v 1.11 2009/01/02 00:20:20 tnozaki Exp $ */ /*- * Copyright (c) 2000 Citrus Project, @@ -30,19 +30,11 @@ #define _RUNE_LOCAL_H_ /* rune.c */ -extern _RuneLocale *_Read_RuneMagi __P((FILE *fp)); -extern _RuneLocale *_Read_CTypeAsRune __P((FILE *fp)); -extern void _NukeRune __P((_RuneLocale *)); - -/* setrunelocale.c */ -extern int _xpg4_setrunelocale __P((const char *)); -extern _RuneLocale *_findrunelocale __P((char *)); -extern int _newrunelocale __P((char *)); +extern _RuneLocale *_Read_RuneMagi(FILE *fp); +extern _RuneLocale *_Read_CTypeAsRune(FILE *fp); +extern void _NukeRune(_RuneLocale *); /* runeglue.c */ -extern int __runetable_to_netbsd_ctype __P((_RuneLocale *)); - -/* ___runetype_mb.c */ -extern _RuneType ___runetype_mb __P((wint_t)); +extern int __runetable_to_netbsd_ctype(_RuneLocale *); #endif diff --git a/lib/libc/locale/runeglue.c b/lib/libc/locale/runeglue.c index e651e1b043b..c1705fa5d08 100644 --- a/lib/libc/locale/runeglue.c +++ b/lib/libc/locale/runeglue.c @@ -1,4 +1,4 @@ -/* $NetBSD: runeglue.c,v 1.13 2008/11/06 19:59:42 christos Exp $ */ +/* $NetBSD: runeglue.c,v 1.14 2009/01/02 00:20:20 tnozaki Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: runeglue.c,v 1.13 2008/11/06 19:59:42 christos Exp $"); +__RCSID("$NetBSD: runeglue.c,v 1.14 2009/01/02 00:20:20 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #define _CTYPE_PRIVATE @@ -47,8 +47,8 @@ __RCSID("$NetBSD: runeglue.c,v 1.13 2008/11/06 19:59:42 christos Exp $"); #include <stdlib.h> #include <string.h> #include <wchar.h> -#include "citrus/citrus_module.h" -#include "citrus/citrus_ctype.h" +#include "citrus_module.h" +#include "citrus_ctype.h" #include "rune.h" #include "rune_local.h" diff --git a/lib/libc/locale/runetable.c b/lib/libc/locale/runetable.c index bc768a6d4e8..73f29174817 100644 --- a/lib/libc/locale/runetable.c +++ b/lib/libc/locale/runetable.c @@ -1,4 +1,4 @@ -/* $NetBSD: runetable.c,v 1.17 2008/08/12 21:25:31 tnozaki Exp $ */ +/* $NetBSD: runetable.c,v 1.18 2009/01/02 00:20:20 tnozaki Exp $ */ /*- * Copyright (c) 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 6/27/93"; #else -__RCSID("$NetBSD: runetable.c,v 1.17 2008/08/12 21:25:31 tnozaki Exp $"); +__RCSID("$NetBSD: runetable.c,v 1.18 2009/01/02 00:20:20 tnozaki Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,12 +49,12 @@ __RCSID("$NetBSD: runetable.c,v 1.17 2008/08/12 21:25:31 tnozaki Exp $"); #include <locale.h> #include <assert.h> #include <wchar.h> -#include <citrus/citrus_module.h> -#include <citrus/citrus_ctype.h> +#include "citrus_module.h" +#include "citrus_ctype.h" #include "rune.h" #include "rune_local.h" -_RuneLocale _DefaultRuneLocale = { +const _RuneLocale _DefaultRuneLocale = { _RUNE_MAGIC_1, "NONE", _DEFAULT_INVALID_RUNE, @@ -349,6 +349,4 @@ _RuneLocale _DefaultRuneLocale = { _C_toupper_ }; -_RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale; - -const char *_PathLocale; +const _RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale; diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index 29400655a48..b248cf3c513 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -1,11 +1,8 @@ -/* $NetBSD: setlocale.c,v 1.54 2008/06/12 20:33:23 ginsbach Exp $ */ +/* $NetBSD: setlocale.c,v 1.55 2009/01/02 00:20:20 tnozaki Exp $ */ -/* - * Copyright (c) 1991, 1993, 2008 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. +/*- + * Copyright (c)2008 Citrus Project, + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,14 +12,11 @@ * 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * 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 REGENTS OR CONTRIBUTORS BE LIABLE + * 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) @@ -34,427 +28,84 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93"; -#else -__RCSID("$NetBSD: setlocale.c,v 1.54 2008/06/12 20:33:23 ginsbach Exp $"); -#endif +__RCSID("$NetBSD: setlocale.c,v 1.55 2009/01/02 00:20:20 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ -#define _CTYPE_PRIVATE - -#include "namespace.h" -#include <sys/localedef.h> +#include <sys/cdefs.h> #include <sys/types.h> -#include <sys/stat.h> -#include <assert.h> -#include <limits.h> -#include <ctype.h> +#include <langinfo.h> #define __SETLOCALE_SOURCE__ #include <locale.h> #include <paths.h> -#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> -#ifdef WITH_RUNE -#include "rune.h" -#include "rune_local.h" -#else -#include "ctypeio.h" -#endif -#include "lcmessages.h" -#include "lcmonetary.h" -#include "lcnumeric.h" -#include "lctime.h" -#ifdef CITRUS -#include <citrus/citrus_namespace.h> -#include <citrus/citrus_region.h> -#include <citrus/citrus_lookup.h> -#include <citrus/citrus_bcs.h> -#else -#include <locale/aliasname_local.h> -#define _lookup_alias(p, a, b, s, c) __unaliasname((p), (a), (b), (s)) -#define _bcs_strcasecmp(a, b) strcasecmp((a), (b)) -#endif +#include "setlocale_local.h" -#define _LOCALE_SYM_FORCE "/force" +const char *_PathLocale = NULL; -/* - * Category names for getenv() - */ -static const char *const categories[_LC_LAST] = { - "LC_ALL", - "LC_COLLATE", - "LC_CTYPE", - "LC_MONETARY", - "LC_NUMERIC", - "LC_TIME", - "LC_MESSAGES" -}; +__link_set_decl(all_categories, _locale_category_t); -/* - * Current locales for each category - */ -static char current_categories[_LC_LAST][32] = { - "C", - "C", - "C", - "C", - "C", - "C", - "C" +#ifndef __lint__ +static +#endif +const _locale_category_t dummy = { + .category = _LC_LAST, /* XXX */ + .setlocale = NULL, }; -/* - * The locales we are going to try and load - */ -static char new_categories[_LC_LAST][32]; - -static char current_locale_string[_LC_LAST * 33]; - -static char *currentlocale __P((void)); -static void revert_to_default __P((int)); -static int force_locale_enable __P((int)); -static int load_locale_sub __P((int, const char *, int)); -static char *loadlocale __P((int)); -static const char *__get_locale_env __P((int)); +__link_set_add_data(all_categories, dummy); -char * -__setlocale(category, locale) - int category; - const char *locale; +_locale_category_t * +_find_category(int category) { - int i, loadlocale_success; - size_t len; - const char *env, *r; - - if (issetugid() || - ((!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE"))) || - !*_PathLocale)) - _PathLocale = _PATH_LOCALE; - - if (category < 0 || category >= _LC_LAST) - return (NULL); - - if (!locale) - return (category ? - current_categories[category] : currentlocale()); - - /* - * Default to the current locale for everything. - */ - for (i = 1; i < _LC_LAST; ++i) - (void)strlcpy(new_categories[i], current_categories[i], - sizeof(new_categories[i])); - - /* - * Now go fill up new_categories from the locale argument - */ - if (!*locale) { - if (category == LC_ALL) { - for (i = 1; i < _LC_LAST; ++i) { - env = __get_locale_env(i); - (void)strlcpy(new_categories[i], env, - sizeof(new_categories[i])); - } - } - else { - env = __get_locale_env(category); - (void)strlcpy(new_categories[category], env, - sizeof(new_categories[category])); - } - } else if (category) { - (void)strlcpy(new_categories[category], locale, - sizeof(new_categories[category])); - } else { - if ((r = strchr(locale, '/')) == 0) { - for (i = 1; i < _LC_LAST; ++i) { - (void)strlcpy(new_categories[i], locale, - sizeof(new_categories[i])); - } - } else { - for (i = 1;;) { - _DIAGASSERT(*r == '/' || *r == 0); - _DIAGASSERT(*locale != 0); - if (*locale == '/') - return (NULL); /* invalid format. */ - len = r - locale; - if (len + 1 > sizeof(new_categories[i])) - return (NULL); /* too long */ - (void)memcpy(new_categories[i], locale, len); - new_categories[i][len] = '\0'; - if (*r == 0) - break; - _DIAGASSERT(*r == '/'); - if (*(locale = ++r) == 0) - /* slash followed by NUL */ - return (NULL); - /* skip until NUL or '/' */ - while (*r && *r != '/') - r++; - if (++i == _LC_LAST) - return (NULL); /* too many slashes. */ - } - if (i + 1 != _LC_LAST) - return (NULL); /* too few slashes. */ - } - } - - if (category) - return (loadlocale(category)); + _locale_category_t * const *p; - loadlocale_success = 0; - for (i = 1; i < _LC_LAST; ++i) { - if (loadlocale(i) != NULL) - loadlocale_success = 1; + __link_set_foreach(p, all_categories) { + if ((*p)->category == category) + return *p; } - - /* - * If all categories failed, return NULL; we don't need to back - * changes off, since none happened. - */ - if (!loadlocale_success) - return NULL; - - return (currentlocale()); -} - -static char * -currentlocale() -{ - int i; - - (void)strlcpy(current_locale_string, current_categories[1], - sizeof(current_locale_string)); - - for (i = 2; i < _LC_LAST; ++i) - if (strcmp(current_categories[1], current_categories[i])) { - (void)snprintf(current_locale_string, - sizeof(current_locale_string), "%s/%s/%s/%s/%s/%s", - current_categories[1], current_categories[2], - current_categories[3], current_categories[4], - current_categories[5], current_categories[6]); - break; - } - return (current_locale_string); + return NULL; } -static void -revert_to_default(category) - int category; +const char * +_get_locale_env(const char *category) { - switch (category) { - case LC_CTYPE: -#ifdef WITH_RUNE - (void)_xpg4_setrunelocale("C"); -#else - if (_ctype_ != _C_ctype_) { - /* LINTED const castaway */ - free((void *)_ctype_); - _ctype_ = _C_ctype_; - } - if (_toupper_tab_ != _C_toupper_) { - /* LINTED const castaway */ - free((void *)_toupper_tab_); - _toupper_tab_ = _C_toupper_; - } - if (_tolower_tab_ != _C_tolower_) { - /* LINTED const castaway */ - free((void *)_tolower_tab_); - _tolower_tab_ = _C_tolower_; - } -#endif - break; - case LC_TIME: - if (_CurrentTimeLocale != &_DefaultTimeLocale) { - free(__UNCONST(_CurrentTimeLocale)); - _CurrentTimeLocale = &_DefaultTimeLocale; - } - break; - case LC_MESSAGES: - if (_CurrentMessagesLocale != &_DefaultMessagesLocale) { - free(__UNCONST(_CurrentMessagesLocale)); - _CurrentMessagesLocale = &_DefaultMessagesLocale; + const char *name; + + /* 1. check LC_ALL */ + name = (const char *)getenv("LC_ALL"); + if (name == NULL || *name == '\0') { + /* 2. check LC_* */ + name = (const char *)getenv(category); + if (name == NULL || *name == '\0') { + /* 3. check LANG */ + name = getenv("LANG"); } - break; - case LC_COLLATE: - break; - case LC_MONETARY: - if (_CurrentMonetaryLocale != &_DefaultMonetaryLocale) { - free(__UNCONST(_CurrentMonetaryLocale)); - _CurrentMonetaryLocale = &_DefaultMonetaryLocale; - } - break; - case LC_NUMERIC: - if (_CurrentNumericLocale != &_DefaultNumericLocale) { - free(__UNCONST(_CurrentNumericLocale)); - _CurrentNumericLocale = &_DefaultNumericLocale; - } - break; } + if (name == NULL || *name == '\0' || strchr(name, '/')) + /* 4. if none is set, fall to "C" */ + name = _C_LOCALE; + return name; } -static int -force_locale_enable(category) - int category; -{ - revert_to_default(category); - - return 0; -} - -static int -load_locale_sub(category, locname, isspecial) - int category; - const char *locname; - int isspecial; +char * +__setlocale(int category, const char *name) { - char name[PATH_MAX]; - int len; - - /* check for the default locales */ - if (!strcmp(new_categories[category], "C") || - !strcmp(new_categories[category], "POSIX")) { - revert_to_default(category); - return 0; - } - - /* check whether special symbol */ - if (isspecial && _bcs_strcasecmp(locname, _LOCALE_SYM_FORCE) == 0) - return force_locale_enable(category); - - /* sanity check */ - if (strchr(locname, '/') != NULL) - return -1; - - len = snprintf(name, sizeof(name), "%s/%s/%s", - _PathLocale, locname, categories[category]); - if (len < 0 || len >= sizeof(name)) - return -1; - - switch (category) { - case LC_CTYPE: -#ifdef WITH_RUNE - if (_xpg4_setrunelocale(__UNCONST(locname))) - return -1; -#else - if (!__loadctype(name)) - return -1; -#endif - break; - - case LC_MESSAGES: - len += snprintf(name + len, sizeof(name) - len, "/%s", - categories[category]); - if (len >= sizeof(name)) - return -1; - if (!__loadmessages(name)) -#ifdef notyet - return -1; -#else - /* - * XXX we don't have LC_MESSAGES support yet, - * but catopen may use the value of LC_MESSAGES category. - * so return successfully if locale directory is present. - */ - /* local */ - { - struct stat st; - - (void)snprintf(name, sizeof(name), "%s/%s", - _PathLocale, locname); - if (stat(name, &st) < 0) - return -1; - if (!S_ISDIR(st.st_mode)) - return -1; + _locale_category_t *l; + struct _locale_impl_t *impl; + + if (category >= LC_ALL && category < _LC_LAST) { + l = _find_category(category); + if (l != NULL) { + if (issetugid() || ((_PathLocale == NULL && + (_PathLocale = getenv("PATH_LOCALE")) == NULL) || + *_PathLocale == '\0')) + _PathLocale = _PATH_LOCALE; + impl = *_current_locale(); + return __UNCONST((*l->setlocale)(name, impl)); } -#endif - break; - - case LC_TIME: - if (!__loadtime(name)) - return -1; - break; - case LC_COLLATE: - return -1; - case LC_MONETARY: - if (!__loadmonetary(name)) - return -1; - break; - case LC_NUMERIC: - if (!__loadnumeric(name)) - return -1; - break; } - - return 0; -} - -static char * -loadlocale(category) - int category; -{ - char aliaspath[PATH_MAX], loccat[PATH_MAX], buf[PATH_MAX]; - const char *alias; - - _DIAGASSERT(0 < category && category < _LC_LAST); - - if (strcmp(new_categories[category], current_categories[category]) == 0) - return (current_categories[category]); - - /* (1) non-aliased file */ - if (!load_locale_sub(category, new_categories[category], 0)) - goto success; - - /* (2) lookup locname/catname type alias */ - (void)snprintf(aliaspath, sizeof(aliaspath), - "%s/" _LOCALE_ALIAS_NAME, _PathLocale); - (void)snprintf(loccat, sizeof(loccat), "%s/%s", - new_categories[category], categories[category]); - alias = _lookup_alias(aliaspath, loccat, buf, sizeof(buf), - _LOOKUP_CASE_SENSITIVE); - if (!load_locale_sub(category, alias, 1)) - goto success; - - /* (3) lookup locname type alias */ - alias = _lookup_alias(aliaspath, new_categories[category], - buf, sizeof(buf), _LOOKUP_CASE_SENSITIVE); - if (!load_locale_sub(category, alias, 1)) - goto success; - return NULL; - -success: - (void)strlcpy(current_categories[category], - new_categories[category], - sizeof(current_categories[category])); - return current_categories[category]; -} - -static const char * -__get_locale_env(category) - int category; -{ - const char *env; - - _DIAGASSERT(category != LC_ALL); - - /* 1. check LC_ALL. */ - env = getenv(categories[0]); - - /* 2. check LC_* */ - if (!env || !*env) - env = getenv(categories[category]); - - /* 3. check LANG */ - if (!env || !*env) - env = getenv("LANG"); - - /* 4. if none is set, fall to "C" */ - if (!env || !*env || strchr(env, '/')) - env = "C"; - - return env; } diff --git a/lib/libc/locale/setlocale_local.h b/lib/libc/locale/setlocale_local.h new file mode 100644 index 00000000000..d0a95790d8c --- /dev/null +++ b/lib/libc/locale/setlocale_local.h @@ -0,0 +1,74 @@ +/* $NetBSD: setlocale_local.h,v 1.1 2009/01/02 00:20:20 tnozaki Exp $ */ + +/*- + * Copyright (c)2008 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 _SETLOCALE_LOCAL_H_ +#define _SETLOCALE_LOCAL_H_ + +#define _LOCALENAME_LEN_MAX 33 + +#define _C_LOCALE "C" +#define _POSIX_LOCALE "POSIX" + +extern const char *_PathLocale; +#define _LOCALE_ALIAS_NAME "locale.alias" + +typedef void *_locale_part_t; + +struct _locale_cache_t { + const unsigned char *ctype_tab; + const short *tolower_tab; + const short *toupper_tab; + size_t mb_cur_max; + struct lconv ldata; + const char *items[ALT_DIGITS + 1]; +}; + +struct _locale_impl_t { + struct _locale_cache_t cache; + char query[_LOCALENAME_LEN_MAX * (_LC_LAST - 1)]; + const char *part_name[_LC_LAST]; + _locale_part_t part_impl[_LC_LAST]; +}; + +typedef const char *(*_locale_set_t)(const char * __restrict, + struct _locale_impl_t * __restrict); + +typedef struct { + const char* name; + int category; + _locale_set_t setlocale; +} _locale_category_t; + +__BEGIN_DECLS +_locale_category_t *_find_category(int); +const char *_get_locale_env(const char *); +struct _locale_impl_t _global_locale; +struct _locale_impl_t **_current_locale(void); +__END_DECLS + +#endif /*_SETLOCALE_LOCAL_H_*/ diff --git a/lib/libc/nls/Makefile.inc b/lib/libc/nls/Makefile.inc index c1fef07abaf..d6a7a3f6847 100644 --- a/lib/libc/nls/Makefile.inc +++ b/lib/libc/nls/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.8 1996/05/13 23:29:32 jtc Exp $ +# $NetBSD: Makefile.inc,v 1.9 2009/01/02 00:20:21 tnozaki Exp $ .PATH: ${.CURDIR}/nls @@ -7,3 +7,10 @@ MAN+= catclose.3 catgets.3 catopen.3 # indirect reference stubs, to be removed soon. SRCS+= _catclose.c _catgets.c _catopen.c + +.if ${CITRUS} == "yes" +CPPFLAGS.catopen.c+= -DHAVE_CITRUS -I${LIBCDIR}/citrus +.else +CPPFLAGS.catopen.c+= -UHAVE_CITRUS -I${LIBCDIR}/locale +.endif + diff --git a/lib/libc/nls/catopen.c b/lib/libc/nls/catopen.c index f7300867946..4f993f98552 100644 --- a/lib/libc/nls/catopen.c +++ b/lib/libc/nls/catopen.c @@ -1,4 +1,4 @@ -/* $NetBSD: catopen.c,v 1.25 2008/04/28 20:23:00 martin Exp $ */ +/* $NetBSD: catopen.c,v 1.26 2009/01/02 00:20:21 tnozaki Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: catopen.c,v 1.25 2008/04/28 20:23:00 martin Exp $"); +__RCSID("$NetBSD: catopen.c,v 1.26 2009/01/02 00:20:21 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #define _NLS_PRIVATE @@ -50,13 +50,14 @@ __RCSID("$NetBSD: catopen.c,v 1.25 2008/04/28 20:23:00 martin Exp $"); #include <string.h> #include <unistd.h> -#ifdef CITRUS -#include <citrus/citrus_namespace.h> -#include <citrus/citrus_region.h> -#include <citrus/citrus_lookup.h> +#ifdef HAVE_CITRUS +#include "citrus_namespace.h" +#include "citrus_bcs.h" +#include "citrus_region.h" +#include "citrus_lookup.h" +#include "citrus_aliasname_local.h" #else -#include <locale/aliasname_local.h> -#define _lookup_alias(p, a, b, s, c) __unaliasname((p), (a), (b), (s)) +#include "aliasname_local.h" #endif #define NLS_ALIAS_DB "/usr/share/nls/nls.alias" @@ -77,7 +78,7 @@ _catopen(name, oflag) { char tmppath[PATH_MAX+1]; const char *nlspath; - const char *lang; + const char *lang, *reallang; char *t; const char *s, *u; nl_catd catd; @@ -101,8 +102,9 @@ _catopen(name, oflag) if (lang == NULL || strchr(lang, '/')) lang = NLS_DEFAULT_LANG; - lang = _lookup_alias(NLS_ALIAS_DB, lang, langbuf, sizeof(langbuf), - _LOOKUP_CASE_SENSITIVE); + reallang = __unaliasname(NLS_ALIAS_DB, lang, langbuf, sizeof(langbuf)); + if (reallang == NULL) + reallang = lang; s = nlspath; t = tmppath; @@ -111,7 +113,7 @@ _catopen(name, oflag) if (*s == '%') { switch (*(++s)) { case 'L': /* locale */ - u = lang; + u = reallang; while (*u && t < tmppath + PATH_MAX) *t++ = *u++; break; diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index 6ff9fd5effd..c0e92cd2edb 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -1,5 +1,5 @@ # from: @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 -# $NetBSD: Makefile.inc,v 1.67 2007/02/17 09:32:58 wiz Exp $ +# $NetBSD: Makefile.inc,v 1.68 2009/01/02 00:20:21 tnozaki Exp $ # string sources .PATH: ${ARCHDIR}/string ${.CURDIR}/string @@ -13,8 +13,10 @@ SRCS+= bm.c strcasecmp.c strncasecmp.c strcasestr.c strcoll.c strdup.c \ SRCS+= wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \ wcslen.c wcsncat.c wcscasecmp.c wcsdup.c wcsncasecmp.c \ wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c wcsstr.c wcstok.c \ - wcswcs.c wcswidth.c \ - wmemchr.c wmemcmp.c wmemcpy.c wmemmove.c wmemset.c + wcswcs.c wmemchr.c wmemcmp.c wmemcpy.c wmemmove.c wmemset.c +CPPFLAGS.wcscmp.c+= -I${LIBCDIR}/locale +CPPFLAGS.wcsncmp.c+= -I${LIBCDIR}/locale +CPPFLAGS.wmemcmp.c+= -I${LIBCDIR}/locale # namespace protection wrappers SRCS+= _strlcat.c _strlcpy.c _strerror_r.c diff --git a/lib/libc/string/wcscmp.c b/lib/libc/string/wcscmp.c index f81fa702f61..652b84b5d18 100644 --- a/lib/libc/string/wcscmp.c +++ b/lib/libc/string/wcscmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcscmp.c,v 1.5 2003/08/07 16:43:54 agc Exp $ */ +/* $NetBSD: wcscmp.c,v 1.6 2009/01/02 00:20:21 tnozaki Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,13 +37,13 @@ #if 0 static char sccsid[] = "@(#)strcmp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: wcscmp.c,v 1.5 2003/08/07 16:43:54 agc Exp $"); +__RCSID("$NetBSD: wcscmp.c,v 1.6 2009/01/02 00:20:21 tnozaki Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include <assert.h> #include <wchar.h> -#include "locale/runetype.h" +#include "runetype.h" /* * Compare strings. diff --git a/lib/libc/string/wcsncmp.c b/lib/libc/string/wcsncmp.c index 5fe8354b57c..45345c8aca2 100644 --- a/lib/libc/string/wcsncmp.c +++ b/lib/libc/string/wcsncmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcsncmp.c,v 1.5 2003/08/07 16:43:54 agc Exp $ */ +/* $NetBSD: wcsncmp.c,v 1.6 2009/01/02 00:20:21 tnozaki Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,13 +34,13 @@ #if 0 static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: wcsncmp.c,v 1.5 2003/08/07 16:43:54 agc Exp $"); +__RCSID("$NetBSD: wcsncmp.c,v 1.6 2009/01/02 00:20:21 tnozaki Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include <assert.h> #include <wchar.h> -#include "locale/runetype.h" +#include "runetype.h" int wcsncmp(s1, s2, n) diff --git a/lib/libc/string/wmemcmp.c b/lib/libc/string/wmemcmp.c index d7db891f654..4ceeb30289e 100644 --- a/lib/libc/string/wmemcmp.c +++ b/lib/libc/string/wmemcmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: wmemcmp.c,v 1.3 2003/04/06 18:33:23 tshiozak Exp $ */ +/* $NetBSD: wmemcmp.c,v 1.4 2009/01/02 00:20:21 tnozaki Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,12 +30,12 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wmemcmp.c,v 1.3 2003/04/06 18:33:23 tshiozak Exp $"); +__RCSID("$NetBSD: wmemcmp.c,v 1.4 2009/01/02 00:20:21 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include <assert.h> #include <wchar.h> -#include "locale/runetype.h" +#include "runetype.h" int wmemcmp(s1, s2, n) |
