2 * Copyright 2013 Garrett D'Amore <garrett@damore.org>
3 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
4 * Copyright (c) 2001, 2003 Alexey Zelkin <phantom@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
37 #include "lmessages.h"
38 #include "lmonetary.h"
39 #include "timelocal.h"
40 #include "localeimpl.h"
43 #define _REL(BASE) ((int)item-BASE)
45 #pragma weak _nl_langinfo = nl_langinfo
48 nl_langinfo_l(nl_item item
, locale_t loc
)
52 const struct lc_monetary
*lmon
= loc
->monetary
;
53 const struct lc_numeric
*lnum
= loc
->numeric
;
54 const struct lc_messages
*lmsgs
= loc
->messages
;
55 const struct lc_time
*ltime
= loc
->time
;
59 s
= loc
->runelocale
->__encoding
;
60 if (strcmp(s
, "NONE") == 0)
62 else if (strncmp(s
, "NONE:", 5) == 0)
63 ret
= (char *)(s
+ 5);
68 ret
= (char *)ltime
->c_fmt
;
71 ret
= (char *)ltime
->x_fmt
;
74 ret
= (char *)ltime
->X_fmt
;
77 ret
= (char *)ltime
->ampm_fmt
;
80 ret
= (char *)ltime
->am
;
83 ret
= (char *)ltime
->pm
;
85 case DAY_1
: case DAY_2
: case DAY_3
:
86 case DAY_4
: case DAY_5
: case DAY_6
: case DAY_7
:
87 ret
= (char *)ltime
->weekday
[_REL(DAY_1
)];
89 case ABDAY_1
: case ABDAY_2
: case ABDAY_3
:
90 case ABDAY_4
: case ABDAY_5
: case ABDAY_6
: case ABDAY_7
:
91 ret
= (char *)ltime
->wday
[_REL(ABDAY_1
)];
93 case MON_1
: case MON_2
: case MON_3
: case MON_4
:
94 case MON_5
: case MON_6
: case MON_7
: case MON_8
:
95 case MON_9
: case MON_10
: case MON_11
: case MON_12
:
96 ret
= (char *)ltime
->month
[_REL(MON_1
)];
98 case ABMON_1
: case ABMON_2
: case ABMON_3
: case ABMON_4
:
99 case ABMON_5
: case ABMON_6
: case ABMON_7
: case ABMON_8
:
100 case ABMON_9
: case ABMON_10
: case ABMON_11
: case ABMON_12
:
101 ret
= (char *)ltime
->mon
[_REL(ABMON_1
)];
104 /* XXX: need to be implemented */
108 /* XXX: need to be implemented */
112 /* XXX: need to be implemented */
116 /* XXX: need to be implemented */
120 /* XXX: need to be implemented */
124 ret
= (char *)lnum
->decimal_point
;
127 ret
= (char *)lnum
->thousands_sep
;
130 ret
= (char *)lmsgs
->yesexpr
;
133 ret
= (char *)lmsgs
->noexpr
;
136 * YESSTR and NOSTR items were removed from Issue 7. But
137 * older applications might still need them. Their use is
140 case YESSTR
: /* LEGACY */
141 ret
= (char *)lmsgs
->yesstr
;
143 case NOSTR
: /* LEGACY */
144 ret
= (char *)lmsgs
->nostr
;
147 * SUSv2 special formatted currency string
150 ret
= lmon
->crncystr
;
153 case _DATE_FMT
: /* Solaris specific extension */
154 ret
= (char *)ltime
->date_fmt
;
157 * Note that FreeBSD also had a private D_MD_ORDER, but that appears
158 * to have been specific to FreeBSD, so we have not included it here.
167 nl_langinfo(nl_item item
)
169 return (nl_langinfo_l(item
, uselocale(NULL
)));