1 | /*- |
---|
2 | * Copyright (C) 1997 by Andrey A. Chernov, Moscow, Russia. |
---|
3 | * All rights reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms, with or without |
---|
6 | * modification, are permitted provided that the following conditions |
---|
7 | * are met: |
---|
8 | * 1. Redistributions of source code must retain the above copyright |
---|
9 | * notice, this list of conditions and the following disclaimer. |
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer in the |
---|
12 | * documentation and/or other materials provided with the distribution. |
---|
13 | * |
---|
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND |
---|
15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
---|
18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
24 | * SUCH DAMAGE. |
---|
25 | * |
---|
26 | * $FreeBSD: src/lib/libc/locale/setlocale.h,v 1.4 2001/12/20 18:28:52 phantom Exp $ |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef _SETLOCALE_H_ |
---|
30 | #define _SETLOCALE_H_ |
---|
31 | |
---|
32 | #include <_ansi.h> |
---|
33 | #include <sys/cdefs.h> |
---|
34 | #include <limits.h> |
---|
35 | #include <string.h> |
---|
36 | #include <stdlib.h> |
---|
37 | #include <wchar.h> |
---|
38 | #include <locale.h> |
---|
39 | |
---|
40 | __BEGIN_DECLS |
---|
41 | |
---|
42 | #define ENCODING_LEN 31 |
---|
43 | #define CATEGORY_LEN 11 |
---|
44 | #define _LC_LAST 7 |
---|
45 | |
---|
46 | #ifdef __CYGWIN__ |
---|
47 | struct lc_collate_T |
---|
48 | { |
---|
49 | __uint32_t lcid; |
---|
50 | int (*mbtowc) (struct _reent *, wchar_t *, const char *, size_t, |
---|
51 | mbstate_t *); |
---|
52 | char codeset[ENCODING_LEN + 1]; |
---|
53 | }; |
---|
54 | extern const struct lc_collate_T _C_collate_locale; |
---|
55 | #endif |
---|
56 | |
---|
57 | struct lc_ctype_T |
---|
58 | { |
---|
59 | const char *codeset; /* codeset for mbtowc conversion */ |
---|
60 | const char *mb_cur_max; |
---|
61 | #ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
---|
62 | const char *outdigits[10]; |
---|
63 | const wchar_t *woutdigits[10]; |
---|
64 | #endif |
---|
65 | }; |
---|
66 | extern const struct lc_ctype_T _C_ctype_locale; |
---|
67 | |
---|
68 | struct lc_monetary_T |
---|
69 | { |
---|
70 | const char *int_curr_symbol; |
---|
71 | const char *currency_symbol; |
---|
72 | const char *mon_decimal_point; |
---|
73 | const char *mon_thousands_sep; |
---|
74 | const char *mon_grouping; |
---|
75 | const char *positive_sign; |
---|
76 | const char *negative_sign; |
---|
77 | const char *int_frac_digits; |
---|
78 | const char *frac_digits; |
---|
79 | const char *p_cs_precedes; |
---|
80 | const char *p_sep_by_space; |
---|
81 | const char *n_cs_precedes; |
---|
82 | const char *n_sep_by_space; |
---|
83 | const char *p_sign_posn; |
---|
84 | const char *n_sign_posn; |
---|
85 | #ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
---|
86 | const char *int_p_cs_precedes; |
---|
87 | const char *int_p_sep_by_space; |
---|
88 | const char *int_n_cs_precedes; |
---|
89 | const char *int_n_sep_by_space; |
---|
90 | const char *int_p_sign_posn; |
---|
91 | const char *int_n_sign_posn; |
---|
92 | const char *codeset; /* codeset for mbtowc conversion */ |
---|
93 | const wchar_t *wint_curr_symbol; |
---|
94 | const wchar_t *wcurrency_symbol; |
---|
95 | const wchar_t *wmon_decimal_point; |
---|
96 | const wchar_t *wmon_thousands_sep; |
---|
97 | const wchar_t *wpositive_sign; |
---|
98 | const wchar_t *wnegative_sign; |
---|
99 | #endif |
---|
100 | }; |
---|
101 | extern const struct lc_monetary_T _C_monetary_locale; |
---|
102 | |
---|
103 | struct lc_numeric_T |
---|
104 | { |
---|
105 | const char *decimal_point; |
---|
106 | const char *thousands_sep; |
---|
107 | const char *grouping; |
---|
108 | #ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
---|
109 | const char *codeset; /* codeset for mbtowc conversion */ |
---|
110 | const wchar_t *wdecimal_point; |
---|
111 | const wchar_t *wthousands_sep; |
---|
112 | #endif |
---|
113 | }; |
---|
114 | extern const struct lc_numeric_T _C_numeric_locale; |
---|
115 | |
---|
116 | struct lc_time_T |
---|
117 | { |
---|
118 | const char *mon[12]; |
---|
119 | const char *month[12]; |
---|
120 | const char *wday[7]; |
---|
121 | const char *weekday[7]; |
---|
122 | const char *X_fmt; |
---|
123 | const char *x_fmt; |
---|
124 | const char *c_fmt; |
---|
125 | const char *am_pm[2]; |
---|
126 | const char *date_fmt; |
---|
127 | const char *alt_month[12]; /* unused */ |
---|
128 | const char *md_order; |
---|
129 | const char *ampm_fmt; |
---|
130 | const char *era; |
---|
131 | const char *era_d_fmt; |
---|
132 | const char *era_d_t_fmt; |
---|
133 | const char *era_t_fmt; |
---|
134 | const char *alt_digits; |
---|
135 | #ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
---|
136 | const char *codeset; /* codeset for mbtowc conversion */ |
---|
137 | const wchar_t *wmon[12]; |
---|
138 | const wchar_t *wmonth[12]; |
---|
139 | const wchar_t *wwday[7]; |
---|
140 | const wchar_t *wweekday[7]; |
---|
141 | const wchar_t *wX_fmt; |
---|
142 | const wchar_t *wx_fmt; |
---|
143 | const wchar_t *wc_fmt; |
---|
144 | const wchar_t *wam_pm[2]; |
---|
145 | const wchar_t *wdate_fmt; |
---|
146 | const wchar_t *wampm_fmt; |
---|
147 | const wchar_t *wera; |
---|
148 | const wchar_t *wera_d_fmt; |
---|
149 | const wchar_t *wera_d_t_fmt; |
---|
150 | const wchar_t *wera_t_fmt; |
---|
151 | const wchar_t *walt_digits; |
---|
152 | #endif |
---|
153 | }; |
---|
154 | extern const struct lc_time_T _C_time_locale; |
---|
155 | |
---|
156 | struct lc_messages_T |
---|
157 | { |
---|
158 | const char *yesexpr; |
---|
159 | const char *noexpr; |
---|
160 | const char *yesstr; |
---|
161 | const char *nostr; |
---|
162 | #ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
---|
163 | const char *codeset; /* codeset for mbtowc conversion */ |
---|
164 | const wchar_t *wyesexpr; |
---|
165 | const wchar_t *wnoexpr; |
---|
166 | const wchar_t *wyesstr; |
---|
167 | const wchar_t *wnostr; |
---|
168 | #endif |
---|
169 | }; |
---|
170 | extern const struct lc_messages_T _C_messages_locale; |
---|
171 | |
---|
172 | struct __lc_cats |
---|
173 | { |
---|
174 | const void *ptr; |
---|
175 | char *buf; |
---|
176 | }; |
---|
177 | |
---|
178 | struct __locale_t |
---|
179 | { |
---|
180 | char categories[_LC_LAST][ENCODING_LEN + 1]; |
---|
181 | int (*wctomb) (struct _reent *, char *, wchar_t, |
---|
182 | mbstate_t *); |
---|
183 | int (*mbtowc) (struct _reent *, wchar_t *, |
---|
184 | const char *, size_t, mbstate_t *); |
---|
185 | int cjk_lang; |
---|
186 | char *ctype_ptr; |
---|
187 | struct lconv lconv; |
---|
188 | #ifndef __HAVE_LOCALE_INFO__ |
---|
189 | char mb_cur_max[2]; |
---|
190 | char ctype_codeset[ENCODING_LEN + 1]; |
---|
191 | char message_codeset[ENCODING_LEN + 1]; |
---|
192 | #else |
---|
193 | struct __lc_cats lc_cat[_LC_LAST]; |
---|
194 | #endif |
---|
195 | }; |
---|
196 | |
---|
197 | #ifdef _MB_CAPABLE |
---|
198 | extern char *__loadlocale (struct __locale_t *, int, const char *); |
---|
199 | extern const char *__get_locale_env(struct _reent *, int); |
---|
200 | #endif /* _MB_CAPABLE */ |
---|
201 | |
---|
202 | extern struct lconv *__localeconv_l (struct __locale_t *locale); |
---|
203 | |
---|
204 | extern size_t _wcsnrtombs_l (struct _reent *, char *, const wchar_t **, |
---|
205 | size_t, size_t, mbstate_t *, struct __locale_t *); |
---|
206 | |
---|
207 | /* In POSIX terms the global locale is the process-wide locale. Use this |
---|
208 | function to always refer to the global locale. */ |
---|
209 | _ELIDABLE_INLINE struct __locale_t * |
---|
210 | __get_global_locale () |
---|
211 | { |
---|
212 | extern struct __locale_t __global_locale; |
---|
213 | return &__global_locale; |
---|
214 | } |
---|
215 | |
---|
216 | /* Per REENT locale. This is newlib-internal. */ |
---|
217 | _ELIDABLE_INLINE struct __locale_t * |
---|
218 | __get_locale_r (struct _reent *r) |
---|
219 | { |
---|
220 | return r->_locale; |
---|
221 | } |
---|
222 | |
---|
223 | /* In POSIX terms the current locale is the locale used by all functions |
---|
224 | using locale info without providing a locale as parameter (*_l functions). |
---|
225 | The current locale is either the locale of the current thread, if the |
---|
226 | thread called uselocale, or the global locale if not. */ |
---|
227 | _ELIDABLE_INLINE struct __locale_t * |
---|
228 | __get_current_locale (void) |
---|
229 | { |
---|
230 | return _REENT->_locale ?: __get_global_locale (); |
---|
231 | } |
---|
232 | |
---|
233 | /* Only access fixed "C" locale using this function. Fake for !_MB_CAPABLE |
---|
234 | targets by returning ptr to globale locale. */ |
---|
235 | _ELIDABLE_INLINE struct __locale_t * |
---|
236 | __get_C_locale (void) |
---|
237 | { |
---|
238 | #ifndef _MB_CAPABLE |
---|
239 | return __get_global_locale (); |
---|
240 | #else |
---|
241 | extern const struct __locale_t __C_locale; |
---|
242 | return (struct __locale_t *) &__C_locale; |
---|
243 | #endif |
---|
244 | } |
---|
245 | |
---|
246 | #ifdef __CYGWIN__ |
---|
247 | _ELIDABLE_INLINE const struct lc_collate_T * |
---|
248 | __get_collate_locale (struct __locale_t *locale) |
---|
249 | { |
---|
250 | return (const struct lc_collate_T *) locale->lc_cat[LC_COLLATE].ptr; |
---|
251 | } |
---|
252 | |
---|
253 | _ELIDABLE_INLINE const struct lc_collate_T * |
---|
254 | __get_current_collate_locale (void) |
---|
255 | { |
---|
256 | return (const struct lc_collate_T *) |
---|
257 | __get_current_locale ()->lc_cat[LC_COLLATE].ptr; |
---|
258 | } |
---|
259 | #endif |
---|
260 | |
---|
261 | #ifdef __HAVE_LOCALE_INFO__ |
---|
262 | _ELIDABLE_INLINE const struct lc_ctype_T * |
---|
263 | __get_ctype_locale (struct __locale_t *locale) |
---|
264 | { |
---|
265 | return (const struct lc_ctype_T *) (locale)->lc_cat[LC_CTYPE].ptr; |
---|
266 | } |
---|
267 | |
---|
268 | _ELIDABLE_INLINE const struct lc_ctype_T * |
---|
269 | __get_current_ctype_locale (void) |
---|
270 | { |
---|
271 | return (const struct lc_ctype_T *) |
---|
272 | __get_current_locale ()->lc_cat[LC_CTYPE].ptr; |
---|
273 | } |
---|
274 | #endif |
---|
275 | |
---|
276 | _ELIDABLE_INLINE int |
---|
277 | __locale_mb_cur_max_l (struct __locale_t *locale) |
---|
278 | { |
---|
279 | #ifdef __HAVE_LOCALE_INFO__ |
---|
280 | return __get_ctype_locale (locale)->mb_cur_max[0]; |
---|
281 | #else |
---|
282 | return locale->mb_cur_max[0]; |
---|
283 | #endif |
---|
284 | } |
---|
285 | |
---|
286 | #ifdef __HAVE_LOCALE_INFO__ |
---|
287 | _ELIDABLE_INLINE const struct lc_monetary_T * |
---|
288 | __get_monetary_locale (struct __locale_t *locale) |
---|
289 | { |
---|
290 | return (const struct lc_monetary_T *) (locale)->lc_cat[LC_MONETARY].ptr; |
---|
291 | } |
---|
292 | |
---|
293 | _ELIDABLE_INLINE const struct lc_monetary_T * |
---|
294 | __get_current_monetary_locale (void) |
---|
295 | { |
---|
296 | return (const struct lc_monetary_T *) |
---|
297 | __get_current_locale ()->lc_cat[LC_MONETARY].ptr; |
---|
298 | } |
---|
299 | |
---|
300 | _ELIDABLE_INLINE const struct lc_numeric_T * |
---|
301 | __get_numeric_locale (struct __locale_t *locale) |
---|
302 | { |
---|
303 | return (const struct lc_numeric_T *) (locale)->lc_cat[LC_NUMERIC].ptr; |
---|
304 | } |
---|
305 | |
---|
306 | _ELIDABLE_INLINE const struct lc_numeric_T * |
---|
307 | __get_current_numeric_locale (void) |
---|
308 | { |
---|
309 | return (const struct lc_numeric_T *) |
---|
310 | __get_current_locale ()->lc_cat[LC_NUMERIC].ptr; |
---|
311 | } |
---|
312 | |
---|
313 | _ELIDABLE_INLINE const struct lc_time_T * |
---|
314 | __get_time_locale (struct __locale_t *locale) |
---|
315 | { |
---|
316 | return (const struct lc_time_T *) (locale)->lc_cat[LC_TIME].ptr; |
---|
317 | } |
---|
318 | |
---|
319 | _ELIDABLE_INLINE const struct lc_time_T * |
---|
320 | __get_current_time_locale (void) |
---|
321 | { |
---|
322 | return (const struct lc_time_T *) |
---|
323 | __get_current_locale ()->lc_cat[LC_TIME].ptr; |
---|
324 | } |
---|
325 | |
---|
326 | _ELIDABLE_INLINE const struct lc_messages_T * |
---|
327 | __get_messages_locale (struct __locale_t *locale) |
---|
328 | { |
---|
329 | return (const struct lc_messages_T *) (locale)->lc_cat[LC_MESSAGES].ptr; |
---|
330 | } |
---|
331 | |
---|
332 | _ELIDABLE_INLINE const struct lc_messages_T * |
---|
333 | __get_current_messages_locale (void) |
---|
334 | { |
---|
335 | return (const struct lc_messages_T *) |
---|
336 | __get_current_locale ()->lc_cat[LC_MESSAGES].ptr; |
---|
337 | } |
---|
338 | #else /* ! __HAVE_LOCALE_INFO__ */ |
---|
339 | _ELIDABLE_INLINE const struct lc_monetary_T * |
---|
340 | __get_monetary_locale (struct __locale_t *locale) |
---|
341 | { |
---|
342 | return &_C_monetary_locale; |
---|
343 | } |
---|
344 | |
---|
345 | _ELIDABLE_INLINE const struct lc_monetary_T * |
---|
346 | __get_current_monetary_locale (void) |
---|
347 | { |
---|
348 | return &_C_monetary_locale; |
---|
349 | } |
---|
350 | |
---|
351 | _ELIDABLE_INLINE const struct lc_numeric_T * |
---|
352 | __get_numeric_locale (struct __locale_t *locale) |
---|
353 | { |
---|
354 | return &_C_numeric_locale; |
---|
355 | } |
---|
356 | |
---|
357 | _ELIDABLE_INLINE const struct lc_numeric_T * |
---|
358 | __get_current_numeric_locale (void) |
---|
359 | { |
---|
360 | return &_C_numeric_locale; |
---|
361 | } |
---|
362 | |
---|
363 | _ELIDABLE_INLINE const struct lc_time_T * |
---|
364 | __get_time_locale (struct __locale_t *locale) |
---|
365 | { |
---|
366 | return &_C_time_locale; |
---|
367 | } |
---|
368 | |
---|
369 | _ELIDABLE_INLINE const struct lc_time_T * |
---|
370 | __get_current_time_locale (void) |
---|
371 | { |
---|
372 | return &_C_time_locale; |
---|
373 | } |
---|
374 | |
---|
375 | _ELIDABLE_INLINE const struct lc_messages_T * |
---|
376 | __get_messages_locale (struct __locale_t *locale) |
---|
377 | { |
---|
378 | return &_C_messages_locale; |
---|
379 | } |
---|
380 | |
---|
381 | _ELIDABLE_INLINE const struct lc_messages_T * |
---|
382 | __get_current_messages_locale (void) |
---|
383 | { |
---|
384 | return &_C_messages_locale; |
---|
385 | } |
---|
386 | #endif /* !__HAVE_LOCALE_INFO__ */ |
---|
387 | |
---|
388 | _ELIDABLE_INLINE const char * |
---|
389 | __locale_charset (struct __locale_t *locale) |
---|
390 | { |
---|
391 | #ifdef __HAVE_LOCALE_INFO__ |
---|
392 | return __get_ctype_locale (locale)->codeset; |
---|
393 | #else |
---|
394 | return locale->ctype_codeset; |
---|
395 | #endif |
---|
396 | } |
---|
397 | |
---|
398 | _ELIDABLE_INLINE const char * |
---|
399 | __current_locale_charset (void) |
---|
400 | { |
---|
401 | #ifdef __HAVE_LOCALE_INFO__ |
---|
402 | return __get_current_ctype_locale ()->codeset; |
---|
403 | #else |
---|
404 | return __get_current_locale ()->ctype_codeset; |
---|
405 | #endif |
---|
406 | } |
---|
407 | |
---|
408 | _ELIDABLE_INLINE const char * |
---|
409 | __locale_msgcharset (void) |
---|
410 | { |
---|
411 | #ifdef __HAVE_LOCALE_INFO__ |
---|
412 | return (char *) __get_current_messages_locale ()->codeset; |
---|
413 | #else |
---|
414 | return (char *) __get_current_locale ()->message_codeset; |
---|
415 | #endif |
---|
416 | } |
---|
417 | |
---|
418 | _ELIDABLE_INLINE int |
---|
419 | __locale_cjk_lang (void) |
---|
420 | { |
---|
421 | return __get_current_locale ()->cjk_lang; |
---|
422 | } |
---|
423 | |
---|
424 | int __ctype_load_locale (struct __locale_t *, const char *, void *, |
---|
425 | const char *, int); |
---|
426 | int __monetary_load_locale (struct __locale_t *, const char *, void *, |
---|
427 | const char *); |
---|
428 | int __numeric_load_locale (struct __locale_t *, const char *, void *, |
---|
429 | const char *); |
---|
430 | int __time_load_locale (struct __locale_t *, const char *, void *, |
---|
431 | const char *); |
---|
432 | int __messages_load_locale (struct __locale_t *, const char *, void *, |
---|
433 | const char *); |
---|
434 | #ifdef __CYGWIN__ |
---|
435 | int __collate_load_locale (struct __locale_t *, const char *, void *, |
---|
436 | const char *); |
---|
437 | |
---|
438 | extern void __set_charset_from_locale (const char *locale, char *charset); |
---|
439 | extern char *__set_locale_from_locale_alias (const char *, char *); |
---|
440 | #endif |
---|
441 | |
---|
442 | __END_DECLS |
---|
443 | |
---|
444 | #endif /* !_SETLOCALE_H_ */ |
---|