OSDN Git Service

- trim any trailing whitespace
[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  /* __UCLIBC_HAS_LOCALE__ */
41
42 #define __LOCALE_C_ONLY
43
44 #define __XL_NPP(N) N
45 #define __LOCALE_PARAM
46 #define __LOCALE_ARG
47
48 #endif /* __UCLIBC_HAS_LOCALE__ */
49
50 /**********************************************************************/
51
52 #define __NL_ITEM_CATEGORY_SHIFT                (8)
53 #define __NL_ITEM_INDEX_MASK                    (0xff)
54
55 /* TODO: Make sure these agree with the locale mmap file gererator! */
56
57 #define __LC_CTYPE                      0
58 #define __LC_NUMERIC            1
59 #define __LC_MONETARY           2
60 #define __LC_TIME                       3
61 #define __LC_COLLATE            4
62 #define __LC_MESSAGES           5
63 #define __LC_ALL                        6
64
65 /**********************************************************************/
66 #ifndef __LOCALE_C_ONLY
67
68 #if defined _LIBC /* && (defined IS_IN_libc || defined NOT_IN_libc) */
69 #include <stddef.h>
70 #include <stdint.h>
71 #include <bits/uClibc_touplow.h>
72
73 #ifndef __UCLIBC_GEN_LOCALE
74 #include <bits/uClibc_locale_data.h>
75 #endif
76 #endif
77
78 /* extern void _locale_set(const unsigned char *p); */
79 /* extern void _locale_init(void); */
80
81 enum {
82         __ctype_encoding_7_bit,         /* C/POSIX */
83         __ctype_encoding_utf8,          /* UTF-8 */
84         __ctype_encoding_8_bit          /* for 8-bit codeset locales */
85 };
86
87 #define LOCALE_STRING_SIZE (2 * __LC_ALL + 2)
88
89  /*
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
94   *
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.
99   */
100
101 #if defined _LIBC && !defined __UCLIBC_GEN_LOCALE /* && (defined IS_IN_libc || defined NOT_IN_libc) */
102 typedef struct {
103         uint16_t num_weights;
104         uint16_t num_starters;
105         uint16_t ii_shift;
106         uint16_t ti_shift;
107         uint16_t ii_len;
108         uint16_t ti_len;
109         uint16_t max_weight;
110         uint16_t num_col_base;
111         uint16_t max_col_index;
112         uint16_t undefined_idx;
113         uint16_t range_low;
114         uint16_t range_count;
115         uint16_t range_base_weight;
116         uint16_t range_rule_offset; /* change name to index? */
117
118         uint16_t ii_mask;
119         uint16_t ti_mask;
120
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;
127
128         /*       uint16_t undefined_idx; */
129         const uint16_t *overrides_tbl;
130         /*       uint16_t *multistart_tbl; */
131
132         const uint16_t *weightstr;
133         const uint16_t *ruletable;
134
135
136         uint16_t *index2weight;
137         uint16_t *index2ruleidx;
138
139         uint16_t MAX_WEIGHTS;
140 } __collate_t;
141
142
143 /*  static unsigned char cur_locale[LOCALE_STRING_SIZE]; */
144
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;
150 #endif
151
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];
156
157 /*      int tables_loaded; */
158 /*      unsigned char lctypes[LOCALE_STRING_SIZE]; */
159         unsigned char cur_locale[LOCALE_STRING_SIZE];
160
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. */
164
165         uint16_t category_offsets[__LC_ALL]; /* TODO -- fix? */
166         unsigned char category_item_count[__LC_ALL]; /* TODO - fix */
167
168         /* ctype */
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];
172
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;
183         /* translit  */
184 #endif /* __UCLIBC_HAS_WCHAR__ */
185 #endif /* __CTYPE_HAS_8_BIT_LOCALES */
186 #ifdef __UCLIBC_HAS_WCHAR__
187
188         const uint16_t *code2flag;
189
190         const unsigned char *tblwctype;
191         const unsigned char *tblwuplow;
192 /*      const unsigned char *tblwcomb; */
193         const int16_t *tblwuplow_diff; /* yes... signed */
194         /* width?? */
195
196         wchar_t decimal_point_wc;
197         wchar_t thousands_sep_wc;
198         int decimal_point_len;
199         int thousands_sep_len;
200
201 #endif /* __UCLIBC_HAS_WCHAR__ */
202
203         /* ctype */
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!!! */
215
216         /* numeric */
217         const char *decimal_point;
218         const char *thousands_sep;
219         const char *grouping;
220
221         /* monetary */
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;
243
244         const char *crncystr;           /* not returned by localeconv */
245
246         /* time */
247         const char *abday_1;
248         const char *abday_2;
249         const char *abday_3;
250         const char *abday_4;
251         const char *abday_5;
252         const char *abday_6;
253         const char *abday_7;
254
255         const char *day_1;
256         const char *day_2;
257         const char *day_3;
258         const char *day_4;
259         const char *day_5;
260         const char *day_6;
261         const char *day_7;
262
263         const char *abmon_1;
264         const char *abmon_2;
265         const char *abmon_3;
266         const char *abmon_4;
267         const char *abmon_5;
268         const char *abmon_6;
269         const char *abmon_7;
270         const char *abmon_8;
271         const char *abmon_9;
272         const char *abmon_10;
273         const char *abmon_11;
274         const char *abmon_12;
275
276         const char *mon_1;
277         const char *mon_2;
278         const char *mon_3;
279         const char *mon_4;
280         const char *mon_5;
281         const char *mon_6;
282         const char *mon_7;
283         const char *mon_8;
284         const char *mon_9;
285         const char *mon_10;
286         const char *mon_11;
287         const char *mon_12;
288
289         const char *am_str;
290         const char *pm_str;
291
292         const char *d_t_fmt;
293         const char *d_fmt;
294         const char *t_fmt;
295         const char *t_fmt_ampm;
296         const char *era;
297
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;
303
304         /* collate is at the end */
305
306         /* messages */
307         const char *yesexpr;
308         const char *noexpr;
309         const char *yesstr;
310         const char *nostr;
311
312         /* collate is at the end */
313         __collate_t collate;
314
315 } __uclibc_locale_t;
316
317 extern __uclibc_locale_t __global_locale_data;
318 extern struct __uclibc_locale_struct * __global_locale;
319 #endif /* _LIBC */
320
321 typedef struct __uclibc_locale_struct *__locale_t;
322
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;
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 #ifdef __UCLIBC_HAS_XLOCALE__
336
337 extern __locale_t __curlocale_var;
338
339 #ifdef __UCLIBC_HAS_THREADS__
340
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())
345
346 #else  /* __UCLIBC_HAS_THREADS__ */
347
348 #define __UCLIBC_CURLOCALE           (__curlocale_var)
349 #define __UCLIBC_CURLOCALE_DATA      (*__curlocale_var)
350
351 #endif /* __UCLIBC_HAS_THREADS__ */
352
353 #elif defined(__UCLIBC_HAS_LOCALE__)
354
355 #define __UCLIBC_CURLOCALE           (__global_locale)
356 #define __UCLIBC_CURLOCALE_DATA      (*__global_locale)
357
358 #endif
359 /**********************************************************************/
360 #if defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE)
361
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
366
367 #else  /* defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE) */
368
369 #define __XL_NPP(N) N
370 #define __LOCALE_PARAM
371 #define __LOCALE_ARG
372 #define __LOCALE_PTR      __UCLIBC_CURLOCALE
373
374 #endif /* defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE) */
375 /**********************************************************************/
376
377 #endif /* !defined(__LOCALE_C_ONLY) */
378 /**********************************************************************/
379
380 #endif /* _UCLIBC_LOCALE_H */