2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2001, 2003 Alexey Zelkin <phantom@FreeBSD.org>
7 * Copyright (c) 2011 The FreeBSD Foundation
9 * Portions of this software were developed by David Chisnall
10 * under sponsorship from the FreeBSD Foundation.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
47 #include "lmessages.h"
48 #include "lmonetary.h"
49 #include "../stdtime/timelocal.h"
51 #define _REL(BASE) ((int)item-BASE)
54 nl_langinfo_l(nl_item item, locale_t loc)
62 s = XLOCALE_CTYPE(loc)->runes->__encoding;
63 if (strcmp(s, "EUC-CN") == 0)
65 else if (strcmp(s, "EUC-JP") == 0)
67 else if (strcmp(s, "EUC-KR") == 0)
69 else if (strcmp(s, "EUC-TW") == 0)
71 else if (strcmp(s, "BIG5") == 0)
73 else if (strcmp(s, "MSKanji") == 0)
75 else if (strcmp(s, "NONE") == 0)
77 else if (strncmp(s, "NONE:", 5) == 0)
78 ret = (char *)(s + 5);
83 ret = (char *) __get_current_time_locale(loc)->c_fmt;
86 ret = (char *) __get_current_time_locale(loc)->x_fmt;
89 ret = (char *) __get_current_time_locale(loc)->X_fmt;
92 ret = (char *) __get_current_time_locale(loc)->ampm_fmt;
95 ret = (char *) __get_current_time_locale(loc)->am;
98 ret = (char *) __get_current_time_locale(loc)->pm;
100 case DAY_1: case DAY_2: case DAY_3:
101 case DAY_4: case DAY_5: case DAY_6: case DAY_7:
102 ret = (char*) __get_current_time_locale(loc)->weekday[_REL(DAY_1)];
104 case ABDAY_1: case ABDAY_2: case ABDAY_3:
105 case ABDAY_4: case ABDAY_5: case ABDAY_6: case ABDAY_7:
106 ret = (char*) __get_current_time_locale(loc)->wday[_REL(ABDAY_1)];
108 case MON_1: case MON_2: case MON_3: case MON_4:
109 case MON_5: case MON_6: case MON_7: case MON_8:
110 case MON_9: case MON_10: case MON_11: case MON_12:
111 ret = (char*) __get_current_time_locale(loc)->month[_REL(MON_1)];
113 case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4:
114 case ABMON_5: case ABMON_6: case ABMON_7: case ABMON_8:
115 case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12:
116 ret = (char*) __get_current_time_locale(loc)->mon[_REL(ABMON_1)];
118 case ALTMON_1: case ALTMON_2: case ALTMON_3: case ALTMON_4:
119 case ALTMON_5: case ALTMON_6: case ALTMON_7: case ALTMON_8:
120 case ALTMON_9: case ALTMON_10: case ALTMON_11: case ALTMON_12:
122 __get_current_time_locale(loc)->alt_month[_REL(ALTMON_1)];
125 /* XXX: need to be implemented */
129 /* XXX: need to be implemented */
133 /* XXX: need to be implemented */
137 /* XXX: need to be implemented */
141 /* XXX: need to be implemented */
145 ret = (char*) __get_current_numeric_locale(loc)->decimal_point;
148 ret = (char*) __get_current_numeric_locale(loc)->thousands_sep;
151 ret = (char*) __get_current_messages_locale(loc)->yesexpr;
154 ret = (char*) __get_current_messages_locale(loc)->noexpr;
157 * YESSTR and NOSTR items marked with LEGACY are available, but not
158 * recommended by SUSv2 to be used in portable applications since
159 * they're subject to remove in future specification editions.
161 case YESSTR: /* LEGACY */
162 ret = (char*) __get_current_messages_locale(loc)->yesstr;
164 case NOSTR: /* LEGACY */
165 ret = (char*) __get_current_messages_locale(loc)->nostr;
168 * SUSv2 special formatted currency string
172 cs = (char*) __get_current_monetary_locale(loc)->currency_symbol;
174 char pos = localeconv_l(loc)->p_cs_precedes;
176 if (pos == localeconv_l(loc)->n_cs_precedes) {
179 if (pos == CHAR_MAX) {
180 if (strcmp(cs, __get_current_monetary_locale(loc)->mon_decimal_point) == 0)
183 psn = pos ? '-' : '+';
185 int clen = strlen(cs);
187 if ((loc->csym = reallocf(loc->csym, clen + 2)) != NULL) {
189 strcpy(loc->csym + 1, cs);
196 case D_MD_ORDER: /* FreeBSD local extension */
197 ret = (char *) __get_current_time_locale(loc)->md_order;
206 nl_langinfo(nl_item item)
208 return nl_langinfo_l(item, __get_locale());