Home | History | Annotate | Line # | Download | only in locale
global_locale.c revision 1.25.10.1
      1 /* $NetBSD: global_locale.c,v 1.25.10.1 2017/07/14 15:53:08 perseant 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.25.10.1 2017/07/14 15:53:08 perseant 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 "collate_local.h"
     44 #include "runetype_local.h"
     45 #include "setlocale_local.h"
     46 
     47 #ifndef NBCHAR_MAX
     48 #define NBCHAR_MAX (char)CHAR_MAX
     49 #endif
     50 
     51 static const _MessagesLocale _DefaultMessagesLocale = {
     52 	"^[Yy]",
     53 	"^[Nn]",
     54 	"yes",
     55 	"no"
     56 };
     57 
     58 static const _MonetaryLocale _DefaultMonetaryLocale = {
     59 	"",
     60 	"",
     61 	"",
     62 	"",
     63 	"",
     64 	"",
     65 	"",
     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 	(char)CHAR_MAX
     80 };
     81 
     82 static const _NumericLocale _DefaultNumericLocale = {
     83 	".",
     84 	"",
     85 	""
     86 };
     87 
     88 static const _TimeLocale _DefaultTimeLocale =
     89 {
     90 	{
     91 		"Sun","Mon","Tue","Wed","Thu","Fri","Sat",
     92 	},
     93 	{
     94 		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
     95 		"Friday", "Saturday"
     96 	},
     97 	{
     98 		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
     99 		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
    100 	},
    101 	{
    102 		"January", "February", "March", "April", "May", "June", "July",
    103 		"August", "September", "October", "November", "December"
    104 	},
    105 	{
    106 		"AM", "PM"
    107 	},
    108 	"%a %b %e %H:%M:%S %Y",
    109 	"%m/%d/%y",
    110 	"%H:%M:%S",
    111 	"%I:%M:%S %p"
    112 };
    113 
    114 static const char _lc_C_locale_name[] = _C_LOCALE;
    115 
    116 __dso_hidden const struct _locale_cache_t _C_cache = {
    117     .ldata = {
    118 	.decimal_point		= __UNCONST("."),
    119 	.thousands_sep		= __UNCONST(""),
    120 	.grouping		= __UNCONST(""),
    121 	.int_curr_symbol	= __UNCONST(""),
    122 	.currency_symbol	= __UNCONST(""),
    123 	.mon_decimal_point	= __UNCONST(""),
    124 	.mon_thousands_sep	= __UNCONST(""),
    125 	.mon_grouping		= __UNCONST(""),
    126 	.positive_sign		= __UNCONST(""),
    127 	.negative_sign		= __UNCONST(""),
    128 	.int_frac_digits	= NBCHAR_MAX,
    129 	.frac_digits		= NBCHAR_MAX,
    130 	.p_cs_precedes		= NBCHAR_MAX,
    131 	.p_sep_by_space		= NBCHAR_MAX,
    132 	.n_cs_precedes		= NBCHAR_MAX,
    133 	.n_sep_by_space		= NBCHAR_MAX,
    134 	.p_sign_posn		= NBCHAR_MAX,
    135 	.n_sign_posn		= NBCHAR_MAX,
    136 	.int_p_cs_precedes	= NBCHAR_MAX,
    137 	.int_n_cs_precedes	= NBCHAR_MAX,
    138 	.int_p_sep_by_space	= NBCHAR_MAX,
    139 	.int_n_sep_by_space	= NBCHAR_MAX,
    140 	.int_p_sign_posn	= NBCHAR_MAX,
    141 	.int_n_sign_posn	= NBCHAR_MAX,
    142     },
    143     .monetary_name = _lc_C_locale_name,
    144     .numeric_name = _lc_C_locale_name,
    145 };
    146 
    147 struct _locale _lc_global_locale = {
    148     .cache = &_C_cache,
    149     .query = { _C_LOCALE },
    150     .part_name = {
    151 	[(size_t)LC_ALL     ] = _lc_C_locale_name,
    152 	[(size_t)LC_COLLATE ] = _lc_C_locale_name,
    153 	[(size_t)LC_CTYPE   ] = _lc_C_locale_name,
    154 	[(size_t)LC_MONETARY] = _lc_C_locale_name,
    155 	[(size_t)LC_NUMERIC ] = _lc_C_locale_name,
    156 	[(size_t)LC_TIME    ] = _lc_C_locale_name,
    157 	[(size_t)LC_MESSAGES] = _lc_C_locale_name,
    158     },
    159     .part_impl = {
    160 	[(size_t)LC_ALL     ] = (_locale_part_t)NULL,
    161 	[(size_t)LC_COLLATE ] = (_locale_part_t)
    162 	    __UNCONST(&_DefaultCollateLocale),
    163 	[(size_t)LC_CTYPE   ] = (_locale_part_t)
    164 	    __UNCONST(&_DefaultRuneLocale),
    165 	[(size_t)LC_MONETARY] = (_locale_part_t)
    166 	    __UNCONST(&_DefaultMonetaryLocale),
    167 	[(size_t)LC_NUMERIC ] = (_locale_part_t)
    168 	    __UNCONST(&_DefaultNumericLocale),
    169 	[(size_t)LC_MESSAGES] = (_locale_part_t)
    170 	    __UNCONST(&_DefaultMessagesLocale),
    171 	[(size_t)LC_TIME] = (_locale_part_t)
    172 	    __UNCONST(&_DefaultTimeLocale),
    173     },
    174 };
    175 
    176 const struct _locale _lc_C_locale = {
    177     .cache = &_C_cache,
    178     .query = { _C_LOCALE },
    179     .part_name = {
    180 	[(size_t)LC_ALL     ] = _lc_C_locale_name,
    181 	[(size_t)LC_COLLATE ] = _lc_C_locale_name,
    182 	[(size_t)LC_CTYPE   ] = _lc_C_locale_name,
    183 	[(size_t)LC_MONETARY] = _lc_C_locale_name,
    184 	[(size_t)LC_NUMERIC ] = _lc_C_locale_name,
    185 	[(size_t)LC_TIME    ] = _lc_C_locale_name,
    186 	[(size_t)LC_MESSAGES] = _lc_C_locale_name,
    187     },
    188     .part_impl = {
    189 	[(size_t)LC_ALL     ] = (_locale_part_t)NULL,
    190 	[(size_t)LC_COLLATE ] = (_locale_part_t)NULL,
    191 	[(size_t)LC_CTYPE   ] = (_locale_part_t)
    192 	    __UNCONST(&_DefaultRuneLocale),
    193 	[(size_t)LC_MONETARY] = (_locale_part_t)
    194 	    __UNCONST(&_DefaultMonetaryLocale),
    195 	[(size_t)LC_NUMERIC ] = (_locale_part_t)
    196 	    __UNCONST(&_DefaultNumericLocale),
    197 	[(size_t)LC_MESSAGES] = (_locale_part_t)
    198 	    __UNCONST(&_DefaultMessagesLocale),
    199 	[(size_t)LC_TIME] = (_locale_part_t)
    200 	    __UNCONST(&_DefaultTimeLocale),
    201     },
    202 };
    203