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

Last change on this file since 21388 was 21355, checked in by rlwalsh, 16 years ago

eliminate VACPP warning & info msgs - see Ticket #1

File size: 120.2 KB
Line 
1/* $Id: ole2nls.c,v 1.6 2003-04-02 12:58:30 sandervl Exp $
2 *
3 * National Language Support library
4 *
5 * Copyright 1995 Martin von Loewis
6 * Copyright 1998 David Lee Lambert
7 * Copyright 2000 Julio César Gázquez
8 */
9
10#ifdef __WIN32OS2__
11#include <odin.h>
12#include <odinwrap.h>
13
14#include <string.h>
15#include <stdio.h>
16#include <heapstring.h>
17#include <ctype.h>
18#include <wcstr.h>
19#endif
20
21#include <string.h>
22#include <stdio.h>
23#include <ctype.h>
24#include <stdlib.h>
25#include <locale.h>
26
27#include "windef.h"
28#include "winbase.h"
29#include "wingdi.h"
30#include "winuser.h"
31#include "wine/unicode.h"
32#include "heap.h"
33#include "options.h"
34#include "winver.h"
35#include "winnls.h"
36#include "winreg.h"
37#include "winerror.h"
38#include "debugtools.h"
39
40#ifdef __WIN32OS2__
41#include <wctype.h>
42#include <unicode.h>
43
44#define DBG_LOCALLOG DBG_kernel32
45#include "dbglocal.h"
46
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)) != NULL)
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 (LPSTR)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 * identityW [Internal]
1363 */
1364static WCHAR identityW(WCHAR c)
1365{
1366 return c;
1367}
1368
1369/*************************************************************************
1370 * LCMapStringA [KERNEL32.492]
1371 *
1372 * Convert a string, or generate a sort key from it.
1373 *
1374 * If (mapflags & LCMAP_SORTKEY), the function will generate
1375 * a sort key for the source string. Else, it will convert it
1376 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1377 *
1378 * RETURNS
1379 * Error : 0.
1380 * Success : length of the result string.
1381 *
1382 * NOTES
1383 * If called with scrlen = -1, the function will compute the length
1384 * of the 0-terminated string strsrc by itself.
1385 *
1386 * If called with dstlen = 0, returns the buffer length that
1387 * would be required.
1388 *
1389 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1390 * as if they are equal.
1391 * In the only code page implemented so far, there may not be
1392 * wide characters in strings passed to LCMapStringA,
1393 * so there is nothing to be done for this flag.
1394 */
1395INT WINAPI LCMapStringA(
1396 LCID lcid, /* [in] locale identifier created with MAKELCID;
1397 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1398 predefined values. */
1399 DWORD mapflags, /* [in] flags */
1400 LPCSTR srcstr, /* [in] source buffer */
1401 INT srclen, /* [in] source length */
1402 LPSTR dststr, /* [out] destination buffer */
1403 INT dstlen) /* [in] destination buffer length */
1404{
1405 int i;
1406
1407 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1408 lcid,mapflags,srcstr,srclen,dststr,dstlen);
1409
1410 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1411 {
1412 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
1413 SetLastError(ERROR_INVALID_PARAMETER);
1414 return 0;
1415 }
1416 if (srclen == -1)
1417 srclen = strlen(srcstr) + 1 ; /* (include final '\0') */
1418
1419#define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1420 LCMAP_LOWERCASE | \
1421 LCMAP_SORTKEY | \
1422 NORM_IGNORECASE | \
1423 NORM_IGNORENONSPACE | \
1424 SORT_STRINGSORT | \
1425 NORM_IGNOREWIDTH | \
1426 NORM_IGNOREKANATYPE)
1427 /* FIXME: as long as we don't support Katakana nor Hiragana
1428 * characters, we can support NORM_IGNOREKANATYPE
1429 */
1430#ifdef DEBUG
1431 if (mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS)
1432 {
1433 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1434 "unimplemented flags: 0x%08lx\n",
1435 lcid,
1436 mapflags,
1437 srcstr,
1438 srclen,
1439 dststr,
1440 dstlen,
1441 mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS
1442 );
1443 }
1444#endif
1445
1446 if ( !(mapflags & LCMAP_SORTKEY) )
1447 {
1448 int i,j;
1449 int (* f)(int) = identity;
1450
1451 int flag_ignorenonspace = mapflags & NORM_IGNORENONSPACE;
1452 int flag_ignoresymbols = mapflags & NORM_IGNORESYMBOLS;
1453
1454 if (flag_ignorenonspace || flag_ignoresymbols)
1455 {
1456 /* For some values of mapflags, the length of the resulting
1457 string is not known at this point. Windows does map the string
1458 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1459 these cases. */
1460 if (dstlen==0)
1461 {
1462 /* Compute required length */
1463 for (i=j=0; i < srclen; i++)
1464 {
1465 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1466 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1467 j++;
1468 }
1469 return j;
1470 }
1471 }
1472 else
1473 {
1474 if (dstlen==0)
1475 return srclen;
1476 if (dstlen<srclen)
1477 {
1478 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1479 return 0;
1480 }
1481 }
1482 if (mapflags & LCMAP_UPPERCASE)
1483 f = toupper;
1484 else if (mapflags & LCMAP_LOWERCASE)
1485 f = tolower;
1486 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1487 for (i=j=0; (i<srclen) && (j<dstlen) ; i++)
1488 {
1489 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1490 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1491 {
1492 dststr[j] = (CHAR) f(srcstr[i]);
1493 j++;
1494 }
1495 }
1496 return j;
1497 }
1498
1499 /* FIXME: This function completely ignores the "lcid" parameter. */
1500 /* else ... (mapflags & LCMAP_SORTKEY) */
1501 {
1502 int unicode_len=0;
1503 int case_len=0;
1504 int diacritic_len=0;
1505 int delayed_punctuation_len=0;
1506 char *case_component;
1507 char *diacritic_component;
1508 char *delayed_punctuation_component;
1509 int room,count;
1510 int flag_stringsort = mapflags & SORT_STRINGSORT;
1511
1512 /* compute how much room we will need */
1513 for (i=0;i<srclen;i++)
1514 {
1515 int ofs;
1516 unsigned char source_char = srcstr[i];
1517 if (source_char!='\0')
1518 {
1519 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
1520 {
1521 unicode_len++;
1522 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
1523 unicode_len++; /* double letter */
1524 }
1525 else
1526 {
1527 delayed_punctuation_len++;
1528 }
1529 }
1530
1531 if (isupper(source_char))
1532 case_len=unicode_len;
1533
1534 ofs = source_char - LCM_Diacritic_Start;
1535 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
1536 diacritic_len=unicode_len;
1537 }
1538
1539 if (mapflags & NORM_IGNORECASE)
1540 case_len=0;
1541 if (mapflags & NORM_IGNORENONSPACE)
1542 diacritic_len=0;
1543
1544 room = 2 * unicode_len /* "unicode" component */
1545 + diacritic_len /* "diacritic" component */
1546 + case_len /* "case" component */
1547 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
1548 + 4 /* four '\1' separators */
1549 + 1 ; /* terminal '\0' */
1550 if (dstlen==0)
1551 return room;
1552 else if (dstlen<room)
1553 {
1554 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1555 return 0;
1556 }
1557#if 0
1558 /*FIXME the Pointercheck should not be nessesary */
1559 if (IsBadWritePtr (dststr,room))
1560 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
1561 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1562 return 0;
1563 }
1564#endif
1565 /* locate each component, write separators */
1566 diacritic_component = dststr + 2*unicode_len ;
1567 *diacritic_component++ = '\1';
1568 case_component = diacritic_component + diacritic_len ;
1569 *case_component++ = '\1';
1570 delayed_punctuation_component = case_component + case_len ;
1571 *delayed_punctuation_component++ = '\1';
1572 *delayed_punctuation_component++ = '\1';
1573
1574 /* read source string char by char, write
1575 corresponding weight in each component. */
1576 for (i=0,count=0;i<srclen;i++)
1577 {
1578 unsigned char source_char=srcstr[i];
1579 if (source_char!='\0')
1580 {
1581 int type,longcode;
1582 type = LCM_Unicode_LUT[-2+2*source_char];
1583 longcode = type >> 4;
1584 type &= 15;
1585 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
1586 {
1587 WORD encrypted_location = (1<<15) + 7 + 4*count;
1588 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
1589 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
1590 /* big-endian is used here because it lets string comparison be
1591 compatible with numerical comparison */
1592
1593 *delayed_punctuation_component++ = type;
1594 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
1595 /* assumption : a punctuation character is never a
1596 double or accented letter */
1597 }
1598 else
1599 {
1600 dststr[2*count] = type;
1601 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
1602 if (longcode)
1603 {
1604 if (count<case_len)
1605 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1606 if (count<diacritic_len)
1607 diacritic_component[count] = 2; /* assumption: a double letter
1608 is never accented */
1609 count++;
1610
1611 dststr[2*count] = type;
1612 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
1613 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1614 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1615 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1616 }
1617
1618 if (count<case_len)
1619 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1620 if (count<diacritic_len)
1621 {
1622 int ofs = source_char - LCM_Diacritic_Start;
1623 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
1624 }
1625 count++;
1626 }
1627 }
1628 }
1629 dststr[room-1] = '\0';
1630 return room;
1631 }
1632}
1633
1634/*************************************************************************
1635 * LCMapStringW [KERNEL32.493]
1636 *
1637 * Convert a string, or generate a sort key from it.
1638 *
1639 * NOTE
1640 *
1641 * See LCMapStringA for documentation
1642 */
1643INT WINAPI LCMapStringW(
1644 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT srclen,LPWSTR dststr,
1645 INT dstlen)
1646{
1647 int i;
1648
1649 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
1650 lcid, mapflags, srcstr, srclen, dststr, dstlen);
1651
1652 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1653 {
1654 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
1655 SetLastError(ERROR_INVALID_PARAMETER);
1656 return 0;
1657 }
1658 if (srclen==-1)
1659 srclen = strlenW(srcstr)+1;
1660
1661 /* FIXME: Both this function and it's companion LCMapStringA()
1662 * completely ignore the "lcid" parameter. In place of the "lcid"
1663 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
1664 * environment variable prior to invoking this function. */
1665 if (mapflags & LCMAP_SORTKEY)
1666 {
1667 /* Possible values of LC_COLLATE. */
1668 char *lc_collate_default = 0; /* value prior to this function */
1669 char *lc_collate_env = 0; /* value retrieved from the environment */
1670
1671 /* General purpose index into strings of any type. */
1672 int str_idx = 0;
1673
1674 /* Lengths of various strings where the length is measured in
1675 * wide characters for wide character strings and in bytes for
1676 * native strings. The lengths include the NULL terminator. */
1677 size_t returned_len = 0;
1678 size_t src_native_len = 0;
1679 size_t dst_native_len = 0;
1680 size_t dststr_libc_len = 0;
1681
1682 /* Native (character set determined by locale) versions of the
1683 * strings source and destination strings. */
1684 LPSTR src_native = 0;
1685 LPSTR dst_native = 0;
1686
1687 /* Version of the source and destination strings using the
1688 * "wchar_t" Unicode data type needed by various libc functions. */
1689 wchar_t *srcstr_libc = 0;
1690 wchar_t *dststr_libc = 0;
1691
1692 if(!(srcstr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
1693 srclen * sizeof(wchar_t))))
1694 {
1695 ERR("Unable to allocate %d bytes for srcstr_libc\n",
1696 srclen * sizeof(wchar_t));
1697 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1698 return 0;
1699 }
1700
1701 /* Convert source string to a libc Unicode string. */
1702 for(str_idx = 0; str_idx < srclen; str_idx++)
1703 {
1704 srcstr_libc[str_idx] = srcstr[str_idx];
1705 }
1706
1707 /* src_native should contain at most 3 bytes for each
1708 * multibyte characters in the original srcstr string. */
1709 src_native_len = 3 * srclen;
1710 if(!(src_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0,
1711 src_native_len)))
1712 {
1713 ERR("Unable to allocate %d bytes for src_native\n", src_native_len);
1714 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1715 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1716 return 0;
1717 }
1718
1719 /* FIXME: Prior to to setting the LC_COLLATE locale category the
1720 * current value is backed up so it can be restored after the
1721 * last LC_COLLATE sensitive function returns.
1722 *
1723 * Even though the locale is adjusted for a minimum amount of
1724 * time a race condition exists where other threads may be
1725 * affected if they invoke LC_COLLATE sensitive functions. One
1726 * possible solution is to wrap all LC_COLLATE sensitive Wine
1727 * functions, like LCMapStringW(), in a mutex.
1728 *
1729 * Another enhancement to the following would be to set the
1730 * LC_COLLATE locale category as a function of the "lcid"
1731 * parameter instead of the "LC_COLLATE" environment variable. */
1732 if(!(lc_collate_default = setlocale(LC_COLLATE, NULL)))
1733 {
1734 ERR("Unable to query the LC_COLLATE catagory\n");
1735 SetLastError(ERROR_INVALID_PARAMETER);
1736 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1737 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1738 return 0;
1739 }
1740
1741 if(!(lc_collate_env = setlocale(LC_COLLATE, "")))
1742 {
1743 ERR("Unable to inherit the LC_COLLATE locale category from the "
1744 "environment. The \"LC_COLLATE\" environment variable is "
1745 "\"%s\".\n", getenv("LC_COLLATE") ?
1746 getenv("LC_COLLATE") : "<unset>");
1747 SetLastError(ERROR_INVALID_PARAMETER);
1748 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1749 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1750 return 0;
1751 }
1752
1753 TRACE("lc_collate_default = %s\n", lc_collate_default);
1754 TRACE("lc_collate_env = %s\n", lc_collate_env);
1755
1756 /* Convert the libc Unicode string to a native multibyte character
1757 * string. */
1758 returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1;
1759 if(returned_len == 0)
1760 {
1761 LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(),
1762 0, srcstr);
1763 ERR("wcstombs failed. The string specified (%s) may contains an "
1764 "invalid character.\n", srcstr_ascii);
1765 SetLastError(ERROR_INVALID_PARAMETER);
1766 if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii);
1767 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1768 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1769 setlocale(LC_COLLATE, lc_collate_default);
1770 return 0;
1771 }
1772 else if(returned_len > src_native_len)
1773 {
1774 src_native[src_native_len - 1] = 0;
1775 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
1776 "than expected (%d bytes).\n", src_native, returned_len,
1777 dst_native_len);
1778
1779 /* Since this is an internal error I'm not sure what the correct
1780 * error code is. */
1781 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1782
1783 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1784 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1785 setlocale(LC_COLLATE, lc_collate_default);
1786 return 0;
1787 }
1788 src_native_len = returned_len;
1789
1790 TRACE("src_native = %s src_native_len = %d\n",
1791 src_native, src_native_len);
1792
1793 /* dst_native seems to contain at most 4 bytes for each byte in
1794 * the original src_native string. Change if need be since this
1795 * isn't documented by the strxfrm() man page. */
1796 dst_native_len = 4 * src_native_len;
1797 if(!(dst_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0, dst_native_len)))
1798 {
1799 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len);
1800 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1801 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1802 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1803 setlocale(LC_COLLATE, lc_collate_default);
1804 return 0;
1805 }
1806
1807 /* The actual translation is done by the following call to
1808 * strxfrm(). The surrounding code could have been simplified
1809 * by calling wcsxfrm() instead except that wcsxfrm() is not
1810 * available on older Linux systems (RedHat 4.1 with
1811 * libc-5.3.12-17).
1812 *
1813 * Also, it is possible that the translation could be done by
1814 * various tables as it is done in LCMapStringA(). However, I'm
1815 * not sure what those tables are. */
1816 returned_len = strxfrm(dst_native, src_native, dst_native_len) + 1;
1817
1818 if(returned_len > dst_native_len)
1819 {
1820 dst_native[dst_native_len - 1] = 0;
1821 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
1822 "than expected (%d bytes).\n", dst_native, returned_len,
1823 dst_native_len);
1824
1825 /* Since this is an internal error I'm not sure what the correct
1826 * error code is. */
1827 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1828
1829 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1830 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1831 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
1832 setlocale(LC_COLLATE, lc_collate_default);
1833 return 0;
1834 }
1835 dst_native_len = returned_len;
1836
1837 TRACE("dst_native = %s dst_native_len = %d\n",
1838 dst_native, dst_native_len);
1839
1840 dststr_libc_len = dst_native_len;
1841 if(!(dststr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
1842 dststr_libc_len * sizeof(wchar_t))))
1843 {
1844 ERR("Unable to allocate %d bytes for dststr_libc\n",
1845 dststr_libc_len * sizeof(wchar_t));
1846 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1847 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1848 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1849 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
1850 setlocale(LC_COLLATE, lc_collate_default);
1851 return 0;
1852 }
1853
1854 /* Convert the native multibyte string to a libc Unicode string. */
1855 returned_len = mbstowcs(dststr_libc, dst_native, dst_native_len) + 1;
1856
1857 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
1858 * function has returned. */
1859 setlocale(LC_COLLATE, lc_collate_default);
1860
1861 if(returned_len == 0)
1862 {
1863 ERR("mbstowcs failed. The native version of the translated string "
1864 "(%s) may contain an invalid character.\n", dst_native);
1865 SetLastError(ERROR_INVALID_PARAMETER);
1866 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1867 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1868 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
1869 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
1870 return 0;
1871 }
1872 if(dstlen)
1873 {
1874 if(returned_len > dstlen)
1875 {
1876 ERR("mbstowcs returned a string that was longer (%d chars) "
1877 "than the buffer provided (%d chars).\n", returned_len,
1878 dstlen);
1879 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1880 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1881 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1882 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
1883 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
1884 return 0;
1885 }
1886 dstlen = returned_len;
1887
1888 /* Convert a libc Unicode string to the destination string. */
1889 for(str_idx = 0; str_idx < dstlen; str_idx++)
1890 {
1891 dststr[str_idx] = dststr_libc[str_idx];
1892 }
1893 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
1894 *(((int *)dststr) + 0),
1895 *(((int *)dststr) + 1),
1896 *(((int *)dststr) + 2),
1897 *(((int *)dststr) + 3));
1898 }
1899 else
1900 {
1901 dstlen = returned_len;
1902 }
1903 TRACE("dstlen (return) = %d\n", dstlen);
1904 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1905 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1906 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
1907 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
1908 return dstlen;
1909 }
1910 else
1911 {
1912#ifdef __WIN32OS2__
1913 WCHAR (*f)(WCHAR)=identityW;
1914#else
1915 int (*f)(int)=identity;
1916#endif
1917
1918 if (dstlen==0)
1919 return srclen;
1920 if (dstlen<srclen)
1921 {
1922 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1923 return 0;
1924 }
1925
1926#ifdef __WIN32OS2__
1927 /* For WCHAR we better use the WCHAR toupper/lower.
1928 * (VAC308 toupper/tolower doesn't do range checks according to standards
1929 * which may cause illegal memory reads access when misused like it were here.
1930 */
1931 if (mapflags & LCMAP_UPPERCASE)
1932 f = toupperW;
1933 else if (mapflags & LCMAP_LOWERCASE)
1934 f = tolowerW;
1935#else
1936 if (mapflags & LCMAP_UPPERCASE)
1937 f = toupper;
1938 else if (mapflags & LCMAP_LOWERCASE)
1939 f = tolower;
1940#endif
1941 if (f)
1942 {
1943 for (i=0; i < srclen; i++)
1944 dststr[i] = (WCHAR) f(srcstr[i]);
1945 }
1946 else
1947 memcpy(dststr, srcstr, sizeof(WCHAR) * srclen);
1948
1949 return srclen;
1950 }
1951}
1952
1953
1954/***********************************************************************
1955 * OLE2NLS_EstimateMappingLength
1956 *
1957 * Estimates the number of characters required to hold the string
1958 * computed by LCMapStringA.
1959 *
1960 * The size is always over-estimated, with a fixed limit on the
1961 * amount of estimation error.
1962 *
1963 * Note that len == -1 is not permitted.
1964 */
1965static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
1966 LPCSTR str, DWORD len)
1967{
1968 /* Estimate only for small strings to keep the estimation error from
1969 * becoming too large. */
1970 if (len < 128) return len * 8 + 5;
1971 else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
1972}
1973
1974/******************************************************************************
1975 * CompareStringA [KERNEL32.143]
1976 * Compares two strings using locale
1977 *
1978 * RETURNS
1979 *
1980 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
1981 * failure: 0
1982 *
1983 * NOTES
1984 *
1985 * Defaults to a word sort, but uses a string sort if
1986 * SORT_STRINGSORT is set.
1987 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
1988 *
1989 * BUGS
1990 *
1991 * This implementation ignores the locale
1992 *
1993 * FIXME
1994 *
1995 * Quite inefficient.
1996 */
1997UINT WINAPI CompareStringA(
1998 DWORD lcid, /* [in] locale ID */
1999 DWORD fdwStyle, /* [in] comparison-style options */
2000 LPCSTR s1, /* [in] first string */
2001 DWORD l1, /* [in] length of first string */
2002 LPCSTR s2, /* [in] second string */
2003 DWORD l2) /* [in] length of second string */
2004{
2005 int mapstring_flags;
2006 int len1,len2;
2007 int result;
2008 LPSTR sk1,sk2;
2009 TRACE("%s and %s\n",
2010 debugstr_a (s1), debugstr_a (s2));
2011
2012 if ( (s1==NULL) || (s2==NULL) )
2013 {
2014 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
2015 SetLastError(ERROR_INVALID_PARAMETER);
2016 return 0;
2017 }
2018
2019 if(fdwStyle & NORM_IGNORESYMBOLS)
2020 FIXME("IGNORESYMBOLS not supported\n");
2021
2022 if (l1 == -1) l1 = strlen(s1);
2023 if (l2 == -1) l2 = strlen(s2);
2024
2025 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2026 len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
2027 len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
2028
2029 if ((len1==0)||(len2==0))
2030 return 0; /* something wrong happened */
2031
2032 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
2033 sk2 = sk1 + len1;
2034 if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
2035 || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2036 {
2037 ERR("Bug in LCmapStringA.\n");
2038 result = 0;
2039 }
2040 else
2041 {
2042 /* strcmp doesn't necessarily return -1, 0, or 1 */
2043 result = strcmp(sk1,sk2);
2044 }
2045 HeapFree(GetProcessHeap(),0,sk1);
2046
2047 if (result < 0)
2048 return 1;
2049 if (result == 0)
2050 return 2;
2051
2052 /* must be greater, if we reach this point */
2053 return 3;
2054}
2055
2056/******************************************************************************
2057 * CompareStringW [KERNEL32.144]
2058 * This implementation ignores the locale
2059 * FIXME : Does only string sort. Should
2060 * be reimplemented the same way as CompareStringA.
2061 */
2062UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
2063 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2064{
2065 int len,ret;
2066 if(fdwStyle & NORM_IGNORENONSPACE)
2067 FIXME("IGNORENONSPACE not supprted\n");
2068 if(fdwStyle & NORM_IGNORESYMBOLS)
2069 FIXME("IGNORESYMBOLS not supported\n");
2070
2071 /* Is strcmp defaulting to string sort or to word sort?? */
2072 /* FIXME: Handle NORM_STRINGSORT */
2073 l1 = (l1==-1)?strlenW(s1):l1;
2074 l2 = (l2==-1)?strlenW(s2):l2;
2075 len = l1<l2 ? l1:l2;
2076 ret = (fdwStyle & NORM_IGNORECASE) ? strncmpiW(s1,s2,len) : strncmpW(s1,s2,len);
2077 /* not equal, return 1 or 3 */
2078 if(ret!=0) {
2079 /* need to translate result */
2080 return ((int)ret < 0) ? 1 : 3;
2081 }
2082 /* same len, return 2 */
2083 if(l1==l2) return 2;
2084 /* the longer one is lexically greater */
2085 return (l1<l2)? 1 : 3;
2086}
2087
2088/******************************************************************************
2089 * OLE_GetFormatA [Internal]
2090 *
2091 * FIXME
2092 * If datelen == 0, it should return the reguired string length.
2093 *
2094 This function implements stuff for GetDateFormat() and
2095 GetTimeFormat().
2096
2097 d single-digit (no leading zero) day (of month)
2098 dd two-digit day (of month)
2099 ddd short day-of-week name
2100 dddd long day-of-week name
2101 M single-digit month
2102 MM two-digit month
2103 MMM short month name
2104 MMMM full month name
2105 y two-digit year, no leading 0
2106 yy two-digit year
2107 yyyy four-digit year
2108 gg era string
2109 h hours with no leading zero (12-hour)
2110 hh hours with full two digits
2111 H hours with no leading zero (24-hour)
2112 HH hours with full two digits
2113 m minutes with no leading zero
2114 mm minutes with full two digits
2115 s seconds with no leading zero
2116 ss seconds with full two digits
2117 t time marker (A or P)
2118 tt time marker (AM, PM)
2119 '' used to quote literal characters
2120 '' (within a quoted string) indicates a literal '
2121
2122 These functions REQUIRE valid locale, date, and format.
2123 */
2124static INT OLE_GetFormatA(LCID locale,
2125 DWORD flags,
2126 DWORD tflags,
2127 LPSYSTEMTIME xtime,
2128 LPCSTR _format, /*in*/
2129 LPSTR date, /*out*/
2130 INT datelen)
2131{
2132 INT inpos, outpos;
2133 int count, type, inquote, Overflow;
2134 char buf[40];
2135 char format[40];
2136 char * pos;
2137 int buflen;
2138
2139 const char * _dgfmt[] = { "%d", "%02d" };
2140 const char ** dgfmt = _dgfmt - 1;
2141
2142 /* report, for debugging */
2143 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",
2144 locale, flags, tflags,
2145 xtime->wYear,xtime->wMonth,xtime->wDayOfWeek,xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2146 _format, _format, date, datelen);
2147
2148 if(datelen == 0) {
2149 FIXME("datelen = 0, returning 255\n");
2150 return 255;
2151 }
2152
2153 /* initalize state variables and output buffer */
2154 inpos = outpos = 0;
2155 count = 0; inquote = 0; Overflow = 0;
2156 type = '\0';
2157 date[0] = buf[0] = '\0';
2158
2159 strcpy(format,_format);
2160
2161 /* alter the formatstring, while it works for all languages now in wine
2162 its possible that it fails when the time looks like ss:mm:hh as example*/
2163 if (tflags & (TIME_NOMINUTESORSECONDS))
2164 { if ((pos = strstr ( format, ":mm")) != NULL)
2165 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2166 }
2167 }
2168 if (tflags & (TIME_NOSECONDS))
2169 { if ((pos = strstr ( format, ":ss")) != NULL)
2170 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2171 }
2172 }
2173
2174 for (inpos = 0;; inpos++) {
2175 /* 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]); */
2176 if (inquote) {
2177 if (format[inpos] == '\'') {
2178 if (format[inpos+1] == '\'') {
2179 inpos += 1;
2180 date[outpos++] = '\'';
2181 } else {
2182 inquote = 0;
2183 continue; /* we did nothing to the output */
2184 }
2185 } else if (format[inpos] == '\0') {
2186 date[outpos++] = '\0';
2187 if (outpos > datelen) Overflow = 1;
2188 break;
2189 } else {
2190 date[outpos++] = format[inpos];
2191 if (outpos > datelen) {
2192 Overflow = 1;
2193 date[outpos-1] = '\0'; /* this is the last place where
2194 it's safe to write */
2195 break;
2196 }
2197 }
2198 } else if ( (count && (format[inpos] != type))
2199 || count == 4
2200 || (count == 2 && strchr("ghHmst", type)) ) {
2201 if (type == 'h' && (tflags & TIME_FORCE24HOURFORMAT)) type= 'H';
2202 if (type == 'd') {
2203 if (count == 4) {
2204 GetLocaleInfoA(locale,
2205 LOCALE_SDAYNAME1
2206 + (xtime->wDayOfWeek+6)%7,
2207 buf, sizeof(buf));
2208 } else if (count == 3) {
2209 GetLocaleInfoA(locale,
2210 LOCALE_SABBREVDAYNAME1
2211 + (xtime->wDayOfWeek+6)%7,
2212 buf, sizeof(buf));
2213 } else {
2214 sprintf(buf, dgfmt[count], xtime->wDay);
2215 }
2216 } else if (type == 'M') {
2217 if (count == 3) {
2218 GetLocaleInfoA(locale,
2219 LOCALE_SABBREVMONTHNAME1
2220 + xtime->wMonth - 1,
2221 buf, sizeof(buf));
2222 } else if (count == 4) {
2223 GetLocaleInfoA(locale,
2224 LOCALE_SMONTHNAME1
2225 + xtime->wMonth - 1,
2226 buf, sizeof(buf));
2227 } else {
2228 sprintf(buf, dgfmt[count], xtime->wMonth);
2229 }
2230 } else if (type == 'y') {
2231 if (count == 4) {
2232 sprintf(buf, "%d", xtime->wYear);
2233 } else if (count == 3) {
2234 strcpy(buf, "yyy");
2235 WARN("unknown format, c=%c, n=%d\n", type, count);
2236 } else {
2237 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2238 }
2239 } else if (type == 'g') {
2240 if (count == 2) {
2241 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2242 strcpy(buf, "AD");
2243 } else {
2244 strcpy(buf, "g");
2245 WARN("unknown format, c=%c, n=%d\n", type, count);
2246 }
2247 } else if (type == 'h') {
2248 /* gives us hours 1:00 -- 12:00 */
2249 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2250 } else if (type == 'H') {
2251 /* 24-hour time */
2252 sprintf(buf, dgfmt[count], xtime->wHour);
2253 } else if ( type == 'm') {
2254 sprintf(buf, dgfmt[count], xtime->wMinute);
2255 } else if ( type == 's') {
2256 sprintf(buf, dgfmt[count], xtime->wSecond);
2257 } else if (type == 't') {
2258 if ((tflags & TIME_NOTIMEMARKER))
2259 buf[0]='\0';
2260 else if (count == 1) {
2261 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2262 } else if (count == 2) {
2263 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2264 GetLocaleInfoA(locale,
2265 (xtime->wHour<12)
2266 ? LOCALE_S1159 : LOCALE_S2359,
2267 buf, sizeof(buf));
2268 }
2269 };
2270
2271 /* we need to check the next char in the format string
2272 again, no matter what happened */
2273 inpos--;
2274
2275 /* add the contents of buf to the output */
2276 buflen = strlen(buf);
2277 if (outpos + buflen < datelen) {
2278 date[outpos] = '\0'; /* for strcat to hook onto */
2279 strcat(date, buf);
2280 outpos += buflen;
2281 } else {
2282 date[outpos] = '\0';
2283 strncat(date, buf, datelen - outpos);
2284 date[datelen - 1] = '\0';
2285 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2286 WARN("insufficient buffer\n");
2287 return 0;
2288 }
2289
2290 /* reset the variables we used to keep track of this item */
2291 count = 0;
2292 type = '\0';
2293 } else if (format[inpos] == '\0') {
2294 /* we can't check for this at the loop-head, because
2295 that breaks the printing of the last format-item */
2296 date[outpos] = '\0';
2297 break;
2298 } else if (count) {
2299 /* continuing a code for an item */
2300 count +=1;
2301 continue;
2302 } else if (strchr("hHmstyMdg", format[inpos])) {
2303 type = format[inpos];
2304 count = 1;
2305 continue;
2306 } else if (format[inpos] == '\'') {
2307 inquote = 1;
2308 continue;
2309 } else {
2310 date[outpos++] = format[inpos];
2311 }
2312 /* now deal with a possible buffer overflow */
2313 if (outpos >= datelen) {
2314 date[datelen - 1] = '\0';
2315 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2316 return 0;
2317 }
2318 }
2319
2320 if (Overflow) {
2321 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2322 };
2323
2324 /* finish it off with a string terminator */
2325 outpos++;
2326 /* sanity check */
2327 if (outpos > datelen-1) outpos = datelen-1;
2328 date[outpos] = '\0';
2329
2330 TRACE("returns string '%s', len %d\n", date, outpos);
2331 return outpos;
2332}
2333
2334/******************************************************************************
2335 * OLE_GetFormatW [INTERNAL]
2336 */
2337static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
2338 LPSYSTEMTIME xtime,
2339 LPCWSTR format,
2340 LPWSTR output, INT outlen)
2341{
2342 INT inpos, outpos;
2343 int count, type=0, inquote;
2344 int Overflow; /* loop check */
2345 char tmp[16];
2346 WCHAR buf[40];
2347 int buflen=0;
2348 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2349 WCHAR arg2[] = {'%','0','2','d',0};
2350 WCHAR *argarr[3];
2351 int datevars=0, timevars=0;
2352
2353 argarr[0] = arg0;
2354 argarr[1] = arg1;
2355 argarr[2] = arg2;
2356
2357 /* make a debug report */
2358 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2359 "%p with max len %d\n",
2360 locale, flags, tflags,
2361 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2362 debugstr_w(format), format, output, outlen);
2363
2364 if(outlen == 0) {
2365 FIXME("outlen = 0, returning 255\n");
2366 return 255;
2367 }
2368
2369 /* initialize state variables */
2370 inpos = outpos = 0;
2371 count = 0;
2372 inquote = Overflow = 0;
2373 /* this is really just a sanity check */
2374 output[0] = buf[0] = 0;
2375
2376 /* this loop is the core of the function */
2377 for (inpos = 0; /* we have several break points */ ; inpos++) {
2378 if (inquote) {
2379 if (format[inpos] == (WCHAR) '\'') {
2380 if (format[inpos+1] == '\'') {
2381 inpos++;
2382 output[outpos++] = '\'';
2383 } else {
2384 inquote = 0;
2385 continue;
2386 }
2387 } else if (format[inpos] == 0) {
2388 output[outpos++] = 0;
2389 if (outpos > outlen) Overflow = 1;
2390 break; /* normal exit (within a quote) */
2391 } else {
2392 output[outpos++] = format[inpos]; /* copy input */
2393 if (outpos > outlen) {
2394 Overflow = 1;
2395 output[outpos-1] = 0;
2396 break;
2397 }
2398 }
2399 } else if ( (count && (format[inpos] != type))
2400 || ( (count==4 && type =='y') ||
2401 (count==4 && type =='M') ||
2402 (count==4 && type =='d') ||
2403 (count==2 && type =='g') ||
2404 (count==2 && type =='h') ||
2405 (count==2 && type =='H') ||
2406 (count==2 && type =='m') ||
2407 (count==2 && type =='s') ||
2408 (count==2 && type =='t') ) ) {
2409 switch(type)
2410 {
2411 case 'd':
2412 if (count == 4) {
2413 GetLocaleInfoW(locale,
2414 LOCALE_SDAYNAME1 + (xtime->wDayOfWeek +6)%7,
2415 buf, sizeof(buf)/sizeof(WCHAR) );
2416 } else if (count == 3) {
2417 GetLocaleInfoW(locale,
2418 LOCALE_SABBREVDAYNAME1 +
2419 (xtime->wDayOfWeek +6)%7,
2420 buf, sizeof(buf)/sizeof(WCHAR) );
2421 } else {
2422 sprintf( tmp, "%.*d", count, xtime->wDay );
2423 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2424 }
2425 break;
2426
2427 case 'M':
2428 if (count == 4) {
2429 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
2430 xtime->wMonth -1, buf,
2431 sizeof(buf)/sizeof(WCHAR) );
2432 } else if (count == 3) {
2433 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
2434 xtime->wMonth -1, buf,
2435 sizeof(buf)/sizeof(WCHAR) );
2436 } else {
2437 sprintf( tmp, "%.*d", count, xtime->wMonth );
2438 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2439 }
2440 break;
2441 case 'y':
2442 if (count == 4) {
2443 sprintf( tmp, "%d", xtime->wYear );
2444 } else if (count == 3) {
2445 strcpy( tmp, "yyy" );
2446 } else {
2447 sprintf( tmp, "%.*d", count, xtime->wYear % 100 );
2448 }
2449 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2450 break;
2451
2452 case 'g':
2453 if (count == 2) {
2454 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2455 strcpy( tmp, "AD" );
2456 } else {
2457 /* Win API sez we copy it verbatim */
2458 strcpy( tmp, "g" );
2459 }
2460 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2461 break;
2462
2463 case 'h':
2464 /* hours 1:00-12:00 --- is this right? */
2465 sprintf( tmp, "%.*d", count, (xtime->wHour-1)%12 +1);
2466 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2467 break;
2468
2469 case 'H':
2470 sprintf( tmp, "%.*d", count, xtime->wHour );
2471 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2472 break;
2473
2474 case 'm':
2475 sprintf( tmp, "%.*d", count, xtime->wMinute );
2476 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2477 break;
2478
2479 case 's':
2480 sprintf( tmp, "%.*d", count, xtime->wSecond );
2481 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2482 break;
2483
2484 case 't':
2485 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
2486 LOCALE_S1159 : LOCALE_S2359,
2487 buf, sizeof(buf) );
2488 if (count == 1) {
2489 buf[1] = 0;
2490 }
2491 break;
2492 }
2493
2494 /* no matter what happened, we need to check this next
2495 character the next time we loop through */
2496 inpos--;
2497
2498 /* cat buf onto the output */
2499 outlen = strlenW(buf);
2500 if (outpos + buflen < outlen) {
2501 strcpyW( output + outpos, buf );
2502 outpos += buflen;
2503 } else {
2504 lstrcpynW( output + outpos, buf, outlen - outpos );
2505 Overflow = 1;
2506 break; /* Abnormal exit */
2507 }
2508
2509 /* reset the variables we used this time */
2510 count = 0;
2511 type = '\0';
2512 } else if (format[inpos] == 0) {
2513 /* we can't check for this at the beginning, because that
2514 would keep us from printing a format spec that ended the
2515 string */
2516 output[outpos] = 0;
2517 break; /* NORMAL EXIT */
2518 } else if (count) {
2519 /* how we keep track of the middle of a format spec */
2520 count++;
2521 continue;
2522 } else if ( (datevars && (format[inpos]=='d' ||
2523 format[inpos]=='M' ||
2524 format[inpos]=='y' ||
2525 format[inpos]=='g') ) ||
2526 (timevars && (format[inpos]=='H' ||
2527 format[inpos]=='h' ||
2528 format[inpos]=='m' ||
2529 format[inpos]=='s' ||
2530 format[inpos]=='t') ) ) {
2531 type = format[inpos];
2532 count = 1;
2533 continue;
2534 } else if (format[inpos] == '\'') {
2535 inquote = 1;
2536 continue;
2537 } else {
2538 /* unquoted literals */
2539 output[outpos++] = format[inpos];
2540 }
2541 }
2542
2543 if (Overflow) {
2544 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2545 WARN(" buffer overflow\n");
2546 };
2547
2548 /* final string terminator and sanity check */
2549 outpos++;
2550 if (outpos > outlen-1) outpos = outlen-1;
2551 output[outpos] = '0';
2552
2553 TRACE(" returning %s\n", debugstr_w(output));
2554
2555 return (!Overflow) ? outlen : 0;
2556
2557}
2558
2559
2560/******************************************************************************
2561 * GetDateFormatA [KERNEL32.310]
2562 * Makes an ASCII string of the date
2563 *
2564 * This function uses format to format the date, or, if format
2565 * is NULL, uses the default for the locale. format is a string
2566 * of literal fields and characters as follows:
2567 *
2568 * - d single-digit (no leading zero) day (of month)
2569 * - dd two-digit day (of month)
2570 * - ddd short day-of-week name
2571 * - dddd long day-of-week name
2572 * - M single-digit month
2573 * - MM two-digit month
2574 * - MMM short month name
2575 * - MMMM full month name
2576 * - y two-digit year, no leading 0
2577 * - yy two-digit year
2578 * - yyyy four-digit year
2579 * - gg era string
2580 *
2581 */
2582INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
2583 CONST SYSTEMTIME *xtime,
2584 LPCSTR format, LPSTR date,INT datelen)
2585{
2586
2587 char format_buf[40];
2588 LPCSTR thisformat;
2589 SYSTEMTIME t;
2590 LPSYSTEMTIME thistime;
2591 LCID thislocale;
2592 INT ret;
2593 FILETIME ft;
2594 BOOL res;
2595
2596 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2597 locale,flags,xtime,format,date,datelen);
2598
2599 if (!locale) {
2600 locale = LOCALE_SYSTEM_DEFAULT;
2601 };
2602
2603 if (locale == LOCALE_SYSTEM_DEFAULT) {
2604 thislocale = GetSystemDefaultLCID();
2605 } else if (locale == LOCALE_USER_DEFAULT) {
2606 thislocale = GetUserDefaultLCID();
2607 } else {
2608 thislocale = locale;
2609 };
2610
2611 if (xtime == NULL) {
2612 GetSystemTime(&t);
2613 } else {
2614 /* Silently correct wDayOfWeek by tranforming to FileTime and back again*/
2615 res=SystemTimeToFileTime(xtime,&ft);
2616 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error*/
2617 /*FIXME: SystemTimeToFileTime doesn't yet do that ckeck*/
2618 if(!res)
2619 {
2620 SetLastError(ERROR_INVALID_PARAMETER);
2621 return 0;
2622 }
2623 FileTimeToSystemTime(&ft,&t);
2624
2625 };
2626 thistime = &t;
2627
2628 if (format == NULL) {
2629 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
2630 ? LOCALE_SLONGDATE
2631 : LOCALE_SSHORTDATE),
2632 format_buf, sizeof(format_buf));
2633 thisformat = format_buf;
2634 } else {
2635 thisformat = format;
2636 };
2637
2638
2639 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
2640 date, datelen);
2641
2642
2643 TRACE(
2644 "GetDateFormatA() returning %d, with data=%s\n",
2645 ret, date);
2646 return ret;
2647}
2648
2649/******************************************************************************
2650 * GetDateFormatW [KERNEL32.311]
2651 * Makes a Unicode string of the date
2652 *
2653 * Acts the same as GetDateFormatA(), except that it's Unicode.
2654 * Accepts & returns sizes as counts of Unicode characters.
2655 *
2656 */
2657INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
2658 CONST SYSTEMTIME *xtime,
2659 LPCWSTR format,
2660 LPWSTR date, INT datelen)
2661{
2662#ifdef __WIN32OS2__
2663 // convert "format" on passing in into ASCII
2664 LPSTR pszAsciiFormat = UnicodeToAsciiString((LPWSTR) format);
2665 LPSTR pszAsciiDate = (char *)alloca(datelen);
2666 int rc;
2667
2668 TRACE("Kernel32-ole2nls: GetDateFormatW(0x%04lx,0x%08lx,%p,%s,%p,%d) not yet complete\n",
2669 locale,flags,xtime,pszAsciiFormat,date,datelen);
2670
2671 // call ASCII variant
2672 rc = GetDateFormatA(locale,
2673 flags,
2674 xtime,
2675 pszAsciiFormat,
2676 pszAsciiDate,
2677 datelen); // is in "characters", not bytes
2678
2679 FreeAsciiString(pszAsciiFormat);
2680
2681 // convert "date" on returning to UNICODE
2682 if (datelen != 0)
2683 {
2684 // in this case 'rc' holds the number of characters to convert
2685 lstrcpynAtoW(date, pszAsciiDate, rc);
2686 }
2687
2688 return rc;
2689
2690#else
2691 unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
2692
2693 FIXME("STUB (should call OLE_GetFormatW)\n");
2694 lstrcpynW(date, datearr, datelen);
2695 return ( datelen < 9) ? datelen : 9;
2696#endif
2697}
2698
2699/**************************************************************************
2700 * EnumDateFormatsA (KERNEL32.198)
2701 */
2702BOOL WINAPI EnumDateFormatsA(
2703 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2704{
2705 LCID Loc = GetUserDefaultLCID();
2706 if(!lpDateFmtEnumProc)
2707 {
2708 SetLastError(ERROR_INVALID_PARAMETER);
2709 return FALSE;
2710 }
2711
2712 switch( Loc )
2713 {
2714
2715 case 0x00000407: /* (Loc,"de_DE") */
2716 {
2717 switch(dwFlags)
2718 {
2719 case DATE_SHORTDATE:
2720 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
2721 if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
2722 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
2723 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
2724 return TRUE;
2725 case DATE_LONGDATE:
2726 if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
2727 if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
2728 if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
2729 return TRUE;
2730 default:
2731 FIXME("Unknown date format (%ld)\n", dwFlags);
2732 SetLastError(ERROR_INVALID_PARAMETER);
2733 return FALSE;
2734 }
2735 }
2736
2737 case 0x0000040c: /* (Loc,"fr_FR") */
2738 {
2739 switch(dwFlags)
2740 {
2741 case DATE_SHORTDATE:
2742 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2743 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
2744 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
2745 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2746 return TRUE;
2747 case DATE_LONGDATE:
2748 if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
2749 if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
2750 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2751 return TRUE;
2752 default:
2753 FIXME("Unknown date format (%ld)\n", dwFlags);
2754 SetLastError(ERROR_INVALID_PARAMETER);
2755 return FALSE;
2756 }
2757 }
2758
2759 case 0x00000c0c: /* (Loc,"fr_CA") */
2760 {
2761 switch(dwFlags)
2762 {
2763 case DATE_SHORTDATE:
2764 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
2765 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
2766 if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
2767 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2768 return TRUE;
2769 case DATE_LONGDATE:
2770 if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
2771 if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
2772 return TRUE;
2773 default:
2774 FIXME("Unknown date format (%ld)\n", dwFlags);
2775 SetLastError(ERROR_INVALID_PARAMETER);
2776 return FALSE;
2777 }
2778 }
2779
2780 case 0x00000809: /* (Loc,"en_UK") */
2781 {
2782 switch(dwFlags)
2783 {
2784 case DATE_SHORTDATE:
2785 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2786 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2787 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
2788 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
2789 return TRUE;
2790 case DATE_LONGDATE:
2791 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
2792 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2793 return TRUE;
2794 default:
2795 FIXME("Unknown date format (%ld)\n", dwFlags);
2796 SetLastError(ERROR_INVALID_PARAMETER);
2797 return FALSE;
2798 }
2799 }
2800
2801 case 0x00000c09: /* (Loc,"en_AU") */
2802 {
2803 switch(dwFlags)
2804 {
2805 case DATE_SHORTDATE:
2806 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
2807 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
2808 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2809 return TRUE;
2810 case DATE_LONGDATE:
2811 if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
2812 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2813 return TRUE;
2814 default:
2815 FIXME("Unknown date format (%ld)\n", dwFlags);
2816 SetLastError(ERROR_INVALID_PARAMETER);
2817 return FALSE;
2818 }
2819 }
2820
2821 case 0x00001009: /* (Loc,"en_CA") */
2822 {
2823 switch(dwFlags)
2824 {
2825 case DATE_SHORTDATE:
2826 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2827 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
2828 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
2829 if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
2830 return TRUE;
2831 case DATE_LONGDATE:
2832 if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
2833 if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
2834 return TRUE;
2835 default:
2836 FIXME("Unknown date format (%ld)\n", dwFlags);
2837 SetLastError(ERROR_INVALID_PARAMETER);
2838 return FALSE;
2839 }
2840 }
2841
2842 case 0x00001409: /* (Loc,"en_NZ") */
2843 {
2844 switch(dwFlags)
2845 {
2846 case DATE_SHORTDATE:
2847 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
2848 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2849 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
2850 return TRUE;
2851 case DATE_LONGDATE:
2852 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2853 if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
2854 return TRUE;
2855 default:
2856 FIXME("Unknown date format (%ld)\n", dwFlags);
2857 SetLastError(ERROR_INVALID_PARAMETER);
2858 return FALSE;
2859 }
2860 }
2861
2862 case 0x00001809: /* (Loc,"en_IE") */
2863 {
2864 switch(dwFlags)
2865 {
2866 case DATE_SHORTDATE:
2867 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2868 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
2869 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
2870 return TRUE;
2871 case DATE_LONGDATE:
2872 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
2873 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2874 return TRUE;
2875 default:
2876 FIXME("Unknown date format (%ld)\n", dwFlags);
2877 SetLastError(ERROR_INVALID_PARAMETER);
2878 return FALSE;
2879 }
2880 }
2881
2882 case 0x00001c09: /* (Loc,"en_ZA") */
2883 {
2884 switch(dwFlags)
2885 {
2886 case DATE_SHORTDATE:
2887 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
2888 return TRUE;
2889 case DATE_LONGDATE:
2890 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
2891 return TRUE;
2892 default:
2893 FIXME("Unknown date format (%ld)\n", dwFlags);
2894 SetLastError(ERROR_INVALID_PARAMETER);
2895 return FALSE;
2896 }
2897 }
2898
2899 case 0x00002009: /* (Loc,"en_JM") */
2900 {
2901 switch(dwFlags)
2902 {
2903 case DATE_SHORTDATE:
2904 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2905 return TRUE;
2906 case DATE_LONGDATE:
2907 if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
2908 if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
2909 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
2910 if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
2911 return TRUE;
2912 default:
2913 FIXME("Unknown date format (%ld)\n", dwFlags);
2914 SetLastError(ERROR_INVALID_PARAMETER);
2915 return FALSE;
2916 }
2917 }
2918
2919 case 0x00002809: /* (Loc,"en_BZ") */
2920 case 0x00002c09: /* (Loc,"en_TT") */
2921 {
2922 switch(dwFlags)
2923 {
2924 case DATE_SHORTDATE:
2925 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2926 return TRUE;
2927 case DATE_LONGDATE:
2928 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
2929 return TRUE;
2930 default:
2931 FIXME("Unknown date format (%ld)\n", dwFlags);
2932 SetLastError(ERROR_INVALID_PARAMETER);
2933 return FALSE;
2934 }
2935 }
2936
2937 default: /* default to US English "en_US" */
2938 {
2939 switch(dwFlags)
2940 {
2941 case DATE_SHORTDATE:
2942 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
2943 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
2944 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
2945 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
2946 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
2947 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
2948 return TRUE;
2949 case DATE_LONGDATE:
2950 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
2951 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
2952 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
2953 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
2954 return TRUE;
2955 default:
2956 FIXME("Unknown date format (%ld)\n", dwFlags);
2957 SetLastError(ERROR_INVALID_PARAMETER);
2958 return FALSE;
2959 }
2960 }
2961 }
2962}
2963
2964/**************************************************************************
2965 * EnumDateFormatsW (KERNEL32.199)
2966 */
2967BOOL WINAPI EnumDateFormatsW(
2968 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2969{
2970 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
2971 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2972 return FALSE;
2973}
2974
2975/**************************************************************************
2976 * EnumTimeFormatsA (KERNEL32.210)
2977 */
2978BOOL WINAPI EnumTimeFormatsA(
2979 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
2980{
2981 LCID Loc = GetUserDefaultLCID();
2982 if(!lpTimeFmtEnumProc)
2983 {
2984 SetLastError(ERROR_INVALID_PARAMETER);
2985 return FALSE;
2986 }
2987 if(dwFlags)
2988 {
2989 FIXME("Unknown time format (%ld)\n", dwFlags);
2990 }
2991
2992 switch( Loc )
2993 {
2994 case 0x00000407: /* (Loc,"de_DE") */
2995 {
2996 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
2997 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
2998 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
2999 if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
3000 if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
3001 return TRUE;
3002 }
3003
3004 case 0x0000040c: /* (Loc,"fr_FR") */
3005 case 0x00000c0c: /* (Loc,"fr_CA") */
3006 {
3007 if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
3008 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3009 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3010 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3011 if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
3012 return TRUE;
3013 }
3014
3015 case 0x00000809: /* (Loc,"en_UK") */
3016 case 0x00000c09: /* (Loc,"en_AU") */
3017 case 0x00001409: /* (Loc,"en_NZ") */
3018 case 0x00001809: /* (Loc,"en_IE") */
3019 {
3020 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3021 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3022 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3023 return TRUE;
3024 }
3025
3026 case 0x00001c09: /* (Loc,"en_ZA") */
3027 case 0x00002809: /* (Loc,"en_BZ") */
3028 case 0x00002c09: /* (Loc,"en_TT") */
3029 {
3030 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3031 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3032 return TRUE;
3033 }
3034
3035 default: /* default to US style "en_US" */
3036 {
3037 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3038 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3039 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3040 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3041 return TRUE;
3042 }
3043 }
3044}
3045
3046/**************************************************************************
3047 * EnumTimeFormatsW (KERNEL32.211)
3048 */
3049BOOL WINAPI EnumTimeFormatsW(
3050 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3051{
3052 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
3053 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3054 return FALSE;
3055}
3056
3057/**************************************************************************
3058 * This function is used just locally !
3059 * Description: Inverts a string.
3060 */
3061static void OLE_InvertString(char* string)
3062{
3063 char sTmpArray[128];
3064 INT counter, i = 0;
3065
3066 for (counter = strlen(string); counter > 0; counter--)
3067 {
3068 memcpy(sTmpArray + i, string + counter-1, 1);
3069 i++;
3070 }
3071 memcpy(sTmpArray + i, "\0", 1);
3072 strcpy(string, sTmpArray);
3073}
3074
3075/***************************************************************************************
3076 * This function is used just locally !
3077 * Description: Test if the given string (psNumber) is valid or not.
3078 * The valid characters are the following:
3079 * - Characters '0' through '9'.
3080 * - One decimal point (dot) if the number is a floating-point value.
3081 * - A minus sign in the first character position if the number is
3082 * a negative value.
3083 * If the function succeeds, psBefore/psAfter will point to the string
3084 * on the right/left of the decimal symbol. pbNegative indicates if the
3085 * number is negative.
3086 */
3087static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
3088{
3089char sNumberSet[] = "0123456789";
3090BOOL bInDecimal = FALSE;
3091
3092 /* Test if we do have a minus sign */
3093 if ( *pInput == '-' )
3094 {
3095 *pbNegative = TRUE;
3096 pInput++; /* Jump to the next character. */
3097 }
3098
3099 while(*pInput != '\0')
3100 {
3101 /* Do we have a valid numeric character */
3102 if ( strchr(sNumberSet, *pInput) != NULL )
3103 {
3104 if (bInDecimal == TRUE)
3105 *psAfter++ = *pInput;
3106 else
3107 *psBefore++ = *pInput;
3108 }
3109 else
3110 {
3111 /* Is this a decimal point (dot) */
3112 if ( *pInput == '.' )
3113 {
3114 /* Is it the first time we find it */
3115 if ((bInDecimal == FALSE))
3116 bInDecimal = TRUE;
3117 else
3118 return -1; /* ERROR: Invalid parameter */
3119 }
3120 else
3121 {
3122 /* It's neither a numeric character, nor a decimal point.
3123 * Thus, return an error.
3124 */
3125 return -1;
3126 }
3127 }
3128 pInput++;
3129 }
3130
3131 /* Add an End of Line character to the output buffers */
3132 *psBefore = '\0';
3133 *psAfter = '\0';
3134
3135 return 0;
3136}
3137
3138/**************************************************************************
3139 * This function is used just locally !
3140 * Description: A number could be formatted using different numbers
3141 * of "digits in group" (example: 4;3;2;0).
3142 * The first parameter of this function is an array
3143 * containing the rule to be used. It's format is the following:
3144 * |NDG|DG1|DG2|...|0|
3145 * where NDG is the number of used "digits in group" and DG1, DG2,
3146 * are the corresponding "digits in group".
3147 * Thus, this function returns the grouping value in the array
3148 * pointed by the second parameter.
3149 */
3150static INT OLE_GetGrouping(char* sRule, INT index)
3151{
3152 char sData[2], sRuleSize[2];
3153 INT nData, nRuleSize;
3154
3155 memcpy(sRuleSize, sRule, 1);
3156 memcpy(sRuleSize+1, "\0", 1);
3157 nRuleSize = atoi(sRuleSize);
3158
3159 if (index > 0 && index < nRuleSize)
3160 {
3161 memcpy(sData, sRule+index, 1);
3162 memcpy(sData+1, "\0", 1);
3163 nData = atoi(sData);
3164 }
3165
3166 else
3167 {
3168 memcpy(sData, sRule+nRuleSize-1, 1);
3169 memcpy(sData+1, "\0", 1);
3170 nData = atoi(sData);
3171 }
3172
3173 return nData;
3174}
3175
3176/**************************************************************************
3177 * GetNumberFormatA (KERNEL32.355)
3178 */
3179INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
3180 LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
3181 LPSTR lpNumberStr, int cchNumber)
3182{
3183 char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
3184 INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
3185 char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
3186 char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
3187 char *pStr = NULL, *pTmpStr = NULL;
3188 LCID systemDefaultLCID;
3189 BOOL bNegative = FALSE;
3190 enum Operations
3191 {
3192 USE_PARAMETER,
3193 USE_LOCALEINFO,
3194 USE_SYSTEMDEFAULT,
3195 RETURN_ERROR
3196 } used_operation;
3197
3198 strncpy(sNumber, lpvalue, 128);
3199 sNumber[127] = '\0';
3200
3201 /* Make sure we have a valid input string, get the number
3202 * of digits before and after the decimal symbol, and check
3203 * if this is a negative number.
3204 */
3205 if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
3206 {
3207 nNumberDecimal = strlen(sDigitsBeforeDecimal);
3208 nDigits = strlen(sDigitsAfterDecimal);
3209 }
3210 else
3211 {
3212 SetLastError(ERROR_INVALID_PARAMETER);
3213 return 0;
3214 }
3215
3216 /* Which source will we use to format the string */
3217 used_operation = RETURN_ERROR;
3218 if (lpFormat != NULL)
3219 {
3220 if (dwflags == 0)
3221 used_operation = USE_PARAMETER;
3222 }
3223 else
3224 {
3225 if (dwflags & LOCALE_NOUSEROVERRIDE)
3226 used_operation = USE_LOCALEINFO;
3227 else
3228 used_operation = USE_SYSTEMDEFAULT;
3229 }
3230
3231 /* Load the fields we need */
3232 switch(used_operation)
3233 {
3234 case USE_LOCALEINFO:
3235 GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3236 GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3237 GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3238 GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3239 GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3240 GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3241 break;
3242 case USE_PARAMETER:
3243 sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
3244 strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
3245 sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
3246 strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
3247 sprintf(sILZero, "%d",lpFormat->LeadingZero);
3248 sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
3249 break;
3250 case USE_SYSTEMDEFAULT:
3251 systemDefaultLCID = GetSystemDefaultLCID();
3252 GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3253 GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3254 GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3255 GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3256 GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3257 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3258 break;
3259 default:
3260 SetLastError(ERROR_INVALID_PARAMETER);
3261 return 0;
3262 }
3263
3264 nNumberDigits = atoi(sNumberDigits);
3265
3266 /* Remove the ";" */
3267 i=0;
3268 j = 1;
3269 for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
3270 {
3271 if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
3272 {
3273 memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
3274 i++;
3275 j++;
3276 }
3277 }
3278 sprintf(sBuffer, "%d", i);
3279 memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3280 memcpy(sRule + j, "\0", 1);
3281
3282 /* First, format the digits before the decimal. */
3283 if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
3284 {
3285 /* Working on an inverted string is easier ! */
3286 OLE_InvertString(sDigitsBeforeDecimal);
3287
3288 nStep = nCounter = i = j = 0;
3289 nRuleIndex = 1;
3290 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3291
3292 /* Here, we will loop until we reach the end of the string.
3293 * An internal counter (j) is used in order to know when to
3294 * insert the "digit group symbol".
3295 */
3296 while (nNumberDecimal > 0)
3297 {
3298 i = nCounter + nStep;
3299 memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
3300 nCounter++;
3301 j++;
3302 if (j >= nGrouping)
3303 {
3304 j = 0;
3305 if (nRuleIndex < sRule[0])
3306 nRuleIndex++;
3307 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3308 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
3309 nStep+= strlen(sDigitGroupSymbol);
3310 }
3311
3312 nNumberDecimal--;
3313 }
3314
3315 memcpy(sDestination + i+1, "\0", 1);
3316 /* Get the string in the right order ! */
3317 OLE_InvertString(sDestination);
3318 }
3319 else
3320 {
3321 nLZ = atoi(sILZero);
3322 if (nLZ != 0)
3323 {
3324 /* Use 0.xxx instead of .xxx */
3325 memcpy(sDestination, "0", 1);
3326 memcpy(sDestination+1, "\0", 1);
3327 }
3328 else
3329 memcpy(sDestination, "\0", 1);
3330
3331 }
3332
3333 /* Second, format the digits after the decimal. */
3334 j = 0;
3335 nCounter = nNumberDigits;
3336 if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
3337 {
3338 i = strlen(sNumber) - strlen(pStr) + 1;
3339 strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
3340 j = strlen(sDigitsAfterDecimal);
3341 if (j < nNumberDigits)
3342 nCounter = nNumberDigits-j;
3343 }
3344 for (i=0;i<nCounter;i++)
3345 memcpy(sDigitsAfterDecimal+i+j, "0", 1);
3346 memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
3347
3348 i = strlen(sDestination);
3349 j = strlen(sDigitsAfterDecimal);
3350 /* Finally, construct the resulting formatted string. */
3351
3352 for (nCounter=0; nCounter<i; nCounter++)
3353 memcpy(sNumber + nCounter, sDestination + nCounter, 1);
3354
3355 memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
3356
3357 for (i=0; i<j; i++)
3358 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
3359 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
3360
3361 /* Is it a negative number */
3362 if (bNegative == TRUE)
3363 {
3364 i = atoi(sNegNumber);
3365 pStr = sDestination;
3366 pTmpStr = sNumber;
3367 switch (i)
3368 {
3369 case 0:
3370 *pStr++ = '(';
3371 while (*sNumber != '\0')
3372 *pStr++ = *pTmpStr++;
3373 *pStr++ = ')';
3374 break;
3375 case 1:
3376 *pStr++ = '-';
3377 while (*pTmpStr != '\0')
3378 *pStr++ = *pTmpStr++;
3379 break;
3380 case 2:
3381 *pStr++ = '-';
3382 *pStr++ = ' ';
3383 while (*pTmpStr != '\0')
3384 *pStr++ = *pTmpStr++;
3385 break;
3386 case 3:
3387 while (*pTmpStr != '\0')
3388 *pStr++ = *pTmpStr++;
3389 *pStr++ = '-';
3390 break;
3391 case 4:
3392 while (*pTmpStr != '\0')
3393 *pStr++ = *pTmpStr++;
3394 *pStr++ = ' ';
3395 *pStr++ = '-';
3396 break;
3397 default:
3398 while (*pTmpStr != '\0')
3399 *pStr++ = *pTmpStr++;
3400 break;
3401 }
3402 }
3403 else
3404 strcpy(sDestination, sNumber);
3405
3406 /* If cchNumber is zero, then returns the number of bytes or characters
3407 * required to hold the formatted number string
3408 */
3409 if (cchNumber==0)
3410 retVal = strlen(sDestination) + 1;
3411 else
3412 {
3413 strncpy (lpNumberStr, sDestination, cchNumber-1);
3414 *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
3415 retVal = strlen(lpNumberStr);
3416 }
3417
3418 return retVal;
3419}
3420
3421/**************************************************************************
3422 * GetNumberFormatW (KERNEL32.@)
3423 */
3424INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
3425 LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
3426 LPWSTR lpNumberStr, int cchNumber)
3427{
3428 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue));
3429
3430 lstrcpynW( lpNumberStr, lpvalue, cchNumber );
3431 return cchNumber? strlenW( lpNumberStr ) : 0;
3432}
3433
3434/**************************************************************************
3435 * GetCurrencyFormatA (KERNEL32.302)
3436 */
3437INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
3438 LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
3439 LPSTR lpCurrencyStr, int cchCurrency)
3440{
3441 UINT nPosOrder, nNegOrder;
3442 INT retVal;
3443 char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
3444 char *pDestination = sDestination;
3445 char sNumberFormated[128];
3446 char *pNumberFormated = sNumberFormated;
3447 LCID systemDefaultLCID;
3448 BOOL bIsPositive = FALSE, bValidFormat = FALSE;
3449 enum Operations
3450 {
3451 USE_PARAMETER,
3452 USE_LOCALEINFO,
3453 USE_SYSTEMDEFAULT,
3454 RETURN_ERROR
3455 } used_operation;
3456
3457 NUMBERFMTA numberFmt;
3458
3459 /* Which source will we use to format the string */
3460 used_operation = RETURN_ERROR;
3461 if (lpFormat != NULL)
3462 {
3463 if (dwflags == 0)
3464 used_operation = USE_PARAMETER;
3465 }
3466 else
3467 {
3468 if (dwflags & LOCALE_NOUSEROVERRIDE)
3469 used_operation = USE_LOCALEINFO;
3470 else
3471 used_operation = USE_SYSTEMDEFAULT;
3472 }
3473
3474 /* Load the fields we need */
3475 switch(used_operation)
3476 {
3477 case USE_LOCALEINFO:
3478 /* Specific to CURRENCYFMTA*/
3479 GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3480 GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3481 GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3482
3483 nPosOrder = atoi(sPosOrder);
3484 nNegOrder = atoi(sNegOrder);
3485 break;
3486 case USE_PARAMETER:
3487 /* Specific to CURRENCYFMTA*/
3488 nNegOrder = lpFormat->NegativeOrder;
3489 nPosOrder = lpFormat->PositiveOrder;
3490 strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
3491 break;
3492 case USE_SYSTEMDEFAULT:
3493 systemDefaultLCID = GetSystemDefaultLCID();
3494 /* Specific to CURRENCYFMTA*/
3495 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3496 GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3497 GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3498
3499 nPosOrder = atoi(sPosOrder);
3500 nNegOrder = atoi(sNegOrder);
3501 break;
3502 default:
3503 SetLastError(ERROR_INVALID_PARAMETER);
3504 return 0;
3505 }
3506
3507 /* Construct a temporary number format structure */
3508 if (lpFormat != NULL)
3509 {
3510 numberFmt.NumDigits = lpFormat->NumDigits;
3511 numberFmt.LeadingZero = lpFormat->LeadingZero;
3512 numberFmt.Grouping = lpFormat->Grouping;
3513 numberFmt.NegativeOrder = 0;
3514 numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
3515 numberFmt.lpThousandSep = lpFormat->lpThousandSep;
3516 bValidFormat = TRUE;
3517 }
3518
3519 /* Make a call to GetNumberFormatA() */
3520 if (*lpvalue == '-')
3521 {
3522 bIsPositive = FALSE;
3523 retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3524 }
3525 else
3526 {
3527 bIsPositive = TRUE;
3528 retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3529 }
3530
3531 if (retVal == 0)
3532 return 0;
3533
3534 /* construct the formatted string */
3535 if (bIsPositive)
3536 {
3537 switch (nPosOrder)
3538 {
3539 case 0: /* Prefix, no separation */
3540 strcpy (pDestination, sCurrencySymbol);
3541 strcat (pDestination, pNumberFormated);
3542 break;
3543 case 1: /* Suffix, no separation */
3544 strcpy (pDestination, pNumberFormated);
3545 strcat (pDestination, sCurrencySymbol);
3546 break;
3547 case 2: /* Prefix, 1 char separation */
3548 strcpy (pDestination, sCurrencySymbol);
3549 strcat (pDestination, " ");
3550 strcat (pDestination, pNumberFormated);
3551 break;
3552 case 3: /* Suffix, 1 char separation */
3553 strcpy (pDestination, pNumberFormated);
3554 strcat (pDestination, " ");
3555 strcat (pDestination, sCurrencySymbol);
3556 break;
3557 default:
3558 SetLastError(ERROR_INVALID_PARAMETER);
3559 return 0;
3560 }
3561 }
3562 else /* negative number */
3563 {
3564 switch (nNegOrder)
3565 {
3566 case 0: /* format: ($1.1) */
3567 strcpy (pDestination, "(");
3568 strcat (pDestination, sCurrencySymbol);
3569 strcat (pDestination, pNumberFormated);
3570 strcat (pDestination, ")");
3571 break;
3572 case 1: /* format: -$1.1 */
3573 strcpy (pDestination, "-");
3574 strcat (pDestination, sCurrencySymbol);
3575 strcat (pDestination, pNumberFormated);
3576 break;
3577 case 2: /* format: $-1.1 */
3578 strcpy (pDestination, sCurrencySymbol);
3579 strcat (pDestination, "-");
3580 strcat (pDestination, pNumberFormated);
3581 break;
3582 case 3: /* format: $1.1- */
3583 strcpy (pDestination, sCurrencySymbol);
3584 strcat (pDestination, pNumberFormated);
3585 strcat (pDestination, "-");
3586 break;
3587 case 4: /* format: (1.1$) */
3588 strcpy (pDestination, "(");
3589 strcat (pDestination, pNumberFormated);
3590 strcat (pDestination, sCurrencySymbol);
3591 strcat (pDestination, ")");
3592 break;
3593 case 5: /* format: -1.1$ */
3594 strcpy (pDestination, "-");
3595 strcat (pDestination, pNumberFormated);
3596 strcat (pDestination, sCurrencySymbol);
3597 break;
3598 case 6: /* format: 1.1-$ */
3599 strcpy (pDestination, pNumberFormated);
3600 strcat (pDestination, "-");
3601 strcat (pDestination, sCurrencySymbol);
3602 break;
3603 case 7: /* format: 1.1$- */
3604 strcpy (pDestination, pNumberFormated);
3605 strcat (pDestination, sCurrencySymbol);
3606 strcat (pDestination, "-");
3607 break;
3608 case 8: /* format: -1.1 $ */
3609 strcpy (pDestination, "-");
3610 strcat (pDestination, pNumberFormated);
3611 strcat (pDestination, " ");
3612 strcat (pDestination, sCurrencySymbol);
3613 break;
3614 case 9: /* format: -$ 1.1 */
3615 strcpy (pDestination, "-");
3616 strcat (pDestination, sCurrencySymbol);
3617 strcat (pDestination, " ");
3618 strcat (pDestination, pNumberFormated);
3619 break;
3620 case 10: /* format: 1.1 $- */
3621 strcpy (pDestination, pNumberFormated);
3622 strcat (pDestination, " ");
3623 strcat (pDestination, sCurrencySymbol);
3624 strcat (pDestination, "-");
3625 break;
3626 case 11: /* format: $ 1.1- */
3627 strcpy (pDestination, sCurrencySymbol);
3628 strcat (pDestination, " ");
3629 strcat (pDestination, pNumberFormated);
3630 strcat (pDestination, "-");
3631 break;
3632 case 12: /* format: $ -1.1 */
3633 strcpy (pDestination, sCurrencySymbol);
3634 strcat (pDestination, " ");
3635 strcat (pDestination, "-");
3636 strcat (pDestination, pNumberFormated);
3637 break;
3638 case 13: /* format: 1.1- $ */
3639 strcpy (pDestination, pNumberFormated);
3640 strcat (pDestination, "-");
3641 strcat (pDestination, " ");
3642 strcat (pDestination, sCurrencySymbol);
3643 break;
3644 case 14: /* format: ($ 1.1) */
3645 strcpy (pDestination, "(");
3646 strcat (pDestination, sCurrencySymbol);
3647 strcat (pDestination, " ");
3648 strcat (pDestination, pNumberFormated);
3649 strcat (pDestination, ")");
3650 break;
3651 case 15: /* format: (1.1 $) */
3652 strcpy (pDestination, "(");
3653 strcat (pDestination, pNumberFormated);
3654 strcat (pDestination, " ");
3655 strcat (pDestination, sCurrencySymbol);
3656 strcat (pDestination, ")");
3657 break;
3658 default:
3659 SetLastError(ERROR_INVALID_PARAMETER);
3660 return 0;
3661 }
3662 }
3663
3664 if (cchCurrency == 0)
3665 return strlen(pDestination) + 1;
3666
3667 else
3668 {
3669 strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
3670 *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
3671 return strlen(lpCurrencyStr);
3672 }
3673}
3674
3675/**************************************************************************
3676 * GetCurrencyFormatW (KERNEL32.303)
3677 */
3678INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
3679 LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
3680 LPWSTR lpCurrencyStr, int cchCurrency)
3681{
3682 FIXME("This API function is NOT implemented !\n");
3683 return 0;
3684}
3685
3686/******************************************************************************
3687 * OLE2NLS_CheckLocale [intern]
3688 */
3689static LCID OLE2NLS_CheckLocale (LCID locale)
3690{
3691 if (!locale)
3692 { locale = LOCALE_SYSTEM_DEFAULT;
3693 }
3694
3695 if (locale == LOCALE_SYSTEM_DEFAULT)
3696 { return GetSystemDefaultLCID();
3697 }
3698 else if (locale == LOCALE_USER_DEFAULT)
3699 { return GetUserDefaultLCID();
3700 }
3701 else
3702 { return locale;
3703 }
3704}
3705/******************************************************************************
3706 * GetTimeFormatA [KERNEL32.422]
3707 * Makes an ASCII string of the time
3708 *
3709 * Formats date according to format, or locale default if format is
3710 * NULL. The format consists of literal characters and fields as follows:
3711 *
3712 * h hours with no leading zero (12-hour)
3713 * hh hours with full two digits
3714 * H hours with no leading zero (24-hour)
3715 * HH hours with full two digits
3716 * m minutes with no leading zero
3717 * mm minutes with full two digits
3718 * s seconds with no leading zero
3719 * ss seconds with full two digits
3720 * t time marker (A or P)
3721 * tt time marker (AM, PM)
3722 *
3723 */
3724INT WINAPI
3725GetTimeFormatA(LCID locale, /* [in] */
3726 DWORD flags, /* [in] */
3727 CONST SYSTEMTIME *xtime, /* [in] */
3728 LPCSTR format, /* [in] */
3729 LPSTR timestr, /* [out] */
3730 INT timelen /* [in] */)
3731{ char format_buf[40];
3732 LPCSTR thisformat;
3733 SYSTEMTIME t;
3734 LPSYSTEMTIME thistime;
3735 LCID thislocale=0;
3736 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
3737 INT ret;
3738
3739 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
3740
3741 thislocale = OLE2NLS_CheckLocale ( locale );
3742
3743 if (format == NULL)
3744 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
3745 { thislocale = GetSystemDefaultLCID();
3746 }
3747 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
3748 thisformat = format_buf;
3749 }
3750 else
3751 { thisformat = format;
3752 }
3753
3754 if (xtime == NULL) /* NULL means use the current local time*/
3755 { GetLocalTime(&t);
3756 thistime = &t;
3757 }
3758 else
3759 { thistime = (LPSYSTEMTIME)xtime;
3760 /* Check that hour,min and sec is in range */
3761 }
3762 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
3763 timestr, timelen);
3764 return ret;
3765}
3766
3767
3768/******************************************************************************
3769 * GetTimeFormatW [KERNEL32.423]
3770 * Makes a Unicode string of the time
3771 */
3772INT WINAPI
3773GetTimeFormatW(LCID locale, /* [in] */
3774 DWORD flags, /* [in] */
3775 CONST SYSTEMTIME *xtime, /* [in] */
3776 LPCWSTR format, /* [in] */
3777 LPWSTR timestr, /* [out] */
3778 INT timelen /* [in] */)
3779{ WCHAR format_buf[40];
3780 LPCWSTR thisformat;
3781 SYSTEMTIME t;
3782 LPSYSTEMTIME thistime;
3783 LCID thislocale=0;
3784 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
3785 INT ret;
3786
3787 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
3788 xtime,debugstr_w(format),timestr,timelen);
3789
3790 thislocale = OLE2NLS_CheckLocale ( locale );
3791
3792 if (format == NULL)
3793 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
3794 { thislocale = GetSystemDefaultLCID();
3795 }
3796 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
3797 thisformat = format_buf;
3798 }
3799 else
3800 { thisformat = format;
3801 }
3802
3803 if (xtime == NULL) /* NULL means use the current local time*/
3804 { GetLocalTime(&t);
3805 thistime = &t;
3806 }
3807 else
3808 { thistime = (LPSYSTEMTIME)xtime;
3809 }
3810
3811 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
3812 timestr, timelen);
3813 return ret;
3814}
3815
3816/******************************************************************************
3817 * EnumCalendarInfoA [KERNEL32.196]
3818 */
3819BOOL WINAPI EnumCalendarInfoA(
3820 CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
3821) {
3822 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);
3823 return FALSE;
3824}
3825
3826#ifdef __WIN32OS2__
3827/*****************************************************************************
3828 * Name : BOOL WIN32API EnumCalendarInfoW
3829 * Purpose : The EnumCalendarInfoW function enumerates calendar information
3830 * for a specified locale. The CalType parameter specifies the type
3831 * of calendar information to enumerate. The function returns the
3832 * specified calendar information for all applicable calendars for
3833 * the locale, or for a single requested calendar, depending on the
3834 * value of the Calendar parameter.
3835 * The EnumCalendarInfo function enumerates the calendar information
3836 * by calling an application-defined callback function. It passes
3837 * the callback function a pointer to a string buffer containing
3838 * the requested calendar information. This continues until either
3839 * the last applicable calendar is found or the callback function
3840 * returns FALSE.
3841 * Parameters: CALINFO_ENUMPROCW lpCalInfoEnumProc pointer to enumeration
3842 * callback function
3843 * LCID Locale locale whose calendar information is of interest
3844 * CALID Calendar calendar whose information is of interest
3845 * CALTYPE CalType type of calendar information of interest
3846 * Variables :
3847 * Result : If the function succeeds, the return value is nonzero.
3848 * If the function fails, the return value is zero
3849 * Remark :
3850 * Status : UNTESTED STUB
3851 *
3852 * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
3853 *****************************************************************************/
3854
3855BOOL WIN32API EnumCalendarInfoW(CALINFO_ENUMPROCW lpCalInfoEnumProc,
3856 LCID Locale,
3857 CALID Calendar,
3858 CALTYPE CalType)
3859{
3860
3861 dprintf(("KERNEL32: EnumCalendarInfoW(%08x,%08x,%08x,%08x)not implemented\n",
3862 lpCalInfoEnumProc,
3863 Locale,
3864 Calendar,
3865 CalType
3866 ));
3867
3868 return (FALSE);
3869}
3870#endif
Note: See TracBrowser for help on using the repository browser.