summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/bits/uClibc_locale.h
blob: b42236d38ac5046d3ac31fd03ddea763d163dfdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*  Copyright (C) 2002, 2003     Manuel Novoa III
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  The GNU C Library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with the GNU C Library; see the file COPYING.LIB.  If
 *  not, see <http://www.gnu.org/licenses/>.
 */

/*  ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION!
 *
 *  Besides uClibc, I'm using this code in my libc for elks, which is
 *  a 16-bit environment with a fairly limited compiler.  It would make
 *  things much easier for me if this file isn't modified unnecessarily.
 *  In particular, please put any new or replacement functions somewhere
 *  else, and modify the makefile to use your version instead.
 *  Thanks.  Manuel
 *
 *  ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION! */

#ifndef _UCLIBC_LOCALE_H
#define _UCLIBC_LOCALE_H

/**********************************************************************/
/* uClibc compatibilty stuff */

#ifdef __UCLIBC_HAS_LOCALE__

# undef __LOCALE_C_ONLY

#else

# define __LOCALE_C_ONLY

# ifdef _LIBC
#  define __XL_NPP(N) N
#  define __LOCALE_PARAM
#  define __LOCALE_ARG
# endif

#endif

/**********************************************************************/

#define __NL_ITEM_CATEGORY_SHIFT        8
#define __NL_ITEM_INDEX_MASK            0xff

/* TODO: Make sure these agree with the locale mmap file gererator! */

#define __LC_CTYPE      0
#define __LC_NUMERIC    1
#define __LC_MONETARY   2
#define __LC_TIME       3
#define __LC_COLLATE    4
#define __LC_MESSAGES   5
#define __LC_ALL        6

/**********************************************************************/
#ifndef __LOCALE_C_ONLY

enum {
	__ctype_encoding_7_bit,		/* C/POSIX */
	__ctype_encoding_utf8,		/* UTF-8 */
	__ctype_encoding_8_bit		/* for 8-bit codeset locales */
};

#define LOCALE_STRING_SIZE (2 * __LC_ALL + 2)

 /*
  * '#' + 2_per_category + '\0'
  *       {locale row # : 0 = C|POSIX} + 0x8001
  *       encoded in two chars as (((N+1) >> 8) | 0x80) and ((N+1) & 0xff)
  *       so decode is  ((((uint16_t)(*s & 0x7f)) << 8) + s[1]) - 1
  *
  *       Note: 0s are not used as they are nul-terminators for strings.
  *       Note: 0xff, 0xff is the encoding for a non-selected locale.
  *             (see setlocale() below).
  * In particular, C/POSIX locale is '#' + "\x80\x01"}*LC_ALL + nul.
  */

struct __uclibc_locale_struct;
typedef struct __uclibc_locale_struct *__locale_t;

#ifdef _LIBC

/* extern void _locale_set(const unsigned char *p); */
extern void weak_function _locale_init(void) attribute_hidden;

#include <stddef.h>
#include <stdint.h>
#include <bits/uClibc_touplow.h>
#ifndef __UCLIBC_GEN_LOCALE
# include <bits/uClibc_locale_data.h>
#endif

#ifndef __UCLIBC_GEN_LOCALE /* && (defined IS_IN_libc || defined NOT_IN_libc) */
typedef struct {
	uint16_t num_weights;
	uint16_t num_starters;
	uint16_t ii_shift;
	uint16_t ti_shift;
	uint16_t ii_len;
	uint16_t ti_len;
	uint16_t max_weight;
	uint16_t num_col_base;
	uint16_t max_col_index;
	uint16_t undefined_idx;
	uint16_t range_low;
	uint16_t range_count;
	uint16_t range_base_weight;
	uint16_t range_rule_offset; /* change name to index? */

	uint16_t ii_mask;
	uint16_t ti_mask;

	const uint16_t *index2weight_tbl;
	const uint16_t *index2ruleidx_tbl;
	const uint16_t *multistart_tbl;
	/*	 uint16_t wcs2colidt_offset_low; */
	/*	 uint16_t wcs2colidt_offset_hi; */
	const uint16_t *wcs2colidt_tbl;

	/*	 uint16_t undefined_idx; */
	const uint16_t *overrides_tbl;
	/*	 uint16_t *multistart_tbl; */

	const uint16_t *weightstr;
	const uint16_t *ruletable;


	uint16_t *index2weight;
	uint16_t *index2ruleidx;

	uint16_t MAX_WEIGHTS;
} __collate_t;

