uClibc_locale.h 6.9 KB

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