Delay import of user32 to allow debugging crashes in user init code.
[wine/multimedia.git] / ole / ole2nls.c
blobe410f737bd0c674e9867ed19aa4dcc7f6ef26a87
1 /*
2 * National Language Support library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
7 */
9 #include <string.h>
10 #include <stdio.h>
11 #include <ctype.h>
12 #include <stdlib.h>
13 #include <locale.h>
15 #include "windef.h"
16 #include "winbase.h"
17 #include "wingdi.h"
18 #include "winuser.h"
19 #include "wine/unicode.h"
20 #include "heap.h"
21 #include "options.h"
22 #include "winver.h"
23 #include "winnls.h"
24 #include "winreg.h"
25 #include "winerror.h"
26 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(string);
30 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
31 * MUST contain all #defines from winnls.h
32 * last entry has NULL name, 0 id.
33 */
34 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
35 static const struct tagLOCALE_NAME2ID {
36 const char *name;
37 LCTYPE id;
38 } locale_name2id[]= {
39 LOCALE_ENTRY(ILANGUAGE),
40 LOCALE_ENTRY(SLANGUAGE),
41 LOCALE_ENTRY(SENGLANGUAGE),
42 LOCALE_ENTRY(SABBREVLANGNAME),
43 LOCALE_ENTRY(SNATIVELANGNAME),
44 LOCALE_ENTRY(ICOUNTRY),
45 LOCALE_ENTRY(SCOUNTRY),
46 LOCALE_ENTRY(SENGCOUNTRY),
47 LOCALE_ENTRY(SABBREVCTRYNAME),
48 LOCALE_ENTRY(SNATIVECTRYNAME),
49 LOCALE_ENTRY(IDEFAULTLANGUAGE),
50 LOCALE_ENTRY(IDEFAULTCOUNTRY),
51 LOCALE_ENTRY(IDEFAULTCODEPAGE),
52 LOCALE_ENTRY(IDEFAULTANSICODEPAGE),
53 LOCALE_ENTRY(IDEFAULTMACCODEPAGE),
54 LOCALE_ENTRY(SLIST),
55 LOCALE_ENTRY(IMEASURE),
56 LOCALE_ENTRY(SDECIMAL),
57 LOCALE_ENTRY(STHOUSAND),
58 LOCALE_ENTRY(SGROUPING),
59 LOCALE_ENTRY(IDIGITS),
60 LOCALE_ENTRY(ILZERO),
61 LOCALE_ENTRY(INEGNUMBER),
62 LOCALE_ENTRY(SNATIVEDIGITS),
63 LOCALE_ENTRY(SCURRENCY),
64 LOCALE_ENTRY(SINTLSYMBOL),
65 LOCALE_ENTRY(SMONDECIMALSEP),
66 LOCALE_ENTRY(SMONTHOUSANDSEP),
67 LOCALE_ENTRY(SMONGROUPING),
68 LOCALE_ENTRY(ICURRDIGITS),
69 LOCALE_ENTRY(IINTLCURRDIGITS),
70 LOCALE_ENTRY(ICURRENCY),
71 LOCALE_ENTRY(INEGCURR),
72 LOCALE_ENTRY(SDATE),
73 LOCALE_ENTRY(STIME),
74 LOCALE_ENTRY(SSHORTDATE),
75 LOCALE_ENTRY(SLONGDATE),
76 LOCALE_ENTRY(STIMEFORMAT),
77 LOCALE_ENTRY(IDATE),
78 LOCALE_ENTRY(ILDATE),
79 LOCALE_ENTRY(ITIME),
80 LOCALE_ENTRY(ITIMEMARKPOSN),
81 LOCALE_ENTRY(ICENTURY),
82 LOCALE_ENTRY(ITLZERO),
83 LOCALE_ENTRY(IDAYLZERO),
84 LOCALE_ENTRY(IMONLZERO),
85 LOCALE_ENTRY(S1159),
86 LOCALE_ENTRY(S2359),
87 LOCALE_ENTRY(ICALENDARTYPE),
88 LOCALE_ENTRY(IOPTIONALCALENDAR),
89 LOCALE_ENTRY(IFIRSTDAYOFWEEK),
90 LOCALE_ENTRY(IFIRSTWEEKOFYEAR),
91 LOCALE_ENTRY(SDAYNAME1),
92 LOCALE_ENTRY(SDAYNAME2),
93 LOCALE_ENTRY(SDAYNAME3),
94 LOCALE_ENTRY(SDAYNAME4),
95 LOCALE_ENTRY(SDAYNAME5),
96 LOCALE_ENTRY(SDAYNAME6),
97 LOCALE_ENTRY(SDAYNAME7),
98 LOCALE_ENTRY(SABBREVDAYNAME1),
99 LOCALE_ENTRY(SABBREVDAYNAME2),
100 LOCALE_ENTRY(SABBREVDAYNAME3),
101 LOCALE_ENTRY(SABBREVDAYNAME4),
102 LOCALE_ENTRY(SABBREVDAYNAME5),
103 LOCALE_ENTRY(SABBREVDAYNAME6),
104 LOCALE_ENTRY(SABBREVDAYNAME7),
105 LOCALE_ENTRY(SMONTHNAME1),
106 LOCALE_ENTRY(SMONTHNAME2),
107 LOCALE_ENTRY(SMONTHNAME3),
108 LOCALE_ENTRY(SMONTHNAME4),
109 LOCALE_ENTRY(SMONTHNAME5),
110 LOCALE_ENTRY(SMONTHNAME6),
111 LOCALE_ENTRY(SMONTHNAME7),
112 LOCALE_ENTRY(SMONTHNAME8),
113 LOCALE_ENTRY(SMONTHNAME9),
114 LOCALE_ENTRY(SMONTHNAME10),
115 LOCALE_ENTRY(SMONTHNAME11),
116 LOCALE_ENTRY(SMONTHNAME12),
117 LOCALE_ENTRY(SMONTHNAME13),
118 LOCALE_ENTRY(SABBREVMONTHNAME1),
119 LOCALE_ENTRY(SABBREVMONTHNAME2),
120 LOCALE_ENTRY(SABBREVMONTHNAME3),
121 LOCALE_ENTRY(SABBREVMONTHNAME4),
122 LOCALE_ENTRY(SABBREVMONTHNAME5),
123 LOCALE_ENTRY(SABBREVMONTHNAME6),
124 LOCALE_ENTRY(SABBREVMONTHNAME7),
125 LOCALE_ENTRY(SABBREVMONTHNAME8),
126 LOCALE_ENTRY(SABBREVMONTHNAME9),
127 LOCALE_ENTRY(SABBREVMONTHNAME10),
128 LOCALE_ENTRY(SABBREVMONTHNAME11),
129 LOCALE_ENTRY(SABBREVMONTHNAME12),
130 LOCALE_ENTRY(SABBREVMONTHNAME13),
131 LOCALE_ENTRY(SPOSITIVESIGN),
132 LOCALE_ENTRY(SNEGATIVESIGN),
133 LOCALE_ENTRY(IPOSSIGNPOSN),
134 LOCALE_ENTRY(INEGSIGNPOSN),
135 LOCALE_ENTRY(IPOSSYMPRECEDES),
136 LOCALE_ENTRY(IPOSSEPBYSPACE),
137 LOCALE_ENTRY(INEGSYMPRECEDES),
138 LOCALE_ENTRY(INEGSEPBYSPACE),
139 LOCALE_ENTRY(FONTSIGNATURE),
140 LOCALE_ENTRY(SISO639LANGNAME),
141 LOCALE_ENTRY(SISO3166CTRYNAME),
142 {NULL,0}
145 static char *GetLocaleSubkeyName( DWORD lctype );
147 /***********************************************************************
148 * GetUserDefaultLCID (KERNEL32.@)
149 * GetUserDefaultLCID (OLE2NLS.1)
151 LCID WINAPI GetUserDefaultLCID(void)
153 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT );
156 /***********************************************************************
157 * GetSystemDefaultLCID (KERNEL32.@)
158 * GetSystemDefaultLCID (OLE2NLS.2)
160 LCID WINAPI GetSystemDefaultLCID(void)
162 return GetUserDefaultLCID();
165 #define NLS_MAX_LANGUAGES 20
166 typedef struct {
167 char lang[128];
168 char country[128];
169 LANGID found_lang_id[NLS_MAX_LANGUAGES];
170 char found_language[NLS_MAX_LANGUAGES][3];
171 char found_country[NLS_MAX_LANGUAGES][3];
172 int n_found;
173 } LANG_FIND_DATA;
175 static BOOL CALLBACK NLS_FindLanguageID_ProcA(HMODULE hModule, LPCSTR type,
176 LPCSTR name, WORD LangID, LONG lParam)
178 LANG_FIND_DATA *l_data = (LANG_FIND_DATA *)lParam;
179 LCID lcid = MAKELCID(LangID, SORT_DEFAULT);
180 char buf_language[128];
181 char buf_country[128];
182 char buf_en_language[128];
184 TRACE("%04X\n", (UINT)LangID);
185 if(PRIMARYLANGID(LangID) == LANG_NEUTRAL)
186 return TRUE; /* continue search */
188 buf_language[0] = 0;
189 buf_country[0] = 0;
191 GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME|LOCALE_NOUSEROVERRIDE,
192 buf_language, sizeof(buf_language));
193 TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language);
195 GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME|LOCALE_NOUSEROVERRIDE,
196 buf_country, sizeof(buf_country));
197 TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country);
199 if(l_data->lang && strlen(l_data->lang) > 0 && !strcasecmp(l_data->lang, buf_language))
201 if(l_data->country && strlen(l_data->country) > 0)
203 if(!strcasecmp(l_data->country, buf_country))
205 l_data->found_lang_id[0] = LangID;
206 l_data->n_found = 1;
207 TRACE("Found lang_id %04X for %s_%s\n", LangID, l_data->lang, l_data->country);
208 return FALSE; /* stop enumeration */
211 else /* l_data->country not specified */
213 if(l_data->n_found < NLS_MAX_LANGUAGES)
215 l_data->found_lang_id[l_data->n_found] = LangID;
216 strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
217 strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
218 l_data->n_found++;
219 TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
220 return TRUE; /* continue search */
225 /* Just in case, check LOCALE_SENGLANGUAGE too,
226 * in hope that possible alias name might have that value.
228 buf_en_language[0] = 0;
229 GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE|LOCALE_NOUSEROVERRIDE,
230 buf_en_language, sizeof(buf_en_language));
231 TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language);
233 if(l_data->lang && strlen(l_data->lang) > 0 && !strcasecmp(l_data->lang, buf_en_language))
235 l_data->found_lang_id[l_data->n_found] = LangID;
236 strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
237 strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
238 l_data->n_found++;
239 TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
242 return TRUE; /* continue search */
245 /***********************************************************************
246 * NLS_GetLanguageID
248 * INPUT:
249 * Lang: a string whose two first chars are the iso name of a language.
250 * Country: a string whose two first chars are the iso name of country
251 * Charset: a string defining the chossen charset encoding
252 * Dialect: a string defining a variation of the locale
254 * all those values are from the standardized format of locale
255 * name in unix which is: Lang[_Country][.Charset][@Dialect]
257 * RETURNS:
258 * the numeric code of the language used by Windows
260 * FIXME: Charset and Dialect are not handled
262 static LANGID NLS_GetLanguageID(LPCSTR Lang, LPCSTR Country, LPCSTR Charset, LPCSTR Dialect)
264 LANG_FIND_DATA l_data;
265 char lang_string[256];
267 if(!Lang)
269 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
270 goto END;
273 memset(&l_data, 0, sizeof(LANG_FIND_DATA));
274 strncpy(l_data.lang, Lang, sizeof(l_data.lang));
276 if(Country && strlen(Country) > 0)
277 strncpy(l_data.country, Country, sizeof(l_data.country));
279 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
280 (LPCSTR)LOCALE_ILANGUAGE, NLS_FindLanguageID_ProcA, (LONG)&l_data);
282 strcpy(lang_string, l_data.lang);
283 if(l_data.country && strlen(l_data.country) > 0)
285 strcat(lang_string, "_");
286 strcat(lang_string, l_data.country);
289 if(!l_data.n_found)
291 if(l_data.country && strlen(l_data.country) > 0)
293 MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string);
294 l_data.country[0] = 0;
295 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
296 (LPCSTR)LOCALE_ILANGUAGE, NLS_FindLanguageID_ProcA, (LONG)&l_data);
300 /* Re-evaluate lang_string */
301 strcpy(lang_string, l_data.lang);
302 if(l_data.country && strlen(l_data.country) > 0)
304 strcat(lang_string, "_");
305 strcat(lang_string, l_data.country);
308 if(!l_data.n_found)
310 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string);
311 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
313 else
315 if(l_data.n_found == 1)
316 TRACE("For language '%s' lang_id %04X was found\n", lang_string, l_data.found_lang_id[0]);
317 else /* l_data->n_found > 1 */
319 int i;
320 MESSAGE("For language '%s' several language ids were found:\n", lang_string);
321 for(i = 0; i < l_data.n_found; i++)
322 MESSAGE("%s_%s - %04X; ", l_data.found_language[i], l_data.found_country[i], l_data.found_lang_id[i]);
324 MESSAGE("\nInstead of using first in the list, suggest to define\n"
325 "your LANG environment variable like this: LANG=%s_%s\n",
326 l_data.found_language[0], l_data.found_country[0]);
329 END:
330 TRACE("Returning %04X\n", l_data.found_lang_id[0]);
331 return l_data.found_lang_id[0];
334 /***********************************************************************
335 * GetUserDefaultLangID (KERNEL32.@)
336 * GetUserDefaultLangID (OLE2NLS.3)
338 LANGID WINAPI GetUserDefaultLangID(void)
340 /* caching result, if defined from environment, which should (?) not change during a WINE session */
341 static LANGID userLCID = 0;
343 if (userLCID == 0)
345 char buf[256];
346 char *lang,*country,*charset,*dialect,*next;
348 if (GetEnvironmentVariableA( "LANGUAGE", buf, sizeof(buf) )) goto ok;
349 if (GetEnvironmentVariableA( "LANG", buf, sizeof(buf) )) goto ok;
350 if (GetEnvironmentVariableA( "LC_ALL", buf, sizeof(buf) )) goto ok;
351 if (GetEnvironmentVariableA( "LC_MESSAGES", buf, sizeof(buf) )) goto ok;
352 if (GetEnvironmentVariableA( "LC_CTYPE", buf, sizeof(buf) )) goto ok;
354 return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
357 if (!strcmp(buf,"POSIX") || !strcmp(buf,"C"))
358 return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
360 lang=buf;
362 do {
363 next=strchr(lang,':'); if (next) *next++='\0';
364 dialect=strchr(lang,'@'); if (dialect) *dialect++='\0';
365 charset=strchr(lang,'.'); if (charset) *charset++='\0';
366 country=strchr(lang,'_'); if (country) *country++='\0';
368 userLCID = NLS_GetLanguageID(lang, country, charset, dialect);
370 lang=next;
371 } while (lang && !userLCID);
373 if (!userLCID)
375 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
376 buf );
377 userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
380 return userLCID;
383 /***********************************************************************
384 * GetSystemDefaultLangID (KERNEL32.@)
385 * GetSystemDefaultLangID (OLE2NLS.4)
387 LANGID WINAPI GetSystemDefaultLangID(void)
389 return GetUserDefaultLangID();
392 /******************************************************************************
393 * ConvertDefaultLocale (KERNEL32.@)
395 LCID WINAPI ConvertDefaultLocale (LCID lcid)
396 { switch (lcid)
397 { case LOCALE_SYSTEM_DEFAULT:
398 return GetSystemDefaultLCID();
399 case LOCALE_USER_DEFAULT:
400 return GetUserDefaultLCID();
401 case LOCALE_NEUTRAL:
402 return MAKELCID (LANG_NEUTRAL, SUBLANG_NEUTRAL);
404 return MAKELANGID( PRIMARYLANGID(lcid), SUBLANG_NEUTRAL);
407 /* Enhanced version of LoadStringW.
408 * It takes LanguageId to find and load language dependant resources.
409 * Resource is copied as is: "binary" strings are not truncated.
410 * Return: length of resource + 1 to distinguish absent resources
411 * from the resources with zero length.
413 static INT NLS_LoadStringExW(HMODULE hModule, LANGID lang_id, UINT res_id, LPWSTR buffer, INT buflen)
415 HRSRC hrsrc;
416 HGLOBAL hmem;
417 WCHAR *p;
418 int string_num;
419 int i;
421 hrsrc = FindResourceExW(hModule, RT_STRINGW, (LPCWSTR)((res_id >> 4) + 1), lang_id);
423 if(!hrsrc) return 0;
424 hmem = LoadResource(hModule, hrsrc);
425 if(!hmem) return 0;
427 p = LockResource(hmem);
428 string_num = res_id & 0x000f;
429 for(i = 0; i < string_num; i++)
430 p += *p + 1;
432 TRACE("strlen = %d\n", (int)*p );
434 if (buffer == NULL) return *p;
435 i = min(buflen - 1, *p);
436 if (i > 0) {
437 memcpy(buffer, p + 1, i * sizeof (WCHAR));
438 buffer[i] = (WCHAR) 0;
439 } else {
440 if (buflen > 1)
441 buffer[0] = (WCHAR) 0;
444 FreeResource(hmem);
445 TRACE("%s loaded!\n", debugstr_w(buffer));
446 return (i + 1);
449 /******************************************************************************
450 * GetLocaleInfoA (KERNEL32.@)
452 * NOTES
453 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
455 * MS online documentation states that the string returned is NULL terminated
456 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
457 * terminated string".
459 INT WINAPI GetLocaleInfoA(LCID lcid,LCTYPE LCType,LPSTR buf,INT len)
461 LPCSTR retString = NULL;
462 int found = 0, i;
463 char *pacKey;
464 char acBuffer[128];
465 DWORD dwBufferSize=128;
466 BOOL NoUserOverride;
468 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid,LCType,buf,len);
470 if (len && (! buf) ) {
471 SetLastError(ERROR_INSUFFICIENT_BUFFER);
472 return 0;
475 if (lcid == LOCALE_NEUTRAL || lcid == LANG_SYSTEM_DEFAULT)
477 lcid = GetSystemDefaultLCID();
479 else if (lcid == LANG_USER_DEFAULT) /*0x800*/
481 lcid = GetUserDefaultLCID();
484 /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
485 from the registry. Instead, use system default values. */
486 NoUserOverride = (LCType & LOCALE_NOUSEROVERRIDE) != 0;
488 LCType &= ~(LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP);
490 /* First, check if it's in the registry. */
491 /* All user customized values are stored in the registry by SetLocaleInfo */
492 if ( !NoUserOverride && (pacKey = GetLocaleSubkeyName(LCType)) )
494 char acRealKey[128];
495 HKEY hKey;
497 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
499 if ( RegOpenKeyExA( HKEY_CURRENT_USER, acRealKey,
500 0, KEY_READ, &hKey) == ERROR_SUCCESS )
502 if ( RegQueryValueExA( hKey, NULL, NULL, NULL, (LPBYTE)acBuffer,
503 &dwBufferSize ) == ERROR_SUCCESS )
505 retString = acBuffer;
506 found = 1;
508 RegCloseKey(hKey);
512 /* If not in the registry, get it from the NLS entries. */
513 if(!found) {
514 WCHAR wcBuffer[128];
515 int res_size;
517 /* check if language is registered in the kernel32 resources */
518 if((res_size = NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid),
519 LCType, wcBuffer, sizeof(wcBuffer)/sizeof(wcBuffer[0])))) {
520 WideCharToMultiByte(CP_ACP, 0, wcBuffer, res_size, acBuffer, dwBufferSize, NULL, NULL);
521 retString = acBuffer;
522 found = 1;
526 /* if not found report a most descriptive error */
527 if(!found) {
528 retString=0;
529 /* If we are through all of this, retLen should not be zero anymore.
530 If it is, the value is not supported */
531 i=0;
532 while (locale_name2id[i].name!=NULL) {
533 if (LCType == locale_name2id[i].id) {
534 retString = locale_name2id[i].name;
535 break;
537 i++;
539 if(!retString)
540 FIXME("Unkown LC type %lX\n", LCType);
541 else
542 FIXME("'%s' is not defined for your language (%04X).\n"
543 "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
544 "and submit patch for inclusion into the next Wine release.\n",
545 retString, LOWORD(lcid));
546 SetLastError(ERROR_INVALID_PARAMETER);
547 return 0;
550 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
551 if (LCType == LOCALE_FONTSIGNATURE) {
552 if (len) {
553 len = (len < sizeof(FONTSIGNATURE)) ? len : sizeof(FONTSIGNATURE);
554 memcpy(buf, retString, len);
555 return len;
557 return sizeof(FONTSIGNATURE);
559 /* if len=0 return only the length, don't touch the buffer*/
560 if (len) {
561 lstrcpynA(buf,retString,len);
562 return strlen(buf) + 1;
564 return strlen(retString)+1;
567 /******************************************************************************
568 * GetLocaleInfoW (KERNEL32.@)
570 * NOTES
571 * MS documentation states that len "specifies the size, in bytes (ANSI version)
572 * or characters (Unicode version), of" wbuf. Thus the number returned is
573 * the same between GetLocaleInfoW and GetLocaleInfoA.
575 INT WINAPI GetLocaleInfoW(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT len)
576 { WORD wlen;
577 LPSTR abuf;
579 if (len && (! wbuf) )
580 { SetLastError(ERROR_INSUFFICIENT_BUFFER);
581 return 0;
584 abuf = (LPSTR)HeapAlloc(GetProcessHeap(),0,len);
585 wlen = GetLocaleInfoA(lcid, LCType, abuf, len);
587 if (wlen && len) /* if len=0 return only the length*/
588 MultiByteToWideChar( CP_ACP, 0, abuf, -1, wbuf, len );
590 HeapFree(GetProcessHeap(),0,abuf);
591 return wlen;
594 /******************************************************************************
596 * GetLocaleSubkeyName [helper function]
598 * - For use with the registry.
599 * - Gets the registry subkey name for a given lctype.
601 static char *GetLocaleSubkeyName( DWORD lctype )
603 char *pacKey=NULL;
605 switch ( lctype )
607 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
608 * the values are stored in the registry, confirmed under Windows,
609 * for the ones that actually assign pacKey. Cases that aren't finished
610 * have not been confirmed, so that must be done before they can be
611 * added.
613 case LOCALE_SDATE : /* The date separator. */
614 pacKey = "sDate";
615 break;
616 case LOCALE_ICURRDIGITS:
617 pacKey = "iCurrDigits";
618 break;
619 case LOCALE_SDECIMAL :
620 pacKey = "sDecimal";
621 break;
622 case LOCALE_ICURRENCY:
623 pacKey = "iCurrency";
624 break;
625 case LOCALE_SGROUPING :
626 pacKey = "sGrouping";
627 break;
628 case LOCALE_IDIGITS:
629 pacKey = "iDigits";
630 break;
631 case LOCALE_SLIST :
632 pacKey = "sList";
633 break;
634 /* case LOCALE_ICALENDARTYPE: */
635 /* case LOCALE_IFIRSTDAYOFWEEK: */
636 /* case LOCALE_IFIRSTWEEKOFYEAR: */
637 /* case LOCALE_SYEARMONTH : */
638 /* case LOCALE_SPOSITIVESIGN : */
639 /* case LOCALE_IPAPERSIZE: */
640 /* break; */
641 case LOCALE_SLONGDATE :
642 pacKey = "sLongDate";
643 break;
644 case LOCALE_SMONDECIMALSEP :
645 pacKey = "sMonDecimalSep";
646 break;
647 case LOCALE_SMONGROUPING:
648 pacKey = "sMonGrouping";
649 break;
650 case LOCALE_IMEASURE:
651 pacKey = "iMeasure";
652 break;
653 case LOCALE_SMONTHOUSANDSEP :
654 pacKey = "sMonThousandSep";
655 break;
656 case LOCALE_INEGCURR:
657 pacKey = "iNegCurr";
658 break;
659 case LOCALE_SNEGATIVESIGN :
660 pacKey = "sNegativeSign";
661 break;
662 case LOCALE_INEGNUMBER:
663 pacKey = "iNegNumber";
664 break;
665 case LOCALE_SSHORTDATE :
666 pacKey = "sShortDate";
667 break;
668 case LOCALE_ILDATE: /* Long Date format ordering specifier. */
669 pacKey = "iLDate";
670 break;
671 case LOCALE_ILZERO:
672 pacKey = "iLZero";
673 break;
674 case LOCALE_ITLZERO:
675 pacKey = "iTLZero";
676 break;
677 case LOCALE_ITIME: /* Time format specifier. */
678 pacKey = "iTime";
679 break;
680 case LOCALE_STHOUSAND :
681 pacKey = "sThousand";
682 break;
683 case LOCALE_S1159: /* AM */
684 pacKey = "s1159";
685 break;
686 case LOCALE_STIME:
687 pacKey = "sTime";
688 break;
689 case LOCALE_S2359: /* PM */
690 pacKey = "s2359";
691 break;
692 case LOCALE_STIMEFORMAT :
693 pacKey = "sTimeFormat";
694 break;
695 case LOCALE_SCURRENCY:
696 pacKey = "sCurrency";
697 break;
699 /* The following are not listed under MSDN as supported,
700 * but seem to be used and also stored in the registry.
703 case LOCALE_IDATE:
704 pacKey = "iDate";
705 break;
706 case LOCALE_SCOUNTRY:
707 pacKey = "sCountry";
708 break;
709 case LOCALE_ICOUNTRY:
710 pacKey = "iCountry";
711 break;
712 case LOCALE_SLANGUAGE:
713 pacKey = "sLanguage";
714 break;
716 default:
717 break;
720 return( pacKey );
723 /******************************************************************************
724 * SetLocaleInfoA [KERNEL32.656]
726 BOOL WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
728 HKEY hKey;
729 char *pacKey;
730 char acRealKey[128];
732 if ( (pacKey = GetLocaleSubkeyName(lctype)) )
734 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
735 if ( RegCreateKeyA( HKEY_CURRENT_USER, acRealKey,
736 &hKey ) == ERROR_SUCCESS )
738 if ( RegSetValueExA( hKey, NULL, 0, REG_SZ,
739 data, strlen(data)+1 ) != ERROR_SUCCESS )
741 ERR("SetLocaleInfoA: %s did not work\n", pacKey );
743 RegCloseKey( hKey );
746 else
748 FIXME("(%ld,%ld,%s): stub\n",lcid,lctype,data);
750 return TRUE;
753 /******************************************************************************
754 * IsValidLocale [KERNEL32.489]
756 BOOL WINAPI IsValidLocale(LCID lcid,DWORD flags)
758 /* check if language is registered in the kernel32 resources */
759 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW, (LPCWSTR)LOCALE_ILANGUAGE, LOWORD(lcid)))
760 return FALSE;
761 else
762 return TRUE;
765 static BOOL CALLBACK EnumResourceLanguagesProcW(HMODULE hModule, LPCWSTR type,
766 LPCWSTR name, WORD LangID, LONG lParam)
768 CHAR bufA[20];
769 WCHAR bufW[20];
770 LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
771 sprintf(bufA, "%08X", (UINT)LangID);
772 MultiByteToWideChar(CP_ACP, 0, bufA, -1, bufW, sizeof(bufW)/sizeof(bufW[0]));
773 return lpfnLocaleEnum(bufW);
776 /******************************************************************************
777 * EnumSystemLocalesW [KERNEL32.209]
779 BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum,
780 DWORD flags )
782 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
784 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW,
785 (LPCWSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcW,
786 (LONG)lpfnLocaleEnum);
788 return TRUE;
791 static BOOL CALLBACK EnumResourceLanguagesProcA(HMODULE hModule, LPCSTR type,
792 LPCSTR name, WORD LangID, LONG lParam)
794 CHAR bufA[20];
795 LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
796 sprintf(bufA, "%08X", (UINT)LangID);
797 return lpfnLocaleEnum(bufA);
800 /******************************************************************************
801 * EnumSystemLocalesA [KERNEL32.208]
803 BOOL WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum,
804 DWORD flags)
806 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
808 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
809 (LPCSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcA,
810 (LONG)lpfnLocaleEnum);
812 return TRUE;
815 static const unsigned char CT_CType2_LUT[] = {
816 C2_NOTAPPLICABLE, /* - 0 */
817 C2_NOTAPPLICABLE, /* - 1 */
818 C2_NOTAPPLICABLE, /* - 2 */
819 C2_NOTAPPLICABLE, /* - 3 */
820 C2_NOTAPPLICABLE, /* - 4 */
821 C2_NOTAPPLICABLE, /* - 5 */
822 C2_NOTAPPLICABLE, /* - 6 */
823 C2_NOTAPPLICABLE, /* - 7 */
824 C2_NOTAPPLICABLE, /* - 8 */
825 C2_SEGMENTSEPARATOR, /* - 9 */
826 C2_NOTAPPLICABLE, /* - 10 */
827 C2_NOTAPPLICABLE, /* - 11 */
828 C2_NOTAPPLICABLE, /* - 12 */
829 C2_NOTAPPLICABLE, /* - 13 */
830 C2_NOTAPPLICABLE, /* - 14 */
831 C2_NOTAPPLICABLE, /* - 15 */
832 C2_NOTAPPLICABLE, /* - 16 */
833 C2_NOTAPPLICABLE, /* - 17 */
834 C2_NOTAPPLICABLE, /* - 18 */
835 C2_NOTAPPLICABLE, /* - 19 */
836 C2_NOTAPPLICABLE, /* - 20 */
837 C2_NOTAPPLICABLE, /* - 21 */
838 C2_NOTAPPLICABLE, /* - 22 */
839 C2_NOTAPPLICABLE, /* - 23 */
840 C2_NOTAPPLICABLE, /* - 24 */
841 C2_NOTAPPLICABLE, /* - 25 */
842 C2_NOTAPPLICABLE, /* - 26 */
843 C2_NOTAPPLICABLE, /* - 27 */
844 C2_NOTAPPLICABLE, /* - 28 */
845 C2_NOTAPPLICABLE, /* - 29 */
846 C2_NOTAPPLICABLE, /* - 30 */
847 C2_NOTAPPLICABLE, /* - 31 */
848 C2_WHITESPACE, /* - 32 */
849 C2_OTHERNEUTRAL, /* ! - 33 */
850 C2_OTHERNEUTRAL, /* " - 34 */ /* " */
851 C2_EUROPETERMINATOR, /* # - 35 */
852 C2_EUROPETERMINATOR, /* $ - 36 */
853 C2_EUROPETERMINATOR, /* % - 37 */
854 C2_LEFTTORIGHT, /* & - 38 */
855 C2_OTHERNEUTRAL, /* ' - 39 */
856 C2_OTHERNEUTRAL, /* ( - 40 */
857 C2_OTHERNEUTRAL, /* ) - 41 */
858 C2_OTHERNEUTRAL, /* * - 42 */
859 C2_EUROPETERMINATOR, /* + - 43 */
860 C2_COMMONSEPARATOR, /* , - 44 */
861 C2_EUROPETERMINATOR, /* - - 45 */
862 C2_EUROPESEPARATOR, /* . - 46 */
863 C2_EUROPESEPARATOR, /* / - 47 */
864 C2_EUROPENUMBER, /* 0 - 48 */
865 C2_EUROPENUMBER, /* 1 - 49 */
866 C2_EUROPENUMBER, /* 2 - 50 */
867 C2_EUROPENUMBER, /* 3 - 51 */
868 C2_EUROPENUMBER, /* 4 - 52 */
869 C2_EUROPENUMBER, /* 5 - 53 */
870 C2_EUROPENUMBER, /* 6 - 54 */
871 C2_EUROPENUMBER, /* 7 - 55 */
872 C2_EUROPENUMBER, /* 8 - 56 */
873 C2_EUROPENUMBER, /* 9 - 57 */
874 C2_COMMONSEPARATOR, /* : - 58 */
875 C2_OTHERNEUTRAL, /* ; - 59 */
876 C2_OTHERNEUTRAL, /* < - 60 */
877 C2_OTHERNEUTRAL, /* = - 61 */
878 C2_OTHERNEUTRAL, /* > - 62 */
879 C2_OTHERNEUTRAL, /* ? - 63 */
880 C2_LEFTTORIGHT, /* @ - 64 */
881 C2_LEFTTORIGHT, /* A - 65 */
882 C2_LEFTTORIGHT, /* B - 66 */
883 C2_LEFTTORIGHT, /* C - 67 */
884 C2_LEFTTORIGHT, /* D - 68 */
885 C2_LEFTTORIGHT, /* E - 69 */
886 C2_LEFTTORIGHT, /* F - 70 */
887 C2_LEFTTORIGHT, /* G - 71 */
888 C2_LEFTTORIGHT, /* H - 72 */
889 C2_LEFTTORIGHT, /* I - 73 */
890 C2_LEFTTORIGHT, /* J - 74 */
891 C2_LEFTTORIGHT, /* K - 75 */
892 C2_LEFTTORIGHT, /* L - 76 */
893 C2_LEFTTORIGHT, /* M - 77 */
894 C2_LEFTTORIGHT, /* N - 78 */
895 C2_LEFTTORIGHT, /* O - 79 */
896 C2_LEFTTORIGHT, /* P - 80 */
897 C2_LEFTTORIGHT, /* Q - 81 */
898 C2_LEFTTORIGHT, /* R - 82 */
899 C2_LEFTTORIGHT, /* S - 83 */
900 C2_LEFTTORIGHT, /* T - 84 */
901 C2_LEFTTORIGHT, /* U - 85 */
902 C2_LEFTTORIGHT, /* V - 86 */
903 C2_LEFTTORIGHT, /* W - 87 */
904 C2_LEFTTORIGHT, /* X - 88 */
905 C2_LEFTTORIGHT, /* Y - 89 */
906 C2_LEFTTORIGHT, /* Z - 90 */
907 C2_OTHERNEUTRAL, /* [ - 91 */
908 C2_OTHERNEUTRAL, /* \ - 92 */
909 C2_OTHERNEUTRAL, /* ] - 93 */
910 C2_OTHERNEUTRAL, /* ^ - 94 */
911 C2_OTHERNEUTRAL, /* _ - 95 */
912 C2_OTHERNEUTRAL, /* ` - 96 */
913 C2_LEFTTORIGHT, /* a - 97 */
914 C2_LEFTTORIGHT, /* b - 98 */
915 C2_LEFTTORIGHT, /* c - 99 */
916 C2_LEFTTORIGHT, /* d - 100 */
917 C2_LEFTTORIGHT, /* e - 101 */
918 C2_LEFTTORIGHT, /* f - 102 */
919 C2_LEFTTORIGHT, /* g - 103 */
920 C2_LEFTTORIGHT, /* h - 104 */
921 C2_LEFTTORIGHT, /* i - 105 */
922 C2_LEFTTORIGHT, /* j - 106 */
923 C2_LEFTTORIGHT, /* k - 107 */
924 C2_LEFTTORIGHT, /* l - 108 */
925 C2_LEFTTORIGHT, /* m - 109 */
926 C2_LEFTTORIGHT, /* n - 110 */
927 C2_LEFTTORIGHT, /* o - 111 */
928 C2_LEFTTORIGHT, /* p - 112 */
929 C2_LEFTTORIGHT, /* q - 113 */
930 C2_LEFTTORIGHT, /* r - 114 */
931 C2_LEFTTORIGHT, /* s - 115 */
932 C2_LEFTTORIGHT, /* t - 116 */
933 C2_LEFTTORIGHT, /* u - 117 */
934 C2_LEFTTORIGHT, /* v - 118 */
935 C2_LEFTTORIGHT, /* w - 119 */
936 C2_LEFTTORIGHT, /* x - 120 */
937 C2_LEFTTORIGHT, /* y - 121 */
938 C2_LEFTTORIGHT, /* z - 122 */
939 C2_OTHERNEUTRAL, /* { - 123 */
940 C2_OTHERNEUTRAL, /* | - 124 */
941 C2_OTHERNEUTRAL, /* } - 125 */
942 C2_OTHERNEUTRAL, /* ~ - 126 */
943 C2_NOTAPPLICABLE, /* \x7f - 127 */
944 C2_NOTAPPLICABLE, /* € - 128 */
945 C2_NOTAPPLICABLE, /* � - 129 */
946 C2_OTHERNEUTRAL, /* ‚ - 130 */
947 C2_LEFTTORIGHT, /* ƒ - 131 */
948 C2_OTHERNEUTRAL, /* „ - 132 */
949 C2_OTHERNEUTRAL, /* … - 133 */
950 C2_OTHERNEUTRAL, /* † - 134 */
951 C2_OTHERNEUTRAL, /* ‡ - 135 */
952 C2_LEFTTORIGHT, /* ˆ - 136 */
953 C2_EUROPETERMINATOR, /* ‰ - 137 */
954 C2_LEFTTORIGHT, /* Š - 138 */
955 C2_OTHERNEUTRAL, /* ‹ - 139 */
956 C2_LEFTTORIGHT, /* Π- 140 */
957 C2_NOTAPPLICABLE, /* � - 141 */
958 C2_NOTAPPLICABLE, /* Ž - 142 */
959 C2_NOTAPPLICABLE, /* � - 143 */
960 C2_NOTAPPLICABLE, /* � - 144 */
961 C2_OTHERNEUTRAL, /* ‘ - 145 */
962 C2_OTHERNEUTRAL, /* ’ - 146 */
963 C2_OTHERNEUTRAL, /* “ - 147 */
964 C2_OTHERNEUTRAL, /* ” - 148 */
965 C2_OTHERNEUTRAL, /* • - 149 */
966 C2_OTHERNEUTRAL, /* – - 150 */
967 C2_OTHERNEUTRAL, /* — - 151 */
968 C2_LEFTTORIGHT, /* ˜ - 152 */
969 C2_OTHERNEUTRAL, /* ™ - 153 */
970 C2_LEFTTORIGHT, /* š - 154 */
971 C2_OTHERNEUTRAL, /* › - 155 */
972 C2_LEFTTORIGHT, /* œ - 156 */
973 C2_NOTAPPLICABLE, /* � - 157 */
974 C2_NOTAPPLICABLE, /* ž - 158 */
975 C2_LEFTTORIGHT, /* Ÿ - 159 */
976 C2_WHITESPACE, /*   - 160 */
977 C2_OTHERNEUTRAL, /* ¡ - 161 */
978 C2_EUROPETERMINATOR, /* ¢ - 162 */
979 C2_EUROPETERMINATOR, /* £ - 163 */
980 C2_EUROPETERMINATOR, /* ¤ - 164 */
981 C2_EUROPETERMINATOR, /* ¥ - 165 */
982 C2_OTHERNEUTRAL, /* ¦ - 166 */
983 C2_OTHERNEUTRAL, /* § - 167 */
984 C2_OTHERNEUTRAL, /* ¨ - 168 */
985 C2_OTHERNEUTRAL, /* © - 169 */
986 C2_OTHERNEUTRAL, /* ª - 170 */
987 C2_OTHERNEUTRAL, /* « - 171 */
988 C2_OTHERNEUTRAL, /* ¬ - 172 */
989 C2_OTHERNEUTRAL, /* ­ - 173 */
990 C2_OTHERNEUTRAL, /* ® - 174 */
991 C2_OTHERNEUTRAL, /* ¯ - 175 */
992 C2_EUROPETERMINATOR, /* ° - 176 */
993 C2_EUROPETERMINATOR, /* ± - 177 */
994 C2_EUROPENUMBER, /* ² - 178 */
995 C2_EUROPENUMBER, /* ³ - 179 */
996 C2_OTHERNEUTRAL, /* ´ - 180 */
997 C2_OTHERNEUTRAL, /* µ - 181 */
998 C2_OTHERNEUTRAL, /* ¶ - 182 */
999 C2_OTHERNEUTRAL, /* · - 183 */
1000 C2_OTHERNEUTRAL, /* ¸ - 184 */
1001 C2_EUROPENUMBER, /* ¹ - 185 */
1002 C2_OTHERNEUTRAL, /* º - 186 */
1003 C2_OTHERNEUTRAL, /* » - 187 */
1004 C2_OTHERNEUTRAL, /* ¼ - 188 */
1005 C2_OTHERNEUTRAL, /* ½ - 189 */
1006 C2_OTHERNEUTRAL, /* ¾ - 190 */
1007 C2_OTHERNEUTRAL, /* ¿ - 191 */
1008 C2_LEFTTORIGHT, /* À - 192 */
1009 C2_LEFTTORIGHT, /* Á - 193 */
1010 C2_LEFTTORIGHT, /* Â - 194 */
1011 C2_LEFTTORIGHT, /* Ã - 195 */
1012 C2_LEFTTORIGHT, /* Ä - 196 */
1013 C2_LEFTTORIGHT, /* Å - 197 */
1014 C2_LEFTTORIGHT, /* Æ - 198 */
1015 C2_LEFTTORIGHT, /* Ç - 199 */
1016 C2_LEFTTORIGHT, /* È - 200 */
1017 C2_LEFTTORIGHT, /* É - 201 */
1018 C2_LEFTTORIGHT, /* Ê - 202 */
1019 C2_LEFTTORIGHT, /* Ë - 203 */
1020 C2_LEFTTORIGHT, /* Ì - 204 */
1021 C2_LEFTTORIGHT, /* Í - 205 */
1022 C2_LEFTTORIGHT, /* Î - 206 */
1023 C2_LEFTTORIGHT, /* Ï - 207 */
1024 C2_LEFTTORIGHT, /* Ð - 208 */
1025 C2_LEFTTORIGHT, /* Ñ - 209 */
1026 C2_LEFTTORIGHT, /* Ò - 210 */
1027 C2_LEFTTORIGHT, /* Ó - 211 */
1028 C2_LEFTTORIGHT, /* Ô - 212 */
1029 C2_LEFTTORIGHT, /* Õ - 213 */
1030 C2_LEFTTORIGHT, /* Ö - 214 */
1031 C2_OTHERNEUTRAL, /* × - 215 */
1032 C2_LEFTTORIGHT, /* Ø - 216 */
1033 C2_LEFTTORIGHT, /* Ù - 217 */
1034 C2_LEFTTORIGHT, /* Ú - 218 */
1035 C2_LEFTTORIGHT, /* Û - 219 */
1036 C2_LEFTTORIGHT, /* Ü - 220 */
1037 C2_LEFTTORIGHT, /* Ý - 221 */
1038 C2_LEFTTORIGHT, /* Þ - 222 */
1039 C2_LEFTTORIGHT, /* ß - 223 */
1040 C2_LEFTTORIGHT, /* à - 224 */
1041 C2_LEFTTORIGHT, /* á - 225 */
1042 C2_LEFTTORIGHT, /* â - 226 */
1043 C2_LEFTTORIGHT, /* ã - 227 */
1044 C2_LEFTTORIGHT, /* ä - 228 */
1045 C2_LEFTTORIGHT, /* å - 229 */
1046 C2_LEFTTORIGHT, /* æ - 230 */
1047 C2_LEFTTORIGHT, /* ç - 231 */
1048 C2_LEFTTORIGHT, /* è - 232 */
1049 C2_LEFTTORIGHT, /* é - 233 */
1050 C2_LEFTTORIGHT, /* ê - 234 */
1051 C2_LEFTTORIGHT, /* ë - 235 */
1052 C2_LEFTTORIGHT, /* ì - 236 */
1053 C2_LEFTTORIGHT, /* í - 237 */
1054 C2_LEFTTORIGHT, /* î - 238 */
1055 C2_LEFTTORIGHT, /* ï - 239 */
1056 C2_LEFTTORIGHT, /* ð - 240 */
1057 C2_LEFTTORIGHT, /* ñ - 241 */
1058 C2_LEFTTORIGHT, /* ò - 242 */
1059 C2_LEFTTORIGHT, /* ó - 243 */
1060 C2_LEFTTORIGHT, /* ô - 244 */
1061 C2_LEFTTORIGHT, /* õ - 245 */
1062 C2_LEFTTORIGHT, /* ö - 246 */
1063 C2_OTHERNEUTRAL, /* ÷ - 247 */
1064 C2_LEFTTORIGHT, /* ø - 248 */
1065 C2_LEFTTORIGHT, /* ù - 249 */
1066 C2_LEFTTORIGHT, /* ú - 250 */
1067 C2_LEFTTORIGHT, /* û - 251 */
1068 C2_LEFTTORIGHT, /* ü - 252 */
1069 C2_LEFTTORIGHT, /* ý - 253 */
1070 C2_LEFTTORIGHT, /* þ - 254 */
1071 C2_LEFTTORIGHT /* ÿ - 255 */
1074 const WORD OLE2NLS_CT_CType3_LUT[] = {
1075 0x0000, /* - 0 */
1076 0x0000, /* - 1 */
1077 0x0000, /* - 2 */
1078 0x0000, /* - 3 */
1079 0x0000, /* - 4 */
1080 0x0000, /* - 5 */
1081 0x0000, /* - 6 */
1082 0x0000, /* - 7 */
1083 0x0000, /* - 8 */
1084 0x0008, /* - 9 */
1085 0x0008, /* - 10 */
1086 0x0008, /* - 11 */
1087 0x0008, /* - 12 */
1088 0x0008, /* - 13 */
1089 0x0000, /* - 14 */
1090 0x0000, /* - 15 */
1091 0x0000, /* - 16 */
1092 0x0000, /* - 17 */
1093 0x0000, /* - 18 */
1094 0x0000, /* - 19 */
1095 0x0000, /* - 20 */
1096 0x0000, /* - 21 */
1097 0x0000, /* - 22 */
1098 0x0000, /* - 23 */
1099 0x0000, /* - 24 */
1100 0x0000, /* - 25 */
1101 0x0000, /* - 26 */
1102 0x0000, /* - 27 */
1103 0x0000, /* - 28 */
1104 0x0000, /* - 29 */
1105 0x0000, /* - 30 */
1106 0x0000, /* - 31 */
1107 0x0048, /* - 32 */
1108 0x0048, /* ! - 33 */
1109 0x0448, /* " - 34 */ /* " */
1110 0x0048, /* # - 35 */
1111 0x0448, /* $ - 36 */
1112 0x0048, /* % - 37 */
1113 0x0048, /* & - 38 */
1114 0x0440, /* ' - 39 */
1115 0x0048, /* ( - 40 */
1116 0x0048, /* ) - 41 */
1117 0x0048, /* * - 42 */
1118 0x0048, /* + - 43 */
1119 0x0048, /* , - 44 */
1120 0x0440, /* - - 45 */
1121 0x0048, /* . - 46 */
1122 0x0448, /* / - 47 */
1123 0x0040, /* 0 - 48 */
1124 0x0040, /* 1 - 49 */
1125 0x0040, /* 2 - 50 */
1126 0x0040, /* 3 - 51 */
1127 0x0040, /* 4 - 52 */
1128 0x0040, /* 5 - 53 */
1129 0x0040, /* 6 - 54 */
1130 0x0040, /* 7 - 55 */
1131 0x0040, /* 8 - 56 */
1132 0x0040, /* 9 - 57 */
1133 0x0048, /* : - 58 */
1134 0x0048, /* ; - 59 */
1135 0x0048, /* < - 60 */
1136 0x0448, /* = - 61 */
1137 0x0048, /* > - 62 */
1138 0x0048, /* ? - 63 */
1139 0x0448, /* @ - 64 */
1140 0x8040, /* A - 65 */
1141 0x8040, /* B - 66 */
1142 0x8040, /* C - 67 */
1143 0x8040, /* D - 68 */
1144 0x8040, /* E - 69 */
1145 0x8040, /* F - 70 */
1146 0x8040, /* G - 71 */
1147 0x8040, /* H - 72 */
1148 0x8040, /* I - 73 */
1149 0x8040, /* J - 74 */
1150 0x8040, /* K - 75 */
1151 0x8040, /* L - 76 */
1152 0x8040, /* M - 77 */
1153 0x8040, /* N - 78 */
1154 0x8040, /* O - 79 */
1155 0x8040, /* P - 80 */
1156 0x8040, /* Q - 81 */
1157 0x8040, /* R - 82 */
1158 0x8040, /* S - 83 */
1159 0x8040, /* T - 84 */
1160 0x8040, /* U - 85 */
1161 0x8040, /* V - 86 */
1162 0x8040, /* W - 87 */
1163 0x8040, /* X - 88 */
1164 0x8040, /* Y - 89 */
1165 0x8040, /* Z - 90 */
1166 0x0048, /* [ - 91 */
1167 0x0448, /* \ - 92 */
1168 0x0048, /* ] - 93 */
1169 0x0448, /* ^ - 94 */
1170 0x0448, /* _ - 95 */
1171 0x0448, /* ` - 96 */
1172 0x8040, /* a - 97 */
1173 0x8040, /* b - 98 */
1174 0x8040, /* c - 99 */
1175 0x8040, /* d - 100 */
1176 0x8040, /* e - 101 */
1177 0x8040, /* f - 102 */
1178 0x8040, /* g - 103 */
1179 0x8040, /* h - 104 */
1180 0x8040, /* i - 105 */
1181 0x8040, /* j - 106 */
1182 0x8040, /* k - 107 */
1183 0x8040, /* l - 108 */
1184 0x8040, /* m - 109 */
1185 0x8040, /* n - 110 */
1186 0x8040, /* o - 111 */
1187 0x8040, /* p - 112 */
1188 0x8040, /* q - 113 */
1189 0x8040, /* r - 114 */
1190 0x8040, /* s - 115 */
1191 0x8040, /* t - 116 */
1192 0x8040, /* u - 117 */
1193 0x8040, /* v - 118 */
1194 0x8040, /* w - 119 */
1195 0x8040, /* x - 120 */
1196 0x8040, /* y - 121 */
1197 0x8040, /* z - 122 */
1198 0x0048, /* { - 123 */
1199 0x0048, /* | - 124 */
1200 0x0048, /* } - 125 */
1201 0x0448, /* ~ - 126 */
1202 0x0000, /* \x7f - 127 */
1203 0x0000, /* € - 128 */
1204 0x0000, /* � - 129 */
1205 0x0008, /* ‚ - 130 */
1206 0x8000, /* ƒ - 131 */
1207 0x0008, /* „ - 132 */
1208 0x0008, /* … - 133 */
1209 0x0008, /* † - 134 */
1210 0x0008, /* ‡ - 135 */
1211 0x0001, /* ˆ - 136 */
1212 0x0008, /* ‰ - 137 */
1213 0x8003, /* Š - 138 */
1214 0x0008, /* ‹ - 139 */
1215 0x8000, /* Π- 140 */
1216 0x0000, /* � - 141 */
1217 0x0000, /* Ž - 142 */
1218 0x0000, /* � - 143 */
1219 0x0000, /* � - 144 */
1220 0x0088, /* ‘ - 145 */
1221 0x0088, /* ’ - 146 */
1222 0x0088, /* “ - 147 */
1223 0x0088, /* ” - 148 */
1224 0x0008, /* • - 149 */
1225 0x0400, /* – - 150 */
1226 0x0400, /* — - 151 */
1227 0x0408, /* ˜ - 152 */
1228 0x0000, /* ™ - 153 */
1229 0x8003, /* š - 154 */
1230 0x0008, /* › - 155 */
1231 0x8000, /* œ - 156 */
1232 0x0000, /* � - 157 */
1233 0x0000, /* ž - 158 */
1234 0x8003, /* Ÿ - 159 */
1235 0x0008, /*   - 160 */
1236 0x0008, /* ¡ - 161 */
1237 0x0048, /* ¢ - 162 */
1238 0x0048, /* £ - 163 */
1239 0x0008, /* ¤ - 164 */
1240 0x0048, /* ¥ - 165 */
1241 0x0048, /* ¦ - 166 */
1242 0x0008, /* § - 167 */
1243 0x0408, /* ¨ - 168 */
1244 0x0008, /* © - 169 */
1245 0x0400, /* ª - 170 */
1246 0x0008, /* « - 171 */
1247 0x0048, /* ¬ - 172 */
1248 0x0408, /* ­ - 173 */
1249 0x0008, /* ® - 174 */
1250 0x0448, /* ¯ - 175 */
1251 0x0008, /* ° - 176 */
1252 0x0008, /* ± - 177 */
1253 0x0000, /* ² - 178 */
1254 0x0000, /* ³ - 179 */
1255 0x0408, /* ´ - 180 */
1256 0x0008, /* µ - 181 */
1257 0x0008, /* ¶ - 182 */
1258 0x0008, /* · - 183 */
1259 0x0408, /* ¸ - 184 */
1260 0x0000, /* ¹ - 185 */
1261 0x0400, /* º - 186 */
1262 0x0008, /* » - 187 */
1263 0x0000, /* ¼ - 188 */
1264 0x0000, /* ½ - 189 */
1265 0x0000, /* ¾ - 190 */
1266 0x0008, /* ¿ - 191 */
1267 0x8003, /* À - 192 */
1268 0x8003, /* Á - 193 */
1269 0x8003, /* Â - 194 */
1270 0x8003, /* Ã - 195 */
1271 0x8003, /* Ä - 196 */
1272 0x8003, /* Å - 197 */
1273 0x8000, /* Æ - 198 */
1274 0x8003, /* Ç - 199 */
1275 0x8003, /* È - 200 */
1276 0x8003, /* É - 201 */
1277 0x8003, /* Ê - 202 */
1278 0x8003, /* Ë - 203 */
1279 0x8003, /* Ì - 204 */
1280 0x8003, /* Í - 205 */
1281 0x8003, /* Î - 206 */
1282 0x8003, /* Ï - 207 */
1283 0x8000, /* Ð - 208 */
1284 0x8003, /* Ñ - 209 */
1285 0x8003, /* Ò - 210 */
1286 0x8003, /* Ó - 211 */
1287 0x8003, /* Ô - 212 */
1288 0x8003, /* Õ - 213 */
1289 0x8003, /* Ö - 214 */
1290 0x0008, /* × - 215 */
1291 0x8003, /* Ø - 216 */
1292 0x8003, /* Ù - 217 */
1293 0x8003, /* Ú - 218 */
1294 0x8003, /* Û - 219 */
1295 0x8003, /* Ü - 220 */
1296 0x8003, /* Ý - 221 */
1297 0x8000, /* Þ - 222 */
1298 0x8000, /* ß - 223 */
1299 0x8003, /* à - 224 */
1300 0x8003, /* á - 225 */
1301 0x8003, /* â - 226 */
1302 0x8003, /* ã - 227 */
1303 0x8003, /* ä - 228 */
1304 0x8003, /* å - 229 */
1305 0x8000, /* æ - 230 */
1306 0x8003, /* ç - 231 */
1307 0x8003, /* è - 232 */
1308 0x8003, /* é - 233 */
1309 0x8003, /* ê - 234 */
1310 0x8003, /* ë - 235 */
1311 0x8003, /* ì - 236 */
1312 0x8003, /* í - 237 */
1313 0x8003, /* î - 238 */
1314 0x8003, /* ï - 239 */
1315 0x8000, /* ð - 240 */
1316 0x8003, /* ñ - 241 */
1317 0x8003, /* ò - 242 */
1318 0x8003, /* ó - 243 */
1319 0x8003, /* ô - 244 */
1320 0x8003, /* õ - 245 */
1321 0x8003, /* ö - 246 */
1322 0x0008, /* ÷ - 247 */
1323 0x8003, /* ø - 248 */
1324 0x8003, /* ù - 249 */
1325 0x8003, /* ú - 250 */
1326 0x8003, /* û - 251 */
1327 0x8003, /* ü - 252 */
1328 0x8003, /* ý - 253 */
1329 0x8000, /* þ - 254 */
1330 0x8003 /* ÿ - 255 */
1333 /******************************************************************************
1334 * GetStringTypeA [KERNEL32.396]
1336 BOOL WINAPI GetStringTypeA(LCID locale,DWORD dwInfoType,LPCSTR src,
1337 INT cchSrc,LPWORD chartype)
1339 return GetStringTypeExA(locale,dwInfoType,src,cchSrc,chartype);
1342 /******************************************************************************
1343 * GetStringTypeExA [KERNEL32.397]
1345 * FIXME: Ignores the locale.
1347 BOOL WINAPI GetStringTypeExA(LCID locale,DWORD dwInfoType,LPCSTR src,
1348 INT cchSrc,LPWORD chartype)
1350 int i;
1352 if ((src==NULL) || (chartype==NULL) || (src==(LPSTR)chartype))
1354 SetLastError(ERROR_INVALID_PARAMETER);
1355 return FALSE;
1358 if (cchSrc==-1)
1359 cchSrc=strlen(src)+1;
1361 switch (dwInfoType) {
1362 case CT_CTYPE1:
1363 for (i=0;i<cchSrc;i++)
1365 chartype[i] = 0;
1366 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1367 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1368 if (islower(src[i])) chartype[i]|=C1_LOWER;
1369 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1370 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1371 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1372 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1373 /* FIXME: isblank() is a GNU extension */
1374 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1375 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1376 /* C1_XDIGIT */
1378 return TRUE;
1380 case CT_CTYPE2:
1381 for (i=0;i<cchSrc;i++)
1383 chartype[i]=(WORD)CT_CType2_LUT[i];
1385 return TRUE;
1387 case CT_CTYPE3:
1388 for (i=0;i<cchSrc;i++)
1390 chartype[i]=OLE2NLS_CT_CType3_LUT[i];
1392 return TRUE;
1394 default:
1395 ERR("Unknown dwInfoType:%ld\n",dwInfoType);
1396 return FALSE;
1400 /***********************************************************************
1401 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1403 DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
1405 if(!szLang)
1406 return 0;
1408 return GetLocaleInfoA(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
1411 /***********************************************************************
1412 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1414 DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
1416 if(!szLang)
1417 return 0;
1419 return GetLocaleInfoW(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
1423 static const unsigned char LCM_Unicode_LUT[] = {
1424 6 , 3, /* - 1 */
1425 6 , 4, /* - 2 */
1426 6 , 5, /* - 3 */
1427 6 , 6, /* - 4 */
1428 6 , 7, /* - 5 */
1429 6 , 8, /* - 6 */
1430 6 , 9, /* - 7 */
1431 6 , 10, /* - 8 */
1432 7 , 5, /* - 9 */
1433 7 , 6, /* - 10 */
1434 7 , 7, /* - 11 */
1435 7 , 8, /* - 12 */
1436 7 , 9, /* - 13 */
1437 6 , 11, /* - 14 */
1438 6 , 12, /* - 15 */
1439 6 , 13, /* - 16 */
1440 6 , 14, /* - 17 */
1441 6 , 15, /* - 18 */
1442 6 , 16, /* - 19 */
1443 6 , 17, /* - 20 */
1444 6 , 18, /* - 21 */
1445 6 , 19, /* - 22 */
1446 6 , 20, /* - 23 */
1447 6 , 21, /* - 24 */
1448 6 , 22, /* - 25 */
1449 6 , 23, /* - 26 */
1450 6 , 24, /* - 27 */
1451 6 , 25, /* - 28 */
1452 6 , 26, /* - 29 */
1453 6 , 27, /* - 30 */
1454 6 , 28, /* - 31 */
1455 7 , 2, /* - 32 */
1456 7 , 28, /* ! - 33 */
1457 7 , 29, /* " - 34 */ /* " */
1458 7 , 31, /* # - 35 */
1459 7 , 33, /* $ - 36 */
1460 7 , 35, /* % - 37 */
1461 7 , 37, /* & - 38 */
1462 6 , 128, /* ' - 39 */
1463 7 , 39, /* ( - 40 */
1464 7 , 42, /* ) - 41 */
1465 7 , 45, /* * - 42 */
1466 8 , 3, /* + - 43 */
1467 7 , 47, /* , - 44 */
1468 6 , 130, /* - - 45 */
1469 7 , 51, /* . - 46 */
1470 7 , 53, /* / - 47 */
1471 12 , 3, /* 0 - 48 */
1472 12 , 33, /* 1 - 49 */
1473 12 , 51, /* 2 - 50 */
1474 12 , 70, /* 3 - 51 */
1475 12 , 88, /* 4 - 52 */
1476 12 , 106, /* 5 - 53 */
1477 12 , 125, /* 6 - 54 */
1478 12 , 144, /* 7 - 55 */
1479 12 , 162, /* 8 - 56 */
1480 12 , 180, /* 9 - 57 */
1481 7 , 55, /* : - 58 */
1482 7 , 58, /* ; - 59 */
1483 8 , 14, /* < - 60 */
1484 8 , 18, /* = - 61 */
1485 8 , 20, /* > - 62 */
1486 7 , 60, /* ? - 63 */
1487 7 , 62, /* @ - 64 */
1488 14 , 2, /* A - 65 */
1489 14 , 9, /* B - 66 */
1490 14 , 10, /* C - 67 */
1491 14 , 26, /* D - 68 */
1492 14 , 33, /* E - 69 */
1493 14 , 35, /* F - 70 */
1494 14 , 37, /* G - 71 */
1495 14 , 44, /* H - 72 */
1496 14 , 50, /* I - 73 */
1497 14 , 53, /* J - 74 */
1498 14 , 54, /* K - 75 */
1499 14 , 72, /* L - 76 */
1500 14 , 81, /* M - 77 */
1501 14 , 112, /* N - 78 */
1502 14 , 124, /* O - 79 */
1503 14 , 126, /* P - 80 */
1504 14 , 137, /* Q - 81 */
1505 14 , 138, /* R - 82 */
1506 14 , 145, /* S - 83 */
1507 14 , 153, /* T - 84 */
1508 14 , 159, /* U - 85 */
1509 14 , 162, /* V - 86 */
1510 14 , 164, /* W - 87 */
1511 14 , 166, /* X - 88 */
1512 14 , 167, /* Y - 89 */
1513 14 , 169, /* Z - 90 */
1514 7 , 63, /* [ - 91 */
1515 7 , 65, /* \ - 92 */
1516 7 , 66, /* ] - 93 */
1517 7 , 67, /* ^ - 94 */
1518 7 , 68, /* _ - 95 */
1519 7 , 72, /* ` - 96 */
1520 14 , 2, /* a - 97 */
1521 14 , 9, /* b - 98 */
1522 14 , 10, /* c - 99 */
1523 14 , 26, /* d - 100 */
1524 14 , 33, /* e - 101 */
1525 14 , 35, /* f - 102 */
1526 14 , 37, /* g - 103 */
1527 14 , 44, /* h - 104 */
1528 14 , 50, /* i - 105 */
1529 14 , 53, /* j - 106 */
1530 14 , 54, /* k - 107 */
1531 14 , 72, /* l - 108 */
1532 14 , 81, /* m - 109 */
1533 14 , 112, /* n - 110 */
1534 14 , 124, /* o - 111 */
1535 14 , 126, /* p - 112 */
1536 14 , 137, /* q - 113 */
1537 14 , 138, /* r - 114 */
1538 14 , 145, /* s - 115 */
1539 14 , 153, /* t - 116 */
1540 14 , 159, /* u - 117 */
1541 14 , 162, /* v - 118 */
1542 14 , 164, /* w - 119 */
1543 14 , 166, /* x - 120 */
1544 14 , 167, /* y - 121 */
1545 14 , 169, /* z - 122 */
1546 7 , 74, /* { - 123 */
1547 7 , 76, /* | - 124 */
1548 7 , 78, /* } - 125 */
1549 7 , 80, /* ~ - 126 */
1550 6 , 29, /* \x7f - 127 */
1551 6 , 30, /* € - 128 */
1552 6 , 31, /* � - 129 */
1553 7 , 123, /* ‚ - 130 */
1554 14 , 35, /* ƒ - 131 */
1555 7 , 127, /* „ - 132 */
1556 10 , 21, /* … - 133 */
1557 10 , 15, /* † - 134 */
1558 10 , 16, /* ‡ - 135 */
1559 7 , 67, /* ˆ - 136 */
1560 10 , 22, /* ‰ - 137 */
1561 14 , 145, /* Š - 138 */
1562 7 , 136, /* ‹ - 139 */
1563 14 + 16 , 124, /* Π- 140 */
1564 6 , 43, /* � - 141 */
1565 6 , 44, /* Ž - 142 */
1566 6 , 45, /* � - 143 */
1567 6 , 46, /* � - 144 */
1568 7 , 121, /* ‘ - 145 */
1569 7 , 122, /* ’ - 146 */
1570 7 , 125, /* “ - 147 */
1571 7 , 126, /* ” - 148 */
1572 10 , 17, /* • - 149 */
1573 6 , 137, /* – - 150 */
1574 6 , 139, /* — - 151 */
1575 7 , 93, /* ˜ - 152 */
1576 14 , 156, /* ™ - 153 */
1577 14 , 145, /* š - 154 */
1578 7 , 137, /* › - 155 */
1579 14 + 16 , 124, /* œ - 156 */
1580 6 , 59, /* � - 157 */
1581 6 , 60, /* ž - 158 */
1582 14 , 167, /* Ÿ - 159 */
1583 7 , 4, /*   - 160 */
1584 7 , 81, /* ¡ - 161 */
1585 10 , 2, /* ¢ - 162 */
1586 10 , 3, /* £ - 163 */
1587 10 , 4, /* ¤ - 164 */
1588 10 , 5, /* ¥ - 165 */
1589 7 , 82, /* ¦ - 166 */
1590 10 , 6, /* § - 167 */
1591 7 , 83, /* ¨ - 168 */
1592 10 , 7, /* © - 169 */
1593 14 , 2, /* ª - 170 */
1594 8 , 24, /* « - 171 */
1595 10 , 8, /* ¬ - 172 */
1596 6 , 131, /* ­ - 173 */
1597 10 , 9, /* ® - 174 */
1598 7 , 84, /* ¯ - 175 */
1599 10 , 10, /* ° - 176 */
1600 8 , 23, /* ± - 177 */
1601 12 , 51, /* ² - 178 */
1602 12 , 70, /* ³ - 179 */
1603 7 , 85, /* ´ - 180 */
1604 10 , 11, /* µ - 181 */
1605 10 , 12, /* ¶ - 182 */
1606 10 , 13, /* · - 183 */
1607 7 , 86, /* ¸ - 184 */
1608 12 , 33, /* ¹ - 185 */
1609 14 , 124, /* º - 186 */
1610 8 , 26, /* » - 187 */
1611 12 , 21, /* ¼ - 188 */
1612 12 , 25, /* ½ - 189 */
1613 12 , 29, /* ¾ - 190 */
1614 7 , 87, /* ¿ - 191 */
1615 14 , 2, /* À - 192 */
1616 14 , 2, /* Á - 193 */
1617 14 , 2, /* Â - 194 */
1618 14 , 2, /* Ã - 195 */
1619 14 , 2, /* Ä - 196 */
1620 14 , 2, /* Å - 197 */
1621 14 + 16 , 2, /* Æ - 198 */
1622 14 , 10, /* Ç - 199 */
1623 14 , 33, /* È - 200 */
1624 14 , 33, /* É - 201 */
1625 14 , 33, /* Ê - 202 */
1626 14 , 33, /* Ë - 203 */
1627 14 , 50, /* Ì - 204 */
1628 14 , 50, /* Í - 205 */
1629 14 , 50, /* Î - 206 */
1630 14 , 50, /* Ï - 207 */
1631 14 , 26, /* Ð - 208 */
1632 14 , 112, /* Ñ - 209 */
1633 14 , 124, /* Ò - 210 */
1634 14 , 124, /* Ó - 211 */
1635 14 , 124, /* Ô - 212 */
1636 14 , 124, /* Õ - 213 */
1637 14 , 124, /* Ö - 214 */
1638 8 , 28, /* × - 215 */
1639 14 , 124, /* Ø - 216 */
1640 14 , 159, /* Ù - 217 */
1641 14 , 159, /* Ú - 218 */
1642 14 , 159, /* Û - 219 */
1643 14 , 159, /* Ü - 220 */
1644 14 , 167, /* Ý - 221 */
1645 14 + 32 , 153, /* Þ - 222 */
1646 14 + 48 , 145, /* ß - 223 */
1647 14 , 2, /* à - 224 */
1648 14 , 2, /* á - 225 */
1649 14 , 2, /* â - 226 */
1650 14 , 2, /* ã - 227 */
1651 14 , 2, /* ä - 228 */
1652 14 , 2, /* å - 229 */
1653 14 + 16 , 2, /* æ - 230 */
1654 14 , 10, /* ç - 231 */
1655 14 , 33, /* è - 232 */
1656 14 , 33, /* é - 233 */
1657 14 , 33, /* ê - 234 */
1658 14 , 33, /* ë - 235 */
1659 14 , 50, /* ì - 236 */
1660 14 , 50, /* í - 237 */
1661 14 , 50, /* î - 238 */
1662 14 , 50, /* ï - 239 */
1663 14 , 26, /* ð - 240 */
1664 14 , 112, /* ñ - 241 */
1665 14 , 124, /* ò - 242 */
1666 14 , 124, /* ó - 243 */
1667 14 , 124, /* ô - 244 */
1668 14 , 124, /* õ - 245 */
1669 14 , 124, /* ö - 246 */
1670 8 , 29, /* ÷ - 247 */
1671 14 , 124, /* ø - 248 */
1672 14 , 159, /* ù - 249 */
1673 14 , 159, /* ú - 250 */
1674 14 , 159, /* û - 251 */
1675 14 , 159, /* ü - 252 */
1676 14 , 167, /* ý - 253 */
1677 14 + 32 , 153, /* þ - 254 */
1678 14 , 167 /* ÿ - 255 */ };
1680 static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
1682 #define LCM_Diacritic_Start 131
1684 static const unsigned char LCM_Diacritic_LUT[] = {
1685 123, /* ƒ - 131 */
1686 2, /* „ - 132 */
1687 2, /* … - 133 */
1688 2, /* † - 134 */
1689 2, /* ‡ - 135 */
1690 3, /* ˆ - 136 */
1691 2, /* ‰ - 137 */
1692 20, /* Š - 138 */
1693 2, /* ‹ - 139 */
1694 2, /* Π- 140 */
1695 2, /* � - 141 */
1696 2, /* Ž - 142 */
1697 2, /* � - 143 */
1698 2, /* � - 144 */
1699 2, /* ‘ - 145 */
1700 2, /* ’ - 146 */
1701 2, /* “ - 147 */
1702 2, /* ” - 148 */
1703 2, /* • - 149 */
1704 2, /* – - 150 */
1705 2, /* — - 151 */
1706 2, /* ˜ - 152 */
1707 2, /* ™ - 153 */
1708 20, /* š - 154 */
1709 2, /* › - 155 */
1710 2, /* œ - 156 */
1711 2, /* � - 157 */
1712 2, /* ž - 158 */
1713 19, /* Ÿ - 159 */
1714 2, /*   - 160 */
1715 2, /* ¡ - 161 */
1716 2, /* ¢ - 162 */
1717 2, /* £ - 163 */
1718 2, /* ¤ - 164 */
1719 2, /* ¥ - 165 */
1720 2, /* ¦ - 166 */
1721 2, /* § - 167 */
1722 2, /* ¨ - 168 */
1723 2, /* © - 169 */
1724 3, /* ª - 170 */
1725 2, /* « - 171 */
1726 2, /* ¬ - 172 */
1727 2, /* ­ - 173 */
1728 2, /* ® - 174 */
1729 2, /* ¯ - 175 */
1730 2, /* ° - 176 */
1731 2, /* ± - 177 */
1732 2, /* ² - 178 */
1733 2, /* ³ - 179 */
1734 2, /* ´ - 180 */
1735 2, /* µ - 181 */
1736 2, /* ¶ - 182 */
1737 2, /* · - 183 */
1738 2, /* ¸ - 184 */
1739 2, /* ¹ - 185 */
1740 3, /* º - 186 */
1741 2, /* » - 187 */
1742 2, /* ¼ - 188 */
1743 2, /* ½ - 189 */
1744 2, /* ¾ - 190 */
1745 2, /* ¿ - 191 */
1746 15, /* À - 192 */
1747 14, /* Á - 193 */
1748 18, /* Â - 194 */
1749 25, /* Ã - 195 */
1750 19, /* Ä - 196 */
1751 26, /* Å - 197 */
1752 2, /* Æ - 198 */
1753 28, /* Ç - 199 */
1754 15, /* È - 200 */
1755 14, /* É - 201 */
1756 18, /* Ê - 202 */
1757 19, /* Ë - 203 */
1758 15, /* Ì - 204 */
1759 14, /* Í - 205 */
1760 18, /* Î - 206 */
1761 19, /* Ï - 207 */
1762 104, /* Ð - 208 */
1763 25, /* Ñ - 209 */
1764 15, /* Ò - 210 */
1765 14, /* Ó - 211 */
1766 18, /* Ô - 212 */
1767 25, /* Õ - 213 */
1768 19, /* Ö - 214 */
1769 2, /* × - 215 */
1770 33, /* Ø - 216 */
1771 15, /* Ù - 217 */
1772 14, /* Ú - 218 */
1773 18, /* Û - 219 */
1774 19, /* Ü - 220 */
1775 14, /* Ý - 221 */
1776 2, /* Þ - 222 */
1777 2, /* ß - 223 */
1778 15, /* à - 224 */
1779 14, /* á - 225 */
1780 18, /* â - 226 */
1781 25, /* ã - 227 */
1782 19, /* ä - 228 */
1783 26, /* å - 229 */
1784 2, /* æ - 230 */
1785 28, /* ç - 231 */
1786 15, /* è - 232 */
1787 14, /* é - 233 */
1788 18, /* ê - 234 */
1789 19, /* ë - 235 */
1790 15, /* ì - 236 */
1791 14, /* í - 237 */
1792 18, /* î - 238 */
1793 19, /* ï - 239 */
1794 104, /* ð - 240 */
1795 25, /* ñ - 241 */
1796 15, /* ò - 242 */
1797 14, /* ó - 243 */
1798 18, /* ô - 244 */
1799 25, /* õ - 245 */
1800 19, /* ö - 246 */
1801 2, /* ÷ - 247 */
1802 33, /* ø - 248 */
1803 15, /* ù - 249 */
1804 14, /* ú - 250 */
1805 18, /* û - 251 */
1806 19, /* ü - 252 */
1807 14, /* ý - 253 */
1808 2, /* þ - 254 */
1809 19, /* ÿ - 255 */
1812 /******************************************************************************
1813 * OLE2NLS_isPunctuation [INTERNAL]
1815 static int OLE2NLS_isPunctuation(unsigned char c)
1817 /* "punctuation character" in this context is a character which is
1818 considered "less important" during word sort comparison.
1819 See LCMapString implementation for the precise definition
1820 of "less important". */
1822 return (LCM_Unicode_LUT[-2+2*c]==6);
1825 /******************************************************************************
1826 * OLE2NLS_isNonSpacing [INTERNAL]
1828 static int OLE2NLS_isNonSpacing(unsigned char c)
1830 /* This function is used by LCMapStringA. Characters
1831 for which it returns true are ignored when mapping a
1832 string with NORM_IGNORENONSPACE */
1833 return ((c==136) || (c==170) || (c==186));
1836 /******************************************************************************
1837 * OLE2NLS_isSymbol [INTERNAL]
1839 static int OLE2NLS_isSymbol(unsigned char c)
1841 /* This function is used by LCMapStringA. Characters
1842 for which it returns true are ignored when mapping a
1843 string with NORM_IGNORESYMBOLS */
1844 return ( (c!=0) && !IsCharAlphaNumericA(c) );
1847 /******************************************************************************
1848 * identity [Internal]
1850 static int identity(int c)
1852 return c;
1855 /*************************************************************************
1856 * LCMapStringA [KERNEL32.492]
1858 * Convert a string, or generate a sort key from it.
1860 * If (mapflags & LCMAP_SORTKEY), the function will generate
1861 * a sort key for the source string. Else, it will convert it
1862 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1864 * RETURNS
1865 * Error : 0.
1866 * Success : length of the result string.
1868 * NOTES
1869 * If called with scrlen = -1, the function will compute the length
1870 * of the 0-terminated string strsrc by itself.
1872 * If called with dstlen = 0, returns the buffer length that
1873 * would be required.
1875 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1876 * as if they are equal.
1877 * In the only code page implemented so far, there may not be
1878 * wide characters in strings passed to LCMapStringA,
1879 * so there is nothing to be done for this flag.
1881 INT WINAPI LCMapStringA(
1882 LCID lcid, /* [in] locale identifier created with MAKELCID;
1883 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1884 predefined values. */
1885 DWORD mapflags, /* [in] flags */
1886 LPCSTR srcstr, /* [in] source buffer */
1887 INT srclen, /* [in] source length */
1888 LPSTR dststr, /* [out] destination buffer */
1889 INT dstlen) /* [in] destination buffer length */
1891 int i;
1893 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1894 lcid,mapflags,srcstr,srclen,dststr,dstlen);
1896 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1898 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
1899 SetLastError(ERROR_INVALID_PARAMETER);
1900 return 0;
1902 if (srclen == -1)
1903 srclen = strlen(srcstr) + 1 ; /* (include final '\0') */
1905 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1906 LCMAP_LOWERCASE | \
1907 LCMAP_SORTKEY | \
1908 NORM_IGNORECASE | \
1909 NORM_IGNORENONSPACE | \
1910 SORT_STRINGSORT | \
1911 NORM_IGNOREWIDTH | \
1912 NORM_IGNOREKANATYPE)
1913 /* FIXME: as long as we don't support Katakana nor Hiragana
1914 * characters, we can support NORM_IGNOREKANATYPE
1916 if (mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS)
1918 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1919 "unimplemented flags: 0x%08lx\n",
1920 lcid,
1921 mapflags,
1922 srcstr,
1923 srclen,
1924 dststr,
1925 dstlen,
1926 mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS
1930 if ( !(mapflags & LCMAP_SORTKEY) )
1932 int i,j;
1933 int (*f)(int) = identity;
1934 int flag_ignorenonspace = mapflags & NORM_IGNORENONSPACE;
1935 int flag_ignoresymbols = mapflags & NORM_IGNORESYMBOLS;
1937 if (flag_ignorenonspace || flag_ignoresymbols)
1939 /* For some values of mapflags, the length of the resulting
1940 string is not known at this point. Windows does map the string
1941 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1942 these cases. */
1943 if (dstlen==0)
1945 /* Compute required length */
1946 for (i=j=0; i < srclen; i++)
1948 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1949 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1950 j++;
1952 return j;
1955 else
1957 if (dstlen==0)
1958 return srclen;
1959 if (dstlen<srclen)
1961 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1962 return 0;
1965 if (mapflags & LCMAP_UPPERCASE)
1966 f = toupper;
1967 else if (mapflags & LCMAP_LOWERCASE)
1968 f = tolower;
1969 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1970 for (i=j=0; (i<srclen) && (j<dstlen) ; i++)
1972 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1973 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1975 dststr[j] = (CHAR) f(srcstr[i]);
1976 j++;
1979 return j;
1982 /* FIXME: This function completely ignores the "lcid" parameter. */
1983 /* else ... (mapflags & LCMAP_SORTKEY) */
1985 int unicode_len=0;
1986 int case_len=0;
1987 int diacritic_len=0;
1988 int delayed_punctuation_len=0;
1989 char *case_component;
1990 char *diacritic_component;
1991 char *delayed_punctuation_component;
1992 int room,count;
1993 int flag_stringsort = mapflags & SORT_STRINGSORT;
1995 /* compute how much room we will need */
1996 for (i=0;i<srclen;i++)
1998 int ofs;
1999 unsigned char source_char = srcstr[i];
2000 if (source_char!='\0')
2002 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
2004 unicode_len++;
2005 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
2006 unicode_len++; /* double letter */
2008 else
2010 delayed_punctuation_len++;
2014 if (isupper(source_char))
2015 case_len=unicode_len;
2017 ofs = source_char - LCM_Diacritic_Start;
2018 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
2019 diacritic_len=unicode_len;
2022 if (mapflags & NORM_IGNORECASE)
2023 case_len=0;
2024 if (mapflags & NORM_IGNORENONSPACE)
2025 diacritic_len=0;
2027 room = 2 * unicode_len /* "unicode" component */
2028 + diacritic_len /* "diacritic" component */
2029 + case_len /* "case" component */
2030 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
2031 + 4 /* four '\1' separators */
2032 + 1 ; /* terminal '\0' */
2033 if (dstlen==0)
2034 return room;
2035 else if (dstlen<room)
2037 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2038 return 0;
2040 #if 0
2041 /*FIXME the Pointercheck should not be nessesary */
2042 if (IsBadWritePtr (dststr,room))
2043 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
2044 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2045 return 0;
2047 #endif
2048 /* locate each component, write separators */
2049 diacritic_component = dststr + 2*unicode_len ;
2050 *diacritic_component++ = '\1';
2051 case_component = diacritic_component + diacritic_len ;
2052 *case_component++ = '\1';
2053 delayed_punctuation_component = case_component + case_len ;
2054 *delayed_punctuation_component++ = '\1';
2055 *delayed_punctuation_component++ = '\1';
2057 /* read source string char by char, write
2058 corresponding weight in each component. */
2059 for (i=0,count=0;i<srclen;i++)
2061 unsigned char source_char=srcstr[i];
2062 if (source_char!='\0')
2064 int type,longcode;
2065 type = LCM_Unicode_LUT[-2+2*source_char];
2066 longcode = type >> 4;
2067 type &= 15;
2068 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
2070 WORD encrypted_location = (1<<15) + 7 + 4*count;
2071 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
2072 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
2073 /* big-endian is used here because it lets string comparison be
2074 compatible with numerical comparison */
2076 *delayed_punctuation_component++ = type;
2077 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
2078 /* assumption : a punctuation character is never a
2079 double or accented letter */
2081 else
2083 dststr[2*count] = type;
2084 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
2085 if (longcode)
2087 if (count<case_len)
2088 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2089 if (count<diacritic_len)
2090 diacritic_component[count] = 2; /* assumption: a double letter
2091 is never accented */
2092 count++;
2094 dststr[2*count] = type;
2095 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
2096 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
2097 32 in the first column of LCM_Unicode_LUT --> longcode = 2
2098 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
2101 if (count<case_len)
2102 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2103 if (count<diacritic_len)
2105 int ofs = source_char - LCM_Diacritic_Start;
2106 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
2108 count++;
2112 dststr[room-1] = '\0';
2113 return room;
2117 /*************************************************************************
2118 * LCMapStringW [KERNEL32.493]
2120 * Convert a string, or generate a sort key from it.
2122 * NOTE
2124 * See LCMapStringA for documentation
2126 INT WINAPI LCMapStringW(
2127 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT srclen,LPWSTR dststr,
2128 INT dstlen)
2130 int i;
2132 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2133 lcid, mapflags, srcstr, srclen, dststr, dstlen);
2135 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2137 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
2138 SetLastError(ERROR_INVALID_PARAMETER);
2139 return 0;
2141 if (srclen==-1)
2142 srclen = strlenW(srcstr)+1;
2144 /* FIXME: Both this function and it's companion LCMapStringA()
2145 * completely ignore the "lcid" parameter. In place of the "lcid"
2146 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2147 * environment variable prior to invoking this function. */
2148 if (mapflags & LCMAP_SORTKEY)
2150 /* Possible values of LC_COLLATE. */
2151 char *lc_collate_default = 0; /* value prior to this function */
2152 char *lc_collate_env = 0; /* value retrieved from the environment */
2154 /* General purpose index into strings of any type. */
2155 int str_idx = 0;
2157 /* Lengths of various strings where the length is measured in
2158 * wide characters for wide character strings and in bytes for
2159 * native strings. The lengths include the NULL terminator. */
2160 size_t returned_len = 0;
2161 size_t src_native_len = 0;
2162 size_t dst_native_len = 0;
2163 size_t dststr_libc_len = 0;
2165 /* Native (character set determined by locale) versions of the
2166 * strings source and destination strings. */
2167 LPSTR src_native = 0;
2168 LPSTR dst_native = 0;
2170 /* Version of the source and destination strings using the
2171 * "wchar_t" Unicode data type needed by various libc functions. */
2172 wchar_t *srcstr_libc = 0;
2173 wchar_t *dststr_libc = 0;
2175 if(!(srcstr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2176 srclen * sizeof(wchar_t))))
2178 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2179 srclen * sizeof(wchar_t));
2180 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2181 return 0;
2184 /* Convert source string to a libc Unicode string. */
2185 for(str_idx = 0; str_idx < srclen; str_idx++)
2187 srcstr_libc[str_idx] = srcstr[str_idx];
2190 /* src_native should contain at most 3 bytes for each
2191 * multibyte characters in the original srcstr string. */
2192 src_native_len = 3 * srclen;
2193 if(!(src_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0,
2194 src_native_len)))
2196 ERR("Unable to allocate %d bytes for src_native\n", src_native_len);
2197 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2198 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2199 return 0;
2202 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2203 * current value is backed up so it can be restored after the
2204 * last LC_COLLATE sensitive function returns.
2206 * Even though the locale is adjusted for a minimum amount of
2207 * time a race condition exists where other threads may be
2208 * affected if they invoke LC_COLLATE sensitive functions. One
2209 * possible solution is to wrap all LC_COLLATE sensitive Wine
2210 * functions, like LCMapStringW(), in a mutex.
2212 * Another enhancement to the following would be to set the
2213 * LC_COLLATE locale category as a function of the "lcid"
2214 * parameter instead of the "LC_COLLATE" environment variable. */
2215 if(!(lc_collate_default = setlocale(LC_COLLATE, NULL)))
2217 ERR("Unable to query the LC_COLLATE catagory\n");
2218 SetLastError(ERROR_INVALID_PARAMETER);
2219 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2220 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2221 return 0;
2224 if(!(lc_collate_env = setlocale(LC_COLLATE, "")))
2226 ERR("Unable to inherit the LC_COLLATE locale category from the "
2227 "environment. The \"LC_COLLATE\" environment variable is "
2228 "\"%s\".\n", getenv("LC_COLLATE") ?
2229 getenv("LC_COLLATE") : "<unset>");
2230 SetLastError(ERROR_INVALID_PARAMETER);
2231 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2232 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2233 return 0;
2236 TRACE("lc_collate_default = %s\n", lc_collate_default);
2237 TRACE("lc_collate_env = %s\n", lc_collate_env);
2239 /* Convert the libc Unicode string to a native multibyte character
2240 * string. */
2241 returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1;
2242 if(returned_len == 0)
2244 LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(),
2245 0, srcstr);
2246 ERR("wcstombs failed. The string specified (%s) may contains an "
2247 "invalid character.\n", srcstr_ascii);
2248 SetLastError(ERROR_INVALID_PARAMETER);
2249 if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii);
2250 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2251 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2252 setlocale(LC_COLLATE, lc_collate_default);
2253 return 0;
2255 else if(returned_len > src_native_len)
2257 src_native[src_native_len - 1] = 0;
2258 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2259 "than expected (%d bytes).\n", src_native, returned_len,
2260 dst_native_len);
2262 /* Since this is an internal error I'm not sure what the correct
2263 * error code is. */
2264 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2266 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2267 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2268 setlocale(LC_COLLATE, lc_collate_default);
2269 return 0;
2271 src_native_len = returned_len;
2273 TRACE("src_native = %s src_native_len = %d\n",
2274 src_native, src_native_len);
2276 /* dst_native seems to contain at most 4 bytes for each byte in
2277 * the original src_native string. Change if need be since this
2278 * isn't documented by the strxfrm() man page. */
2279 dst_native_len = 4 * src_native_len;
2280 if(!(dst_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0, dst_native_len)))
2282 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len);
2283 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2284 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2285 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2286 setlocale(LC_COLLATE, lc_collate_default);
2287 return 0;
2290 /* The actual translation is done by the following call to
2291 * strxfrm(). The surrounding code could have been simplified
2292 * by calling wcsxfrm() instead except that wcsxfrm() is not
2293 * available on older Linux systems (RedHat 4.1 with
2294 * libc-5.3.12-17).
2296 * Also, it is possible that the translation could be done by
2297 * various tables as it is done in LCMapStringA(). However, I'm
2298 * not sure what those tables are. */
2299 returned_len = strxfrm(dst_native, src_native, dst_native_len) + 1;
2301 if(returned_len > dst_native_len)
2303 dst_native[dst_native_len - 1] = 0;
2304 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2305 "than expected (%d bytes).\n", dst_native, returned_len,
2306 dst_native_len);
2308 /* Since this is an internal error I'm not sure what the correct
2309 * error code is. */
2310 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2312 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2313 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2314 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2315 setlocale(LC_COLLATE, lc_collate_default);
2316 return 0;
2318 dst_native_len = returned_len;
2320 TRACE("dst_native = %s dst_native_len = %d\n",
2321 dst_native, dst_native_len);
2323 dststr_libc_len = dst_native_len;
2324 if(!(dststr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2325 dststr_libc_len * sizeof(wchar_t))))
2327 ERR("Unable to allocate %d bytes for dststr_libc\n",
2328 dststr_libc_len * sizeof(wchar_t));
2329 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2330 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2331 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2332 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2333 setlocale(LC_COLLATE, lc_collate_default);
2334 return 0;
2337 /* Convert the native multibyte string to a libc Unicode string. */
2338 returned_len = mbstowcs(dststr_libc, dst_native, dst_native_len) + 1;
2340 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2341 * function has returned. */
2342 setlocale(LC_COLLATE, lc_collate_default);
2344 if(returned_len == 0)
2346 ERR("mbstowcs failed. The native version of the translated string "
2347 "(%s) may contain an invalid character.\n", dst_native);
2348 SetLastError(ERROR_INVALID_PARAMETER);
2349 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2350 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2351 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2352 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2353 return 0;
2355 if(dstlen)
2357 if(returned_len > dstlen)
2359 ERR("mbstowcs returned a string that was longer (%d chars) "
2360 "than the buffer provided (%d chars).\n", returned_len,
2361 dstlen);
2362 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2363 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2364 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2365 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2366 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2367 return 0;
2369 dstlen = returned_len;
2371 /* Convert a libc Unicode string to the destination string. */
2372 for(str_idx = 0; str_idx < dstlen; str_idx++)
2374 dststr[str_idx] = dststr_libc[str_idx];
2376 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2377 *(((int *)dststr) + 0),
2378 *(((int *)dststr) + 1),
2379 *(((int *)dststr) + 2),
2380 *(((int *)dststr) + 3));
2382 else
2384 dstlen = returned_len;
2386 TRACE("dstlen (return) = %d\n", dstlen);
2387 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2388 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2389 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2390 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2391 return dstlen;
2393 else
2395 int (*f)(int)=identity;
2397 if (dstlen==0)
2398 return srclen;
2399 if (dstlen<srclen)
2401 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2402 return 0;
2405 if (mapflags & LCMAP_UPPERCASE)
2406 f = toupper;
2407 else if (mapflags & LCMAP_LOWERCASE)
2408 f = tolower;
2409 for (i=0; i < srclen; i++)
2410 dststr[i] = (WCHAR) f(srcstr[i]);
2411 return srclen;
2416 /***********************************************************************
2417 * OLE2NLS_EstimateMappingLength
2419 * Estimates the number of characters required to hold the string
2420 * computed by LCMapStringA.
2422 * The size is always over-estimated, with a fixed limit on the
2423 * amount of estimation error.
2425 * Note that len == -1 is not permitted.
2427 static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
2428 LPCSTR str, DWORD len)
2430 /* Estimate only for small strings to keep the estimation error from
2431 * becoming too large. */
2432 if (len < 128) return len * 8 + 5;
2433 else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
2436 /******************************************************************************
2437 * CompareStringA [KERNEL32.143]
2438 * Compares two strings using locale
2440 * RETURNS
2442 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2443 * failure: 0
2445 * NOTES
2447 * Defaults to a word sort, but uses a string sort if
2448 * SORT_STRINGSORT is set.
2449 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2451 * BUGS
2453 * This implementation ignores the locale
2455 * FIXME
2457 * Quite inefficient.
2459 UINT WINAPI CompareStringA(
2460 DWORD lcid, /* [in] locale ID */
2461 DWORD fdwStyle, /* [in] comparison-style options */
2462 LPCSTR s1, /* [in] first string */
2463 DWORD l1, /* [in] length of first string */
2464 LPCSTR s2, /* [in] second string */
2465 DWORD l2) /* [in] length of second string */
2467 int mapstring_flags;
2468 int len1,len2;
2469 int result;
2470 LPSTR sk1,sk2;
2471 TRACE("%s and %s\n",
2472 debugstr_a (s1), debugstr_a (s2));
2474 if ( (s1==NULL) || (s2==NULL) )
2476 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
2477 SetLastError(ERROR_INVALID_PARAMETER);
2478 return 0;
2481 if(fdwStyle & NORM_IGNORESYMBOLS)
2482 FIXME("IGNORESYMBOLS not supported\n");
2484 if (l1 == -1) l1 = strlen(s1);
2485 if (l2 == -1) l2 = strlen(s2);
2487 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2488 len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
2489 len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
2491 if ((len1==0)||(len2==0))
2492 return 0; /* something wrong happened */
2494 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
2495 sk2 = sk1 + len1;
2496 if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
2497 || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2499 ERR("Bug in LCmapStringA.\n");
2500 result = 0;
2502 else
2504 /* strcmp doesn't necessarily return -1, 0, or 1 */
2505 result = strcmp(sk1,sk2);
2507 HeapFree(GetProcessHeap(),0,sk1);
2509 if (result < 0)
2510 return 1;
2511 if (result == 0)
2512 return 2;
2514 /* must be greater, if we reach this point */
2515 return 3;
2518 /******************************************************************************
2519 * CompareStringW [KERNEL32.144]
2520 * This implementation ignores the locale
2521 * FIXME : Does only string sort. Should
2522 * be reimplemented the same way as CompareStringA.
2524 UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
2525 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2527 int len,ret;
2528 if(fdwStyle & NORM_IGNORENONSPACE)
2529 FIXME("IGNORENONSPACE not supprted\n");
2530 if(fdwStyle & NORM_IGNORESYMBOLS)
2531 FIXME("IGNORESYMBOLS not supported\n");
2533 /* Is strcmp defaulting to string sort or to word sort?? */
2534 /* FIXME: Handle NORM_STRINGSORT */
2535 l1 = (l1==-1)?strlenW(s1):l1;
2536 l2 = (l2==-1)?strlenW(s2):l2;
2537 len = l1<l2 ? l1:l2;
2538 ret = (fdwStyle & NORM_IGNORECASE) ? strncmpiW(s1,s2,len) : strncmpW(s1,s2,len);
2539 /* not equal, return 1 or 3 */
2540 if(ret!=0) {
2541 /* need to translate result */
2542 return ((int)ret < 0) ? 1 : 3;
2544 /* same len, return 2 */
2545 if(l1==l2) return 2;
2546 /* the longer one is lexically greater */
2547 return (l1<l2)? 1 : 3;
2550 /******************************************************************************
2551 * OLE_GetFormatA [Internal]
2553 * FIXME
2554 * If datelen == 0, it should return the reguired string length.
2556 This function implements stuff for GetDateFormat() and
2557 GetTimeFormat().
2559 d single-digit (no leading zero) day (of month)
2560 dd two-digit day (of month)
2561 ddd short day-of-week name
2562 dddd long day-of-week name
2563 M single-digit month
2564 MM two-digit month
2565 MMM short month name
2566 MMMM full month name
2567 y two-digit year, no leading 0
2568 yy two-digit year
2569 yyyy four-digit year
2570 gg era string
2571 h hours with no leading zero (12-hour)
2572 hh hours with full two digits
2573 H hours with no leading zero (24-hour)
2574 HH hours with full two digits
2575 m minutes with no leading zero
2576 mm minutes with full two digits
2577 s seconds with no leading zero
2578 ss seconds with full two digits
2579 t time marker (A or P)
2580 tt time marker (AM, PM)
2581 '' used to quote literal characters
2582 '' (within a quoted string) indicates a literal '
2584 These functions REQUIRE valid locale, date, and format.
2586 static INT OLE_GetFormatA(LCID locale,
2587 DWORD flags,
2588 DWORD tflags,
2589 LPSYSTEMTIME xtime,
2590 LPCSTR _format, /*in*/
2591 LPSTR date, /*out*/
2592 INT datelen)
2594 INT inpos, outpos;
2595 int count, type, inquote, Overflow;
2596 char buf[40];
2597 char format[40];
2598 char * pos;
2599 int buflen;
2601 const char * _dgfmt[] = { "%d", "%02d" };
2602 const char ** dgfmt = _dgfmt - 1;
2604 /* report, for debugging */
2605 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",
2606 locale, flags, tflags,
2607 xtime->wYear,xtime->wMonth,xtime->wDayOfWeek,xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2608 _format, _format, date, datelen);
2610 if(datelen == 0) {
2611 FIXME("datelen = 0, returning 255\n");
2612 return 255;
2615 /* initalize state variables and output buffer */
2616 inpos = outpos = 0;
2617 count = 0; inquote = 0; Overflow = 0;
2618 type = '\0';
2619 date[0] = buf[0] = '\0';
2621 strcpy(format,_format);
2623 /* alter the formatstring, while it works for all languages now in wine
2624 its possible that it fails when the time looks like ss:mm:hh as example*/
2625 if (tflags & (TIME_NOMINUTESORSECONDS))
2626 { if ((pos = strstr ( format, ":mm")))
2627 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2630 if (tflags & (TIME_NOSECONDS))
2631 { if ((pos = strstr ( format, ":ss")))
2632 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2636 for (inpos = 0;; inpos++) {
2637 /* 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]); */
2638 if (inquote) {
2639 if (format[inpos] == '\'') {
2640 if (format[inpos+1] == '\'') {
2641 inpos += 1;
2642 date[outpos++] = '\'';
2643 } else {
2644 inquote = 0;
2645 continue; /* we did nothing to the output */
2647 } else if (format[inpos] == '\0') {
2648 date[outpos++] = '\0';
2649 if (outpos > datelen) Overflow = 1;
2650 break;
2651 } else {
2652 date[outpos++] = format[inpos];
2653 if (outpos > datelen) {
2654 Overflow = 1;
2655 date[outpos-1] = '\0'; /* this is the last place where
2656 it's safe to write */
2657 break;
2660 } else if ( (count && (format[inpos] != type))
2661 || count == 4
2662 || (count == 2 && strchr("ghHmst", type)) ) {
2663 if (type == 'h' && (tflags & TIME_FORCE24HOURFORMAT)) type= 'H';
2664 if (type == 'd') {
2665 if (count == 4) {
2666 GetLocaleInfoA(locale,
2667 LOCALE_SDAYNAME1
2668 + (xtime->wDayOfWeek+6)%7,
2669 buf, sizeof(buf));
2670 } else if (count == 3) {
2671 GetLocaleInfoA(locale,
2672 LOCALE_SABBREVDAYNAME1
2673 + (xtime->wDayOfWeek+6)%7,
2674 buf, sizeof(buf));
2675 } else {
2676 sprintf(buf, dgfmt[count], xtime->wDay);
2678 } else if (type == 'M') {
2679 if (count == 3) {
2680 GetLocaleInfoA(locale,
2681 LOCALE_SABBREVMONTHNAME1
2682 + xtime->wMonth - 1,
2683 buf, sizeof(buf));
2684 } else if (count == 4) {
2685 GetLocaleInfoA(locale,
2686 LOCALE_SMONTHNAME1
2687 + xtime->wMonth - 1,
2688 buf, sizeof(buf));
2689 } else {
2690 sprintf(buf, dgfmt[count], xtime->wMonth);
2692 } else if (type == 'y') {
2693 if (count == 4) {
2694 sprintf(buf, "%d", xtime->wYear);
2695 } else if (count == 3) {
2696 strcpy(buf, "yyy");
2697 WARN("unknown format, c=%c, n=%d\n", type, count);
2698 } else {
2699 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2701 } else if (type == 'g') {
2702 if (count == 2) {
2703 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2704 strcpy(buf, "AD");
2705 } else {
2706 strcpy(buf, "g");
2707 WARN("unknown format, c=%c, n=%d\n", type, count);
2709 } else if (type == 'h') {
2710 /* gives us hours 1:00 -- 12:00 */
2711 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2712 } else if (type == 'H') {
2713 /* 24-hour time */
2714 sprintf(buf, dgfmt[count], xtime->wHour);
2715 } else if ( type == 'm') {
2716 sprintf(buf, dgfmt[count], xtime->wMinute);
2717 } else if ( type == 's') {
2718 sprintf(buf, dgfmt[count], xtime->wSecond);
2719 } else if (type == 't') {
2720 if ((tflags & TIME_NOTIMEMARKER))
2721 buf[0]='\0';
2722 else if (count == 1) {
2723 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2724 } else if (count == 2) {
2725 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2726 GetLocaleInfoA(locale,
2727 (xtime->wHour<12)
2728 ? LOCALE_S1159 : LOCALE_S2359,
2729 buf, sizeof(buf));
2733 /* we need to check the next char in the format string
2734 again, no matter what happened */
2735 inpos--;
2737 /* add the contents of buf to the output */
2738 buflen = strlen(buf);
2739 if (outpos + buflen < datelen) {
2740 date[outpos] = '\0'; /* for strcat to hook onto */
2741 strcat(date, buf);
2742 outpos += buflen;
2743 } else {
2744 date[outpos] = '\0';
2745 strncat(date, buf, datelen - outpos);
2746 date[datelen - 1] = '\0';
2747 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2748 WARN("insufficient buffer\n");
2749 return 0;
2752 /* reset the variables we used to keep track of this item */
2753 count = 0;
2754 type = '\0';
2755 } else if (format[inpos] == '\0') {
2756 /* we can't check for this at the loop-head, because
2757 that breaks the printing of the last format-item */
2758 date[outpos] = '\0';
2759 break;
2760 } else if (count) {
2761 /* continuing a code for an item */
2762 count +=1;
2763 continue;
2764 } else if (strchr("hHmstyMdg", format[inpos])) {
2765 type = format[inpos];
2766 count = 1;
2767 continue;
2768 } else if (format[inpos] == '\'') {
2769 inquote = 1;
2770 continue;
2771 } else {
2772 date[outpos++] = format[inpos];
2774 /* now deal with a possible buffer overflow */
2775 if (outpos >= datelen) {
2776 date[datelen - 1] = '\0';
2777 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2778 return 0;
2782 if (Overflow) {
2783 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2786 /* finish it off with a string terminator */
2787 outpos++;
2788 /* sanity check */
2789 if (outpos > datelen-1) outpos = datelen-1;
2790 date[outpos] = '\0';
2792 TRACE("returns string '%s', len %d\n", date, outpos);
2793 return outpos;
2796 /******************************************************************************
2797 * OLE_GetFormatW [INTERNAL]
2799 static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
2800 LPSYSTEMTIME xtime,
2801 LPCWSTR format,
2802 LPWSTR output, INT outlen)
2804 INT inpos, outpos;
2805 int count, type=0, inquote;
2806 int Overflow; /* loop check */
2807 char tmp[16];
2808 WCHAR buf[40];
2809 int buflen=0;
2810 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2811 WCHAR arg2[] = {'%','0','2','d',0};
2812 WCHAR *argarr[3];
2813 int datevars=0, timevars=0;
2815 argarr[0] = arg0;
2816 argarr[1] = arg1;
2817 argarr[2] = arg2;
2819 /* make a debug report */
2820 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2821 "%p with max len %d\n",
2822 locale, flags, tflags,
2823 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2824 debugstr_w(format), format, output, outlen);
2826 if(outlen == 0) {
2827 FIXME("outlen = 0, returning 255\n");
2828 return 255;
2831 /* initialize state variables */
2832 inpos = outpos = 0;
2833 count = 0;
2834 inquote = Overflow = 0;
2835 /* this is really just a sanity check */
2836 output[0] = buf[0] = 0;
2838 /* this loop is the core of the function */
2839 for (inpos = 0; /* we have several break points */ ; inpos++) {
2840 if (inquote) {
2841 if (format[inpos] == (WCHAR) '\'') {
2842 if (format[inpos+1] == '\'') {
2843 inpos++;
2844 output[outpos++] = '\'';
2845 } else {
2846 inquote = 0;
2847 continue;
2849 } else if (format[inpos] == 0) {
2850 output[outpos++] = 0;
2851 if (outpos > outlen) Overflow = 1;
2852 break; /* normal exit (within a quote) */
2853 } else {
2854 output[outpos++] = format[inpos]; /* copy input */
2855 if (outpos > outlen) {
2856 Overflow = 1;
2857 output[outpos-1] = 0;
2858 break;
2861 } else if ( (count && (format[inpos] != type))
2862 || ( (count==4 && type =='y') ||
2863 (count==4 && type =='M') ||
2864 (count==4 && type =='d') ||
2865 (count==2 && type =='g') ||
2866 (count==2 && type =='h') ||
2867 (count==2 && type =='H') ||
2868 (count==2 && type =='m') ||
2869 (count==2 && type =='s') ||
2870 (count==2 && type =='t') ) ) {
2871 switch(type)
2873 case 'd':
2874 if (count == 4) {
2875 GetLocaleInfoW(locale,
2876 LOCALE_SDAYNAME1 + (xtime->wDayOfWeek +6)%7,
2877 buf, sizeof(buf)/sizeof(WCHAR) );
2878 } else if (count == 3) {
2879 GetLocaleInfoW(locale,
2880 LOCALE_SABBREVDAYNAME1 +
2881 (xtime->wDayOfWeek +6)%7,
2882 buf, sizeof(buf)/sizeof(WCHAR) );
2883 } else {
2884 sprintf( tmp, "%.*d", count, xtime->wDay );
2885 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2887 break;
2889 case 'M':
2890 if (count == 4) {
2891 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
2892 xtime->wMonth -1, buf,
2893 sizeof(buf)/sizeof(WCHAR) );
2894 } else if (count == 3) {
2895 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
2896 xtime->wMonth -1, buf,
2897 sizeof(buf)/sizeof(WCHAR) );
2898 } else {
2899 sprintf( tmp, "%.*d", count, xtime->wMonth );
2900 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2902 break;
2903 case 'y':
2904 if (count == 4) {
2905 sprintf( tmp, "%d", xtime->wYear );
2906 } else if (count == 3) {
2907 strcpy( tmp, "yyy" );
2908 } else {
2909 sprintf( tmp, "%.*d", count, xtime->wYear % 100 );
2911 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2912 break;
2914 case 'g':
2915 if (count == 2) {
2916 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2917 strcpy( tmp, "AD" );
2918 } else {
2919 /* Win API sez we copy it verbatim */
2920 strcpy( tmp, "g" );
2922 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2923 break;
2925 case 'h':
2926 /* hours 1:00-12:00 --- is this right? */
2927 sprintf( tmp, "%.*d", count, (xtime->wHour-1)%12 +1);
2928 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2929 break;
2931 case 'H':
2932 sprintf( tmp, "%.*d", count, xtime->wHour );
2933 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2934 break;
2936 case 'm':
2937 sprintf( tmp, "%.*d", count, xtime->wMinute );
2938 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2939 break;
2941 case 's':
2942 sprintf( tmp, "%.*d", count, xtime->wSecond );
2943 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2944 break;
2946 case 't':
2947 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
2948 LOCALE_S1159 : LOCALE_S2359,
2949 buf, sizeof(buf) );
2950 if (count == 1) {
2951 buf[1] = 0;
2953 break;
2956 /* no matter what happened, we need to check this next
2957 character the next time we loop through */
2958 inpos--;
2960 /* cat buf onto the output */
2961 outlen = strlenW(buf);
2962 if (outpos + buflen < outlen) {
2963 strcpyW( output + outpos, buf );
2964 outpos += buflen;
2965 } else {
2966 lstrcpynW( output + outpos, buf, outlen - outpos );
2967 Overflow = 1;
2968 break; /* Abnormal exit */
2971 /* reset the variables we used this time */
2972 count = 0;
2973 type = '\0';
2974 } else if (format[inpos] == 0) {
2975 /* we can't check for this at the beginning, because that
2976 would keep us from printing a format spec that ended the
2977 string */
2978 output[outpos] = 0;
2979 break; /* NORMAL EXIT */
2980 } else if (count) {
2981 /* how we keep track of the middle of a format spec */
2982 count++;
2983 continue;
2984 } else if ( (datevars && (format[inpos]=='d' ||
2985 format[inpos]=='M' ||
2986 format[inpos]=='y' ||
2987 format[inpos]=='g') ) ||
2988 (timevars && (format[inpos]=='H' ||
2989 format[inpos]=='h' ||
2990 format[inpos]=='m' ||
2991 format[inpos]=='s' ||
2992 format[inpos]=='t') ) ) {
2993 type = format[inpos];
2994 count = 1;
2995 continue;
2996 } else if (format[inpos] == '\'') {
2997 inquote = 1;
2998 continue;
2999 } else {
3000 /* unquoted literals */
3001 output[outpos++] = format[inpos];
3005 if (Overflow) {
3006 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3007 WARN(" buffer overflow\n");
3010 /* final string terminator and sanity check */
3011 outpos++;
3012 if (outpos > outlen-1) outpos = outlen-1;
3013 output[outpos] = '0';
3015 TRACE(" returning %s\n", debugstr_w(output));
3017 return (!Overflow) ? outlen : 0;
3022 /******************************************************************************
3023 * GetDateFormatA [KERNEL32.310]
3024 * Makes an ASCII string of the date
3026 * This function uses format to format the date, or, if format
3027 * is NULL, uses the default for the locale. format is a string
3028 * of literal fields and characters as follows:
3030 * - d single-digit (no leading zero) day (of month)
3031 * - dd two-digit day (of month)
3032 * - ddd short day-of-week name
3033 * - dddd long day-of-week name
3034 * - M single-digit month
3035 * - MM two-digit month
3036 * - MMM short month name
3037 * - MMMM full month name
3038 * - y two-digit year, no leading 0
3039 * - yy two-digit year
3040 * - yyyy four-digit year
3041 * - gg era string
3044 INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
3045 LPSYSTEMTIME xtime,
3046 LPCSTR format, LPSTR date,INT datelen)
3049 char format_buf[40];
3050 LPCSTR thisformat;
3051 SYSTEMTIME t;
3052 LPSYSTEMTIME thistime;
3053 LCID thislocale;
3054 INT ret;
3055 FILETIME ft;
3056 BOOL res;
3058 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
3059 locale,flags,xtime,format,date,datelen);
3061 if (!locale) {
3062 locale = LOCALE_SYSTEM_DEFAULT;
3065 if (locale == LOCALE_SYSTEM_DEFAULT) {
3066 thislocale = GetSystemDefaultLCID();
3067 } else if (locale == LOCALE_USER_DEFAULT) {
3068 thislocale = GetUserDefaultLCID();
3069 } else {
3070 thislocale = locale;
3073 if (xtime == NULL) {
3074 GetSystemTime(&t);
3075 } else {
3076 /* Silently correct wDayOfWeek by tranforming to FileTime and back again*/
3077 res=SystemTimeToFileTime(xtime,&ft);
3078 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error*/
3079 /*FIXME: SystemTimeToFileTime doesn't yet do that ckeck*/
3080 if(!res)
3082 SetLastError(ERROR_INVALID_PARAMETER);
3083 return 0;
3085 FileTimeToSystemTime(&ft,&t);
3088 thistime = &t;
3090 if (format == NULL) {
3091 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
3092 ? LOCALE_SLONGDATE
3093 : LOCALE_SSHORTDATE),
3094 format_buf, sizeof(format_buf));
3095 thisformat = format_buf;
3096 } else {
3097 thisformat = format;
3101 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
3102 date, datelen);
3105 TRACE(
3106 "GetDateFormatA() returning %d, with data=%s\n",
3107 ret, date);
3108 return ret;
3111 /******************************************************************************
3112 * GetDateFormatW [KERNEL32.311]
3113 * Makes a Unicode string of the date
3115 * Acts the same as GetDateFormatA(), except that it's Unicode.
3116 * Accepts & returns sizes as counts of Unicode characters.
3119 INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
3120 LPSYSTEMTIME xtime,
3121 LPCWSTR format,
3122 LPWSTR date, INT datelen)
3124 unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
3126 FIXME("STUB (should call OLE_GetFormatW)\n");
3127 lstrcpynW(date, datearr, datelen);
3128 return ( datelen < 9) ? datelen : 9;
3133 /**************************************************************************
3134 * EnumDateFormatsA (KERNEL32.198)
3136 BOOL WINAPI EnumDateFormatsA(
3137 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3139 LCID Loc = GetUserDefaultLCID();
3140 if(!lpDateFmtEnumProc)
3142 SetLastError(ERROR_INVALID_PARAMETER);
3143 return FALSE;
3146 switch( Loc )
3149 case 0x00000407: /* (Loc,"de_DE") */
3151 switch(dwFlags)
3153 case DATE_SHORTDATE:
3154 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3155 if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
3156 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3157 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3158 return TRUE;
3159 case DATE_LONGDATE:
3160 if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
3161 if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
3162 if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
3163 return TRUE;
3164 default:
3165 FIXME("Unknown date format (%ld)\n", dwFlags);
3166 SetLastError(ERROR_INVALID_PARAMETER);
3167 return FALSE;
3171 case 0x0000040c: /* (Loc,"fr_FR") */
3173 switch(dwFlags)
3175 case DATE_SHORTDATE:
3176 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3177 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3178 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3179 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3180 return TRUE;
3181 case DATE_LONGDATE:
3182 if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
3183 if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
3184 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3185 return TRUE;
3186 default:
3187 FIXME("Unknown date format (%ld)\n", dwFlags);
3188 SetLastError(ERROR_INVALID_PARAMETER);
3189 return FALSE;
3193 case 0x00000c0c: /* (Loc,"fr_CA") */
3195 switch(dwFlags)
3197 case DATE_SHORTDATE:
3198 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3199 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3200 if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
3201 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3202 return TRUE;
3203 case DATE_LONGDATE:
3204 if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
3205 if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
3206 return TRUE;
3207 default:
3208 FIXME("Unknown date format (%ld)\n", dwFlags);
3209 SetLastError(ERROR_INVALID_PARAMETER);
3210 return FALSE;
3214 case 0x00000809: /* (Loc,"en_UK") */
3216 switch(dwFlags)
3218 case DATE_SHORTDATE:
3219 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3220 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3221 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3222 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3223 return TRUE;
3224 case DATE_LONGDATE:
3225 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3226 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3227 return TRUE;
3228 default:
3229 FIXME("Unknown date format (%ld)\n", dwFlags);
3230 SetLastError(ERROR_INVALID_PARAMETER);
3231 return FALSE;
3235 case 0x00000c09: /* (Loc,"en_AU") */
3237 switch(dwFlags)
3239 case DATE_SHORTDATE:
3240 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3241 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3242 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3243 return TRUE;
3244 case DATE_LONGDATE:
3245 if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
3246 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3247 return TRUE;
3248 default:
3249 FIXME("Unknown date format (%ld)\n", dwFlags);
3250 SetLastError(ERROR_INVALID_PARAMETER);
3251 return FALSE;
3255 case 0x00001009: /* (Loc,"en_CA") */
3257 switch(dwFlags)
3259 case DATE_SHORTDATE:
3260 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3261 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3262 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3263 if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
3264 return TRUE;
3265 case DATE_LONGDATE:
3266 if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
3267 if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
3268 return TRUE;
3269 default:
3270 FIXME("Unknown date format (%ld)\n", dwFlags);
3271 SetLastError(ERROR_INVALID_PARAMETER);
3272 return FALSE;
3276 case 0x00001409: /* (Loc,"en_NZ") */
3278 switch(dwFlags)
3280 case DATE_SHORTDATE:
3281 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3282 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3283 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3284 return TRUE;
3285 case DATE_LONGDATE:
3286 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3287 if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
3288 return TRUE;
3289 default:
3290 FIXME("Unknown date format (%ld)\n", dwFlags);
3291 SetLastError(ERROR_INVALID_PARAMETER);
3292 return FALSE;
3296 case 0x00001809: /* (Loc,"en_IE") */
3298 switch(dwFlags)
3300 case DATE_SHORTDATE:
3301 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3302 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3303 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3304 return TRUE;
3305 case DATE_LONGDATE:
3306 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3307 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3308 return TRUE;
3309 default:
3310 FIXME("Unknown date format (%ld)\n", dwFlags);
3311 SetLastError(ERROR_INVALID_PARAMETER);
3312 return FALSE;
3316 case 0x00001c09: /* (Loc,"en_ZA") */
3318 switch(dwFlags)
3320 case DATE_SHORTDATE:
3321 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3322 return TRUE;
3323 case DATE_LONGDATE:
3324 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3325 return TRUE;
3326 default:
3327 FIXME("Unknown date format (%ld)\n", dwFlags);
3328 SetLastError(ERROR_INVALID_PARAMETER);
3329 return FALSE;
3333 case 0x00002009: /* (Loc,"en_JM") */
3335 switch(dwFlags)
3337 case DATE_SHORTDATE:
3338 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3339 return TRUE;
3340 case DATE_LONGDATE:
3341 if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
3342 if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
3343 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
3344 if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
3345 return TRUE;
3346 default:
3347 FIXME("Unknown date format (%ld)\n", dwFlags);
3348 SetLastError(ERROR_INVALID_PARAMETER);
3349 return FALSE;
3353 case 0x00002809: /* (Loc,"en_BZ") */
3354 case 0x00002c09: /* (Loc,"en_TT") */
3356 switch(dwFlags)
3358 case DATE_SHORTDATE:
3359 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3360 return TRUE;
3361 case DATE_LONGDATE:
3362 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
3363 return TRUE;
3364 default:
3365 FIXME("Unknown date format (%ld)\n", dwFlags);
3366 SetLastError(ERROR_INVALID_PARAMETER);
3367 return FALSE;
3371 default: /* default to US English "en_US" */
3373 switch(dwFlags)
3375 case DATE_SHORTDATE:
3376 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
3377 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
3378 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
3379 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
3380 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3381 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
3382 return TRUE;
3383 case DATE_LONGDATE:
3384 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
3385 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
3386 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
3387 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
3388 return TRUE;
3389 default:
3390 FIXME("Unknown date format (%ld)\n", dwFlags);
3391 SetLastError(ERROR_INVALID_PARAMETER);
3392 return FALSE;
3398 /**************************************************************************
3399 * EnumDateFormatsW (KERNEL32.199)
3401 BOOL WINAPI EnumDateFormatsW(
3402 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3404 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
3405 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3406 return FALSE;
3409 /**************************************************************************
3410 * EnumTimeFormatsA (KERNEL32.210)
3412 BOOL WINAPI EnumTimeFormatsA(
3413 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3415 LCID Loc = GetUserDefaultLCID();
3416 if(!lpTimeFmtEnumProc)
3418 SetLastError(ERROR_INVALID_PARAMETER);
3419 return FALSE;
3421 if(dwFlags)
3423 FIXME("Unknown time format (%ld)\n", dwFlags);
3426 switch( Loc )
3428 case 0x00000407: /* (Loc,"de_DE") */
3430 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3431 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3432 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3433 if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
3434 if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
3435 return TRUE;
3438 case 0x0000040c: /* (Loc,"fr_FR") */
3439 case 0x00000c0c: /* (Loc,"fr_CA") */
3441 if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
3442 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3443 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3444 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3445 if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
3446 return TRUE;
3449 case 0x00000809: /* (Loc,"en_UK") */
3450 case 0x00000c09: /* (Loc,"en_AU") */
3451 case 0x00001409: /* (Loc,"en_NZ") */
3452 case 0x00001809: /* (Loc,"en_IE") */
3454 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3455 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3456 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3457 return TRUE;
3460 case 0x00001c09: /* (Loc,"en_ZA") */
3461 case 0x00002809: /* (Loc,"en_BZ") */
3462 case 0x00002c09: /* (Loc,"en_TT") */
3464 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3465 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3466 return TRUE;
3469 default: /* default to US style "en_US" */
3471 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3472 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3473 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3474 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3475 return TRUE;
3480 /**************************************************************************
3481 * EnumTimeFormatsW (KERNEL32.211)
3483 BOOL WINAPI EnumTimeFormatsW(
3484 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3486 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
3487 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3488 return FALSE;
3491 /**************************************************************************
3492 * This function is used just locally !
3493 * Description: Inverts a string.
3495 static void OLE_InvertString(char* string)
3497 char sTmpArray[128];
3498 INT counter, i = 0;
3500 for (counter = strlen(string); counter > 0; counter--)
3502 memcpy(sTmpArray + i, string + counter-1, 1);
3503 i++;
3505 memcpy(sTmpArray + i, "\0", 1);
3506 strcpy(string, sTmpArray);
3509 /***************************************************************************************
3510 * This function is used just locally !
3511 * Description: Test if the given string (psNumber) is valid or not.
3512 * The valid characters are the following:
3513 * - Characters '0' through '9'.
3514 * - One decimal point (dot) if the number is a floating-point value.
3515 * - A minus sign in the first character position if the number is
3516 * a negative value.
3517 * If the function succeeds, psBefore/psAfter will point to the string
3518 * on the right/left of the decimal symbol. pbNegative indicates if the
3519 * number is negative.
3521 static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
3523 char sNumberSet[] = "0123456789";
3524 BOOL bInDecimal = FALSE;
3526 /* Test if we do have a minus sign */
3527 if ( *pInput == '-' )
3529 *pbNegative = TRUE;
3530 pInput++; /* Jump to the next character. */
3533 while(*pInput != '\0')
3535 /* Do we have a valid numeric character */
3536 if ( strchr(sNumberSet, *pInput) != NULL )
3538 if (bInDecimal == TRUE)
3539 *psAfter++ = *pInput;
3540 else
3541 *psBefore++ = *pInput;
3543 else
3545 /* Is this a decimal point (dot) */
3546 if ( *pInput == '.' )
3548 /* Is it the first time we find it */
3549 if ((bInDecimal == FALSE))
3550 bInDecimal = TRUE;
3551 else
3552 return -1; /* ERROR: Invalid parameter */
3554 else
3556 /* It's neither a numeric character, nor a decimal point.
3557 * Thus, return an error.
3559 return -1;
3562 pInput++;
3565 /* Add an End of Line character to the output buffers */
3566 *psBefore = '\0';
3567 *psAfter = '\0';
3569 return 0;
3572 /**************************************************************************
3573 * This function is used just locally !
3574 * Description: A number could be formatted using different numbers
3575 * of "digits in group" (example: 4;3;2;0).
3576 * The first parameter of this function is an array
3577 * containing the rule to be used. It's format is the following:
3578 * |NDG|DG1|DG2|...|0|
3579 * where NDG is the number of used "digits in group" and DG1, DG2,
3580 * are the corresponding "digits in group".
3581 * Thus, this function returns the grouping value in the array
3582 * pointed by the second parameter.
3584 static INT OLE_GetGrouping(char* sRule, INT index)
3586 char sData[2], sRuleSize[2];
3587 INT nData, nRuleSize;
3589 memcpy(sRuleSize, sRule, 1);
3590 memcpy(sRuleSize+1, "\0", 1);
3591 nRuleSize = atoi(sRuleSize);
3593 if (index > 0 && index < nRuleSize)
3595 memcpy(sData, sRule+index, 1);
3596 memcpy(sData+1, "\0", 1);
3597 nData = atoi(sData);
3600 else
3602 memcpy(sData, sRule+nRuleSize-1, 1);
3603 memcpy(sData+1, "\0", 1);
3604 nData = atoi(sData);
3607 return nData;
3610 /**************************************************************************
3611 * GetNumberFormatA (KERNEL32.355)
3613 INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
3614 LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
3615 LPSTR lpNumberStr, int cchNumber)
3617 char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
3618 INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
3619 char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
3620 char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
3621 char *pStr = NULL, *pTmpStr = NULL;
3622 LCID systemDefaultLCID;
3623 BOOL bNegative = FALSE;
3624 enum Operations
3626 USE_PARAMETER,
3627 USE_LOCALEINFO,
3628 USE_SYSTEMDEFAULT,
3629 RETURN_ERROR
3630 } used_operation;
3632 strncpy(sNumber, lpvalue, 128);
3633 sNumber[127] = '\0';
3635 /* Make sure we have a valid input string, get the number
3636 * of digits before and after the decimal symbol, and check
3637 * if this is a negative number.
3639 if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
3641 nNumberDecimal = strlen(sDigitsBeforeDecimal);
3642 nDigits = strlen(sDigitsAfterDecimal);
3644 else
3646 SetLastError(ERROR_INVALID_PARAMETER);
3647 return 0;
3650 /* Which source will we use to format the string */
3651 used_operation = RETURN_ERROR;
3652 if (lpFormat != NULL)
3654 if (dwflags == 0)
3655 used_operation = USE_PARAMETER;
3657 else
3659 if (dwflags & LOCALE_NOUSEROVERRIDE)
3660 used_operation = USE_LOCALEINFO;
3661 else
3662 used_operation = USE_SYSTEMDEFAULT;
3665 /* Load the fields we need */
3666 switch(used_operation)
3668 case USE_LOCALEINFO:
3669 GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3670 GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3671 GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3672 GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3673 GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3674 GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3675 break;
3676 case USE_PARAMETER:
3677 sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
3678 strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
3679 sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
3680 strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
3681 sprintf(sILZero, "%d",lpFormat->LeadingZero);
3682 sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
3683 break;
3684 case USE_SYSTEMDEFAULT:
3685 systemDefaultLCID = GetSystemDefaultLCID();
3686 GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3687 GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3688 GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3689 GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3690 GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3691 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3692 break;
3693 default:
3694 SetLastError(ERROR_INVALID_PARAMETER);
3695 return 0;
3698 nNumberDigits = atoi(sNumberDigits);
3700 /* Remove the ";" */
3701 i=0;
3702 j = 1;
3703 for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
3705 if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
3707 memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
3708 i++;
3709 j++;
3712 sprintf(sBuffer, "%d", i);
3713 memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3714 memcpy(sRule + j, "\0", 1);
3716 /* First, format the digits before the decimal. */
3717 if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
3719 /* Working on an inverted string is easier ! */
3720 OLE_InvertString(sDigitsBeforeDecimal);
3722 nStep = nCounter = i = j = 0;
3723 nRuleIndex = 1;
3724 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3726 /* Here, we will loop until we reach the end of the string.
3727 * An internal counter (j) is used in order to know when to
3728 * insert the "digit group symbol".
3730 while (nNumberDecimal > 0)
3732 i = nCounter + nStep;
3733 memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
3734 nCounter++;
3735 j++;
3736 if (j >= nGrouping)
3738 j = 0;
3739 if (nRuleIndex < sRule[0])
3740 nRuleIndex++;
3741 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3742 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
3743 nStep+= strlen(sDigitGroupSymbol);
3746 nNumberDecimal--;
3749 memcpy(sDestination + i+1, "\0", 1);
3750 /* Get the string in the right order ! */
3751 OLE_InvertString(sDestination);
3753 else
3755 nLZ = atoi(sILZero);
3756 if (nLZ != 0)
3758 /* Use 0.xxx instead of .xxx */
3759 memcpy(sDestination, "0", 1);
3760 memcpy(sDestination+1, "\0", 1);
3762 else
3763 memcpy(sDestination, "\0", 1);
3767 /* Second, format the digits after the decimal. */
3768 j = 0;
3769 nCounter = nNumberDigits;
3770 if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
3772 i = strlen(sNumber) - strlen(pStr) + 1;
3773 strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
3774 j = strlen(sDigitsAfterDecimal);
3775 if (j < nNumberDigits)
3776 nCounter = nNumberDigits-j;
3778 for (i=0;i<nCounter;i++)
3779 memcpy(sDigitsAfterDecimal+i+j, "0", 1);
3780 memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
3782 i = strlen(sDestination);
3783 j = strlen(sDigitsAfterDecimal);
3784 /* Finally, construct the resulting formatted string. */
3786 for (nCounter=0; nCounter<i; nCounter++)
3787 memcpy(sNumber + nCounter, sDestination + nCounter, 1);
3789 memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
3791 for (i=0; i<j; i++)
3792 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
3793 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
3795 /* Is it a negative number */
3796 if (bNegative == TRUE)
3798 i = atoi(sNegNumber);
3799 pStr = sDestination;
3800 pTmpStr = sNumber;
3801 switch (i)
3803 case 0:
3804 *pStr++ = '(';
3805 while (*sNumber != '\0')
3806 *pStr++ = *pTmpStr++;
3807 *pStr++ = ')';
3808 break;
3809 case 1:
3810 *pStr++ = '-';
3811 while (*pTmpStr != '\0')
3812 *pStr++ = *pTmpStr++;
3813 break;
3814 case 2:
3815 *pStr++ = '-';
3816 *pStr++ = ' ';
3817 while (*pTmpStr != '\0')
3818 *pStr++ = *pTmpStr++;
3819 break;
3820 case 3:
3821 while (*pTmpStr != '\0')
3822 *pStr++ = *pTmpStr++;
3823 *pStr++ = '-';
3824 break;
3825 case 4:
3826 while (*pTmpStr != '\0')
3827 *pStr++ = *pTmpStr++;
3828 *pStr++ = ' ';
3829 *pStr++ = '-';
3830 break;
3831 default:
3832 while (*pTmpStr != '\0')
3833 *pStr++ = *pTmpStr++;
3834 break;
3837 else
3838 strcpy(sDestination, sNumber);
3840 /* If cchNumber is zero, then returns the number of bytes or characters
3841 * required to hold the formatted number string
3843 if (cchNumber==0)
3844 retVal = strlen(sDestination) + 1;
3845 else
3847 strncpy (lpNumberStr, sDestination, cchNumber-1);
3848 *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
3849 retVal = strlen(lpNumberStr);
3852 return retVal;
3855 /**************************************************************************
3856 * GetNumberFormatW (KERNEL32.@)
3858 INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
3859 LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
3860 LPWSTR lpNumberStr, int cchNumber)
3862 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue));
3864 lstrcpynW( lpNumberStr, lpvalue, cchNumber );
3865 return cchNumber? strlenW( lpNumberStr ) : 0;
3868 /**************************************************************************
3869 * GetCurrencyFormatA (KERNEL32.302)
3871 INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
3872 LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
3873 LPSTR lpCurrencyStr, int cchCurrency)
3875 UINT nPosOrder, nNegOrder;
3876 INT retVal;
3877 char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
3878 char *pDestination = sDestination;
3879 char sNumberFormated[128];
3880 char *pNumberFormated = sNumberFormated;
3881 LCID systemDefaultLCID;
3882 BOOL bIsPositive = FALSE, bValidFormat = FALSE;
3883 enum Operations
3885 USE_PARAMETER,
3886 USE_LOCALEINFO,
3887 USE_SYSTEMDEFAULT,
3888 RETURN_ERROR
3889 } used_operation;
3891 NUMBERFMTA numberFmt;
3893 /* Which source will we use to format the string */
3894 used_operation = RETURN_ERROR;
3895 if (lpFormat != NULL)
3897 if (dwflags == 0)
3898 used_operation = USE_PARAMETER;
3900 else
3902 if (dwflags & LOCALE_NOUSEROVERRIDE)
3903 used_operation = USE_LOCALEINFO;
3904 else
3905 used_operation = USE_SYSTEMDEFAULT;
3908 /* Load the fields we need */
3909 switch(used_operation)
3911 case USE_LOCALEINFO:
3912 /* Specific to CURRENCYFMTA*/
3913 GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3914 GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3915 GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3917 nPosOrder = atoi(sPosOrder);
3918 nNegOrder = atoi(sNegOrder);
3919 break;
3920 case USE_PARAMETER:
3921 /* Specific to CURRENCYFMTA*/
3922 nNegOrder = lpFormat->NegativeOrder;
3923 nPosOrder = lpFormat->PositiveOrder;
3924 strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
3925 break;
3926 case USE_SYSTEMDEFAULT:
3927 systemDefaultLCID = GetSystemDefaultLCID();
3928 /* Specific to CURRENCYFMTA*/
3929 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3930 GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3931 GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3933 nPosOrder = atoi(sPosOrder);
3934 nNegOrder = atoi(sNegOrder);
3935 break;
3936 default:
3937 SetLastError(ERROR_INVALID_PARAMETER);
3938 return 0;
3941 /* Construct a temporary number format structure */
3942 if (lpFormat != NULL)
3944 numberFmt.NumDigits = lpFormat->NumDigits;
3945 numberFmt.LeadingZero = lpFormat->LeadingZero;
3946 numberFmt.Grouping = lpFormat->Grouping;
3947 numberFmt.NegativeOrder = 0;
3948 numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
3949 numberFmt.lpThousandSep = lpFormat->lpThousandSep;
3950 bValidFormat = TRUE;
3953 /* Make a call to GetNumberFormatA() */
3954 if (*lpvalue == '-')
3956 bIsPositive = FALSE;
3957 retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3959 else
3961 bIsPositive = TRUE;
3962 retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3965 if (retVal == 0)
3966 return 0;
3968 /* construct the formatted string */
3969 if (bIsPositive)
3971 switch (nPosOrder)
3973 case 0: /* Prefix, no separation */
3974 strcpy (pDestination, sCurrencySymbol);
3975 strcat (pDestination, pNumberFormated);
3976 break;
3977 case 1: /* Suffix, no separation */
3978 strcpy (pDestination, pNumberFormated);
3979 strcat (pDestination, sCurrencySymbol);
3980 break;
3981 case 2: /* Prefix, 1 char separation */
3982 strcpy (pDestination, sCurrencySymbol);
3983 strcat (pDestination, " ");
3984 strcat (pDestination, pNumberFormated);
3985 break;
3986 case 3: /* Suffix, 1 char separation */
3987 strcpy (pDestination, pNumberFormated);
3988 strcat (pDestination, " ");
3989 strcat (pDestination, sCurrencySymbol);
3990 break;
3991 default:
3992 SetLastError(ERROR_INVALID_PARAMETER);
3993 return 0;
3996 else /* negative number */
3998 switch (nNegOrder)
4000 case 0: /* format: ($1.1) */
4001 strcpy (pDestination, "(");
4002 strcat (pDestination, sCurrencySymbol);
4003 strcat (pDestination, pNumberFormated);
4004 strcat (pDestination, ")");
4005 break;
4006 case 1: /* format: -$1.1 */
4007 strcpy (pDestination, "-");
4008 strcat (pDestination, sCurrencySymbol);
4009 strcat (pDestination, pNumberFormated);
4010 break;
4011 case 2: /* format: $-1.1 */
4012 strcpy (pDestination, sCurrencySymbol);
4013 strcat (pDestination, "-");
4014 strcat (pDestination, pNumberFormated);
4015 break;
4016 case 3: /* format: $1.1- */
4017 strcpy (pDestination, sCurrencySymbol);
4018 strcat (pDestination, pNumberFormated);
4019 strcat (pDestination, "-");
4020 break;
4021 case 4: /* format: (1.1$) */
4022 strcpy (pDestination, "(");
4023 strcat (pDestination, pNumberFormated);
4024 strcat (pDestination, sCurrencySymbol);
4025 strcat (pDestination, ")");
4026 break;
4027 case 5: /* format: -1.1$ */
4028 strcpy (pDestination, "-");
4029 strcat (pDestination, pNumberFormated);
4030 strcat (pDestination, sCurrencySymbol);
4031 break;
4032 case 6: /* format: 1.1-$ */
4033 strcpy (pDestination, pNumberFormated);
4034 strcat (pDestination, "-");
4035 strcat (pDestination, sCurrencySymbol);
4036 break;
4037 case 7: /* format: 1.1$- */
4038 strcpy (pDestination, pNumberFormated);
4039 strcat (pDestination, sCurrencySymbol);
4040 strcat (pDestination, "-");
4041 break;
4042 case 8: /* format: -1.1 $ */
4043 strcpy (pDestination, "-");
4044 strcat (pDestination, pNumberFormated);
4045 strcat (pDestination, " ");
4046 strcat (pDestination, sCurrencySymbol);
4047 break;
4048 case 9: /* format: -$ 1.1 */
4049 strcpy (pDestination, "-");
4050 strcat (pDestination, sCurrencySymbol);
4051 strcat (pDestination, " ");
4052 strcat (pDestination, pNumberFormated);
4053 break;
4054 case 10: /* format: 1.1 $- */
4055 strcpy (pDestination, pNumberFormated);
4056 strcat (pDestination, " ");
4057 strcat (pDestination, sCurrencySymbol);
4058 strcat (pDestination, "-");
4059 break;
4060 case 11: /* format: $ 1.1- */
4061 strcpy (pDestination, sCurrencySymbol);
4062 strcat (pDestination, " ");
4063 strcat (pDestination, pNumberFormated);
4064 strcat (pDestination, "-");
4065 break;
4066 case 12: /* format: $ -1.1 */
4067 strcpy (pDestination, sCurrencySymbol);
4068 strcat (pDestination, " ");
4069 strcat (pDestination, "-");
4070 strcat (pDestination, pNumberFormated);
4071 break;
4072 case 13: /* format: 1.1- $ */
4073 strcpy (pDestination, pNumberFormated);
4074 strcat (pDestination, "-");
4075 strcat (pDestination, " ");
4076 strcat (pDestination, sCurrencySymbol);
4077 break;
4078 case 14: /* format: ($ 1.1) */
4079 strcpy (pDestination, "(");
4080 strcat (pDestination, sCurrencySymbol);
4081 strcat (pDestination, " ");
4082 strcat (pDestination, pNumberFormated);
4083 strcat (pDestination, ")");
4084 break;
4085 case 15: /* format: (1.1 $) */
4086 strcpy (pDestination, "(");
4087 strcat (pDestination, pNumberFormated);
4088 strcat (pDestination, " ");
4089 strcat (pDestination, sCurrencySymbol);
4090 strcat (pDestination, ")");
4091 break;
4092 default:
4093 SetLastError(ERROR_INVALID_PARAMETER);
4094 return 0;
4098 if (cchCurrency == 0)
4099 return strlen(pDestination) + 1;
4101 else
4103 strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
4104 *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
4105 return strlen(lpCurrencyStr);
4109 /**************************************************************************
4110 * GetCurrencyFormatW (KERNEL32.303)
4112 INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
4113 LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
4114 LPWSTR lpCurrencyStr, int cchCurrency)
4116 FIXME("This API function is NOT implemented !\n");
4117 return 0;
4120 /******************************************************************************
4121 * OLE2NLS_CheckLocale [intern]
4123 static LCID OLE2NLS_CheckLocale (LCID locale)
4125 if (!locale)
4126 { locale = LOCALE_SYSTEM_DEFAULT;
4129 if (locale == LOCALE_SYSTEM_DEFAULT)
4130 { return GetSystemDefaultLCID();
4132 else if (locale == LOCALE_USER_DEFAULT)
4133 { return GetUserDefaultLCID();
4135 else
4136 { return locale;
4139 /******************************************************************************
4140 * GetTimeFormatA [KERNEL32.422]
4141 * Makes an ASCII string of the time
4143 * Formats date according to format, or locale default if format is
4144 * NULL. The format consists of literal characters and fields as follows:
4146 * h hours with no leading zero (12-hour)
4147 * hh hours with full two digits
4148 * H hours with no leading zero (24-hour)
4149 * HH hours with full two digits
4150 * m minutes with no leading zero
4151 * mm minutes with full two digits
4152 * s seconds with no leading zero
4153 * ss seconds with full two digits
4154 * t time marker (A or P)
4155 * tt time marker (AM, PM)
4158 INT WINAPI
4159 GetTimeFormatA(LCID locale, /* [in] */
4160 DWORD flags, /* [in] */
4161 LPSYSTEMTIME xtime, /* [in] */
4162 LPCSTR format, /* [in] */
4163 LPSTR timestr, /* [out] */
4164 INT timelen /* [in] */)
4165 { char format_buf[40];
4166 LPCSTR thisformat;
4167 SYSTEMTIME t;
4168 LPSYSTEMTIME thistime;
4169 LCID thislocale=0;
4170 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4171 INT ret;
4173 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
4175 thislocale = OLE2NLS_CheckLocale ( locale );
4177 if (format == NULL)
4178 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4179 { thislocale = GetSystemDefaultLCID();
4181 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
4182 thisformat = format_buf;
4184 else
4185 { thisformat = format;
4188 if (xtime == NULL) /* NULL means use the current local time*/
4189 { GetLocalTime(&t);
4190 thistime = &t;
4192 else
4193 { thistime = xtime;
4194 /* Check that hour,min and sec is in range */
4196 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
4197 timestr, timelen);
4198 return ret;
4202 /******************************************************************************
4203 * GetTimeFormatW [KERNEL32.423]
4204 * Makes a Unicode string of the time
4206 INT WINAPI
4207 GetTimeFormatW(LCID locale, /* [in] */
4208 DWORD flags, /* [in] */
4209 LPSYSTEMTIME xtime, /* [in] */
4210 LPCWSTR format, /* [in] */
4211 LPWSTR timestr, /* [out] */
4212 INT timelen /* [in] */)
4213 { WCHAR format_buf[40];
4214 LPCWSTR thisformat;
4215 SYSTEMTIME t;
4216 LPSYSTEMTIME thistime;
4217 LCID thislocale=0;
4218 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4219 INT ret;
4221 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
4222 xtime,debugstr_w(format),timestr,timelen);
4224 thislocale = OLE2NLS_CheckLocale ( locale );
4226 if (format == NULL)
4227 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4228 { thislocale = GetSystemDefaultLCID();
4230 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
4231 thisformat = format_buf;
4233 else
4234 { thisformat = format;
4237 if (xtime == NULL) /* NULL means use the current local time*/
4238 { GetLocalTime(&t);
4239 thistime = &t;
4241 else
4242 { thistime = xtime;
4245 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
4246 timestr, timelen);
4247 return ret;
4250 /******************************************************************************
4251 * EnumCalendarInfoA [KERNEL32.196]
4253 BOOL WINAPI EnumCalendarInfoA(
4254 CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
4256 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);
4257 return FALSE;