ReactOS 0.4.15-dev-8339-g4028de8
japanese.c File Reference
#include <k32.h>
#include <debug.h>
#include "japanese.h"
Include dependency graph for japanese.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define JAPANESE_ERA_MAX   16
 

Functions

HANDLE NLS_RegOpenKey (HANDLE hRootKey, LPCWSTR szKeyName)
 
BOOL NLS_RegEnumValue (HANDLE hKey, UINT ulIndex, LPWSTR szValueName, ULONG valueNameSize, LPWSTR szValueData, ULONG valueDataSize)
 
void JapaneseEra_ClearCache (void)
 
static INT JapaneseEra_Compare (const void *e1, const void *e2)
 
BOOL JapaneseEra_IsFirstYearGannen (void)
 
static PCJAPANESE_ERA JapaneseEra_Load (DWORD *pdwCount)
 
static BOOL JapaneseEra_ToSystemTime (PCJAPANESE_ERA pEra, LPSYSTEMTIME pst)
 
PCJAPANESE_ERA JapaneseEra_Find (const SYSTEMTIME *pst OPTIONAL)
 

Variables

static BOOL s_bIsGannenCached = FALSE
 
static DWORD s_JapaneseEraCount = 0
 
static JAPANESE_ERA s_JapaneseEraTable [JAPANESE_ERA_MAX]
 

Macro Definition Documentation

◆ JAPANESE_ERA_MAX

#define JAPANESE_ERA_MAX   16

Definition at line 13 of file japanese.c.

◆ NDEBUG

#define NDEBUG

Definition at line 9 of file japanese.c.

Function Documentation

◆ JapaneseEra_ClearCache()

void JapaneseEra_ClearCache ( void  )

Definition at line 38 of file japanese.c.

39{
42}
#define FALSE
Definition: types.h:117
static BOOL s_bIsGannenCached
Definition: japanese.c:17
static DWORD s_JapaneseEraCount
Definition: japanese.c:18

Referenced by InvalidateNLSCache().

◆ JapaneseEra_Compare()

static INT JapaneseEra_Compare ( const void e1,
const void e2 
)
static

Definition at line 44 of file japanese.c.

45{
48 if (pEra1->wYear < pEra2->wYear)
49 return -1;
50 if (pEra1->wYear > pEra2->wYear)
51 return 1;
52 if (pEra1->wMonth < pEra2->wMonth)
53 return -1;
54 if (pEra1->wMonth > pEra2->wMonth)
55 return 1;
56 if (pEra1->wDay < pEra2->wDay)
57 return -1;
58 if (pEra1->wDay > pEra2->wDay)
59 return 1;
60 return 0;
61}
const JAPANESE_ERA * PCJAPANESE_ERA
Definition: japanese.h:19
WORD wDay
Definition: japanese.h:13
WORD wMonth
Definition: japanese.h:12
WORD wYear
Definition: japanese.h:11

Referenced by JapaneseEra_Load().

◆ JapaneseEra_Find()

PCJAPANESE_ERA JapaneseEra_Find ( const SYSTEMTIME *pst  OPTIONAL)

Definition at line 236 of file japanese.c.

237{
238 DWORD dwIndex, dwCount = 0;
239 PCJAPANESE_ERA pTable, pEntry, pPrevEntry = NULL;
240 SYSTEMTIME st1, st2;
241 FILETIME ft1, ft2;
242 LONG nCompare;
243
244 /* pst --> ft1 */
245 if (pst == NULL)
246 {
247 GetLocalTime(&st1);
248 pst = &st1;
249 }
250 SystemTimeToFileTime(pst, &ft1);
251
252 /* load era table */
253 pTable = JapaneseEra_Load(&dwCount);
254 if (pTable == NULL || dwCount == 0 || dwCount > JAPANESE_ERA_MAX)
255 {
256 return NULL;
257 }
258
259 /* for all eras */
260 for (dwIndex = 0; dwIndex < dwCount; dwIndex++)
261 {
262 pEntry = &pTable[dwIndex];
263
264 /* pEntry --> st2 --> ft2 */
266 SystemTimeToFileTime(&st2, &ft2);
267
268 /* ft1 <=> ft2 */
269 nCompare = CompareFileTime(&ft1, &ft2);
270 if (nCompare == 0)
271 return pEntry;
272 if (nCompare < 0)
273 return pPrevEntry;
274 pPrevEntry = pEntry;
275 }
276
277 return pPrevEntry;
278}
#define NULL
Definition: types.h:112
BOOL WINAPI SystemTimeToFileTime(IN CONST SYSTEMTIME *lpSystemTime, OUT LPFILETIME lpFileTime)
Definition: time.c:158
LONG WINAPI CompareFileTime(IN CONST FILETIME *lpFileTime1, IN CONST FILETIME *lpFileTime2)
Definition: time.c:106
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:286
unsigned long DWORD
Definition: ntddk_ex.h:95
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
static PCJAPANESE_ERA JapaneseEra_Load(DWORD *pdwCount)
Definition: japanese.c:110
#define JAPANESE_ERA_MAX
Definition: japanese.c:13
static BOOL JapaneseEra_ToSystemTime(PCJAPANESE_ERA pEra, LPSYSTEMTIME pst)
Definition: japanese.c:224
long LONG
Definition: pedump.c:60
static const EHCI_PERIOD pTable[]
Definition: usbehci.c:29

