uClibc_locale.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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 Library General Public
  5. * License as published by the Free Software Foundation; either
  6. * version 2 of the License, or (at your option) any later version.
  7. *
  8. * This 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. * Library General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Library General Public
  14. * License along with this library; if not, write to the Free
  15. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. /* ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
  18. *
  19. * Besides uClibc, I'm using this code in my libc for elks, which is
  20. * a 16-bit environment with a fairly limited compiler. It would make
  21. * things much easier for me if this file isn't modified unnecessarily.
  22. * In particular, please put any new or replacement functions somewhere
  23. * else, and modify the makefile to use your version instead.
  24. * Thanks. Manuel
  25. *
  26. * ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! */
  27. #ifndef _UCLIBC_LOCALE_H
  28. #define _UCLIBC_LOCALE_H
  29. /**********************************************************************/
  30. /* uClibc compatibilty stuff */
  31. #ifdef __UCLIBC_HAS_LOCALE__
  32. #undef __LOCALE_C_ONLY
  33. #else /* __UCLIBC_HAS_LOCALE__ */
  34. #define __LOCALE_C_ONLY
  35. #define __XL(N) N
  36. #define __XL_NPP(N) N
  37. #define __XL_ALIAS(N)
  38. #define __LOCALE_PARAM
  39. #define __LOCALE_ARG
  40. #endif /* __UCLIBC_HAS_LOCALE__ */
  41. /**********************************************************************/
  42. #define __NL_ITEM_CATEGORY_SHIFT (8)
  43. #define __NL_ITEM_INDEX_MASK (0xff)
  44. /* TODO: Make sure these agree with the locale mmap file gererator! */
  45. #define __LC_CTYPE 0
  46. #define __LC_NUMERIC 1
  47. #define __LC_MONETARY 2
  48. #define __LC_TIME 3
  49. #define __LC_COLLATE 4
  50. #define __LC_MESSAGES 5
  51. #define __LC_ALL 6
  52. /**********************************************************************/
  53. /* #if defined(_LIBC) && !defined(__LOCALE_C_ONLY) */
  54. #ifndef __LOCALE_C_ONLY
  55. #include <stddef.h>
  56. #include <stdint.h>
  57. #include <bits/uClibc_touplow.h>
  58. #include <bits/uClibc_locale_data.h>
  59. extern void _locale_set(const unsigned char *p);
  60. extern void _locale_init(void);
  61. enum {
  62. __ctype_encoding_7_bit, /* C/POSIX */
  63. __ctype_encoding_utf8, /* UTF-8 */
  64. __ctype_encoding_8_bit /* for 8-bit codeset locales */
  65. };
  66. #define LOCALE_STRING_SIZE (2 * __LC_ALL + 2)
  67. /*
  68. * '#' + 2_per_category + '\0'
  69. * {locale row # : 0 = C|POSIX} + 0x8001
  70. * encoded in two chars as (((N+1) >> 8) | 0x80) and ((N+1) & 0xff)
  71. * so decode is ((((uint16_t)(*s & 0x7f)) << 8) + s[1]) - 1
  72. *
  73. * Note: 0s are not used as they are nul-terminators for strings.
  74. * Note: 0xff, 0xff is the encoding for a non-selected locale.
  75. * (see setlocale() below).
  76. * In particular, C/POSIX locale is '#' + "\x80\x01"}*LC_ALL + nul.
  77. */
  78. typedef struct {
  79. uint16_t num_weights;
  80. uint16_t num_starters;
  81. uint16_t ii_shift;
  82. uint16_t ti_shift;
  83. uint16_t ii_len;
  84. uint16_t ti_len;
  85. uint16_t max_weight;
  86. uint16_t num_col_base;
  87. uint16_t max_col_index;
  88. uint16_t undefined_idx;
  89. uint16_t range_low;
  90. uint16_t range_count;
  91. uint16_t range_base_weight;
  92. uint16_t range_rule_offset; /* change name to index? */
  93. uint16_t ii_mask;
  94. uint16_t ti_mask;
  95. const uint16_t *index2weight_tbl;
  96. const uint16_t *index2ruleidx_tbl;
  97. const uint16_t *multistart_tbl;
  98. /* uint16_t wcs2colidt_offset_low; */
  99. /* uint16_t wcs2colidt_offset_hi; */
  100. const uint16_t *wcs2colidt_tbl;
  101. /* uint16_t undefined_idx; */
  102. const uint16_t *overrides_tbl;
  103. /* uint16_t *multistart_tbl; */
  104. const uint16_t *weightstr;
  105. const uint16_t *ruletable;
  106. uint16_t *index2weight;
  107. uint16_t *index2ruleidx;
  108. uint16_t MAX_WEIGHTS;
  109. } __collate_t;
  110. /* static unsigned char cur_locale[LOCALE_STRING_SIZE]; */
  111. typedef struct {
  112. #ifdef __UCLIBC_HAS_XLOCALE__
  113. const __uint16_t *__ctype_b;
  114. const __ctype_touplow_t *__ctype_tolower;
  115. const __ctype_touplow_t *__ctype_toupper;
  116. #endif
  117. /* int tables_loaded; */
  118. /* unsigned char lctypes[LOCALE_STRING_SIZE]; */
  119. unsigned char cur_locale[LOCALE_STRING_SIZE];
  120. /* NL_LANGINFO stuff. BEWARE ORDERING!!! must agree with NL_* constants! */
  121. /* Also, numeric must be followed by monetary and the items must be in
  122. * the "struct lconv" order. */
  123. uint16_t category_offsets[__LC_ALL]; /* TODO -- fix? */
  124. unsigned char category_item_count[__LC_ALL]; /* TODO - fix */
  125. /* ctype */
  126. unsigned char encoding; /* C/POSIX, 8-bit, UTF-8 */
  127. unsigned char mb_cur_max; /* determined by encoding _AND_ translit!!! */
  128. const unsigned char outdigit_length[10];
  129. #ifdef __CTYPE_HAS_8_BIT_LOCALES
  130. const unsigned char *idx8ctype;
  131. const unsigned char *tbl8ctype;
  132. const unsigned char *idx8uplow;
  133. const unsigned char *tbl8uplow;
  134. #ifdef __UCLIBC_HAS_WCHAR__
  135. const unsigned char *idx8c2wc;
  136. const uint16_t *tbl8c2wc; /* char > 0x7f to wide char */
  137. const unsigned char *idx8wc2c;
  138. const unsigned char *tbl8wc2c;
  139. /* translit */
  140. #endif /* __UCLIBC_HAS_WCHAR__ */
  141. #endif /* __CTYPE_HAS_8_BIT_LOCALES */
  142. #ifdef __UCLIBC_HAS_WCHAR__
  143. const uint16_t *code2flag;
  144. const unsigned char *tblwctype;
  145. const unsigned char *tblwuplow;
  146. /* const unsigned char *tblwcomb; */
  147. const int16_t *tblwuplow_diff; /* yes... signed */
  148. /* width?? */
  149. wchar_t decimal_point_wc;
  150. wchar_t thousands_sep_wc;
  151. int decimal_point_len;
  152. int thousands_sep_len;
  153. #endif /* __UCLIBC_HAS_WCHAR__ */
  154. /* ctype */
  155. const char *outdigit0_mb;
  156. const char *outdigit1_mb;
  157. const char *outdigit2_mb;
  158. const char *outdigit3_mb;
  159. const char *outdigit4_mb;
  160. const char *outdigit5_mb;
  161. const char *outdigit6_mb;
  162. const char *outdigit7_mb;
  163. const char *outdigit8_mb;
  164. const char *outdigit9_mb;
  165. const char *codeset; /* MUST BE LAST!!! */
  166. /* numeric */
  167. const char *decimal_point;
  168. const char *thousands_sep;
  169. const char *grouping;
  170. /* monetary */
  171. const char *int_curr_symbol;
  172. const char *currency_symbol;
  173. const char *mon_decimal_point;
  174. const char *mon_thousands_sep;
  175. const char *mon_grouping;
  176. const char *positive_sign;
  177. const char *negative_sign;
  178. const char *int_frac_digits;
  179. const char *frac_digits;
  180. const char *p_cs_precedes;
  181. const char *p_sep_by_space;
  182. const char *n_cs_precedes;
  183. const char *n_sep_by_space;
  184. const char *p_sign_posn;
  185. const char *n_sign_posn;
  186. const char *int_p_cs_precedes;
  187. const char *int_p_sep_by_space;
  188. const char *int_n_cs_precedes;
  189. const char *int_n_sep_by_space;
  190. const char *int_p_sign_posn;
  191. const char *int_n_sign_posn;
  192. const char *crncystr; /* not returned by localeconv */
  193. /* time */
  194. const char *abday_1;
  195. const char *abday_2;
  196. const char *abday_3;
  197. const char *abday_4;
  198. const char *abday_5;
  199. const char *abday_6;
  200. const char *abday_7;
  201. const char *day_1;
  202. const char *day_2;
  203. const char *day_3;
  204. const char *day_4;
  205. const char *day_5;
  206. const char *day_6;
  207. const char *day_7;
  208. const char *abmon_1;
  209. const char *abmon_2;
  210. const char *abmon_3;
  211. const char *abmon_4;
  212. const char *abmon_5;
  213. const char *abmon_6;
  214. const char *abmon_7;
  215. const char *abmon_8;
  216. const char *abmon_9;
  217. const char *abmon_10;
  218. const char *abmon_11;
  219. const char *abmon_12;
  220. const char *mon_1;
  221. const char *mon_2;
  222. const char *mon_3;
  223. const char *mon_4;
  224. const char *mon_5;
  225. const char *mon_6;
  226. const char *mon_7;
  227. const char *mon_8;
  228. const char *mon_9;
  229. const char *mon_10;
  230. const char *mon_11;
  231. const char *mon_12;
  232. const char *am_str;
  233. const char *pm_str;
  234. const char *d_t_fmt;
  235. const char *d_fmt;
  236. const char *t_fmt;
  237. const char *t_fmt_ampm;
  238. const char *era;
  239. const char *era_year; /* non SUSv3 */
  240. const char *era_d_fmt;
  241. const char *alt_digits;
  242. const char *era_d_t_fmt;
  243. const char *era_t_fmt;
  244. /* collate is at the end */
  245. /* messages */
  246. const char *yesexpr;
  247. const char *noexpr;
  248. const char *yesstr;
  249. const char *nostr;
  250. /* collate is at the end */
  251. __collate_t collate;
  252. } __uclibc_locale_t;
  253. typedef __uclibc_locale_t *__locale_t;
  254. extern __locale_t __global_locale;
  255. extern int __locale_mbrtowc_l(wchar_t *__restrict dst,
  256. const char *__restrict src,
  257. __locale_t loc );
  258. #ifdef L_setlocale
  259. /* so we only get the warning once... */
  260. #warning need thread version of CUR_LOCALE!
  261. #endif
  262. /**********************************************************************/
  263. #ifdef __UCLIBC_HAS_XLOCALE__
  264. extern __locale_t __curlocale_var;
  265. #ifdef __UCLIBC_HAS_THREADS__
  266. extern __locale_t __curlocale(void) __THROW __attribute__ ((__const__));
  267. extern __locale_t __curlocale_set(__locale_t newloc);
  268. #define __UCLIBC_CURLOCALE (__curlocale())
  269. #define __UCLIBC_CURLOCALE_DATA (*__curlocale())
  270. #else /* __UCLIBC_HAS_THREADS__ */
  271. #define __UCLIBC_CURLOCALE (__curlocale_var)
  272. #define __UCLIBC_CURLOCALE_DATA (*__curlocale_var)
  273. #endif /* __UCLIBC_HAS_THREADS__ */
  274. #elif defined(__UCLIBC_HAS_LOCALE__)
  275. #define __UCLIBC_CURLOCALE (__global_locale)
  276. #define __UCLIBC_CURLOCALE_DATA (*__global_locale)
  277. #endif
  278. /**********************************************************************/
  279. #if defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE)
  280. #define __XL(N) __ ## N ## _l
  281. #define __XL_NPP(N) N ## _l
  282. #define __XL_ALIAS(N) weak_alias( __ ## N ## _l , N ## _l )
  283. #define __LOCALE_PARAM , __locale_t locale_arg
  284. #define __LOCALE_ARG , locale_arg
  285. #define __LOCALE_PTR locale_arg
  286. #else /* defined(__UCLIBC_HAS_XLOCALE__) && defined(__STDLIB_DO_XLOCALE) */
  287. #define __XL(N) N
  288. #define __XL_NPP(N) N
  289. #define __XL_ALIAS(N)
  290. #define __LOCALE_PARAM
  291. #define __LOCALE_ARG
  292. #define __LOCALE_PTR __UCLIBC_CURLOCALE
  293. #endif /* defined(__UCLIBC_HAS_XLOCALE__) && defined(__STDLIB_DO_XLOCALE) */
  294. /**********************************************************************/
  295. #endif /* defined(_LIBC) && !defined(__LOCALE_C_ONLY) */
  296. /**********************************************************************/
  297. #endif /* _UCLIBC_LOCALE_H */