uClibc_locale.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /* Copyright (C) 2002 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_WCHAR__
  32. #define __WCHAR_ENABLED
  33. #endif
  34. #ifdef __UCLIBC_HAS_LOCALE__
  35. #undef __LOCALE_C_ONLY
  36. #else /* __UCLIBC_HAS_LOCALE__ */
  37. #define __LOCALE_C_ONLY
  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(__WCHAR_ENABLED)
  52. /* TODO: This really needs to be somewhere else... */
  53. #include <limits.h>
  54. #include <stdint.h>
  55. #if WCHAR_MIN == 0
  56. typedef wchar_t __uwchar_t;
  57. #elif WCHAR_MAX <= USHRT_MAX
  58. typedef unsigned short __uwchar_t;
  59. #elif WCHAR_MAX <= UINT_MAX
  60. typedef unsigned int __uwchar_t;
  61. #elif WCHAR_MAX <= ULONG_MAX
  62. typedef unsigned long __uwchar_t;
  63. #elif defined(ULLONG_MAX) && (WCHAR_MAX <= ULLONG_MAX)
  64. typedef unsigned long long __uwchar_t;
  65. #elif WCHAR_MAX <= UINT_MAX
  66. typedef uintmax_t __uwchar_t;
  67. #else
  68. #error Can not determine an appropriate type for __uwchar_t!
  69. #endif
  70. #endif
  71. /**********************************************************************/
  72. #if defined(_LIBC) && !defined(__LOCALE_C_ONLY)
  73. #include <stddef.h>
  74. #include <stdint.h>
  75. #include <bits/uClibc_locale_data.h>
  76. extern void _locale_set(const unsigned char *p);
  77. extern void _locale_init(void);
  78. /* TODO: assumes 8-bit chars!!! */
  79. enum {
  80. __ctype_encoding_7_bit, /* C/POSIX */
  81. __ctype_encoding_utf8, /* UTF-8 */
  82. __ctype_encoding_8_bit /* for 8-bit codeset locales */
  83. };
  84. #define LOCALE_STRING_SIZE (2 * __LC_ALL + 2)
  85. /*
  86. * '#' + 2_per_category + '\0'
  87. * {locale row # : 0 = C|POSIX} + 0x8001
  88. * encoded in two chars as (((N+1) >> 8) | 0x80) and ((N+1) & 0xff)
  89. * so decode is ((((uint16_t)(*s & 0x7f)) << 8) + s[1]) - 1
  90. *
  91. * Note: 0s are not used as they are nul-terminators for strings.
  92. * Note: 0xff, 0xff is the encoding for a non-selected locale.
  93. * (see setlocale() below).
  94. * In particular, C/POSIX locale is '#' + "\x80\x01"}*LC_ALL + nul.
  95. */
  96. /* static unsigned char cur_locale[LOCALE_STRING_SIZE]; */
  97. typedef struct {
  98. /* int tables_loaded; */
  99. /* unsigned char lctypes[LOCALE_STRING_SIZE]; */
  100. unsigned char cur_locale[LOCALE_STRING_SIZE];
  101. /* NL_LANGINFO stuff. BEWARE ORDERING!!! must agree with NL_* constants! */
  102. /* Also, numeric must be followed by monetary and the items must be in
  103. * the "struct lconv" order. */
  104. uint16_t category_offsets[__LC_ALL]; /* TODO -- fix? */
  105. unsigned char category_item_count[__LC_ALL]; /* TODO - fix */
  106. /* ctype */
  107. unsigned char encoding; /* C/POSIX, 8-bit, UTF-8 */
  108. unsigned char mb_cur_max; /* determined by encoding _AND_ translit!!! */
  109. const char *codeset;
  110. #ifdef __CTYPE_HAS_8_BIT_LOCALES
  111. const unsigned char *idx8ctype;
  112. const unsigned char *tbl8ctype;
  113. const unsigned char *idx8uplow;
  114. const unsigned char *tbl8uplow;
  115. #ifdef __WCHAR_ENABLED
  116. const unsigned char *idx8c2wc;
  117. const uint16_t *tbl8c2wc; /* char > 0x7f to wide char */
  118. const unsigned char *idx8wc2c;
  119. const unsigned char *tbl8wc2c;
  120. /* translit */
  121. #endif /* __WCHAR_ENABLED */
  122. #endif /* __CTYPE_HAS_8_BIT_LOCALES */
  123. #ifdef __WCHAR_ENABLED
  124. const unsigned char *tblwctype;
  125. const unsigned char *tblwuplow;
  126. const unsigned char *tblwcomb;
  127. const int16_t *tblwuplow_diff; /* yes... signed */
  128. /* width?? */
  129. #endif /* __WCHAR_ENABLED */
  130. /* numeric */
  131. const char *decimal_point;
  132. const char *thousands_sep;
  133. const char *grouping;
  134. /* monetary */
  135. const char *int_curr_symbol;
  136. const char *currency_symbol;
  137. const char *mon_decimal_point;
  138. const char *mon_thousands_sep;
  139. const char *mon_grouping;
  140. const char *positive_sign;
  141. const char *negative_sign;
  142. const char *int_frac_digits;
  143. const char *frac_digits;
  144. const char *p_cs_precedes;
  145. const char *p_sep_by_space;
  146. const char *n_cs_precedes;
  147. const char *n_sep_by_space;
  148. const char *p_sign_posn;
  149. const char *n_sign_posn;
  150. const char *int_p_cs_precedes;
  151. const char *int_p_sep_by_space;
  152. const char *int_n_cs_precedes;
  153. const char *int_n_sep_by_space;
  154. const char *int_p_sign_posn;
  155. const char *int_n_sign_posn;
  156. const char *crncystr; /* not returned by localeconv */
  157. /* time */
  158. const char *abday_1;
  159. const char *abday_2;
  160. const char *abday_3;
  161. const char *abday_4;
  162. const char *abday_5;
  163. const char *abday_6;
  164. const char *abday_7;
  165. const char *day_1;
  166. const char *day_2;
  167. const char *day_3;
  168. const char *day_4;
  169. const char *day_5;
  170. const char *day_6;
  171. const char *day_7;
  172. const char *abmon_1;
  173. const char *abmon_2;
  174. const char *abmon_3;
  175. const char *abmon_4;
  176. const char *abmon_5;
  177. const char *abmon_6;
  178. const char *abmon_7;
  179. const char *abmon_8;
  180. const char *abmon_9;
  181. const char *abmon_10;
  182. const char *abmon_11;
  183. const char *abmon_12;
  184. const char *mon_1;
  185. const char *mon_2;
  186. const char *mon_3;
  187. const char *mon_4;
  188. const char *mon_5;
  189. const char *mon_6;
  190. const char *mon_7;
  191. const char *mon_8;
  192. const char *mon_9;
  193. const char *mon_10;
  194. const char *mon_11;
  195. const char *mon_12;
  196. const char *am_str;
  197. const char *pm_str;
  198. const char *d_t_fmt;
  199. const char *d_fmt;
  200. const char *t_fmt;
  201. const char *t_fmt_ampm;
  202. const char *era;
  203. const char *era_year; /* non SUSv3 */
  204. const char *era_d_fmt;
  205. const char *alt_digits;
  206. const char *era_d_t_fmt;
  207. const char *era_t_fmt;
  208. /* collate */
  209. /* messages */
  210. const char *yesexpr;
  211. const char *noexpr;
  212. } __locale_t;
  213. extern __locale_t __global_locale;
  214. #endif /* defined(_LIBC) && !defined(__LOCALE_C_ONLY) */
  215. #endif /* _UCLIBC_LOCALE_H */