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
42 # define __LOCALE_C_ONLY
45 # define __XL_NPP(N) N
46 # define __LOCALE_PARAM
52 /**********************************************************************/
54 #define __NL_ITEM_CATEGORY_SHIFT 8
55 #define __NL_ITEM_INDEX_MASK 0xff
57 /* TODO: Make sure these agree with the locale mmap file gererator! */
60 #define __LC_NUMERIC 1
61 #define __LC_MONETARY 2
63 #define __LC_COLLATE 4
64 #define __LC_MESSAGES 5
67 /**********************************************************************/
68 #ifndef __LOCALE_C_ONLY
71 __ctype_encoding_7_bit, /* C/POSIX */
72 __ctype_encoding_utf8, /* UTF-8 */
73 __ctype_encoding_8_bit /* for 8-bit codeset locales */
76 #define LOCALE_STRING_SIZE (2 * __LC_ALL + 2)
79 * '#' + 2_per_category + '\0'
80 * {locale row # : 0 = C|POSIX} + 0x8001
81 * encoded in two chars as (((N+1) >> 8) | 0x80) and ((N+1) & 0xff)
82 * so decode is ((((uint16_t)(*s & 0x7f)) << 8) + s[1]) - 1
84 * Note: 0s are not used as they are nul-terminators for strings.
85 * Note: 0xff, 0xff is the encoding for a non-selected locale.
86 * (see setlocale() below).
87 * In particular, C/POSIX locale is '#' + "\x80\x01"}*LC_ALL + nul.
90 struct __uclibc_locale_struct;
91 typedef struct __uclibc_locale_struct *__locale_t;
95 /* extern void _locale_set(const unsigned char *p); */
96 extern void weak_function _locale_init(void) attribute_hidden;
100 #include <bits/uClibc_touplow.h>
101 #ifndef __UCLIBC_GEN_LOCALE
102 # include <bits/uClibc_locale_data.h>
105 #ifndef __UCLIBC_GEN_LOCALE /* && (defined IS_IN_libc || defined NOT_IN_libc) */
107 uint16_t num_weights;
108 uint16_t num_starters;
114 uint16_t num_col_base;
115 uint16_t max_col_index;
116 uint16_t undefined_idx;
118 uint16_t range_count;
119 uint16_t range_base_weight;
120 uint16_t range_rule_offset; /* change name to index? */
125 const uint16_t *index2weight_tbl;
126 const uint16_t *index2ruleidx_tbl;
127 const uint16_t *multistart_tbl;
128 /* uint16_t wcs2colidt_offset_low; */
129 /* uint16_t wcs2colidt_offset_hi; */
130 const uint16_t *wcs2colidt_tbl;
132 /* uint16_t undefined_idx; */
133 const uint16_t *overrides_tbl;
134 /* uint16_t *multistart_tbl; */
136 const uint16_t *weightstr;
137 const uint16_t *ruletable;
140 uint16_t *index2weight;
141 uint16_t *index2ruleidx;
143 uint16_t MAX_WEIGHTS;
146 /* static unsigned char cur_locale[LOCALE_STRING_SIZE]; */
148 struct __uclibc_locale_struct {
149 #ifdef __UCLIBC_HAS_XLOCALE__
150 const __ctype_mask_t *__ctype_b;
151 const __ctype_touplow_t *__ctype_tolower;
152 const __ctype_touplow_t *__ctype_toupper;
155 /* For now, just embed this in the structure. */
156 __ctype_mask_t __ctype_b_data[256 + __UCLIBC_CTYPE_B_TBL_OFFSET];
157 __ctype_touplow_t __ctype_tolower_data[256 + __UCLIBC_CTYPE_TO_TBL_OFFSET];
158 __ctype_touplow_t __ctype_toupper_data[256 + __UCLIBC_CTYPE_TO_TBL_OFFSET];
160 /* int tables_loaded; */
161 /* unsigned char lctypes[LOCALE_STRING_SIZE]; */
162 unsigned char cur_locale[LOCALE_STRING_SIZE];
164 /* NL_LANGINFO stuff. BEWARE ORDERING!!! must agree with NL_* constants! */
165 /* Also, numeric must be followed by monetary and the items must be in
166 * the "struct lconv" order. */
168 uint16_t category_offsets[__LC_ALL]; /* TODO -- fix? */
169 unsigned char category_item_count[__LC_ALL]; /* TODO - fix */
172 unsigned char encoding; /* C/POSIX, 8-bit, UTF-8 */
173 unsigned char mb_cur_max; /* determined by encoding _AND_ translit!!! */
174 const unsigned char outdigit_length[10];
176 #ifdef __CTYPE_HAS_8_BIT_LOCALES
177 const unsigned char *idx8ctype;
178 const unsigned char *tbl8ctype;
179 const unsigned char *idx8uplow;
180 const unsigned char *tbl8uplow;
181 # ifdef __UCLIBC_HAS_WCHAR__
182 const unsigned char *idx8c2wc;
183 const uint16_t *tbl8c2wc; /* char > 0x7f to wide char */
184 const unsigned char *idx8wc2c;
185 const unsigned char *tbl8wc2c;
188 #endif /* __CTYPE_HAS_8_BIT_LOCALES */
189 #ifdef __UCLIBC_HAS_WCHAR__
191 const uint16_t *code2flag;
193 const unsigned char *tblwctype;
194 const unsigned char *tblwuplow;
195 /* const unsigned char *tblwcomb; */
196 const int16_t *tblwuplow_diff; /* yes... signed */
199 wchar_t decimal_point_wc;
200 wchar_t thousands_sep_wc;
201 int decimal_point_len;
202 int thousands_sep_len;
204 #endif /* __UCLIBC_HAS_WCHAR__ */
207 const char *outdigit0_mb;
208 const char *outdigit1_mb;
209 const char *outdigit2_mb;
210 const char *outdigit3_mb;
211 const char *outdigit4_mb;
212 const char *outdigit5_mb;
213 const char *outdigit6_mb;
214 const char *outdigit7_mb;
215 const char *outdigit8_mb;
216 const char *outdigit9_mb;
217 const char *codeset; /* MUST BE LAST!!! */
220 const char *decimal_point;
221 const char *thousands_sep;
222 const char *grouping;
225 const char *int_curr_symbol;
226 const char *currency_symbol;
227 const char *mon_decimal_point;
228 const char *mon_thousands_sep;
229 const char *mon_grouping;
230 const char *positive_sign;
231 const char *negative_sign;
232 const char *int_frac_digits;
233 const char *frac_digits;
234 const char *p_cs_precedes;
235 const char *p_sep_by_space;
236 const char *n_cs_precedes;
237 const char *n_sep_by_space;
238 const char *p_sign_posn;
239 const char *n_sign_posn;
240 const char *int_p_cs_precedes;
241 const char *int_p_sep_by_space;
242 const char *int_n_cs_precedes;
243 const char *int_n_sep_by_space;
244 const char *int_p_sign_posn;
245 const char *int_n_sign_posn;
247 const char *crncystr; /* not returned by localeconv */
275 const char *abmon_10;
276 const char *abmon_11;
277 const char *abmon_12;
298 const char *t_fmt_ampm;
301 const char *era_year; /* non SUSv3 */
302 const char *era_d_fmt;
303 const char *alt_digits;
304 const char *era_d_t_fmt;
305 const char *era_t_fmt;
313 /* collate is at the end */
317 extern struct __uclibc_locale_struct __global_locale_data;
318 extern struct __uclibc_locale_struct *__global_locale;
319 #endif /* !__UCLIBC_GEN_LOCALE */
321 #if defined IS_IN_libc || defined NOT_IN_libc
322 /* If you plan to remove xxx_IN_libc guards,
323 * remove attribute_hidden, it won't work.
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!
335 /**********************************************************************/
336 #ifdef __UCLIBC_HAS_XLOCALE__
338 extern __locale_t __curlocale_var;
339 # ifdef __UCLIBC_HAS_THREADS__
340 extern __locale_t __curlocale(void) __THROW __attribute__ ((__const__));
341 libc_hidden_proto(__curlocale)
342 extern __locale_t __curlocale_set(__locale_t newloc);
343 libc_hidden_proto(__curlocale_set)
344 # define __UCLIBC_CURLOCALE (__curlocale())
346 # define __UCLIBC_CURLOCALE (__curlocale_var)
349 #elif defined(__UCLIBC_HAS_LOCALE__)
351 # define __UCLIBC_CURLOCALE (__global_locale)
354 /**********************************************************************/
355 #if defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE)
357 # define __XL_NPP(N) N ## _l
358 # define __LOCALE_PARAM , __locale_t locale_arg
359 # define __LOCALE_ARG , locale_arg
360 # define __LOCALE_PTR locale_arg
364 # define __XL_NPP(N) N
365 # define __LOCALE_PARAM
366 # define __LOCALE_ARG
367 # define __LOCALE_PTR __UCLIBC_CURLOCALE
370 /**********************************************************************/
374 #endif /* !defined(__LOCALE_C_ONLY) */
376 #endif /* _UCLIBC_LOCALE_H */