Add support for additional locale categories: LC_MESSAGES, LC_MONETARY,

LC_NUMERIC.

The code used to load LC_TIME was refactored in to a more general routine.
This common routine is now used to load LC_TIME along with the newly added
categories.

Changes discussed with/reviewed by christos.
This commit is contained in:
ginsbach 2008-05-17 03:49:54 +00:00
parent a4e1a9b84e
commit bcd54758b8
16 changed files with 743 additions and 144 deletions

View File

@ -1,12 +1,13 @@
# from: @(#)Makefile.inc 5.1 (Berkeley) 2/18/91
# $NetBSD: Makefile.inc,v 1.51 2007/03/28 19:05:48 manu Exp $
# $NetBSD: Makefile.inc,v 1.52 2008/05/17 03:49:54 ginsbach Exp $
# locale sources
.PATH: ${ARCHDIR}/locale ${.CURDIR}/locale
SRCS+= _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \
ctypeio.c localeconv.c nl_langinfo.c setlocale.c setlocale1.c \
setlocale32.c __mb_cur_max.c wcscoll.c wcsftime.c timeio.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 \
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

View File

@ -1,4 +1,4 @@
/* $NetBSD: _def_time.c,v 1.9 2007/03/28 19:05:53 manu Exp $ */
/* $NetBSD: _def_time.c,v 1.10 2008/05/17 03:49:54 ginsbach Exp $ */
/*
* Written by J.T. Conklin <jtc@NetBSD.org>.
@ -7,13 +7,13 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: _def_time.c,v 1.9 2007/03/28 19:05:53 manu Exp $");
__RCSID("$NetBSD: _def_time.c,v 1.10 2008/05/17 03:49:54 ginsbach Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/localedef.h>
#include <locale.h>
_TimeLocale _DefaultTimeLocale =
const _TimeLocale _DefaultTimeLocale =
{
{
"Sun","Mon","Tue","Wed","Thu","Fri","Sat",
@ -39,4 +39,4 @@ _TimeLocale _DefaultTimeLocale =
"%I:%M:%S %p"
};
_TimeLocale *_CurrentTimeLocale = &_DefaultTimeLocale;
const _TimeLocale *_CurrentTimeLocale = &_DefaultTimeLocale;

View File

@ -0,0 +1,71 @@
/* $NetBSD: lcmessages.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: lcmessages.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 "localeio.h"
#include "lcmessages.h"
#define NSTRINGS (sizeof(_MessagesLocale)/sizeof(const char **))
int
__loadmessages(const char *filename)
{
_DIAGASSERT(filename != NULL);
return __loadlocale(filename, NSTRINGS, 0, sizeof(_MessagesLocale),
&_CurrentMessagesLocale, &_DefaultMessagesLocale);
}
#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 */

View File

@ -0,0 +1,33 @@
/* $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

View File

@ -0,0 +1,130 @@
/* $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

View File

@ -0,0 +1,33 @@
/* $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

View File

@ -0,0 +1,86 @@
/* $NetBSD: lcnumeric.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: lcnumeric.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 "localeio.h"
#include "lcnumeric.h"
#define NSTRINGS (sizeof(_NumericLocale)/sizeof(const char **))
int
__loadnumeric(const char *filename)
{
const char **gpp;
_DIAGASSERT(filename != NULL);
if (!__loadlocale(filename, NSTRINGS, 0, sizeof(_NumericLocale),
&_CurrentNumericLocale, &_DefaultNumericLocale)) {
return 0;
}
gpp = __UNCONST(&_CurrentNumericLocale->grouping);
*gpp = __convertgrouping(_CurrentNumericLocale->grouping);
return 1;
}
#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 */

View File

