uClibc_locale.h 9.8 KB

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