1 /* 2 * Copyright 2010-2011, Oliver Tappe, zooey@hirschkaefer.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _LOCALE_BACKEND_H 6 #define _LOCALE_BACKEND_H 7 8 9 #include <SupportDefs.h> 10 11 #include <time.h> 12 #include <wctype.h> 13 14 15 struct lconv; 16 struct lc_time_t; 17 struct locale_data; // glibc 18 19 20 namespace BPrivate { 21 namespace Libroot { 22 23 24 struct LocaleCtypeDataBridge { 25 const unsigned short** addrOfClassInfoTable; 26 const int** addrOfToLowerTable; 27 const int** addrOfToUpperTable; 28 29 const unsigned short* posixClassInfo; 30 const int* posixToLowerMap; 31 const int* posixToUpperMap; 32 33 LocaleCtypeDataBridge(); 34 35 void setMbCurMax(unsigned short mbCurMax); 36 }; 37 38 39 struct LocaleMessagesDataBridge { 40 const char** posixLanginfo; 41 42 LocaleMessagesDataBridge(); 43 }; 44 45 46 struct LocaleMonetaryDataBridge { 47 const struct lconv* posixLocaleConv; 48 49 LocaleMonetaryDataBridge(); 50 }; 51 52 53 struct LocaleNumericDataBridge { 54 private: 55 // struct used by glibc to store numeric locale data 56 struct GlibcNumericLocale { 57 const char* name; 58 const char* filedata; 59 off_t filesize; 60 int mmaped; 61 unsigned int usage_count; 62 int use_translit; 63 const char *options; 64 unsigned int nstrings; 65 union locale_data_value 66 { 67 const uint32_t* wstr; 68 const char* string; 69 unsigned int word; 70 } 71 values[6]; 72 }; 73 locale_data* originalGlibcLocale; 74 75 public: 76 const struct lconv* posixLocaleConv; 77 GlibcNumericLocale glibcNumericLocale; 78 79 LocaleNumericDataBridge(); 80 ~LocaleNumericDataBridge(); 81 }; 82 83 84 struct LocaleTimeDataBridge { 85 const struct lc_time_t* posixLCTimeInfo; 86 87 LocaleTimeDataBridge(); 88 }; 89 90 91 struct TimeConversionDataBridge { 92 int* addrOfDaylight; 93 long* addrOfTimezone; 94 char** addrOfTZName; 95 96 TimeConversionDataBridge(); 97 }; 98 99 100 struct LocaleDataBridge { 101 LocaleCtypeDataBridge ctypeDataBridge; 102 LocaleMessagesDataBridge messagesDataBridge; 103 LocaleMonetaryDataBridge monetaryDataBridge; 104 LocaleNumericDataBridge numericDataBridge; 105 LocaleTimeDataBridge timeDataBridge; 106 TimeConversionDataBridge timeConversionDataBridge; 107 const char** posixLanginfo; 108 109 LocaleDataBridge(); 110 }; 111 112 113 class LocaleBackend { 114 public: 115 LocaleBackend(); 116 virtual ~LocaleBackend(); 117 118 virtual const char* SetLocale(int category, const char* locale) = 0; 119 virtual const struct lconv* LocaleConv() = 0; 120 virtual const struct lc_time_t* LCTimeInfo() = 0; 121 122 virtual int IsWCType(wint_t wc, wctype_t charClass) = 0; 123 virtual status_t ToWCTrans(wint_t wc, wctrans_t transition, 124 wint_t& result) = 0; 125 126 virtual status_t MultibyteToWchar(wchar_t* wcOut, const char* mb, 127 size_t mbLength, mbstate_t* mbState, 128 size_t& lengthOut) = 0; 129 virtual status_t WcharToMultibyte(char* mbOut, wchar_t wc, 130 mbstate_t* mbState, size_t& lengthOut) = 0; 131 132 virtual const char* GetLanginfo(int index) = 0; 133 134 virtual status_t Strcoll(const char* a, const char* b, 135 int& out) = 0; 136 virtual status_t Strxfrm(char* out, const char* in, size_t size, 137 size_t& outSize) = 0; 138 139 virtual status_t TZSet(const char* timeZoneID, 140 const char* tz) = 0; 141 virtual status_t Localtime(const time_t* inTime, 142 struct tm* tmOut) = 0; 143 virtual status_t Gmtime(const time_t* inTime, 144 struct tm* tmOut) = 0; 145 virtual status_t Mktime(struct tm* inOutTm, time_t& timeOut) = 0; 146 147 virtual void Initialize(LocaleDataBridge* dataBridge) = 0; 148 149 static status_t LoadBackend(); 150 }; 151 152 153 extern LocaleBackend* gLocaleBackend; 154 155 156 } // namespace Libroot 157 } // namespace BPrivate 158 159 160 #endif // _LOCALE_BACKEND_H 161