@ -0,0 +1,30 @@
/* $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

92
lib/libc/locale/lctime.c Normal file
View File

@ -0,0 +1,92 @@
/* $NetBSD: lctime.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: lctime.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 "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 <stdio.h>
void
__dumptimelocale()
{
int i;
for (i = 0; i < 7; i++)
(void)printf("abday[%d] = \"%s\"\n",
i, _CurrentTimeLocale->abday[i]);
for (i = 0; i < 7; i++)
(void)printf("day[%d] = \"%s\"\n",
i, _CurrentTimeLocale->day[i]);
for (i = 0; i < 12; i++)
(void)printf("abmon[%d] = \"%s\"\n",
i, _CurrentTimeLocale->abmon[i]);
for (i = 0; i < 12; i++)
(void)printf("mon[%d] = \"%s\"\n",
i, _CurrentTimeLocale->mon[i]);
for (i = 0; i < 2; i++)
(void)printf("am_pm[%d] = \"%s\"\n",
i, _CurrentTimeLocale->am_pm[i]);
(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);
}
#endif /* LOCALE_DEBUG */

33
lib/libc/locale/lctime.h Normal file
View File

@ -0,0 +1,33 @@
/* $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

154
lib/libc/locale/localeio.c Normal file
View File

@ -0,0 +1,154 @@
/* $NetBSD: localeio.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: localeio.c,v 1.1 2008/05/17 03:49:54 ginsbach 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 <fcntl.h>
#include <limits.h>
#include <locale.h>
#include <paths.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "localeio.h"
int
__loadlocale(const char *name, size_t nstr, size_t nbytes, size_t localesize,
void *currentlocale, const void *defaultlocale)
{
int fd, i;
unsigned char **ap, *buf, *bp, *cp, *cbp, *ebp;
unsigned char ***locale;
struct stat st;
size_t bufsize;
_DIAGASSERT(name != NULL);
_DIAGASSERT(localesize != 0);
_DIAGASSERT(currentlocale != NULL);
_DIAGASSERT(defaultlocale != NULL);
if ((fd = open(name, O_RDONLY)) == -1)
return 0;
if ((fstat(fd, &st) == -1) || (st.st_size <= 0))
goto error1;
bufsize = localesize + (size_t)st.st_size;
if ((buf = malloc(bufsize)) == NULL)
goto error1;
bp = buf + localesize;
if (read(fd, bp, (size_t)st.st_size) != st.st_size)
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)
goto error2;
*bp++ = '\0';
}
cp = buf + (sizeof(unsigned char *) * nstr);
for (i = 0, cbp = bp; i < nbytes; i++) {
int n;
while (bp != ebp && *bp != '\n')
bp++;
if (bp == ebp)
goto error2;
/* ignore overflow/underflow and bad characters */
n = (unsigned char)strtol((char *)cbp, NULL, 0);
cp[i] = (unsigned char)(n & CHAR_MAX);
cbp = bp;
}
locale = currentlocale;
if (*locale != defaultlocale)
free(*locale);
*locale = (unsigned char **)(void *)buf;
(void)close(fd);
return 1;
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;
}

View File

