OSDN Git Service

6273fa3921db46f06bd660313e356415dff37ced
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / common / bits / uClibc_locale.h
1 /*  Copyright (C) 2002, 2003     Manuel Novoa III
2  *
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.
7  *
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.
12  *
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
16  *  02111-1307 USA.
17  */
18
19 /*  ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION!
20  *
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.
26  *  Thanks.  Manuel
27  *
28  *  ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION! */
29
30 #ifndef _UCLIBC_LOCALE_H
31 #define _UCLIBC_LOCALE_H
32
33 /**********************************************************************/
34 /* uClibc compatibilty stuff */
35
36 #ifdef __UCLIBC_HAS_LOCALE__
37
38 # undef __LOCALE_C_ONLY
39
40 #else
41
42 # define __LOCALE_C_ONLY
43
44 # ifdef _LIBC
45 #  define __XL_NPP(N) N
46 #  define __LOCALE_PARAM
47 #  define __LOCALE_ARG
48 # endif
49
50 #endif
51
52 /**********************************************************************/
53
54 #define __NL_ITEM_CATEGORY_SHIFT        8
55 #define __NL_ITEM_INDEX_MASK            0xff
56
57 /* TODO: Make sure these agree with the locale mmap file gererator! */
58
59 #define __LC_CTYPE      0
60 #define __LC_NUMERIC    1
61 #define __LC_MONETARY   2
62 #define __LC_TIME       3
63 #define __LC_COLLATE    4
64 #define __LC_MESSAGES   5
65 #define __LC_ALL        6
66
67 /**********************************************************************/
68 #ifndef __LOCALE_C_ONLY
69
70 enum {
71         __ctype_encoding_7_bit,         /* C/POSIX */
72         __ctype_encoding_utf8,          /* UTF-8 */
73         __ctype_encoding_8_bit          /* for 8-bit codeset locales */
74 };
75
76 #define LOCALE_STRING_SIZE (2 * __LC_ALL + 2)
77
78  /*
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
83   *
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.
88   */
89
90 struct __uclibc_locale_struct;
91 typedef struct __uclibc_locale_struct *__locale_t;
92
93 #ifdef _LIBC
94
95 /* extern void _locale_set(const unsigned char *p); */
96 extern void weak_function _locale_init(void) attribute_hidden;
97
98 #include <stddef.h>
99 #include <stdint.h>
100 #include <bits/uClibc_touplow.h>
101 #ifndef __UCLIBC_GEN_LOCALE
102 # include <bits/uClibc_locale_data.h>
103 #endif
104
105 #ifndef __UCLIBC_GEN_LOCALE /* && (defined IS_IN_libc || defined NOT_IN_libc) */
106 typedef struct {
107         uint16_t num_weights;
108         uint16_t num_starters;
109         uint16_t ii_shift;
110         uint16_t ti_shift;
111         uint16_t ii_len;
112         uint16_t ti_len;
113         uint16_t max_weight;
114         uint16_t num_col_base;
115         uint16_t max_col_index;
116         uint16_t undefined_idx;
117         uint16_t range_low;
118         uint16_t range_count;
119         uint16_t range_base_weight;
120         uint16_t range_rule_offset; /* change name to index? */
121
122         uint16_t ii_mask;
123         uint16_t ti_mask;
124
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;
131
132         /*       uint16_t undefined_idx; */
133         const uint16_t *overrides_tbl;
134         /*       uint16_t *multistart_tbl; */
135
136         const uint16_t *weightstr;
137         const uint16_t *ruletable;
138
139
140         uint16_t *index2weight;
141         uint16_t *index2ruleidx;
142
143         uint16_t MAX_WEIGHTS;
144 } __collate_t;
145
146 /*  static unsigned char cur_locale[LOCALE_STRING_SIZE]; */
147
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;
153 #endif
154
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];
159
160 /*      int tables_loaded; */
161 /*      unsigned char lctypes[LOCALE_STRING_SIZE]; */
162         unsigned char cur_locale[LOCALE_STRING_SIZE];
163
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. */
167
168         uint16_t category_offsets[__LC_ALL]; /* TODO -- fix? */
169         unsigned char category_item_count[__LC_ALL]; /* TODO - fix */
170
171         /* ctype */
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];
175
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;
186         /* translit  */
187 # endif
188 #endif /* __CTYPE_HAS_8_BIT_LOCALES */
189 #ifdef __UCLIBC_HAS_WCHAR__
190
191         const uint16_t *code2flag;
192
193         const unsigned char *tblwctype;
194         const unsigned char *tblwuplow;
195 /*      const unsigned char *tblwcomb; */
196         const int16_t *tblwuplow_diff; /* yes... signed */
197         /* width?? */
198
199         wchar_t decimal_point_wc;
200         wchar_t thousands_sep_wc;
201         int decimal_point_len;
202         int thousands_sep_len;
203
204 #endif /* __UCLIBC_HAS_WCHAR__ */
205
206         /* ctype */
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!!! */
218
219         /* numeric */
220         const char *decimal_point;
221         const char *thousands_sep;
222         const char *grouping;
223
224         /* monetary */
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;
246
247         const char *crncystr;           /* not returned by localeconv */
248
249         /* time */
250         const char *abday_1;
251         const char *abday_2;
252         const char *abday_3;
253         const char *abday_4;
254         const char *abday_5;
255         const char *abday_6;
256         const char *abday_7;
257
258         const char *day_1;
259         const char *day_2;
260         const char *day_3;
261         const char *day_4;
262         const char *day_5;
263         const char *day_6;
264         const char *day_7;
265
266         const char *abmon_1;
267         const char *abmon_2;
268         const char *abmon_3;
269         const char *abmon_4;
270         const char *abmon_5;
271         const char *abmon_6;
272         const char *abmon_7;
273         const char *abmon_8;
274         const char *abmon_9;
275         const char *abmon_10;
276         const char *abmon_11;
277         const char *abmon_12;
278
279         const char *mon_1;
280         const char *mon_2;
281         const char *mon_3;
282         const char *mon_4;
283         const char *mon_5;
284         const char *mon_6;
285         const char *mon_7;
286         const char *mon_8;
287         const char *mon_9;
288         const char *mon_10;
289         const char *mon_11;
290         const char *mon_12;
291
292         const char *am_str;
293         const char *pm_str;
294
295         const char *d_t_fmt;
296         const char *d_fmt;
297         const char *t_fmt;
298         const char *t_fmt_ampm;
299         const char *era;
300
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;
306
307         /* messages */
308         const char *yesexpr;
309         const char *noexpr;
310         const char *yesstr;
311         const char *nostr;
312
313         /* collate is at the end */
314         __collate_t collate;
315 };
316
317 extern struct __uclibc_locale_struct __global_locale_data;
318 extern struct __uclibc_locale_struct *__global_locale;
319 #endif /* !__UCLIBC_GEN_LOCALE */
320
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.
324  */
325 extern int __locale_mbrtowc_l(wchar_t *__restrict dst,
326                                 const char *__restrict src,
327                                 __locale_t loc) attribute_hidden;
328 #endif
329
330 #ifdef L_setlocale
331 /* so we only get the warning once... */
332 #warning need thread version of CUR_LOCALE!
333 #endif
334
335 /**********************************************************************/
336 #ifdef __UCLIBC_HAS_XLOCALE__
337
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())
345 # else
346 #  define __UCLIBC_CURLOCALE  (__curlocale_var)
347 # endif
348
349 #elif defined(__UCLIBC_HAS_LOCALE__)
350
351 # define __UCLIBC_CURLOCALE   (__global_locale)
352
353 #endif
354 /**********************************************************************/
355 #if defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE)
356
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
361
362 #else
363
364 # define __XL_NPP(N) N
365 # define __LOCALE_PARAM
366 # define __LOCALE_ARG
367 # define __LOCALE_PTR      __UCLIBC_CURLOCALE
368
369 #endif
370 /**********************************************************************/
371
372 #endif /* _LIBC */
373
374 #endif /* !defined(__LOCALE_C_ONLY) */
375
376 #endif /* _UCLIBC_LOCALE_H */