Referenced by GetCalendarInfoW(), and NLS_GetDateTimeFormatW().

◆ JapaneseEra_IsFirstYearGannen()

BOOL JapaneseEra_IsFirstYearGannen ( void  )

Definition at line 63 of file japanese.c.

64{
65#ifdef DONT_USE_REGISTRY
66 return TRUE;
67#else
69 DWORD dwIndex;
70 WCHAR szName[32], szValue[32];
71 static BOOL s_bFirstIsGannen = TRUE;
72
74 return s_bFirstIsGannen;
75
76 KeyHandle = NLS_RegOpenKey(NULL, L"\\Registry\\Machine\\System\\"
77 L"CurrentControlSet\\Control\\Nls\\Calendars\\Japanese");
78 if (!KeyHandle)
79 return TRUE;
80
81 s_bFirstIsGannen = TRUE;
82 for (dwIndex = 0; dwIndex < 16; ++dwIndex)
83 {
84 if (!NLS_RegEnumValue(KeyHandle, dwIndex, szName, sizeof(szName),
85 szValue, sizeof(szValue)))
86 {
87 break;
88 }
89
90 if (lstrcmpiW(szName, L"InitialEraYear") == 0)
91 {
92 s_bFirstIsGannen = (szValue[0] == 0x5143);
93 break;
94 }
95 }
96
98
100
101 return s_bFirstIsGannen;
102#endif
103}
#define TRUE
Definition: types.h:120
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4261
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL NLS_RegEnumValue(HANDLE hKey, UINT ulIndex, LPWSTR szValueName, ULONG valueNameSize, LPWSTR szValueData, ULONG valueDataSize)
HANDLE NLS_RegOpenKey(HANDLE hRootKey, LPCWSTR szKeyName)
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define L(x)
Definition: ntvdm.h:50
static const WCHAR szName[]
Definition: powrprof.c:45
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by NLS_GetDateTimeFormatW().

◆ JapaneseEra_Load()

static PCJAPANESE_ERA JapaneseEra_Load ( DWORD pdwCount)
static

Definition at line 110 of file japanese.c.

