uClibc_locale.h 9.9 KB

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