]>
Commit | Line | Data |
---|---|---|
34fdb893 | 1 | /* Test driver for nl_langinfo[_l] functions. |
04277e02 | 2 | Copyright (C) 2000-2019 Free Software Foundation, Inc. |
16093625 UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Ulrich Drepper <drepper@cygnus.com>. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
16093625 UD |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
16093625 | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 17 | License along with the GNU C Library; if not, see |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
16093625 | 19 | |
f79d99cb UD |
20 | #include <langinfo.h> |
21 | #include <locale.h> | |
22 | #include <stdio.h> | |
f1e09846 | 23 | #include <string.h> |
f79d99cb UD |
24 | |
25 | ||
26 | struct map | |
27 | { | |
28 | const char *str; | |
29 | int val; | |
30 | } map[] = | |
31 | { | |
32 | #define VAL(name) { #name, name } | |
33 | VAL (ABDAY_1), | |
34 | VAL (ABDAY_2), | |
35 | VAL (ABDAY_3), | |
36 | VAL (ABDAY_4), | |
37 | VAL (ABDAY_5), | |
38 | VAL (ABDAY_6), | |
39 | VAL (ABDAY_7), | |
40 | VAL (ABMON_1), | |
41 | VAL (ABMON_10), | |
42 | VAL (ABMON_11), | |
43 | VAL (ABMON_12), | |
44 | VAL (ABMON_2), | |
45 | VAL (ABMON_3), | |
46 | VAL (ABMON_4), | |
47 | VAL (ABMON_5), | |
48 | VAL (ABMON_6), | |
49 | VAL (ABMON_7), | |
50 | VAL (ABMON_8), | |
51 | VAL (ABMON_9), | |
52 | VAL (ALT_DIGITS), | |
95cb863a RL |
53 | VAL (ALTMON_1), |
54 | VAL (ALTMON_10), | |
55 | VAL (ALTMON_11), | |
56 | VAL (ALTMON_12), | |
57 | VAL (ALTMON_2), | |
58 | VAL (ALTMON_3), | |
59 | VAL (ALTMON_4), | |
60 | VAL (ALTMON_5), | |
61 | VAL (ALTMON_6), | |
62 | VAL (ALTMON_7), | |
63 | VAL (ALTMON_8), | |
64 | VAL (ALTMON_9), | |
f79d99cb UD |
65 | VAL (AM_STR), |
66 | VAL (CRNCYSTR), | |
67 | VAL (CURRENCY_SYMBOL), | |
68 | VAL (DAY_1), | |
69 | VAL (DAY_2), | |
70 | VAL (DAY_3), | |
71 | VAL (DAY_4), | |
72 | VAL (DAY_5), | |
73 | VAL (DAY_6), | |
74 | VAL (DAY_7), | |
75 | VAL (DECIMAL_POINT), | |
76 | VAL (D_FMT), | |
77 | VAL (D_T_FMT), | |
78 | VAL (ERA), | |
79 | VAL (ERA_D_FMT), | |
80 | VAL (ERA_D_T_FMT), | |
81 | VAL (ERA_T_FMT), | |
82 | VAL (ERA_YEAR), | |
83 | VAL (FRAC_DIGITS), | |
84 | VAL (GROUPING), | |
85 | VAL (INT_CURR_SYMBOL), | |
86 | VAL (INT_FRAC_DIGITS), | |
87 | VAL (MON_1), | |
88 | VAL (MON_10), | |
89 | VAL (MON_11), | |
90 | VAL (MON_12), | |
91 | VAL (MON_2), | |
92 | VAL (MON_3), | |
93 | VAL (MON_4), | |
94 | VAL (MON_5), | |
95 | VAL (MON_6), | |
96 | VAL (MON_7), | |
97 | VAL (MON_8), | |
98 | VAL (MON_9), | |
99 | VAL (MON_DECIMAL_POINT), | |
100 | VAL (MON_GROUPING), | |
101 | VAL (MON_THOUSANDS_SEP), | |
102 | VAL (NEGATIVE_SIGN), | |
103 | VAL (NOEXPR), | |
104 | VAL (NOSTR), | |
105 | VAL (N_CS_PRECEDES), | |
106 | VAL (N_SEP_BY_SPACE), | |
107 | VAL (N_SIGN_POSN), | |
108 | VAL (PM_STR), | |
109 | VAL (POSITIVE_SIGN), | |
110 | VAL (P_CS_PRECEDES), | |
111 | VAL (P_SEP_BY_SPACE), | |
112 | VAL (P_SIGN_POSN), | |
113 | VAL (RADIXCHAR), | |
114 | VAL (THOUSANDS_SEP), | |
115 | VAL (THOUSEP), | |
116 | VAL (T_FMT), | |
117 | VAL (T_FMT_AMPM), | |
118 | VAL (YESEXPR), | |
119 | VAL (YESSTR) | |
120 | }; | |
121 | ||
122 | ||
123 | static int | |
124 | map_paramstr (const char *str) | |
125 | { | |
126 | int low = 0; | |
127 | int high = sizeof (map) / sizeof (map[0]); | |
128 | ||
129 | while (low < high) | |
130 | { | |
131 | int med = (low + high) / 2; | |
132 | int cmpres; | |
133 | ||
134 | cmpres = strcmp (str, map[med].str); | |
135 | if (cmpres == 0) | |
136 | return map[med].val; | |
137 | else if (cmpres > 0) | |
138 | low = med + 1; | |
139 | else | |
140 | high = med; | |
141 | } | |
142 | ||
143 | return -1; | |
144 | } | |
145 | ||
146 | ||
147 | #ifdef DEBUG | |
148 | # define REASON(str) printf ("\"%s\" ignored: %s\n", buf, str) | |
149 | #else | |
150 | # define REASON(str) | |
151 | #endif | |
152 | ||
0035851c AS |
153 | static int |
154 | do_test (void) | |
f79d99cb UD |
155 | { |
156 | int result = 0; | |
157 | ||
158 | while (! feof (stdin)) | |
159 | { | |
160 | char buf[1000]; | |
161 | char *rp; | |
162 | char *locale; | |
163 | char *paramstr; | |
164 | char *expected; | |
f79d99cb UD |
165 | int param; |
166 | ||
167 | if (fgets (buf, sizeof (buf), stdin) == NULL) | |
168 | break; | |
169 | ||
170 | /* Split the fields. There are three is them: | |
171 | 1. locale | |
172 | 2. langinfo() parameter | |
173 | 3. expected result; this can be a string with white space etc. | |
174 | */ | |
175 | rp = buf; | |
176 | while (*rp == ' ' || *rp == '\t') | |
177 | ++rp; | |
178 | ||
179 | if (*rp == '#') | |
180 | { | |
181 | /* It's a comment line. Ignore it. */ | |
182 | REASON ("comment"); | |
183 | continue; | |
184 | } | |
185 | locale = rp; | |
186 | ||
187 | while (*rp != '\0' && *rp != ' ' && *rp != '\t' && *rp != '\n') | |
188 | ++rp; | |
189 | if (*rp == '\0' || *rp == '\n') | |
190 | { | |
191 | /* Incomplete line. */ | |
192 | REASON ("incomplete line"); | |
193 | continue; | |
194 | } | |
195 | *rp++ = '\0'; | |
196 | ||
197 | while (*rp == ' ' || *rp == '\t') | |
198 | ++rp; | |
199 | paramstr = rp; | |
200 | ||
201 | while (*rp != '\0' && *rp != ' ' && *rp != '\t' && *rp != '\n') | |
202 | ++rp; | |
203 | if (*rp == '\0' || *rp == '\n') | |
204 | { | |
205 | /* Incomplete line. */ | |
206 | REASON ("incomplete line"); | |
207 | continue; | |
208 | } | |
209 | *rp++ = '\0'; | |
210 | ||
211 | while (*rp == ' ' || *rp == '\t') | |
212 | ++rp; | |
213 | ||
214 | if (*rp == '"') | |
215 | { | |
216 | char *wp; | |
217 | ||
218 | expected = wp = ++rp; | |
219 | while (*rp != '"' && *rp != '\n' && *rp != '\0') | |
220 | { | |
221 | if (*rp == '\\') | |
222 | { | |
223 | ++rp; | |
224 | if (*rp == '\0') | |
225 | break; | |
a9706118 | 226 | if (*rp >= '0' && *rp <= '9') |
f79d99cb UD |
227 | { |
228 | int val = *rp - '0'; | |
229 | if (rp[1] >= '0' && rp[1] <= '9') | |
230 | { | |
231 | ++rp; | |
232 | val *= 10; | |
233 | val += *rp - '0'; | |
234 | if (rp[1] >= '0' && rp[1] <= '9') | |
235 | { | |
236 | ++rp; | |
237 | val *= 10; | |
238 | val += *rp - '0'; | |
239 | } | |
240 | } | |
241 | *rp = val; | |
242 | } | |
243 | } | |
244 | *wp++ = *rp++; | |
245 | } | |
246 | ||
247 | if (*rp != '"') | |
248 | { | |
249 | REASON ("missing '\"'"); | |
250 | continue; | |
251 | } | |
252 | ||
253 | *wp = '\0'; | |
254 | } | |
255 | else | |
256 | { | |
257 | expected = rp; | |
258 | while (*rp != '\0' && *rp != '\n') | |
259 | ++rp; | |
260 | *rp = '\0'; | |
261 | } | |
262 | ||
263 | param = map_paramstr (paramstr); | |
264 | if (param == -1) | |
265 | { | |
266 | /* Invalid parameter. */ | |
267 | REASON ("invalid parameter"); | |
268 | continue; | |
269 | } | |
270 | ||
34fdb893 | 271 | result = test_locale (locale, paramstr, param, expected); |
f79d99cb UD |
272 | } |
273 | ||
274 | return result; | |
275 | } | |
0035851c AS |
276 | |
277 | #define TEST_FUNCTION do_test () | |
278 | #include "../test-skeleton.c" |