111{
112#ifndef DONT_USE_REGISTRY
114 DWORD dwIndex;
115 WCHAR szName[128], szValue[128];
117 LPWSTR pch1, pch2, pch3, pch4;
118#endif
119
120 ASSERT(pdwCount != NULL);
121
122 /* return cache if any */
123 if (s_JapaneseEraCount != 0)
124 {
125 *pdwCount = s_JapaneseEraCount;
126 return s_JapaneseEraTable;
127 }
128
129#ifdef DONT_USE_REGISTRY
131#else
132 /* init */
133 *pdwCount = 0;
135
136 /* open registry key */
137 KeyHandle = NLS_RegOpenKey(NULL, L"\\Registry\\Machine\\System\\"
138 L"CurrentControlSet\\Control\\Nls\\Calendars\\Japanese\\Eras");
139 if (!KeyHandle)
140 return NULL;
141
142 /* for all values */
143 for (dwIndex = 0; dwIndex < JAPANESE_ERA_MAX; ++dwIndex)
144 {
145 pEntry = &s_JapaneseEraTable[dwIndex];
146
147 /* get name and data */
148 if (!NLS_RegEnumValue(KeyHandle, dwIndex, szName, sizeof(szName),
149 szValue, sizeof(szValue)))
150 {
151 break;
152 }
153
154 /* split fields */
155 pch1 = szName;
156 pch2 = wcschr(pch1, L' ');
157 if (pch2 == NULL)
158 {
159 break;
160 }
161 *pch2++ = UNICODE_NULL;
162
163 pch3 = wcschr(pch2, L' ');
164 if (pch3 == NULL)
165 {
166 break;
167 }
168 *pch3++ = UNICODE_NULL;
169
170 pEntry->wYear = _wtoi(pch1);
171 pEntry->wMonth = _wtoi(pch2);
172 pEntry->wDay = _wtoi(pch3);
173 if (pEntry->wYear == 0 || pEntry->wMonth == 0 || pEntry->wDay == 0)
174 {
175 break;
176 }
177
178 /* split fields */
179 pch1 = szValue;
180 pch2 = wcschr(pch1, L'_');
181 if (pch2 == NULL)
182 {
183 break;
184 }
185 *pch2++ = UNICODE_NULL;
186
187 pch3 = wcschr(pch2, L'_');
188 if (pch3 == NULL)
189 {
190 break;
191 }
192 *pch3++ = UNICODE_NULL;
193
194 pch4 = wcschr(pch3, L'_');
195 if (pch4 == NULL)
196 {
197 break;
198 }
199 *pch4++ = UNICODE_NULL;
200
201 /* store */
202 RtlStringCbCopyW(pEntry->szEraName, sizeof(pEntry->szEraName), pch1);
203 RtlStringCbCopyW(pEntry->szEraAbbrev, sizeof(pEntry->szEraAbbrev), pch2);
204 RtlStringCbCopyW(pEntry->szEnglishEraName, sizeof(pEntry->szEnglishEraName), pch3);
205 RtlStringCbCopyW(pEntry->szEnglishEraAbbrev, sizeof(pEntry->szEnglishEraAbbrev), pch4);
206 }
207
208 /* close key */
210
211 /* sort */
214
215 /* make cache */
216 s_JapaneseEraCount = dwIndex;
217#endif
218
219 *pdwCount = s_JapaneseEraCount;
220
221 return s_JapaneseEraTable;
222}
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define wcschr
Definition: compat.h:17
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
static INT JapaneseEra_Compare(const void *e1, const void *e2)
Definition: japanese.c:44
static JAPANESE_ERA s_JapaneseEraTable[JAPANESE_ERA_MAX]
Definition: japanese.c:30
#define ASSERT(a)
Definition: mode.c:44
#define UNICODE_NULL
NTSTRSAFEAPI RtlStringCbCopyW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:174
void __cdecl qsort(_Inout_updates_bytes_(_NumOfElements *_SizeOfElements) void *_Base, _In_ size_t _NumOfElements, _In_ size_t _SizeOfElements, _In_ int(__cdecl *_PtFuncCompare)(const void *, const void *))
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by JapaneseEra_Find().

◆ JapaneseEra_ToSystemTime()

static BOOL JapaneseEra_ToSystemTime ( PCJAPANESE_ERA  pEra,
LPSYSTEMTIME  pst 
)
static

Definition at line 224 of file japanese.c.

225{
226 ASSERT(pEra != NULL);
227 ASSERT(pst != NULL);
228
229 ZeroMemory(pst, sizeof(*pst));
230 pst->wYear = pEra->wYear;
231 pst->wMonth = pEra->wMonth;
232 pst->wDay = pEra->wDay;
233 return TRUE;
234}
WORD wYear
Definition: winbase.h:905
WORD wMonth
Definition: winbase.h:906
WORD wDay
Definition: winbase.h:908
#define ZeroMemory
Definition: winbase.h:1712

Referenced by JapaneseEra_Find().

◆ NLS_RegEnumValue()

BOOL NLS_RegEnumValue ( HANDLE  hKey,
UINT  ulIndex,
LPWSTR  szValueName,
ULONG  valueNameSize,
LPWSTR  szValueData,
ULONG  valueDataSize 
)

◆ NLS_RegOpenKey()

HANDLE NLS_RegOpenKey ( HANDLE  hRootKey,
LPCWSTR  szKeyName 
)

Variable Documentation

◆ s_bIsGannenCached

BOOL s_bIsGannenCached = FALSE
static

Definition at line 17 of file japanese.c.

Referenced by JapaneseEra_ClearCache(), and JapaneseEra_IsFirstYearGannen().

◆ s_JapaneseEraCount

DWORD s_JapaneseEraCount = 0
static

Definition at line 18 of file japanese.c.

Referenced by JapaneseEra_ClearCache(), and JapaneseEra_Load().

◆ s_JapaneseEraTable

JAPANESE_ERA s_JapaneseEraTable[JAPANESE_ERA_MAX]
static

Definition at line 19 of file japanese.c.

Referenced by JapaneseEra_Load().