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