1 /* Copyright (C) 2002, 2003 Manuel Novoa III
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * The GNU C Library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with the GNU C Library; if not, write to the Free
15 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 /* ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
21 * Besides uClibc, I'm using this code in my libc for elks, which is
22 * a 16-bit environment with a fairly limited compiler. It would make
23 * things much easier for me if this file isn't modified unnecessarily.
24 * In particular, please put any new or replacement functions somewhere
25 * else, and modify the makefile to use your version instead.
28 * ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! */
30 #ifndef _UCLIBC_LOCALE_H
31 #define _UCLIBC_LOCALE_H
33 /**********************************************************************/
34 /* uClibc compatibilty stuff */
36 #ifdef __UCLIBC_HAS_LOCALE__
38 #undef __LOCALE_C_ONLY
40 #else /* __UCLIBC_HAS_LOCALE__ */
42 #define __LOCALE_C_ONLY
45 #define __LOCALE_PARAM
48 #endif /* __UCLIBC_HAS_LOCALE__ */
50 /**********************************************************************/
52 #define __NL_ITEM_CATEGORY_SHIFT (8)
53 #define __NL_ITEM_INDEX_MASK (0xff)
55 /* TODO: Make sure these agree with the locale mmap file gererator! */
58 #define __LC_NUMERIC 1
59 #define __LC_MONETARY 2
61 #define __LC_COLLATE 4
62 #define __LC_MESSAGES 5
65 /**********************************************************************/
66 #ifndef __LOCALE_C_ONLY
68 #if defined _LIBC /* && (defined IS_IN_libc || defined NOT_IN_libc) */
71 #include <bits/uClibc_touplow.h>
73 #ifndef __UCLIBC_GEN_LOCALE
74 #include <bits/uClibc_locale_data.h>
78 /* extern void _locale_set(const unsigned char *p); */
79 /* extern void _locale_init(void); */
82 __ctype_encoding_7_bit, /* C/POSIX */
83 __ctype_encoding_utf8, /* UTF-8 */
84 __ctype_encoding_8_bit /* for 8-bit codeset locales */
87 #define LOCALE_STRING_SIZE (2 * __LC_ALL + 2)
90 * '#' + 2_per_category + '\0'
91 * {locale row # : 0 = C|POSIX} + 0x8001
92 * encoded in two chars as (((N+1) >> 8) | 0x80) and ((N+1) & 0xff)
93 * so decode is ((((uint16_t)(*s & 0x7f)) << 8) + s[1]) - 1
95 * Note: 0s are not used as they are nul-terminators for strings.
96 * Note: 0xff, 0xff is the encoding for a non-selected locale.
97 * (see setlocale() below).
98 * In particular, C/POSIX locale is '#' + "\x80\x01"}*LC_ALL + nul.
101 #if defined _LIBC && !defined __UCLIBC_GEN_LOCALE /* && (defined IS_IN_libc || defined NOT_IN_libc) */
103 uint16_t num_weights;
104 uint16_t num_starters;
110 uint16_t num_col_base;
111 uint16_t max_col_index;
112 uint16_t undefined_idx;
114 uint16_t range_count;
115 uint16_t range_base_weight;
116 uint16_t range_rule_offset; /* change name to index? */
121 const uint16_t *index2weight_tbl;
122 const uint16_t *index2ruleidx_tbl;
123 const uint16_t *multistart_tbl;
124 /* uint16_t wcs2colidt_offset_low; */
125 /* uint16_t wcs2colidt_offset_hi; */
126 const uint16_t *wcs2colidt_tbl;
128 /* uint16_t undefined_idx; */
129 const uint16_t *overrides_tbl;
130 /* uint16_t *multistart_tbl; */
132 const uint16_t *weightstr;
133 const uint16_t *ruletable;
136 uint16_t *index2weight;
137 uint16_t *index2ruleidx;
139 uint16_t MAX_WEIGHTS;
143 /* static unsigned char cur_locale[LOCALE_STRING_SIZE]; */
145 typedef struct __uclibc_locale_struct {
146 #ifdef __UCLIBC_HAS_XLOCALE__
147 const __ctype_mask_t *__ctype_b;
148 const __ctype_touplow_t *__ctype_tolower;
149 const __ctype_touplow_t *__ctype_toupper;
152 /* For now, just embed this in the structure. */
153 __ctype_mask_t __ctype_b_data[256 + __UCLIBC_CTYPE_B_TBL_OFFSET];
154 __ctype_touplow_t __ctype_tolower_data[256 + __UCLIBC_CTYPE_TO_TBL_OFFSET];
155 __ctype_touplow_t __ctype_toupper_data[256 + __UCLIBC_CTYPE_TO_TBL_OFFSET];
157 /* int tables_loaded; */
158 /* unsigned char lctypes[LOCALE_STRING_SIZE]; */
159 unsigned char cur_locale[LOCALE_STRING_SIZE];
161 /* NL_LANGINFO stuff. BEWARE ORDERING!!! must agree with NL_* constants! */
162 /* Also, numeric must be followed by monetary and the items must be in
163 * the "struct lconv" order. */
165 uint16_t category_offsets[__LC_ALL]; /* TODO -- fix? */
166 unsigned char category_item_count[__LC_ALL]; /* TODO - fix */
169 unsigned char encoding; /* C/POSIX, 8-bit, UTF-8 */
170 unsigned char mb_cur_max; /* determined by encoding _AND_ translit!!! */
171 const unsigned char outdigit_length[10];
173 #ifdef __CTYPE_HAS_8_BIT_LOCALES
174 const unsigned char *idx8ctype;
175 const unsigned char *tbl8ctype;
176 const unsigned char *idx8uplow;
177 const unsigned char *tbl8uplow;
178 #ifdef __UCLIBC_HAS_WCHAR__
179 const unsigned char *idx8c2wc;
180 const uint16_t *tbl8c2wc; /* char > 0x7f to wide char */
181 const unsigned char *idx8wc2c;
182 const unsigned char *tbl8wc2c;
184 #endif /* __UCLIBC_HAS_WCHAR__ */
185 #endif /* __CTYPE_HAS_8_BIT_LOCALES */
186 #ifdef __UCLIBC_HAS_WCHAR__
188 const uint16_t *code2flag;
190 const unsigned char *tblwctype;
191 const unsigned char *tblwuplow;
192 /* const unsigned char *tblwcomb; */
193 const int16_t *tblwuplow_diff; /* yes... signed */
196 wchar_t decimal_point_wc;
197 wchar_t thousands_sep_wc;
198 int decimal_point_len;
199 int thousands_sep_len;
201 #endif /* __UCLIBC_HAS_WCHAR__ */
204 const char *outdigit0_mb;
205 const char *outdigit1_mb;
206 const char *outdigit2_mb;
207 const char *outdigit3_mb;
208 const char *outdigit4_mb;
209 const char *outdigit5_mb;
210 const char *outdigit6_mb;
211 const char *outdigit7_mb;
212 const char *outdigit8_mb;
213 const char *outdigit9_mb;
214 const char *codeset; /* MUST BE LAST!!! */
217 const char *decimal_point;
218 const char *thousands_sep;
219 const char *grouping;
222 const char *int_curr_symbol;
223 const char *currency_symbol;
224 const char *mon_decimal_point;
225 const char *mon_thousands_sep;
226 const char *mon_grouping;
227 const char *positive_sign;
228 const char *negative_sign;
229 const char *int_frac_digits;
230 const char *frac_digits;
231 const char *p_cs_precedes;
232 const char *p_sep_by_space;
233 const char *n_cs_precedes;
234 const char *n_sep_by_space;
235 const char *p_sign_posn;
236 const char *n_sign_posn;
237 const char *int_p_cs_precedes;
238 const char *int_p_sep_by_space;
239 const char *int_n_cs_precedes;
240 const char *int_n_sep_by_space;
241 const char *int_p_sign_posn;
242 const char *int_n_sign_posn;
244 const char *crncystr; /* not returned by localeconv */
272 const char *abmon_10;
273 const char *abmon_11;
274 const char *abmon_12;
295 const char *t_fmt_ampm;
298 const char *era_year; /* non SUSv3 */
299 const char *era_d_fmt;
300 const char *alt_digits;
301 const char *era_d_t_fmt;
302 const char *era_t_fmt;
304 /* collate is at the end */
312 /* collate is at the end */
317 extern __uclibc_locale_t __global_locale_data;
318 extern struct __uclibc_locale_struct * __global_locale;
321 typedef struct __uclibc_locale_struct *__locale_t;
323 /* if we need to leave only _LIBC, then attribute_hidden is not usable */
324 #if defined _LIBC && (defined IS_IN_libc || defined NOT_IN_libc)
325 extern int __locale_mbrtowc_l(wchar_t *__restrict dst,
326 const char *__restrict src,
327 __locale_t loc ) attribute_hidden;
331 /* so we only get the warning once... */
332 #warning need thread version of CUR_LOCALE!
334 /**********************************************************************/
335 #ifdef __UCLIBC_HAS_XLOCALE__
337 extern __locale_t __curlocale_var;
339 #ifdef __UCLIBC_HAS_THREADS__
341 extern __locale_t __curlocale(void) __THROW __attribute__ ((__const__));
342 extern __locale_t __curlocale_set(__locale_t newloc);
343 #define __UCLIBC_CURLOCALE (__curlocale())
344 #define __UCLIBC_CURLOCALE_DATA (*__curlocale())
346 #else /* __UCLIBC_HAS_THREADS__ */
348 #define __UCLIBC_CURLOCALE (__curlocale_var)
349 #define __UCLIBC_CURLOCALE_DATA (*__curlocale_var)
351 #endif /* __UCLIBC_HAS_THREADS__ */
353 #elif defined(__UCLIBC_HAS_LOCALE__)
355 #define __UCLIBC_CURLOCALE (__global_locale)
356 #define __UCLIBC_CURLOCALE_DATA (*__global_locale)
359 /**********************************************************************/
360 #if defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE)
362 #define __XL_NPP(N) N ## _l
363 #define __LOCALE_PARAM , __locale_t locale_arg
364 #define __LOCALE_ARG , locale_arg
365 #define __LOCALE_PTR locale_arg
367 #else /* defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE) */
369 #define __XL_NPP(N) N
370 #define __LOCALE_PARAM
372 #define __LOCALE_PTR __UCLIBC_CURLOCALE
374 #endif /* defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE) */
375 /**********************************************************************/
377 #endif /* !defined(__LOCALE_C_ONLY) */
378 /**********************************************************************/
380 #endif /* _UCLIBC_LOCALE_H */