@ -0,0 +1,34 @@
/* $NetBSD: localeio.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 __loadlocale(const char *, size_t, size_t, size_t, void *, const void *);
const char * __convertgrouping(const char *);
__END_DECLS

View File

@ -1,7 +1,7 @@
/* $NetBSD: setlocale.c,v 1.52 2007/09/29 07:55:45 tnozaki Exp $ */
/* $NetBSD: setlocale.c,v 1.53 2008/05/17 03:49:54 ginsbach Exp $ */
/*
* Copyright (c) 1991, 1993
* 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
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93";
#else
__RCSID("$NetBSD: setlocale.c,v 1.52 2007/09/29 07:55:45 tnozaki Exp $");
__RCSID("$NetBSD: setlocale.c,v 1.53 2008/05/17 03:49:54 ginsbach Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -63,7 +63,10 @@ __RCSID("$NetBSD: setlocale.c,v 1.52 2007/09/29 07:55:45 tnozaki Exp $");
#else
#include "ctypeio.h"
#endif
#include "timeio.h"
#include "lcmessages.h"
#include "lcmonetary.h"
#include "lcnumeric.h"
#include "lctime.h"
#ifdef CITRUS
#include <citrus/citrus_namespace.h>
@ -265,14 +268,29 @@ revert_to_default(category)
break;
case LC_TIME:
if (_CurrentTimeLocale != &_DefaultTimeLocale) {
free((void *)_CurrentTimeLocale);
free(__UNCONST(_CurrentTimeLocale));
_CurrentTimeLocale = &_DefaultTimeLocale;
}
break;
case LC_MESSAGES:
if (_CurrentMessagesLocale != &_DefaultMessagesLocale) {
free(__UNCONST(_CurrentMessagesLocale));
_CurrentMessagesLocale = &_DefaultMessagesLocale;
}
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;
}
}
@ -324,6 +342,7 @@ load_locale_sub(category, locname, isspecial)
break;
case LC_MESSAGES:
#ifdef OLD_NO_LC_MESSAGES
/*
* XXX we don't have LC_MESSAGES support yet,
* but catopen may use the value of LC_MESSAGES category.
@ -339,6 +358,10 @@ load_locale_sub(category, locname, isspecial)
if (!S_ISDIR(st.st_mode))
return -1;
}
#else
if (!__loadmessages(name))
return -1;
#endif
break;
case LC_TIME:
@ -346,9 +369,15 @@ load_locale_sub(category, locname, isspecial)
return -1;
break;
case LC_COLLATE:
case LC_MONETARY:
case LC_NUMERIC:
return -1;
case LC_MONETARY:
if (!__loadmonetary(name))
return -1;
break;
case LC_NUMERIC:
if (!__loadnumeric(name))
return -1;
break;
}
return 0;

View File

@ -1,92 +0,0 @@
/* $NetBSD: timeio.c,v 1.2 2007/04/04 21:54:45 christos Exp $ */
/*
* Copyright (c) 2000 Joachim Kuebart. 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Joachim Kuebart.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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/types.h>
#include <sys/stat.h>
#include <sys/localedef.h>
#include <stdio.h>
#include <stdlib.h>
#include "timeio.h"
int
__loadtime(name)
const char *name;
{
FILE *fp;
struct stat st;
unsigned char **ab, *p, *pend;
_TimeLocale *tl;
if ((fp = fopen(name, "r")) == NULL)
return 0;
if (fstat(fileno(fp), &st) != 0)
goto closeit;
if ((tl = malloc(sizeof(*tl) + (unsigned)st.st_size)) == NULL)
goto closeit;
if (fread(tl + 1, (unsigned)st.st_size, 1, fp) != 1) {
free(tl);
goto closeit;
}
(void)fclose(fp);
/* LINTED pointer cast */
p = (unsigned char *)&tl[1];
pend = p + (unsigned)st.st_size;
/* LINTED pointer cast */
for (ab = (unsigned char **)tl;
ab != (unsigned char **)&tl[1];
ab++) {
*ab = p;
while (p != pend && *p != '\n')
p++;
if (p == pend) {
free(tl);
return 0;
}
*p++ = '\0';
}
if (_CurrentTimeLocale != &_DefaultTimeLocale)
/* LINTED const castaway */
free((void *)_CurrentTimeLocale);
_CurrentTimeLocale = tl;
return 1;
closeit:
(void)fclose(fp);
return 0;
}

View File

@ -1,35 +0,0 @@
/* $NetBSD: timeio.h,v 1.1 2007/03/28 19:05:54 manu Exp $ */
/*
* Copyright (c) 2000 Joachim Kuebart. 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Joachim Kuebart.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 __P((const char *));
__END_DECLS

View File

@ -1,4 +1,4 @@
/* $NetBSD: localedef.h,v 1.8 2007/03/30 15:55:38 he Exp $ */
/* $NetBSD: localedef.h,v 1.9 2008/05/17 03:49:54 ginsbach Exp $ */
/*
* Copyright (c) 1994 Winning Strategies, Inc.
@ -94,7 +94,7 @@ typedef struct {
const char *t_fmt_ampm;
} _TimeLocale;
extern _TimeLocale *_CurrentTimeLocale;
extern _TimeLocale _DefaultTimeLocale;
extern const _TimeLocale *_CurrentTimeLocale;
extern const _TimeLocale _DefaultTimeLocale;
#endif /* !_SYS_LOCALEDEF_H_ */