1 | /* $Id: ole2nls.c,v 1.6 2003-04-02 12:58:30 sandervl Exp $
|
---|
2 | *
|
---|
3 | * National Language Support library
|
---|
4 | *
|
---|
5 | * Copyright 1995 Martin von Loewis
|
---|
6 | * Copyright 1998 David Lee Lambert
|
---|
7 | * Copyright 2000 Julio César Gázquez
|
---|
8 | */
|
---|
9 |
|
---|
10 | #ifdef __WIN32OS2__
|
---|
11 | #include <odin.h>
|
---|
12 | #include <odinwrap.h>
|
---|
13 |
|
---|
14 | #include <string.h>
|
---|
15 | #include <stdio.h>
|
---|
16 | #include <heapstring.h>
|
---|
17 | #include <ctype.h>
|
---|
18 | #include <wcstr.h>
|
---|
19 | #endif
|
---|
20 |
|
---|
21 | #include <string.h>
|
---|
22 | #include <stdio.h>
|
---|
23 | #include <ctype.h>
|
---|
24 | #include <stdlib.h>
|
---|
25 | #include <locale.h>
|
---|
26 |
|
---|
27 | #include "windef.h"
|
---|
28 | #include "winbase.h"
|
---|
29 | #include "wingdi.h"
|
---|
30 | #include "winuser.h"
|
---|
31 | #include "wine/unicode.h"
|
---|
32 | #include "heap.h"
|
---|
33 | #include "options.h"
|
---|
34 | #include "winver.h"
|
---|
35 | #include "winnls.h"
|
---|
36 | #include "winreg.h"
|
---|
37 | #include "winerror.h"
|
---|
38 | #include "debugtools.h"
|
---|
39 |
|
---|
40 | #ifdef __WIN32OS2__
|
---|
41 | #include <wctype.h>
|
---|
42 | #include <unicode.h>
|
---|
43 |
|
---|
44 | #define DBG_LOCALLOG DBG_kernel32
|
---|
45 | #include "dbglocal.h"
|
---|
46 |
|
---|
47 | ODINDEBUGCHANNEL(KERNEL32-OLE2NLS)
|
---|
48 | #endif
|
---|
49 |
|
---|
50 | DEFAULT_DEBUG_CHANNEL(string);
|
---|
51 |
|
---|
52 | /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
|
---|
53 | * MUST contain all #defines from winnls.h
|
---|
54 | * last entry has NULL name, 0 id.
|
---|
55 | */
|
---|
56 | #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
|
---|
57 | static const struct tagLOCALE_NAME2ID {
|
---|
58 | const char *name;
|
---|
59 | LCTYPE id;
|
---|
60 | } locale_name2id[]= {
|
---|
61 | LOCALE_ENTRY(ILANGUAGE),
|
---|
62 | LOCALE_ENTRY(SLANGUAGE),
|
---|
63 | LOCALE_ENTRY(SENGLANGUAGE),
|
---|
64 | LOCALE_ENTRY(SABBREVLANGNAME),
|
---|
65 | LOCALE_ENTRY(SNATIVELANGNAME),
|
---|
66 | LOCALE_ENTRY(ICOUNTRY),
|
---|
67 | LOCALE_ENTRY(SCOUNTRY),
|
---|
68 | LOCALE_ENTRY(SENGCOUNTRY),
|
---|
69 | LOCALE_ENTRY(SABBREVCTRYNAME),
|
---|
70 | LOCALE_ENTRY(SNATIVECTRYNAME),
|
---|
71 | LOCALE_ENTRY(IDEFAULTLANGUAGE),
|
---|
72 | LOCALE_ENTRY(IDEFAULTCOUNTRY),
|
---|
73 | LOCALE_ENTRY(IDEFAULTCODEPAGE),
|
---|
74 | LOCALE_ENTRY(IDEFAULTANSICODEPAGE),
|
---|
75 | LOCALE_ENTRY(IDEFAULTMACCODEPAGE),
|
---|
76 | LOCALE_ENTRY(SLIST),
|
---|
77 | LOCALE_ENTRY(IMEASURE),
|
---|
78 | LOCALE_ENTRY(SDECIMAL),
|
---|
79 | LOCALE_ENTRY(STHOUSAND),
|
---|
80 | LOCALE_ENTRY(SGROUPING),
|
---|
81 | LOCALE_ENTRY(IDIGITS),
|
---|
82 | LOCALE_ENTRY(ILZERO),
|
---|
83 | LOCALE_ENTRY(INEGNUMBER),
|
---|
84 | LOCALE_ENTRY(SNATIVEDIGITS),
|
---|
85 | LOCALE_ENTRY(SCURRENCY),
|
---|
86 | LOCALE_ENTRY(SINTLSYMBOL),
|
---|
87 | LOCALE_ENTRY(SMONDECIMALSEP),
|
---|
88 | LOCALE_ENTRY(SMONTHOUSANDSEP),
|
---|
89 | LOCALE_ENTRY(SMONGROUPING),
|
---|
90 | LOCALE_ENTRY(ICURRDIGITS),
|
---|
91 | LOCALE_ENTRY(IINTLCURRDIGITS),
|
---|
92 | LOCALE_ENTRY(ICURRENCY),
|
---|
93 | LOCALE_ENTRY(INEGCURR),
|
---|
94 | LOCALE_ENTRY(SDATE),
|
---|
95 | LOCALE_ENTRY(STIME),
|
---|
96 | LOCALE_ENTRY(SSHORTDATE),
|
---|
97 | LOCALE_ENTRY(SLONGDATE),
|
---|
98 | LOCALE_ENTRY(STIMEFORMAT),
|
---|
99 | LOCALE_ENTRY(IDATE),
|
---|
100 | LOCALE_ENTRY(ILDATE),
|
---|
101 | LOCALE_ENTRY(ITIME),
|
---|
102 | LOCALE_ENTRY(ITIMEMARKPOSN),
|
---|
103 | LOCALE_ENTRY(ICENTURY),
|
---|
104 | LOCALE_ENTRY(ITLZERO),
|
---|
105 | LOCALE_ENTRY(IDAYLZERO),
|
---|
106 | LOCALE_ENTRY(IMONLZERO),
|
---|
107 | LOCALE_ENTRY(S1159),
|
---|
108 | LOCALE_ENTRY(S2359),
|
---|
109 | LOCALE_ENTRY(ICALENDARTYPE),
|
---|
110 | LOCALE_ENTRY(IOPTIONALCALENDAR),
|
---|
111 | LOCALE_ENTRY(IFIRSTDAYOFWEEK),
|
---|
112 | LOCALE_ENTRY(IFIRSTWEEKOFYEAR),
|
---|
113 | LOCALE_ENTRY(SDAYNAME1),
|
---|
114 | LOCALE_ENTRY(SDAYNAME2),
|
---|
115 | LOCALE_ENTRY(SDAYNAME3),
|
---|
116 | LOCALE_ENTRY(SDAYNAME4),
|
---|
117 | LOCALE_ENTRY(SDAYNAME5),
|
---|
118 | LOCALE_ENTRY(SDAYNAME6),
|
---|
119 | LOCALE_ENTRY(SDAYNAME7),
|
---|
120 | LOCALE_ENTRY(SABBREVDAYNAME1),
|
---|
121 | LOCALE_ENTRY(SABBREVDAYNAME2),
|
---|
122 | LOCALE_ENTRY(SABBREVDAYNAME3),
|
---|
123 | LOCALE_ENTRY(SABBREVDAYNAME4),
|
---|
124 | LOCALE_ENTRY(SABBREVDAYNAME5),
|
---|
125 | LOCALE_ENTRY(SABBREVDAYNAME6),
|
---|
126 | LOCALE_ENTRY(SABBREVDAYNAME7),
|
---|
127 | LOCALE_ENTRY(SMONTHNAME1),
|
---|
128 | LOCALE_ENTRY(SMONTHNAME2),
|
---|
129 | LOCALE_ENTRY(SMONTHNAME3),
|
---|
130 | LOCALE_ENTRY(SMONTHNAME4),
|
---|
131 | LOCALE_ENTRY(SMONTHNAME5),
|
---|
132 | LOCALE_ENTRY(SMONTHNAME6),
|
---|
133 | LOCALE_ENTRY(SMONTHNAME7),
|
---|
134 | LOCALE_ENTRY(SMONTHNAME8),
|
---|
135 | LOCALE_ENTRY(SMONTHNAME9),
|
---|
136 | LOCALE_ENTRY(SMONTHNAME10),
|
---|
137 | LOCALE_ENTRY(SMONTHNAME11),
|
---|
138 | LOCALE_ENTRY(SMONTHNAME12),
|
---|
139 | LOCALE_ENTRY(SMONTHNAME13),
|
---|
140 | LOCALE_ENTRY(SABBREVMONTHNAME1),
|
---|
141 | LOCALE_ENTRY(SABBREVMONTHNAME2),
|
---|
142 | LOCALE_ENTRY(SABBREVMONTHNAME3),
|
---|
143 | LOCALE_ENTRY(SABBREVMONTHNAME4),
|
---|
144 | LOCALE_ENTRY(SABBREVMONTHNAME5),
|
---|
145 | LOCALE_ENTRY(SABBREVMONTHNAME6),
|
---|
146 | LOCALE_ENTRY(SABBREVMONTHNAME7),
|
---|
147 | LOCALE_ENTRY(SABBREVMONTHNAME8),
|
---|
148 | LOCALE_ENTRY(SABBREVMONTHNAME9),
|
---|
149 | LOCALE_ENTRY(SABBREVMONTHNAME10),
|
---|
150 | LOCALE_ENTRY(SABBREVMONTHNAME11),
|
---|
151 | LOCALE_ENTRY(SABBREVMONTHNAME12),
|
---|
152 | LOCALE_ENTRY(SABBREVMONTHNAME13),
|
---|
153 | LOCALE_ENTRY(SPOSITIVESIGN),
|
---|
154 | LOCALE_ENTRY(SNEGATIVESIGN),
|
---|
155 | LOCALE_ENTRY(IPOSSIGNPOSN),
|
---|
156 | LOCALE_ENTRY(INEGSIGNPOSN),
|
---|
157 | LOCALE_ENTRY(IPOSSYMPRECEDES),
|
---|
158 | LOCALE_ENTRY(IPOSSEPBYSPACE),
|
---|
159 | LOCALE_ENTRY(INEGSYMPRECEDES),
|
---|
160 | LOCALE_ENTRY(INEGSEPBYSPACE),
|
---|
161 | LOCALE_ENTRY(FONTSIGNATURE),
|
---|
162 | LOCALE_ENTRY(SISO639LANGNAME),
|
---|
163 | LOCALE_ENTRY(SISO3166CTRYNAME),
|
---|
164 | {NULL,0}
|
---|
165 | };
|
---|
166 |
|
---|
167 | static char *GetLocaleSubkeyName( DWORD lctype );
|
---|
168 |
|
---|
169 | #ifndef __WIN32OS2__
|
---|
170 | /***********************************************************************
|
---|
171 | * GetUserDefaultLCID (KERNEL32.@)
|
---|
172 | * GetUserDefaultLCID (OLE2NLS.1)
|
---|
173 | */
|
---|
174 | LCID WINAPI GetUserDefaultLCID(void)
|
---|
175 | {
|
---|
176 | return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT );
|
---|
177 | }
|
---|
178 |
|
---|
179 | /***********************************************************************
|
---|
180 | * GetSystemDefaultLCID (KERNEL32.@)
|
---|
181 | * GetSystemDefaultLCID (OLE2NLS.2)
|
---|
182 | */
|
---|
183 | LCID WINAPI GetSystemDefaultLCID(void)
|
---|
184 | {
|
---|
185 | return GetUserDefaultLCID();
|
---|
186 | }
|
---|
187 | #endif //__WIN32OS2__
|
---|
188 |
|
---|
189 | #define NLS_MAX_LANGUAGES 20
|
---|
190 | typedef struct {
|
---|
191 | char lang[128];
|
---|
192 | char country[128];
|
---|
193 | LANGID found_lang_id[NLS_MAX_LANGUAGES];
|
---|
194 | char found_language[NLS_MAX_LANGUAGES][3];
|
---|
195 | char found_country[NLS_MAX_LANGUAGES][3];
|
---|
196 | int n_found;
|
---|
197 | } LANG_FIND_DATA;
|
---|
198 |
|
---|
199 | static BOOL CALLBACK NLS_FindLanguageID_ProcA(HMODULE hModule, LPCSTR type,
|
---|
200 | LPCSTR name, WORD LangID, LONG lParam)
|
---|
201 | {
|
---|
202 | LANG_FIND_DATA *l_data = (LANG_FIND_DATA *)lParam;
|
---|
203 | LCID lcid = MAKELCID(LangID, SORT_DEFAULT);
|
---|
204 | char buf_language[128];
|
---|
205 | char buf_country[128];
|
---|
206 | char buf_en_language[128];
|
---|
207 |
|
---|
208 | TRACE("%04X\n", (UINT)LangID);
|
---|
209 | if(PRIMARYLANGID(LangID) == LANG_NEUTRAL)
|
---|
210 | return TRUE; /* continue search */
|
---|
211 |
|
---|
212 | buf_language[0] = 0;
|
---|
213 | buf_country[0] = 0;
|
---|
214 |
|
---|
215 | GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME|LOCALE_NOUSEROVERRIDE,
|
---|
216 | buf_language, sizeof(buf_language));
|
---|
217 | TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language);
|
---|
218 |
|
---|
219 | GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME|LOCALE_NOUSEROVERRIDE,
|
---|
220 | buf_country, sizeof(buf_country));
|
---|
221 | TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country);
|
---|
222 |
|
---|
223 | if(l_data->lang && strlen(l_data->lang) > 0 && !strcasecmp(l_data->lang, buf_language))
|
---|
224 | {
|
---|
225 | if(l_data->country && strlen(l_data->country) > 0)
|
---|
226 | {
|
---|
227 | if(!strcasecmp(l_data->country, buf_country))
|
---|
228 | {
|
---|
229 | l_data->found_lang_id[0] = LangID;
|
---|
230 | l_data->n_found = 1;
|
---|
231 | TRACE("Found lang_id %04X for %s_%s\n", LangID, l_data->lang, l_data->country);
|
---|
232 | return FALSE; /* stop enumeration */
|
---|
233 | }
|
---|
234 | }
|
---|
235 | else /* l_data->country not specified */
|
---|
236 | {
|
---|
237 | if(l_data->n_found < NLS_MAX_LANGUAGES)
|
---|
238 | {
|
---|
239 | l_data->found_lang_id[l_data->n_found] = LangID;
|
---|
240 | strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
|
---|
241 | strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
|
---|
242 | l_data->n_found++;
|
---|
243 | TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
|
---|
244 | return TRUE; /* continue search */
|
---|
245 | }
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | /* Just in case, check LOCALE_SENGLANGUAGE too,
|
---|
250 | * in hope that possible alias name might have that value.
|
---|
251 | */
|
---|
252 | buf_en_language[0] = 0;
|
---|
253 | GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE|LOCALE_NOUSEROVERRIDE,
|
---|
254 | buf_en_language, sizeof(buf_en_language));
|
---|
255 | TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language);
|
---|
256 |
|
---|
257 | if(l_data->lang && strlen(l_data->lang) > 0 && !strcasecmp(l_data->lang, buf_en_language))
|
---|
258 | {
|
---|
259 | l_data->found_lang_id[l_data->n_found] = LangID;
|
---|
260 | strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
|
---|
261 | strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
|
---|
262 | l_data->n_found++;
|
---|
263 | TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
|
---|
264 | }
|
---|
265 |
|
---|
266 | return TRUE; /* continue search */
|
---|
267 | }
|
---|
268 |
|
---|
269 | /***********************************************************************
|
---|
270 | * NLS_GetLanguageID
|
---|
271 | *
|
---|
272 | * INPUT:
|
---|
273 | * Lang: a string whose two first chars are the iso name of a language.
|
---|
274 | * Country: a string whose two first chars are the iso name of country
|
---|
275 | * Charset: a string defining the chossen charset encoding
|
---|
276 | * Dialect: a string defining a variation of the locale
|
---|
277 | *
|
---|
278 | * all those values are from the standardized format of locale
|
---|
279 | * name in unix which is: Lang[_Country][.Charset][@Dialect]
|
---|
280 | *
|
---|
281 | * RETURNS:
|
---|
282 | * the numeric code of the language used by Windows
|
---|
283 | *
|
---|
284 | * FIXME: Charset and Dialect are not handled
|
---|
285 | */
|
---|
286 | static LANGID NLS_GetLanguageID(LPCSTR Lang, LPCSTR Country, LPCSTR Charset, LPCSTR Dialect)
|
---|
287 | {
|
---|
288 | LANG_FIND_DATA l_data;
|
---|
289 | char lang_string[256];
|
---|
290 |
|
---|
291 | if(!Lang)
|
---|
292 | {
|
---|
293 | l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
|
---|
294 | goto END;
|
---|
295 | }
|
---|
296 |
|
---|
297 | memset(&l_data, 0, sizeof(LANG_FIND_DATA));
|
---|
298 | strncpy(l_data.lang, Lang, sizeof(l_data.lang));
|
---|
299 |
|
---|
300 | if(Country && strlen(Country) > 0)
|
---|
301 | strncpy(l_data.country, Country, sizeof(l_data.country));
|
---|
302 |
|
---|
303 | EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
|
---|
304 | (LPCSTR)LOCALE_ILANGUAGE, NLS_FindLanguageID_ProcA, (LONG)&l_data);
|
---|
305 |
|
---|
306 | strcpy(lang_string, l_data.lang);
|
---|
307 | if(l_data.country && strlen(l_data.country) > 0)
|
---|
308 | {
|
---|
309 | strcat(lang_string, "_");
|
---|
310 | strcat(lang_string, l_data.country);
|
---|
311 | }
|
---|
312 |
|
---|
313 | if(!l_data.n_found)
|
---|
314 | {
|
---|
315 | if(l_data.country && strlen(l_data.country) > 0)
|
---|
316 | {
|
---|
317 | MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string);
|
---|
318 | l_data.country[0] = 0;
|
---|
319 | EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
|
---|
320 | (LPCSTR)LOCALE_ILANGUAGE, NLS_FindLanguageID_ProcA, (LONG)&l_data);
|
---|
321 | }
|
---|
322 | }
|
---|
323 |
|
---|
324 | /* Re-evaluate lang_string */
|
---|
325 | strcpy(lang_string, l_data.lang);
|
---|
326 | if(l_data.country && strlen(l_data.country) > 0)
|
---|
327 | {
|
---|
328 | strcat(lang_string, "_");
|
---|
329 | strcat(lang_string, l_data.country);
|
---|
330 | }
|
---|
331 |
|
---|
332 | if(!l_data.n_found)
|
---|
333 | {
|
---|
334 | MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string);
|
---|
335 | l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
|
---|
336 | }
|
---|
337 | else
|
---|
338 | {
|
---|
339 | if(l_data.n_found == 1)
|
---|
340 | TRACE("For language '%s' lang_id %04X was found\n", lang_string, l_data.found_lang_id[0]);
|
---|
341 | else /* l_data->n_found > 1 */
|
---|
342 | {
|
---|
343 | int i;
|
---|
344 | MESSAGE("For language '%s' several language ids were found:\n", lang_string);
|
---|
345 | for(i = 0; i < l_data.n_found; i++)
|
---|
346 | MESSAGE("%s_%s - %04X; ", l_data.found_language[i], l_data.found_country[i], l_data.found_lang_id[i]);
|
---|
347 |
|
---|
348 | MESSAGE("\nInstead of using first in the list, suggest to define\n"
|
---|
349 | "your LANG environment variable like this: LANG=%s_%s\n",
|
---|
350 | l_data.found_language[0], l_data.found_country[0]);
|
---|
351 | }
|
---|
352 | }
|
---|
353 | END:
|
---|
354 | TRACE("Returning %04X\n", l_data.found_lang_id[0]);
|
---|
355 | return l_data.found_lang_id[0];
|
---|
356 | }
|
---|
357 | #ifndef __WIN32OS2__
|
---|
358 | /***********************************************************************
|
---|
359 | * GetUserDefaultLangID (KERNEL32.@)
|
---|
360 | * GetUserDefaultLangID (OLE2NLS.3)
|
---|
361 | */
|
---|
362 | LANGID WINAPI GetUserDefaultLangID(void)
|
---|
363 | {
|
---|
364 | /* caching result, if defined from environment, which should (?) not change during a WINE session */
|
---|
365 | static LANGID userLCID = 0;
|
---|
366 |
|
---|
367 | if (userLCID == 0)
|
---|
368 | {
|
---|
369 | char buf[256];
|
---|
370 | char *lang,*country,*charset,*dialect,*next;
|
---|
371 |
|
---|
372 | if (GetEnvironmentVariableA( "LANGUAGE", buf, sizeof(buf) )) goto ok;
|
---|
373 | if (GetEnvironmentVariableA( "LANG", buf, sizeof(buf) )) goto ok;
|
---|
374 | if (GetEnvironmentVariableA( "LC_ALL", buf, sizeof(buf) )) goto ok;
|
---|
375 | if (GetEnvironmentVariableA( "LC_MESSAGES", buf, sizeof(buf) )) goto ok;
|
---|
376 | if (GetEnvironmentVariableA( "LC_CTYPE", buf, sizeof(buf) )) goto ok;
|
---|
377 |
|
---|
378 | return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
|
---|
379 |
|
---|
380 | ok:
|
---|
381 | if (!strcmp(buf,"POSIX") || !strcmp(buf,"C"))
|
---|
382 | return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
|
---|
383 |
|
---|
384 | lang=buf;
|
---|
385 |
|
---|
386 | do {
|
---|
387 | next=strchr(lang,':'); if (next) *next++='\0';
|
---|
388 | dialect=strchr(lang,'@'); if (dialect) *dialect++='\0';
|
---|
389 | charset=strchr(lang,'.'); if (charset) *charset++='\0';
|
---|
390 | country=strchr(lang,'_'); if (country) *country++='\0';
|
---|
391 |
|
---|
392 | userLCID = NLS_GetLanguageID(lang, country, charset, dialect);
|
---|
393 |
|
---|
394 | lang=next;
|
---|
395 | } while (lang && !userLCID);
|
---|
396 |
|
---|
397 | if (!userLCID)
|
---|
398 | {
|
---|
399 | MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
|
---|
400 | buf );
|
---|
401 | userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
|
---|
402 | }
|
---|
403 | }
|
---|
404 | return userLCID;
|
---|
405 | }
|
---|
406 |
|
---|
407 | /***********************************************************************
|
---|
408 | * GetSystemDefaultLangID (KERNEL32.@)
|
---|
409 | * GetSystemDefaultLangID (OLE2NLS.4)
|
---|
410 | */
|
---|
411 | LANGID WINAPI GetSystemDefaultLangID(void)
|
---|
412 | {
|
---|
413 | return GetUserDefaultLangID();
|
---|
414 | }
|
---|
415 | #endif //__WIN32OS2__
|
---|
416 | /******************************************************************************
|
---|
417 | * ConvertDefaultLocale (KERNEL32.@)
|
---|
418 | */
|
---|
419 | LCID WINAPI ConvertDefaultLocale (LCID lcid)
|
---|
420 | { switch (lcid)
|
---|
421 | { case LOCALE_SYSTEM_DEFAULT:
|
---|
422 | return GetSystemDefaultLCID();
|
---|
423 | case LOCALE_USER_DEFAULT:
|
---|
424 | return GetUserDefaultLCID();
|
---|
425 | case LOCALE_NEUTRAL:
|
---|
426 | return MAKELCID (LANG_NEUTRAL, SUBLANG_NEUTRAL);
|
---|
427 | }
|
---|
428 | return MAKELANGID( PRIMARYLANGID(lcid), SUBLANG_NEUTRAL);
|
---|
429 | }
|
---|
430 |
|
---|
431 | /* Enhanced version of LoadStringW.
|
---|
432 | * It takes LanguageId to find and load language dependant resources.
|
---|
433 | * Resource is copied as is: "binary" strings are not truncated.
|
---|
434 | * Return: length of resource + 1 to distinguish absent resources
|
---|
435 | * from the resources with zero length.
|
---|
436 | */
|
---|
437 | static INT NLS_LoadStringExW(HMODULE hModule, LANGID lang_id, UINT res_id, LPWSTR buffer, INT buflen)
|
---|
438 | {
|
---|
439 | HRSRC hrsrc;
|
---|
440 | HGLOBAL hmem;
|
---|
441 | WCHAR *p;
|
---|
442 | int string_num;
|
---|
443 | int i;
|
---|
444 |
|
---|
445 | /* Replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
|
---|
446 | if(SUBLANGID(lang_id) == SUBLANG_NEUTRAL)
|
---|
447 | lang_id = MAKELANGID(PRIMARYLANGID(lang_id), SUBLANG_DEFAULT);
|
---|
448 |
|
---|
449 | hrsrc = FindResourceExW(hModule, RT_STRINGW, (LPCWSTR)((res_id >> 4) + 1), lang_id);
|
---|
450 |
|
---|
451 | if(!hrsrc) return 0;
|
---|
452 | hmem = LoadResource(hModule, hrsrc);
|
---|
453 | if(!hmem) return 0;
|
---|
454 |
|
---|
455 | p = LockResource(hmem);
|
---|
456 | string_num = res_id & 0x000f;
|
---|
457 | for(i = 0; i < string_num; i++)
|
---|
458 | p += *p + 1;
|
---|
459 |
|
---|
460 | TRACE("strlen = %d\n", (int)*p );
|
---|
461 |
|
---|
462 | if (buffer == NULL) return *p;
|
---|
463 | i = min(buflen - 1, *p);
|
---|
464 | if (i > 0) {
|
---|
465 | memcpy(buffer, p + 1, i * sizeof (WCHAR));
|
---|
466 | buffer[i] = (WCHAR) 0;
|
---|
467 | } else {
|
---|
468 | if (buflen > 1)
|
---|
469 | buffer[0] = (WCHAR) 0;
|
---|
470 | }
|
---|
471 |
|
---|
472 | FreeResource(hmem);
|
---|
473 | TRACE("%s loaded!\n", debugstr_w(buffer));
|
---|
474 | return (i + 1);
|
---|
475 | }
|
---|
476 |
|
---|
477 | /******************************************************************************
|
---|
478 | * GetLocaleInfoA (KERNEL32.@)
|
---|
479 | *
|
---|
480 | * NOTES
|
---|
481 | * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
|
---|
482 | *
|
---|
483 | * MS online documentation states that the string returned is NULL terminated
|
---|
484 | * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
|
---|
485 | * terminated string".
|
---|
486 | */
|
---|
487 | INT WINAPI GetLocaleInfoA(LCID lcid,LCTYPE LCType,LPSTR buf,INT len)
|
---|
488 | {
|
---|
489 | LPCSTR retString = NULL;
|
---|
490 | int found = 0, i;
|
---|
491 | char *pacKey;
|
---|
492 | char acBuffer[128];
|
---|
493 | DWORD dwBufferSize=128;
|
---|
494 | BOOL NoUserOverride;
|
---|
495 |
|
---|
496 | TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid,LCType,buf,len);
|
---|
497 |
|
---|
498 | if (len && (! buf) ) {
|
---|
499 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
500 | return 0;
|
---|
501 | }
|
---|
502 |
|
---|
503 | if (lcid == LOCALE_NEUTRAL || lcid == LANG_SYSTEM_DEFAULT)
|
---|
504 | {
|
---|
505 | lcid = GetSystemDefaultLCID();
|
---|
506 | }
|
---|
507 | else if (lcid == LANG_USER_DEFAULT) /*0x800*/
|
---|
508 | {
|
---|
509 | lcid = GetUserDefaultLCID();
|
---|
510 | }
|
---|
511 |
|
---|
512 | /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
|
---|
513 | from the registry. Instead, use system default values. */
|
---|
514 | NoUserOverride = (LCType & LOCALE_NOUSEROVERRIDE) != 0;
|
---|
515 |
|
---|
516 | LCType &= ~(LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP);
|
---|
517 |
|
---|
518 | /* First, check if it's in the registry. */
|
---|
519 | /* All user customized values are stored in the registry by SetLocaleInfo */
|
---|
520 | if ( !NoUserOverride && (pacKey = GetLocaleSubkeyName(LCType)) )
|
---|
521 | {
|
---|
522 | char acRealKey[128];
|
---|
523 | HKEY hKey;
|
---|
524 |
|
---|
525 | sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
|
---|
526 |
|
---|
527 | if ( RegOpenKeyExA( HKEY_CURRENT_USER, acRealKey,
|
---|
528 | 0, KEY_READ, &hKey) == ERROR_SUCCESS )
|
---|
529 | {
|
---|
530 | if ( RegQueryValueExA( hKey, NULL, NULL, NULL, (LPBYTE)acBuffer,
|
---|
531 | &dwBufferSize ) == ERROR_SUCCESS )
|
---|
532 | {
|
---|
533 | retString = acBuffer;
|
---|
534 | found = 1;
|
---|
535 | }
|
---|
536 | RegCloseKey(hKey);
|
---|
537 | }
|
---|
538 | }
|
---|
539 |
|
---|
540 | /* If not in the registry, get it from the NLS entries. */
|
---|
541 | if(!found) {
|
---|
542 | WCHAR wcBuffer[128];
|
---|
543 | int res_size;
|
---|
544 |
|
---|
545 | /* check if language is registered in the kernel32 resources */
|
---|
546 | #ifdef __WIN32OS2__
|
---|
547 | if((res_size = NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid),
|
---|
548 | LCType, wcBuffer, sizeof(wcBuffer)/sizeof(wcBuffer[0]))) > 1) {
|
---|
549 | #else
|
---|
550 | if((res_size = NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid),
|
---|
551 | LCType, wcBuffer, sizeof(wcBuffer)/sizeof(wcBuffer[0])))) {
|
---|
552 | #endif
|
---|
553 | WideCharToMultiByte(CP_ACP, 0, wcBuffer, res_size, acBuffer, dwBufferSize, NULL, NULL);
|
---|
554 | retString = acBuffer;
|
---|
555 | found = 1;
|
---|
556 | }
|
---|
557 |
|
---|
558 | #ifdef __WIN32OS2__
|
---|
559 | /* nls not found: try with English (United States) */
|
---|
560 | if(!found && (res_size = NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(0x0409),
|
---|
561 | LCType, wcBuffer, sizeof(wcBuffer)/sizeof(wcBuffer[0])))>1) {
|
---|
562 | WideCharToMultiByte(CP_ACP, 0, wcBuffer, res_size, acBuffer, dwBufferSize, NULL, NULL);
|
---|
563 | retString = acBuffer;
|
---|
564 | found = 1;
|
---|
565 | }
|
---|
566 | #endif
|
---|
567 | }
|
---|
568 |
|
---|
569 | /* if not found report a most descriptive error */
|
---|
570 | if(!found) {
|
---|
571 | retString=0;
|
---|
572 | /* If we are through all of this, retLen should not be zero anymore.
|
---|
573 | If it is, the value is not supported */
|
---|
574 | i=0;
|
---|
575 | while (locale_name2id[i].name!=NULL) {
|
---|
576 | if (LCType == locale_name2id[i].id) {
|
---|
577 | retString = locale_name2id[i].name;
|
---|
578 | break;
|
---|
579 | }
|
---|
580 | i++;
|
---|
581 | }
|
---|
582 | if(!retString)
|
---|
583 | FIXME("Unkown LC type %lX\n", LCType);
|
---|
584 | else
|
---|
585 | FIXME("'%s' is not defined for your language (%04X).\n"
|
---|
586 | "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
|
---|
587 | "and submit patch for inclusion into the next Wine release.\n",
|
---|
588 | retString, LOWORD(lcid));
|
---|
589 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
590 | return 0;
|
---|
591 | }
|
---|
592 |
|
---|
593 | /* a FONTSIGNATURE is not a string, just 6 DWORDs */
|
---|
594 | if (LCType == LOCALE_FONTSIGNATURE) {
|
---|
595 | if (len) {
|
---|
596 | len = (len < sizeof(FONTSIGNATURE)) ? len : sizeof(FONTSIGNATURE);
|
---|
597 | memcpy(buf, retString, len);
|
---|
598 | return len;
|
---|
599 | }
|
---|
600 | return sizeof(FONTSIGNATURE);
|
---|
601 | }
|
---|
602 | /* if len=0 return only the length, don't touch the buffer*/
|
---|
603 | if (len) {
|
---|
604 | lstrcpynA(buf,retString,len);
|
---|
605 | return strlen(buf) + 1;
|
---|
606 | }
|
---|
607 | return strlen(retString)+1;
|
---|
608 | }
|
---|
609 |
|
---|
610 | /******************************************************************************
|
---|
611 | * GetLocaleInfoW (KERNEL32.@)
|
---|
612 | *
|
---|
613 | * NOTES
|
---|
614 | * MS documentation states that len "specifies the size, in bytes (ANSI version)
|
---|
615 | * or characters (Unicode version), of" wbuf. Thus the number returned is
|
---|
616 | * the same between GetLocaleInfoW and GetLocaleInfoA.
|
---|
617 | */
|
---|
618 | INT WINAPI GetLocaleInfoW(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT len)
|
---|
619 | { WORD wlen;
|
---|
620 | LPSTR abuf;
|
---|
621 |
|
---|
622 | if (len && (! wbuf) )
|
---|
623 | { SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
624 | return 0;
|
---|
625 | }
|
---|
626 |
|
---|
627 | abuf = (LPSTR)HeapAlloc(GetProcessHeap(),0,len);
|
---|
628 | wlen = GetLocaleInfoA(lcid, LCType, abuf, len);
|
---|
629 |
|
---|
630 | if (wlen && len) /* if len=0 return only the length*/
|
---|
631 | MultiByteToWideChar( CP_ACP, 0, abuf, -1, wbuf, len );
|
---|
632 |
|
---|
633 | HeapFree(GetProcessHeap(),0,abuf);
|
---|
634 | return wlen;
|
---|
635 | }
|
---|
636 |
|
---|
637 |
|
---|
638 | /******************************************************************************
|
---|
639 | *
|
---|
640 | * GetLocaleSubkeyName [helper function]
|
---|
641 | *
|
---|
642 | * - For use with the registry.
|
---|
643 | * - Gets the registry subkey name for a given lctype.
|
---|
644 | */
|
---|
645 | static char *GetLocaleSubkeyName( DWORD lctype )
|
---|
646 | {
|
---|
647 | char *pacKey=NULL;
|
---|
648 |
|
---|
649 | switch ( lctype )
|
---|
650 | {
|
---|
651 | /* These values are used by SetLocaleInfo and GetLocaleInfo, and
|
---|
652 | * the values are stored in the registry, confirmed under Windows,
|
---|
653 | * for the ones that actually assign pacKey. Cases that aren't finished
|
---|
654 | * have not been confirmed, so that must be done before they can be
|
---|
655 | * added.
|
---|
656 | */
|
---|
657 | case LOCALE_SDATE : /* The date separator. */
|
---|
658 | pacKey = "sDate";
|
---|
659 | break;
|
---|
660 | case LOCALE_ICURRDIGITS:
|
---|
661 | pacKey = "iCurrDigits";
|
---|
662 | break;
|
---|
663 | case LOCALE_SDECIMAL :
|
---|
664 | pacKey = "sDecimal";
|
---|
665 | break;
|
---|
666 | case LOCALE_ICURRENCY:
|
---|
667 | pacKey = "iCurrency";
|
---|
668 | break;
|
---|
669 | case LOCALE_SGROUPING :
|
---|
670 | pacKey = "sGrouping";
|
---|
671 | break;
|
---|
672 | case LOCALE_IDIGITS:
|
---|
673 | pacKey = "iDigits";
|
---|
674 | break;
|
---|
675 | case LOCALE_SLIST :
|
---|
676 | pacKey = "sList";
|
---|
677 | break;
|
---|
678 | /* case LOCALE_ICALENDARTYPE: */
|
---|
679 | /* case LOCALE_IFIRSTDAYOFWEEK: */
|
---|
680 | #ifdef __WIN32OS2__
|
---|
681 | case LOCALE_IFIRSTDAYOFWEEK:
|
---|
682 | pacKey = "iFirstDayOfWeek";
|
---|
683 | break;
|
---|
684 | #endif
|
---|
685 | /* case LOCALE_IFIRSTWEEKOFYEAR: */
|
---|
686 | /* case LOCALE_SYEARMONTH : */
|
---|
687 | /* case LOCALE_SPOSITIVESIGN : */
|
---|
688 | /* case LOCALE_IPAPERSIZE: */
|
---|
689 | /* break; */
|
---|
690 | case LOCALE_SLONGDATE :
|
---|
691 | pacKey = "sLongDate";
|
---|
692 | break;
|
---|
693 | case LOCALE_SMONDECIMALSEP :
|
---|
694 | pacKey = "sMonDecimalSep";
|
---|
695 | break;
|
---|
696 | case LOCALE_SMONGROUPING:
|
---|
697 | pacKey = "sMonGrouping";
|
---|
698 | break;
|
---|
699 | case LOCALE_IMEASURE:
|
---|
700 | pacKey = "iMeasure";
|
---|
701 | break;
|
---|
702 | case LOCALE_SMONTHOUSANDSEP :
|
---|
703 | pacKey = "sMonThousandSep";
|
---|
704 | break;
|
---|
705 | case LOCALE_INEGCURR:
|
---|
706 | pacKey = "iNegCurr";
|
---|
707 | break;
|
---|
708 | case LOCALE_SNEGATIVESIGN :
|
---|
709 | pacKey = "sNegativeSign";
|
---|
710 | break;
|
---|
711 | case LOCALE_INEGNUMBER:
|
---|
712 | pacKey = "iNegNumber";
|
---|
713 | break;
|
---|
714 | case LOCALE_SSHORTDATE :
|
---|
715 | pacKey = "sShortDate";
|
---|
716 | break;
|
---|
717 | case LOCALE_ILDATE: /* Long Date format ordering specifier. */
|
---|
718 | pacKey = "iLDate";
|
---|
719 | break;
|
---|
720 | case LOCALE_ILZERO:
|
---|
721 | pacKey = "iLZero";
|
---|
722 | break;
|
---|
723 | case LOCALE_ITLZERO:
|
---|
724 | pacKey = "iTLZero";
|
---|
725 | break;
|
---|
726 | case LOCALE_ITIME: /* Time format specifier. */
|
---|
727 | pacKey = "iTime";
|
---|
728 | break;
|
---|
729 | case LOCALE_STHOUSAND :
|
---|
730 | pacKey = "sThousand";
|
---|
731 | break;
|
---|
732 | case LOCALE_S1159: /* AM */
|
---|
733 | pacKey = "s1159";
|
---|
734 | break;
|
---|
735 | case LOCALE_STIME:
|
---|
736 | pacKey = "sTime";
|
---|
737 | break;
|
---|
738 | case LOCALE_S2359: /* PM */
|
---|
739 | pacKey = "s2359";
|
---|
740 | break;
|
---|
741 | case LOCALE_STIMEFORMAT :
|
---|
742 | pacKey = "sTimeFormat";
|
---|
743 | break;
|
---|
744 | case LOCALE_SCURRENCY:
|
---|
745 | pacKey = "sCurrency";
|
---|
746 | break;
|
---|
747 |
|
---|
748 | /* The following are not listed under MSDN as supported,
|
---|
749 | * but seem to be used and also stored in the registry.
|
---|
750 | */
|
---|
751 |
|
---|
752 | case LOCALE_IDATE:
|
---|
753 | pacKey = "iDate";
|
---|
754 | break;
|
---|
755 | case LOCALE_SCOUNTRY:
|
---|
756 | pacKey = "sCountry";
|
---|
757 | break;
|
---|
758 | case LOCALE_ICOUNTRY:
|
---|
759 | pacKey = "iCountry";
|
---|
760 | break;
|
---|
761 | case LOCALE_SLANGUAGE:
|
---|
762 | pacKey = "sLanguage";
|
---|
763 | break;
|
---|
764 |
|
---|
765 | default:
|
---|
766 | break;
|
---|
767 | }
|
---|
768 |
|
---|
769 | return( pacKey );
|
---|
770 | }
|
---|
771 |
|
---|
772 | /******************************************************************************
|
---|
773 | * SetLocaleInfoA [KERNEL32.656]
|
---|
774 | */
|
---|
775 | BOOL WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
|
---|
776 | {
|
---|
777 | HKEY hKey;
|
---|
778 | char *pacKey;
|
---|
779 | char acRealKey[128];
|
---|
780 |
|
---|
781 | if ( (pacKey = GetLocaleSubkeyName(lctype)) )
|
---|
782 | {
|
---|
783 | sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
|
---|
784 | if ( RegCreateKeyA( HKEY_CURRENT_USER, acRealKey,
|
---|
785 | &hKey ) == ERROR_SUCCESS )
|
---|
786 | {
|
---|
787 | if ( RegSetValueExA( hKey, NULL, 0, REG_SZ,
|
---|
788 | data, strlen(data)+1 ) != ERROR_SUCCESS )
|
---|
789 | {
|
---|
790 | ERR("SetLocaleInfoA: %s did not work\n", pacKey );
|
---|
791 | }
|
---|
792 | RegCloseKey( hKey );
|
---|
793 | }
|
---|
794 | }
|
---|
795 | else
|
---|
796 | {
|
---|
797 | FIXME("(%ld,%ld,%s): stub\n",lcid,lctype,data);
|
---|
798 | }
|
---|
799 | return TRUE;
|
---|
800 | }
|
---|
801 |
|
---|
802 | #ifdef __WIN32OS2__
|
---|
803 | /*****************************************************************************
|
---|
804 | * Name : BOOL SetLocaleInfoW
|
---|
805 | * Purpose : The SetLocaleInfoW function sets an item of locale information.
|
---|
806 | * It does so by making an entry in the process portion of the
|
---|
807 | * locale table. This setting only affects the user override portion
|
---|
808 | * of the locale settings; it does not set the system defaults.
|
---|
809 | * Only certain types of locale information, or LCTYPE values, can
|
---|
810 | * be set by this function. See the following Remarks section for a
|
---|
811 | * list of valid LCTYPE values.
|
---|
812 | * The locale information is always passed in as a null-terminated
|
---|
813 | * Unicode string in the Unicode (W) version of the function, and as
|
---|
814 | * a null-terminated ANSI string in the ANSI (A) version. No integers
|
---|
815 | * are allowed by this function; any numeric values must be specified
|
---|
816 | * as Unicode or ANSI text. Each LCTYPE has a particular format, as
|
---|
817 | * noted in Locale Identifiers.
|
---|
818 | * Parameters: LCID Locale locale identifier
|
---|
819 | * LCTYPE LCType type of information to set
|
---|
820 | * LPCTSTR lpLCData pointer to information to set
|
---|
821 | * Variables :
|
---|
822 | * Result : TRUE / FALSE
|
---|
823 | * Remark :
|
---|
824 | * Status : UNTESTED STUB
|
---|
825 | *
|
---|
826 | * Author : Patrick Haller [Mon, 1998/06/15 08:00]
|
---|
827 | *****************************************************************************/
|
---|
828 |
|
---|
829 | BOOL WIN32API SetLocaleInfoW(LCID Locale,
|
---|
830 | LCTYPE LCType,
|
---|
831 | LPCWSTR lpLCData)
|
---|
832 | {
|
---|
833 | dprintf(("KERNEL32: SetLocaleInfoW(%08xh,%08xh,%08xh) not implemented.\n",
|
---|
834 | Locale,
|
---|
835 | LCType,
|
---|
836 | lpLCData));
|
---|
837 |
|
---|
838 | return (FALSE);
|
---|
839 | }
|
---|
840 | #endif
|
---|
841 |
|
---|
842 | /******************************************************************************
|
---|
843 | * IsValidLocale [KERNEL32.489]
|
---|
844 | */
|
---|
845 | BOOL WINAPI IsValidLocale(LCID lcid,DWORD flags)
|
---|
846 | {
|
---|
847 | /* check if language is registered in the kernel32 resources */
|
---|
848 | if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW, (LPCWSTR)LOCALE_ILANGUAGE, LOWORD(lcid)))
|
---|
849 | return FALSE;
|
---|
850 | else
|
---|
851 | return TRUE;
|
---|
852 | }
|
---|
853 |
|
---|
854 | static BOOL CALLBACK EnumResourceLanguagesProcW(HMODULE hModule, LPCWSTR type,
|
---|
855 | LPCWSTR name, WORD LangID, LONG lParam)
|
---|
856 | {
|
---|
857 | CHAR bufA[20];
|
---|
858 | WCHAR bufW[20];
|
---|
859 | LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
|
---|
860 | sprintf(bufA, "%08X", (UINT)LangID);
|
---|
861 | MultiByteToWideChar(CP_ACP, 0, bufA, -1, bufW, sizeof(bufW)/sizeof(bufW[0]));
|
---|
862 | return lpfnLocaleEnum(bufW);
|
---|
863 | }
|
---|
864 |
|
---|
865 | /******************************************************************************
|
---|
866 | * EnumSystemLocalesW [KERNEL32.209]
|
---|
867 | */
|
---|
868 | BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum,
|
---|
869 | DWORD flags )
|
---|
870 | {
|
---|
871 | TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
|
---|
872 |
|
---|
873 | EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW,
|
---|
874 | (LPCWSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcW,
|
---|
875 | (LONG)lpfnLocaleEnum);
|
---|
876 |
|
---|
877 | return TRUE;
|
---|
878 | }
|
---|
879 |
|
---|
880 | static BOOL CALLBACK EnumResourceLanguagesProcA(HMODULE hModule, LPCSTR type,
|
---|
881 | LPCSTR name, WORD LangID, LONG lParam)
|
---|
882 | {
|
---|
883 | CHAR bufA[20];
|
---|
884 | LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
|
---|
885 | sprintf(bufA, "%08X", (UINT)LangID);
|
---|
886 | return lpfnLocaleEnum(bufA);
|
---|
887 | }
|
---|
888 |
|
---|
889 | /******************************************************************************
|
---|
890 | * EnumSystemLocalesA [KERNEL32.208]
|
---|
891 | */
|
---|
892 | BOOL WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum,
|
---|
893 | DWORD flags)
|
---|
894 | {
|
---|
895 | TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
|
---|
896 |
|
---|
897 | EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
|
---|
898 | (LPCSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcA,
|
---|
899 | (LONG)lpfnLocaleEnum);
|
---|
900 |
|
---|
901 | return TRUE;
|
---|
902 | }
|
---|
903 |
|
---|
904 | /***********************************************************************
|
---|
905 | * VerLanguageNameA [KERNEL32.709][VERSION.9]
|
---|
906 | */
|
---|
907 | DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
|
---|
908 | {
|
---|
909 | if(!szLang)
|
---|
910 | return 0;
|
---|
911 |
|
---|
912 | return GetLocaleInfoA(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
|
---|
913 | }
|
---|
914 |
|
---|
915 | /***********************************************************************
|
---|
916 | * VerLanguageNameW [KERNEL32.710][VERSION.10]
|
---|
917 | */
|
---|
918 | DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
|
---|
919 | {
|
---|
920 | if(!szLang)
|
---|
921 | return 0;
|
---|
922 |
|
---|
923 | return GetLocaleInfoW(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
|
---|
924 | }
|
---|
925 |
|
---|
926 |
|
---|
927 | static const unsigned char LCM_Unicode_LUT[] = {
|
---|
928 | 6 , 3, /* - 1 */
|
---|
929 | 6 , 4, /* - 2 */
|
---|
930 | 6 , 5, /* - 3 */
|
---|
931 | 6 , 6, /* - 4 */
|
---|
932 | 6 , 7, /* - 5 */
|
---|
933 | 6 , 8, /* - 6 */
|
---|
934 | 6 , 9, /* - 7 */
|
---|
935 | 6 , 10, /* - 8 */
|
---|
936 | 7 , 5, /* - 9 */
|
---|
937 | 7 , 6, /* - 10 */
|
---|
938 | 7 , 7, /* - 11 */
|
---|
939 | 7 , 8, /* - 12 */
|
---|
940 | 7 , 9, /* - 13 */
|
---|
941 | 6 , 11, /* - 14 */
|
---|
942 | 6 , 12, /* - 15 */
|
---|
943 | 6 , 13, /* - 16 */
|
---|
944 | 6 , 14, /* - 17 */
|
---|
945 | 6 , 15, /* - 18 */
|
---|
946 | 6 , 16, /* - 19 */
|
---|
947 | 6 , 17, /* - 20 */
|
---|
948 | 6 , 18, /* - 21 */
|
---|
949 | 6 , 19, /* - 22 */
|
---|
950 | 6 , 20, /* - 23 */
|
---|
951 | 6 , 21, /* - 24 */
|
---|
952 | 6 , 22, /* - 25 */
|
---|
953 | 6 , 23, /* - 26 */
|
---|
954 | 6 , 24, /* - 27 */
|
---|
955 | 6 , 25, /* - 28 */
|
---|
956 | 6 , 26, /* - 29 */
|
---|
957 | 6 , 27, /* - 30 */
|
---|
958 | 6 , 28, /* - 31 */
|
---|
959 | 7 , 2, /* - 32 */
|
---|
960 | 7 , 28, /* ! - 33 */
|
---|
961 | 7 , 29, /* " - 34 */ /* " */
|
---|
962 | 7 , 31, /* # - 35 */
|
---|
963 | 7 , 33, /* $ - 36 */
|
---|
964 | 7 , 35, /* % - 37 */
|
---|
965 | 7 , 37, /* & - 38 */
|
---|
966 | 6 , 128, /* ' - 39 */
|
---|
967 | 7 , 39, /* ( - 40 */
|
---|
968 | 7 , 42, /* ) - 41 */
|
---|
969 | 7 , 45, /* * - 42 */
|
---|
970 | 8 , 3, /* + - 43 */
|
---|
971 | 7 , 47, /* , - 44 */
|
---|
972 | 6 , 130, /* - - 45 */
|
---|
973 | 7 , 51, /* . - 46 */
|
---|
974 | 7 , 53, /* / - 47 */
|
---|
975 | 12 , 3, /* 0 - 48 */
|
---|
976 | 12 , 33, /* 1 - 49 */
|
---|
977 | 12 , 51, /* 2 - 50 */
|
---|
978 | 12 , 70, /* 3 - 51 */
|
---|
979 | 12 , 88, /* 4 - 52 */
|
---|
980 | 12 , 106, /* 5 - 53 */
|
---|
981 | 12 , 125, /* 6 - 54 */
|
---|
982 | 12 , 144, /* 7 - 55 */
|
---|
983 | 12 , 162, /* 8 - 56 */
|
---|
984 | 12 , 180, /* 9 - 57 */
|
---|
985 | 7 , 55, /* : - 58 */
|
---|
986 | 7 , 58, /* ; - 59 */
|
---|
987 | 8 , 14, /* < - 60 */
|
---|
988 | 8 , 18, /* = - 61 */
|
---|
989 | 8 , 20, /* > - 62 */
|
---|
990 | 7 , 60, /* ? - 63 */
|
---|
991 | 7 , 62, /* @ - 64 */
|
---|
992 | 14 , 2, /* A - 65 */
|
---|
993 | 14 , 9, /* B - 66 */
|
---|
994 | 14 , 10, /* C - 67 */
|
---|
995 | 14 , 26, /* D - 68 */
|
---|
996 | 14 , 33, /* E - 69 */
|
---|
997 | 14 , 35, /* F - 70 */
|
---|
998 | 14 , 37, /* G - 71 */
|
---|
999 | 14 , 44, /* H - 72 */
|
---|
1000 | 14 , 50, /* I - 73 */
|
---|
1001 | 14 , 53, /* J - 74 */
|
---|
1002 | 14 , 54, /* K - 75 */
|
---|
1003 | 14 , 72, /* L - 76 */
|
---|
1004 | 14 , 81, /* M - 77 */
|
---|
1005 | 14 , 112, /* N - 78 */
|
---|
1006 | 14 , 124, /* O - 79 */
|
---|
1007 | 14 , 126, /* P - 80 */
|
---|
1008 | 14 , 137, /* Q - 81 */
|
---|
1009 | 14 , 138, /* R - 82 */
|
---|
1010 | 14 , 145, /* S - 83 */
|
---|
1011 | 14 , 153, /* T - 84 */
|
---|
1012 | 14 , 159, /* U - 85 */
|
---|
1013 | 14 , 162, /* V - 86 */
|
---|
1014 | 14 , 164, /* W - 87 */
|
---|
1015 | 14 , 166, /* X - 88 */
|
---|
1016 | 14 , 167, /* Y - 89 */
|
---|
1017 | 14 , 169, /* Z - 90 */
|
---|
1018 | 7 , 63, /* [ - 91 */
|
---|
1019 | 7 , 65, /* \ - 92 */
|
---|
1020 | 7 , 66, /* ] - 93 */
|
---|
1021 | 7 , 67, /* ^ - 94 */
|
---|
1022 | 7 , 68, /* _ - 95 */
|
---|
1023 | 7 , 72, /* ` - 96 */
|
---|
1024 | 14 , 2, /* a - 97 */
|
---|
1025 | 14 , 9, /* b - 98 */
|
---|
1026 | 14 , 10, /* c - 99 */
|
---|
1027 | 14 , 26, /* d - 100 */
|
---|
1028 | 14 , 33, /* e - 101 */
|
---|
1029 | 14 , 35, /* f - 102 */
|
---|
1030 | 14 , 37, /* g - 103 */
|
---|
1031 | 14 , 44, /* h - 104 */
|
---|
1032 | 14 , 50, /* i - 105 */
|
---|
1033 | 14 , 53, /* j - 106 */
|
---|
1034 | 14 , 54, /* k - 107 */
|
---|
1035 | 14 , 72, /* l - 108 */
|
---|
1036 | 14 , 81, /* m - 109 */
|
---|
1037 | 14 , 112, /* n - 110 */
|
---|
1038 | 14 , 124, /* o - 111 */
|
---|
1039 | 14 , 126, /* p - 112 */
|
---|
1040 | 14 , 137, /* q - 113 */
|
---|
1041 | 14 , 138, /* r - 114 */
|
---|
1042 | 14 , 145, /* s - 115 */
|
---|
1043 | 14 , 153, /* t - 116 */
|
---|
1044 | 14 , 159, /* u - 117 */
|
---|
1045 | 14 , 162, /* v - 118 */
|
---|
1046 | 14 , 164, /* w - 119 */
|
---|
1047 | 14 , 166, /* x - 120 */
|
---|
1048 | 14 , 167, /* y - 121 */
|
---|
1049 | 14 , 169, /* z - 122 */
|
---|
1050 | 7 , 74, /* { - 123 */
|
---|
1051 | 7 , 76, /* | - 124 */
|
---|
1052 | 7 , 78, /* } - 125 */
|
---|
1053 | 7 , 80, /* ~ - 126 */
|
---|
1054 | 6 , 29, /* - 127 */
|
---|
1055 | 6 , 30, /* - 128 */
|
---|
1056 | 6 , 31, /* - 129 */
|
---|
1057 | 7 , 123, /* - 130 */
|
---|
1058 | 14 , 35, /* - 131 */
|
---|
1059 | 7 , 127, /* - 132 */
|
---|
1060 | 10 , 21, /*
|
---|
1061 | - 133 */
|
---|
1062 | 10 , 15, /* - 134 */
|
---|
1063 | 10 , 16, /* - 135 */
|
---|
1064 | 7 , 67, /* - 136 */
|
---|
1065 | 10 , 22, /* - 137 */
|
---|
1066 | 14 , 145, /* - 138 */
|
---|
1067 | 7 , 136, /* - 139 */
|
---|
1068 | 14 + 16 , 124, /* - 140 */
|
---|
1069 | 6 , 43, /* - 141 */
|
---|
1070 | 6 , 44, /* - 142 */
|
---|
1071 | 6 , 45, /* - 143 */
|
---|
1072 | 6 , 46, /* - 144 */
|
---|
1073 | 7 , 121, /* - 145 */
|
---|
1074 | 7 , 122, /* - 146 */
|
---|
1075 | 7 , 125, /* - 147 */
|
---|
1076 | 7 , 126, /* - 148 */
|
---|
1077 | 10 , 17, /* - 149 */
|
---|
1078 | 6 , 137, /* - 150 */
|
---|
1079 | 6 , 139, /* - 151 */
|
---|
1080 | 7 , 93, /* - 152 */
|
---|
1081 | 14 , 156, /* - 153 */
|
---|
1082 | 14 , 145, /* - 154 */
|
---|
1083 | 7 , 137, /* - 155 */
|
---|
1084 | 14 + 16 , 124, /* - 156 */
|
---|
1085 | 6 , 59, /* - 157 */
|
---|
1086 | 6 , 60, /* - 158 */
|
---|
1087 | 14 , 167, /* - 159 */
|
---|
1088 | 7 , 4, /* - 160 */
|
---|
1089 | 7 , 81, /* ¡ - 161 */
|
---|
1090 | 10 , 2, /* ¢ - 162 */
|
---|
1091 | 10 , 3, /* £ - 163 */
|
---|
1092 | 10 , 4, /* € - 164 */
|
---|
1093 | 10 , 5, /* ¥ - 165 */
|
---|
1094 | 7 , 82, /* Š - 166 */
|
---|
1095 | 10 , 6, /* § - 167 */
|
---|
1096 | 7 , 83, /* š - 168 */
|
---|
1097 | 10 , 7, /* © - 169 */
|
---|
1098 | 14 , 2, /* ª - 170 */
|
---|
1099 | 8 , 24, /* « - 171 */
|
---|
1100 | 10 , 8, /* ¬ - 172 */
|
---|
1101 | 6 , 131, /* - 173 */
|
---|
1102 | 10 , 9, /* ® - 174 */
|
---|
1103 | 7 , 84, /* ¯ - 175 */
|
---|
1104 | 10 , 10, /* ° - 176 */
|
---|
1105 | 8 , 23, /* ± - 177 */
|
---|
1106 | 12 , 51, /* ² - 178 */
|
---|
1107 | 12 , 70, /* ³ - 179 */
|
---|
1108 | 7 , 85, /* Ž - 180 */
|
---|
1109 | 10 , 11, /* µ - 181 */
|
---|
1110 | 10 , 12, /* ¶ - 182 */
|
---|
1111 | 10 , 13, /* · - 183 */
|
---|
1112 | 7 , 86, /* ž - 184 */
|
---|
1113 | 12 , 33, /* ¹ - 185 */
|
---|
1114 | 14 , 124, /* º - 186 */
|
---|
1115 | 8 , 26, /* » - 187 */
|
---|
1116 | 12 , 21, /* Œ - 188 */
|
---|
1117 | 12 , 25, /* œ - 189 */
|
---|
1118 | 12 , 29, /* Ÿ - 190 */
|
---|
1119 | 7 , 87, /* ¿ - 191 */
|
---|
1120 | 14 , 2, /* À - 192 */
|
---|
1121 | 14 , 2, /* Á - 193 */
|
---|
1122 | 14 , 2, /* Â - 194 */
|
---|
1123 | 14 , 2, /* Ã - 195 */
|
---|
1124 | 14 , 2, /* Ä - 196 */
|
---|
1125 | 14 , 2, /* Å - 197 */
|
---|
1126 | 14 + 16 , 2, /* Æ - 198 */
|
---|
1127 | 14 , 10, /* Ç - 199 */
|
---|
1128 | 14 , 33, /* È - 200 */
|
---|
1129 | 14 , 33, /* É - 201 */
|
---|
1130 | 14 , 33, /* Ê - 202 */
|
---|
1131 | 14 , 33, /* Ë - 203 */
|
---|
1132 | 14 , 50, /* Ì - 204 */
|
---|
1133 | 14 , 50, /* Í - 205 */
|
---|
1134 | 14 , 50, /* Î - 206 */
|
---|
1135 | 14 , 50, /* Ï - 207 */
|
---|
1136 | 14 , 26, /* Ð - 208 */
|
---|
1137 | 14 , 112, /* Ñ - 209 */
|
---|
1138 | 14 , 124, /* Ò - 210 */
|
---|
1139 | 14 , 124, /* Ó - 211 */
|
---|
1140 | 14 , 124, /* Ô - 212 */
|
---|
1141 | 14 , 124, /* Õ - 213 */
|
---|
1142 | 14 , 124, /* Ö - 214 */
|
---|
1143 | 8 , 28, /* × - 215 */
|
---|
1144 | 14 , 124, /* Ø - 216 */
|
---|
1145 | 14 , 159, /* Ù - 217 */
|
---|
1146 | 14 , 159, /* Ú - 218 */
|
---|
1147 | 14 , 159, /* Û - 219 */
|
---|
1148 | 14 , 159, /* Ü - 220 */
|
---|
1149 | 14 , 167, /* Ý - 221 */
|
---|
1150 | 14 + 32 , 153, /* Þ - 222 */
|
---|
1151 | 14 + 48 , 145, /* ß - 223 */
|
---|
1152 | 14 , 2, /* à - 224 */
|
---|
1153 | 14 , 2, /* á - 225 */
|
---|
1154 | 14 , 2, /* â - 226 */
|
---|
1155 | 14 , 2, /* ã - 227 */
|
---|
1156 | 14 , 2, /* ä - 228 */
|
---|
1157 | 14 , 2, /* å - 229 */
|
---|
1158 | 14 + 16 , 2, /* æ - 230 */
|
---|
1159 | 14 , 10, /* ç - 231 */
|
---|
1160 | 14 , 33, /* è - 232 */
|
---|
1161 | 14 , 33, /* é - 233 */
|
---|
1162 | 14 , 33, /* ê - 234 */
|
---|
1163 | 14 , 33, /* ë - 235 */
|
---|
1164 | 14 , 50, /* ì - 236 */
|
---|
1165 | 14 , 50, /* í - 237 */
|
---|
1166 | 14 , 50, /* î - 238 */
|
---|
1167 | 14 , 50, /* ï - 239 */
|
---|
1168 | 14 , 26, /* ð - 240 */
|
---|
1169 | 14 , 112, /* ñ - 241 */
|
---|
1170 | 14 , 124, /* ò - 242 */
|
---|
1171 | 14 , 124, /* ó - 243 */
|
---|
1172 | 14 , 124, /* ô - 244 */
|
---|
1173 | 14 , 124, /* õ - 245 */
|
---|
1174 | 14 , 124, /* ö - 246 */
|
---|
1175 | 8 , 29, /* ÷ - 247 */
|
---|
1176 | 14 , 124, /* ø - 248 */
|
---|
1177 | 14 , 159, /* ù - 249 */
|
---|
1178 | 14 , 159, /* ú - 250 */
|
---|
1179 | 14 , 159, /* û - 251 */
|
---|
1180 | 14 , 159, /* ü - 252 */
|
---|
1181 | 14 , 167, /* ý - 253 */
|
---|
1182 | 14 + 32 , 153, /* þ - 254 */
|
---|
1183 | 14 , 167 /* ÿ - 255 */ };
|
---|
1184 |
|
---|
1185 | static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
|
---|
1186 |
|
---|
1187 | #define LCM_Diacritic_Start 131
|
---|
1188 |
|
---|
1189 | static const unsigned char LCM_Diacritic_LUT[] = {
|
---|
1190 | 123, /* - 131 */
|
---|
1191 | 2, /* - 132 */
|
---|
1192 | 2, /*
|
---|
1193 | - 133 */
|
---|
1194 | 2, /* - 134 */
|
---|
1195 | 2, /* - 135 */
|
---|
1196 | 3, /* - 136 */
|
---|
1197 | 2, /* - 137 */
|
---|
1198 | 20, /* - 138 */
|
---|
1199 | 2, /* - 139 */
|
---|
1200 | 2, /* - 140 */
|
---|
1201 | 2, /* - 141 */
|
---|
1202 | 2, /* - 142 */
|
---|
1203 | 2, /* - 143 */
|
---|
1204 | 2, /* - 144 */
|
---|
1205 | 2, /* - 145 */
|
---|
1206 | 2, /* - 146 */
|
---|
1207 | 2, /* - 147 */
|
---|
1208 | 2, /* - 148 */
|
---|
1209 | 2, /* - 149 */
|
---|
1210 | 2, /* - 150 */
|
---|
1211 | 2, /* - 151 */
|
---|
1212 | 2, /* - 152 */
|
---|
1213 | 2, /* - 153 */
|
---|
1214 | 20, /* - 154 */
|
---|
1215 | 2, /* - 155 */
|
---|
1216 | 2, /* - 156 */
|
---|
1217 | 2, /* - 157 */
|
---|
1218 | 2, /* - 158 */
|
---|
1219 | 19, /* - 159 */
|
---|
1220 | 2, /* - 160 */
|
---|
1221 | 2, /* ¡ - 161 */
|
---|
1222 | 2, /* ¢ - 162 */
|
---|
1223 | 2, /* £ - 163 */
|
---|
1224 | 2, /* € - 164 */
|
---|
1225 | 2, /* ¥ - 165 */
|
---|
1226 | 2, /* Š - 166 */
|
---|
1227 | 2, /* § - 167 */
|
---|
1228 | 2, /* š - 168 */
|
---|
1229 | 2, /* © - 169 */
|
---|
1230 | 3, /* ª - 170 */
|
---|
1231 | 2, /* « - 171 */
|
---|
1232 | 2, /* ¬ - 172 */
|
---|
1233 | 2, /* - 173 */
|
---|
1234 | 2, /* ® - 174 */
|
---|
1235 | 2, /* ¯ - 175 */
|
---|
1236 | 2, /* ° - 176 */
|
---|
1237 | 2, /* ± - 177 */
|
---|
1238 | 2, /* ² - 178 */
|
---|
1239 | 2, /* ³ - 179 */
|
---|
1240 | 2, /* Ž - 180 */
|
---|
1241 | 2, /* µ - 181 */
|
---|
1242 | 2, /* ¶ - 182 */
|
---|
1243 | 2, /* · - 183 */
|
---|
1244 | 2, /* ž - 184 */
|
---|
1245 | 2, /* ¹ - 185 */
|
---|
1246 | 3, /* º - 186 */
|
---|
1247 | 2, /* » - 187 */
|
---|
1248 | 2, /* Œ - 188 */
|
---|
1249 | 2, /* œ - 189 */
|
---|
1250 | 2, /* Ÿ - 190 */
|
---|
1251 | 2, /* ¿ - 191 */
|
---|
1252 | 15, /* À - 192 */
|
---|
1253 | 14, /* Á - 193 */
|
---|
1254 | 18, /* Â - 194 */
|
---|
1255 | 25, /* Ã - 195 */
|
---|
1256 | 19, /* Ä - 196 */
|
---|
1257 | 26, /* Å - 197 */
|
---|
1258 | 2, /* Æ - 198 */
|
---|
1259 | 28, /* Ç - 199 */
|
---|
1260 | 15, /* È - 200 */
|
---|
1261 | 14, /* É - 201 */
|
---|
1262 | 18, /* Ê - 202 */
|
---|
1263 | 19, /* Ë - 203 */
|
---|
1264 | 15, /* Ì - 204 */
|
---|
1265 | 14, /* Í - 205 */
|
---|
1266 | 18, /* Î - 206 */
|
---|
1267 | 19, /* Ï - 207 */
|
---|
1268 | 104, /* Ð - 208 */
|
---|
1269 | 25, /* Ñ - 209 */
|
---|
1270 | 15, /* Ò - 210 */
|
---|
1271 | 14, /* Ó - 211 */
|
---|
1272 | 18, /* Ô - 212 */
|
---|
1273 | 25, /* Õ - 213 */
|
---|
1274 | 19, /* Ö - 214 */
|
---|
1275 | 2, /* × - 215 */
|
---|
1276 | 33, /* Ø - 216 */
|
---|
1277 | 15, /* Ù - 217 */
|
---|
1278 | 14, /* Ú - 218 */
|
---|
1279 | 18, /* Û - 219 */
|
---|
1280 | 19, /* Ü - 220 */
|
---|
1281 | 14, /* Ý - 221 */
|
---|
1282 | 2, /* Þ - 222 */
|
---|
1283 | 2, /* ß - 223 */
|
---|
1284 | 15, /* à - 224 */
|
---|
1285 | 14, /* á - 225 */
|
---|
1286 | 18, /* â - 226 */
|
---|
1287 | 25, /* ã - 227 */
|
---|
1288 | 19, /* ä - 228 */
|
---|
1289 | 26, /* å - 229 */
|
---|
1290 | 2, /* æ - 230 */
|
---|
1291 | 28, /* ç - 231 */
|
---|
1292 | 15, /* è - 232 */
|
---|
1293 | 14, /* é - 233 */
|
---|
1294 | 18, /* ê - 234 */
|
---|
1295 | 19, /* ë - 235 */
|
---|
1296 | 15, /* ì - 236 */
|
---|
1297 | 14, /* í - 237 */
|
---|
1298 | 18, /* î - 238 */
|
---|
1299 | 19, /* ï - 239 */
|
---|
1300 | 104, /* ð - 240 */
|
---|
1301 | 25, /* ñ - 241 */
|
---|
1302 | 15, /* ò - 242 */
|
---|
1303 | 14, /* ó - 243 */
|
---|
1304 | 18, /* ô - 244 */
|
---|
1305 | 25, /* õ - 245 */
|
---|
1306 | 19, /* ö - 246 */
|
---|
1307 | 2, /* ÷ - 247 */
|
---|
1308 | 33, /* ø - 248 */
|
---|
1309 | 15, /* ù - 249 */
|
---|
1310 | 14, /* ú - 250 */
|
---|
1311 | 18, /* û - 251 */
|
---|
1312 | 19, /* ü - 252 */
|
---|
1313 | 14, /* ý - 253 */
|
---|
1314 | 2, /* þ - 254 */
|
---|
1315 | 19, /* ÿ - 255 */
|
---|
1316 | } ;
|
---|
1317 |
|
---|
1318 | /******************************************************************************
|
---|
1319 | * OLE2NLS_isPunctuation [INTERNAL]
|
---|
1320 | */
|
---|
1321 | static int OLE2NLS_isPunctuation(unsigned char c)
|
---|
1322 | {
|
---|
1323 | /* "punctuation character" in this context is a character which is
|
---|
1324 | considered "less important" during word sort comparison.
|
---|
1325 | See LCMapString implementation for the precise definition
|
---|
1326 | of "less important". */
|
---|
1327 |
|
---|
1328 | return (LCM_Unicode_LUT[-2+2*c]==6);
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 | /******************************************************************************
|
---|
1332 | * OLE2NLS_isNonSpacing [INTERNAL]
|
---|
1333 | */
|
---|
1334 | static int OLE2NLS_isNonSpacing(unsigned char c)
|
---|
1335 | {
|
---|
1336 | /* This function is used by LCMapStringA. Characters
|
---|
1337 | for which it returns true are ignored when mapping a
|
---|
1338 | string with NORM_IGNORENONSPACE */
|
---|
1339 | return ((c==136) || (c==170) || (c==186));
|
---|
1340 | }
|
---|
1341 |
|
---|
1342 | /******************************************************************************
|
---|
1343 | * OLE2NLS_isSymbol [INTERNAL]
|
---|
1344 | */
|
---|
1345 | static int OLE2NLS_isSymbol(unsigned char c)
|
---|
1346 | {
|
---|
1347 | /* This function is used by LCMapStringA. Characters
|
---|
1348 | for which it returns true are ignored when mapping a
|
---|
1349 | string with NORM_IGNORESYMBOLS */
|
---|
1350 | return ( (c!=0) && !(isalpha(c) || isdigit(c)) );
|
---|
1351 | }
|
---|
1352 |
|
---|
1353 | /******************************************************************************
|
---|
1354 | * identity [Internal]
|
---|
1355 | */
|
---|
1356 | static int identity(int c)
|
---|
1357 | {
|
---|
1358 | return c;
|
---|
1359 | }
|
---|
1360 |
|
---|
1361 | /*************************************************************************
|
---|
1362 | * LCMapStringA [KERNEL32.492]
|
---|
1363 | *
|
---|
1364 | * Convert a string, or generate a sort key from it.
|
---|
1365 | *
|
---|
1366 | * If (mapflags & LCMAP_SORTKEY), the function will generate
|
---|
1367 | * a sort key for the source string. Else, it will convert it
|
---|
1368 | * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
|
---|
1369 | *
|
---|
1370 | * RETURNS
|
---|
1371 | * Error : 0.
|
---|
1372 | * Success : length of the result string.
|
---|
1373 | *
|
---|
1374 | * NOTES
|
---|
1375 | * If called with scrlen = -1, the function will compute the length
|
---|
1376 | * of the 0-terminated string strsrc by itself.
|
---|
1377 | *
|
---|
1378 | * If called with dstlen = 0, returns the buffer length that
|
---|
1379 | * would be required.
|
---|
1380 | *
|
---|
1381 | * NORM_IGNOREWIDTH means to compare ASCII and wide characters
|
---|
1382 | * as if they are equal.
|
---|
1383 | * In the only code page implemented so far, there may not be
|
---|
1384 | * wide characters in strings passed to LCMapStringA,
|
---|
1385 | * so there is nothing to be done for this flag.
|
---|
1386 | */
|
---|
1387 | INT WINAPI LCMapStringA(
|
---|
1388 | LCID lcid, /* [in] locale identifier created with MAKELCID;
|
---|
1389 | LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
|
---|
1390 | predefined values. */
|
---|
1391 | DWORD mapflags, /* [in] flags */
|
---|
1392 | LPCSTR srcstr, /* [in] source buffer */
|
---|
1393 | INT srclen, /* [in] source length */
|
---|
1394 | LPSTR dststr, /* [out] destination buffer */
|
---|
1395 | INT dstlen) /* [in] destination buffer length */
|
---|
1396 | {
|
---|
1397 | int i;
|
---|
1398 |
|
---|
1399 | TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
|
---|
1400 | lcid,mapflags,srcstr,srclen,dststr,dstlen);
|
---|
1401 |
|
---|
1402 | if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
|
---|
1403 | {
|
---|
1404 | ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
|
---|
1405 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1406 | return 0;
|
---|
1407 | }
|
---|
1408 | if (srclen == -1)
|
---|
1409 | srclen = strlen(srcstr) + 1 ; /* (include final '\0') */
|
---|
1410 |
|
---|
1411 | #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
|
---|
1412 | LCMAP_LOWERCASE | \
|
---|
1413 | LCMAP_SORTKEY | \
|
---|
1414 | NORM_IGNORECASE | \
|
---|
1415 | NORM_IGNORENONSPACE | \
|
---|
1416 | SORT_STRINGSORT | \
|
---|
1417 | NORM_IGNOREWIDTH | \
|
---|
1418 | NORM_IGNOREKANATYPE)
|
---|
1419 | /* FIXME: as long as we don't support Katakana nor Hiragana
|
---|
1420 | * characters, we can support NORM_IGNOREKANATYPE
|
---|
1421 | */
|
---|
1422 | #ifdef DEBUG
|
---|
1423 | if (mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS)
|
---|
1424 | {
|
---|
1425 | FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
|
---|
1426 | "unimplemented flags: 0x%08lx\n",
|
---|
1427 | lcid,
|
---|
1428 | mapflags,
|
---|
1429 | srcstr,
|
---|
1430 | srclen,
|
---|
1431 | dststr,
|
---|
1432 | dstlen,
|
---|
1433 | mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS
|
---|
1434 | );
|
---|
1435 | }
|
---|
1436 | #endif
|
---|
1437 |
|
---|
1438 | if ( !(mapflags & LCMAP_SORTKEY) )
|
---|
1439 | {
|
---|
1440 | int i,j;
|
---|
1441 | int (* f)(int) = identity;
|
---|
1442 |
|
---|
1443 | int flag_ignorenonspace = mapflags & NORM_IGNORENONSPACE;
|
---|
1444 | int flag_ignoresymbols = mapflags & NORM_IGNORESYMBOLS;
|
---|
1445 |
|
---|
1446 | if (flag_ignorenonspace || flag_ignoresymbols)
|
---|
1447 | {
|
---|
1448 | /* For some values of mapflags, the length of the resulting
|
---|
1449 | string is not known at this point. Windows does map the string
|
---|
1450 | and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
|
---|
1451 | these cases. */
|
---|
1452 | if (dstlen==0)
|
---|
1453 | {
|
---|
1454 | /* Compute required length */
|
---|
1455 | for (i=j=0; i < srclen; i++)
|
---|
1456 | {
|
---|
1457 | if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
|
---|
1458 | && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
|
---|
1459 | j++;
|
---|
1460 | }
|
---|
1461 | return j;
|
---|
1462 | }
|
---|
1463 | }
|
---|
1464 | else
|
---|
1465 | {
|
---|
1466 | if (dstlen==0)
|
---|
1467 | return srclen;
|
---|
1468 | if (dstlen<srclen)
|
---|
1469 | {
|
---|
1470 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
1471 | return 0;
|
---|
1472 | }
|
---|
1473 | }
|
---|
1474 | if (mapflags & LCMAP_UPPERCASE)
|
---|
1475 | f = toupper;
|
---|
1476 | else if (mapflags & LCMAP_LOWERCASE)
|
---|
1477 | f = tolower;
|
---|
1478 | /* FIXME: NORM_IGNORENONSPACE requires another conversion */
|
---|
1479 | for (i=j=0; (i<srclen) && (j<dstlen) ; i++)
|
---|
1480 | {
|
---|
1481 | if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
|
---|
1482 | && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
|
---|
1483 | {
|
---|
1484 | dststr[j] = (CHAR) f(srcstr[i]);
|
---|
1485 | j++;
|
---|
1486 | }
|
---|
1487 | }
|
---|
1488 | return j;
|
---|
1489 | }
|
---|
1490 |
|
---|
1491 | /* FIXME: This function completely ignores the "lcid" parameter. */
|
---|
1492 | /* else ... (mapflags & LCMAP_SORTKEY) */
|
---|
1493 | {
|
---|
1494 | int unicode_len=0;
|
---|
1495 | int case_len=0;
|
---|
1496 | int diacritic_len=0;
|
---|
1497 | int delayed_punctuation_len=0;
|
---|
1498 | char *case_component;
|
---|
1499 | char *diacritic_component;
|
---|
1500 | char *delayed_punctuation_component;
|
---|
1501 | int room,count;
|
---|
1502 | int flag_stringsort = mapflags & SORT_STRINGSORT;
|
---|
1503 |
|
---|
1504 | /* compute how much room we will need */
|
---|
1505 | for (i=0;i<srclen;i++)
|
---|
1506 | {
|
---|
1507 | int ofs;
|
---|
1508 | unsigned char source_char = srcstr[i];
|
---|
1509 | if (source_char!='\0')
|
---|
1510 | {
|
---|
1511 | if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
|
---|
1512 | {
|
---|
1513 | unicode_len++;
|
---|
1514 | if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
|
---|
1515 | unicode_len++; /* double letter */
|
---|
1516 | }
|
---|
1517 | else
|
---|
1518 | {
|
---|
1519 | delayed_punctuation_len++;
|
---|
1520 | }
|
---|
1521 | }
|
---|
1522 |
|
---|
1523 | if (isupper(source_char))
|
---|
1524 | case_len=unicode_len;
|
---|
1525 |
|
---|
1526 | ofs = source_char - LCM_Diacritic_Start;
|
---|
1527 | if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
|
---|
1528 | diacritic_len=unicode_len;
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 | if (mapflags & NORM_IGNORECASE)
|
---|
1532 | case_len=0;
|
---|
1533 | if (mapflags & NORM_IGNORENONSPACE)
|
---|
1534 | diacritic_len=0;
|
---|
1535 |
|
---|
1536 | room = 2 * unicode_len /* "unicode" component */
|
---|
1537 | + diacritic_len /* "diacritic" component */
|
---|
1538 | + case_len /* "case" component */
|
---|
1539 | + 4 * delayed_punctuation_len /* punctuation in word sort mode */
|
---|
1540 | + 4 /* four '\1' separators */
|
---|
1541 | + 1 ; /* terminal '\0' */
|
---|
1542 | if (dstlen==0)
|
---|
1543 | return room;
|
---|
1544 | else if (dstlen<room)
|
---|
1545 | {
|
---|
1546 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
1547 | return 0;
|
---|
1548 | }
|
---|
1549 | #if 0
|
---|
1550 | /*FIXME the Pointercheck should not be nessesary */
|
---|
1551 | if (IsBadWritePtr (dststr,room))
|
---|
1552 | { ERR("bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
|
---|
1553 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
1554 | return 0;
|
---|
1555 | }
|
---|
1556 | #endif
|
---|
1557 | /* locate each component, write separators */
|
---|
1558 | diacritic_component = dststr + 2*unicode_len ;
|
---|
1559 | *diacritic_component++ = '\1';
|
---|
1560 | case_component = diacritic_component + diacritic_len ;
|
---|
1561 | *case_component++ = '\1';
|
---|
1562 | delayed_punctuation_component = case_component + case_len ;
|
---|
1563 | *delayed_punctuation_component++ = '\1';
|
---|
1564 | *delayed_punctuation_component++ = '\1';
|
---|
1565 |
|
---|
1566 | /* read source string char by char, write
|
---|
1567 | corresponding weight in each component. */
|
---|
1568 | for (i=0,count=0;i<srclen;i++)
|
---|
1569 | {
|
---|
1570 | unsigned char source_char=srcstr[i];
|
---|
1571 | if (source_char!='\0')
|
---|
1572 | {
|
---|
1573 | int type,longcode;
|
---|
1574 | type = LCM_Unicode_LUT[-2+2*source_char];
|
---|
1575 | longcode = type >> 4;
|
---|
1576 | type &= 15;
|
---|
1577 | if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
|
---|
1578 | {
|
---|
1579 | WORD encrypted_location = (1<<15) + 7 + 4*count;
|
---|
1580 | *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
|
---|
1581 | *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
|
---|
1582 | /* big-endian is used here because it lets string comparison be
|
---|
1583 | compatible with numerical comparison */
|
---|
1584 |
|
---|
1585 | *delayed_punctuation_component++ = type;
|
---|
1586 | *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
|
---|
1587 | /* assumption : a punctuation character is never a
|
---|
1588 | double or accented letter */
|
---|
1589 | }
|
---|
1590 | else
|
---|
1591 | {
|
---|
1592 | dststr[2*count] = type;
|
---|
1593 | dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
|
---|
1594 | if (longcode)
|
---|
1595 | {
|
---|
1596 | if (count<case_len)
|
---|
1597 | case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
|
---|
1598 | if (count<diacritic_len)
|
---|
1599 | diacritic_component[count] = 2; /* assumption: a double letter
|
---|
1600 | is never accented */
|
---|
1601 | count++;
|
---|
1602 |
|
---|
1603 | dststr[2*count] = type;
|
---|
1604 | dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
|
---|
1605 | /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
|
---|
1606 | 32 in the first column of LCM_Unicode_LUT --> longcode = 2
|
---|
1607 | 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
|
---|
1608 | }
|
---|
1609 |
|
---|
1610 | if (count<case_len)
|
---|
1611 | case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
|
---|
1612 | if (count<diacritic_len)
|
---|
1613 | {
|
---|
1614 | int ofs = source_char - LCM_Diacritic_Start;
|
---|
1615 | diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
|
---|
1616 | }
|
---|
1617 | count++;
|
---|
1618 | }
|
---|
1619 | }
|
---|
1620 | }
|
---|
1621 | dststr[room-1] = '\0';
|
---|
1622 | return room;
|
---|
1623 | }
|
---|
1624 | }
|
---|
1625 |
|
---|
1626 | /*************************************************************************
|
---|
1627 | * LCMapStringW [KERNEL32.493]
|
---|
1628 | *
|
---|
1629 | * Convert a string, or generate a sort key from it.
|
---|
1630 | *
|
---|
1631 | * NOTE
|
---|
1632 | *
|
---|
1633 | * See LCMapStringA for documentation
|
---|
1634 | */
|
---|
1635 | INT WINAPI LCMapStringW(
|
---|
1636 | LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT srclen,LPWSTR dststr,
|
---|
1637 | INT dstlen)
|
---|
1638 | {
|
---|
1639 | int i;
|
---|
1640 |
|
---|
1641 | TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
|
---|
1642 | lcid, mapflags, srcstr, srclen, dststr, dstlen);
|
---|
1643 |
|
---|
1644 | if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
|
---|
1645 | {
|
---|
1646 | ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
|
---|
1647 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1648 | return 0;
|
---|
1649 | }
|
---|
1650 | if (srclen==-1)
|
---|
1651 | srclen = strlenW(srcstr)+1;
|
---|
1652 |
|
---|
1653 | /* FIXME: Both this function and it's companion LCMapStringA()
|
---|
1654 | * completely ignore the "lcid" parameter. In place of the "lcid"
|
---|
1655 | * parameter the application must set the "LC_COLLATE" or "LC_ALL"
|
---|
1656 | * environment variable prior to invoking this function. */
|
---|
1657 | if (mapflags & LCMAP_SORTKEY)
|
---|
1658 | {
|
---|
1659 | /* Possible values of LC_COLLATE. */
|
---|
1660 | char *lc_collate_default = 0; /* value prior to this function */
|
---|
1661 | char *lc_collate_env = 0; /* value retrieved from the environment */
|
---|
1662 |
|
---|
1663 | /* General purpose index into strings of any type. */
|
---|
1664 | int str_idx = 0;
|
---|
1665 |
|
---|
1666 | /* Lengths of various strings where the length is measured in
|
---|
1667 | * wide characters for wide character strings and in bytes for
|
---|
1668 | * native strings. The lengths include the NULL terminator. */
|
---|
1669 | size_t returned_len = 0;
|
---|
1670 | size_t src_native_len = 0;
|
---|
1671 | size_t dst_native_len = 0;
|
---|
1672 | size_t dststr_libc_len = 0;
|
---|
1673 |
|
---|
1674 | /* Native (character set determined by locale) versions of the
|
---|
1675 | * strings source and destination strings. */
|
---|
1676 | LPSTR src_native = 0;
|
---|
1677 | LPSTR dst_native = 0;
|
---|
1678 |
|
---|
1679 | /* Version of the source and destination strings using the
|
---|
1680 | * "wchar_t" Unicode data type needed by various libc functions. */
|
---|
1681 | wchar_t *srcstr_libc = 0;
|
---|
1682 | wchar_t *dststr_libc = 0;
|
---|
1683 |
|
---|
1684 | if(!(srcstr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
|
---|
1685 | srclen * sizeof(wchar_t))))
|
---|
1686 | {
|
---|
1687 | ERR("Unable to allocate %d bytes for srcstr_libc\n",
|
---|
1688 | srclen * sizeof(wchar_t));
|
---|
1689 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1690 | return 0;
|
---|
1691 | }
|
---|
1692 |
|
---|
1693 | /* Convert source string to a libc Unicode string. */
|
---|
1694 | for(str_idx = 0; str_idx < srclen; str_idx++)
|
---|
1695 | {
|
---|
1696 | srcstr_libc[str_idx] = srcstr[str_idx];
|
---|
1697 | }
|
---|
1698 |
|
---|
1699 | /* src_native should contain at most 3 bytes for each
|
---|
1700 | * multibyte characters in the original srcstr string. */
|
---|
1701 | src_native_len = 3 * srclen;
|
---|
1702 | if(!(src_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0,
|
---|
1703 | src_native_len)))
|
---|
1704 | {
|
---|
1705 | ERR("Unable to allocate %d bytes for src_native\n", src_native_len);
|
---|
1706 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1707 | if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
|
---|
1708 | return 0;
|
---|
1709 | }
|
---|
1710 |
|
---|
1711 | /* FIXME: Prior to to setting the LC_COLLATE locale category the
|
---|
1712 | * current value is backed up so it can be restored after the
|
---|
1713 | * last LC_COLLATE sensitive function returns.
|
---|
1714 | *
|
---|
1715 | * Even though the locale is adjusted for a minimum amount of
|
---|
1716 | * time a race condition exists where other threads may be
|
---|
1717 | * affected if they invoke LC_COLLATE sensitive functions. One
|
---|
1718 | * possible solution is to wrap all LC_COLLATE sensitive Wine
|
---|
1719 | * functions, like LCMapStringW(), in a mutex.
|
---|
1720 | *
|
---|
1721 | * Another enhancement to the following would be to set the
|
---|
1722 | * LC_COLLATE locale category as a function of the "lcid"
|
---|
1723 | * parameter instead of the "LC_COLLATE" environment variable. */
|
---|
1724 | if(!(lc_collate_default = setlocale(LC_COLLATE, NULL)))
|
---|
1725 | {
|
---|
1726 | ERR("Unable to query the LC_COLLATE catagory\n");
|
---|
1727 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1728 | if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
|
---|
1729 | if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
|
---|
1730 | return 0;
|
---|
1731 | }
|
---|
1732 |
|
---|
1733 | if(!(lc_collate_env = setlocale(LC_COLLATE, "")))
|
---|
1734 | {
|
---|
1735 | ERR("Unable to inherit the LC_COLLATE locale category from the "
|
---|
1736 | "environment. The \"LC_COLLATE\" environment variable is "
|
---|
1737 | "\"%s\".\n", getenv("LC_COLLATE") ?
|
---|
1738 | getenv("LC_COLLATE") : "<unset>");
|
---|
1739 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1740 | if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
|
---|
1741 | if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
|
---|
1742 | return 0;
|
---|
1743 | }
|
---|
1744 |
|
---|
1745 | TRACE("lc_collate_default = %s\n", lc_collate_default);
|
---|
1746 | TRACE("lc_collate_env = %s\n", lc_collate_env);
|
---|
1747 |
|
---|
1748 | /* Convert the libc Unicode string to a native multibyte character
|
---|
1749 | * string. */
|
---|
1750 | returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1;
|
---|
1751 | if(returned_len == 0)
|
---|
1752 | {
|
---|
1753 | LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(),
|
---|
1754 | 0, srcstr);
|
---|
1755 | ERR("wcstombs failed. The string specified (%s) may contains an "
|
---|
1756 | "invalid character.\n", srcstr_ascii);
|
---|
1757 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1758 | if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii);
|
---|
1759 | if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
|
---|
1760 | if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
|
---|
1761 | setlocale(LC_COLLATE, lc_collate_default);
|
---|
1762 | return 0;
|
---|
1763 | }
|
---|
1764 | else if(returned_len > src_native_len)
|
---|
1765 | {
|
---|
1766 | src_native[src_native_len - 1] = 0;
|
---|
1767 | ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
|
---|
1768 | "than expected (%d bytes).\n", src_native, returned_len,
|
---|
1769 | dst_native_len);
|
---|
1770 |
|
---|
1771 | /* Since this is an internal error I'm not sure what the correct
|
---|
1772 | * error code is. */
|
---|
1773 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1774 |
|
---|
1775 | if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
|
---|
1776 | if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
|
---|
1777 | setlocale(LC_COLLATE, lc_collate_default);
|
---|
1778 | return 0;
|
---|
1779 | }
|
---|
1780 | src_native_len = returned_len;
|
---|
1781 |
|
---|
1782 | TRACE("src_native = %s src_native_len = %d\n",
|
---|
1783 | src_native, src_native_len);
|
---|
1784 |
|
---|
1785 | /* dst_native seems to contain at most 4 bytes for each byte in
|
---|
1786 | * the original src_native string. Change if need be since this
|
---|
1787 | * isn't documented by the strxfrm() man page. */
|
---|
1788 | dst_native_len = 4 * src_native_len;
|
---|
1789 | if(!(dst_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0, dst_native_len)))
|
---|
1790 | {
|
---|
1791 | ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len);
|
---|
1792 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1793 | if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
|
---|
1794 | if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
|
---|
1795 | setlocale(LC_COLLATE, lc_collate_default);
|
---|
1796 | return 0;
|
---|
1797 | }
|
---|
1798 |
|
---|
1799 | /* The actual translation is done by the following call to
|
---|
1800 | * strxfrm(). The surrounding code could have been simplified
|
---|
1801 | * by calling wcsxfrm() instead except that wcsxfrm() is not
|
---|
1802 | * available on older Linux systems (RedHat 4.1 with
|
---|
1803 | * libc-5.3.12-17).
|
---|
1804 | *
|
---|
1805 | * Also, it is possible that the translation could be done by
|
---|
1806 | * various tables as it is done in LCMapStringA(). However, I'm
|
---|
1807 | * not sure what those tables are. */
|
---|
1808 | returned_len = strxfrm(dst_native, src_native, dst_native_len) + 1;
|
---|
1809 |
|
---|
1810 | if(returned_len > dst_native_len)
|
---|
1811 | {
|
---|
1812 | dst_native[dst_native_len - 1] = 0;
|
---|
1813 | ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
|
---|
1814 | "than expected (%d bytes).\n", dst_native, returned_len,
|
---|
1815 | dst_native_len);
|
---|
1816 |
|
---|
1817 | /* Since this is an internal error I'm not sure what the correct
|
---|
1818 | * error code is. */
|
---|
1819 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1820 |
|
---|
1821 | if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
|
---|
1822 | if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
|
---|
1823 | if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
|
---|
1824 | setlocale(LC_COLLATE, lc_collate_default);
|
---|
1825 | return 0;
|
---|
1826 | }
|
---|
1827 | dst_native_len = returned_len;
|
---|
1828 |
|
---|
1829 | TRACE("dst_native = %s dst_native_len = %d\n",
|
---|
1830 | dst_native, dst_native_len);
|
---|
1831 |
|
---|
1832 | dststr_libc_len = dst_native_len;
|
---|
1833 | if(!(dststr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
|
---|
1834 | dststr_libc_len * sizeof(wchar_t))))
|
---|
1835 | {
|
---|
1836 | ERR("Unable to allocate %d bytes for dststr_libc\n",
|
---|
1837 | dststr_libc_len * sizeof(wchar_t));
|
---|
1838 | SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
---|
1839 | if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
|
---|
1840 | if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
|
---|
1841 | if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
|
---|
1842 | setlocale(LC_COLLATE, lc_collate_default);
|
---|
1843 | return 0;
|
---|
1844 | }
|
---|
1845 |
|
---|
1846 | /* Convert the native multibyte string to a libc Unicode string. */
|
---|
1847 | returned_len = mbstowcs(dststr_libc, dst_native, dst_native_len) + 1;
|
---|
1848 |
|
---|
1849 | /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
|
---|
1850 | * function has returned. */
|
---|
1851 | setlocale(LC_COLLATE, lc_collate_default);
|
---|
1852 |
|
---|
1853 | if(returned_len == 0)
|
---|
1854 | {
|
---|
1855 | ERR("mbstowcs failed. The native version of the translated string "
|
---|
1856 | "(%s) may contain an invalid character.\n", dst_native);
|
---|
1857 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1858 | if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
|
---|
1859 | if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
|
---|
1860 | if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
|
---|
1861 | if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
|
---|
1862 | return 0;
|
---|
1863 | }
|
---|
1864 | if(dstlen)
|
---|
1865 | {
|
---|
1866 | if(returned_len > dstlen)
|
---|
1867 | {
|
---|
1868 | ERR("mbstowcs returned a string that was longer (%d chars) "
|
---|
1869 | "than the buffer provided (%d chars).\n", returned_len,
|
---|
1870 | dstlen);
|
---|
1871 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
1872 | if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
|
---|
1873 | if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
|
---|
1874 | if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
|
---|
1875 | if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
|
---|
1876 | return 0;
|
---|
1877 | }
|
---|
1878 | dstlen = returned_len;
|
---|
1879 |
|
---|
1880 | /* Convert a libc Unicode string to the destination string. */
|
---|
1881 | for(str_idx = 0; str_idx < dstlen; str_idx++)
|
---|
1882 | {
|
---|
1883 | dststr[str_idx] = dststr_libc[str_idx];
|
---|
1884 | }
|
---|
1885 | TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
|
---|
1886 | *(((int *)dststr) + 0),
|
---|
1887 | *(((int *)dststr) + 1),
|
---|
1888 | *(((int *)dststr) + 2),
|
---|
1889 | *(((int *)dststr) + 3));
|
---|
1890 | }
|
---|
1891 | else
|
---|
1892 | {
|
---|
1893 | dstlen = returned_len;
|
---|
1894 | }
|
---|
1895 | TRACE("dstlen (return) = %d\n", dstlen);
|
---|
1896 | if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
|
---|
1897 | if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
|
---|
1898 | if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
|
---|
1899 | if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
|
---|
1900 | return dstlen;
|
---|
1901 | }
|
---|
1902 | else
|
---|
1903 | {
|
---|
1904 | int (*f)(int)=identity;
|
---|
1905 |
|
---|
1906 | if (dstlen==0)
|
---|
1907 | return srclen;
|
---|
1908 | if (dstlen<srclen)
|
---|
1909 | {
|
---|
1910 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
1911 | return 0;
|
---|
1912 | }
|
---|
1913 |
|
---|
1914 | if (mapflags & LCMAP_UPPERCASE)
|
---|
1915 | f = toupper;
|
---|
1916 | else if (mapflags & LCMAP_LOWERCASE)
|
---|
1917 | f = tolower;
|
---|
1918 | if (f)
|
---|
1919 | {
|
---|
1920 | for (i=0; i < srclen; i++)
|
---|
1921 | dststr[i] = (WCHAR) f(srcstr[i]);
|
---|
1922 | }
|
---|
1923 | else
|
---|
1924 | memcpy(dststr, srcstr, sizeof(WCHAR) * srclen);
|
---|
1925 |
|
---|
1926 | return srclen;
|
---|
1927 | }
|
---|
1928 | }
|
---|
1929 |
|
---|
1930 |
|
---|
1931 | /***********************************************************************
|
---|
1932 | * OLE2NLS_EstimateMappingLength
|
---|
1933 | *
|
---|
1934 | * Estimates the number of characters required to hold the string
|
---|
1935 | * computed by LCMapStringA.
|
---|
1936 | *
|
---|
1937 | * The size is always over-estimated, with a fixed limit on the
|
---|
1938 | * amount of estimation error.
|
---|
1939 | *
|
---|
1940 | * Note that len == -1 is not permitted.
|
---|
1941 | */
|
---|
1942 | static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
|
---|
1943 | LPCSTR str, DWORD len)
|
---|
1944 | {
|
---|
1945 | /* Estimate only for small strings to keep the estimation error from
|
---|
1946 | * becoming too large. */
|
---|
1947 | if (len < 128) return len * 8 + 5;
|
---|
1948 | else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
|
---|
1949 | }
|
---|
1950 |
|
---|
1951 | /******************************************************************************
|
---|
1952 | * CompareStringA [KERNEL32.143]
|
---|
1953 | * Compares two strings using locale
|
---|
1954 | *
|
---|
1955 | * RETURNS
|
---|
1956 | *
|
---|
1957 | * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
|
---|
1958 | * failure: 0
|
---|
1959 | *
|
---|
1960 | * NOTES
|
---|
1961 | *
|
---|
1962 | * Defaults to a word sort, but uses a string sort if
|
---|
1963 | * SORT_STRINGSORT is set.
|
---|
1964 | * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
|
---|
1965 | *
|
---|
1966 | * BUGS
|
---|
1967 | *
|
---|
1968 | * This implementation ignores the locale
|
---|
1969 | *
|
---|
1970 | * FIXME
|
---|
1971 | *
|
---|
1972 | * Quite inefficient.
|
---|
1973 | */
|
---|
1974 | UINT WINAPI CompareStringA(
|
---|
1975 | DWORD lcid, /* [in] locale ID */
|
---|
1976 | DWORD fdwStyle, /* [in] comparison-style options */
|
---|
1977 | LPCSTR s1, /* [in] first string */
|
---|
1978 | DWORD l1, /* [in] length of first string */
|
---|
1979 | LPCSTR s2, /* [in] second string */
|
---|
1980 | DWORD l2) /* [in] length of second string */
|
---|
1981 | {
|
---|
1982 | int mapstring_flags;
|
---|
1983 | int len1,len2;
|
---|
1984 | int result;
|
---|
1985 | LPSTR sk1,sk2;
|
---|
1986 | TRACE("%s and %s\n",
|
---|
1987 | debugstr_a (s1), debugstr_a (s2));
|
---|
1988 |
|
---|
1989 | if ( (s1==NULL) || (s2==NULL) )
|
---|
1990 | {
|
---|
1991 | ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
|
---|
1992 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
1993 | return 0;
|
---|
1994 | }
|
---|
1995 |
|
---|
1996 | if(fdwStyle & NORM_IGNORESYMBOLS)
|
---|
1997 | FIXME("IGNORESYMBOLS not supported\n");
|
---|
1998 |
|
---|
1999 | if (l1 == -1) l1 = strlen(s1);
|
---|
2000 | if (l2 == -1) l2 = strlen(s2);
|
---|
2001 |
|
---|
2002 | mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
|
---|
2003 | len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
|
---|
2004 | len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
|
---|
2005 |
|
---|
2006 | if ((len1==0)||(len2==0))
|
---|
2007 | return 0; /* something wrong happened */
|
---|
2008 |
|
---|
2009 | sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
|
---|
2010 | sk2 = sk1 + len1;
|
---|
2011 | if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
|
---|
2012 | || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
|
---|
2013 | {
|
---|
2014 | ERR("Bug in LCmapStringA.\n");
|
---|
2015 | result = 0;
|
---|
2016 | }
|
---|
2017 | else
|
---|
2018 | {
|
---|
2019 | /* strcmp doesn't necessarily return -1, 0, or 1 */
|
---|
2020 | result = strcmp(sk1,sk2);
|
---|
2021 | }
|
---|
2022 | HeapFree(GetProcessHeap(),0,sk1);
|
---|
2023 |
|
---|
2024 | if (result < 0)
|
---|
2025 | return 1;
|
---|
2026 | if (result == 0)
|
---|
2027 | return 2;
|
---|
2028 |
|
---|
2029 | /* must be greater, if we reach this point */
|
---|
2030 | return 3;
|
---|
2031 | }
|
---|
2032 |
|
---|
2033 | /******************************************************************************
|
---|
2034 | * CompareStringW [KERNEL32.144]
|
---|
2035 | * This implementation ignores the locale
|
---|
2036 | * FIXME : Does only string sort. Should
|
---|
2037 | * be reimplemented the same way as CompareStringA.
|
---|
2038 | */
|
---|
2039 | UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
|
---|
2040 | LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
|
---|
2041 | {
|
---|
2042 | int len,ret;
|
---|
2043 | if(fdwStyle & NORM_IGNORENONSPACE)
|
---|
2044 | FIXME("IGNORENONSPACE not supprted\n");
|
---|
2045 | if(fdwStyle & NORM_IGNORESYMBOLS)
|
---|
2046 | FIXME("IGNORESYMBOLS not supported\n");
|
---|
2047 |
|
---|
2048 | /* Is strcmp defaulting to string sort or to word sort?? */
|
---|
2049 | /* FIXME: Handle NORM_STRINGSORT */
|
---|
2050 | l1 = (l1==-1)?strlenW(s1):l1;
|
---|
2051 | l2 = (l2==-1)?strlenW(s2):l2;
|
---|
2052 | len = l1<l2 ? l1:l2;
|
---|
2053 | ret = (fdwStyle & NORM_IGNORECASE) ? strncmpiW(s1,s2,len) : strncmpW(s1,s2,len);
|
---|
2054 | /* not equal, return 1 or 3 */
|
---|
2055 | if(ret!=0) {
|
---|
2056 | /* need to translate result */
|
---|
2057 | return ((int)ret < 0) ? 1 : 3;
|
---|
2058 | }
|
---|
2059 | /* same len, return 2 */
|
---|
2060 | if(l1==l2) return 2;
|
---|
2061 | /* the longer one is lexically greater */
|
---|
2062 | return (l1<l2)? 1 : 3;
|
---|
2063 | }
|
---|
2064 |
|
---|
2065 | /******************************************************************************
|
---|
2066 | * OLE_GetFormatA [Internal]
|
---|
2067 | *
|
---|
2068 | * FIXME
|
---|
2069 | * If datelen == 0, it should return the reguired string length.
|
---|
2070 | *
|
---|
2071 | This function implements stuff for GetDateFormat() and
|
---|
2072 | GetTimeFormat().
|
---|
2073 |
|
---|
2074 | d single-digit (no leading zero) day (of month)
|
---|
2075 | dd two-digit day (of month)
|
---|
2076 | ddd short day-of-week name
|
---|
2077 | dddd long day-of-week name
|
---|
2078 | M single-digit month
|
---|
2079 | MM two-digit month
|
---|
2080 | MMM short month name
|
---|
2081 | MMMM full month name
|
---|
2082 | y two-digit year, no leading 0
|
---|
2083 | yy two-digit year
|
---|
2084 | yyyy four-digit year
|
---|
2085 | gg era string
|
---|
2086 | h hours with no leading zero (12-hour)
|
---|
2087 | hh hours with full two digits
|
---|
2088 | H hours with no leading zero (24-hour)
|
---|
2089 | HH hours with full two digits
|
---|
2090 | m minutes with no leading zero
|
---|
2091 | mm minutes with full two digits
|
---|
2092 | s seconds with no leading zero
|
---|
2093 | ss seconds with full two digits
|
---|
2094 | t time marker (A or P)
|
---|
2095 | tt time marker (AM, PM)
|
---|
2096 | '' used to quote literal characters
|
---|
2097 | '' (within a quoted string) indicates a literal '
|
---|
2098 |
|
---|
2099 | These functions REQUIRE valid locale, date, and format.
|
---|
2100 | */
|
---|
2101 | static INT OLE_GetFormatA(LCID locale,
|
---|
2102 | DWORD flags,
|
---|
2103 | DWORD tflags,
|
---|
2104 | LPSYSTEMTIME xtime,
|
---|
2105 | LPCSTR _format, /*in*/
|
---|
2106 | LPSTR date, /*out*/
|
---|
2107 | INT datelen)
|
---|
2108 | {
|
---|
2109 | INT inpos, outpos;
|
---|
2110 | int count, type, inquote, Overflow;
|
---|
2111 | char buf[40];
|
---|
2112 | char format[40];
|
---|
2113 | char * pos;
|
---|
2114 | int buflen;
|
---|
2115 |
|
---|
2116 | const char * _dgfmt[] = { "%d", "%02d" };
|
---|
2117 | const char ** dgfmt = _dgfmt - 1;
|
---|
2118 |
|
---|
2119 | /* report, for debugging */
|
---|
2120 | TRACE("(0x%lx,0x%lx, 0x%lx, time(y=%d m=%d wd=%d d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
|
---|
2121 | locale, flags, tflags,
|
---|
2122 | xtime->wYear,xtime->wMonth,xtime->wDayOfWeek,xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
|
---|
2123 | _format, _format, date, datelen);
|
---|
2124 |
|
---|
2125 | if(datelen == 0) {
|
---|
2126 | FIXME("datelen = 0, returning 255\n");
|
---|
2127 | return 255;
|
---|
2128 | }
|
---|
2129 |
|
---|
2130 | /* initalize state variables and output buffer */
|
---|
2131 | inpos = outpos = 0;
|
---|
2132 | count = 0; inquote = 0; Overflow = 0;
|
---|
2133 | type = '\0';
|
---|
2134 | date[0] = buf[0] = '\0';
|
---|
2135 |
|
---|
2136 | strcpy(format,_format);
|
---|
2137 |
|
---|
2138 | /* alter the formatstring, while it works for all languages now in wine
|
---|
2139 | its possible that it fails when the time looks like ss:mm:hh as example*/
|
---|
2140 | if (tflags & (TIME_NOMINUTESORSECONDS))
|
---|
2141 | { if ((pos = strstr ( format, ":mm")))
|
---|
2142 | { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
|
---|
2143 | }
|
---|
2144 | }
|
---|
2145 | if (tflags & (TIME_NOSECONDS))
|
---|
2146 | { if ((pos = strstr ( format, ":ss")))
|
---|
2147 | { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
|
---|
2148 | }
|
---|
2149 | }
|
---|
2150 |
|
---|
2151 | for (inpos = 0;; inpos++) {
|
---|
2152 | /* TRACE("STATE inpos=%2d outpos=%2d count=%d inquote=%d type=%c buf,date = %c,%c\n", inpos, outpos, count, inquote, type, buf[inpos], date[outpos]); */
|
---|
2153 | if (inquote) {
|
---|
2154 | if (format[inpos] == '\'') {
|
---|
2155 | if (format[inpos+1] == '\'') {
|
---|
2156 | inpos += 1;
|
---|
2157 | date[outpos++] = '\'';
|
---|
2158 | } else {
|
---|
2159 | inquote = 0;
|
---|
2160 | continue; /* we did nothing to the output */
|
---|
2161 | }
|
---|
2162 | } else if (format[inpos] == '\0') {
|
---|
2163 | date[outpos++] = '\0';
|
---|
2164 | if (outpos > datelen) Overflow = 1;
|
---|
2165 | break;
|
---|
2166 | } else {
|
---|
2167 | date[outpos++] = format[inpos];
|
---|
2168 | if (outpos > datelen) {
|
---|
2169 | Overflow = 1;
|
---|
2170 | date[outpos-1] = '\0'; /* this is the last place where
|
---|
2171 | it's safe to write */
|
---|
2172 | break;
|
---|
2173 | }
|
---|
2174 | }
|
---|
2175 | } else if ( (count && (format[inpos] != type))
|
---|
2176 | || count == 4
|
---|
2177 | || (count == 2 && strchr("ghHmst", type)) ) {
|
---|
2178 | if (type == 'h' && (tflags & TIME_FORCE24HOURFORMAT)) type= 'H';
|
---|
2179 | if (type == 'd') {
|
---|
2180 | if (count == 4) {
|
---|
2181 | GetLocaleInfoA(locale,
|
---|
2182 | LOCALE_SDAYNAME1
|
---|
2183 | + (xtime->wDayOfWeek+6)%7,
|
---|
2184 | buf, sizeof(buf));
|
---|
2185 | } else if (count == 3) {
|
---|
2186 | GetLocaleInfoA(locale,
|
---|
2187 | LOCALE_SABBREVDAYNAME1
|
---|
2188 | + (xtime->wDayOfWeek+6)%7,
|
---|
2189 | buf, sizeof(buf));
|
---|
2190 | } else {
|
---|
2191 | sprintf(buf, dgfmt[count], xtime->wDay);
|
---|
2192 | }
|
---|
2193 | } else if (type == 'M') {
|
---|
2194 | if (count == 3) {
|
---|
2195 | GetLocaleInfoA(locale,
|
---|
2196 | LOCALE_SABBREVMONTHNAME1
|
---|
2197 | + xtime->wMonth - 1,
|
---|
2198 | buf, sizeof(buf));
|
---|
2199 | } else if (count == 4) {
|
---|
2200 | GetLocaleInfoA(locale,
|
---|
2201 | LOCALE_SMONTHNAME1
|
---|
2202 | + xtime->wMonth - 1,
|
---|
2203 | buf, sizeof(buf));
|
---|
2204 | } else {
|
---|
2205 | sprintf(buf, dgfmt[count], xtime->wMonth);
|
---|
2206 | }
|
---|
2207 | } else if (type == 'y') {
|
---|
2208 | if (count == 4) {
|
---|
2209 | sprintf(buf, "%d", xtime->wYear);
|
---|
2210 | } else if (count == 3) {
|
---|
2211 | strcpy(buf, "yyy");
|
---|
2212 | WARN("unknown format, c=%c, n=%d\n", type, count);
|
---|
2213 | } else {
|
---|
2214 | sprintf(buf, dgfmt[count], xtime->wYear % 100);
|
---|
2215 | }
|
---|
2216 | } else if (type == 'g') {
|
---|
2217 | if (count == 2) {
|
---|
2218 | FIXME("LOCALE_ICALENDARTYPE unimp.\n");
|
---|
2219 | strcpy(buf, "AD");
|
---|
2220 | } else {
|
---|
2221 | strcpy(buf, "g");
|
---|
2222 | WARN("unknown format, c=%c, n=%d\n", type, count);
|
---|
2223 | }
|
---|
2224 | } else if (type == 'h') {
|
---|
2225 | /* gives us hours 1:00 -- 12:00 */
|
---|
2226 | sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
|
---|
2227 | } else if (type == 'H') {
|
---|
2228 | /* 24-hour time */
|
---|
2229 | sprintf(buf, dgfmt[count], xtime->wHour);
|
---|
2230 | } else if ( type == 'm') {
|
---|
2231 | sprintf(buf, dgfmt[count], xtime->wMinute);
|
---|
2232 | } else if ( type == 's') {
|
---|
2233 | sprintf(buf, dgfmt[count], xtime->wSecond);
|
---|
2234 | } else if (type == 't') {
|
---|
2235 | if ((tflags & TIME_NOTIMEMARKER))
|
---|
2236 | buf[0]='\0';
|
---|
2237 | else if (count == 1) {
|
---|
2238 | sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
|
---|
2239 | } else if (count == 2) {
|
---|
2240 | /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
|
---|
2241 | GetLocaleInfoA(locale,
|
---|
2242 | (xtime->wHour<12)
|
---|
2243 | ? LOCALE_S1159 : LOCALE_S2359,
|
---|
2244 | buf, sizeof(buf));
|
---|
2245 | }
|
---|
2246 | };
|
---|
2247 |
|
---|
2248 | /* we need to check the next char in the format string
|
---|
2249 | again, no matter what happened */
|
---|
2250 | inpos--;
|
---|
2251 |
|
---|
2252 | /* add the contents of buf to the output */
|
---|
2253 | buflen = strlen(buf);
|
---|
2254 | if (outpos + buflen < datelen) {
|
---|
2255 | date[outpos] = '\0'; /* for strcat to hook onto */
|
---|
2256 | strcat(date, buf);
|
---|
2257 | outpos += buflen;
|
---|
2258 | } else {
|
---|
2259 | date[outpos] = '\0';
|
---|
2260 | strncat(date, buf, datelen - outpos);
|
---|
2261 | date[datelen - 1] = '\0';
|
---|
2262 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
2263 | WARN("insufficient buffer\n");
|
---|
2264 | return 0;
|
---|
2265 | }
|
---|
2266 |
|
---|
2267 | /* reset the variables we used to keep track of this item */
|
---|
2268 | count = 0;
|
---|
2269 | type = '\0';
|
---|
2270 | } else if (format[inpos] == '\0') {
|
---|
2271 | /* we can't check for this at the loop-head, because
|
---|
2272 | that breaks the printing of the last format-item */
|
---|
2273 | date[outpos] = '\0';
|
---|
2274 | break;
|
---|
2275 | } else if (count) {
|
---|
2276 | /* continuing a code for an item */
|
---|
2277 | count +=1;
|
---|
2278 | continue;
|
---|
2279 | } else if (strchr("hHmstyMdg", format[inpos])) {
|
---|
2280 | type = format[inpos];
|
---|
2281 | count = 1;
|
---|
2282 | continue;
|
---|
2283 | } else if (format[inpos] == '\'') {
|
---|
2284 | inquote = 1;
|
---|
2285 | continue;
|
---|
2286 | } else {
|
---|
2287 | date[outpos++] = format[inpos];
|
---|
2288 | }
|
---|
2289 | /* now deal with a possible buffer overflow */
|
---|
2290 | if (outpos >= datelen) {
|
---|
2291 | date[datelen - 1] = '\0';
|
---|
2292 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
2293 | return 0;
|
---|
2294 | }
|
---|
2295 | }
|
---|
2296 |
|
---|
2297 | if (Overflow) {
|
---|
2298 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
2299 | };
|
---|
2300 |
|
---|
2301 | /* finish it off with a string terminator */
|
---|
2302 | outpos++;
|
---|
2303 | /* sanity check */
|
---|
2304 | if (outpos > datelen-1) outpos = datelen-1;
|
---|
2305 | date[outpos] = '\0';
|
---|
2306 |
|
---|
2307 | TRACE("returns string '%s', len %d\n", date, outpos);
|
---|
2308 | return outpos;
|
---|
2309 | }
|
---|
2310 |
|
---|
2311 | /******************************************************************************
|
---|
2312 | * OLE_GetFormatW [INTERNAL]
|
---|
2313 | */
|
---|
2314 | static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
|
---|
2315 | LPSYSTEMTIME xtime,
|
---|
2316 | LPCWSTR format,
|
---|
2317 | LPWSTR output, INT outlen)
|
---|
2318 | {
|
---|
2319 | INT inpos, outpos;
|
---|
2320 | int count, type=0, inquote;
|
---|
2321 | int Overflow; /* loop check */
|
---|
2322 | char tmp[16];
|
---|
2323 | WCHAR buf[40];
|
---|
2324 | int buflen=0;
|
---|
2325 | WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
|
---|
2326 | WCHAR arg2[] = {'%','0','2','d',0};
|
---|
2327 | WCHAR *argarr[3];
|
---|
2328 | int datevars=0, timevars=0;
|
---|
2329 |
|
---|
2330 | argarr[0] = arg0;
|
---|
2331 | argarr[1] = arg1;
|
---|
2332 | argarr[2] = arg2;
|
---|
2333 |
|
---|
2334 | /* make a debug report */
|
---|
2335 | TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
|
---|
2336 | "%p with max len %d\n",
|
---|
2337 | locale, flags, tflags,
|
---|
2338 | xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
|
---|
2339 | debugstr_w(format), format, output, outlen);
|
---|
2340 |
|
---|
2341 | if(outlen == 0) {
|
---|
2342 | FIXME("outlen = 0, returning 255\n");
|
---|
2343 | return 255;
|
---|
2344 | }
|
---|
2345 |
|
---|
2346 | /* initialize state variables */
|
---|
2347 | inpos = outpos = 0;
|
---|
2348 | count = 0;
|
---|
2349 | inquote = Overflow = 0;
|
---|
2350 | /* this is really just a sanity check */
|
---|
2351 | output[0] = buf[0] = 0;
|
---|
2352 |
|
---|
2353 | /* this loop is the core of the function */
|
---|
2354 | for (inpos = 0; /* we have several break points */ ; inpos++) {
|
---|
2355 | if (inquote) {
|
---|
2356 | if (format[inpos] == (WCHAR) '\'') {
|
---|
2357 | if (format[inpos+1] == '\'') {
|
---|
2358 | inpos++;
|
---|
2359 | output[outpos++] = '\'';
|
---|
2360 | } else {
|
---|
2361 | inquote = 0;
|
---|
2362 | continue;
|
---|
2363 | }
|
---|
2364 | } else if (format[inpos] == 0) {
|
---|
2365 | output[outpos++] = 0;
|
---|
2366 | if (outpos > outlen) Overflow = 1;
|
---|
2367 | break; /* normal exit (within a quote) */
|
---|
2368 | } else {
|
---|
2369 | output[outpos++] = format[inpos]; /* copy input */
|
---|
2370 | if (outpos > outlen) {
|
---|
2371 | Overflow = 1;
|
---|
2372 | output[outpos-1] = 0;
|
---|
2373 | break;
|
---|
2374 | }
|
---|
2375 | }
|
---|
2376 | } else if ( (count && (format[inpos] != type))
|
---|
2377 | || ( (count==4 && type =='y') ||
|
---|
2378 | (count==4 && type =='M') ||
|
---|
2379 | (count==4 && type =='d') ||
|
---|
2380 | (count==2 && type =='g') ||
|
---|
2381 | (count==2 && type =='h') ||
|
---|
2382 | (count==2 && type =='H') ||
|
---|
2383 | (count==2 && type =='m') ||
|
---|
2384 | (count==2 && type =='s') ||
|
---|
2385 | (count==2 && type =='t') ) ) {
|
---|
2386 | switch(type)
|
---|
2387 | {
|
---|
2388 | case 'd':
|
---|
2389 | if (count == 4) {
|
---|
2390 | GetLocaleInfoW(locale,
|
---|
2391 | LOCALE_SDAYNAME1 + (xtime->wDayOfWeek +6)%7,
|
---|
2392 | buf, sizeof(buf)/sizeof(WCHAR) );
|
---|
2393 | } else if (count == 3) {
|
---|
2394 | GetLocaleInfoW(locale,
|
---|
2395 | LOCALE_SABBREVDAYNAME1 +
|
---|
2396 | (xtime->wDayOfWeek +6)%7,
|
---|
2397 | buf, sizeof(buf)/sizeof(WCHAR) );
|
---|
2398 | } else {
|
---|
2399 | sprintf( tmp, "%.*d", count, xtime->wDay );
|
---|
2400 | MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
|
---|
2401 | }
|
---|
2402 | break;
|
---|
2403 |
|
---|
2404 | case 'M':
|
---|
2405 | if (count == 4) {
|
---|
2406 | GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
|
---|
2407 | xtime->wMonth -1, buf,
|
---|
2408 | sizeof(buf)/sizeof(WCHAR) );
|
---|
2409 | } else if (count == 3) {
|
---|
2410 | GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
|
---|
2411 | xtime->wMonth -1, buf,
|
---|
2412 | sizeof(buf)/sizeof(WCHAR) );
|
---|
2413 | } else {
|
---|
2414 | sprintf( tmp, "%.*d", count, xtime->wMonth );
|
---|
2415 | MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
|
---|
2416 | }
|
---|
2417 | break;
|
---|
2418 | case 'y':
|
---|
2419 | if (count == 4) {
|
---|
2420 | sprintf( tmp, "%d", xtime->wYear );
|
---|
2421 | } else if (count == 3) {
|
---|
2422 | strcpy( tmp, "yyy" );
|
---|
2423 | } else {
|
---|
2424 | sprintf( tmp, "%.*d", count, xtime->wYear % 100 );
|
---|
2425 | }
|
---|
2426 | MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
|
---|
2427 | break;
|
---|
2428 |
|
---|
2429 | case 'g':
|
---|
2430 | if (count == 2) {
|
---|
2431 | FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
|
---|
2432 | strcpy( tmp, "AD" );
|
---|
2433 | } else {
|
---|
2434 | /* Win API sez we copy it verbatim */
|
---|
2435 | strcpy( tmp, "g" );
|
---|
2436 | }
|
---|
2437 | MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
|
---|
2438 | break;
|
---|
2439 |
|
---|
2440 | case 'h':
|
---|
2441 | /* hours 1:00-12:00 --- is this right? */
|
---|
2442 | sprintf( tmp, "%.*d", count, (xtime->wHour-1)%12 +1);
|
---|
2443 | MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
|
---|
2444 | break;
|
---|
2445 |
|
---|
2446 | case 'H':
|
---|
2447 | sprintf( tmp, "%.*d", count, xtime->wHour );
|
---|
2448 | MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
|
---|
2449 | break;
|
---|
2450 |
|
---|
2451 | case 'm':
|
---|
2452 | sprintf( tmp, "%.*d", count, xtime->wMinute );
|
---|
2453 | MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
|
---|
2454 | break;
|
---|
2455 |
|
---|
2456 | case 's':
|
---|
2457 | sprintf( tmp, "%.*d", count, xtime->wSecond );
|
---|
2458 | MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
|
---|
2459 | break;
|
---|
2460 |
|
---|
2461 | case 't':
|
---|
2462 | GetLocaleInfoW(locale, (xtime->wHour < 12) ?
|
---|
2463 | LOCALE_S1159 : LOCALE_S2359,
|
---|
2464 | buf, sizeof(buf) );
|
---|
2465 | if (count == 1) {
|
---|
2466 | buf[1] = 0;
|
---|
2467 | }
|
---|
2468 | break;
|
---|
2469 | }
|
---|
2470 |
|
---|
2471 | /* no matter what happened, we need to check this next
|
---|
2472 | character the next time we loop through */
|
---|
2473 | inpos--;
|
---|
2474 |
|
---|
2475 | /* cat buf onto the output */
|
---|
2476 | outlen = strlenW(buf);
|
---|
2477 | if (outpos + buflen < outlen) {
|
---|
2478 | strcpyW( output + outpos, buf );
|
---|
2479 | outpos += buflen;
|
---|
2480 | } else {
|
---|
2481 | lstrcpynW( output + outpos, buf, outlen - outpos );
|
---|
2482 | Overflow = 1;
|
---|
2483 | break; /* Abnormal exit */
|
---|
2484 | }
|
---|
2485 |
|
---|
2486 | /* reset the variables we used this time */
|
---|
2487 | count = 0;
|
---|
2488 | type = '\0';
|
---|
2489 | } else if (format[inpos] == 0) {
|
---|
2490 | /* we can't check for this at the beginning, because that
|
---|
2491 | would keep us from printing a format spec that ended the
|
---|
2492 | string */
|
---|
2493 | output[outpos] = 0;
|
---|
2494 | break; /* NORMAL EXIT */
|
---|
2495 | } else if (count) {
|
---|
2496 | /* how we keep track of the middle of a format spec */
|
---|
2497 | count++;
|
---|
2498 | continue;
|
---|
2499 | } else if ( (datevars && (format[inpos]=='d' ||
|
---|
2500 | format[inpos]=='M' ||
|
---|
2501 | format[inpos]=='y' ||
|
---|
2502 | format[inpos]=='g') ) ||
|
---|
2503 | (timevars && (format[inpos]=='H' ||
|
---|
2504 | format[inpos]=='h' ||
|
---|
2505 | format[inpos]=='m' ||
|
---|
2506 | format[inpos]=='s' ||
|
---|
2507 | format[inpos]=='t') ) ) {
|
---|
2508 | type = format[inpos];
|
---|
2509 | count = 1;
|
---|
2510 | continue;
|
---|
2511 | } else if (format[inpos] == '\'') {
|
---|
2512 | inquote = 1;
|
---|
2513 | continue;
|
---|
2514 | } else {
|
---|
2515 | /* unquoted literals */
|
---|
2516 | output[outpos++] = format[inpos];
|
---|
2517 | }
|
---|
2518 | }
|
---|
2519 |
|
---|
2520 | if (Overflow) {
|
---|
2521 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
2522 | WARN(" buffer overflow\n");
|
---|
2523 | };
|
---|
2524 |
|
---|
2525 | /* final string terminator and sanity check */
|
---|
2526 | outpos++;
|
---|
2527 | if (outpos > outlen-1) outpos = outlen-1;
|
---|
2528 | output[outpos] = '0';
|
---|
2529 |
|
---|
2530 | TRACE(" returning %s\n", debugstr_w(output));
|
---|
2531 |
|
---|
2532 | return (!Overflow) ? outlen : 0;
|
---|
2533 |
|
---|
2534 | }
|
---|
2535 |
|
---|
2536 |
|
---|
2537 | /******************************************************************************
|
---|
2538 | * GetDateFormatA [KERNEL32.310]
|
---|
2539 | * Makes an ASCII string of the date
|
---|
2540 | *
|
---|
2541 | * This function uses format to format the date, or, if format
|
---|
2542 | * is NULL, uses the default for the locale. format is a string
|
---|
2543 | * of literal fields and characters as follows:
|
---|
2544 | *
|
---|
2545 | * - d single-digit (no leading zero) day (of month)
|
---|
2546 | * - dd two-digit day (of month)
|
---|
2547 | * - ddd short day-of-week name
|
---|
2548 | * - dddd long day-of-week name
|
---|
2549 | * - M single-digit month
|
---|
2550 | * - MM two-digit month
|
---|
2551 | * - MMM short month name
|
---|
2552 | * - MMMM full month name
|
---|
2553 | * - y two-digit year, no leading 0
|
---|
2554 | * - yy two-digit year
|
---|
2555 | * - yyyy four-digit year
|
---|
2556 | * - gg era string
|
---|
2557 | *
|
---|
2558 | */
|
---|
2559 | INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
|
---|
2560 | CONST SYSTEMTIME *xtime,
|
---|
2561 | LPCSTR format, LPSTR date,INT datelen)
|
---|
2562 | {
|
---|
2563 |
|
---|
2564 | char format_buf[40];
|
---|
2565 | LPCSTR thisformat;
|
---|
2566 | SYSTEMTIME t;
|
---|
2567 | LPSYSTEMTIME thistime;
|
---|
2568 | LCID thislocale;
|
---|
2569 | INT ret;
|
---|
2570 | FILETIME ft;
|
---|
2571 | BOOL res;
|
---|
2572 |
|
---|
2573 | TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
|
---|
2574 | locale,flags,xtime,format,date,datelen);
|
---|
2575 |
|
---|
2576 | if (!locale) {
|
---|
2577 | locale = LOCALE_SYSTEM_DEFAULT;
|
---|
2578 | };
|
---|
2579 |
|
---|
2580 | if (locale == LOCALE_SYSTEM_DEFAULT) {
|
---|
2581 | thislocale = GetSystemDefaultLCID();
|
---|
2582 | } else if (locale == LOCALE_USER_DEFAULT) {
|
---|
2583 | thislocale = GetUserDefaultLCID();
|
---|
2584 | } else {
|
---|
2585 | thislocale = locale;
|
---|
2586 | };
|
---|
2587 |
|
---|
2588 | if (xtime == NULL) {
|
---|
2589 | GetSystemTime(&t);
|
---|
2590 | } else {
|
---|
2591 | /* Silently correct wDayOfWeek by tranforming to FileTime and back again*/
|
---|
2592 | res=SystemTimeToFileTime(xtime,&ft);
|
---|
2593 | /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error*/
|
---|
2594 | /*FIXME: SystemTimeToFileTime doesn't yet do that ckeck*/
|
---|
2595 | if(!res)
|
---|
2596 | {
|
---|
2597 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2598 | return 0;
|
---|
2599 | }
|
---|
2600 | FileTimeToSystemTime(&ft,&t);
|
---|
2601 |
|
---|
2602 | };
|
---|
2603 | thistime = &t;
|
---|
2604 |
|
---|
2605 | if (format == NULL) {
|
---|
2606 | GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
|
---|
2607 | ? LOCALE_SLONGDATE
|
---|
2608 | : LOCALE_SSHORTDATE),
|
---|
2609 | format_buf, sizeof(format_buf));
|
---|
2610 | thisformat = format_buf;
|
---|
2611 | } else {
|
---|
2612 | thisformat = format;
|
---|
2613 | };
|
---|
2614 |
|
---|
2615 |
|
---|
2616 | ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
|
---|
2617 | date, datelen);
|
---|
2618 |
|
---|
2619 |
|
---|
2620 | TRACE(
|
---|
2621 | "GetDateFormatA() returning %d, with data=%s\n",
|
---|
2622 | ret, date);
|
---|
2623 | return ret;
|
---|
2624 | }
|
---|
2625 |
|
---|
2626 | /******************************************************************************
|
---|
2627 | * GetDateFormatW [KERNEL32.311]
|
---|
2628 | * Makes a Unicode string of the date
|
---|
2629 | *
|
---|
2630 | * Acts the same as GetDateFormatA(), except that it's Unicode.
|
---|
2631 | * Accepts & returns sizes as counts of Unicode characters.
|
---|
2632 | *
|
---|
2633 | */
|
---|
2634 | INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
|
---|
2635 | CONST SYSTEMTIME *xtime,
|
---|
2636 | LPCWSTR format,
|
---|
2637 | LPWSTR date, INT datelen)
|
---|
2638 | {
|
---|
2639 | #ifdef __WIN32OS2__
|
---|
2640 | // convert "format" on passing in into ASCII
|
---|
2641 | LPSTR pszAsciiFormat = UnicodeToAsciiString((LPWSTR) format);
|
---|
2642 | LPSTR pszAsciiDate = (char *)alloca(datelen);
|
---|
2643 | int rc;
|
---|
2644 |
|
---|
2645 | TRACE("Kernel32-ole2nls: GetDateFormatW(0x%04lx,0x%08lx,%p,%s,%p,%d) not yet complete\n",
|
---|
2646 | locale,flags,xtime,pszAsciiFormat,date,datelen);
|
---|
2647 |
|
---|
2648 | // call ASCII variant
|
---|
2649 | rc = GetDateFormatA(locale,
|
---|
2650 | flags,
|
---|
2651 | xtime,
|
---|
2652 | pszAsciiFormat,
|
---|
2653 | pszAsciiDate,
|
---|
2654 | datelen); // is in "characters", not bytes
|
---|
2655 |
|
---|
2656 | FreeAsciiString(pszAsciiFormat);
|
---|
2657 |
|
---|
2658 | // convert "date" on returning to UNICODE
|
---|
2659 | if (datelen != 0)
|
---|
2660 | {
|
---|
2661 | // in this case 'rc' holds the number of characters to convert
|
---|
2662 | lstrcpynAtoW(date, pszAsciiDate, rc);
|
---|
2663 | }
|
---|
2664 |
|
---|
2665 | return rc;
|
---|
2666 |
|
---|
2667 | #else
|
---|
2668 | unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
|
---|
2669 |
|
---|
2670 | FIXME("STUB (should call OLE_GetFormatW)\n");
|
---|
2671 | lstrcpynW(date, datearr, datelen);
|
---|
2672 | return ( datelen < 9) ? datelen : 9;
|
---|
2673 | #endif
|
---|
2674 | }
|
---|
2675 |
|
---|
2676 | /**************************************************************************
|
---|
2677 | * EnumDateFormatsA (KERNEL32.198)
|
---|
2678 | */
|
---|
2679 | BOOL WINAPI EnumDateFormatsA(
|
---|
2680 | DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
|
---|
2681 | {
|
---|
2682 | LCID Loc = GetUserDefaultLCID();
|
---|
2683 | if(!lpDateFmtEnumProc)
|
---|
2684 | {
|
---|
2685 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2686 | return FALSE;
|
---|
2687 | }
|
---|
2688 |
|
---|
2689 | switch( Loc )
|
---|
2690 | {
|
---|
2691 |
|
---|
2692 | case 0x00000407: /* (Loc,"de_DE") */
|
---|
2693 | {
|
---|
2694 | switch(dwFlags)
|
---|
2695 | {
|
---|
2696 | case DATE_SHORTDATE:
|
---|
2697 | if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
|
---|
2698 | if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
|
---|
2699 | if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
|
---|
2700 | if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
|
---|
2701 | return TRUE;
|
---|
2702 | case DATE_LONGDATE:
|
---|
2703 | if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
|
---|
2704 | if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
|
---|
2705 | if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
|
---|
2706 | return TRUE;
|
---|
2707 | default:
|
---|
2708 | FIXME("Unknown date format (%ld)\n", dwFlags);
|
---|
2709 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2710 | return FALSE;
|
---|
2711 | }
|
---|
2712 | }
|
---|
2713 |
|
---|
2714 | case 0x0000040c: /* (Loc,"fr_FR") */
|
---|
2715 | {
|
---|
2716 | switch(dwFlags)
|
---|
2717 | {
|
---|
2718 | case DATE_SHORTDATE:
|
---|
2719 | if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
|
---|
2720 | if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
|
---|
2721 | if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
|
---|
2722 | if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
|
---|
2723 | return TRUE;
|
---|
2724 | case DATE_LONGDATE:
|
---|
2725 | if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
|
---|
2726 | if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
|
---|
2727 | if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
|
---|
2728 | return TRUE;
|
---|
2729 | default:
|
---|
2730 | FIXME("Unknown date format (%ld)\n", dwFlags);
|
---|
2731 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2732 | return FALSE;
|
---|
2733 | }
|
---|
2734 | }
|
---|
2735 |
|
---|
2736 | case 0x00000c0c: /* (Loc,"fr_CA") */
|
---|
2737 | {
|
---|
2738 | switch(dwFlags)
|
---|
2739 | {
|
---|
2740 | case DATE_SHORTDATE:
|
---|
2741 | if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
|
---|
2742 | if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
|
---|
2743 | if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
|
---|
2744 | if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
|
---|
2745 | return TRUE;
|
---|
2746 | case DATE_LONGDATE:
|
---|
2747 | if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
|
---|
2748 | if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
|
---|
2749 | return TRUE;
|
---|
2750 | default:
|
---|
2751 | FIXME("Unknown date format (%ld)\n", dwFlags);
|
---|
2752 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2753 | return FALSE;
|
---|
2754 | }
|
---|
2755 | }
|
---|
2756 |
|
---|
2757 | case 0x00000809: /* (Loc,"en_UK") */
|
---|
2758 | {
|
---|
2759 | switch(dwFlags)
|
---|
2760 | {
|
---|
2761 | case DATE_SHORTDATE:
|
---|
2762 | if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
|
---|
2763 | if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
|
---|
2764 | if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
|
---|
2765 | if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
|
---|
2766 | return TRUE;
|
---|
2767 | case DATE_LONGDATE:
|
---|
2768 | if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
|
---|
2769 | if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
|
---|
2770 | return TRUE;
|
---|
2771 | default:
|
---|
2772 | FIXME("Unknown date format (%ld)\n", dwFlags);
|
---|
2773 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2774 | return FALSE;
|
---|
2775 | }
|
---|
2776 | }
|
---|
2777 |
|
---|
2778 | case 0x00000c09: /* (Loc,"en_AU") */
|
---|
2779 | {
|
---|
2780 | switch(dwFlags)
|
---|
2781 | {
|
---|
2782 | case DATE_SHORTDATE:
|
---|
2783 | if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
|
---|
2784 | if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
|
---|
2785 | if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
|
---|
2786 | return TRUE;
|
---|
2787 | case DATE_LONGDATE:
|
---|
2788 | if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
|
---|
2789 | if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
|
---|
2790 | return TRUE;
|
---|
2791 | default:
|
---|
2792 | FIXME("Unknown date format (%ld)\n", dwFlags);
|
---|
2793 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2794 | return FALSE;
|
---|
2795 | }
|
---|
2796 | }
|
---|
2797 |
|
---|
2798 | case 0x00001009: /* (Loc,"en_CA") */
|
---|
2799 | {
|
---|
2800 | switch(dwFlags)
|
---|
2801 | {
|
---|
2802 | case DATE_SHORTDATE:
|
---|
2803 | if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
|
---|
2804 | if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
|
---|
2805 | if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
|
---|
2806 | if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
|
---|
2807 | return TRUE;
|
---|
2808 | case DATE_LONGDATE:
|
---|
2809 | if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
|
---|
2810 | if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
|
---|
2811 | return TRUE;
|
---|
2812 | default:
|
---|
2813 | FIXME("Unknown date format (%ld)\n", dwFlags);
|
---|
2814 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2815 | return FALSE;
|
---|
2816 | }
|
---|
2817 | }
|
---|
2818 |
|
---|
2819 | case 0x00001409: /* (Loc,"en_NZ") */
|
---|
2820 | {
|
---|
2821 | switch(dwFlags)
|
---|
2822 | {
|
---|
2823 | case DATE_SHORTDATE:
|
---|
2824 | if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
|
---|
2825 | if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
|
---|
2826 | if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
|
---|
2827 | return TRUE;
|
---|
2828 | case DATE_LONGDATE:
|
---|
2829 | if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
|
---|
2830 | if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
|
---|
2831 | return TRUE;
|
---|
2832 | default:
|
---|
2833 | FIXME("Unknown date format (%ld)\n", dwFlags);
|
---|
2834 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2835 | return FALSE;
|
---|
2836 | }
|
---|
2837 | }
|
---|
2838 |
|
---|
2839 | case 0x00001809: /* (Loc,"en_IE") */
|
---|
2840 | {
|
---|
2841 | switch(dwFlags)
|
---|
2842 | {
|
---|
2843 | case DATE_SHORTDATE:
|
---|
2844 | if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
|
---|
2845 | if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
|
---|
2846 | if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
|
---|
2847 | return TRUE;
|
---|
2848 | case DATE_LONGDATE:
|
---|
2849 | if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
|
---|
2850 | if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
|
---|
2851 | return TRUE;
|
---|
2852 | default:
|
---|
2853 | FIXME("Unknown date format (%ld)\n", dwFlags);
|
---|
2854 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2855 | return FALSE;
|
---|
2856 | }
|
---|
2857 | }
|
---|
2858 |
|
---|
2859 | case 0x00001c09: /* (Loc,"en_ZA") */
|
---|
2860 | {
|
---|
2861 | switch(dwFlags)
|
---|
2862 | {
|
---|
2863 | case DATE_SHORTDATE:
|
---|
2864 | if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
|
---|
2865 | return TRUE;
|
---|
2866 | case DATE_LONGDATE:
|
---|
2867 | if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
|
---|
2868 | return TRUE;
|
---|
2869 | default:
|
---|
2870 | FIXME("Unknown date format (%ld)\n", dwFlags);
|
---|
2871 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2872 | return FALSE;
|
---|
2873 | }
|
---|
2874 | }
|
---|
2875 |
|
---|
2876 | case 0x00002009: /* (Loc,"en_JM") */
|
---|
2877 | {
|
---|
2878 | switch(dwFlags)
|
---|
2879 | {
|
---|
2880 | case DATE_SHORTDATE:
|
---|
2881 | if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
|
---|
2882 | return TRUE;
|
---|
2883 | case DATE_LONGDATE:
|
---|
2884 | if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
|
---|
2885 | if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
|
---|
2886 | if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
|
---|
2887 | if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
|
---|
2888 | return TRUE;
|
---|
2889 | default:
|
---|
2890 | FIXME("Unknown date format (%ld)\n", dwFlags);
|
---|
2891 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2892 | return FALSE;
|
---|
2893 | }
|
---|
2894 | }
|
---|
2895 |
|
---|
2896 | case 0x00002809: /* (Loc,"en_BZ") */
|
---|
2897 | case 0x00002c09: /* (Loc,"en_TT") */
|
---|
2898 | {
|
---|
2899 | switch(dwFlags)
|
---|
2900 | {
|
---|
2901 | case DATE_SHORTDATE:
|
---|
2902 | if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
|
---|
2903 | return TRUE;
|
---|
2904 | case DATE_LONGDATE:
|
---|
2905 | if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
|
---|
2906 | return TRUE;
|
---|
2907 | default:
|
---|
2908 | FIXME("Unknown date format (%ld)\n", dwFlags);
|
---|
2909 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2910 | return FALSE;
|
---|
2911 | }
|
---|
2912 | }
|
---|
2913 |
|
---|
2914 | default: /* default to US English "en_US" */
|
---|
2915 | {
|
---|
2916 | switch(dwFlags)
|
---|
2917 | {
|
---|
2918 | case DATE_SHORTDATE:
|
---|
2919 | if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
|
---|
2920 | if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
|
---|
2921 | if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
|
---|
2922 | if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
|
---|
2923 | if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
|
---|
2924 | if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
|
---|
2925 | return TRUE;
|
---|
2926 | case DATE_LONGDATE:
|
---|
2927 | if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
|
---|
2928 | if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
|
---|
2929 | if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
|
---|
2930 | if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
|
---|
2931 | return TRUE;
|
---|
2932 | default:
|
---|
2933 | FIXME("Unknown date format (%ld)\n", dwFlags);
|
---|
2934 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2935 | return FALSE;
|
---|
2936 | }
|
---|
2937 | }
|
---|
2938 | }
|
---|
2939 | }
|
---|
2940 |
|
---|
2941 | /**************************************************************************
|
---|
2942 | * EnumDateFormatsW (KERNEL32.199)
|
---|
2943 | */
|
---|
2944 | BOOL WINAPI EnumDateFormatsW(
|
---|
2945 | DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
|
---|
2946 | {
|
---|
2947 | FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
|
---|
2948 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
---|
2949 | return FALSE;
|
---|
2950 | }
|
---|
2951 |
|
---|
2952 | /**************************************************************************
|
---|
2953 | * EnumTimeFormatsA (KERNEL32.210)
|
---|
2954 | */
|
---|
2955 | BOOL WINAPI EnumTimeFormatsA(
|
---|
2956 | TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
|
---|
2957 | {
|
---|
2958 | LCID Loc = GetUserDefaultLCID();
|
---|
2959 | if(!lpTimeFmtEnumProc)
|
---|
2960 | {
|
---|
2961 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
2962 | return FALSE;
|
---|
2963 | }
|
---|
2964 | if(dwFlags)
|
---|
2965 | {
|
---|
2966 | FIXME("Unknown time format (%ld)\n", dwFlags);
|
---|
2967 | }
|
---|
2968 |
|
---|
2969 | switch( Loc )
|
---|
2970 | {
|
---|
2971 | case 0x00000407: /* (Loc,"de_DE") */
|
---|
2972 | {
|
---|
2973 | if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
|
---|
2974 | if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
|
---|
2975 | if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
|
---|
2976 | if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
|
---|
2977 | if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
|
---|
2978 | return TRUE;
|
---|
2979 | }
|
---|
2980 |
|
---|
2981 | case 0x0000040c: /* (Loc,"fr_FR") */
|
---|
2982 | case 0x00000c0c: /* (Loc,"fr_CA") */
|
---|
2983 | {
|
---|
2984 | if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
|
---|
2985 | if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
|
---|
2986 | if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
|
---|
2987 | if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
|
---|
2988 | if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
|
---|
2989 | return TRUE;
|
---|
2990 | }
|
---|
2991 |
|
---|
2992 | case 0x00000809: /* (Loc,"en_UK") */
|
---|
2993 | case 0x00000c09: /* (Loc,"en_AU") */
|
---|
2994 | case 0x00001409: /* (Loc,"en_NZ") */
|
---|
2995 | case 0x00001809: /* (Loc,"en_IE") */
|
---|
2996 | {
|
---|
2997 | if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
|
---|
2998 | if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
|
---|
2999 | if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
|
---|
3000 | return TRUE;
|
---|
3001 | }
|
---|
3002 |
|
---|
3003 | case 0x00001c09: /* (Loc,"en_ZA") */
|
---|
3004 | case 0x00002809: /* (Loc,"en_BZ") */
|
---|
3005 | case 0x00002c09: /* (Loc,"en_TT") */
|
---|
3006 | {
|
---|
3007 | if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
|
---|
3008 | if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
|
---|
3009 | return TRUE;
|
---|
3010 | }
|
---|
3011 |
|
---|
3012 | default: /* default to US style "en_US" */
|
---|
3013 | {
|
---|
3014 | if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
|
---|
3015 | if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
|
---|
3016 | if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
|
---|
3017 | if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
|
---|
3018 | return TRUE;
|
---|
3019 | }
|
---|
3020 | }
|
---|
3021 | }
|
---|
3022 |
|
---|
3023 | /**************************************************************************
|
---|
3024 | * EnumTimeFormatsW (KERNEL32.211)
|
---|
3025 | */
|
---|
3026 | BOOL WINAPI EnumTimeFormatsW(
|
---|
3027 | TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
|
---|
3028 | {
|
---|
3029 | FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
|
---|
3030 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
---|
3031 | return FALSE;
|
---|
3032 | }
|
---|
3033 |
|
---|
3034 | /**************************************************************************
|
---|
3035 | * This function is used just locally !
|
---|
3036 | * Description: Inverts a string.
|
---|
3037 | */
|
---|
3038 | static void OLE_InvertString(char* string)
|
---|
3039 | {
|
---|
3040 | char sTmpArray[128];
|
---|
3041 | INT counter, i = 0;
|
---|
3042 |
|
---|
3043 | for (counter = strlen(string); counter > 0; counter--)
|
---|
3044 | {
|
---|
3045 | memcpy(sTmpArray + i, string + counter-1, 1);
|
---|
3046 | i++;
|
---|
3047 | }
|
---|
3048 | memcpy(sTmpArray + i, "\0", 1);
|
---|
3049 | strcpy(string, sTmpArray);
|
---|
3050 | }
|
---|
3051 |
|
---|
3052 | /***************************************************************************************
|
---|
3053 | * This function is used just locally !
|
---|
3054 | * Description: Test if the given string (psNumber) is valid or not.
|
---|
3055 | * The valid characters are the following:
|
---|
3056 | * - Characters '0' through '9'.
|
---|
3057 | * - One decimal point (dot) if the number is a floating-point value.
|
---|
3058 | * - A minus sign in the first character position if the number is
|
---|
3059 | * a negative value.
|
---|
3060 | * If the function succeeds, psBefore/psAfter will point to the string
|
---|
3061 | * on the right/left of the decimal symbol. pbNegative indicates if the
|
---|
3062 | * number is negative.
|
---|
3063 | */
|
---|
3064 | static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
|
---|
3065 | {
|
---|
3066 | char sNumberSet[] = "0123456789";
|
---|
3067 | BOOL bInDecimal = FALSE;
|
---|
3068 |
|
---|
3069 | /* Test if we do have a minus sign */
|
---|
3070 | if ( *pInput == '-' )
|
---|
3071 | {
|
---|
3072 | *pbNegative = TRUE;
|
---|
3073 | pInput++; /* Jump to the next character. */
|
---|
3074 | }
|
---|
3075 |
|
---|
3076 | while(*pInput != '\0')
|
---|
3077 | {
|
---|
3078 | /* Do we have a valid numeric character */
|
---|
3079 | if ( strchr(sNumberSet, *pInput) != NULL )
|
---|
3080 | {
|
---|
3081 | if (bInDecimal == TRUE)
|
---|
3082 | *psAfter++ = *pInput;
|
---|
3083 | else
|
---|
3084 | *psBefore++ = *pInput;
|
---|
3085 | }
|
---|
3086 | else
|
---|
3087 | {
|
---|
3088 | /* Is this a decimal point (dot) */
|
---|
3089 | if ( *pInput == '.' )
|
---|
3090 | {
|
---|
3091 | /* Is it the first time we find it */
|
---|
3092 | if ((bInDecimal == FALSE))
|
---|
3093 | bInDecimal = TRUE;
|
---|
3094 | else
|
---|
3095 | return -1; /* ERROR: Invalid parameter */
|
---|
3096 | }
|
---|
3097 | else
|
---|
3098 | {
|
---|
3099 | /* It's neither a numeric character, nor a decimal point.
|
---|
3100 | * Thus, return an error.
|
---|
3101 | */
|
---|
3102 | return -1;
|
---|
3103 | }
|
---|
3104 | }
|
---|
3105 | pInput++;
|
---|
3106 | }
|
---|
3107 |
|
---|
3108 | /* Add an End of Line character to the output buffers */
|
---|
3109 | *psBefore = '\0';
|
---|
3110 | *psAfter = '\0';
|
---|
3111 |
|
---|
3112 | return 0;
|
---|
3113 | }
|
---|
3114 |
|
---|
3115 | /**************************************************************************
|
---|
3116 | * This function is used just locally !
|
---|
3117 | * Description: A number could be formatted using different numbers
|
---|
3118 | * of "digits in group" (example: 4;3;2;0).
|
---|
3119 | * The first parameter of this function is an array
|
---|
3120 | * containing the rule to be used. It's format is the following:
|
---|
3121 | * |NDG|DG1|DG2|...|0|
|
---|
3122 | * where NDG is the number of used "digits in group" and DG1, DG2,
|
---|
3123 | * are the corresponding "digits in group".
|
---|
3124 | * Thus, this function returns the grouping value in the array
|
---|
3125 | * pointed by the second parameter.
|
---|
3126 | */
|
---|
3127 | static INT OLE_GetGrouping(char* sRule, INT index)
|
---|
3128 | {
|
---|
3129 | char sData[2], sRuleSize[2];
|
---|
3130 | INT nData, nRuleSize;
|
---|
3131 |
|
---|
3132 | memcpy(sRuleSize, sRule, 1);
|
---|
3133 | memcpy(sRuleSize+1, "\0", 1);
|
---|
3134 | nRuleSize = atoi(sRuleSize);
|
---|
3135 |
|
---|
3136 | if (index > 0 && index < nRuleSize)
|
---|
3137 | {
|
---|
3138 | memcpy(sData, sRule+index, 1);
|
---|
3139 | memcpy(sData+1, "\0", 1);
|
---|
3140 | nData = atoi(sData);
|
---|
3141 | }
|
---|
3142 |
|
---|
3143 | else
|
---|
3144 | {
|
---|
3145 | memcpy(sData, sRule+nRuleSize-1, 1);
|
---|
3146 | memcpy(sData+1, "\0", 1);
|
---|
3147 | nData = atoi(sData);
|
---|
3148 | }
|
---|
3149 |
|
---|
3150 | return nData;
|
---|
3151 | }
|
---|
3152 |
|
---|
3153 | /**************************************************************************
|
---|
3154 | * GetNumberFormatA (KERNEL32.355)
|
---|
3155 | */
|
---|
3156 | INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
|
---|
3157 | LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
|
---|
3158 | LPSTR lpNumberStr, int cchNumber)
|
---|
3159 | {
|
---|
3160 | char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
|
---|
3161 | INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
|
---|
3162 | char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
|
---|
3163 | char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
|
---|
3164 | char *pStr = NULL, *pTmpStr = NULL;
|
---|
3165 | LCID systemDefaultLCID;
|
---|
3166 | BOOL bNegative = FALSE;
|
---|
3167 | enum Operations
|
---|
3168 | {
|
---|
3169 | USE_PARAMETER,
|
---|
3170 | USE_LOCALEINFO,
|
---|
3171 | USE_SYSTEMDEFAULT,
|
---|
3172 | RETURN_ERROR
|
---|
3173 | } used_operation;
|
---|
3174 |
|
---|
3175 | strncpy(sNumber, lpvalue, 128);
|
---|
3176 | sNumber[127] = '\0';
|
---|
3177 |
|
---|
3178 | /* Make sure we have a valid input string, get the number
|
---|
3179 | * of digits before and after the decimal symbol, and check
|
---|
3180 | * if this is a negative number.
|
---|
3181 | */
|
---|
3182 | if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
|
---|
3183 | {
|
---|
3184 | nNumberDecimal = strlen(sDigitsBeforeDecimal);
|
---|
3185 | nDigits = strlen(sDigitsAfterDecimal);
|
---|
3186 | }
|
---|
3187 | else
|
---|
3188 | {
|
---|
3189 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
3190 | return 0;
|
---|
3191 | }
|
---|
3192 |
|
---|
3193 | /* Which source will we use to format the string */
|
---|
3194 | used_operation = RETURN_ERROR;
|
---|
3195 | if (lpFormat != NULL)
|
---|
3196 | {
|
---|
3197 | if (dwflags == 0)
|
---|
3198 | used_operation = USE_PARAMETER;
|
---|
3199 | }
|
---|
3200 | else
|
---|
3201 | {
|
---|
3202 | if (dwflags & LOCALE_NOUSEROVERRIDE)
|
---|
3203 | used_operation = USE_LOCALEINFO;
|
---|
3204 | else
|
---|
3205 | used_operation = USE_SYSTEMDEFAULT;
|
---|
3206 | }
|
---|
3207 |
|
---|
3208 | /* Load the fields we need */
|
---|
3209 | switch(used_operation)
|
---|
3210 | {
|
---|
3211 | case USE_LOCALEINFO:
|
---|
3212 | GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
|
---|
3213 | GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
|
---|
3214 | GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
|
---|
3215 | GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
|
---|
3216 | GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
|
---|
3217 | GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
|
---|
3218 | break;
|
---|
3219 | case USE_PARAMETER:
|
---|
3220 | sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
|
---|
3221 | strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
|
---|
3222 | sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
|
---|
3223 | strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
|
---|
3224 | sprintf(sILZero, "%d",lpFormat->LeadingZero);
|
---|
3225 | sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
|
---|
3226 | break;
|
---|
3227 | case USE_SYSTEMDEFAULT:
|
---|
3228 | systemDefaultLCID = GetSystemDefaultLCID();
|
---|
3229 | GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
|
---|
3230 | GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
|
---|
3231 | GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
|
---|
3232 | GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
|
---|
3233 | GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
|
---|
3234 | GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
|
---|
3235 | break;
|
---|
3236 | default:
|
---|
3237 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
3238 | return 0;
|
---|
3239 | }
|
---|
3240 |
|
---|
3241 | nNumberDigits = atoi(sNumberDigits);
|
---|
3242 |
|
---|
3243 | /* Remove the ";" */
|
---|
3244 | i=0;
|
---|
3245 | j = 1;
|
---|
3246 | for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
|
---|
3247 | {
|
---|
3248 | if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
|
---|
3249 | {
|
---|
3250 | memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
|
---|
3251 | i++;
|
---|
3252 | j++;
|
---|
3253 | }
|
---|
3254 | }
|
---|
3255 | sprintf(sBuffer, "%d", i);
|
---|
3256 | memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
|
---|
3257 | memcpy(sRule + j, "\0", 1);
|
---|
3258 |
|
---|
3259 | /* First, format the digits before the decimal. */
|
---|
3260 | if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
|
---|
3261 | {
|
---|
3262 | /* Working on an inverted string is easier ! */
|
---|
3263 | OLE_InvertString(sDigitsBeforeDecimal);
|
---|
3264 |
|
---|
3265 | nStep = nCounter = i = j = 0;
|
---|
3266 | nRuleIndex = 1;
|
---|
3267 | nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
|
---|
3268 |
|
---|
3269 | /* Here, we will loop until we reach the end of the string.
|
---|
3270 | * An internal counter (j) is used in order to know when to
|
---|
3271 | * insert the "digit group symbol".
|
---|
3272 | */
|
---|
3273 | while (nNumberDecimal > 0)
|
---|
3274 | {
|
---|
3275 | i = nCounter + nStep;
|
---|
3276 | memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
|
---|
3277 | nCounter++;
|
---|
3278 | j++;
|
---|
3279 | if (j >= nGrouping)
|
---|
3280 | {
|
---|
3281 | j = 0;
|
---|
3282 | if (nRuleIndex < sRule[0])
|
---|
3283 | nRuleIndex++;
|
---|
3284 | nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
|
---|
3285 | memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
|
---|
3286 | nStep+= strlen(sDigitGroupSymbol);
|
---|
3287 | }
|
---|
3288 |
|
---|
3289 | nNumberDecimal--;
|
---|
3290 | }
|
---|
3291 |
|
---|
3292 | memcpy(sDestination + i+1, "\0", 1);
|
---|
3293 | /* Get the string in the right order ! */
|
---|
3294 | OLE_InvertString(sDestination);
|
---|
3295 | }
|
---|
3296 | else
|
---|
3297 | {
|
---|
3298 | nLZ = atoi(sILZero);
|
---|
3299 | if (nLZ != 0)
|
---|
3300 | {
|
---|
3301 | /* Use 0.xxx instead of .xxx */
|
---|
3302 | memcpy(sDestination, "0", 1);
|
---|
3303 | memcpy(sDestination+1, "\0", 1);
|
---|
3304 | }
|
---|
3305 | else
|
---|
3306 | memcpy(sDestination, "\0", 1);
|
---|
3307 |
|
---|
3308 | }
|
---|
3309 |
|
---|
3310 | /* Second, format the digits after the decimal. */
|
---|
3311 | j = 0;
|
---|
3312 | nCounter = nNumberDigits;
|
---|
3313 | if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
|
---|
3314 | {
|
---|
3315 | i = strlen(sNumber) - strlen(pStr) + 1;
|
---|
3316 | strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
|
---|
3317 | j = strlen(sDigitsAfterDecimal);
|
---|
3318 | if (j < nNumberDigits)
|
---|
3319 | nCounter = nNumberDigits-j;
|
---|
3320 | }
|
---|
3321 | for (i=0;i<nCounter;i++)
|
---|
3322 | memcpy(sDigitsAfterDecimal+i+j, "0", 1);
|
---|
3323 | memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
|
---|
3324 |
|
---|
3325 | i = strlen(sDestination);
|
---|
3326 | j = strlen(sDigitsAfterDecimal);
|
---|
3327 | /* Finally, construct the resulting formatted string. */
|
---|
3328 |
|
---|
3329 | for (nCounter=0; nCounter<i; nCounter++)
|
---|
3330 | memcpy(sNumber + nCounter, sDestination + nCounter, 1);
|
---|
3331 |
|
---|
3332 | memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
|
---|
3333 |
|
---|
3334 | for (i=0; i<j; i++)
|
---|
3335 | memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
|
---|
3336 | memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
|
---|
3337 |
|
---|
3338 | /* Is it a negative number */
|
---|
3339 | if (bNegative == TRUE)
|
---|
3340 | {
|
---|
3341 | i = atoi(sNegNumber);
|
---|
3342 | pStr = sDestination;
|
---|
3343 | pTmpStr = sNumber;
|
---|
3344 | switch (i)
|
---|
3345 | {
|
---|
3346 | case 0:
|
---|
3347 | *pStr++ = '(';
|
---|
3348 | while (*sNumber != '\0')
|
---|
3349 | *pStr++ = *pTmpStr++;
|
---|
3350 | *pStr++ = ')';
|
---|
3351 | break;
|
---|
3352 | case 1:
|
---|
3353 | *pStr++ = '-';
|
---|
3354 | while (*pTmpStr != '\0')
|
---|
3355 | *pStr++ = *pTmpStr++;
|
---|
3356 | break;
|
---|
3357 | case 2:
|
---|
3358 | *pStr++ = '-';
|
---|
3359 | *pStr++ = ' ';
|
---|
3360 | while (*pTmpStr != '\0')
|
---|
3361 | *pStr++ = *pTmpStr++;
|
---|
3362 | break;
|
---|
3363 | case 3:
|
---|
3364 | while (*pTmpStr != '\0')
|
---|
3365 | *pStr++ = *pTmpStr++;
|
---|
3366 | *pStr++ = '-';
|
---|
3367 | break;
|
---|
3368 | case 4:
|
---|
3369 | while (*pTmpStr != '\0')
|
---|
3370 | *pStr++ = *pTmpStr++;
|
---|
3371 | *pStr++ = ' ';
|
---|
3372 | *pStr++ = '-';
|
---|
3373 | break;
|
---|
3374 | default:
|
---|
3375 | while (*pTmpStr != '\0')
|
---|
3376 | *pStr++ = *pTmpStr++;
|
---|
3377 | break;
|
---|
3378 | }
|
---|
3379 | }
|
---|
3380 | else
|
---|
3381 | strcpy(sDestination, sNumber);
|
---|
3382 |
|
---|
3383 | /* If cchNumber is zero, then returns the number of bytes or characters
|
---|
3384 | * required to hold the formatted number string
|
---|
3385 | */
|
---|
3386 | if (cchNumber==0)
|
---|
3387 | retVal = strlen(sDestination) + 1;
|
---|
3388 | else
|
---|
3389 | {
|
---|
3390 | strncpy (lpNumberStr, sDestination, cchNumber-1);
|
---|
3391 | *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
|
---|
3392 | retVal = strlen(lpNumberStr);
|
---|
3393 | }
|
---|
3394 |
|
---|
3395 | return retVal;
|
---|
3396 | }
|
---|
3397 |
|
---|
3398 | /**************************************************************************
|
---|
3399 | * GetNumberFormatW (KERNEL32.@)
|
---|
3400 | */
|
---|
3401 | INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
|
---|
3402 | LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
|
---|
3403 | LPWSTR lpNumberStr, int cchNumber)
|
---|
3404 | {
|
---|
3405 | FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue));
|
---|
3406 |
|
---|
3407 | lstrcpynW( lpNumberStr, lpvalue, cchNumber );
|
---|
3408 | return cchNumber? strlenW( lpNumberStr ) : 0;
|
---|
3409 | }
|
---|
3410 |
|
---|
3411 | /**************************************************************************
|
---|
3412 | * GetCurrencyFormatA (KERNEL32.302)
|
---|
3413 | */
|
---|
3414 | INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
|
---|
3415 | LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
|
---|
3416 | LPSTR lpCurrencyStr, int cchCurrency)
|
---|
3417 | {
|
---|
3418 | UINT nPosOrder, nNegOrder;
|
---|
3419 | INT retVal;
|
---|
3420 | char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
|
---|
3421 | char *pDestination = sDestination;
|
---|
3422 | char sNumberFormated[128];
|
---|
3423 | char *pNumberFormated = sNumberFormated;
|
---|
3424 | LCID systemDefaultLCID;
|
---|
3425 | BOOL bIsPositive = FALSE, bValidFormat = FALSE;
|
---|
3426 | enum Operations
|
---|
3427 | {
|
---|
3428 | USE_PARAMETER,
|
---|
3429 | USE_LOCALEINFO,
|
---|
3430 | USE_SYSTEMDEFAULT,
|
---|
3431 | RETURN_ERROR
|
---|
3432 | } used_operation;
|
---|
3433 |
|
---|
3434 | NUMBERFMTA numberFmt;
|
---|
3435 |
|
---|
3436 | /* Which source will we use to format the string */
|
---|
3437 | used_operation = RETURN_ERROR;
|
---|
3438 | if (lpFormat != NULL)
|
---|
3439 | {
|
---|
3440 | if (dwflags == 0)
|
---|
3441 | used_operation = USE_PARAMETER;
|
---|
3442 | }
|
---|
3443 | else
|
---|
3444 | {
|
---|
3445 | if (dwflags & LOCALE_NOUSEROVERRIDE)
|
---|
3446 | used_operation = USE_LOCALEINFO;
|
---|
3447 | else
|
---|
3448 | used_operation = USE_SYSTEMDEFAULT;
|
---|
3449 | }
|
---|
3450 |
|
---|
3451 | /* Load the fields we need */
|
---|
3452 | switch(used_operation)
|
---|
3453 | {
|
---|
3454 | case USE_LOCALEINFO:
|
---|
3455 | /* Specific to CURRENCYFMTA*/
|
---|
3456 | GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
|
---|
3457 | GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
|
---|
3458 | GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
|
---|
3459 |
|
---|
3460 | nPosOrder = atoi(sPosOrder);
|
---|
3461 | nNegOrder = atoi(sNegOrder);
|
---|
3462 | break;
|
---|
3463 | case USE_PARAMETER:
|
---|
3464 | /* Specific to CURRENCYFMTA*/
|
---|
3465 | nNegOrder = lpFormat->NegativeOrder;
|
---|
3466 | nPosOrder = lpFormat->PositiveOrder;
|
---|
3467 | strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
|
---|
3468 | break;
|
---|
3469 | case USE_SYSTEMDEFAULT:
|
---|
3470 | systemDefaultLCID = GetSystemDefaultLCID();
|
---|
3471 | /* Specific to CURRENCYFMTA*/
|
---|
3472 | GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
|
---|
3473 | GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
|
---|
3474 | GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
|
---|
3475 |
|
---|
3476 | nPosOrder = atoi(sPosOrder);
|
---|
3477 | nNegOrder = atoi(sNegOrder);
|
---|
3478 | break;
|
---|
3479 | default:
|
---|
3480 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
3481 | return 0;
|
---|
3482 | }
|
---|
3483 |
|
---|
3484 | /* Construct a temporary number format structure */
|
---|
3485 | if (lpFormat != NULL)
|
---|
3486 | {
|
---|
3487 | numberFmt.NumDigits = lpFormat->NumDigits;
|
---|
3488 | numberFmt.LeadingZero = lpFormat->LeadingZero;
|
---|
3489 | numberFmt.Grouping = lpFormat->Grouping;
|
---|
3490 | numberFmt.NegativeOrder = 0;
|
---|
3491 | numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
|
---|
3492 | numberFmt.lpThousandSep = lpFormat->lpThousandSep;
|
---|
3493 | bValidFormat = TRUE;
|
---|
3494 | }
|
---|
3495 |
|
---|
3496 | /* Make a call to GetNumberFormatA() */
|
---|
3497 | if (*lpvalue == '-')
|
---|
3498 | {
|
---|
3499 | bIsPositive = FALSE;
|
---|
3500 | retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
|
---|
3501 | }
|
---|
3502 | else
|
---|
3503 | {
|
---|
3504 | bIsPositive = TRUE;
|
---|
3505 | retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
|
---|
3506 | }
|
---|
3507 |
|
---|
3508 | if (retVal == 0)
|
---|
3509 | return 0;
|
---|
3510 |
|
---|
3511 | /* construct the formatted string */
|
---|
3512 | if (bIsPositive)
|
---|
3513 | {
|
---|
3514 | switch (nPosOrder)
|
---|
3515 | {
|
---|
3516 | case 0: /* Prefix, no separation */
|
---|
3517 | strcpy (pDestination, sCurrencySymbol);
|
---|
3518 | strcat (pDestination, pNumberFormated);
|
---|
3519 | break;
|
---|
3520 | case 1: /* Suffix, no separation */
|
---|
3521 | strcpy (pDestination, pNumberFormated);
|
---|
3522 | strcat (pDestination, sCurrencySymbol);
|
---|
3523 | break;
|
---|
3524 | case 2: /* Prefix, 1 char separation */
|
---|
3525 | strcpy (pDestination, sCurrencySymbol);
|
---|
3526 | strcat (pDestination, " ");
|
---|
3527 | strcat (pDestination, pNumberFormated);
|
---|
3528 | break;
|
---|
3529 | case 3: /* Suffix, 1 char separation */
|
---|
3530 | strcpy (pDestination, pNumberFormated);
|
---|
3531 | strcat (pDestination, " ");
|
---|
3532 | strcat (pDestination, sCurrencySymbol);
|
---|
3533 | break;
|
---|
3534 | default:
|
---|
3535 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
3536 | return 0;
|
---|
3537 | }
|
---|
3538 | }
|
---|
3539 | else /* negative number */
|
---|
3540 | {
|
---|
3541 | switch (nNegOrder)
|
---|
3542 | {
|
---|
3543 | case 0: /* format: ($1.1) */
|
---|
3544 | strcpy (pDestination, "(");
|
---|
3545 | strcat (pDestination, sCurrencySymbol);
|
---|
3546 | strcat (pDestination, pNumberFormated);
|
---|
3547 | strcat (pDestination, ")");
|
---|
3548 | break;
|
---|
3549 | case 1: /* format: -$1.1 */
|
---|
3550 | strcpy (pDestination, "-");
|
---|
3551 | strcat (pDestination, sCurrencySymbol);
|
---|
3552 | strcat (pDestination, pNumberFormated);
|
---|
3553 | break;
|
---|
3554 | case 2: /* format: $-1.1 */
|
---|
3555 | strcpy (pDestination, sCurrencySymbol);
|
---|
3556 | strcat (pDestination, "-");
|
---|
3557 | strcat (pDestination, pNumberFormated);
|
---|
3558 | break;
|
---|
3559 | case 3: /* format: $1.1- */
|
---|
3560 | strcpy (pDestination, sCurrencySymbol);
|
---|
3561 | strcat (pDestination, pNumberFormated);
|
---|
3562 | strcat (pDestination, "-");
|
---|
3563 | break;
|
---|
3564 | case 4: /* format: (1.1$) */
|
---|
3565 | strcpy (pDestination, "(");
|
---|
3566 | strcat (pDestination, pNumberFormated);
|
---|
3567 | strcat (pDestination, sCurrencySymbol);
|
---|
3568 | strcat (pDestination, ")");
|
---|
3569 | break;
|
---|
3570 | case 5: /* format: -1.1$ */
|
---|
3571 | strcpy (pDestination, "-");
|
---|
3572 | strcat (pDestination, pNumberFormated);
|
---|
3573 | strcat (pDestination, sCurrencySymbol);
|
---|
3574 | break;
|
---|
3575 | case 6: /* format: 1.1-$ */
|
---|
3576 | strcpy (pDestination, pNumberFormated);
|
---|
3577 | strcat (pDestination, "-");
|
---|
3578 | strcat (pDestination, sCurrencySymbol);
|
---|
3579 | break;
|
---|
3580 | case 7: /* format: 1.1$- */
|
---|
3581 | strcpy (pDestination, pNumberFormated);
|
---|
3582 | strcat (pDestination, sCurrencySymbol);
|
---|
3583 | strcat (pDestination, "-");
|
---|
3584 | break;
|
---|
3585 | case 8: /* format: -1.1 $ */
|
---|
3586 | strcpy (pDestination, "-");
|
---|
3587 | strcat (pDestination, pNumberFormated);
|
---|
3588 | strcat (pDestination, " ");
|
---|
3589 | strcat (pDestination, sCurrencySymbol);
|
---|
3590 | break;
|
---|
3591 | case 9: /* format: -$ 1.1 */
|
---|
3592 | strcpy (pDestination, "-");
|
---|
3593 | strcat (pDestination, sCurrencySymbol);
|
---|
3594 | strcat (pDestination, " ");
|
---|
3595 | strcat (pDestination, pNumberFormated);
|
---|
3596 | break;
|
---|
3597 | case 10: /* format: 1.1 $- */
|
---|
3598 | strcpy (pDestination, pNumberFormated);
|
---|
3599 | strcat (pDestination, " ");
|
---|
3600 | strcat (pDestination, sCurrencySymbol);
|
---|
3601 | strcat (pDestination, "-");
|
---|
3602 | break;
|
---|
3603 | case 11: /* format: $ 1.1- */
|
---|
3604 | strcpy (pDestination, sCurrencySymbol);
|
---|
3605 | strcat (pDestination, " ");
|
---|
3606 | strcat (pDestination, pNumberFormated);
|
---|
3607 | strcat (pDestination, "-");
|
---|
3608 | break;
|
---|
3609 | case 12: /* format: $ -1.1 */
|
---|
3610 | strcpy (pDestination, sCurrencySymbol);
|
---|
3611 | strcat (pDestination, " ");
|
---|
3612 | strcat (pDestination, "-");
|
---|
3613 | strcat (pDestination, pNumberFormated);
|
---|
3614 | break;
|
---|
3615 | case 13: /* format: 1.1- $ */
|
---|
3616 | strcpy (pDestination, pNumberFormated);
|
---|
3617 | strcat (pDestination, "-");
|
---|
3618 | strcat (pDestination, " ");
|
---|
3619 | strcat (pDestination, sCurrencySymbol);
|
---|
3620 | break;
|
---|
3621 | case 14: /* format: ($ 1.1) */
|
---|
3622 | strcpy (pDestination, "(");
|
---|
3623 | strcat (pDestination, sCurrencySymbol);
|
---|
3624 | strcat (pDestination, " ");
|
---|
3625 | strcat (pDestination, pNumberFormated);
|
---|
3626 | strcat (pDestination, ")");
|
---|
3627 | break;
|
---|
3628 | case 15: /* format: (1.1 $) */
|
---|
3629 | strcpy (pDestination, "(");
|
---|
3630 | strcat (pDestination, pNumberFormated);
|
---|
3631 | strcat (pDestination, " ");
|
---|
3632 | strcat (pDestination, sCurrencySymbol);
|
---|
3633 | strcat (pDestination, ")");
|
---|
3634 | break;
|
---|
3635 | default:
|
---|
3636 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
3637 | return 0;
|
---|
3638 | }
|
---|
3639 | }
|
---|
3640 |
|
---|
3641 | if (cchCurrency == 0)
|
---|
3642 | return strlen(pDestination) + 1;
|
---|
3643 |
|
---|
3644 | else
|
---|
3645 | {
|
---|
3646 | strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
|
---|
3647 | *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
|
---|
3648 | return strlen(lpCurrencyStr);
|
---|
3649 | }
|
---|
3650 | }
|
---|
3651 |
|
---|
3652 | /**************************************************************************
|
---|
3653 | * GetCurrencyFormatW (KERNEL32.303)
|
---|
3654 | */
|
---|
3655 | INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
|
---|
3656 | LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
|
---|
3657 | LPWSTR lpCurrencyStr, int cchCurrency)
|
---|
3658 | {
|
---|
3659 | FIXME("This API function is NOT implemented !\n");
|
---|
3660 | return 0;
|
---|
3661 | }
|
---|
3662 |
|
---|
3663 | /******************************************************************************
|
---|
3664 | * OLE2NLS_CheckLocale [intern]
|
---|
3665 | */
|
---|
3666 | static LCID OLE2NLS_CheckLocale (LCID locale)
|
---|
3667 | {
|
---|
3668 | if (!locale)
|
---|
3669 | { locale = LOCALE_SYSTEM_DEFAULT;
|
---|
3670 | }
|
---|
3671 |
|
---|
3672 | if (locale == LOCALE_SYSTEM_DEFAULT)
|
---|
3673 | { return GetSystemDefaultLCID();
|
---|
3674 | }
|
---|
3675 | else if (locale == LOCALE_USER_DEFAULT)
|
---|
3676 | { return GetUserDefaultLCID();
|
---|
3677 | }
|
---|
3678 | else
|
---|
3679 | { return locale;
|
---|
3680 | }
|
---|
3681 | }
|
---|
3682 | /******************************************************************************
|
---|
3683 | * GetTimeFormatA [KERNEL32.422]
|
---|
3684 | * Makes an ASCII string of the time
|
---|
3685 | *
|
---|
3686 | * Formats date according to format, or locale default if format is
|
---|
3687 | * NULL. The format consists of literal characters and fields as follows:
|
---|
3688 | *
|
---|
3689 | * h hours with no leading zero (12-hour)
|
---|
3690 | * hh hours with full two digits
|
---|
3691 | * H hours with no leading zero (24-hour)
|
---|
3692 | * HH hours with full two digits
|
---|
3693 | * m minutes with no leading zero
|
---|
3694 | * mm minutes with full two digits
|
---|
3695 | * s seconds with no leading zero
|
---|
3696 | * ss seconds with full two digits
|
---|
3697 | * t time marker (A or P)
|
---|
3698 | * tt time marker (AM, PM)
|
---|
3699 | *
|
---|
3700 | */
|
---|
3701 | INT WINAPI
|
---|
3702 | GetTimeFormatA(LCID locale, /* [in] */
|
---|
3703 | DWORD flags, /* [in] */
|
---|
3704 | CONST SYSTEMTIME *xtime, /* [in] */
|
---|
3705 | LPCSTR format, /* [in] */
|
---|
3706 | LPSTR timestr, /* [out] */
|
---|
3707 | INT timelen /* [in] */)
|
---|
3708 | { char format_buf[40];
|
---|
3709 | LPCSTR thisformat;
|
---|
3710 | SYSTEMTIME t;
|
---|
3711 | LPSYSTEMTIME thistime;
|
---|
3712 | LCID thislocale=0;
|
---|
3713 | DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
|
---|
3714 | INT ret;
|
---|
3715 |
|
---|
3716 | TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
|
---|
3717 |
|
---|
3718 | thislocale = OLE2NLS_CheckLocale ( locale );
|
---|
3719 |
|
---|
3720 | if (format == NULL)
|
---|
3721 | { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
|
---|
3722 | { thislocale = GetSystemDefaultLCID();
|
---|
3723 | }
|
---|
3724 | GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
|
---|
3725 | thisformat = format_buf;
|
---|
3726 | }
|
---|
3727 | else
|
---|
3728 | { thisformat = format;
|
---|
3729 | }
|
---|
3730 |
|
---|
3731 | if (xtime == NULL) /* NULL means use the current local time*/
|
---|
3732 | { GetLocalTime(&t);
|
---|
3733 | thistime = &t;
|
---|
3734 | }
|
---|
3735 | else
|
---|
3736 | { thistime = xtime;
|
---|
3737 | /* Check that hour,min and sec is in range */
|
---|
3738 | }
|
---|
3739 | ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
|
---|
3740 | timestr, timelen);
|
---|
3741 | return ret;
|
---|
3742 | }
|
---|
3743 |
|
---|
3744 |
|
---|
3745 | /******************************************************************************
|
---|
3746 | * GetTimeFormatW [KERNEL32.423]
|
---|
3747 | * Makes a Unicode string of the time
|
---|
3748 | */
|
---|
3749 | INT WINAPI
|
---|
3750 | GetTimeFormatW(LCID locale, /* [in] */
|
---|
3751 | DWORD flags, /* [in] */
|
---|
3752 | CONST SYSTEMTIME *xtime, /* [in] */
|
---|
3753 | LPCWSTR format, /* [in] */
|
---|
3754 | LPWSTR timestr, /* [out] */
|
---|
3755 | INT timelen /* [in] */)
|
---|
3756 | { WCHAR format_buf[40];
|
---|
3757 | LPCWSTR thisformat;
|
---|
3758 | SYSTEMTIME t;
|
---|
3759 | LPSYSTEMTIME thistime;
|
---|
3760 | LCID thislocale=0;
|
---|
3761 | DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
|
---|
3762 | INT ret;
|
---|
3763 |
|
---|
3764 | TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
|
---|
3765 | xtime,debugstr_w(format),timestr,timelen);
|
---|
3766 |
|
---|
3767 | thislocale = OLE2NLS_CheckLocale ( locale );
|
---|
3768 |
|
---|
3769 | if (format == NULL)
|
---|
3770 | { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
|
---|
3771 | { thislocale = GetSystemDefaultLCID();
|
---|
3772 | }
|
---|
3773 | GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
|
---|
3774 | thisformat = format_buf;
|
---|
3775 | }
|
---|
3776 | else
|
---|
3777 | { thisformat = format;
|
---|
3778 | }
|
---|
3779 |
|
---|
3780 | if (xtime == NULL) /* NULL means use the current local time*/
|
---|
3781 | { GetLocalTime(&t);
|
---|
3782 | thistime = &t;
|
---|
3783 | }
|
---|
3784 | else
|
---|
3785 | { thistime = xtime;
|
---|
3786 | }
|
---|
3787 |
|
---|
3788 | ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
|
---|
3789 | timestr, timelen);
|
---|
3790 | return ret;
|
---|
3791 | }
|
---|
3792 |
|
---|
3793 | /******************************************************************************
|
---|
3794 | * EnumCalendarInfoA [KERNEL32.196]
|
---|
3795 | */
|
---|
3796 | BOOL WINAPI EnumCalendarInfoA(
|
---|
3797 | CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
|
---|
3798 | ) {
|
---|
3799 | FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);
|
---|
3800 | return FALSE;
|
---|
3801 | }
|
---|
3802 |
|
---|
3803 | #ifdef __WIN32OS2__
|
---|
3804 | /*****************************************************************************
|
---|
3805 | * Name : BOOL WIN32API EnumCalendarInfoW
|
---|
3806 | * Purpose : The EnumCalendarInfoW function enumerates calendar information
|
---|
3807 | * for a specified locale. The CalType parameter specifies the type
|
---|
3808 | * of calendar information to enumerate. The function returns the
|
---|
3809 | * specified calendar information for all applicable calendars for
|
---|
3810 | * the locale, or for a single requested calendar, depending on the
|
---|
3811 | * value of the Calendar parameter.
|
---|
3812 | * The EnumCalendarInfo function enumerates the calendar information
|
---|
3813 | * by calling an application-defined callback function. It passes
|
---|
3814 | * the callback function a pointer to a string buffer containing
|
---|
3815 | * the requested calendar information. This continues until either
|
---|
3816 | * the last applicable calendar is found or the callback function
|
---|
3817 | * returns FALSE.
|
---|
3818 | * Parameters: CALINFO_ENUMPROCW lpCalInfoEnumProc pointer to enumeration
|
---|
3819 | * callback function
|
---|
3820 | * LCID Locale locale whose calendar information is of interest
|
---|
3821 | * CALID Calendar calendar whose information is of interest
|
---|
3822 | * CALTYPE CalType type of calendar information of interest
|
---|
3823 | * Variables :
|
---|
3824 | * Result : If the function succeeds, the return value is nonzero.
|
---|
3825 | * If the function fails, the return value is zero
|
---|
3826 | * Remark :
|
---|
3827 | * Status : UNTESTED STUB
|
---|
3828 | *
|
---|
3829 | * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
|
---|
3830 | *****************************************************************************/
|
---|
3831 |
|
---|
3832 | BOOL WIN32API EnumCalendarInfoW(CALINFO_ENUMPROCW lpCalInfoEnumProc,
|
---|
3833 | LCID Locale,
|
---|
3834 | CALID Calendar,
|
---|
3835 | CALTYPE CalType)
|
---|
3836 | {
|
---|
3837 |
|
---|
3838 | dprintf(("KERNEL32: EnumCalendarInfoW(%08x,%08x,%08x,%08x)not implemented\n",
|
---|
3839 | lpCalInfoEnumProc,
|
---|
3840 | Locale,
|
---|
3841 | Calendar,
|
---|
3842 | CalType
|
---|
3843 | ));
|
---|
3844 |
|
---|
3845 | return (FALSE);
|
---|
3846 | }
|
---|
3847 | #endif
|
---|