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
19 #include "wine/unicode.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.
34 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
35 static const struct tagLOCALE_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),
55 LOCALE_ENTRY(IMEASURE),
56 LOCALE_ENTRY(SDECIMAL),
57 LOCALE_ENTRY(STHOUSAND),
58 LOCALE_ENTRY(SGROUPING),
59 LOCALE_ENTRY(IDIGITS),
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),
74 LOCALE_ENTRY(SSHORTDATE),
75 LOCALE_ENTRY(SLONGDATE),
76 LOCALE_ENTRY(STIMEFORMAT),
80 LOCALE_ENTRY(ITIMEMARKPOSN),
81 LOCALE_ENTRY(ICENTURY),
82 LOCALE_ENTRY(ITLZERO),
83 LOCALE_ENTRY(IDAYLZERO),
84 LOCALE_ENTRY(IMONLZERO),
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),
145 static char *GetLocaleSubkeyName( DWORD lctype );
147 /***********************************************************************
148 * GetUserDefaultLCID (KERNEL32.@)
150 LCID WINAPI GetUserDefaultLCID(void)
152 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT );
155 /***********************************************************************
156 * GetSystemDefaultLCID (KERNEL32.@)
158 LCID WINAPI GetSystemDefaultLCID(void)
160 return GetUserDefaultLCID();
163 #define NLS_MAX_LANGUAGES 20
167 LANGID found_lang_id[NLS_MAX_LANGUAGES];
168 char found_language[NLS_MAX_LANGUAGES][3];
169 char found_country[NLS_MAX_LANGUAGES][3];
173 static BOOL CALLBACK NLS_FindLanguageID_ProcA(HMODULE hModule, LPCSTR type,
174 LPCSTR name, WORD LangID, LONG lParam)
176 LANG_FIND_DATA *l_data = (LANG_FIND_DATA *)lParam;
177 LCID lcid = MAKELCID(LangID, SORT_DEFAULT);
178 char buf_language[128];
179 char buf_country[128];
180 char buf_en_language[128];
182 TRACE("%04X\n", (UINT)LangID);
183 if(PRIMARYLANGID(LangID) == LANG_NEUTRAL)
184 return TRUE; /* continue search */
189 GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME|LOCALE_NOUSEROVERRIDE,
190 buf_language, sizeof(buf_language));
191 TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language);
193 GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME|LOCALE_NOUSEROVERRIDE,
194 buf_country, sizeof(buf_country));
195 TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country);
197 if(l_data->lang && strlen(l_data->lang) > 0 && !strcasecmp(l_data->lang, buf_language))
199 if(l_data->country && strlen(l_data->country) > 0)
201 if(!strcasecmp(l_data->country, buf_country))
203 l_data->found_lang_id[0] = LangID;
205 TRACE("Found lang_id %04X for %s_%s\n", LangID, l_data->lang, l_data->country);
206 return FALSE; /* stop enumeration */
209 else /* l_data->country not specified */
211 if(l_data->n_found < NLS_MAX_LANGUAGES)
213 l_data->found_lang_id[l_data->n_found] = LangID;
214 strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
215 strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
217 TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
218 return TRUE; /* continue search */
223 /* Just in case, check LOCALE_SENGLANGUAGE too,
224 * in hope that possible alias name might have that value.
226 buf_en_language[0] = 0;
227 GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE|LOCALE_NOUSEROVERRIDE,
228 buf_en_language, sizeof(buf_en_language));
229 TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language);
231 if(l_data->lang && strlen(l_data->lang) > 0 && !strcasecmp(l_data->lang, buf_en_language))
233 l_data->found_lang_id[l_data->n_found] = LangID;
234 strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
235 strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
237 TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
240 return TRUE; /* continue search */
243 /***********************************************************************
247 * Lang: a string whose two first chars are the iso name of a language.
248 * Country: a string whose two first chars are the iso name of country
249 * Charset: a string defining the chossen charset encoding
250 * Dialect: a string defining a variation of the locale
252 * all those values are from the standardized format of locale
253 * name in unix which is: Lang[_Country][.Charset][@Dialect]
256 * the numeric code of the language used by Windows
258 * FIXME: Charset and Dialect are not handled
260 static LANGID NLS_GetLanguageID(LPCSTR Lang, LPCSTR Country, LPCSTR Charset, LPCSTR Dialect)
262 LANG_FIND_DATA l_data;
263 char lang_string[256];
267 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
271 memset(&l_data, 0, sizeof(LANG_FIND_DATA));
272 strncpy(l_data.lang, Lang, sizeof(l_data.lang));
274 if(Country && strlen(Country) > 0)
275 strncpy(l_data.country, Country, sizeof(l_data.country));
277 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
278 (LPCSTR)LOCALE_ILANGUAGE, NLS_FindLanguageID_ProcA, (LONG)&l_data);
280 strcpy(lang_string, l_data.lang);
281 if(l_data.country && strlen(l_data.country) > 0)
283 strcat(lang_string, "_");
284 strcat(lang_string, l_data.country);
289 if(l_data.country && strlen(l_data.country) > 0)
291 MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string);
292 l_data.country[0] = 0;
293 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
294 (LPCSTR)LOCALE_ILANGUAGE, NLS_FindLanguageID_ProcA, (LONG)&l_data);
298 /* Re-evaluate lang_string */
299 strcpy(lang_string, l_data.lang);
300 if(l_data.country && strlen(l_data.country) > 0)
302 strcat(lang_string, "_");
303 strcat(lang_string, l_data.country);
308 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string);
309 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
313 if(l_data.n_found == 1)
314 TRACE("For language '%s' lang_id %04X was found\n", lang_string, l_data.found_lang_id[0]);
315 else /* l_data->n_found > 1 */
318 MESSAGE("For language '%s' several language ids were found:\n", lang_string);
319 for(i = 0; i < l_data.n_found; i++)
320 MESSAGE("%s_%s - %04X; ", l_data.found_language[i], l_data.found_country[i], l_data.found_lang_id[i]);
322 MESSAGE("\nInstead of using first in the list, suggest to define\n"
323 "your LANG environment variable like this: LANG=%s_%s\n",
324 l_data.found_language[0], l_data.found_country[0]);
328 TRACE("Returning %04X\n", l_data.found_lang_id[0]);
329 return l_data.found_lang_id[0];
332 /***********************************************************************
333 * GetUserDefaultLangID (KERNEL32.@)
335 LANGID WINAPI GetUserDefaultLangID(void)
337 /* caching result, if defined from environment, which should (?) not change during a WINE session */
338 static LANGID userLCID = 0;
343 char *lang,*country,*charset,*dialect,*next;
345 if (GetEnvironmentVariableA( "LANGUAGE", buf, sizeof(buf) )) goto ok;
346 if (GetEnvironmentVariableA( "LANG", buf, sizeof(buf) )) goto ok;
347 if (GetEnvironmentVariableA( "LC_ALL", buf, sizeof(buf) )) goto ok;
348 if (GetEnvironmentVariableA( "LC_MESSAGES", buf, sizeof(buf) )) goto ok;
349 if (GetEnvironmentVariableA( "LC_CTYPE", buf, sizeof(buf) )) goto ok;
351 return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
354 if (!strcmp(buf,"POSIX") || !strcmp(buf,"C"))
355 return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
360 next=strchr(lang,':'); if (next) *next++='\0';
361 dialect=strchr(lang,'@'); if (dialect) *dialect++='\0';
362 charset=strchr(lang,'.'); if (charset) *charset++='\0';
363 country=strchr(lang,'_'); if (country) *country++='\0';
365 userLCID = NLS_GetLanguageID(lang, country, charset, dialect);
368 } while (lang && !userLCID);
372 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
374 userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
380 /***********************************************************************
381 * GetSystemDefaultLangID (KERNEL32.@)
383 LANGID WINAPI GetSystemDefaultLangID(void)
385 return GetUserDefaultLangID();
388 /******************************************************************************
389 * ConvertDefaultLocale (KERNEL32.@)
391 LCID WINAPI ConvertDefaultLocale (LCID lcid)
393 { case LOCALE_SYSTEM_DEFAULT:
394 return GetSystemDefaultLCID();
395 case LOCALE_USER_DEFAULT:
396 return GetUserDefaultLCID();
398 return MAKELCID (LANG_NEUTRAL, SUBLANG_NEUTRAL);
400 return MAKELANGID( PRIMARYLANGID(lcid), SUBLANG_NEUTRAL);
403 /* Enhanced version of LoadStringW.
404 * It takes LanguageId to find and load language dependant resources.
405 * Resource is copied as is: "binary" strings are not truncated.
406 * Return: length of resource + 1 to distinguish absent resources
407 * from the resources with zero length.
409 static INT NLS_LoadStringExW(HMODULE hModule, LANGID lang_id, UINT res_id, LPWSTR buffer, INT buflen)
417 /* Replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
418 if(SUBLANGID(lang_id) == SUBLANG_NEUTRAL)
419 lang_id = MAKELANGID(PRIMARYLANGID(lang_id), SUBLANG_DEFAULT);
421 hrsrc = FindResourceExW(hModule, RT_STRINGW, (LPCWSTR)((res_id >> 4) + 1), lang_id);
424 hmem = LoadResource(hModule, hrsrc);
427 p = LockResource(hmem);
428 string_num = res_id & 0x000f;
429 for(i = 0; i < string_num; i++)
432 TRACE("strlen = %d\n", (int)*p );
434 if (buffer == NULL) return *p;
435 i = min(buflen - 1, *p);
437 memcpy(buffer, p + 1, i * sizeof (WCHAR));
438 buffer[i] = (WCHAR) 0;
441 buffer[0] = (WCHAR) 0;
445 TRACE("%s loaded!\n", debugstr_w(buffer));
449 /******************************************************************************
450 * GetLocaleInfoA (KERNEL32.@)
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;
465 DWORD dwBufferSize=128;
468 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid,LCType,buf,len);
470 if (len && (! buf) ) {
471 SetLastError(ERROR_INSUFFICIENT_BUFFER);
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)) )
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;
512 /* If not in the registry, get it from the NLS entries. */
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;
526 /* if not found report a most descriptive error */
529 /* If we are through all of this, retLen should not be zero anymore.
530 If it is, the value is not supported */
532 while (locale_name2id[i].name!=NULL) {
533 if (LCType == locale_name2id[i].id) {
534 retString = locale_name2id[i].name;
540 FIXME("Unkown LC type %lX\n", LCType);
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);
550 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
551 if (LCType == LOCALE_FONTSIGNATURE) {
553 len = (len < sizeof(FONTSIGNATURE)) ? len : sizeof(FONTSIGNATURE);
554 memcpy(buf, retString, len);
557 return sizeof(FONTSIGNATURE);
559 /* if len=0 return only the length, don't touch the buffer*/
561 lstrcpynA(buf,retString,len);
562 return strlen(buf) + 1;
564 return strlen(retString)+1;
567 /******************************************************************************
568 * GetLocaleInfoW (KERNEL32.@)
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)
579 if (len && (! wbuf) )
580 { SetLastError(ERROR_INSUFFICIENT_BUFFER);
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);
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 )
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
613 case LOCALE_SDATE : /* The date separator. */
616 case LOCALE_ICURRDIGITS:
617 pacKey = "iCurrDigits";
619 case LOCALE_SDECIMAL :
622 case LOCALE_ICURRENCY:
623 pacKey = "iCurrency";
625 case LOCALE_SGROUPING :
626 pacKey = "sGrouping";
634 /* case LOCALE_ICALENDARTYPE: */
635 /* case LOCALE_IFIRSTDAYOFWEEK: */
636 /* case LOCALE_IFIRSTWEEKOFYEAR: */
637 /* case LOCALE_SYEARMONTH : */
638 /* case LOCALE_SPOSITIVESIGN : */
639 /* case LOCALE_IPAPERSIZE: */
641 case LOCALE_SLONGDATE :
642 pacKey = "sLongDate";
644 case LOCALE_SMONDECIMALSEP :
645 pacKey = "sMonDecimalSep";
647 case LOCALE_SMONGROUPING:
648 pacKey = "sMonGrouping";
650 case LOCALE_IMEASURE:
653 case LOCALE_SMONTHOUSANDSEP :
654 pacKey = "sMonThousandSep";
656 case LOCALE_INEGCURR:
659 case LOCALE_SNEGATIVESIGN :
660 pacKey = "sNegativeSign";
662 case LOCALE_INEGNUMBER:
663 pacKey = "iNegNumber";
665 case LOCALE_SSHORTDATE :
666 pacKey = "sShortDate";
668 case LOCALE_ILDATE: /* Long Date format ordering specifier. */
677 case LOCALE_ITIME: /* Time format specifier. */
680 case LOCALE_STHOUSAND :
681 pacKey = "sThousand";
683 case LOCALE_S1159: /* AM */
689 case LOCALE_S2359: /* PM */
692 case LOCALE_STIMEFORMAT :
693 pacKey = "sTimeFormat";
695 case LOCALE_SCURRENCY:
696 pacKey = "sCurrency";
699 /* The following are not listed under MSDN as supported,
700 * but seem to be used and also stored in the registry.
706 case LOCALE_SCOUNTRY:
709 case LOCALE_ICOUNTRY:
712 case LOCALE_SLANGUAGE:
713 pacKey = "sLanguage";
723 /******************************************************************************
724 * SetLocaleInfoA [KERNEL32.@]
726 BOOL WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
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 );
748 FIXME("(%ld,%ld,%s): stub\n",lcid,lctype,data);
753 /******************************************************************************
754 * IsValidLocale [KERNEL32.@]
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)))
765 static BOOL CALLBACK EnumResourceLanguagesProcW(HMODULE hModule, LPCWSTR type,
766 LPCWSTR name, WORD LangID, LONG lParam)
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.@]
779 BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum,
782 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
784 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW,
785 (LPCWSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcW,
786 (LONG)lpfnLocaleEnum);
791 static BOOL CALLBACK EnumResourceLanguagesProcA(HMODULE hModule, LPCSTR type,
792 LPCSTR name, WORD LangID, LONG lParam)
795 LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
796 sprintf(bufA, "%08X", (UINT)LangID);
797 return lpfnLocaleEnum(bufA);
800 /******************************************************************************
801 * EnumSystemLocalesA [KERNEL32.@]
803 BOOL WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum,
806 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
808 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
809 (LPCSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcA,
810 (LONG)lpfnLocaleEnum);
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, /*
\7f - 127 */
944 C2_NOTAPPLICABLE, /*
\80 - 128 */
945 C2_NOTAPPLICABLE, /*
\81 - 129 */
946 C2_OTHERNEUTRAL, /*
\82 - 130 */
947 C2_LEFTTORIGHT, /*
\83 - 131 */
948 C2_OTHERNEUTRAL, /*
\84 - 132 */
949 C2_OTHERNEUTRAL, /*
\85 - 133 */
950 C2_OTHERNEUTRAL, /*
\86 - 134 */
951 C2_OTHERNEUTRAL, /*
\87 - 135 */
952 C2_LEFTTORIGHT, /*
\88 - 136 */
953 C2_EUROPETERMINATOR, /*
\89 - 137 */
954 C2_LEFTTORIGHT, /*
\8a - 138 */
955 C2_OTHERNEUTRAL, /*
\8b - 139 */
956 C2_LEFTTORIGHT, /*
\8c - 140 */
957 C2_NOTAPPLICABLE, /*
\8d - 141 */
958 C2_NOTAPPLICABLE, /*
\8e - 142 */
959 C2_NOTAPPLICABLE, /*
\8f - 143 */
960 C2_NOTAPPLICABLE, /*
\90 - 144 */
961 C2_OTHERNEUTRAL, /*
\91 - 145 */
962 C2_OTHERNEUTRAL, /*
\92 - 146 */
963 C2_OTHERNEUTRAL, /*
\93 - 147 */
964 C2_OTHERNEUTRAL, /*
\94 - 148 */
965 C2_OTHERNEUTRAL, /*
\95 - 149 */
966 C2_OTHERNEUTRAL, /*
\96 - 150 */
967 C2_OTHERNEUTRAL, /*
\97 - 151 */
968 C2_LEFTTORIGHT, /*
\98 - 152 */
969 C2_OTHERNEUTRAL, /*
\99 - 153 */
970 C2_LEFTTORIGHT, /*
\9a - 154 */
971 C2_OTHERNEUTRAL, /*
\9b - 155 */
972 C2_LEFTTORIGHT, /*
\9c - 156 */
973 C2_NOTAPPLICABLE, /*
\9d - 157 */
974 C2_NOTAPPLICABLE, /*
\9e - 158 */
975 C2_LEFTTORIGHT, /*
\9f - 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 static const WORD OLE2NLS_CT_CType3_LUT[] = {
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, /*
\7f - 127 */
1203 0x0000, /*
\80 - 128 */
1204 0x0000, /*
\81 - 129 */
1205 0x0008, /*
\82 - 130 */
1206 0x8000, /*
\83 - 131 */
1207 0x0008, /*
\84 - 132 */
1208 0x0008, /*
\85 - 133 */
1209 0x0008, /*
\86 - 134 */
1210 0x0008, /*
\87 - 135 */
1211 0x0001, /*
\88 - 136 */
1212 0x0008, /*
\89 - 137 */
1213 0x8003, /*
\8a - 138 */
1214 0x0008, /*
\8b - 139 */
1215 0x8000, /*
\8c - 140 */
1216 0x0000, /*
\8d - 141 */
1217 0x0000, /*
\8e - 142 */
1218 0x0000, /*
\8f - 143 */
1219 0x0000, /*
\90 - 144 */
1220 0x0088, /*
\91 - 145 */
1221 0x0088, /*
\92 - 146 */
1222 0x0088, /*
\93 - 147 */
1223 0x0088, /*
\94 - 148 */
1224 0x0008, /*
\95 - 149 */
1225 0x0400, /*
\96 - 150 */
1226 0x0400, /*
\97 - 151 */
1227 0x0408, /*
\98 - 152 */
1228 0x0000, /*
\99 - 153 */
1229 0x8003, /*
\9a - 154 */
1230 0x0008, /*
\9b - 155 */
1231 0x8000, /*
\9c - 156 */
1232 0x0000, /*
\9d - 157 */
1233 0x0000, /*
\9e - 158 */
1234 0x8003, /*
\9f - 159 */
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.@]
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.@]
1345 * FIXME: Ignores the locale.
1347 BOOL WINAPI GetStringTypeExA(LCID locale,DWORD dwInfoType,LPCSTR src,
1348 INT cchSrc,LPWORD chartype)
1352 if ((src==NULL) || (chartype==NULL) || (src==(LPSTR)chartype))
1354 SetLastError(ERROR_INVALID_PARAMETER);
1359 cchSrc=strlen(src)+1;
1361 switch (dwInfoType) {
1363 for (i=0;i<cchSrc;i++)
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;
1381 for (i=0;i<cchSrc;i++)
1383 chartype[i]=(WORD)CT_CType2_LUT[i];
1388 for (i=0;i<cchSrc;i++)
1390 chartype[i]=OLE2NLS_CT_CType3_LUT[i];
1395 ERR("Unknown dwInfoType:%ld\n",dwInfoType);
1400 /***********************************************************************
1401 * VerLanguageNameA [KERNEL32.@]
1403 DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
1408 return GetLocaleInfoA(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
1411 /***********************************************************************
1412 * VerLanguageNameW [KERNEL32.@]
1414 DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
1419 return GetLocaleInfoW(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
1423 static const unsigned char LCM_Unicode_LUT[] = {
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 */
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, /*
\7f - 127 */
1551 6 , 30, /*
\80 - 128 */
1552 6 , 31, /*
\81 - 129 */
1553 7 , 123, /*
\82 - 130 */
1554 14 , 35, /*
\83 - 131 */
1555 7 , 127, /*
\84 - 132 */
1556 10 , 21, /*
\85 - 133 */
1557 10 , 15, /*
\86 - 134 */
1558 10 , 16, /*
\87 - 135 */
1559 7 , 67, /*
\88 - 136 */
1560 10 , 22, /*
\89 - 137 */
1561 14 , 145, /*
\8a - 138 */
1562 7 , 136, /*
\8b - 139 */
1563 14 + 16 , 124, /*
\8c - 140 */
1564 6 , 43, /*
\8d - 141 */
1565 6 , 44, /*
\8e - 142 */
1566 6 , 45, /*
\8f - 143 */
1567 6 , 46, /*
\90 - 144 */
1568 7 , 121, /*
\91 - 145 */
1569 7 , 122, /*
\92 - 146 */
1570 7 , 125, /*
\93 - 147 */
1571 7 , 126, /*
\94 - 148 */
1572 10 , 17, /*
\95 - 149 */
1573 6 , 137, /*
\96 - 150 */
1574 6 , 139, /*
\97 - 151 */
1575 7 , 93, /*
\98 - 152 */
1576 14 , 156, /*
\99 - 153 */
1577 14 , 145, /*
\9a - 154 */
1578 7 , 137, /*
\9b - 155 */
1579 14 + 16 , 124, /*
\9c - 156 */
1580 6 , 59, /*
\9d - 157 */
1581 6 , 60, /*
\9e - 158 */
1582 14 , 167, /*
\9f - 159 */
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, /*
\83 - 131 */
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]
1838 * FIXME: handle current locale
1840 static int OLE2NLS_isSymbol(unsigned char c)
1842 /* This function is used by LCMapStringA. Characters
1843 for which it returns true are ignored when mapping a
1844 string with NORM_IGNORESYMBOLS */
1845 return ( (c!=0) && !(isalpha(c) || isdigit(c)) );
1848 /******************************************************************************
1849 * identity [Internal]
1851 static int identity(int c)
1856 /*************************************************************************
1857 * LCMapStringA [KERNEL32.@]
1859 * Convert a string, or generate a sort key from it.
1861 * If (mapflags & LCMAP_SORTKEY), the function will generate
1862 * a sort key for the source string. Else, it will convert it
1863 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1867 * Success : length of the result string.
1870 * If called with scrlen = -1, the function will compute the length
1871 * of the 0-terminated string strsrc by itself.
1873 * If called with dstlen = 0, returns the buffer length that
1874 * would be required.
1876 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1877 * as if they are equal.
1878 * In the only code page implemented so far, there may not be
1879 * wide characters in strings passed to LCMapStringA,
1880 * so there is nothing to be done for this flag.
1882 INT WINAPI LCMapStringA(
1883 LCID lcid, /* [in] locale identifier created with MAKELCID;
1884 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1885 predefined values. */
1886 DWORD mapflags, /* [in] flags */
1887 LPCSTR srcstr, /* [in] source buffer */
1888 INT srclen, /* [in] source length */
1889 LPSTR dststr, /* [out] destination buffer */
1890 INT dstlen) /* [in] destination buffer length */
1894 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1895 lcid,mapflags,debugstr_an(srcstr,srclen),srclen,dststr,dstlen);
1897 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1899 ERR("(src=%s,dest=%s): Invalid NULL string\n",
1900 debugstr_an(srcstr,srclen), dststr);
1901 SetLastError(ERROR_INVALID_PARAMETER);
1905 srclen = strlen(srcstr) + 1 ; /* (include final '\0') */
1907 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1911 NORM_IGNORENONSPACE | \
1913 NORM_IGNOREWIDTH | \
1914 NORM_IGNOREKANATYPE)
1915 /* FIXME: as long as we don't support Katakana nor Hiragana
1916 * characters, we can support NORM_IGNOREKANATYPE
1918 if (mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS)
1920 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1921 "unimplemented flags: 0x%08lx\n",
1928 mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS
1932 if ( !(mapflags & LCMAP_SORTKEY) )
1935 int (*f)(int) = identity;
1936 int flag_ignorenonspace = mapflags & NORM_IGNORENONSPACE;
1937 int flag_ignoresymbols = mapflags & NORM_IGNORESYMBOLS;
1939 if (flag_ignorenonspace || flag_ignoresymbols)
1941 /* For some values of mapflags, the length of the resulting
1942 string is not known at this point. Windows does map the string
1943 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1947 /* Compute required length */
1948 for (i=j=0; i < srclen; i++)
1950 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1951 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1963 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1967 if (mapflags & LCMAP_UPPERCASE)
1969 else if (mapflags & LCMAP_LOWERCASE)
1971 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1972 for (i=j=0; (i<srclen) && (j<dstlen) ; i++)
1974 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1975 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1977 dststr[j] = (CHAR) f(srcstr[i]);
1984 /* FIXME: This function completely ignores the "lcid" parameter. */
1985 /* else ... (mapflags & LCMAP_SORTKEY) */
1989 int diacritic_len=0;
1990 int delayed_punctuation_len=0;
1991 char *case_component;
1992 char *diacritic_component;
1993 char *delayed_punctuation_component;
1995 int flag_stringsort = mapflags & SORT_STRINGSORT;
1997 /* compute how much room we will need */
1998 for (i=0;i<srclen;i++)
2001 unsigned char source_char = srcstr[i];
2002 if (source_char!='\0')
2004 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
2007 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
2008 unicode_len++; /* double letter */
2012 delayed_punctuation_len++;
2016 if (isupper(source_char))
2017 case_len=unicode_len;
2019 ofs = source_char - LCM_Diacritic_Start;
2020 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
2021 diacritic_len=unicode_len;
2024 if (mapflags & NORM_IGNORECASE)
2026 if (mapflags & NORM_IGNORENONSPACE)
2029 room = 2 * unicode_len /* "unicode" component */
2030 + diacritic_len /* "diacritic" component */
2031 + case_len /* "case" component */
2032 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
2033 + 4 /* four '\1' separators */
2034 + 1 ; /* terminal '\0' */
2037 else if (dstlen<room)
2039 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2043 /*FIXME the Pointercheck should not be nessesary */
2044 if (IsBadWritePtr (dststr,room))
2045 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
2046 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2050 /* locate each component, write separators */
2051 diacritic_component = dststr + 2*unicode_len ;
2052 *diacritic_component++ = '\1';
2053 case_component = diacritic_component + diacritic_len ;
2054 *case_component++ = '\1';
2055 delayed_punctuation_component = case_component + case_len ;
2056 *delayed_punctuation_component++ = '\1';
2057 *delayed_punctuation_component++ = '\1';
2059 /* read source string char by char, write
2060 corresponding weight in each component. */
2061 for (i=0,count=0;i<srclen;i++)
2063 unsigned char source_char=srcstr[i];
2064 if (source_char!='\0')
2067 type = LCM_Unicode_LUT[-2+2*source_char];
2068 longcode = type >> 4;
2070 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
2072 WORD encrypted_location = (1<<15) + 7 + 4*count;
2073 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
2074 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
2075 /* big-endian is used here because it lets string comparison be
2076 compatible with numerical comparison */
2078 *delayed_punctuation_component++ = type;
2079 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
2080 /* assumption : a punctuation character is never a
2081 double or accented letter */
2085 dststr[2*count] = type;
2086 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
2090 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2091 if (count<diacritic_len)
2092 diacritic_component[count] = 2; /* assumption: a double letter
2093 is never accented */
2096 dststr[2*count] = type;
2097 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
2098 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
2099 32 in the first column of LCM_Unicode_LUT --> longcode = 2
2100 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
2104 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2105 if (count<diacritic_len)
2107 int ofs = source_char - LCM_Diacritic_Start;
2108 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
2114 dststr[room-1] = '\0';
2119 /*************************************************************************
2120 * LCMapStringW [KERNEL32.@]
2122 * Convert a string, or generate a sort key from it.
2126 * See LCMapStringA for documentation
2128 INT WINAPI LCMapStringW(
2129 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT srclen,LPWSTR dststr,
2134 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2135 lcid, mapflags, srcstr, srclen, dststr, dstlen);
2137 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2139 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
2140 SetLastError(ERROR_INVALID_PARAMETER);
2144 srclen = strlenW(srcstr)+1;
2146 /* FIXME: Both this function and it's companion LCMapStringA()
2147 * completely ignore the "lcid" parameter. In place of the "lcid"
2148 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2149 * environment variable prior to invoking this function. */
2150 if (mapflags & LCMAP_SORTKEY)
2152 /* Possible values of LC_COLLATE. */
2153 char *lc_collate_default = 0; /* value prior to this function */
2154 char *lc_collate_env = 0; /* value retrieved from the environment */
2156 /* General purpose index into strings of any type. */
2159 /* Lengths of various strings where the length is measured in
2160 * wide characters for wide character strings and in bytes for
2161 * native strings. The lengths include the NULL terminator. */
2162 size_t returned_len = 0;
2163 size_t src_native_len = 0;
2164 size_t dst_native_len = 0;
2165 size_t dststr_libc_len = 0;
2167 /* Native (character set determined by locale) versions of the
2168 * strings source and destination strings. */
2169 LPSTR src_native = 0;
2170 LPSTR dst_native = 0;
2172 /* Version of the source and destination strings using the
2173 * "wchar_t" Unicode data type needed by various libc functions. */
2174 wchar_t *srcstr_libc = 0;
2175 wchar_t *dststr_libc = 0;
2177 if(!(srcstr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2178 srclen * sizeof(wchar_t))))
2180 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2181 srclen * sizeof(wchar_t));
2182 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2186 /* Convert source string to a libc Unicode string. */
2187 for(str_idx = 0; str_idx < srclen; str_idx++)
2189 srcstr_libc[str_idx] = srcstr[str_idx];
2192 /* src_native should contain at most 3 bytes for each
2193 * multibyte characters in the original srcstr string. */
2194 src_native_len = 3 * srclen;
2195 if(!(src_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0,
2198 ERR("Unable to allocate %d bytes for src_native\n", src_native_len);
2199 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2200 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2204 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2205 * current value is backed up so it can be restored after the
2206 * last LC_COLLATE sensitive function returns.
2208 * Even though the locale is adjusted for a minimum amount of
2209 * time a race condition exists where other threads may be
2210 * affected if they invoke LC_COLLATE sensitive functions. One
2211 * possible solution is to wrap all LC_COLLATE sensitive Wine
2212 * functions, like LCMapStringW(), in a mutex.
2214 * Another enhancement to the following would be to set the
2215 * LC_COLLATE locale category as a function of the "lcid"
2216 * parameter instead of the "LC_COLLATE" environment variable. */
2217 if(!(lc_collate_default = setlocale(LC_COLLATE, NULL)))
2219 ERR("Unable to query the LC_COLLATE catagory\n");
2220 SetLastError(ERROR_INVALID_PARAMETER);
2221 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2222 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2226 if(!(lc_collate_env = setlocale(LC_COLLATE, "")))
2228 ERR("Unable to inherit the LC_COLLATE locale category from the "
2229 "environment. The \"LC_COLLATE\" environment variable is "
2230 "\"%s\".\n", getenv("LC_COLLATE") ?
2231 getenv("LC_COLLATE") : "<unset>");
2232 SetLastError(ERROR_INVALID_PARAMETER);
2233 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2234 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2238 TRACE("lc_collate_default = %s\n", lc_collate_default);
2239 TRACE("lc_collate_env = %s\n", lc_collate_env);
2241 /* Convert the libc Unicode string to a native multibyte character
2243 returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1;
2244 if(returned_len == 0)
2246 LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(),
2248 ERR("wcstombs failed. The string specified (%s) may contains an "
2249 "invalid character.\n", srcstr_ascii);
2250 SetLastError(ERROR_INVALID_PARAMETER);
2251 if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii);
2252 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2253 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2254 setlocale(LC_COLLATE, lc_collate_default);
2257 else if(returned_len > src_native_len)
2259 src_native[src_native_len - 1] = 0;
2260 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2261 "than expected (%d bytes).\n", src_native, returned_len,
2264 /* Since this is an internal error I'm not sure what the correct
2266 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2268 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2269 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2270 setlocale(LC_COLLATE, lc_collate_default);
2273 src_native_len = returned_len;
2275 TRACE("src_native = %s src_native_len = %d\n",
2276 src_native, src_native_len);
2278 /* dst_native seems to contain at most 4 bytes for each byte in
2279 * the original src_native string. Change if need be since this
2280 * isn't documented by the strxfrm() man page. */
2281 dst_native_len = 4 * src_native_len;
2282 if(!(dst_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0, dst_native_len)))
2284 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len);
2285 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2286 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2287 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2288 setlocale(LC_COLLATE, lc_collate_default);
2292 /* The actual translation is done by the following call to
2293 * strxfrm(). The surrounding code could have been simplified
2294 * by calling wcsxfrm() instead except that wcsxfrm() is not
2295 * available on older Linux systems (RedHat 4.1 with
2298 * Also, it is possible that the translation could be done by
2299 * various tables as it is done in LCMapStringA(). However, I'm
2300 * not sure what those tables are. */
2301 returned_len = strxfrm(dst_native, src_native, dst_native_len) + 1;
2303 if(returned_len > dst_native_len)
2305 dst_native[dst_native_len - 1] = 0;
2306 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2307 "than expected (%d bytes).\n", dst_native, returned_len,
2310 /* Since this is an internal error I'm not sure what the correct
2312 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2314 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2315 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2316 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2317 setlocale(LC_COLLATE, lc_collate_default);
2320 dst_native_len = returned_len;
2322 TRACE("dst_native = %s dst_native_len = %d\n",
2323 dst_native, dst_native_len);
2325 dststr_libc_len = dst_native_len;
2326 if(!(dststr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2327 dststr_libc_len * sizeof(wchar_t))))
2329 ERR("Unable to allocate %d bytes for dststr_libc\n",
2330 dststr_libc_len * sizeof(wchar_t));
2331 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2332 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2333 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2334 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2335 setlocale(LC_COLLATE, lc_collate_default);
2339 /* Convert the native multibyte string to a libc Unicode string. */
2340 returned_len = mbstowcs(dststr_libc, dst_native, dst_native_len) + 1;
2342 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2343 * function has returned. */
2344 setlocale(LC_COLLATE, lc_collate_default);
2346 if(returned_len == 0)
2348 ERR("mbstowcs failed. The native version of the translated string "
2349 "(%s) may contain an invalid character.\n", dst_native);
2350 SetLastError(ERROR_INVALID_PARAMETER);
2351 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2352 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2353 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2354 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2359 if(returned_len > dstlen)
2361 ERR("mbstowcs returned a string that was longer (%d chars) "
2362 "than the buffer provided (%d chars).\n", returned_len,
2364 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2365 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2366 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2367 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2368 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2371 dstlen = returned_len;
2373 /* Convert a libc Unicode string to the destination string. */
2374 for(str_idx = 0; str_idx < dstlen; str_idx++)
2376 dststr[str_idx] = dststr_libc[str_idx];
2378 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2379 *(((int *)dststr) + 0),
2380 *(((int *)dststr) + 1),
2381 *(((int *)dststr) + 2),
2382 *(((int *)dststr) + 3));
2386 dstlen = returned_len;
2388 TRACE("dstlen (return) = %d\n", dstlen);
2389 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2390 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2391 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2392 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2397 int (*f)(int)=identity;
2403 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2407 if (mapflags & LCMAP_UPPERCASE)
2409 else if (mapflags & LCMAP_LOWERCASE)
2411 for (i=0; i < srclen; i++)
2412 dststr[i] = (WCHAR) f(srcstr[i]);
2418 /***********************************************************************
2419 * OLE2NLS_EstimateMappingLength
2421 * Estimates the number of characters required to hold the string
2422 * computed by LCMapStringA.
2424 * The size is always over-estimated, with a fixed limit on the
2425 * amount of estimation error.
2427 * Note that len == -1 is not permitted.
2429 static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
2430 LPCSTR str, DWORD len)
2432 /* Estimate only for small strings to keep the estimation error from
2433 * becoming too large. */
2434 if (len < 128) return len * 8 + 5;
2435 else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
2438 /******************************************************************************
2439 * CompareStringA [KERNEL32.@]
2440 * Compares two strings using locale
2444 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2449 * Defaults to a word sort, but uses a string sort if
2450 * SORT_STRINGSORT is set.
2451 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2455 * This implementation ignores the locale
2459 * Quite inefficient.
2461 UINT WINAPI CompareStringA(
2462 DWORD lcid, /* [in] locale ID */
2463 DWORD fdwStyle, /* [in] comparison-style options */
2464 LPCSTR s1, /* [in] first string */
2465 DWORD l1, /* [in] length of first string */
2466 LPCSTR s2, /* [in] second string */
2467 DWORD l2) /* [in] length of second string */
2469 int mapstring_flags;
2473 TRACE("%s and %s\n",
2474 debugstr_an (s1,l1), debugstr_an (s2,l2));
2476 if ( (s1==NULL) || (s2==NULL) )
2478 ERR("(s1=%s,s2=%s): Invalid NULL string\n",
2479 debugstr_an(s1,l1), debugstr_an(s2,l2));
2480 SetLastError(ERROR_INVALID_PARAMETER);
2484 if(fdwStyle & NORM_IGNORESYMBOLS)
2485 FIXME("IGNORESYMBOLS not supported\n");
2487 if (l1 == -1) l1 = strlen(s1);
2488 if (l2 == -1) l2 = strlen(s2);
2490 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2491 len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
2492 len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
2494 if ((len1==0)||(len2==0))
2495 return 0; /* something wrong happened */
2497 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
2499 if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
2500 || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2502 ERR("Bug in LCmapStringA.\n");
2507 /* strcmp doesn't necessarily return -1, 0, or 1 */
2508 result = strcmp(sk1,sk2);
2510 HeapFree(GetProcessHeap(),0,sk1);
2517 /* must be greater, if we reach this point */
2521 /******************************************************************************
2522 * CompareStringW [KERNEL32.@]
2523 * This implementation ignores the locale
2524 * FIXME : Does only string sort. Should
2525 * be reimplemented the same way as CompareStringA.
2527 UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
2528 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2531 if(fdwStyle & NORM_IGNORENONSPACE)
2532 FIXME("IGNORENONSPACE not supprted\n");
2533 if(fdwStyle & NORM_IGNORESYMBOLS)
2534 FIXME("IGNORESYMBOLS not supported\n");
2536 /* Is strcmp defaulting to string sort or to word sort?? */
2537 /* FIXME: Handle NORM_STRINGSORT */
2538 l1 = (l1==-1)?strlenW(s1):l1;
2539 l2 = (l2==-1)?strlenW(s2):l2;
2540 len = l1<l2 ? l1:l2;
2541 ret = (fdwStyle & NORM_IGNORECASE) ? strncmpiW(s1,s2,len) : strncmpW(s1,s2,len);
2542 /* not equal, return 1 or 3 */
2544 /* need to translate result */
2545 return ((int)ret < 0) ? 1 : 3;
2547 /* same len, return 2 */
2548 if(l1==l2) return 2;
2549 /* the longer one is lexically greater */
2550 return (l1<l2)? 1 : 3;
2553 /******************************************************************************
2554 * OLE_GetFormatA [Internal]
2557 * If datelen == 0, it should return the reguired string length.
2559 This function implements stuff for GetDateFormat() and
2562 d single-digit (no leading zero) day (of month)
2563 dd two-digit day (of month)
2564 ddd short day-of-week name
2565 dddd long day-of-week name
2566 M single-digit month
2568 MMM short month name
2569 MMMM full month name
2570 y two-digit year, no leading 0
2572 yyyy four-digit year
2574 h hours with no leading zero (12-hour)
2575 hh hours with full two digits
2576 H hours with no leading zero (24-hour)
2577 HH hours with full two digits
2578 m minutes with no leading zero
2579 mm minutes with full two digits
2580 s seconds with no leading zero
2581 ss seconds with full two digits
2582 t time marker (A or P)
2583 tt time marker (AM, PM)
2584 '' used to quote literal characters
2585 '' (within a quoted string) indicates a literal '
2587 These functions REQUIRE valid locale, date, and format.
2589 static INT OLE_GetFormatA(LCID locale,
2593 LPCSTR _format, /*in*/
2598 int count, type, inquote, Overflow;
2604 const char * _dgfmt[] = { "%d", "%02d" };
2605 const char ** dgfmt = _dgfmt - 1;
2607 /* report, for debugging */
2608 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",
2609 locale, flags, tflags,
2610 xtime->wYear,xtime->wMonth,xtime->wDayOfWeek,xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2611 _format, _format, date, datelen);
2614 FIXME("datelen = 0, returning 255\n");
2618 /* initalize state variables and output buffer */
2620 count = 0; inquote = 0; Overflow = 0;
2622 date[0] = buf[0] = '\0';
2624 strcpy(format,_format);
2626 /* alter the formatstring, while it works for all languages now in wine
2627 its possible that it fails when the time looks like ss:mm:hh as example*/
2628 if (tflags & (TIME_NOMINUTESORSECONDS))
2629 { if ((pos = strstr ( format, ":mm")))
2630 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2633 if (tflags & (TIME_NOSECONDS))
2634 { if ((pos = strstr ( format, ":ss")))
2635 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2639 for (inpos = 0;; inpos++) {
2640 /* 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]); */
2642 if (format[inpos] == '\'') {
2643 if (format[inpos+1] == '\'') {
2645 date[outpos++] = '\'';
2648 continue; /* we did nothing to the output */
2650 } else if (format[inpos] == '\0') {
2651 date[outpos++] = '\0';
2652 if (outpos > datelen) Overflow = 1;
2655 date[outpos++] = format[inpos];
2656 if (outpos > datelen) {
2658 date[outpos-1] = '\0'; /* this is the last place where
2659 it's safe to write */
2663 } else if ( (count && (format[inpos] != type))
2665 || (count == 2 && strchr("ghHmst", type)) ) {
2666 if (type == 'h' && (tflags & TIME_FORCE24HOURFORMAT)) type= 'H';
2669 GetLocaleInfoA(locale,
2671 + (xtime->wDayOfWeek+6)%7,
2673 } else if (count == 3) {
2674 GetLocaleInfoA(locale,
2675 LOCALE_SABBREVDAYNAME1
2676 + (xtime->wDayOfWeek+6)%7,
2679 sprintf(buf, dgfmt[count], xtime->wDay);
2681 } else if (type == 'M') {
2683 GetLocaleInfoA(locale,
2684 LOCALE_SABBREVMONTHNAME1
2685 + xtime->wMonth - 1,
2687 } else if (count == 4) {
2688 GetLocaleInfoA(locale,
2690 + xtime->wMonth - 1,
2693 sprintf(buf, dgfmt[count], xtime->wMonth);
2695 } else if (type == 'y') {
2697 sprintf(buf, "%d", xtime->wYear);
2698 } else if (count == 3) {
2700 WARN("unknown format, c=%c, n=%d\n", type, count);
2702 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2704 } else if (type == 'g') {
2706 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2710 WARN("unknown format, c=%c, n=%d\n", type, count);
2712 } else if (type == 'h') {
2713 /* gives us hours 1:00 -- 12:00 */
2714 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2715 } else if (type == 'H') {
2717 sprintf(buf, dgfmt[count], xtime->wHour);
2718 } else if ( type == 'm') {
2719 sprintf(buf, dgfmt[count], xtime->wMinute);
2720 } else if ( type == 's') {
2721 sprintf(buf, dgfmt[count], xtime->wSecond);
2722 } else if (type == 't') {
2723 if ((tflags & TIME_NOTIMEMARKER))
2725 else if (count == 1) {
2726 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2727 } else if (count == 2) {
2728 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2729 GetLocaleInfoA(locale,
2731 ? LOCALE_S1159 : LOCALE_S2359,
2736 /* we need to check the next char in the format string
2737 again, no matter what happened */
2740 /* add the contents of buf to the output */
2741 buflen = strlen(buf);
2742 if (outpos + buflen < datelen) {
2743 date[outpos] = '\0'; /* for strcat to hook onto */
2747 date[outpos] = '\0';
2748 strncat(date, buf, datelen - outpos);
2749 date[datelen - 1] = '\0';
2750 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2751 WARN("insufficient buffer\n");
2755 /* reset the variables we used to keep track of this item */
2758 } else if (format[inpos] == '\0') {
2759 /* we can't check for this at the loop-head, because
2760 that breaks the printing of the last format-item */
2761 date[outpos] = '\0';
2764 /* continuing a code for an item */
2767 } else if (strchr("hHmstyMdg", format[inpos])) {
2768 type = format[inpos];
2771 } else if (format[inpos] == '\'') {
2775 date[outpos++] = format[inpos];
2777 /* now deal with a possible buffer overflow */
2778 if (outpos >= datelen) {
2779 date[datelen - 1] = '\0';
2780 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2786 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2789 /* finish it off with a string terminator */
2792 if (outpos > datelen-1) outpos = datelen-1;
2793 date[outpos] = '\0';
2795 TRACE("returns string '%s', len %d\n", date, outpos);
2799 /******************************************************************************
2800 * OLE_GetFormatW [INTERNAL]
2802 static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
2805 LPWSTR output, INT outlen)
2808 int count, type=0, inquote;
2809 int Overflow; /* loop check */
2813 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2814 WCHAR arg2[] = {'%','0','2','d',0};
2816 int datevars=0, timevars=0;
2822 /* make a debug report */
2823 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2824 "%p with max len %d\n",
2825 locale, flags, tflags,
2826 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2827 debugstr_w(format), format, output, outlen);
2830 FIXME("outlen = 0, returning 255\n");
2834 /* initialize state variables */
2837 inquote = Overflow = 0;
2838 /* this is really just a sanity check */
2839 output[0] = buf[0] = 0;
2841 /* this loop is the core of the function */
2842 for (inpos = 0; /* we have several break points */ ; inpos++) {
2844 if (format[inpos] == (WCHAR) '\'') {
2845 if (format[inpos+1] == '\'') {
2847 output[outpos++] = '\'';
2852 } else if (format[inpos] == 0) {
2853 output[outpos++] = 0;
2854 if (outpos > outlen) Overflow = 1;
2855 break; /* normal exit (within a quote) */
2857 output[outpos++] = format[inpos]; /* copy input */
2858 if (outpos > outlen) {
2860 output[outpos-1] = 0;
2864 } else if ( (count && (format[inpos] != type))
2865 || ( (count==4 && type =='y') ||
2866 (count==4 && type =='M') ||
2867 (count==4 && type =='d') ||
2868 (count==2 && type =='g') ||
2869 (count==2 && type =='h') ||
2870 (count==2 && type =='H') ||
2871 (count==2 && type =='m') ||
2872 (count==2 && type =='s') ||
2873 (count==2 && type =='t') ) ) {
2878 GetLocaleInfoW(locale,
2879 LOCALE_SDAYNAME1 + (xtime->wDayOfWeek +6)%7,
2880 buf, sizeof(buf)/sizeof(WCHAR) );
2881 } else if (count == 3) {
2882 GetLocaleInfoW(locale,
2883 LOCALE_SABBREVDAYNAME1 +
2884 (xtime->wDayOfWeek +6)%7,
2885 buf, sizeof(buf)/sizeof(WCHAR) );
2887 sprintf( tmp, "%.*d", count, xtime->wDay );
2888 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2894 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
2895 xtime->wMonth -1, buf,
2896 sizeof(buf)/sizeof(WCHAR) );
2897 } else if (count == 3) {
2898 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
2899 xtime->wMonth -1, buf,
2900 sizeof(buf)/sizeof(WCHAR) );
2902 sprintf( tmp, "%.*d", count, xtime->wMonth );
2903 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2908 sprintf( tmp, "%d", xtime->wYear );
2909 } else if (count == 3) {
2910 strcpy( tmp, "yyy" );
2912 sprintf( tmp, "%.*d", count, xtime->wYear % 100 );
2914 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2919 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2920 strcpy( tmp, "AD" );
2922 /* Win API sez we copy it verbatim */
2925 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2929 /* hours 1:00-12:00 --- is this right? */
2930 sprintf( tmp, "%.*d", count, (xtime->wHour-1)%12 +1);
2931 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2935 sprintf( tmp, "%.*d", count, xtime->wHour );
2936 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2940 sprintf( tmp, "%.*d", count, xtime->wMinute );
2941 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2945 sprintf( tmp, "%.*d", count, xtime->wSecond );
2946 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2950 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
2951 LOCALE_S1159 : LOCALE_S2359,
2959 /* no matter what happened, we need to check this next
2960 character the next time we loop through */
2963 /* cat buf onto the output */
2964 outlen = strlenW(buf);
2965 if (outpos + buflen < outlen) {
2966 strcpyW( output + outpos, buf );
2969 lstrcpynW( output + outpos, buf, outlen - outpos );
2971 break; /* Abnormal exit */
2974 /* reset the variables we used this time */
2977 } else if (format[inpos] == 0) {
2978 /* we can't check for this at the beginning, because that
2979 would keep us from printing a format spec that ended the
2982 break; /* NORMAL EXIT */
2984 /* how we keep track of the middle of a format spec */
2987 } else if ( (datevars && (format[inpos]=='d' ||
2988 format[inpos]=='M' ||
2989 format[inpos]=='y' ||
2990 format[inpos]=='g') ) ||
2991 (timevars && (format[inpos]=='H' ||
2992 format[inpos]=='h' ||
2993 format[inpos]=='m' ||
2994 format[inpos]=='s' ||
2995 format[inpos]=='t') ) ) {
2996 type = format[inpos];
2999 } else if (format[inpos] == '\'') {
3003 /* unquoted literals */
3004 output[outpos++] = format[inpos];
3009 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3010 WARN(" buffer overflow\n");
3013 /* final string terminator and sanity check */
3015 if (outpos > outlen-1) outpos = outlen-1;
3016 output[outpos] = '0';
3018 TRACE(" returning %s\n", debugstr_w(output));
3020 return (!Overflow) ? outlen : 0;
3025 /******************************************************************************
3026 * GetDateFormatA [KERNEL32.@]
3027 * Makes an ASCII string of the date
3029 * This function uses format to format the date, or, if format
3030 * is NULL, uses the default for the locale. format is a string
3031 * of literal fields and characters as follows:
3033 * - d single-digit (no leading zero) day (of month)
3034 * - dd two-digit day (of month)
3035 * - ddd short day-of-week name
3036 * - dddd long day-of-week name
3037 * - M single-digit month
3038 * - MM two-digit month
3039 * - MMM short month name
3040 * - MMMM full month name
3041 * - y two-digit year, no leading 0
3042 * - yy two-digit year
3043 * - yyyy four-digit year
3047 INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
3049 LPCSTR format, LPSTR date,INT datelen)
3052 char format_buf[40];
3055 LPSYSTEMTIME thistime;
3061 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
3062 locale,flags,xtime,format,date,datelen);
3065 locale = LOCALE_SYSTEM_DEFAULT;
3068 if (locale == LOCALE_SYSTEM_DEFAULT) {
3069 thislocale = GetSystemDefaultLCID();
3070 } else if (locale == LOCALE_USER_DEFAULT) {
3071 thislocale = GetUserDefaultLCID();
3073 thislocale = locale;
3076 if (xtime == NULL) {
3079 /* Silently correct wDayOfWeek by transforming to FileTime and back again */
3080 res=SystemTimeToFileTime(xtime,&ft);
3081 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error */
3082 /*FIXME: SystemTimeToFileTime doesn't yet do that check */
3085 SetLastError(ERROR_INVALID_PARAMETER);
3088 FileTimeToSystemTime(&ft,&t);
3093 if (format == NULL) {
3094 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
3096 : LOCALE_SSHORTDATE),
3097 format_buf, sizeof(format_buf));
3098 thisformat = format_buf;
3100 thisformat = format;
3104 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
3109 "GetDateFormatA() returning %d, with data=%s\n",
3114 /******************************************************************************
3115 * GetDateFormatW [KERNEL32.@]
3116 * Makes a Unicode string of the date
3118 * Acts the same as GetDateFormatA(), except that it's Unicode.
3119 * Accepts & returns sizes as counts of Unicode characters.
3122 INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
3125 LPWSTR date, INT datelen)
3127 unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
3129 FIXME("STUB (should call OLE_GetFormatW)\n");
3130 lstrcpynW(date, datearr, datelen);
3131 return ( datelen < 9) ? datelen : 9;
3136 /**************************************************************************
3137 * EnumDateFormatsA (KERNEL32.@)
3139 BOOL WINAPI EnumDateFormatsA(
3140 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3142 LCID Loc = GetUserDefaultLCID();
3143 if(!lpDateFmtEnumProc)
3145 SetLastError(ERROR_INVALID_PARAMETER);
3152 case 0x00000407: /* (Loc,"de_DE") */
3156 case DATE_SHORTDATE:
3157 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3158 if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
3159 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3160 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3163 if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
3164 if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
3165 if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
3168 FIXME("Unknown date format (%ld)\n", dwFlags);
3169 SetLastError(ERROR_INVALID_PARAMETER);
3174 case 0x0000040c: /* (Loc,"fr_FR") */
3178 case DATE_SHORTDATE:
3179 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3180 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3181 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3182 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3185 if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
3186 if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
3187 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3190 FIXME("Unknown date format (%ld)\n", dwFlags);
3191 SetLastError(ERROR_INVALID_PARAMETER);
3196 case 0x00000c0c: /* (Loc,"fr_CA") */
3200 case DATE_SHORTDATE:
3201 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3202 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3203 if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
3204 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3207 if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
3208 if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
3211 FIXME("Unknown date format (%ld)\n", dwFlags);
3212 SetLastError(ERROR_INVALID_PARAMETER);
3217 case 0x00000809: /* (Loc,"en_UK") */
3221 case DATE_SHORTDATE:
3222 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3223 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3224 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3225 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3228 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3229 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3232 FIXME("Unknown date format (%ld)\n", dwFlags);
3233 SetLastError(ERROR_INVALID_PARAMETER);
3238 case 0x00000c09: /* (Loc,"en_AU") */
3242 case DATE_SHORTDATE:
3243 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3244 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3245 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3248 if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
3249 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3252 FIXME("Unknown date format (%ld)\n", dwFlags);
3253 SetLastError(ERROR_INVALID_PARAMETER);
3258 case 0x00001009: /* (Loc,"en_CA") */
3262 case DATE_SHORTDATE:
3263 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3264 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3265 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3266 if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
3269 if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
3270 if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
3273 FIXME("Unknown date format (%ld)\n", dwFlags);
3274 SetLastError(ERROR_INVALID_PARAMETER);
3279 case 0x00001409: /* (Loc,"en_NZ") */
3283 case DATE_SHORTDATE:
3284 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3285 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3286 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3289 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3290 if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
3293 FIXME("Unknown date format (%ld)\n", dwFlags);
3294 SetLastError(ERROR_INVALID_PARAMETER);
3299 case 0x00001809: /* (Loc,"en_IE") */
3303 case DATE_SHORTDATE:
3304 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3305 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3306 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3309 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3310 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3313 FIXME("Unknown date format (%ld)\n", dwFlags);
3314 SetLastError(ERROR_INVALID_PARAMETER);
3319 case 0x00001c09: /* (Loc,"en_ZA") */
3323 case DATE_SHORTDATE:
3324 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3327 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3330 FIXME("Unknown date format (%ld)\n", dwFlags);
3331 SetLastError(ERROR_INVALID_PARAMETER);
3336 case 0x00002009: /* (Loc,"en_JM") */
3340 case DATE_SHORTDATE:
3341 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3344 if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
3345 if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
3346 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
3347 if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
3350 FIXME("Unknown date format (%ld)\n", dwFlags);
3351 SetLastError(ERROR_INVALID_PARAMETER);
3356 case 0x00002809: /* (Loc,"en_BZ") */
3357 case 0x00002c09: /* (Loc,"en_TT") */
3361 case DATE_SHORTDATE:
3362 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3365 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
3368 FIXME("Unknown date format (%ld)\n", dwFlags);
3369 SetLastError(ERROR_INVALID_PARAMETER);
3374 default: /* default to US English "en_US" */
3378 case DATE_SHORTDATE:
3379 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
3380 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
3381 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
3382 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
3383 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3384 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
3387 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
3388 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
3389 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
3390 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
3393 FIXME("Unknown date format (%ld)\n", dwFlags);
3394 SetLastError(ERROR_INVALID_PARAMETER);
3401 /**************************************************************************
3402 * EnumDateFormatsW (KERNEL32.@)
3404 BOOL WINAPI EnumDateFormatsW(
3405 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3407 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
3408 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3412 /**************************************************************************
3413 * EnumTimeFormatsA (KERNEL32.@)
3415 BOOL WINAPI EnumTimeFormatsA(
3416 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3418 LCID Loc = GetUserDefaultLCID();
3419 if(!lpTimeFmtEnumProc)
3421 SetLastError(ERROR_INVALID_PARAMETER);
3426 FIXME("Unknown time format (%ld)\n", dwFlags);
3431 case 0x00000407: /* (Loc,"de_DE") */
3433 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3434 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3435 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3436 if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
3437 if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
3441 case 0x0000040c: /* (Loc,"fr_FR") */
3442 case 0x00000c0c: /* (Loc,"fr_CA") */
3444 if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
3445 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3446 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3447 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3448 if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
3452 case 0x00000809: /* (Loc,"en_UK") */
3453 case 0x00000c09: /* (Loc,"en_AU") */
3454 case 0x00001409: /* (Loc,"en_NZ") */
3455 case 0x00001809: /* (Loc,"en_IE") */
3457 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3458 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3459 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3463 case 0x00001c09: /* (Loc,"en_ZA") */
3464 case 0x00002809: /* (Loc,"en_BZ") */
3465 case 0x00002c09: /* (Loc,"en_TT") */
3467 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3468 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3472 default: /* default to US style "en_US" */
3474 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3475 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3476 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3477 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3483 /**************************************************************************
3484 * EnumTimeFormatsW (KERNEL32.@)
3486 BOOL WINAPI EnumTimeFormatsW(
3487 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3489 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
3490 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3494 /**************************************************************************
3495 * This function is used just locally !
3496 * Description: Inverts a string.
3498 static void OLE_InvertString(char* string)
3500 char sTmpArray[128];
3503 for (counter = strlen(string); counter > 0; counter--)
3505 memcpy(sTmpArray + i, string + counter-1, 1);
3508 memcpy(sTmpArray + i, "\0", 1);
3509 strcpy(string, sTmpArray);
3512 /***************************************************************************************
3513 * This function is used just locally !
3514 * Description: Test if the given string (psNumber) is valid or not.
3515 * The valid characters are the following:
3516 * - Characters '0' through '9'.
3517 * - One decimal point (dot) if the number is a floating-point value.
3518 * - A minus sign in the first character position if the number is
3520 * If the function succeeds, psBefore/psAfter will point to the string
3521 * on the right/left of the decimal symbol. pbNegative indicates if the
3522 * number is negative.
3524 static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
3526 char sNumberSet[] = "0123456789";
3527 BOOL bInDecimal = FALSE;
3529 /* Test if we do have a minus sign */
3530 if ( *pInput == '-' )
3533 pInput++; /* Jump to the next character. */
3536 while(*pInput != '\0')
3538 /* Do we have a valid numeric character */
3539 if ( strchr(sNumberSet, *pInput) != NULL )
3541 if (bInDecimal == TRUE)
3542 *psAfter++ = *pInput;
3544 *psBefore++ = *pInput;
3548 /* Is this a decimal point (dot) */
3549 if ( *pInput == '.' )
3551 /* Is it the first time we find it */
3552 if ((bInDecimal == FALSE))
3555 return -1; /* ERROR: Invalid parameter */
3559 /* It's neither a numeric character, nor a decimal point.
3560 * Thus, return an error.
3568 /* Add an End of Line character to the output buffers */
3575 /**************************************************************************
3576 * This function is used just locally !
3577 * Description: A number could be formatted using different numbers
3578 * of "digits in group" (example: 4;3;2;0).
3579 * The first parameter of this function is an array
3580 * containing the rule to be used. Its format is the following:
3581 * |NDG|DG1|DG2|...|0|
3582 * where NDG is the number of used "digits in group" and DG1, DG2,
3583 * are the corresponding "digits in group".
3584 * Thus, this function returns the grouping value in the array
3585 * pointed by the second parameter.
3587 static INT OLE_GetGrouping(char* sRule, INT index)
3589 char sData[2], sRuleSize[2];
3590 INT nData, nRuleSize;
3592 memcpy(sRuleSize, sRule, 1);
3593 memcpy(sRuleSize+1, "\0", 1);
3594 nRuleSize = atoi(sRuleSize);
3596 if (index > 0 && index < nRuleSize)
3598 memcpy(sData, sRule+index, 1);
3599 memcpy(sData+1, "\0", 1);
3600 nData = atoi(sData);
3605 memcpy(sData, sRule+nRuleSize-1, 1);
3606 memcpy(sData+1, "\0", 1);
3607 nData = atoi(sData);
3613 /**************************************************************************
3614 * GetNumberFormatA (KERNEL32.@)
3616 INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
3617 LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
3618 LPSTR lpNumberStr, int cchNumber)
3620 char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
3621 INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
3622 char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
3623 char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
3624 char *pStr = NULL, *pTmpStr = NULL;
3625 LCID systemDefaultLCID;
3626 BOOL bNegative = FALSE;
3635 strncpy(sNumber, lpvalue, 128);
3636 sNumber[127] = '\0';
3638 /* Make sure we have a valid input string, get the number
3639 * of digits before and after the decimal symbol, and check
3640 * if this is a negative number.
3642 if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
3644 nNumberDecimal = strlen(sDigitsBeforeDecimal);
3645 nDigits = strlen(sDigitsAfterDecimal);
3649 SetLastError(ERROR_INVALID_PARAMETER);
3653 /* Which source will we use to format the string */
3654 used_operation = RETURN_ERROR;
3655 if (lpFormat != NULL)
3658 used_operation = USE_PARAMETER;
3662 if (dwflags & LOCALE_NOUSEROVERRIDE)
3663 used_operation = USE_LOCALEINFO;
3665 used_operation = USE_SYSTEMDEFAULT;
3668 /* Load the fields we need */
3669 switch(used_operation)
3671 case USE_LOCALEINFO:
3672 GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3673 GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3674 GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3675 GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3676 GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3677 GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3680 sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
3681 strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
3682 sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
3683 strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
3684 sprintf(sILZero, "%d",lpFormat->LeadingZero);
3685 sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
3687 case USE_SYSTEMDEFAULT:
3688 systemDefaultLCID = GetSystemDefaultLCID();
3689 GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3690 GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3691 GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3692 GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3693 GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3694 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3697 SetLastError(ERROR_INVALID_PARAMETER);
3701 nNumberDigits = atoi(sNumberDigits);
3703 /* Remove the ";" */
3706 for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
3708 if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
3710 memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
3715 sprintf(sBuffer, "%d", i);
3716 memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3717 memcpy(sRule + j, "\0", 1);
3719 /* First, format the digits before the decimal. */
3720 if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
3722 /* Working on an inverted string is easier ! */
3723 OLE_InvertString(sDigitsBeforeDecimal);
3725 nStep = nCounter = i = j = 0;
3727 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3729 /* Here, we will loop until we reach the end of the string.
3730 * An internal counter (j) is used in order to know when to
3731 * insert the "digit group symbol".
3733 while (nNumberDecimal > 0)
3735 i = nCounter + nStep;
3736 memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
3742 if (nRuleIndex < sRule[0])
3744 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3745 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
3746 nStep+= strlen(sDigitGroupSymbol);
3752 memcpy(sDestination + i+1, "\0", 1);
3753 /* Get the string in the right order ! */
3754 OLE_InvertString(sDestination);
3758 nLZ = atoi(sILZero);
3761 /* Use 0.xxx instead of .xxx */
3762 memcpy(sDestination, "0", 1);
3763 memcpy(sDestination+1, "\0", 1);
3766 memcpy(sDestination, "\0", 1);
3770 /* Second, format the digits after the decimal. */
3772 nCounter = nNumberDigits;
3773 if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
3775 i = strlen(sNumber) - strlen(pStr) + 1;
3776 strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
3777 j = strlen(sDigitsAfterDecimal);
3778 if (j < nNumberDigits)
3779 nCounter = nNumberDigits-j;
3781 for (i=0;i<nCounter;i++)
3782 memcpy(sDigitsAfterDecimal+i+j, "0", 1);
3783 memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
3785 i = strlen(sDestination);
3786 j = strlen(sDigitsAfterDecimal);
3787 /* Finally, construct the resulting formatted string. */
3789 for (nCounter=0; nCounter<i; nCounter++)
3790 memcpy(sNumber + nCounter, sDestination + nCounter, 1);
3792 memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
3795 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
3796 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
3798 /* Is it a negative number */
3799 if (bNegative == TRUE)
3801 i = atoi(sNegNumber);
3802 pStr = sDestination;
3808 while (*sNumber != '\0')
3809 *pStr++ = *pTmpStr++;
3814 while (*pTmpStr != '\0')
3815 *pStr++ = *pTmpStr++;
3820 while (*pTmpStr != '\0')
3821 *pStr++ = *pTmpStr++;
3824 while (*pTmpStr != '\0')
3825 *pStr++ = *pTmpStr++;
3829 while (*pTmpStr != '\0')
3830 *pStr++ = *pTmpStr++;
3835 while (*pTmpStr != '\0')
3836 *pStr++ = *pTmpStr++;
3841 strcpy(sDestination, sNumber);
3843 /* If cchNumber is zero, then returns the number of bytes or characters
3844 * required to hold the formatted number string
3847 retVal = strlen(sDestination) + 1;
3850 strncpy (lpNumberStr, sDestination, cchNumber-1);
3851 *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
3852 retVal = strlen(lpNumberStr);
3858 /**************************************************************************
3859 * GetNumberFormatW (KERNEL32.@)
3861 INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
3862 LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
3863 LPWSTR lpNumberStr, int cchNumber)
3865 FIXME("%s: stub, no reformatting done\n",debugstr_w(lpvalue));
3867 lstrcpynW( lpNumberStr, lpvalue, cchNumber );
3868 return cchNumber? strlenW( lpNumberStr ) : 0;
3871 /**************************************************************************
3872 * GetCurrencyFormatA (KERNEL32.@)
3874 INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
3875 LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
3876 LPSTR lpCurrencyStr, int cchCurrency)
3878 UINT nPosOrder, nNegOrder;
3880 char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
3881 char *pDestination = sDestination;
3882 char sNumberFormated[128];
3883 char *pNumberFormated = sNumberFormated;
3884 LCID systemDefaultLCID;
3885 BOOL bIsPositive = FALSE, bValidFormat = FALSE;
3894 NUMBERFMTA numberFmt;
3896 /* Which source will we use to format the string */
3897 used_operation = RETURN_ERROR;
3898 if (lpFormat != NULL)
3901 used_operation = USE_PARAMETER;
3905 if (dwflags & LOCALE_NOUSEROVERRIDE)
3906 used_operation = USE_LOCALEINFO;
3908 used_operation = USE_SYSTEMDEFAULT;
3911 /* Load the fields we need */
3912 switch(used_operation)
3914 case USE_LOCALEINFO:
3915 /* Specific to CURRENCYFMTA */
3916 GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3917 GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3918 GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3920 nPosOrder = atoi(sPosOrder);
3921 nNegOrder = atoi(sNegOrder);
3924 /* Specific to CURRENCYFMTA */
3925 nNegOrder = lpFormat->NegativeOrder;
3926 nPosOrder = lpFormat->PositiveOrder;
3927 strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
3929 case USE_SYSTEMDEFAULT:
3930 systemDefaultLCID = GetSystemDefaultLCID();
3931 /* Specific to CURRENCYFMTA */
3932 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3933 GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3934 GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3936 nPosOrder = atoi(sPosOrder);
3937 nNegOrder = atoi(sNegOrder);
3940 SetLastError(ERROR_INVALID_PARAMETER);
3944 /* Construct a temporary number format structure */
3945 if (lpFormat != NULL)
3947 numberFmt.NumDigits = lpFormat->NumDigits;
3948 numberFmt.LeadingZero = lpFormat->LeadingZero;
3949 numberFmt.Grouping = lpFormat->Grouping;
3950 numberFmt.NegativeOrder = 0;
3951 numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
3952 numberFmt.lpThousandSep = lpFormat->lpThousandSep;
3953 bValidFormat = TRUE;
3956 /* Make a call to GetNumberFormatA() */
3957 if (*lpvalue == '-')
3959 bIsPositive = FALSE;
3960 retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3965 retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3971 /* construct the formatted string */
3976 case 0: /* Prefix, no separation */
3977 strcpy (pDestination, sCurrencySymbol);
3978 strcat (pDestination, pNumberFormated);
3980 case 1: /* Suffix, no separation */
3981 strcpy (pDestination, pNumberFormated);
3982 strcat (pDestination, sCurrencySymbol);
3984 case 2: /* Prefix, 1 char separation */
3985 strcpy (pDestination, sCurrencySymbol);
3986 strcat (pDestination, " ");
3987 strcat (pDestination, pNumberFormated);
3989 case 3: /* Suffix, 1 char separation */
3990 strcpy (pDestination, pNumberFormated);
3991 strcat (pDestination, " ");
3992 strcat (pDestination, sCurrencySymbol);
3995 SetLastError(ERROR_INVALID_PARAMETER);
3999 else /* negative number */
4003 case 0: /* format: ($1.1) */
4004 strcpy (pDestination, "(");
4005 strcat (pDestination, sCurrencySymbol);
4006 strcat (pDestination, pNumberFormated);
4007 strcat (pDestination, ")");
4009 case 1: /* format: -$1.1 */
4010 strcpy (pDestination, "-");
4011 strcat (pDestination, sCurrencySymbol);
4012 strcat (pDestination, pNumberFormated);
4014 case 2: /* format: $-1.1 */
4015 strcpy (pDestination, sCurrencySymbol);
4016 strcat (pDestination, "-");
4017 strcat (pDestination, pNumberFormated);
4019 case 3: /* format: $1.1- */
4020 strcpy (pDestination, sCurrencySymbol);
4021 strcat (pDestination, pNumberFormated);
4022 strcat (pDestination, "-");
4024 case 4: /* format: (1.1$) */
4025 strcpy (pDestination, "(");
4026 strcat (pDestination, pNumberFormated);
4027 strcat (pDestination, sCurrencySymbol);
4028 strcat (pDestination, ")");
4030 case 5: /* format: -1.1$ */
4031 strcpy (pDestination, "-");
4032 strcat (pDestination, pNumberFormated);
4033 strcat (pDestination, sCurrencySymbol);
4035 case 6: /* format: 1.1-$ */
4036 strcpy (pDestination, pNumberFormated);
4037 strcat (pDestination, "-");
4038 strcat (pDestination, sCurrencySymbol);
4040 case 7: /* format: 1.1$- */
4041 strcpy (pDestination, pNumberFormated);
4042 strcat (pDestination, sCurrencySymbol);
4043 strcat (pDestination, "-");
4045 case 8: /* format: -1.1 $ */
4046 strcpy (pDestination, "-");
4047 strcat (pDestination, pNumberFormated);
4048 strcat (pDestination, " ");
4049 strcat (pDestination, sCurrencySymbol);
4051 case 9: /* format: -$ 1.1 */
4052 strcpy (pDestination, "-");
4053 strcat (pDestination, sCurrencySymbol);
4054 strcat (pDestination, " ");
4055 strcat (pDestination, pNumberFormated);
4057 case 10: /* format: 1.1 $- */
4058 strcpy (pDestination, pNumberFormated);
4059 strcat (pDestination, " ");
4060 strcat (pDestination, sCurrencySymbol);
4061 strcat (pDestination, "-");
4063 case 11: /* format: $ 1.1- */
4064 strcpy (pDestination, sCurrencySymbol);
4065 strcat (pDestination, " ");
4066 strcat (pDestination, pNumberFormated);
4067 strcat (pDestination, "-");
4069 case 12: /* format: $ -1.1 */
4070 strcpy (pDestination, sCurrencySymbol);
4071 strcat (pDestination, " ");
4072 strcat (pDestination, "-");
4073 strcat (pDestination, pNumberFormated);
4075 case 13: /* format: 1.1- $ */
4076 strcpy (pDestination, pNumberFormated);
4077 strcat (pDestination, "-");
4078 strcat (pDestination, " ");
4079 strcat (pDestination, sCurrencySymbol);
4081 case 14: /* format: ($ 1.1) */
4082 strcpy (pDestination, "(");
4083 strcat (pDestination, sCurrencySymbol);
4084 strcat (pDestination, " ");
4085 strcat (pDestination, pNumberFormated);
4086 strcat (pDestination, ")");
4088 case 15: /* format: (1.1 $) */
4089 strcpy (pDestination, "(");
4090 strcat (pDestination, pNumberFormated);
4091 strcat (pDestination, " ");
4092 strcat (pDestination, sCurrencySymbol);
4093 strcat (pDestination, ")");
4096 SetLastError(ERROR_INVALID_PARAMETER);
4101 if (cchCurrency == 0)
4102 return strlen(pDestination) + 1;
4106 strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
4107 *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
4108 return strlen(lpCurrencyStr);
4112 /**************************************************************************
4113 * GetCurrencyFormatW (KERNEL32.@)
4115 INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
4116 LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
4117 LPWSTR lpCurrencyStr, int cchCurrency)
4119 FIXME("This API function is NOT implemented !\n");
4123 /******************************************************************************
4124 * OLE2NLS_CheckLocale [intern]
4126 static LCID OLE2NLS_CheckLocale (LCID locale)
4129 { locale = LOCALE_SYSTEM_DEFAULT;
4132 if (locale == LOCALE_SYSTEM_DEFAULT)
4133 { return GetSystemDefaultLCID();
4135 else if (locale == LOCALE_USER_DEFAULT)
4136 { return GetUserDefaultLCID();
4142 /******************************************************************************
4143 * GetTimeFormatA [KERNEL32.@]
4144 * Makes an ASCII string of the time
4146 * Formats date according to format, or locale default if format is
4147 * NULL. The format consists of literal characters and fields as follows:
4149 * h hours with no leading zero (12-hour)
4150 * hh hours with full two digits
4151 * H hours with no leading zero (24-hour)
4152 * HH hours with full two digits
4153 * m minutes with no leading zero
4154 * mm minutes with full two digits
4155 * s seconds with no leading zero
4156 * ss seconds with full two digits
4157 * t time marker (A or P)
4158 * tt time marker (AM, PM)
4162 GetTimeFormatA(LCID locale, /* [in] */
4163 DWORD flags, /* [in] */
4164 LPSYSTEMTIME xtime, /* [in] */
4165 LPCSTR format, /* [in] */
4166 LPSTR timestr, /* [out] */
4167 INT timelen /* [in] */)
4168 { char format_buf[40];
4171 LPSYSTEMTIME thistime;
4173 DWORD thisflags=LOCALE_STIMEFORMAT; /* standard timeformat */
4176 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
4178 thislocale = OLE2NLS_CheckLocale ( locale );
4181 { if (flags & LOCALE_NOUSEROVERRIDE) /* use system default */
4182 { thislocale = GetSystemDefaultLCID();
4184 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
4185 thisformat = format_buf;
4188 { thisformat = format;
4191 if (xtime == NULL) /* NULL means use the current local time */
4197 /* Check that hour,min and sec is in range */
4199 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
4205 /******************************************************************************
4206 * GetTimeFormatW [KERNEL32.@]
4207 * Makes a Unicode string of the time
4210 GetTimeFormatW(LCID locale, /* [in] */
4211 DWORD flags, /* [in] */
4212 LPSYSTEMTIME xtime, /* [in] */
4213 LPCWSTR format, /* [in] */
4214 LPWSTR timestr, /* [out] */
4215 INT timelen /* [in] */)
4216 { WCHAR format_buf[40];
4219 LPSYSTEMTIME thistime;
4221 DWORD thisflags=LOCALE_STIMEFORMAT; /* standard timeformat */
4224 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
4225 xtime,debugstr_w(format),timestr,timelen);
4227 thislocale = OLE2NLS_CheckLocale ( locale );
4230 { if (flags & LOCALE_NOUSEROVERRIDE) /* use system default */
4231 { thislocale = GetSystemDefaultLCID();
4233 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
4234 thisformat = format_buf;
4237 { thisformat = format;
4240 if (xtime == NULL) /* NULL means use the current local time */
4248 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
4253 /******************************************************************************
4254 * EnumCalendarInfoA [KERNEL32.@]
4256 BOOL WINAPI EnumCalendarInfoA(
4257 CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
4259 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);