uClibc_locale.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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; see the file COPYING.LIB. If
  15. * not, see <http://www.gnu.org/licenses/>.
  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
  34. # define __LOCALE_C_ONLY
  35. # ifdef _LIBC
  36. # define __XL_NPP(N) N
  37. # define __LOCALE_PARAM
  38. # define __LOCALE_ARG
  39. # endif
  40. #endif
  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. #ifndef __LOCALE_C_ONLY
  54. enum {
  55. __ctype_encoding_7_bit, /* C/POSIX */
  56. __ctype_encoding_utf8, /* UTF-8 */
  57. __ctype_encoding_8_bit /* for 8-bit codeset locales */
  58. };
  59. #define LOCALE_STRING_SIZE (2 * __LC_ALL + 2)
  60. /*
  61. * '#' + 2_per_category + '\0'
  62. * {locale row # : 0 = C|POSIX} + 0x8001
  63. * encoded in two chars as (((N+1) >> 8) | 0x80) and ((N+1) & 0xff)
  64. * so decode is ((((uint16_t)(*s & 0x7f)) << 8) + s[1]) - 1
  65. *
  66. * Note: 0s are not used as they are nul-terminators for strings.
  67. * Note: 0xff, 0xff is the encoding for a non-selected locale.
  68. * (see setlocale() below).
  69. * In particular, C/POSIX locale is '#' + "\x80\x01"}*LC_ALL + nul.
  70. */
  71. struct __uclibc_locale_struct;
  72. typedef struct __uclibc_locale_struct *__locale_t;
  73. #ifdef _LIBC
  74. /* extern void _locale_set(const unsigned char *p); */
  75. extern void weak_function _locale_init(void) attribute_hidden;
  76. #include <stddef.h>
  77. #include <stdint.h>
  78. #include <bits/uClibc_touplow.h>
  79. #ifndef __UCLIBC_GEN_LOCALE
  80. # include <bits/uClibc_locale_data.h>
  81. #endif
  82. #ifndef __UCLIBC_GEN_LOCALE /* && (defined IS_IN_libc || defined NOT_IN_libc) */
  83. typedef struct {
  84. uint16_t num_weights;
  85. uint16_t num_starters;
  86. uint16_t ii_shift;
  87. uint16_t ti_shift;
  88. uint16_t ii_len;
  89. uint16_t ti_len;
  90. uint16_t max_weight;
  91. uint16_t num_col_base;
  92. uint16_t max_col_index;
  93. uint16_t undefined_idx;
  94. uint16_t range_low;
  95. uint16_t range_count;
  96. uint16_t range_base_weight;
  97. uint16_t range_rule_offset; /* change name to index? */
  98. uint16_t ii_mask;
  99. uint16_t ti_mask;
  100. const uint16_t *index2weight_tbl;
  101. const uint16_t *index2ruleidx_tbl;
  102. const uint16_t *multistart_tbl;
  103. /* uint16_t wcs2colidt_offset_low; */
  104. /* uint16_t wcs2colidt_offset_hi; */
  105. const uint16_t *wcs2colidt_tbl;
  106. /* uint16_t undefined_idx; */
  107. const uint16_t *overrides_tbl;
  108. /* uint16_t *multistart_tbl; */
  109. const uint16_t *weightstr;
  110. const uint16_t *ruletable;
  111. uint16_t *index2weight;
  112. uint16_t *index2ruleidx;
  113. uint16_t MAX_WEIGHTS;
  114. } __collate_t;
  115. /* static unsigned char cur_locale[LOCALE_STRING_SIZE]; */
  116. struct __uclibc_locale_struct {
  117. #ifdef __UCLIBC_HAS_XLOCALE__
  118. const __ctype_mask_t *__ctype_b;
  119. const __ctype_touplow_t *__ctype_tolower;
  120. const __ctype_touplow_t *__ctype_toupper;
  121. #endif
  122. /* For now, just embed this in the structure. */
  123. __ctype_mask_t __ctype_b_data[256 + __UCLIBC_CTYPE_B_TBL_OFFSET];
  124. __ctype_touplow_t __ctype_tolower_data[256 + __UCLIBC_CTYPE_TO_TBL_OFFSET];
  125. __ctype_touplow_t __ctype_toupper_data[256 + __UCLIBC_CTYPE_TO_TBL_OFFSET];
  126. /* int tables_loaded; */
  127. /* unsigned char lctypes[LOCALE_STRING_SIZE]; */
  128. unsigned char cur_locale[LOCALE_STRING_SIZE];
  129. /* NL_LANGINFO stuff. BEWARE ORDERING!!! must agree with NL_* constants! */
  130. /* Also, numeric must be followed by monetary and the items must be in
  131. * the "struct lconv" order. */
  132. uint16_t category_offsets[__LC_ALL]; /* TODO -- fix? */
  133. unsigned char category_item_count[__LC_ALL]; /* TODO - fix */
  134. /* ctype */
  135. unsigned char encoding; /* C/POSIX, 8-bit, UTF-8 */
  136. unsigned char mb_cur_max; /* determined by encoding _AND_ translit!!! */
  137. const unsigned char outdigit_length[10];
  138. #ifdef __CTYPE_HAS_8_BIT_LOCALES
  139. const unsigned char *idx8ctype;
  140. const unsigned char *tbl8ctype;
  141. const unsigned char *idx8uplow;
  142. const unsigned char *tbl8uplow;
  143. # ifdef __UCLIBC_HAS_WCHAR__
  144. const unsigned char *idx8c2wc;
  145. const uint16_t *tbl8c2wc; /* char > 0x7f to wide char */
  146. const unsigned char *idx8wc2c;
  147. const unsigned char *tbl8wc2c;
  148. /* translit */
  149. # endif
  150. #endif /* __CTYPE_HAS_8_BIT_LOCALES */
  151. #ifdef __UCLIBC_HAS_WCHAR__
  152. const uint16_t *code2flag;
  153. const unsigned char *tblwctype;
  154. const unsigned char *tblwuplow;
  155. /* const unsigned char *tblwcomb; */
  156. const int16_t *tblwuplow_diff; /* yes... signed */
  157. /* width?? */
  158. wchar_t decimal_point_wc;
  159. wchar_t thousands_sep_wc;
  160. int decimal_point_len;
  161. int thousands_sep_len;
  162. #endif /* __UCLIBC_HAS_WCHAR__ */
  163. /* ctype */
  164. const char *outdigit0_mb;
  165. const char *outdigit1_mb;
  166. const char *outdigit2_mb;
  167. const char *outdigit3_mb;
  168. const char *outdigit4_mb;
  169. const char *outdigit5_mb;
  170. const char *outdigit6_mb;
  171. const char *outdigit7_mb;
  172. const char *outdigit8_mb;
  173. const char *outdigit9_mb;
  174. const char *codeset; /* MUST BE LAST!!! */
  175. /* numeric */
  176. const char *decimal_point;
  177. const char *thousands_sep;
  178. const char *grouping;
  179. /* monetary */
  180. const char *int_curr_symbol;
  181. const char *currency_symbol;
  182. const char *mon_decimal_point;
  183. const char *mon_thousands_sep;
  184. const char *mon_grouping;
  185. const char *positive_sign;
  186. const char *negative_sign;
  187. const char *int_frac_digits;
  188. const char *frac_digits;
  189. const char *p_cs_precedes;
  190. const char *p_sep_by_space;
  191. const char *n_cs_precedes;
  192. const char *n_sep_by_space;
  193. const char *p_sign_posn;
  194. const char *n_sign_posn;
  195. const char *int_p_cs_precedes;
  196. const char *int_p_sep_by_space;
  197. const char *int_n_cs_precedes;
  198. const char *int_n_sep_by_space;
  199. const char *int_p_sign_posn;
  200. const char *int_n_sign_posn;
  201. const char *crncystr; /* not returned by localeconv */
  202. /* time */
  203. const char *abday_1;
  204. const char *abday_2;
  205. const char *abday_3;
  206. const char *abday_4;
  207. const char *abday_5;
  208. const char *abday_6;
  209. const char *abday_7;
  210. const char *day_1;
  211. const char *day_2;
  212. const char *day_3;
  213. const char *day_4;
  214. const char *day_5;
  215. const char *day_6;
  216. const char *day_7;
  217. const char *abmon_1;
  218. const char *abmon_2;
  219. const char *abmon_3;
  220. const char *abmon_4;
  221. const char *abmon_5;
  222. const char *abmon_6;
  223. const char *abmon_7;
  224. const char *abmon_8;
  225. const char *abmon_9;
  226. const char *abmon_10;
  227. const char *abmon_11;
  228. const char *abmon_12;
  229. const char *mon_1;
  230. const char *mon_2;
  231. const char *mon_3;
  232. const char *mon_4;
  233. const char *mon_5;
  234. const char *mon_6;
  235. const char *mon_7;
  236. const char *mon_8;
  237. const char *mon_9;
  238. const char *mon_10;
  239. const char *mon_11;
  240. const char *mon_12;
  241. const char *am_str;
  242. const char *pm_str;
  243. const char *d_t_fmt;
  244. const char *d_fmt;
  245. const char *t_fmt;
  246. const char *t_fmt_ampm;
  247. const char *era;
  248. const char *era_year; /* non SUSv3 */
  249. const char *era_d_fmt;
  250. const char *alt_digits;
  251. const char *era_d_t_fmt;
  252. const char *era_t_fmt;
  253. /* messages */
  254. const char *yesexpr;
  255. const char *noexpr;
  256. const char *yesstr;
  257. const char *nostr;
  258. /* collate is at the end */
  259. __collate_t collate;
  260. };
  261. extern struct __uclibc_locale_struct __global_locale_data;
  262. extern struct __uclibc_locale_struct *__global_locale;
  263. #endif /* !__UCLIBC_GEN_LOCALE */
  264. #if defined IS_IN_libc || defined NOT_IN_libc
  265. /* If you plan to remove xxx_IN_libc guards,
  266. * remove attribute_hidden, it won't work.
  267. */
  268. extern int __locale_mbrtowc_l(wchar_t *__restrict dst,
  269. const char *__restrict src,
  270. __locale_t loc) attribute_hidden;
  271. #endif
  272. #ifdef L_setlocale
  273. /* so we only get the warning once... */
  274. #warning need thread version of CUR_LOCALE!
  275. #endif
  276. /**********************************************************************/
  277. #ifdef __UCLIBC_HAS_XLOCALE__
  278. extern __locale_t __curlocale_var;
  279. # ifdef __UCLIBC_HAS_THREADS__
  280. extern __locale_t __curlocale(void) __THROW __attribute__ ((__const__));
  281. libc_hidden_proto(__curlocale)
  282. extern __locale_t __curlocale_set(__locale_t newloc);
  283. libc_hidden_proto(__curlocale_set)
  284. # define __UCLIBC_CURLOCALE (__curlocale())
  285. # else
  286. # define __UCLIBC_CURLOCALE (__curlocale_var)
  287. # endif
  288. #elif defined(__UCLIBC_HAS_LOCALE__)
  289. # define __UCLIBC_CURLOCALE (__global_locale)
  290. #endif
  291. /**********************************************************************/
  292. #if defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE)
  293. # define __XL_NPP(N) N ## _l
  294. # define __LOCALE_PARAM , __locale_t locale_arg
  295. # define __LOCALE_ARG , locale_arg
  296. # define __LOCALE_PTR locale_arg
  297. #else
  298. # define __XL_NPP(N) N
  299. # define __LOCALE_PARAM
  300. # define __LOCALE_ARG
  301. # define __LOCALE_PTR __UCLIBC_CURLOCALE
  302. #endif
  303. /**********************************************************************/
  304. #endif /* _LIBC */
  305. #endif /* !defined(__LOCALE_C_ONLY) */
  306. #endif /* _UCLIBC_LOCALE_H */