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; see the file COPYING.LIB. If
15 * not, see <http://www.gnu.org/licenses/>.
18 /* ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
20 * Besides uClibc, I'm using this code in my libc for elks, which is
21 * a 16-bit environment with a fairly limited compiler. It would make
22 * things much easier for me if this file isn't modified unnecessarily.
23 * In particular, please put any new or replacement functions somewhere
24 * else, and modify the makefile to use your version instead.
27 * ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! */
29 #ifndef _UCLIBC_LOCALE_H
30 #define _UCLIBC_LOCALE_H
32 /**********************************************************************/
33 /* uClibc compatibilty stuff */
35 #ifdef __UCLIBC_HAS_LOCALE__
37 # undef __LOCALE_C_ONLY
41 # define __LOCALE_C_ONLY
44 # define __XL_NPP(N) N
45 # define __LOCALE_PARAM
51 /**********************************************************************/
53 #define __NL_ITEM_CATEGORY_SHIFT 8
54 #define __NL_ITEM_INDEX_MASK 0xff
56 /* TODO: Make sure these agree with the locale mmap file gererator! */
59 #define __LC_NUMERIC 1
60 #define __LC_MONETARY 2
62 #define __LC_COLLATE 4
63 #define __LC_MESSAGES 5
66 /**********************************************************************/
67 #ifndef __LOCALE_C_ONLY
70 __ctype_encoding_7_bit, /* C/POSIX */
71 __ctype_encoding_utf8, /* UTF-8 */
72 __ctype_encoding_8_bit /* for 8-bit codeset locales */
75 #define LOCALE_STRING_SIZE (2 * __LC_ALL + 2)
78 * '#' + 2_per_category + '\0'
79 * {locale row # : 0 = C|POSIX} + 0x8001
80 * encoded in two chars as (((N+1) >> 8) | 0x80) and ((N+1) & 0xff)
81 * so decode is ((((uint16_t)(*s & 0x7f)) << 8) + s[1]) - 1
83 * Note: 0s are not used as they are nul-terminators for strings.
84 * Note: 0xff, 0xff is the encoding for a non-selected locale.
85 * (see setlocale() below).
86 * In particular, C/POSIX locale is '#' + "\x80\x01"}*LC_ALL + nul.
89 struct __uclibc_locale_struct;
90 typedef struct __uclibc_locale_struct *__locale_t;
94 /* extern void _locale_set(const unsigned char *p); */
95 extern void weak_function _locale_init(void) attribute_hidden;
99 #include <bits/uClibc_touplow.h>
100 #ifndef __UCLIBC_GEN_LOCALE
101 # include <bits/uClibc_locale_data.h>
104 #ifndef __UCLIBC_GEN_LOCALE /* && (defined IS_IN_libc || defined NOT_IN_libc) */
106 uint16_t num_weights;
107 uint16_t num_starters;
113 uint16_t num_col_base;
114 uint16_t max_col_index;
115 uint16_t undefined_idx;
117 uint16_t range_count;
118 uint16_t range_base_weight;
119 uint16_t range_rule_offset; /* change name to index? */
124 const uint16_t *index2weight_tbl;
125 const uint16_t *index2ruleidx_tbl;
126 const uint16_t *multistart_tbl;
127 /* uint16_t wcs2colidt_offset_low; */
128 /* uint16_t wcs2colidt_offset_hi; */
129 const uint16_t *wcs2colidt_tbl;
131 /* uint16_t undefined_idx; */
132 const uint16_t *overrides_tbl;
133 /* uint16_t *multistart_tbl; */
135 const uint16_t *weightstr;
136 const uint16_t *ruletable;
139 uint16_t *index2weight;
140 uint16_t *index2ruleidx;
142 uint16_t MAX_WEIGHTS;
145 /* static unsigned char cur_locale[LOCALE_STRING_SIZE]; */
147 struct __uclibc_locale_struct {
148 #ifdef __UCLIBC_HAS_XLOCALE__
149 const __ctype_mask_t *__ctype_b;
150 const __ctype_touplow_t *__ctype_tolower;
151 const __ctype_touplow_t *__ctype_toupper;
154 /* For now, just embed this in the structure. */
155 __ctype_mask_t __ctype_b_data[256 + __UCLIBC_CTYPE_B_TBL_OFFSET];
156 __ctype_touplow_t __ctype_tolower_data[256 + __UCLIBC_CTYPE_TO_TBL_OFFSET];
157 __ctype_touplow_t __ctype_toupper_data[256 + __UCLIBC_CTYPE_TO_TBL_OFFSET];
159 /* int tables_loaded; */
160 /* unsigned char lctypes[LOCALE_STRING_SIZE]; */
161 unsigned char cur_locale[LOCALE_STRING_SIZE];
163 /* NL_LANGINFO stuff. BEWARE ORDERING!!! must agree with NL_* constants! */
164 /* Also, numeric must be followed by monetary and the items must be in
165 * the "struct lconv" order. */
167 uint16_t category_offsets[__LC_ALL]; /* TODO -- fix? */
168 unsigned char category_item_count[__LC_ALL]; /* TODO - fix */
171 unsigned char encoding; /* C/POSIX, 8-bit, UTF-8 */
172 unsigned char mb_cur_max; /* determined by encoding _AND_ translit!!! */
173 const unsigned char outdigit_length[10];
175 #ifdef __CTYPE_HAS_8_BIT_LOCALES
176 const unsigned char *idx8ctype;
177 const unsigned char *tbl8ctype;
178 const unsigned char *idx8uplow;
179 const unsigned char *tbl8uplow;
180 # ifdef __UCLIBC_HAS_WCHAR__
181 const unsigned char *idx8c2wc;
182 const uint16_t *tbl8c2wc; /* char > 0x7f to wide char */
183 const unsigned char *idx8wc2c;
184 const unsigned char *tbl8wc2c;
187 #endif /* __CTYPE_HAS_8_BIT_LOCALES */
188 #ifdef __UCLIBC_HAS_WCHAR__
190 const uint16_t *code2flag;
192 const unsigned char *tblwctype;
193 const unsigned char *tblwuplow;
194 /* const unsigned char *tblwcomb; */
195 const int16_t *tblwuplow_diff; /* yes... signed */
198 wchar_t decimal_point_wc;
199 wchar_t thousands_sep_wc;
200 int decimal_point_len;
201 int thousands_sep_len;
203 #endif /* __UCLIBC_HAS_WCHAR__ */
206 const char *outdigit0_mb;
207 const char *outdigit1_mb;
208 const char *outdigit2_mb;
209 const char *outdigit3_mb;
210 const char *outdigit4_mb;
211 const char *outdigit5_mb;
212 const char *outdigit6_mb;
213 const char *outdigit7_mb;
214 const char *outdigit8_mb;
215 const char *outdigit9_mb;
216 const char *codeset; /* MUST BE LAST!!! */
219 const char *decimal_point;
220 const char *thousands_sep;
221 const char *grouping;
224 const char *int_curr_symbol;
225 const char *currency_symbol;
226 const char *mon_decimal_point;
227 const char *mon_thousands_sep;
228 const char *mon_grouping;
229 const char *positive_sign;
230 const char *negative_sign;
231 const char *int_frac_digits;
232 const char *frac_digits;
233 const char *p_cs_precedes;
234 const char *p_sep_by_space;
235 const char *n_cs_precedes;
236 const char *n_sep_by_space;
237 const char *p_sign_posn;
238 const char *n_sign_posn;
239 const char *int_p_cs_precedes;
240 const char *int_p_sep_by_space;
241 const char *int_n_cs_precedes;
242 const char *int_n_sep_by_space;
243 const char *int_p_sign_posn;
244 const char *int_n_sign_posn;
246 const char *crncystr; /* not returned by localeconv */
274 const char *abmon_10;
275 const char *abmon_11;
276 const char *abmon_12;
297 const char *t_fmt_ampm;
300 const char *era_year; /* non SUSv3 */
301 const char *era_d_fmt;
302 const char *alt_digits;
303 const char *era_d_t_fmt;
304 const char *era_t_fmt;
312 /* collate is at the end */
316 extern struct __uclibc_locale_struct __global_locale_data;
317 extern struct __uclibc_locale_struct *__global_locale;
318 #endif /* !__UCLIBC_GEN_LOCALE */
320 #if defined IS_IN_libc || defined NOT_IN_libc
321 /* If you plan to remove xxx_IN_libc guards,
322 * remove attribute_hidden, it won't work.
324 extern int __locale_mbrtowc_l(wchar_t *__restrict dst,
325 const char *__restrict src,
326 __locale_t loc) attribute_hidden;
330 /* so we only get the warning once... */
331 #warning need thread version of CUR_LOCALE!
334 /**********************************************************************/
335 #ifdef __UCLIBC_HAS_XLOCALE__
337 extern __locale_t __curlocale_var;
338 # ifdef __UCLIBC_HAS_THREADS__
339 extern __locale_t __curlocale(void) __THROW __attribute__ ((__const__));
340 libc_hidden_proto(__curlocale)
341 extern __locale_t __curlocale_set(__locale_t newloc);
342 libc_hidden_proto(__curlocale_set)
343 # define __UCLIBC_CURLOCALE (__curlocale())
345 # define __UCLIBC_CURLOCALE (__curlocale_var)
348 #elif defined(__UCLIBC_HAS_LOCALE__)
350 # define __UCLIBC_CURLOCALE (__global_locale)
353 /**********************************************************************/
354 #if defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE)
356 # define __XL_NPP(N) N ## _l
357 # define __LOCALE_PARAM , __locale_t locale_arg
358 # define __LOCALE_ARG , locale_arg
359 # define __LOCALE_PTR locale_arg
363 # define __XL_NPP(N) N
364 # define __LOCALE_PARAM
365 # define __LOCALE_ARG
366 # define __LOCALE_PTR __UCLIBC_CURLOCALE
369 /**********************************************************************/
373 #endif /* !defined(__LOCALE_C_ONLY) */
375 #endif /* _UCLIBC_LOCALE_H */