1 /* $MirOS: src/lib/libc/i18n/langinfo.c,v 1.16 2007/02/02 21:06:20 tg Exp $ */
2
3 /*-
4 * Copyright (c) 2003, 2004, 2005, 2006, 2007
5 * Thorsten Glaser <tg@mirbsd.de>
6 * Derived from work placed into the public domain by
7 * J.T. Conklin <jtc@netbsd.org>
8 *
9 * Provided that these terms and disclaimer and all copyright notices
10 * are retained or reproduced in an accompanying document, permission
11 * is granted to deal in this work without restriction, including un-
12 * limited rights to use, publicly perform, distribute, sell, modify,
13 * merge, give away, or sublicence.
14 *
15 * Advertising materials mentioning features or use of this work must
16 * display the following acknowledgement:
17 * This product includes material provided by Thorsten Glaser.
18 *
19 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
20 * the utmost extent permitted by applicable law, neither express nor
21 * implied; without malicious intent or gross negligence. In no event
22 * may a licensor, author or contributor be held liable for indirect,
23 * direct, other damage, loss, or other issues arising in any way out
24 * of dealing in the work, even if advised of the possibility of such
25 * damage or existence of a defect, except proven that it results out
26 * of said person's immediate fault when using the work as intended.
27 *-
28 * Fake locale support, just enough to fool people. Functions are de-
29 * fined weak in case someone wants to override these.
30 */
31
32 #define _LOCALE_CONST_LCONV
33 #include <sys/param.h>
34 #include <sys/localedef.h>
35 #include <langinfo.h>
36 #include <locale.h>
37 #include <stdlib.h>
38
39 __RCSID("$MirOS: src/lib/libc/i18n/langinfo.c,v 1.16 2007/02/02 21:06:20 tg Exp $");
40
41 /* fake locale support */
42
43 struct lconv *__weak_localeconv(void);
44 /* const for gcc's sake */
45 const char *__weak_nl_langinfo(nl_item);
46
47 _TimeLocale _DefaultTimeLocale = {
48 { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" },
49 { "Sunday", "Monday", "Tuesday", "Wednesday",
50 "Thursday", "Friday", "Saturday" },
51 { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
52 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" },
53 { "January", "February", "March", "April",
54 "May", "June", "July", "August", "September",
55 "October", "November", "December" },
56 { "AM", "PM" },
57 "%a %b %d %H:%M:%S %Y", "%m/%d/%y",
58 "%H:%M:%S", "%I:%M:%S %p"
59 };
60
61 struct lconv _DefaultLocaleConv = {
62 ".", "", "", "", "", "", "", "", "", "",
63 CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
64 CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX
65 };
66
67 struct lconv *
__weak_localeconv(void)68 __weak_localeconv(void)
69 {
70 return ((struct lconv *)&_DefaultLocaleConv);
71 }
72
73 const char *
__weak_nl_langinfo(nl_item item)74 __weak_nl_langinfo(nl_item item)
75 {
76 const char *s;
77
78 switch (item) {
79 case CODESET:
80 s = "UTF-8";
81 break;
82 case D_T_FMT:
83 s = _DefaultTimeLocale.d_t_fmt;
84 break;
85 case D_FMT:
86 s = _DefaultTimeLocale.d_fmt;
87 break;
88 case T_FMT:
89 s = _DefaultTimeLocale.t_fmt;
90 break;
91 case T_FMT_AMPM:
92 s = _DefaultTimeLocale.t_fmt_ampm;
93 break;
94 case AM_STR:
95 case PM_STR:
96 s = _DefaultTimeLocale.am_pm[item - AM_STR];
97 break;
98 case DAY_1:
99 case DAY_2:
100 case DAY_3:
101 case DAY_4:
102 case DAY_5:
103 case DAY_6:
104 case DAY_7:
105 s = _DefaultTimeLocale.day[item - DAY_1];
106 break;
107 case ABDAY_1:
108 case ABDAY_2:
109 case ABDAY_3:
110 case ABDAY_4:
111 case ABDAY_5:
112 case ABDAY_6:
113 case ABDAY_7:
114 s = _DefaultTimeLocale.abday[item - ABDAY_1];
115 break;
116 case MON_1:
117 case MON_2:
118 case MON_3:
119 case MON_4:
120 case MON_5:
121 case MON_6:
122 case MON_7:
123 case MON_8:
124 case MON_9:
125 case MON_10:
126 case MON_11:
127 case MON_12:
128 s = _DefaultTimeLocale.mon[item - MON_1];
129 break;
130 case ABMON_1:
131 case ABMON_2:
132 case ABMON_3:
133 case ABMON_4:
134 case ABMON_5:
135 case ABMON_6:
136 case ABMON_7:
137 case ABMON_8:
138 case ABMON_9:
139 case ABMON_10:
140 case ABMON_11:
141 case ABMON_12:
142 s = _DefaultTimeLocale.abmon[item - ABMON_1];
143 break;
144 case RADIXCHAR:
145 s = _DefaultLocaleConv.decimal_point;
146 break;
147 case YESSTR:
148 s = "yes";
149 break;
150 case YESEXPR:
151 s = "^[Yy]";
152 break;
153 case NOSTR:
154 s = "no";
155 break;
156 case NOEXPR:
157 s = "^[Nn]";
158 break;
159 case THOUSEP:
160 case CRNCYSTR:
161 default:
162 s = _DefaultLocaleConv.thousands_sep;
163 break;
164 }
165
166 return (s);
167 }
168
169 __weak_alias(localeconv, __weak_localeconv);
170 __weak_alias(nl_langinfo, __weak_nl_langinfo);
171