dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libc / port / locale / nl_langinfo.c
blob076162b2ce8ac563919124ab5fb15d0bf2b540b0
1 /*
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>
5 * All rights reserved.
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.
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.
29 #include "lint.h"
30 #include <langinfo.h>
31 #include <limits.h>
32 #include <locale.h>
33 #include <stdlib.h>
34 #include <string.h>
36 #include "lnumeric.h"
37 #include "lmessages.h"
38 #include "lmonetary.h"
39 #include "timelocal.h"
40 #include "localeimpl.h"
41 #include "runetype.h"
43 #define _REL(BASE) ((int)item-BASE)
45 #pragma weak _nl_langinfo = nl_langinfo
47 char *
48 nl_langinfo_l(nl_item item, locale_t loc)
50 char *ret;
51 const char *s;
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;
57 switch (item) {
58 case CODESET:
59 s = loc->runelocale->__encoding;
60 if (strcmp(s, "NONE") == 0)
61 ret = "US-ASCII";
62 else if (strncmp(s, "NONE:", 5) == 0)
63 ret = (char *)(s + 5);
64 else
65 ret = (char *)s;
66 break;
67 case D_T_FMT:
68 ret = (char *)ltime->c_fmt;
69 break;
70 case D_FMT:
71 ret = (char *)ltime->x_fmt;
72 break;
73 case T_FMT:
74 ret = (char *)ltime->X_fmt;
75 break;
76 case T_FMT_AMPM:
77 ret = (char *)ltime->ampm_fmt;
78 break;
79 case AM_STR:
80 ret = (char *)ltime->am;
81 break;
82 case PM_STR:
83 ret = (char *)ltime->pm;
84 break;
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)];
88 break;
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)];
92 break;
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)];
97 break;
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)];
102 break;
103 case ERA:
104 /* XXX: need to be implemented */
105 ret = "";
106 break;
107 case ERA_D_FMT:
108 /* XXX: need to be implemented */
109 ret = "";
110 break;
111 case ERA_D_T_FMT:
112 /* XXX: need to be implemented */
113 ret = "";
114 break;
115 case ERA_T_FMT:
116 /* XXX: need to be implemented */
117 ret = "";
118 break;
119 case ALT_DIGITS:
120 /* XXX: need to be implemented */
121 ret = "";
122 break;
123 case RADIXCHAR:
124 ret = (char *)lnum->decimal_point;
125 break;
126 case THOUSEP:
127 ret = (char *)lnum->thousands_sep;
128 break;
129 case YESEXPR:
130 ret = (char *)lmsgs->yesexpr;
131 break;
132 case NOEXPR:
133 ret = (char *)lmsgs->noexpr;
134 break;
136 * YESSTR and NOSTR items were removed from Issue 7. But
137 * older applications might still need them. Their use is
138 * discouraged.
140 case YESSTR: /* LEGACY */
141 ret = (char *)lmsgs->yesstr;
142 break;
143 case NOSTR: /* LEGACY */
144 ret = (char *)lmsgs->nostr;
145 break;
147 * SUSv2 special formatted currency string
149 case CRNCYSTR:
150 ret = lmon->crncystr;
151 break;
153 case _DATE_FMT: /* Solaris specific extension */
154 ret = (char *)ltime->date_fmt;
155 break;
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.
160 default:
161 ret = "";
163 return (ret);
166 char *
167 nl_langinfo(nl_item item)
169 return (nl_langinfo_l(item, uselocale(NULL)));