Home | History | Annotate | Line # | Download | only in locale
global_locale.c revision 1.21
      1 /* $NetBSD: global_locale.c,v 1.21 2013/09/13 13:13:32 joerg Exp $ */
      2 
      3 /*-
      4  * Copyright (c)2008 Citrus Project,
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 #if defined(LIBC_SCCS) && !defined(lint)
     31 __RCSID("$NetBSD: global_locale.c,v 1.21 2013/09/13 13:13:32 joerg Exp $");
     32 #endif /* LIBC_SCCS and not lint */
     33 
     34 #include <sys/types.h>
     35 #include <sys/ctype_bits.h>
     36 #include <sys/localedef.h>
     37 #include <langinfo.h>
     38 #include <limits.h>
     39 #define __SETLOCALE_SOURCE__
     40 #include <locale.h>
     41 #include <stdlib.h>
     42 
     43 #include "runetype_local.h"
     44 #include "setlocale_local.h"
     45 
     46 #ifndef NBCHAR_MAX
     47 #define NBCHAR_MAX (char)CHAR_MAX
     48 #endif
     49 
     50 static const _MessagesLocale _DefaultMessagesLocale = {
     51 	"^[Yy]",
     52 	"^[Nn]",
     53 	"yes",
     54 	"no"
     55 };
     56 
     57 static const _MonetaryLocale _DefaultMonetaryLocale = {
     58 	"",
     59 	"",
     60 	"",
     61 	"",
     62 	"",
     63 	"",
     64 	"",
     65 	(char)CHAR_MAX,
     66 	(char)CHAR_MAX,
     67 	(char)CHAR_MAX,
     68 	(char)CHAR_MAX,
     69 	(char)CHAR_MAX,
     70 	(char)CHAR_MAX,
     71 	(char)CHAR_MAX,
     72 	(char)CHAR_MAX,
     73 	(char)CHAR_MAX,
     74 	(char)CHAR_MAX,
     75 	(char)CHAR_MAX,
     76 	(char)CHAR_MAX,
     77 	(char)CHAR_MAX,
     78 	(char)CHAR_MAX
     79 };
     80 
     81 static const _NumericLocale _DefaultNumericLocale = {
     82 	".",
     83 	"",
     84 	""
     85 };
     86 
     87 static const _TimeLocale _DefaultTimeLocale =
     88 {
     89 	{
     90 		"Sun","Mon","Tue","Wed","Thu","Fri","Sat",
     91 	},
     92 	{
     93 		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
     94 		"Friday", "Saturday"
     95 	},
     96 	{
     97 		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
     98 		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
     99 	},
    100 	{
    101 		"January", "February", "March", "April", "May", "June", "July",
    102 		"August", "September", "October", "November", "December"
    103 	},
    104 	{
    105 		"AM", "PM"
    106 	},
    107 	"%a %b %e %H:%M:%S %Y",
    108 	"%m/%d/%y",
    109 	"%H:%M:%S",
    110 	"%I:%M:%S %p"
    111 };
    112 
    113 static const char _lc_C_locale_name[] = _C_LOCALE;
    114 
    115 __dso_hidden const struct _locale_cache_t _C_cache = {
    116     .ldata = {
    117 	.decimal_point		= __UNCONST("."),
    118 	.thousands_sep		= __UNCONST(""),
    119 	.grouping		= __UNCONST(""),
    120 	.int_curr_symbol	= __UNCONST(""),
    121 	.currency_symbol	= __UNCONST(""),
    122 	.mon_decimal_point	= __UNCONST(""),
    123 	.mon_thousands_sep	= __UNCONST(""),
    124 	.mon_grouping		= __UNCONST(""),
    125 	.positive_sign		= __UNCONST(""),
    126 	.negative_sign		= __UNCONST(""),
    127 	.int_frac_digits	= NBCHAR_MAX,
    128 	.frac_digits		= NBCHAR_MAX,
    129 	.p_cs_precedes		= NBCHAR_MAX,
    130 	.p_sep_by_space		= NBCHAR_MAX,
    131 	.n_cs_precedes		= NBCHAR_MAX,
    132 	.n_sep_by_space		= NBCHAR_MAX,
    133 	.p_sign_posn		= NBCHAR_MAX,
    134 	.n_sign_posn		= NBCHAR_MAX,
    135 	.int_p_cs_precedes	= NBCHAR_MAX,
    136 	.int_n_cs_precedes	= NBCHAR_MAX,
    137 	.int_p_sep_by_space	= NBCHAR_MAX,
    138 	.int_n_sep_by_space	= NBCHAR_MAX,
    139 	.int_p_sign_posn	= NBCHAR_MAX,
    140 	.int_n_sign_posn	= NBCHAR_MAX,
    141     },
    142     .monetary_name = _lc_C_locale_name,
    143     .numeric_name = _lc_C_locale_name,
    144 };
    145 
    146 __dso_protected struct _locale _lc_global_locale = {
    147     .cache = &_C_cache,
    148     .query = { _C_LOCALE },
    149     .part_name = {
    150 	[(size_t)LC_ALL     ] = _lc_C_locale_name,
    151 	[(size_t)LC_COLLATE ] = _lc_C_locale_name,
    152 	[(size_t)LC_CTYPE   ] = _lc_C_locale_name,
    153 	[(size_t)LC_MONETARY] = _lc_C_locale_name,
    154 	[(size_t)LC_NUMERIC ] = _lc_C_locale_name,
    155 	[(size_t)LC_TIME    ] = _lc_C_locale_name,
    156 	[(size_t)LC_MESSAGES] = _lc_C_locale_name,
    157     },
    158     .part_impl = {
    159 	[(size_t)LC_ALL     ] = (_locale_part_t)NULL,
    160 	[(size_t)LC_COLLATE ] = (_locale_part_t)NULL,
    161 	[(size_t)LC_CTYPE   ] = (_locale_part_t)
    162 	    __UNCONST(&_DefaultRuneLocale),
    163 	[(size_t)LC_MONETARY] = (_locale_part_t)
    164 	    __UNCONST(&_DefaultMonetaryLocale),
    165 	[(size_t)LC_NUMERIC ] = (_locale_part_t)
    166 	    __UNCONST(&_DefaultNumericLocale),
    167 	[(size_t)LC_MESSAGES] = (_locale_part_t)
    168 	    __UNCONST(&_DefaultMessagesLocale),
    169 	[(size_t)LC_TIME] = (_locale_part_t)
    170 	    __UNCONST(&_DefaultTimeLocale),
    171     },
    172 };
    173 
    174 __dso_protected const struct _locale _lc_C_locale = {
    175     .cache = &_C_cache,
    176     .query = { _C_LOCALE },
    177     .part_name = {
    178 	[(size_t)LC_ALL     ] = _lc_C_locale_name,
    179 	[(size_t)LC_COLLATE ] = _lc_C_locale_name,
    180 	[(size_t)LC_CTYPE   ] = _lc_C_locale_name,
    181 	[(size_t)LC_MONETARY] = _lc_C_locale_name,
    182 	[(size_t)LC_NUMERIC ] = _lc_C_locale_name,
    183 	[(size_t)LC_TIME    ] = _lc_C_locale_name,
    184 	[(size_t)LC_MESSAGES] = _lc_C_locale_name,
    185     },
    186     .part_impl = {
    187 	[(size_t)LC_ALL     ] = (_locale_part_t)NULL,
    188 	[(size_t)LC_COLLATE ] = (_locale_part_t)NULL,
    189 	[(size_t)LC_CTYPE   ] = (_locale_part_t)
    190 	    __UNCONST(&_DefaultRuneLocale),
    191 	[(size_t)LC_MONETARY] = (_locale_part_t)
    192 	    __UNCONST(&_DefaultMonetaryLocale),
    193 	[(size_t)LC_NUMERIC ] = (_locale_part_t)
    194 	    __UNCONST(&_DefaultNumericLocale),
    195 	[(size_t)LC_MESSAGES] = (_locale_part_t)
    196 	    __UNCONST(&_DefaultMessagesLocale),
    197 	[(size_t)LC_TIME] = (_locale_part_t)
    198 	    __UNCONST(&_DefaultTimeLocale),
    199     },
    200 };
    201