/*  static unsigned char cur_locale[LOCALE_STRING_SIZE]; */

struct __uclibc_locale_struct {
#ifdef __UCLIBC_HAS_XLOCALE__
	const __ctype_mask_t *__ctype_b;
	const __ctype_touplow_t *__ctype_tolower;
	const __ctype_touplow_t *__ctype_toupper;
#endif

	/* For now, just embed this in the structure. */
	__ctype_mask_t __ctype_b_data[256 + __UCLIBC_CTYPE_B_TBL_OFFSET];
	__ctype_touplow_t __ctype_tolower_data[256 + __UCLIBC_CTYPE_TO_TBL_OFFSET];
	__ctype_touplow_t __ctype_toupper_data[256 + __UCLIBC_CTYPE_TO_TBL_OFFSET];

/*  	int tables_loaded; */
/*  	unsigned char lctypes[LOCALE_STRING_SIZE]; */
	unsigned char cur_locale[LOCALE_STRING_SIZE];

	/* NL_LANGINFO stuff. BEWARE ORDERING!!! must agree with NL_* constants! */
	/* Also, numeric must be followed by monetary and the items must be in
	 * the "struct lconv" order. */

	uint16_t category_offsets[__LC_ALL]; /* TODO -- fix? */
	unsigned char category_item_count[__LC_ALL]; /* TODO - fix */

	/* ctype */
	unsigned char encoding;		/* C/POSIX, 8-bit, UTF-8 */
	unsigned char mb_cur_max;	/* determined by encoding _AND_ translit!!! */
	const unsigned char outdigit_length[10];

#ifdef __CTYPE_HAS_8_BIT_LOCALES
	const unsigned char *idx8ctype;
	const unsigned char *tbl8ctype;
	const unsigned char *idx8uplow;
	const unsigned char *tbl8uplow;
# ifdef __UCLIBC_HAS_WCHAR__
	const unsigned char *idx8c2wc;
	const uint16_t *tbl8c2wc;	/* char > 0x7f to wide char */
	const unsigned char *idx8wc2c;
	const unsigned char *tbl8wc2c;
	/* translit  */
# endif
#endif /* __CTYPE_HAS_8_BIT_LOCALES */
#ifdef __UCLIBC_HAS_WCHAR__

	const uint16_t *code2flag;

	const unsigned char *tblwctype;
	const unsigned char *tblwuplow;
/* 	const unsigned char *tblwcomb; */
	const int16_t *tblwuplow_diff; /* yes... signed */
	/* width?? */

	wchar_t decimal_point_wc;
	wchar_t thousands_sep_wc;
	int decimal_point_len;
	int thousands_sep_len;

#endif /* __UCLIBC_HAS_WCHAR__ */

	/* ctype */
	const char *outdigit0_mb;
	const char *outdigit1_mb;
	const char *outdigit2_mb;
	const char *outdigit3_mb;
	const char *outdigit4_mb;
	const char *outdigit5_mb;
	const char *outdigit6_mb;
	const char *outdigit7_mb;
	const char *outdigit8_mb;
	const char *outdigit9_mb;
	const char *codeset;		/* MUST BE LAST!!! */

	/* numeric */
	const char *decimal_point;
	const char *thousands_sep;
	const char *grouping;

