source: trunk/src/kernel32/ole2nls.c@ 8049

Last change on this file since 8049 was 8031, checked in by sandervl, 23 years ago

YD: Fall back to english resource if time format not found for default language; updated italian NLS resource

File size: 119.5 KB
Line 
1/* $Id: ole2nls.c,v 1.3 2002-03-04 10:44:58 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
47ODINDEBUGCHANNEL(KERNEL32-OLE2NLS)
48#endif
49
50DEFAULT_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}
57static 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
167static char *GetLocaleSubkeyName( DWORD lctype );
168
169#ifndef __WIN32OS2__
170/***********************************************************************
171 * GetUserDefaultLCID (KERNEL32.@)
172 * GetUserDefaultLCID (OLE2NLS.1)
173 */
174LCID WINAPI GetUserDefaultLCID(void)
175{
176 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT );
177}
178
179/***********************************************************************
180 * GetSystemDefaultLCID (KERNEL32.@)
181 * GetSystemDefaultLCID (OLE2NLS.2)
182 */
183LCID WINAPI GetSystemDefaultLCID(void)
184{
185 return GetUserDefaultLCID();
186}
187#endif //__WIN32OS2__
188
189#define NLS_MAX_LANGUAGES 20
190typedef 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
199static 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 */
286static 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 }
353END:
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 */
362LANGID 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 */
411LANGID WINAPI GetSystemDefaultLangID(void)
412{
413 return GetUserDefaultLangID();
414}
415#endif //__WIN32OS2__
416/******************************************************************************
417 * ConvertDefaultLocale (KERNEL32.@)
418 */
419LCID 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 */
437static 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 */
487INT 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 */
618INT 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 */
645static 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 */
775BOOL 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
829BOOL 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 */
845BOOL 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
854static 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 */
868BOOL 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
880static 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 */
892BOOL 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 */
907DWORD 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 */
918DWORD 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
927static 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
1185static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
1186
1187#define LCM_Diacritic_Start 131
1188
1189static const unsigned char LCM_Diacritic_LUT[] = {
1190123, /* ƒ - 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 */
1268104, /* Ð - 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 */
1300104, /* ð - 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 */
1321static 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 */
1334static 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 */
1345static 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 */
1356static 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 */
1387INT 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 */
1635INT 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 for (i=0; i < srclen; i++)
1919 dststr[i] = (WCHAR) f(srcstr[i]);
1920 return srclen;
1921 }
1922}
1923
1924
1925/***********************************************************************
1926 * OLE2NLS_EstimateMappingLength
1927 *
1928 * Estimates the number of characters required to hold the string
1929 * computed by LCMapStringA.
1930 *
1931 * The size is always over-estimated, with a fixed limit on the
1932 * amount of estimation error.
1933 *
1934 * Note that len == -1 is not permitted.
1935 */
1936static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
1937 LPCSTR str, DWORD len)
1938{
1939 /* Estimate only for small strings to keep the estimation error from
1940 * becoming too large. */
1941 if (len < 128) return len * 8 + 5;
1942 else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
1943}
1944
1945/******************************************************************************
1946 * CompareStringA [KERNEL32.143]
1947 * Compares two strings using locale
1948 *
1949 * RETURNS
1950 *
1951 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
1952 * failure: 0
1953 *
1954 * NOTES
1955 *
1956 * Defaults to a word sort, but uses a string sort if
1957 * SORT_STRINGSORT is set.
1958 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
1959 *
1960 * BUGS
1961 *
1962 * This implementation ignores the locale
1963 *
1964 * FIXME
1965 *
1966 * Quite inefficient.
1967 */
1968UINT WINAPI CompareStringA(
1969 DWORD lcid, /* [in] locale ID */
1970 DWORD fdwStyle, /* [in] comparison-style options */
1971 LPCSTR s1, /* [in] first string */
1972 DWORD l1, /* [in] length of first string */
1973 LPCSTR s2, /* [in] second string */
1974 DWORD l2) /* [in] length of second string */
1975{
1976 int mapstring_flags;
1977 int len1,len2;
1978 int result;
1979 LPSTR sk1,sk2;
1980 TRACE("%s and %s\n",
1981 debugstr_a (s1), debugstr_a (s2));
1982
1983 if ( (s1==NULL) || (s2==NULL) )
1984 {
1985 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
1986 SetLastError(ERROR_INVALID_PARAMETER);
1987 return 0;
1988 }
1989
1990 if(fdwStyle & NORM_IGNORESYMBOLS)
1991 FIXME("IGNORESYMBOLS not supported\n");
1992
1993 if (l1 == -1) l1 = strlen(s1);
1994 if (l2 == -1) l2 = strlen(s2);
1995
1996 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
1997 len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
1998 len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
1999
2000 if ((len1==0)||(len2==0))
2001 return 0; /* something wrong happened */
2002
2003 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
2004 sk2 = sk1 + len1;
2005 if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
2006 || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2007 {
2008 ERR("Bug in LCmapStringA.\n");
2009 result = 0;
2010 }
2011 else
2012 {
2013 /* strcmp doesn't necessarily return -1, 0, or 1 */
2014 result = strcmp(sk1,sk2);
2015 }
2016 HeapFree(GetProcessHeap(),0,sk1);
2017
2018 if (result < 0)
2019 return 1;
2020 if (result == 0)
2021 return 2;
2022
2023 /* must be greater, if we reach this point */
2024 return 3;
2025}
2026
2027/******************************************************************************
2028 * CompareStringW [KERNEL32.144]
2029 * This implementation ignores the locale
2030 * FIXME : Does only string sort. Should
2031 * be reimplemented the same way as CompareStringA.
2032 */
2033UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
2034 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2035{
2036 int len,ret;
2037 if(fdwStyle & NORM_IGNORENONSPACE)
2038 FIXME("IGNORENONSPACE not supprted\n");
2039 if(fdwStyle & NORM_IGNORESYMBOLS)
2040 FIXME("IGNORESYMBOLS not supported\n");
2041
2042 /* Is strcmp defaulting to string sort or to word sort?? */
2043 /* FIXME: Handle NORM_STRINGSORT */
2044 l1 = (l1==-1)?strlenW(s1):l1;
2045 l2 = (l2==-1)?strlenW(s2):l2;
2046 len = l1<l2 ? l1:l2;
2047 ret = (fdwStyle & NORM_IGNORECASE) ? strncmpiW(s1,s2,len) : strncmpW(s1,s2,len);
2048 /* not equal, return 1 or 3 */
2049 if(ret!=0) {
2050 /* need to translate result */
2051 return ((int)ret < 0) ? 1 : 3;
2052 }
2053 /* same len, return 2 */
2054 if(l1==l2) return 2;
2055 /* the longer one is lexically greater */
2056 return (l1<l2)? 1 : 3;
2057}
2058
2059/******************************************************************************
2060 * OLE_GetFormatA [Internal]
2061 *
2062 * FIXME
2063 * If datelen == 0, it should return the reguired string length.
2064 *
2065 This function implements stuff for GetDateFormat() and
2066 GetTimeFormat().
2067
2068 d single-digit (no leading zero) day (of month)
2069 dd two-digit day (of month)
2070 ddd short day-of-week name
2071 dddd long day-of-week name
2072 M single-digit month
2073 MM two-digit month
2074 MMM short month name
2075 MMMM full month name
2076 y two-digit year, no leading 0
2077 yy two-digit year
2078 yyyy four-digit year
2079 gg era string
2080 h hours with no leading zero (12-hour)
2081 hh hours with full two digits
2082 H hours with no leading zero (24-hour)
2083 HH hours with full two digits
2084 m minutes with no leading zero
2085 mm minutes with full two digits
2086 s seconds with no leading zero
2087 ss seconds with full two digits
2088 t time marker (A or P)
2089 tt time marker (AM, PM)
2090 '' used to quote literal characters
2091 '' (within a quoted string) indicates a literal '
2092
2093 These functions REQUIRE valid locale, date, and format.
2094 */
2095static INT OLE_GetFormatA(LCID locale,
2096 DWORD flags,
2097 DWORD tflags,
2098 LPSYSTEMTIME xtime,
2099 LPCSTR _format, /*in*/
2100 LPSTR date, /*out*/
2101 INT datelen)
2102{
2103 INT inpos, outpos;
2104 int count, type, inquote, Overflow;
2105 char buf[40];
2106 char format[40];
2107 char * pos;
2108 int buflen;
2109
2110 const char * _dgfmt[] = { "%d", "%02d" };
2111 const char ** dgfmt = _dgfmt - 1;
2112
2113 /* report, for debugging */
2114 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",
2115 locale, flags, tflags,
2116 xtime->wYear,xtime->wMonth,xtime->wDayOfWeek,xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2117 _format, _format, date, datelen);
2118
2119 if(datelen == 0) {
2120 FIXME("datelen = 0, returning 255\n");
2121 return 255;
2122 }
2123
2124 /* initalize state variables and output buffer */
2125 inpos = outpos = 0;
2126 count = 0; inquote = 0; Overflow = 0;
2127 type = '\0';
2128 date[0] = buf[0] = '\0';
2129
2130 strcpy(format,_format);
2131
2132 /* alter the formatstring, while it works for all languages now in wine
2133 its possible that it fails when the time looks like ss:mm:hh as example*/
2134 if (tflags & (TIME_NOMINUTESORSECONDS))
2135 { if ((pos = strstr ( format, ":mm")))
2136 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2137 }
2138 }
2139 if (tflags & (TIME_NOSECONDS))
2140 { if ((pos = strstr ( format, ":ss")))
2141 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2142 }
2143 }
2144
2145 for (inpos = 0;; inpos++) {
2146 /* 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]); */
2147 if (inquote) {
2148 if (format[inpos] == '\'') {
2149 if (format[inpos+1] == '\'') {
2150 inpos += 1;
2151 date[outpos++] = '\'';
2152 } else {
2153 inquote = 0;
2154 continue; /* we did nothing to the output */
2155 }
2156 } else if (format[inpos] == '\0') {
2157 date[outpos++] = '\0';
2158 if (outpos > datelen) Overflow = 1;
2159 break;
2160 } else {
2161 date[outpos++] = format[inpos];
2162 if (outpos > datelen) {
2163 Overflow = 1;
2164 date[outpos-1] = '\0'; /* this is the last place where
2165 it's safe to write */
2166 break;
2167 }
2168 }
2169 } else if ( (count && (format[inpos] != type))
2170 || count == 4
2171 || (count == 2 && strchr("ghHmst", type)) ) {
2172 if (type == 'h' && (tflags & TIME_FORCE24HOURFORMAT)) type= 'H';
2173 if (type == 'd') {
2174 if (count == 4) {
2175 GetLocaleInfoA(locale,
2176 LOCALE_SDAYNAME1
2177 + (xtime->wDayOfWeek+6)%7,
2178 buf, sizeof(buf));
2179 } else if (count == 3) {
2180 GetLocaleInfoA(locale,
2181 LOCALE_SABBREVDAYNAME1
2182 + (xtime->wDayOfWeek+6)%7,
2183 buf, sizeof(buf));
2184 } else {
2185 sprintf(buf, dgfmt[count], xtime->wDay);
2186 }
2187 } else if (type == 'M') {
2188 if (count == 3) {
2189 GetLocaleInfoA(locale,
2190 LOCALE_SABBREVMONTHNAME1
2191 + xtime->wMonth - 1,
2192 buf, sizeof(buf));
2193 } else if (count == 4) {
2194 GetLocaleInfoA(locale,
2195 LOCALE_SMONTHNAME1
2196 + xtime->wMonth - 1,
2197 buf, sizeof(buf));
2198 } else {
2199 sprintf(buf, dgfmt[count], xtime->wMonth);
2200 }
2201 } else if (type == 'y') {
2202 if (count == 4) {
2203 sprintf(buf, "%d", xtime->wYear);
2204 } else if (count == 3) {
2205 strcpy(buf, "yyy");
2206 WARN("unknown format, c=%c, n=%d\n", type, count);
2207 } else {
2208 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2209 }
2210 } else if (type == 'g') {
2211 if (count == 2) {
2212 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2213 strcpy(buf, "AD");
2214 } else {
2215 strcpy(buf, "g");
2216 WARN("unknown format, c=%c, n=%d\n", type, count);
2217 }
2218 } else if (type == 'h') {
2219 /* gives us hours 1:00 -- 12:00 */
2220 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2221 } else if (type == 'H') {
2222 /* 24-hour time */
2223 sprintf(buf, dgfmt[count], xtime->wHour);
2224 } else if ( type == 'm') {
2225 sprintf(buf, dgfmt[count], xtime->wMinute);
2226 } else if ( type == 's') {
2227 sprintf(buf, dgfmt[count], xtime->wSecond);
2228 } else if (type == 't') {
2229 if ((tflags & TIME_NOTIMEMARKER))
2230 buf[0]='\0';
2231 else if (count == 1) {
2232 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2233 } else if (count == 2) {
2234 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2235 GetLocaleInfoA(locale,
2236 (xtime->wHour<12)
2237 ? LOCALE_S1159 : LOCALE_S2359,
2238 buf, sizeof(buf));
2239 }
2240 };
2241
2242 /* we need to check the next char in the format string
2243 again, no matter what happened */
2244 inpos--;
2245
2246 /* add the contents of buf to the output */
2247 buflen = strlen(buf);
2248 if (outpos + buflen < datelen) {
2249 date[outpos] = '\0'; /* for strcat to hook onto */
2250 strcat(date, buf);
2251 outpos += buflen;
2252 } else {
2253 date[outpos] = '\0';
2254 strncat(date, buf, datelen - outpos);
2255 date[datelen - 1] = '\0';
2256 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2257 WARN("insufficient buffer\n");
2258 return 0;
2259 }
2260
2261 /* reset the variables we used to keep track of this item */
2262 count = 0;
2263 type = '\0';
2264 } else if (format[inpos] == '\0') {
2265 /* we can't check for this at the loop-head, because
2266 that breaks the printing of the last format-item */
2267 date[outpos] = '\0';
2268 break;
2269 } else if (count) {
2270 /* continuing a code for an item */
2271 count +=1;
2272 continue;
2273 } else if (strchr("hHmstyMdg", format[inpos])) {
2274 type = format[inpos];
2275 count = 1;
2276 continue;
2277 } else if (format[inpos] == '\'') {
2278 inquote = 1;
2279 continue;
2280 } else {
2281 date[outpos++] = format[inpos];
2282 }
2283 /* now deal with a possible buffer overflow */
2284 if (outpos >= datelen) {
2285 date[datelen - 1] = '\0';
2286 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2287 return 0;
2288 }
2289 }
2290
2291 if (Overflow) {
2292 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2293 };
2294
2295 /* finish it off with a string terminator */
2296 outpos++;
2297 /* sanity check */
2298 if (outpos > datelen-1) outpos = datelen-1;
2299 date[outpos] = '\0';
2300
2301 TRACE("returns string '%s', len %d\n", date, outpos);
2302 return outpos;
2303}
2304
2305/******************************************************************************
2306 * OLE_GetFormatW [INTERNAL]
2307 */
2308static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
2309 LPSYSTEMTIME xtime,
2310 LPCWSTR format,
2311 LPWSTR output, INT outlen)
2312{
2313 INT inpos, outpos;
2314 int count, type=0, inquote;
2315 int Overflow; /* loop check */
2316 char tmp[16];
2317 WCHAR buf[40];
2318 int buflen=0;
2319 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2320 WCHAR arg2[] = {'%','0','2','d',0};
2321 WCHAR *argarr[3];
2322 int datevars=0, timevars=0;
2323
2324 argarr[0] = arg0;
2325 argarr[1] = arg1;
2326 argarr[2] = arg2;
2327
2328 /* make a debug report */
2329 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2330 "%p with max len %d\n",
2331 locale, flags, tflags,
2332 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2333 debugstr_w(format), format, output, outlen);
2334
2335 if(outlen == 0) {
2336 FIXME("outlen = 0, returning 255\n");
2337 return 255;
2338 }
2339
2340 /* initialize state variables */
2341 inpos = outpos = 0;
2342 count = 0;
2343 inquote = Overflow = 0;
2344 /* this is really just a sanity check */
2345 output[0] = buf[0] = 0;
2346
2347 /* this loop is the core of the function */
2348 for (inpos = 0; /* we have several break points */ ; inpos++) {
2349 if (inquote) {
2350 if (format[inpos] == (WCHAR) '\'') {
2351 if (format[inpos+1] == '\'') {
2352 inpos++;
2353 output[outpos++] = '\'';
2354 } else {
2355 inquote = 0;
2356 continue;
2357 }
2358 } else if (format[inpos] == 0) {
2359 output[outpos++] = 0;
2360 if (outpos > outlen) Overflow = 1;
2361 break; /* normal exit (within a quote) */
2362 } else {
2363 output[outpos++] = format[inpos]; /* copy input */
2364 if (outpos > outlen) {
2365 Overflow = 1;
2366 output[outpos-1] = 0;
2367 break;
2368 }
2369 }
2370 } else if ( (count && (format[inpos] != type))
2371 || ( (count==4 && type =='y') ||
2372 (count==4 && type =='M') ||
2373 (count==4 && type =='d') ||
2374 (count==2 && type =='g') ||
2375 (count==2 && type =='h') ||
2376 (count==2 && type =='H') ||
2377 (count==2 && type =='m') ||
2378 (count==2 && type =='s') ||
2379 (count==2 && type =='t') ) ) {
2380 switch(type)
2381 {
2382 case 'd':
2383 if (count == 4) {
2384 GetLocaleInfoW(locale,
2385 LOCALE_SDAYNAME1 + (xtime->wDayOfWeek +6)%7,
2386 buf, sizeof(buf)/sizeof(WCHAR) );
2387 } else if (count == 3) {
2388 GetLocaleInfoW(locale,
2389 LOCALE_SABBREVDAYNAME1 +
2390 (xtime->wDayOfWeek +6)%7,
2391 buf, sizeof(buf)/sizeof(WCHAR) );
2392 } else {
2393 sprintf( tmp, "%.*d", count, xtime->wDay );
2394 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2395 }
2396 break;
2397
2398 case 'M':
2399 if (count == 4) {
2400 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
2401 xtime->wMonth -1, buf,
2402 sizeof(buf)/sizeof(WCHAR) );
2403 } else if (count == 3) {
2404 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
2405 xtime->wMonth -1, buf,
2406 sizeof(buf)/sizeof(WCHAR) );
2407 } else {
2408 sprintf( tmp, "%.*d", count, xtime->wMonth );
2409 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2410 }
2411 break;
2412 case 'y':
2413 if (count == 4) {
2414 sprintf( tmp, "%d", xtime->wYear );
2415 } else if (count == 3) {
2416 strcpy( tmp, "yyy" );
2417 } else {
2418 sprintf( tmp, "%.*d", count, xtime->wYear % 100 );
2419 }
2420 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2421 break;
2422
2423 case 'g':
2424 if (count == 2) {
2425 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2426 strcpy( tmp, "AD" );
2427 } else {
2428 /* Win API sez we copy it verbatim */
2429 strcpy( tmp, "g" );
2430 }
2431 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2432 break;
2433
2434 case 'h':
2435 /* hours 1:00-12:00 --- is this right? */
2436 sprintf( tmp, "%.*d", count, (xtime->wHour-1)%12 +1);
2437 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2438 break;
2439
2440 case 'H':
2441 sprintf( tmp, "%.*d", count, xtime->wHour );
2442 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2443 break;
2444
2445 case 'm':
2446 sprintf( tmp, "%.*d", count, xtime->wMinute );
2447 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2448 break;
2449
2450 case 's':
2451 sprintf( tmp, "%.*d", count, xtime->wSecond );
2452 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2453 break;
2454
2455 case 't':
2456 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
2457 LOCALE_S1159 : LOCALE_S2359,
2458 buf, sizeof(buf) );
2459 if (count == 1) {
2460 buf[1] = 0;
2461 }
2462 break;
2463 }
2464
2465 /* no matter what happened, we need to check this next
2466 character the next time we loop through */
2467 inpos--;
2468
2469 /* cat buf onto the output */
2470 outlen = strlenW(buf);
2471 if (outpos + buflen < outlen) {
2472 strcpyW( output + outpos, buf );
2473 outpos += buflen;
2474 } else {
2475 lstrcpynW( output + outpos, buf, outlen - outpos );
2476 Overflow = 1;
2477 break; /* Abnormal exit */
2478 }
2479
2480 /* reset the variables we used this time */
2481 count = 0;
2482 type = '\0';
2483 } else if (format[inpos] == 0) {
2484 /* we can't check for this at the beginning, because that
2485 would keep us from printing a format spec that ended the
2486 string */
2487 output[outpos] = 0;
2488 break; /* NORMAL EXIT */
2489 } else if (count) {
2490 /* how we keep track of the middle of a format spec */
2491 count++;
2492 continue;
2493 } else if ( (datevars && (format[inpos]=='d' ||
2494 format[inpos]=='M' ||
2495 format[inpos]=='y' ||
2496 format[inpos]=='g') ) ||
2497 (timevars && (format[inpos]=='H' ||
2498 format[inpos]=='h' ||
2499 format[inpos]=='m' ||
2500 format[inpos]=='s' ||
2501 format[inpos]=='t') ) ) {
2502 type = format[inpos];
2503 count = 1;
2504 continue;
2505 } else if (format[inpos] == '\'') {
2506 inquote = 1;
2507 continue;
2508 } else {
2509 /* unquoted literals */
2510 output[outpos++] = format[inpos];
2511 }
2512 }
2513
2514 if (Overflow) {
2515 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2516 WARN(" buffer overflow\n");
2517 };
2518
2519 /* final string terminator and sanity check */
2520 outpos++;
2521 if (outpos > outlen-1) outpos = outlen-1;
2522 output[outpos] = '0';
2523
2524 TRACE(" returning %s\n", debugstr_w(output));
2525
2526 return (!Overflow) ? outlen : 0;
2527
2528}
2529
2530
2531/******************************************************************************
2532 * GetDateFormatA [KERNEL32.310]
2533 * Makes an ASCII string of the date
2534 *
2535 * This function uses format to format the date, or, if format
2536 * is NULL, uses the default for the locale. format is a string
2537 * of literal fields and characters as follows:
2538 *
2539 * - d single-digit (no leading zero) day (of month)
2540 * - dd two-digit day (of month)
2541 * - ddd short day-of-week name
2542 * - dddd long day-of-week name
2543 * - M single-digit month
2544 * - MM two-digit month
2545 * - MMM short month name
2546 * - MMMM full month name
2547 * - y two-digit year, no leading 0
2548 * - yy two-digit year
2549 * - yyyy four-digit year
2550 * - gg era string
2551 *
2552 */
2553INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
2554 LPSYSTEMTIME xtime,
2555 LPCSTR format, LPSTR date,INT datelen)
2556{
2557
2558 char format_buf[40];
2559 LPCSTR thisformat;
2560 SYSTEMTIME t;
2561 LPSYSTEMTIME thistime;
2562 LCID thislocale;
2563 INT ret;
2564 FILETIME ft;
2565 BOOL res;
2566
2567 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2568 locale,flags,xtime,format,date,datelen);
2569
2570 if (!locale) {
2571 locale = LOCALE_SYSTEM_DEFAULT;
2572 };
2573
2574 if (locale == LOCALE_SYSTEM_DEFAULT) {
2575 thislocale = GetSystemDefaultLCID();
2576 } else if (locale == LOCALE_USER_DEFAULT) {
2577 thislocale = GetUserDefaultLCID();
2578 } else {
2579 thislocale = locale;
2580 };
2581
2582 if (xtime == NULL) {
2583 GetSystemTime(&t);
2584 } else {
2585 /* Silently correct wDayOfWeek by tranforming to FileTime and back again*/
2586 res=SystemTimeToFileTime(xtime,&ft);
2587 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error*/
2588 /*FIXME: SystemTimeToFileTime doesn't yet do that ckeck*/
2589 if(!res)
2590 {
2591 SetLastError(ERROR_INVALID_PARAMETER);
2592 return 0;
2593 }
2594 FileTimeToSystemTime(&ft,&t);
2595
2596 };
2597 thistime = &t;
2598
2599 if (format == NULL) {
2600 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
2601 ? LOCALE_SLONGDATE
2602 : LOCALE_SSHORTDATE),
2603 format_buf, sizeof(format_buf));
2604 thisformat = format_buf;
2605 } else {
2606 thisformat = format;
2607 };
2608
2609
2610 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
2611 date, datelen);
2612
2613
2614 TRACE(
2615 "GetDateFormatA() returning %d, with data=%s\n",
2616 ret, date);
2617 return ret;
2618}
2619
2620/******************************************************************************
2621 * GetDateFormatW [KERNEL32.311]
2622 * Makes a Unicode string of the date
2623 *
2624 * Acts the same as GetDateFormatA(), except that it's Unicode.
2625 * Accepts & returns sizes as counts of Unicode characters.
2626 *
2627 */
2628INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
2629 LPSYSTEMTIME xtime,
2630 LPCWSTR format,
2631 LPWSTR date, INT datelen)
2632{
2633#ifdef __WIN32OS2__
2634 // convert "format" on passing in into ASCII
2635 LPSTR pszAsciiFormat = UnicodeToAsciiString((LPWSTR) format);
2636 LPSTR pszAsciiDate = (char *)alloca(datelen);
2637 int rc;
2638
2639 TRACE("Kernel32-ole2nls: GetDateFormatW(0x%04lx,0x%08lx,%p,%s,%p,%d) not yet complete\n",
2640 locale,flags,xtime,pszAsciiFormat,date,datelen);
2641
2642 // call ASCII variant
2643 rc = GetDateFormatA(locale,
2644 flags,
2645 xtime,
2646 pszAsciiFormat,
2647 pszAsciiDate,
2648 datelen); // is in "characters", not bytes
2649
2650 FreeAsciiString(pszAsciiFormat);
2651
2652 // convert "date" on returning to UNICODE
2653 if (datelen != 0)
2654 {
2655 // in this case 'rc' holds the number of characters to convert
2656 lstrcpynAtoW(date, pszAsciiDate, rc);
2657 }
2658
2659 return rc;
2660
2661#else
2662 unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
2663
2664 FIXME("STUB (should call OLE_GetFormatW)\n");
2665 lstrcpynW(date, datearr, datelen);
2666 return ( datelen < 9) ? datelen : 9;
2667#endif
2668}
2669
2670/**************************************************************************
2671 * EnumDateFormatsA (KERNEL32.198)
2672 */
2673BOOL WINAPI EnumDateFormatsA(
2674 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2675{
2676 LCID Loc = GetUserDefaultLCID();
2677 if(!lpDateFmtEnumProc)
2678 {
2679 SetLastError(ERROR_INVALID_PARAMETER);
2680 return FALSE;
2681 }
2682
2683 switch( Loc )
2684 {
2685
2686 case 0x00000407: /* (Loc,"de_DE") */
2687 {
2688 switch(dwFlags)
2689 {
2690 case DATE_SHORTDATE:
2691 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
2692 if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
2693 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
2694 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
2695 return TRUE;
2696 case DATE_LONGDATE:
2697 if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
2698 if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
2699 if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
2700 return TRUE;
2701 default:
2702 FIXME("Unknown date format (%ld)\n", dwFlags);
2703 SetLastError(ERROR_INVALID_PARAMETER);
2704 return FALSE;
2705 }
2706 }
2707
2708 case 0x0000040c: /* (Loc,"fr_FR") */
2709 {
2710 switch(dwFlags)
2711 {
2712 case DATE_SHORTDATE:
2713 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2714 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
2715 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
2716 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2717 return TRUE;
2718 case DATE_LONGDATE:
2719 if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
2720 if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
2721 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2722 return TRUE;
2723 default:
2724 FIXME("Unknown date format (%ld)\n", dwFlags);
2725 SetLastError(ERROR_INVALID_PARAMETER);
2726 return FALSE;
2727 }
2728 }
2729
2730 case 0x00000c0c: /* (Loc,"fr_CA") */
2731 {
2732 switch(dwFlags)
2733 {
2734 case DATE_SHORTDATE:
2735 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
2736 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
2737 if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
2738 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2739 return TRUE;
2740 case DATE_LONGDATE:
2741 if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
2742 if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
2743 return TRUE;
2744 default:
2745 FIXME("Unknown date format (%ld)\n", dwFlags);
2746 SetLastError(ERROR_INVALID_PARAMETER);
2747 return FALSE;
2748 }
2749 }
2750
2751 case 0x00000809: /* (Loc,"en_UK") */
2752 {
2753 switch(dwFlags)
2754 {
2755 case DATE_SHORTDATE:
2756 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2757 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2758 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
2759 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
2760 return TRUE;
2761 case DATE_LONGDATE:
2762 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
2763 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2764 return TRUE;
2765 default:
2766 FIXME("Unknown date format (%ld)\n", dwFlags);
2767 SetLastError(ERROR_INVALID_PARAMETER);
2768 return FALSE;
2769 }
2770 }
2771
2772 case 0x00000c09: /* (Loc,"en_AU") */
2773 {
2774 switch(dwFlags)
2775 {
2776 case DATE_SHORTDATE:
2777 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
2778 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
2779 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2780 return TRUE;
2781 case DATE_LONGDATE:
2782 if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
2783 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2784 return TRUE;
2785 default:
2786 FIXME("Unknown date format (%ld)\n", dwFlags);
2787 SetLastError(ERROR_INVALID_PARAMETER);
2788 return FALSE;
2789 }
2790 }
2791
2792 case 0x00001009: /* (Loc,"en_CA") */
2793 {
2794 switch(dwFlags)
2795 {
2796 case DATE_SHORTDATE:
2797 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2798 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
2799 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
2800 if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
2801 return TRUE;
2802 case DATE_LONGDATE:
2803 if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
2804 if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
2805 return TRUE;
2806 default:
2807 FIXME("Unknown date format (%ld)\n", dwFlags);
2808 SetLastError(ERROR_INVALID_PARAMETER);
2809 return FALSE;
2810 }
2811 }
2812
2813 case 0x00001409: /* (Loc,"en_NZ") */
2814 {
2815 switch(dwFlags)
2816 {
2817 case DATE_SHORTDATE:
2818 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
2819 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2820 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
2821 return TRUE;
2822 case DATE_LONGDATE:
2823 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2824 if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
2825 return TRUE;
2826 default:
2827 FIXME("Unknown date format (%ld)\n", dwFlags);
2828 SetLastError(ERROR_INVALID_PARAMETER);
2829 return FALSE;
2830 }
2831 }
2832
2833 case 0x00001809: /* (Loc,"en_IE") */
2834 {
2835 switch(dwFlags)
2836 {
2837 case DATE_SHORTDATE:
2838 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2839 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
2840 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
2841 return TRUE;
2842 case DATE_LONGDATE:
2843 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
2844 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2845 return TRUE;
2846 default:
2847 FIXME("Unknown date format (%ld)\n", dwFlags);
2848 SetLastError(ERROR_INVALID_PARAMETER);
2849 return FALSE;
2850 }
2851 }
2852
2853 case 0x00001c09: /* (Loc,"en_ZA") */
2854 {
2855 switch(dwFlags)
2856 {
2857 case DATE_SHORTDATE:
2858 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
2859 return TRUE;
2860 case DATE_LONGDATE:
2861 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
2862 return TRUE;
2863 default:
2864 FIXME("Unknown date format (%ld)\n", dwFlags);
2865 SetLastError(ERROR_INVALID_PARAMETER);
2866 return FALSE;
2867 }
2868 }
2869
2870 case 0x00002009: /* (Loc,"en_JM") */
2871 {
2872 switch(dwFlags)
2873 {
2874 case DATE_SHORTDATE:
2875 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2876 return TRUE;
2877 case DATE_LONGDATE:
2878 if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
2879 if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
2880 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
2881 if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
2882 return TRUE;
2883 default:
2884 FIXME("Unknown date format (%ld)\n", dwFlags);
2885 SetLastError(ERROR_INVALID_PARAMETER);
2886 return FALSE;
2887 }
2888 }
2889
2890 case 0x00002809: /* (Loc,"en_BZ") */
2891 case 0x00002c09: /* (Loc,"en_TT") */
2892 {
2893 switch(dwFlags)
2894 {
2895 case DATE_SHORTDATE:
2896 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2897 return TRUE;
2898 case DATE_LONGDATE:
2899 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
2900 return TRUE;
2901 default:
2902 FIXME("Unknown date format (%ld)\n", dwFlags);
2903 SetLastError(ERROR_INVALID_PARAMETER);
2904 return FALSE;
2905 }
2906 }
2907
2908 default: /* default to US English "en_US" */
2909 {
2910 switch(dwFlags)
2911 {
2912 case DATE_SHORTDATE:
2913 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
2914 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
2915 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
2916 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
2917 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
2918 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
2919 return TRUE;
2920 case DATE_LONGDATE:
2921 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
2922 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
2923 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
2924 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
2925 return TRUE;
2926 default:
2927 FIXME("Unknown date format (%ld)\n", dwFlags);
2928 SetLastError(ERROR_INVALID_PARAMETER);
2929 return FALSE;
2930 }
2931 }
2932 }
2933}
2934
2935/**************************************************************************
2936 * EnumDateFormatsW (KERNEL32.199)
2937 */
2938BOOL WINAPI EnumDateFormatsW(
2939 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2940{
2941 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
2942 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2943 return FALSE;
2944}
2945
2946/**************************************************************************
2947 * EnumTimeFormatsA (KERNEL32.210)
2948 */
2949BOOL WINAPI EnumTimeFormatsA(
2950 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
2951{
2952 LCID Loc = GetUserDefaultLCID();
2953 if(!lpTimeFmtEnumProc)
2954 {
2955 SetLastError(ERROR_INVALID_PARAMETER);
2956 return FALSE;
2957 }
2958 if(dwFlags)
2959 {
2960 FIXME("Unknown time format (%ld)\n", dwFlags);
2961 }
2962
2963 switch( Loc )
2964 {
2965 case 0x00000407: /* (Loc,"de_DE") */
2966 {
2967 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
2968 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
2969 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
2970 if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
2971 if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
2972 return TRUE;
2973 }
2974
2975 case 0x0000040c: /* (Loc,"fr_FR") */
2976 case 0x00000c0c: /* (Loc,"fr_CA") */
2977 {
2978 if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
2979 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
2980 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
2981 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
2982 if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
2983 return TRUE;
2984 }
2985
2986 case 0x00000809: /* (Loc,"en_UK") */
2987 case 0x00000c09: /* (Loc,"en_AU") */
2988 case 0x00001409: /* (Loc,"en_NZ") */
2989 case 0x00001809: /* (Loc,"en_IE") */
2990 {
2991 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
2992 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
2993 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
2994 return TRUE;
2995 }
2996
2997 case 0x00001c09: /* (Loc,"en_ZA") */
2998 case 0x00002809: /* (Loc,"en_BZ") */
2999 case 0x00002c09: /* (Loc,"en_TT") */
3000 {
3001 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3002 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3003 return TRUE;
3004 }
3005
3006 default: /* default to US style "en_US" */
3007 {
3008 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3009 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3010 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3011 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3012 return TRUE;
3013 }
3014 }
3015}
3016
3017/**************************************************************************
3018 * EnumTimeFormatsW (KERNEL32.211)
3019 */
3020BOOL WINAPI EnumTimeFormatsW(
3021 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3022{
3023 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
3024 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3025 return FALSE;
3026}
3027
3028/**************************************************************************
3029 * This function is used just locally !
3030 * Description: Inverts a string.
3031 */
3032static void OLE_InvertString(char* string)
3033{
3034 char sTmpArray[128];
3035 INT counter, i = 0;
3036
3037 for (counter = strlen(string); counter > 0; counter--)
3038 {
3039 memcpy(sTmpArray + i, string + counter-1, 1);
3040 i++;
3041 }
3042 memcpy(sTmpArray + i, "\0", 1);
3043 strcpy(string, sTmpArray);
3044}
3045
3046/***************************************************************************************
3047 * This function is used just locally !
3048 * Description: Test if the given string (psNumber) is valid or not.
3049 * The valid characters are the following:
3050 * - Characters '0' through '9'.
3051 * - One decimal point (dot) if the number is a floating-point value.
3052 * - A minus sign in the first character position if the number is
3053 * a negative value.
3054 * If the function succeeds, psBefore/psAfter will point to the string
3055 * on the right/left of the decimal symbol. pbNegative indicates if the
3056 * number is negative.
3057 */
3058static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
3059{
3060char sNumberSet[] = "0123456789";
3061BOOL bInDecimal = FALSE;
3062
3063 /* Test if we do have a minus sign */
3064 if ( *pInput == '-' )
3065 {
3066 *pbNegative = TRUE;
3067 pInput++; /* Jump to the next character. */
3068 }
3069
3070 while(*pInput != '\0')
3071 {
3072 /* Do we have a valid numeric character */
3073 if ( strchr(sNumberSet, *pInput) != NULL )
3074 {
3075 if (bInDecimal == TRUE)
3076 *psAfter++ = *pInput;
3077 else
3078 *psBefore++ = *pInput;
3079 }
3080 else
3081 {
3082 /* Is this a decimal point (dot) */
3083 if ( *pInput == '.' )
3084 {
3085 /* Is it the first time we find it */
3086 if ((bInDecimal == FALSE))
3087 bInDecimal = TRUE;
3088 else
3089 return -1; /* ERROR: Invalid parameter */
3090 }
3091 else
3092 {
3093 /* It's neither a numeric character, nor a decimal point.
3094 * Thus, return an error.
3095 */
3096 return -1;
3097 }
3098 }
3099 pInput++;
3100 }
3101
3102 /* Add an End of Line character to the output buffers */
3103 *psBefore = '\0';
3104 *psAfter = '\0';
3105
3106 return 0;
3107}
3108
3109/**************************************************************************
3110 * This function is used just locally !
3111 * Description: A number could be formatted using different numbers
3112 * of "digits in group" (example: 4;3;2;0).
3113 * The first parameter of this function is an array
3114 * containing the rule to be used. It's format is the following:
3115 * |NDG|DG1|DG2|...|0|
3116 * where NDG is the number of used "digits in group" and DG1, DG2,
3117 * are the corresponding "digits in group".
3118 * Thus, this function returns the grouping value in the array
3119 * pointed by the second parameter.
3120 */
3121static INT OLE_GetGrouping(char* sRule, INT index)
3122{
3123 char sData[2], sRuleSize[2];
3124 INT nData, nRuleSize;
3125
3126 memcpy(sRuleSize, sRule, 1);
3127 memcpy(sRuleSize+1, "\0", 1);
3128 nRuleSize = atoi(sRuleSize);
3129
3130 if (index > 0 && index < nRuleSize)
3131 {
3132 memcpy(sData, sRule+index, 1);
3133 memcpy(sData+1, "\0", 1);
3134 nData = atoi(sData);
3135 }
3136
3137 else
3138 {
3139 memcpy(sData, sRule+nRuleSize-1, 1);
3140 memcpy(sData+1, "\0", 1);
3141 nData = atoi(sData);
3142 }
3143
3144 return nData;
3145}
3146
3147/**************************************************************************
3148 * GetNumberFormatA (KERNEL32.355)
3149 */
3150INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
3151 LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
3152 LPSTR lpNumberStr, int cchNumber)
3153{
3154 char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
3155 INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
3156 char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
3157 char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
3158 char *pStr = NULL, *pTmpStr = NULL;
3159 LCID systemDefaultLCID;
3160 BOOL bNegative = FALSE;
3161 enum Operations
3162 {
3163 USE_PARAMETER,
3164 USE_LOCALEINFO,
3165 USE_SYSTEMDEFAULT,
3166 RETURN_ERROR
3167 } used_operation;
3168
3169 strncpy(sNumber, lpvalue, 128);
3170 sNumber[127] = '\0';
3171
3172 /* Make sure we have a valid input string, get the number
3173 * of digits before and after the decimal symbol, and check
3174 * if this is a negative number.
3175 */
3176 if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
3177 {
3178 nNumberDecimal = strlen(sDigitsBeforeDecimal);
3179 nDigits = strlen(sDigitsAfterDecimal);
3180 }
3181 else
3182 {
3183 SetLastError(ERROR_INVALID_PARAMETER);
3184 return 0;
3185 }
3186
3187 /* Which source will we use to format the string */
3188 used_operation = RETURN_ERROR;
3189 if (lpFormat != NULL)
3190 {
3191 if (dwflags == 0)
3192 used_operation = USE_PARAMETER;
3193 }
3194 else
3195 {
3196 if (dwflags & LOCALE_NOUSEROVERRIDE)
3197 used_operation = USE_LOCALEINFO;
3198 else
3199 used_operation = USE_SYSTEMDEFAULT;
3200 }
3201
3202 /* Load the fields we need */
3203 switch(used_operation)
3204 {
3205 case USE_LOCALEINFO:
3206 GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3207 GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3208 GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3209 GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3210 GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3211 GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3212 break;
3213 case USE_PARAMETER:
3214 sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
3215 strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
3216 sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
3217 strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
3218 sprintf(sILZero, "%d",lpFormat->LeadingZero);
3219 sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
3220 break;
3221 case USE_SYSTEMDEFAULT:
3222 systemDefaultLCID = GetSystemDefaultLCID();
3223 GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3224 GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3225 GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3226 GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3227 GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3228 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3229 break;
3230 default:
3231 SetLastError(ERROR_INVALID_PARAMETER);
3232 return 0;
3233 }
3234
3235 nNumberDigits = atoi(sNumberDigits);
3236
3237 /* Remove the ";" */
3238 i=0;
3239 j = 1;
3240 for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
3241 {
3242 if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
3243 {
3244 memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
3245 i++;
3246 j++;
3247 }
3248 }
3249 sprintf(sBuffer, "%d", i);
3250 memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3251 memcpy(sRule + j, "\0", 1);
3252
3253 /* First, format the digits before the decimal. */
3254 if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
3255 {
3256 /* Working on an inverted string is easier ! */
3257 OLE_InvertString(sDigitsBeforeDecimal);
3258
3259 nStep = nCounter = i = j = 0;
3260 nRuleIndex = 1;
3261 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3262
3263 /* Here, we will loop until we reach the end of the string.
3264 * An internal counter (j) is used in order to know when to
3265 * insert the "digit group symbol".
3266 */
3267 while (nNumberDecimal > 0)
3268 {
3269 i = nCounter + nStep;
3270 memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
3271 nCounter++;
3272 j++;
3273 if (j >= nGrouping)
3274 {
3275 j = 0;
3276 if (nRuleIndex < sRule[0])
3277 nRuleIndex++;
3278 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3279 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
3280 nStep+= strlen(sDigitGroupSymbol);
3281 }
3282
3283 nNumberDecimal--;
3284 }
3285
3286 memcpy(sDestination + i+1, "\0", 1);
3287 /* Get the string in the right order ! */
3288 OLE_InvertString(sDestination);
3289 }
3290 else
3291 {
3292 nLZ = atoi(sILZero);
3293 if (nLZ != 0)
3294 {
3295 /* Use 0.xxx instead of .xxx */
3296 memcpy(sDestination, "0", 1);
3297 memcpy(sDestination+1, "\0", 1);
3298 }
3299 else
3300 memcpy(sDestination, "\0", 1);
3301
3302 }
3303
3304 /* Second, format the digits after the decimal. */
3305 j = 0;
3306 nCounter = nNumberDigits;
3307 if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
3308 {
3309 i = strlen(sNumber) - strlen(pStr) + 1;
3310 strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
3311 j = strlen(sDigitsAfterDecimal);
3312 if (j < nNumberDigits)
3313 nCounter = nNumberDigits-j;
3314 }
3315 for (i=0;i<nCounter;i++)
3316 memcpy(sDigitsAfterDecimal+i+j, "0", 1);
3317 memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
3318
3319 i = strlen(sDestination);
3320 j = strlen(sDigitsAfterDecimal);
3321 /* Finally, construct the resulting formatted string. */
3322
3323 for (nCounter=0; nCounter<i; nCounter++)
3324 memcpy(sNumber + nCounter, sDestination + nCounter, 1);
3325
3326 memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
3327
3328 for (i=0; i<j; i++)
3329 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
3330 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
3331
3332 /* Is it a negative number */
3333 if (bNegative == TRUE)
3334 {
3335 i = atoi(sNegNumber);
3336 pStr = sDestination;
3337 pTmpStr = sNumber;
3338 switch (i)
3339 {
3340 case 0:
3341 *pStr++ = '(';
3342 while (*sNumber != '\0')
3343 *pStr++ = *pTmpStr++;
3344 *pStr++ = ')';
3345 break;
3346 case 1:
3347 *pStr++ = '-';
3348 while (*pTmpStr != '\0')
3349 *pStr++ = *pTmpStr++;
3350 break;
3351 case 2:
3352 *pStr++ = '-';
3353 *pStr++ = ' ';
3354 while (*pTmpStr != '\0')
3355 *pStr++ = *pTmpStr++;
3356 break;
3357 case 3:
3358 while (*pTmpStr != '\0')
3359 *pStr++ = *pTmpStr++;
3360 *pStr++ = '-';
3361 break;
3362 case 4:
3363 while (*pTmpStr != '\0')
3364 *pStr++ = *pTmpStr++;
3365 *pStr++ = ' ';
3366 *pStr++ = '-';
3367 break;
3368 default:
3369 while (*pTmpStr != '\0')
3370 *pStr++ = *pTmpStr++;
3371 break;
3372 }
3373 }
3374 else
3375 strcpy(sDestination, sNumber);
3376
3377 /* If cchNumber is zero, then returns the number of bytes or characters
3378 * required to hold the formatted number string
3379 */
3380 if (cchNumber==0)
3381 retVal = strlen(sDestination) + 1;
3382 else
3383 {
3384 strncpy (lpNumberStr, sDestination, cchNumber-1);
3385 *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
3386 retVal = strlen(lpNumberStr);
3387 }
3388
3389 return retVal;
3390}
3391
3392/**************************************************************************
3393 * GetNumberFormatW (KERNEL32.@)
3394 */
3395INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
3396 LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
3397 LPWSTR lpNumberStr, int cchNumber)
3398{
3399 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue));
3400
3401 lstrcpynW( lpNumberStr, lpvalue, cchNumber );
3402 return cchNumber? strlenW( lpNumberStr ) : 0;
3403}
3404
3405/**************************************************************************
3406 * GetCurrencyFormatA (KERNEL32.302)
3407 */
3408INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
3409 LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
3410 LPSTR lpCurrencyStr, int cchCurrency)
3411{
3412 UINT nPosOrder, nNegOrder;
3413 INT retVal;
3414 char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
3415 char *pDestination = sDestination;
3416 char sNumberFormated[128];
3417 char *pNumberFormated = sNumberFormated;
3418 LCID systemDefaultLCID;
3419 BOOL bIsPositive = FALSE, bValidFormat = FALSE;
3420 enum Operations
3421 {
3422 USE_PARAMETER,
3423 USE_LOCALEINFO,
3424 USE_SYSTEMDEFAULT,
3425 RETURN_ERROR
3426 } used_operation;
3427
3428 NUMBERFMTA numberFmt;
3429
3430 /* Which source will we use to format the string */
3431 used_operation = RETURN_ERROR;
3432 if (lpFormat != NULL)
3433 {
3434 if (dwflags == 0)
3435 used_operation = USE_PARAMETER;
3436 }
3437 else
3438 {
3439 if (dwflags & LOCALE_NOUSEROVERRIDE)
3440 used_operation = USE_LOCALEINFO;
3441 else
3442 used_operation = USE_SYSTEMDEFAULT;
3443 }
3444
3445 /* Load the fields we need */
3446 switch(used_operation)
3447 {
3448 case USE_LOCALEINFO:
3449 /* Specific to CURRENCYFMTA*/
3450 GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3451 GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3452 GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3453
3454 nPosOrder = atoi(sPosOrder);
3455 nNegOrder = atoi(sNegOrder);
3456 break;
3457 case USE_PARAMETER:
3458 /* Specific to CURRENCYFMTA*/
3459 nNegOrder = lpFormat->NegativeOrder;
3460 nPosOrder = lpFormat->PositiveOrder;
3461 strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
3462 break;
3463 case USE_SYSTEMDEFAULT:
3464 systemDefaultLCID = GetSystemDefaultLCID();
3465 /* Specific to CURRENCYFMTA*/
3466 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3467 GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3468 GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3469
3470 nPosOrder = atoi(sPosOrder);
3471 nNegOrder = atoi(sNegOrder);
3472 break;
3473 default:
3474 SetLastError(ERROR_INVALID_PARAMETER);
3475 return 0;
3476 }
3477
3478 /* Construct a temporary number format structure */
3479 if (lpFormat != NULL)
3480 {
3481 numberFmt.NumDigits = lpFormat->NumDigits;
3482 numberFmt.LeadingZero = lpFormat->LeadingZero;
3483 numberFmt.Grouping = lpFormat->Grouping;
3484 numberFmt.NegativeOrder = 0;
3485 numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
3486 numberFmt.lpThousandSep = lpFormat->lpThousandSep;
3487 bValidFormat = TRUE;
3488 }
3489
3490 /* Make a call to GetNumberFormatA() */
3491 if (*lpvalue == '-')
3492 {
3493 bIsPositive = FALSE;
3494 retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3495 }
3496 else
3497 {
3498 bIsPositive = TRUE;
3499 retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3500 }
3501
3502 if (retVal == 0)
3503 return 0;
3504
3505 /* construct the formatted string */
3506 if (bIsPositive)
3507 {
3508 switch (nPosOrder)
3509 {
3510 case 0: /* Prefix, no separation */
3511 strcpy (pDestination, sCurrencySymbol);
3512 strcat (pDestination, pNumberFormated);
3513 break;
3514 case 1: /* Suffix, no separation */
3515 strcpy (pDestination, pNumberFormated);
3516 strcat (pDestination, sCurrencySymbol);
3517 break;
3518 case 2: /* Prefix, 1 char separation */
3519 strcpy (pDestination, sCurrencySymbol);
3520 strcat (pDestination, " ");
3521 strcat (pDestination, pNumberFormated);
3522 break;
3523 case 3: /* Suffix, 1 char separation */
3524 strcpy (pDestination, pNumberFormated);
3525 strcat (pDestination, " ");
3526 strcat (pDestination, sCurrencySymbol);
3527 break;
3528 default:
3529 SetLastError(ERROR_INVALID_PARAMETER);
3530 return 0;
3531 }
3532 }
3533 else /* negative number */
3534 {
3535 switch (nNegOrder)
3536 {
3537 case 0: /* format: ($1.1) */
3538 strcpy (pDestination, "(");
3539 strcat (pDestination, sCurrencySymbol);
3540 strcat (pDestination, pNumberFormated);
3541 strcat (pDestination, ")");
3542 break;
3543 case 1: /* format: -$1.1 */
3544 strcpy (pDestination, "-");
3545 strcat (pDestination, sCurrencySymbol);
3546 strcat (pDestination, pNumberFormated);
3547 break;
3548 case 2: /* format: $-1.1 */
3549 strcpy (pDestination, sCurrencySymbol);
3550 strcat (pDestination, "-");
3551 strcat (pDestination, pNumberFormated);
3552 break;
3553 case 3: /* format: $1.1- */
3554 strcpy (pDestination, sCurrencySymbol);
3555 strcat (pDestination, pNumberFormated);
3556 strcat (pDestination, "-");
3557 break;
3558 case 4: /* format: (1.1$) */
3559 strcpy (pDestination, "(");
3560 strcat (pDestination, pNumberFormated);
3561 strcat (pDestination, sCurrencySymbol);
3562 strcat (pDestination, ")");
3563 break;
3564 case 5: /* format: -1.1$ */
3565 strcpy (pDestination, "-");
3566 strcat (pDestination, pNumberFormated);
3567 strcat (pDestination, sCurrencySymbol);
3568 break;
3569 case 6: /* format: 1.1-$ */
3570 strcpy (pDestination, pNumberFormated);
3571 strcat (pDestination, "-");
3572 strcat (pDestination, sCurrencySymbol);
3573 break;
3574 case 7: /* format: 1.1$- */
3575 strcpy (pDestination, pNumberFormated);
3576 strcat (pDestination, sCurrencySymbol);
3577 strcat (pDestination, "-");
3578 break;
3579 case 8: /* format: -1.1 $ */
3580 strcpy (pDestination, "-");
3581 strcat (pDestination, pNumberFormated);
3582 strcat (pDestination, " ");
3583 strcat (pDestination, sCurrencySymbol);
3584 break;
3585 case 9: /* format: -$ 1.1 */
3586 strcpy (pDestination, "-");
3587 strcat (pDestination, sCurrencySymbol);
3588 strcat (pDestination, " ");
3589 strcat (pDestination, pNumberFormated);
3590 break;
3591 case 10: /* format: 1.1 $- */
3592 strcpy (pDestination, pNumberFormated);
3593 strcat (pDestination, " ");
3594 strcat (pDestination, sCurrencySymbol);
3595 strcat (pDestination, "-");
3596 break;
3597 case 11: /* format: $ 1.1- */
3598 strcpy (pDestination, sCurrencySymbol);
3599 strcat (pDestination, " ");
3600 strcat (pDestination, pNumberFormated);
3601 strcat (pDestination, "-");
3602 break;
3603 case 12: /* format: $ -1.1 */
3604 strcpy (pDestination, sCurrencySymbol);
3605 strcat (pDestination, " ");
3606 strcat (pDestination, "-");
3607 strcat (pDestination, pNumberFormated);
3608 break;
3609 case 13: /* format: 1.1- $ */
3610 strcpy (pDestination, pNumberFormated);
3611 strcat (pDestination, "-");
3612 strcat (pDestination, " ");
3613 strcat (pDestination, sCurrencySymbol);
3614 break;
3615 case 14: /* format: ($ 1.1) */
3616 strcpy (pDestination, "(");
3617 strcat (pDestination, sCurrencySymbol);
3618 strcat (pDestination, " ");
3619 strcat (pDestination, pNumberFormated);
3620 strcat (pDestination, ")");
3621 break;
3622 case 15: /* format: (1.1 $) */
3623 strcpy (pDestination, "(");
3624 strcat (pDestination, pNumberFormated);
3625 strcat (pDestination, " ");
3626 strcat (pDestination, sCurrencySymbol);
3627 strcat (pDestination, ")");
3628 break;
3629 default:
3630 SetLastError(ERROR_INVALID_PARAMETER);
3631 return 0;
3632 }
3633 }
3634
3635 if (cchCurrency == 0)
3636 return strlen(pDestination) + 1;
3637
3638 else
3639 {
3640 strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
3641 *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
3642 return strlen(lpCurrencyStr);
3643 }
3644}
3645
3646/**************************************************************************
3647 * GetCurrencyFormatW (KERNEL32.303)
3648 */
3649INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
3650 LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
3651 LPWSTR lpCurrencyStr, int cchCurrency)
3652{
3653 FIXME("This API function is NOT implemented !\n");
3654 return 0;
3655}
3656
3657/******************************************************************************
3658 * OLE2NLS_CheckLocale [intern]
3659 */
3660static LCID OLE2NLS_CheckLocale (LCID locale)
3661{
3662 if (!locale)
3663 { locale = LOCALE_SYSTEM_DEFAULT;
3664 }
3665
3666 if (locale == LOCALE_SYSTEM_DEFAULT)
3667 { return GetSystemDefaultLCID();
3668 }
3669 else if (locale == LOCALE_USER_DEFAULT)
3670 { return GetUserDefaultLCID();
3671 }
3672 else
3673 { return locale;
3674 }
3675}
3676/******************************************************************************
3677 * GetTimeFormatA [KERNEL32.422]
3678 * Makes an ASCII string of the time
3679 *
3680 * Formats date according to format, or locale default if format is
3681 * NULL. The format consists of literal characters and fields as follows:
3682 *
3683 * h hours with no leading zero (12-hour)
3684 * hh hours with full two digits
3685 * H hours with no leading zero (24-hour)
3686 * HH hours with full two digits
3687 * m minutes with no leading zero
3688 * mm minutes with full two digits
3689 * s seconds with no leading zero
3690 * ss seconds with full two digits
3691 * t time marker (A or P)
3692 * tt time marker (AM, PM)
3693 *
3694 */
3695INT WINAPI
3696GetTimeFormatA(LCID locale, /* [in] */
3697 DWORD flags, /* [in] */
3698 LPSYSTEMTIME xtime, /* [in] */
3699 LPCSTR format, /* [in] */
3700 LPSTR timestr, /* [out] */
3701 INT timelen /* [in] */)
3702{ char format_buf[40];
3703 LPCSTR thisformat;
3704 SYSTEMTIME t;
3705 LPSYSTEMTIME thistime;
3706 LCID thislocale=0;
3707 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
3708 INT ret;
3709
3710 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
3711
3712 thislocale = OLE2NLS_CheckLocale ( locale );
3713
3714 if (format == NULL)
3715 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
3716 { thislocale = GetSystemDefaultLCID();
3717 }
3718 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
3719 thisformat = format_buf;
3720 }
3721 else
3722 { thisformat = format;
3723 }
3724
3725 if (xtime == NULL) /* NULL means use the current local time*/
3726 { GetLocalTime(&t);
3727 thistime = &t;
3728 }
3729 else
3730 { thistime = xtime;
3731 /* Check that hour,min and sec is in range */
3732 }
3733 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
3734 timestr, timelen);
3735 return ret;
3736}
3737
3738
3739/******************************************************************************
3740 * GetTimeFormatW [KERNEL32.423]
3741 * Makes a Unicode string of the time
3742 */
3743INT WINAPI
3744GetTimeFormatW(LCID locale, /* [in] */
3745 DWORD flags, /* [in] */
3746 LPSYSTEMTIME xtime, /* [in] */
3747 LPCWSTR format, /* [in] */
3748 LPWSTR timestr, /* [out] */
3749 INT timelen /* [in] */)
3750{ WCHAR format_buf[40];
3751 LPCWSTR thisformat;
3752 SYSTEMTIME t;
3753 LPSYSTEMTIME thistime;
3754 LCID thislocale=0;
3755 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
3756 INT ret;
3757
3758 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
3759 xtime,debugstr_w(format),timestr,timelen);
3760
3761 thislocale = OLE2NLS_CheckLocale ( locale );
3762
3763 if (format == NULL)
3764 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
3765 { thislocale = GetSystemDefaultLCID();
3766 }
3767 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
3768 thisformat = format_buf;
3769 }
3770 else
3771 { thisformat = format;
3772 }
3773
3774 if (xtime == NULL) /* NULL means use the current local time*/
3775 { GetLocalTime(&t);
3776 thistime = &t;
3777 }
3778 else
3779 { thistime = xtime;
3780 }
3781
3782 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
3783 timestr, timelen);
3784 return ret;
3785}
3786
3787/******************************************************************************
3788 * EnumCalendarInfoA [KERNEL32.196]
3789 */
3790BOOL WINAPI EnumCalendarInfoA(
3791 CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
3792) {
3793 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);
3794 return FALSE;
3795}
3796
3797#ifdef __WIN32OS2__
3798/*****************************************************************************
3799 * Name : BOOL WIN32API EnumCalendarInfoW
3800 * Purpose : The EnumCalendarInfoW function enumerates calendar information
3801 * for a specified locale. The CalType parameter specifies the type
3802 * of calendar information to enumerate. The function returns the
3803 * specified calendar information for all applicable calendars for
3804 * the locale, or for a single requested calendar, depending on the
3805 * value of the Calendar parameter.
3806 * The EnumCalendarInfo function enumerates the calendar information
3807 * by calling an application-defined callback function. It passes
3808 * the callback function a pointer to a string buffer containing
3809 * the requested calendar information. This continues until either
3810 * the last applicable calendar is found or the callback function
3811 * returns FALSE.
3812 * Parameters: CALINFO_ENUMPROCW lpCalInfoEnumProc pointer to enumeration
3813 * callback function
3814 * LCID Locale locale whose calendar information is of interest
3815 * CALID Calendar calendar whose information is of interest
3816 * CALTYPE CalType type of calendar information of interest
3817 * Variables :
3818 * Result : If the function succeeds, the return value is nonzero.
3819 * If the function fails, the return value is zero
3820 * Remark :
3821 * Status : UNTESTED STUB
3822 *
3823 * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
3824 *****************************************************************************/
3825
3826BOOL WIN32API EnumCalendarInfoW(CALINFO_ENUMPROCW lpCalInfoEnumProc,
3827 LCID Locale,
3828 CALID Calendar,
3829 CALTYPE CalType)
3830{
3831
3832 dprintf(("KERNEL32: EnumCalendarInfoW(%08x,%08x,%08x,%08x)not implemented\n",
3833 lpCalInfoEnumProc,
3834 Locale,
3835 Calendar,
3836 CalType
3837 ));
3838
3839 return (FALSE);
3840}
3841#endif
Note: See TracBrowser for help on using the repository browser.