1 #ifndef _LOCALE_IMPL_H 2 #define _LOCALE_IMPL_H 3 4 #include <locale.h> 5 #include <stdlib.h> 6 #include "libc.h" 7 #include "pthread_impl.h" 8 9 #define LOCALE_NAME_MAX 23 10 #define VALID 2 11 #define INVALID 1 12 #define ICU_VALID 3 13 14 struct __locale_map { 15 const void *map; 16 size_t map_size; 17 char name[LOCALE_NAME_MAX+1]; 18 const struct __locale_map *next; 19 char flag; 20 }; 21 22 extern hidden volatile int __locale_lock[1]; 23 24 extern hidden const struct __locale_map __c_dot_utf8; 25 extern hidden const struct __locale_struct __c_locale; 26 extern hidden const struct __locale_struct __c_dot_utf8_locale; 27 28 hidden const struct __locale_map *__get_locale(int, const char *); 29 hidden const char *__mo_lookup(const void *, size_t, const char *); 30 hidden const char *__lctrans(const char *, const struct __locale_map *); 31 hidden const char *__lctrans_cur(const char *); 32 hidden const char *__lctrans_impl(const char *, const struct __locale_map *); 33 hidden int __loc_is_allocated(locale_t); 34 hidden char *__gettextdomain(void); 35 36 #ifdef FEATURE_ICU_LOCALE 37 #define ICU_GET_VERSION_NUM_SYMBOL "GetIcuVersion" 38 #define ICU_SET_DATA_DIRECTORY_SYMBOL "SetOhosIcuDirectory" 39 #define ICU_UNUM_OPEN_SYMBOL "unum_open" 40 #define ICU_UNUM_CLOSE_SYMBOL "unum_close" 41 #define ICU_STR_FROM_UTF8_SYMBOL "u_strFromUTF8" 42 #define ICU_STR_FROM_UTF32_SYMBOL "u_strFromUTF32" 43 #define ICU_UNUM_PARSE_DOUBLE_SYMBOL "unum_parseDouble" 44 #define ICU_UNUM_GET_SYMBOL_SYMBOL "unum_getSymbol" 45 #define ICU_AUSTRNCPY_SYMBOL "u_austrncpy" 46 #ifdef FEATURE_ICU_LOCALE_TMP 47 #define ICU_UCHAR_ISALNUM_SYMBOL "u_isalnum" 48 #endif 49 50 typedef enum { 51 ICU_UC = 0, 52 ICU_I18N, 53 } icu_so_type; 54 55 #define MAX_VALID_ICU_NAME_LEN 8 56 typedef uint16_t u_char; 57 58 hidden void set_icu_directory(); 59 hidden void get_icu_symbol(icu_so_type type, void **icu_symbol_handle, const char *symbol_name); 60 hidden void get_valid_icu_locale_name(const char *name, const char *icu_name, int icu_name_len); 61 hidden void *icu_unum_open(char *icu_locale_name, int *cur_status); 62 hidden void icu_unum_close(void *fmt); 63 hidden double icu_parse_double(void *fmt, u_char *ustr, int32_t *parse_pos, int *cur_status); 64 65 typedef char *(*f_icuuc_get_icu_version)(void); 66 typedef void (*f_icuuc_u_set_data_directory)(void); 67 typedef void *(*f_icu18n_unum_open)(int, void *, int32_t, const char *, void *, void *); 68 typedef void (*f_icu18n_unum_close)(void *); 69 typedef void *(*f_icu18n_u_str_from_utf8)(u_char *, int32_t, int32_t *, const char *, int32_t, int *); 70 typedef void *(*f_icu18n_u_str_from_utf32)(u_char *, int32_t, int32_t *, const wchar_t *, int32_t, int *); 71 typedef double (*f_icu18n_unum_parse_double)(void *, u_char *, int32_t, int32_t *, int *); 72 typedef int32_t(*f_icu18n_unum_get_symbol)(const void *, int, u_char *, int32_t, int *); 73 typedef char *(*f_icuuc_u_austrncpy)(char *, const u_char *, int32_t); 74 #ifdef FEATURE_ICU_LOCALE_TMP 75 typedef int(*f_icu18n_u_isalnum)(int c); 76 #endif 77 78 struct icu_opt_func { 79 f_icuuc_get_icu_version get_icu_version; 80 f_icuuc_u_set_data_directory set_data_directory; 81 f_icu18n_unum_open unum_open; 82 f_icu18n_unum_close unum_close; 83 f_icu18n_u_str_from_utf8 u_str_from_utf8; 84 f_icu18n_u_str_from_utf32 u_str_from_utf32; 85 f_icu18n_unum_parse_double unum_parse_double; 86 f_icu18n_unum_get_symbol unum_get_symbol; 87 f_icuuc_u_austrncpy u_austrncpy; 88 #ifdef FEATURE_ICU_LOCALE_TMP 89 f_icu18n_u_isalnum u_isalnum; 90 #endif 91 }; 92 extern hidden struct icu_opt_func g_icu_opt_func; 93 94 #define DLSYM_ICU_SUCC 0 95 #define DLSYM_ICU_FAIL 1 96 #define ICU_ERROR (-1) 97 #endif 98 99 #define LOC_MAP_FAILED ((const struct __locale_map *)-1) 100 101 #define LCTRANS(msg, lc, loc) __lctrans(msg, (loc)->cat[(lc)]) 102 #define LCTRANS_CUR(msg) __lctrans_cur(msg) 103 104 #define C_LOCALE ((locale_t)&__c_locale) 105 #define UTF8_LOCALE ((locale_t)&__c_dot_utf8_locale) 106 107 #define CURRENT_LOCALE (__pthread_self()->locale) 108 109 #define CURRENT_UTF8 (!!__pthread_self()->locale->cat[LC_CTYPE]) 110 111 #undef MB_CUR_MAX 112 #define MB_CUR_MAX (CURRENT_UTF8 ? 4 : 1) 113 114 #endif 115