uClibc_locale.h 10 KB

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