source: trunk/libs/newlib/src/newlib/libc/locale/setlocale.h @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 11.7 KB
Line 
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__
47struct 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};
54extern const struct lc_collate_T _C_collate_locale;
55#endif
56
57struct 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};
66extern const struct lc_ctype_T _C_ctype_locale;
67
68struct 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};
101extern const struct lc_monetary_T _C_monetary_locale;
102
103struct 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};
114extern const struct lc_numeric_T _C_numeric_locale;
115
116struct 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};
154extern const struct lc_time_T _C_time_locale;
155
156struct  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};
170extern const struct lc_messages_T _C_messages_locale;
171
172struct __lc_cats
173{
174  const void    *ptr;
175  char          *buf;
176};
177
178struct __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
198extern char *__loadlocale (struct __locale_t *, int, const char *);
199extern const char *__get_locale_env(struct _reent *, int);
200#endif /* _MB_CAPABLE */
201
202extern struct lconv *__localeconv_l (struct __locale_t *locale);
203
204extern 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
424int __ctype_load_locale (struct __locale_t *, const char *, void *,
425                         const char *, int);
426int __monetary_load_locale (struct __locale_t *, const char *, void *,
427                            const char *);
428int __numeric_load_locale (struct __locale_t *, const char *, void *,
429                           const char *);
430int __time_load_locale (struct __locale_t *, const char *, void *,
431                        const char *);
432int __messages_load_locale (struct __locale_t *, const char *, void *,
433                            const char *);
434#ifdef __CYGWIN__
435int __collate_load_locale (struct __locale_t *, const char *, void *,
436                           const char *);
437
438extern void __set_charset_from_locale (const char *locale, char *charset);
439extern char *__set_locale_from_locale_alias (const char *, char *);
440#endif
441
442__END_DECLS
443
444#endif /* !_SETLOCALE_H_ */
Note: See TracBrowser for help on using the repository browser.