	/* monetary */
	const char *int_curr_symbol;
	const char *currency_symbol;
	const char *mon_decimal_point;
	const char *mon_thousands_sep;
	const char *mon_grouping;
	const char *positive_sign;
	const char *negative_sign;
	const char *int_frac_digits;
	const char *frac_digits;
	const char *p_cs_precedes;
	const char *p_sep_by_space;
	const char *n_cs_precedes;
	const char *n_sep_by_space;
	const char *p_sign_posn;
	const char *n_sign_posn;
	const char *int_p_cs_precedes;
	const char *int_p_sep_by_space;
	const char *int_n_cs_precedes;
	const char *int_n_sep_by_space;
	const char *int_p_sign_posn;
	const char *int_n_sign_posn;

	const char *crncystr;		/* not returned by localeconv */

	/* time */
	const char *abday_1;
	const char *abday_2;
	const char *abday_3;
	const char *abday_4;
	const char *abday_5;
	const char *abday_6;
	const char *abday_7;

	const char *day_1;
	const char *day_2;
	const char *day_3;
	const char *day_4;
	const char *day_5;
	const char *day_6;
	const char *day_7;

	const char *abmon_1;
	const char *abmon_2;
	const char *abmon_3;
	const char *abmon_4;
	const char *abmon_5;
	const char *abmon_6;
	const char *abmon_7;
	const char *abmon_8;
	const char *abmon_9;
	const char *abmon_10;
	const char *abmon_11;
	const char *abmon_12;

	const char *mon_1;
	const char *mon_2;
	const char *mon_3;
	const char *mon_4;
	const char *mon_5;
	const char *mon_6;
	const char *mon_7;
	const char *mon_8;
	const char *mon_9;
	const char *mon_10;
	const char *mon_11;
	const char *mon_12;

	const char *am_str;
	const char *pm_str;

	const char *d_t_fmt;
	const char *d_fmt;
	const char *t_fmt;
	const char *t_fmt_ampm;
	const char *era;

	const char *era_year;		/* non SUSv3 */
	const char *era_d_fmt;
	const char *alt_digits;
	const char *era_d_t_fmt;
	const char *era_t_fmt;

	/* messages */
	const char *yesexpr;
	const char *noexpr;
	const char *yesstr;
	const char *nostr;

	/* collate is at the end */
	__collate_t collate;
};

extern struct __uclibc_locale_struct __global_locale_data;
extern struct __uclibc_locale_struct *__global_locale;
#endif /* !__UCLIBC_GEN_LOCALE */

#if defined IS_IN_libc || defined NOT_IN_libc
/* If you plan to remove xxx_IN_libc guards,
 * remove attribute_hidden, it won't work.
 */
extern int __locale_mbrtowc_l(wchar_t *__restrict dst,
				const char *__restrict src,
				__locale_t loc) attribute_hidden;
#endif

#ifdef L_setlocale
/* so we only get the warning once... */
#warning need thread version of CUR_LOCALE!
#endif

/**********************************************************************/
#ifdef __UCLIBC_HAS_XLOCALE__

extern __locale_t __curlocale_var;
# ifdef __UCLIBC_HAS_THREADS__
extern __locale_t __curlocale(void)  __THROW __attribute__ ((__const__));
libc_hidden_proto(__curlocale)
extern __locale_t __curlocale_set(__locale_t newloc);
libc_hidden_proto(__curlocale_set)
#  define __UCLIBC_CURLOCALE  (__curlocale())
# else
#  define __UCLIBC_CURLOCALE  (__curlocale_var)
# endif

#elif defined(__UCLIBC_HAS_LOCALE__)

# define __UCLIBC_CURLOCALE   (__global_locale)

#endif
/**********************************************************************/
#if defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE)

# define __XL_NPP(N) N ## _l
# define __LOCALE_PARAM    , __locale_t locale_arg
# define __LOCALE_ARG      , locale_arg
# define __LOCALE_PTR      locale_arg

#else

# define __XL_NPP(N) N
# define __LOCALE_PARAM
# define __LOCALE_ARG
# define __LOCALE_PTR      __UCLIBC_CURLOCALE

#endif
/**********************************************************************/

#endif /* _LIBC */

#endif /* !defined(__LOCALE_C_ONLY) */

#endif /* _UCLIBC_LOCALE_H */