2 * National Language Support library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
19 #include "wine/unicode.h"
25 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(string
);
29 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
30 * MUST contain all #defines from winnls.h
31 * last entry has NULL name, 0 id.
33 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
34 static const struct tagLOCALE_NAME2ID
{
38 LOCALE_ENTRY(ILANGUAGE
),
39 LOCALE_ENTRY(SLANGUAGE
),
40 LOCALE_ENTRY(SENGLANGUAGE
),
41 LOCALE_ENTRY(SABBREVLANGNAME
),
42 LOCALE_ENTRY(SNATIVELANGNAME
),
43 LOCALE_ENTRY(ICOUNTRY
),
44 LOCALE_ENTRY(SCOUNTRY
),
45 LOCALE_ENTRY(SENGCOUNTRY
),
46 LOCALE_ENTRY(SABBREVCTRYNAME
),
47 LOCALE_ENTRY(SNATIVECTRYNAME
),
48 LOCALE_ENTRY(IDEFAULTLANGUAGE
),
49 LOCALE_ENTRY(IDEFAULTCOUNTRY
),
50 LOCALE_ENTRY(IDEFAULTCODEPAGE
),
51 LOCALE_ENTRY(IDEFAULTANSICODEPAGE
),
52 LOCALE_ENTRY(IDEFAULTMACCODEPAGE
),
54 LOCALE_ENTRY(IMEASURE
),
55 LOCALE_ENTRY(SDECIMAL
),
56 LOCALE_ENTRY(STHOUSAND
),
57 LOCALE_ENTRY(SGROUPING
),
58 LOCALE_ENTRY(IDIGITS
),
60 LOCALE_ENTRY(INEGNUMBER
),
61 LOCALE_ENTRY(SNATIVEDIGITS
),
62 LOCALE_ENTRY(SCURRENCY
),
63 LOCALE_ENTRY(SINTLSYMBOL
),
64 LOCALE_ENTRY(SMONDECIMALSEP
),
65 LOCALE_ENTRY(SMONTHOUSANDSEP
),
66 LOCALE_ENTRY(SMONGROUPING
),
67 LOCALE_ENTRY(ICURRDIGITS
),
68 LOCALE_ENTRY(IINTLCURRDIGITS
),
69 LOCALE_ENTRY(ICURRENCY
),
70 LOCALE_ENTRY(INEGCURR
),
73 LOCALE_ENTRY(SSHORTDATE
),
74 LOCALE_ENTRY(SLONGDATE
),
75 LOCALE_ENTRY(STIMEFORMAT
),
79 LOCALE_ENTRY(ITIMEMARKPOSN
),
80 LOCALE_ENTRY(ICENTURY
),
81 LOCALE_ENTRY(ITLZERO
),
82 LOCALE_ENTRY(IDAYLZERO
),
83 LOCALE_ENTRY(IMONLZERO
),
86 LOCALE_ENTRY(ICALENDARTYPE
),
87 LOCALE_ENTRY(IOPTIONALCALENDAR
),
88 LOCALE_ENTRY(IFIRSTDAYOFWEEK
),
89 LOCALE_ENTRY(IFIRSTWEEKOFYEAR
),
90 LOCALE_ENTRY(SDAYNAME1
),
91 LOCALE_ENTRY(SDAYNAME2
),
92 LOCALE_ENTRY(SDAYNAME3
),
93 LOCALE_ENTRY(SDAYNAME4
),
94 LOCALE_ENTRY(SDAYNAME5
),
95 LOCALE_ENTRY(SDAYNAME6
),
96 LOCALE_ENTRY(SDAYNAME7
),
97 LOCALE_ENTRY(SABBREVDAYNAME1
),
98 LOCALE_ENTRY(SABBREVDAYNAME2
),
99 LOCALE_ENTRY(SABBREVDAYNAME3
),
100 LOCALE_ENTRY(SABBREVDAYNAME4
),
101 LOCALE_ENTRY(SABBREVDAYNAME5
),
102 LOCALE_ENTRY(SABBREVDAYNAME6
),
103 LOCALE_ENTRY(SABBREVDAYNAME7
),
104 LOCALE_ENTRY(SMONTHNAME1
),
105 LOCALE_ENTRY(SMONTHNAME2
),
106 LOCALE_ENTRY(SMONTHNAME3
),
107 LOCALE_ENTRY(SMONTHNAME4
),
108 LOCALE_ENTRY(SMONTHNAME5
),
109 LOCALE_ENTRY(SMONTHNAME6
),
110 LOCALE_ENTRY(SMONTHNAME7
),
111 LOCALE_ENTRY(SMONTHNAME8
),
112 LOCALE_ENTRY(SMONTHNAME9
),
113 LOCALE_ENTRY(SMONTHNAME10
),
114 LOCALE_ENTRY(SMONTHNAME11
),
115 LOCALE_ENTRY(SMONTHNAME12
),
116 LOCALE_ENTRY(SMONTHNAME13
),
117 LOCALE_ENTRY(SABBREVMONTHNAME1
),
118 LOCALE_ENTRY(SABBREVMONTHNAME2
),
119 LOCALE_ENTRY(SABBREVMONTHNAME3
),
120 LOCALE_ENTRY(SABBREVMONTHNAME4
),
121 LOCALE_ENTRY(SABBREVMONTHNAME5
),
122 LOCALE_ENTRY(SABBREVMONTHNAME6
),
123 LOCALE_ENTRY(SABBREVMONTHNAME7
),
124 LOCALE_ENTRY(SABBREVMONTHNAME8
),
125 LOCALE_ENTRY(SABBREVMONTHNAME9
),
126 LOCALE_ENTRY(SABBREVMONTHNAME10
),
127 LOCALE_ENTRY(SABBREVMONTHNAME11
),
128 LOCALE_ENTRY(SABBREVMONTHNAME12
),
129 LOCALE_ENTRY(SABBREVMONTHNAME13
),
130 LOCALE_ENTRY(SPOSITIVESIGN
),
131 LOCALE_ENTRY(SNEGATIVESIGN
),
132 LOCALE_ENTRY(IPOSSIGNPOSN
),
133 LOCALE_ENTRY(INEGSIGNPOSN
),
134 LOCALE_ENTRY(IPOSSYMPRECEDES
),
135 LOCALE_ENTRY(IPOSSEPBYSPACE
),
136 LOCALE_ENTRY(INEGSYMPRECEDES
),
137 LOCALE_ENTRY(INEGSEPBYSPACE
),
138 LOCALE_ENTRY(FONTSIGNATURE
),
139 LOCALE_ENTRY(SISO639LANGNAME
),
140 LOCALE_ENTRY(SISO3166CTRYNAME
),
144 static char *GetLocaleSubkeyName( DWORD lctype
);
146 /***********************************************************************
147 * GetUserDefaultLCID (KERNEL32.@)
149 LCID WINAPI
GetUserDefaultLCID(void)
151 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT
);
154 /***********************************************************************
155 * GetSystemDefaultLCID (KERNEL32.@)
157 LCID WINAPI
GetSystemDefaultLCID(void)
159 return GetUserDefaultLCID();
162 #define NLS_MAX_LANGUAGES 20
166 LANGID found_lang_id
[NLS_MAX_LANGUAGES
];
167 char found_language
[NLS_MAX_LANGUAGES
][3];
168 char found_country
[NLS_MAX_LANGUAGES
][3];
172 static BOOL CALLBACK
NLS_FindLanguageID_ProcA(HMODULE hModule
, LPCSTR type
,
173 LPCSTR name
, WORD LangID
, LONG lParam
)
175 LANG_FIND_DATA
*l_data
= (LANG_FIND_DATA
*)lParam
;
176 LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
177 char buf_language
[128];
178 char buf_country
[128];
179 char buf_en_language
[128];
181 TRACE("%04X\n", (UINT
)LangID
);
182 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
183 return TRUE
; /* continue search */
188 GetLocaleInfoA(lcid
, LOCALE_SISO639LANGNAME
|LOCALE_NOUSEROVERRIDE
,
189 buf_language
, sizeof(buf_language
));
190 TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language
);
192 GetLocaleInfoA(lcid
, LOCALE_SISO3166CTRYNAME
|LOCALE_NOUSEROVERRIDE
,
193 buf_country
, sizeof(buf_country
));
194 TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country
);
196 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_language
))
198 if(l_data
->country
&& strlen(l_data
->country
) > 0)
200 if(!strcasecmp(l_data
->country
, buf_country
))
202 l_data
->found_lang_id
[0] = LangID
;
204 TRACE("Found lang_id %04X for %s_%s\n", LangID
, l_data
->lang
, l_data
->country
);
205 return FALSE
; /* stop enumeration */
208 else /* l_data->country not specified */
210 if(l_data
->n_found
< NLS_MAX_LANGUAGES
)
212 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
213 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
214 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
216 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
217 return TRUE
; /* continue search */
222 /* Just in case, check LOCALE_SENGLANGUAGE too,
223 * in hope that possible alias name might have that value.
225 buf_en_language
[0] = 0;
226 GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
|LOCALE_NOUSEROVERRIDE
,
227 buf_en_language
, sizeof(buf_en_language
));
228 TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language
);
230 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_en_language
))
232 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
233 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
234 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
236 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
239 return TRUE
; /* continue search */
242 /***********************************************************************
246 * Lang: a string whose two first chars are the iso name of a language.
247 * Country: a string whose two first chars are the iso name of country
248 * Charset: a string defining the chossen charset encoding
249 * Dialect: a string defining a variation of the locale
251 * all those values are from the standardized format of locale
252 * name in unix which is: Lang[_Country][.Charset][@Dialect]
255 * the numeric code of the language used by Windows
257 * FIXME: Charset and Dialect are not handled
259 static LANGID
NLS_GetLanguageID(LPCSTR Lang
, LPCSTR Country
, LPCSTR Charset
, LPCSTR Dialect
)
261 LANG_FIND_DATA l_data
;
262 char lang_string
[256];
266 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
270 memset(&l_data
, 0, sizeof(LANG_FIND_DATA
));
271 strncpy(l_data
.lang
, Lang
, sizeof(l_data
.lang
));
273 if(Country
&& strlen(Country
) > 0)
274 strncpy(l_data
.country
, Country
, sizeof(l_data
.country
));
276 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
277 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
279 strcpy(lang_string
, l_data
.lang
);
280 if(l_data
.country
&& strlen(l_data
.country
) > 0)
282 strcat(lang_string
, "_");
283 strcat(lang_string
, l_data
.country
);
288 if(l_data
.country
&& strlen(l_data
.country
) > 0)
290 MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string
);
291 l_data
.country
[0] = 0;
292 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
293 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
297 /* Re-evaluate lang_string */
298 strcpy(lang_string
, l_data
.lang
);
299 if(l_data
.country
&& strlen(l_data
.country
) > 0)
301 strcat(lang_string
, "_");
302 strcat(lang_string
, l_data
.country
);
307 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string
);
308 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
312 if(l_data
.n_found
== 1)
313 TRACE("For language '%s' lang_id %04X was found\n", lang_string
, l_data
.found_lang_id
[0]);
314 else /* l_data->n_found > 1 */
317 MESSAGE("For language '%s' several language ids were found:\n", lang_string
);
318 for(i
= 0; i
< l_data
.n_found
; i
++)
319 MESSAGE("%s_%s - %04X; ", l_data
.found_language
[i
], l_data
.found_country
[i
], l_data
.found_lang_id
[i
]);
321 MESSAGE("\nInstead of using first in the list, suggest to define\n"
322 "your LANG environment variable like this: LANG=%s_%s\n",
323 l_data
.found_language
[0], l_data
.found_country
[0]);
327 TRACE("Returning %04X\n", l_data
.found_lang_id
[0]);
328 return l_data
.found_lang_id
[0];
331 /***********************************************************************
332 * GetUserDefaultLangID (KERNEL32.@)
334 LANGID WINAPI
GetUserDefaultLangID(void)
336 /* caching result, if defined from environment, which should (?) not change during a WINE session */
337 static LANGID userLCID
= 0;
342 char *lang
,*country
,*charset
,*dialect
,*next
;
344 if (GetEnvironmentVariableA( "LANGUAGE", buf
, sizeof(buf
) )) goto ok
;
345 if (GetEnvironmentVariableA( "LANG", buf
, sizeof(buf
) )) goto ok
;
346 if (GetEnvironmentVariableA( "LC_ALL", buf
, sizeof(buf
) )) goto ok
;
347 if (GetEnvironmentVariableA( "LC_MESSAGES", buf
, sizeof(buf
) )) goto ok
;
348 if (GetEnvironmentVariableA( "LC_CTYPE", buf
, sizeof(buf
) )) goto ok
;
350 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
353 if (!strcmp(buf
,"POSIX") || !strcmp(buf
,"C"))
354 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
359 next
=strchr(lang
,':'); if (next
) *next
++='\0';
360 dialect
=strchr(lang
,'@'); if (dialect
) *dialect
++='\0';
361 charset
=strchr(lang
,'.'); if (charset
) *charset
++='\0';
362 country
=strchr(lang
,'_'); if (country
) *country
++='\0';
364 userLCID
= NLS_GetLanguageID(lang
, country
, charset
, dialect
);
367 } while (lang
&& !userLCID
);
371 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
373 userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
379 /***********************************************************************
380 * GetSystemDefaultLangID (KERNEL32.@)
382 LANGID WINAPI
GetSystemDefaultLangID(void)
384 return GetUserDefaultLangID();
387 /******************************************************************************
388 * ConvertDefaultLocale (KERNEL32.@)
390 LCID WINAPI
ConvertDefaultLocale (LCID lcid
)
392 { case LOCALE_SYSTEM_DEFAULT
:
393 return GetSystemDefaultLCID();
394 case LOCALE_USER_DEFAULT
:
395 return GetUserDefaultLCID();
397 return MAKELCID (LANG_NEUTRAL
, SUBLANG_NEUTRAL
);
399 return MAKELANGID( PRIMARYLANGID(lcid
), SUBLANG_NEUTRAL
);
402 /* Enhanced version of LoadStringW.
403 * It takes LanguageId to find and load language dependant resources.
404 * Resource is copied as is: "binary" strings are not truncated.
405 * Return: length of resource + 1 to distinguish absent resources
406 * from the resources with zero length.
408 static INT
NLS_LoadStringExW(HMODULE hModule
, LANGID lang_id
, UINT res_id
, LPWSTR buffer
, INT buflen
)
416 /* Replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
417 if(SUBLANGID(lang_id
) == SUBLANG_NEUTRAL
)
418 lang_id
= MAKELANGID(PRIMARYLANGID(lang_id
), SUBLANG_DEFAULT
);
420 hrsrc
= FindResourceExW(hModule
, RT_STRINGW
, (LPCWSTR
)((res_id
>> 4) + 1), lang_id
);
423 hmem
= LoadResource(hModule
, hrsrc
);
426 p
= LockResource(hmem
);
427 string_num
= res_id
& 0x000f;
428 for(i
= 0; i
< string_num
; i
++)
431 TRACE("strlen = %d\n", (int)*p
);
433 if (buffer
== NULL
) return *p
;
434 i
= min(buflen
- 1, *p
);
436 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
437 buffer
[i
] = (WCHAR
) 0;
440 buffer
[0] = (WCHAR
) 0;
444 TRACE("%s loaded!\n", debugstr_w(buffer
));
448 /******************************************************************************
449 * GetLocaleInfoA (KERNEL32.@)
452 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
454 * MS online documentation states that the string returned is NULL terminated
455 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
456 * terminated string".
458 INT WINAPI
GetLocaleInfoA(LCID lcid
,LCTYPE LCType
,LPSTR buf
,INT len
)
460 LPCSTR retString
= NULL
;
464 DWORD dwBufferSize
=128;
467 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid
,LCType
,buf
,len
);
469 if (len
&& (! buf
) ) {
470 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
474 if (lcid
== LOCALE_NEUTRAL
|| lcid
== LANG_SYSTEM_DEFAULT
)
476 lcid
= GetSystemDefaultLCID();
478 else if (lcid
== LANG_USER_DEFAULT
) /*0x800*/
480 lcid
= GetUserDefaultLCID();
483 /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
484 from the registry. Instead, use system default values. */
485 NoUserOverride
= (LCType
& LOCALE_NOUSEROVERRIDE
) != 0;
487 LCType
&= ~(LOCALE_NOUSEROVERRIDE
|LOCALE_USE_CP_ACP
);
489 /* First, check if it's in the registry. */
490 /* All user customized values are stored in the registry by SetLocaleInfo */
491 if ( !NoUserOverride
&& (pacKey
= GetLocaleSubkeyName(LCType
)) )
496 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
498 if ( RegOpenKeyExA( HKEY_CURRENT_USER
, acRealKey
,
499 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
501 if ( RegQueryValueExA( hKey
, NULL
, NULL
, NULL
, (LPBYTE
)acBuffer
,
502 &dwBufferSize
) == ERROR_SUCCESS
)
504 retString
= acBuffer
;
511 /* If not in the registry, get it from the NLS entries. */
516 /* check if language is registered in the kernel32 resources */
517 if((res_size
= NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid
),
518 LCType
, wcBuffer
, sizeof(wcBuffer
)/sizeof(wcBuffer
[0])))) {
519 WideCharToMultiByte(CP_ACP
, 0, wcBuffer
, res_size
, acBuffer
, dwBufferSize
, NULL
, NULL
);
520 retString
= acBuffer
;
525 /* if not found report a most descriptive error */
528 /* If we are through all of this, retLen should not be zero anymore.
529 If it is, the value is not supported */
531 while (locale_name2id
[i
].name
!=NULL
) {
532 if (LCType
== locale_name2id
[i
].id
) {
533 retString
= locale_name2id
[i
].name
;
539 FIXME("Unkown LC type %lX\n", LCType
);
541 FIXME("'%s' is not defined for your language (%04X).\n"
542 "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
543 "and submit patch for inclusion into the next Wine release.\n",
544 retString
, LOWORD(lcid
));
545 SetLastError(ERROR_INVALID_PARAMETER
);
549 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
550 if (LCType
== LOCALE_FONTSIGNATURE
) {
552 len
= (len
< sizeof(FONTSIGNATURE
)) ? len
: sizeof(FONTSIGNATURE
);
553 memcpy(buf
, retString
, len
);
556 return sizeof(FONTSIGNATURE
);
558 /* if len=0 return only the length, don't touch the buffer*/
560 lstrcpynA(buf
,retString
,len
);
561 return strlen(buf
) + 1;
563 return strlen(retString
)+1;
566 /******************************************************************************
567 * GetLocaleInfoW (KERNEL32.@)
570 * MS documentation states that len "specifies the size, in bytes (ANSI version)
571 * or characters (Unicode version), of" wbuf. Thus the number returned is
572 * the same between GetLocaleInfoW and GetLocaleInfoA.
574 INT WINAPI
GetLocaleInfoW(LCID lcid
,LCTYPE LCType
,LPWSTR wbuf
,INT len
)
578 if (len
&& (! wbuf
) )
579 { SetLastError(ERROR_INSUFFICIENT_BUFFER
);
583 abuf
= (LPSTR
)HeapAlloc(GetProcessHeap(),0,len
);
584 wlen
= GetLocaleInfoA(lcid
, LCType
, abuf
, len
);
586 if (wlen
&& len
) /* if len=0 return only the length*/
587 MultiByteToWideChar( CP_ACP
, 0, abuf
, -1, wbuf
, len
);
589 HeapFree(GetProcessHeap(),0,abuf
);
593 /******************************************************************************
595 * GetLocaleSubkeyName [helper function]
597 * - For use with the registry.
598 * - Gets the registry subkey name for a given lctype.
600 static char *GetLocaleSubkeyName( DWORD lctype
)
606 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
607 * the values are stored in the registry, confirmed under Windows,
608 * for the ones that actually assign pacKey. Cases that aren't finished
609 * have not been confirmed, so that must be done before they can be
612 case LOCALE_SDATE
: /* The date separator. */
615 case LOCALE_ICURRDIGITS
:
616 pacKey
= "iCurrDigits";
618 case LOCALE_SDECIMAL
:
621 case LOCALE_ICURRENCY
:
622 pacKey
= "iCurrency";
624 case LOCALE_SGROUPING
:
625 pacKey
= "sGrouping";
633 /* case LOCALE_ICALENDARTYPE: */
634 /* case LOCALE_IFIRSTDAYOFWEEK: */
635 /* case LOCALE_IFIRSTWEEKOFYEAR: */
636 /* case LOCALE_SYEARMONTH : */
637 /* case LOCALE_SPOSITIVESIGN : */
638 /* case LOCALE_IPAPERSIZE: */
640 case LOCALE_SLONGDATE
:
641 pacKey
= "sLongDate";
643 case LOCALE_SMONDECIMALSEP
:
644 pacKey
= "sMonDecimalSep";
646 case LOCALE_SMONGROUPING
:
647 pacKey
= "sMonGrouping";
649 case LOCALE_IMEASURE
:
652 case LOCALE_SMONTHOUSANDSEP
:
653 pacKey
= "sMonThousandSep";
655 case LOCALE_INEGCURR
:
658 case LOCALE_SNEGATIVESIGN
:
659 pacKey
= "sNegativeSign";
661 case LOCALE_INEGNUMBER
:
662 pacKey
= "iNegNumber";
664 case LOCALE_SSHORTDATE
:
665 pacKey
= "sShortDate";
667 case LOCALE_ILDATE
: /* Long Date format ordering specifier. */
676 case LOCALE_ITIME
: /* Time format specifier. */
679 case LOCALE_STHOUSAND
:
680 pacKey
= "sThousand";
682 case LOCALE_S1159
: /* AM */
688 case LOCALE_S2359
: /* PM */
691 case LOCALE_STIMEFORMAT
:
692 pacKey
= "sTimeFormat";
694 case LOCALE_SCURRENCY
:
695 pacKey
= "sCurrency";
698 /* The following are not listed under MSDN as supported,
699 * but seem to be used and also stored in the registry.
705 case LOCALE_SCOUNTRY
:
708 case LOCALE_ICOUNTRY
:
711 case LOCALE_SLANGUAGE
:
712 pacKey
= "sLanguage";
722 /******************************************************************************
723 * SetLocaleInfoA [KERNEL32.@]
725 BOOL WINAPI
SetLocaleInfoA(LCID lcid
, LCTYPE lctype
, LPCSTR data
)
731 if ( (pacKey
= GetLocaleSubkeyName(lctype
)) )
733 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
734 if ( RegCreateKeyA( HKEY_CURRENT_USER
, acRealKey
,
735 &hKey
) == ERROR_SUCCESS
)
737 if ( RegSetValueExA( hKey
, NULL
, 0, REG_SZ
,
738 data
, strlen(data
)+1 ) != ERROR_SUCCESS
)
740 ERR("SetLocaleInfoA: %s did not work\n", pacKey
);
747 FIXME("(%ld,%ld,%s): stub\n",lcid
,lctype
,data
);
752 /******************************************************************************
753 * IsValidLocale [KERNEL32.@]
755 BOOL WINAPI
IsValidLocale(LCID lcid
,DWORD flags
)
757 /* check if language is registered in the kernel32 resources */
758 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW
, (LPCWSTR
)LOCALE_ILANGUAGE
, LOWORD(lcid
)))
764 static BOOL CALLBACK
EnumResourceLanguagesProcW(HMODULE hModule
, LPCWSTR type
,
765 LPCWSTR name
, WORD LangID
, LONG lParam
)
769 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
770 sprintf(bufA
, "%08X", (UINT
)LangID
);
771 MultiByteToWideChar(CP_ACP
, 0, bufA
, -1, bufW
, sizeof(bufW
)/sizeof(bufW
[0]));
772 return lpfnLocaleEnum(bufW
);
775 /******************************************************************************
776 * EnumSystemLocalesW [KERNEL32.@]
778 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
,
781 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
783 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW
,
784 (LPCWSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcW
,
785 (LONG
)lpfnLocaleEnum
);
790 static BOOL CALLBACK
EnumResourceLanguagesProcA(HMODULE hModule
, LPCSTR type
,
791 LPCSTR name
, WORD LangID
, LONG lParam
)
794 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
795 sprintf(bufA
, "%08X", (UINT
)LangID
);
796 return lpfnLocaleEnum(bufA
);
799 /******************************************************************************
800 * EnumSystemLocalesA [KERNEL32.@]
802 BOOL WINAPI
EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum
,
805 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
807 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
808 (LPCSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcA
,
809 (LONG
)lpfnLocaleEnum
);
814 /***********************************************************************
815 * VerLanguageNameA [KERNEL32.@]
817 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
822 return GetLocaleInfoA(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
825 /***********************************************************************
826 * VerLanguageNameW [KERNEL32.@]
828 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
833 return GetLocaleInfoW(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
837 static const unsigned char LCM_Unicode_LUT
[] = {
871 7 , 29, /* " - 34 */ /* " */
876 6 , 128, /* ' - 39 */
882 6 , 130, /* - - 45 */
886 12 , 33, /* 1 - 49 */
887 12 , 51, /* 2 - 50 */
888 12 , 70, /* 3 - 51 */
889 12 , 88, /* 4 - 52 */
890 12 , 106, /* 5 - 53 */
891 12 , 125, /* 6 - 54 */
892 12 , 144, /* 7 - 55 */
893 12 , 162, /* 8 - 56 */
894 12 , 180, /* 9 - 57 */
904 14 , 10, /* C - 67 */
905 14 , 26, /* D - 68 */
906 14 , 33, /* E - 69 */
907 14 , 35, /* F - 70 */
908 14 , 37, /* G - 71 */
909 14 , 44, /* H - 72 */
910 14 , 50, /* I - 73 */
911 14 , 53, /* J - 74 */
912 14 , 54, /* K - 75 */
913 14 , 72, /* L - 76 */
914 14 , 81, /* M - 77 */
915 14 , 112, /* N - 78 */
916 14 , 124, /* O - 79 */
917 14 , 126, /* P - 80 */
918 14 , 137, /* Q - 81 */
919 14 , 138, /* R - 82 */
920 14 , 145, /* S - 83 */
921 14 , 153, /* T - 84 */
922 14 , 159, /* U - 85 */
923 14 , 162, /* V - 86 */
924 14 , 164, /* W - 87 */
925 14 , 166, /* X - 88 */
926 14 , 167, /* Y - 89 */
927 14 , 169, /* Z - 90 */
936 14 , 10, /* c - 99 */
937 14 , 26, /* d - 100 */
938 14 , 33, /* e - 101 */
939 14 , 35, /* f - 102 */
940 14 , 37, /* g - 103 */
941 14 , 44, /* h - 104 */
942 14 , 50, /* i - 105 */
943 14 , 53, /* j - 106 */
944 14 , 54, /* k - 107 */
945 14 , 72, /* l - 108 */
946 14 , 81, /* m - 109 */
947 14 , 112, /* n - 110 */
948 14 , 124, /* o - 111 */
949 14 , 126, /* p - 112 */
950 14 , 137, /* q - 113 */
951 14 , 138, /* r - 114 */
952 14 , 145, /* s - 115 */
953 14 , 153, /* t - 116 */
954 14 , 159, /* u - 117 */
955 14 , 162, /* v - 118 */
956 14 , 164, /* w - 119 */
957 14 , 166, /* x - 120 */
958 14 , 167, /* y - 121 */
959 14 , 169, /* z - 122 */
960 7 , 74, /* { - 123 */
961 7 , 76, /* | - 124 */
962 7 , 78, /* } - 125 */
963 7 , 80, /* ~ - 126 */
964 6 , 29, /* \x7f - 127 */
965 6 , 30, /* € - 128 */
966 6 , 31, /* � - 129 */
967 7 , 123, /* ‚ - 130 */
968 14 , 35, /* ƒ - 131 */
969 7 , 127, /* „ - 132 */
970 10 , 21, /* … - 133 */
971 10 , 15, /* † - 134 */
972 10 , 16, /* ‡ - 135 */
973 7 , 67, /* ˆ - 136 */
974 10 , 22, /* ‰ - 137 */
975 14 , 145, /* Š - 138 */
976 7 , 136, /* ‹ - 139 */
977 14 + 16 , 124, /* Œ - 140 */
978 6 , 43, /* � - 141 */
979 6 , 44, /* Ž - 142 */
980 6 , 45, /* � - 143 */
981 6 , 46, /* � - 144 */
982 7 , 121, /* ‘ - 145 */
983 7 , 122, /* ’ - 146 */
984 7 , 125, /* “ - 147 */
985 7 , 126, /* ” - 148 */
986 10 , 17, /* • - 149 */
987 6 , 137, /* – - 150 */
988 6 , 139, /* — - 151 */
989 7 , 93, /* ˜ - 152 */
990 14 , 156, /* ™ - 153 */
991 14 , 145, /* š - 154 */
992 7 , 137, /* › - 155 */
993 14 + 16 , 124, /* œ - 156 */
994 6 , 59, /* � - 157 */
995 6 , 60, /* ž - 158 */
996 14 , 167, /* Ÿ - 159 */
998 7 , 81, /* ¡ - 161 */
999 10 , 2, /* ¢ - 162 */
1000 10 , 3, /* £ - 163 */
1001 10 , 4, /* ¤ - 164 */
1002 10 , 5, /* ¥ - 165 */
1003 7 , 82, /* ¦ - 166 */
1004 10 , 6, /* § - 167 */
1005 7 , 83, /* ¨ - 168 */
1006 10 , 7, /* © - 169 */
1007 14 , 2, /* ª - 170 */
1008 8 , 24, /* « - 171 */
1009 10 , 8, /* ¬ - 172 */
1010 6 , 131, /* - 173 */
1011 10 , 9, /* ® - 174 */
1012 7 , 84, /* ¯ - 175 */
1013 10 , 10, /* ° - 176 */
1014 8 , 23, /* ± - 177 */
1015 12 , 51, /* ² - 178 */
1016 12 , 70, /* ³ - 179 */
1017 7 , 85, /* ´ - 180 */
1018 10 , 11, /* µ - 181 */
1019 10 , 12, /* ¶ - 182 */
1020 10 , 13, /* · - 183 */
1021 7 , 86, /* ¸ - 184 */
1022 12 , 33, /* ¹ - 185 */
1023 14 , 124, /* º - 186 */
1024 8 , 26, /* » - 187 */
1025 12 , 21, /* ¼ - 188 */
1026 12 , 25, /* ½ - 189 */
1027 12 , 29, /* ¾ - 190 */
1028 7 , 87, /* ¿ - 191 */
1029 14 , 2, /* À - 192 */
1030 14 , 2, /* Á - 193 */
1031 14 , 2, /* Â - 194 */
1032 14 , 2, /* Ã - 195 */
1033 14 , 2, /* Ä - 196 */
1034 14 , 2, /* Å - 197 */
1035 14 + 16 , 2, /* Æ - 198 */
1036 14 , 10, /* Ç - 199 */
1037 14 , 33, /* È - 200 */
1038 14 , 33, /* É - 201 */
1039 14 , 33, /* Ê - 202 */
1040 14 , 33, /* Ë - 203 */
1041 14 , 50, /* Ì - 204 */
1042 14 , 50, /* Í - 205 */
1043 14 , 50, /* Î - 206 */
1044 14 , 50, /* Ï - 207 */
1045 14 , 26, /* Ð - 208 */
1046 14 , 112, /* Ñ - 209 */
1047 14 , 124, /* Ò - 210 */
1048 14 , 124, /* Ó - 211 */
1049 14 , 124, /* Ô - 212 */
1050 14 , 124, /* Õ - 213 */
1051 14 , 124, /* Ö - 214 */
1052 8 , 28, /* × - 215 */
1053 14 , 124, /* Ø - 216 */
1054 14 , 159, /* Ù - 217 */
1055 14 , 159, /* Ú - 218 */
1056 14 , 159, /* Û - 219 */
1057 14 , 159, /* Ü - 220 */
1058 14 , 167, /* Ý - 221 */
1059 14 + 32 , 153, /* Þ - 222 */
1060 14 + 48 , 145, /* ß - 223 */
1061 14 , 2, /* à - 224 */
1062 14 , 2, /* á - 225 */
1063 14 , 2, /* â - 226 */
1064 14 , 2, /* ã - 227 */
1065 14 , 2, /* ä - 228 */
1066 14 , 2, /* å - 229 */
1067 14 + 16 , 2, /* æ - 230 */
1068 14 , 10, /* ç - 231 */
1069 14 , 33, /* è - 232 */
1070 14 , 33, /* é - 233 */
1071 14 , 33, /* ê - 234 */
1072 14 , 33, /* ë - 235 */
1073 14 , 50, /* ì - 236 */
1074 14 , 50, /* í - 237 */
1075 14 , 50, /* î - 238 */
1076 14 , 50, /* ï - 239 */
1077 14 , 26, /* ð - 240 */
1078 14 , 112, /* ñ - 241 */
1079 14 , 124, /* ò - 242 */
1080 14 , 124, /* ó - 243 */
1081 14 , 124, /* ô - 244 */
1082 14 , 124, /* õ - 245 */
1083 14 , 124, /* ö - 246 */
1084 8 , 29, /* ÷ - 247 */
1085 14 , 124, /* ø - 248 */
1086 14 , 159, /* ù - 249 */
1087 14 , 159, /* ú - 250 */
1088 14 , 159, /* û - 251 */
1089 14 , 159, /* ü - 252 */
1090 14 , 167, /* ý - 253 */
1091 14 + 32 , 153, /* þ - 254 */
1092 14 , 167 /* ÿ - 255 */ };
1094 static const unsigned char LCM_Unicode_LUT_2
[] = { 33, 44, 145 };
1096 #define LCM_Diacritic_Start 131
1098 static const unsigned char LCM_Diacritic_LUT
[] = {
1226 /******************************************************************************
1227 * OLE2NLS_isPunctuation [INTERNAL]
1229 static int OLE2NLS_isPunctuation(unsigned char c
)
1231 /* "punctuation character" in this context is a character which is
1232 considered "less important" during word sort comparison.
1233 See LCMapString implementation for the precise definition
1234 of "less important". */
1236 return (LCM_Unicode_LUT
[-2+2*c
]==6);
1239 /******************************************************************************
1240 * OLE2NLS_isNonSpacing [INTERNAL]
1242 static int OLE2NLS_isNonSpacing(unsigned char c
)
1244 /* This function is used by LCMapStringA. Characters
1245 for which it returns true are ignored when mapping a
1246 string with NORM_IGNORENONSPACE */
1247 return ((c
==136) || (c
==170) || (c
==186));
1250 /******************************************************************************
1251 * OLE2NLS_isSymbol [INTERNAL]
1252 * FIXME: handle current locale
1254 static int OLE2NLS_isSymbol(unsigned char c
)
1256 /* This function is used by LCMapStringA. Characters
1257 for which it returns true are ignored when mapping a
1258 string with NORM_IGNORESYMBOLS */
1259 return ( (c
!=0) && !(isalpha(c
) || isdigit(c
)) );
1262 /******************************************************************************
1263 * identity [Internal]
1265 static int identity(int c
)
1270 /*************************************************************************
1271 * LCMapStringA [KERNEL32.@]
1273 * Convert a string, or generate a sort key from it.
1275 * If (mapflags & LCMAP_SORTKEY), the function will generate
1276 * a sort key for the source string. Else, it will convert it
1277 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1281 * Success : length of the result string.
1284 * If called with scrlen = -1, the function will compute the length
1285 * of the 0-terminated string strsrc by itself.
1287 * If called with dstlen = 0, returns the buffer length that
1288 * would be required.
1290 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1291 * as if they are equal.
1292 * In the only code page implemented so far, there may not be
1293 * wide characters in strings passed to LCMapStringA,
1294 * so there is nothing to be done for this flag.
1296 INT WINAPI
LCMapStringA(
1297 LCID lcid
, /* [in] locale identifier created with MAKELCID;
1298 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1299 predefined values. */
1300 DWORD mapflags
, /* [in] flags */
1301 LPCSTR srcstr
, /* [in] source buffer */
1302 INT srclen
, /* [in] source length */
1303 LPSTR dststr
, /* [out] destination buffer */
1304 INT dstlen
) /* [in] destination buffer length */
1308 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1309 lcid
,mapflags
,debugstr_an(srcstr
,srclen
),srclen
,dststr
,dstlen
);
1311 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1313 ERR("(src=%s,dest=%s): Invalid NULL string\n",
1314 debugstr_an(srcstr
,srclen
), dststr
);
1315 SetLastError(ERROR_INVALID_PARAMETER
);
1319 srclen
= strlen(srcstr
) + 1 ; /* (include final '\0') */
1321 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1325 NORM_IGNORENONSPACE | \
1327 NORM_IGNOREWIDTH | \
1328 NORM_IGNOREKANATYPE)
1329 /* FIXME: as long as we don't support Katakana nor Hiragana
1330 * characters, we can support NORM_IGNOREKANATYPE
1332 if (mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
)
1334 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1335 "unimplemented flags: 0x%08lx\n",
1342 mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
1346 if ( !(mapflags
& LCMAP_SORTKEY
) )
1349 int (*f
)(int) = identity
;
1350 int flag_ignorenonspace
= mapflags
& NORM_IGNORENONSPACE
;
1351 int flag_ignoresymbols
= mapflags
& NORM_IGNORESYMBOLS
;
1353 if (flag_ignorenonspace
|| flag_ignoresymbols
)
1355 /* For some values of mapflags, the length of the resulting
1356 string is not known at this point. Windows does map the string
1357 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1361 /* Compute required length */
1362 for (i
=j
=0; i
< srclen
; i
++)
1364 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1365 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1377 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1381 if (mapflags
& LCMAP_UPPERCASE
)
1383 else if (mapflags
& LCMAP_LOWERCASE
)
1385 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1386 for (i
=j
=0; (i
<srclen
) && (j
<dstlen
) ; i
++)
1388 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1389 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1391 dststr
[j
] = (CHAR
) f(srcstr
[i
]);
1398 /* FIXME: This function completely ignores the "lcid" parameter. */
1399 /* else ... (mapflags & LCMAP_SORTKEY) */
1403 int diacritic_len
=0;
1404 int delayed_punctuation_len
=0;
1405 char *case_component
;
1406 char *diacritic_component
;
1407 char *delayed_punctuation_component
;
1409 int flag_stringsort
= mapflags
& SORT_STRINGSORT
;
1411 /* compute how much room we will need */
1412 for (i
=0;i
<srclen
;i
++)
1415 unsigned char source_char
= srcstr
[i
];
1416 if (source_char
!='\0')
1418 if (flag_stringsort
|| !OLE2NLS_isPunctuation(source_char
))
1421 if ( LCM_Unicode_LUT
[-2+2*source_char
] & ~15 )
1422 unicode_len
++; /* double letter */
1426 delayed_punctuation_len
++;
1430 if (isupper(source_char
))
1431 case_len
=unicode_len
;
1433 ofs
= source_char
- LCM_Diacritic_Start
;
1434 if ((ofs
>=0) && (LCM_Diacritic_LUT
[ofs
]!=2))
1435 diacritic_len
=unicode_len
;
1438 if (mapflags
& NORM_IGNORECASE
)
1440 if (mapflags
& NORM_IGNORENONSPACE
)
1443 room
= 2 * unicode_len
/* "unicode" component */
1444 + diacritic_len
/* "diacritic" component */
1445 + case_len
/* "case" component */
1446 + 4 * delayed_punctuation_len
/* punctuation in word sort mode */
1447 + 4 /* four '\1' separators */
1448 + 1 ; /* terminal '\0' */
1451 else if (dstlen
<room
)
1453 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1457 /*FIXME the Pointercheck should not be nessesary */
1458 if (IsBadWritePtr (dststr
,room
))
1459 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr
,dstlen
);
1460 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1464 /* locate each component, write separators */
1465 diacritic_component
= dststr
+ 2*unicode_len
;
1466 *diacritic_component
++ = '\1';
1467 case_component
= diacritic_component
+ diacritic_len
;
1468 *case_component
++ = '\1';
1469 delayed_punctuation_component
= case_component
+ case_len
;
1470 *delayed_punctuation_component
++ = '\1';
1471 *delayed_punctuation_component
++ = '\1';
1473 /* read source string char by char, write
1474 corresponding weight in each component. */
1475 for (i
=0,count
=0;i
<srclen
;i
++)
1477 unsigned char source_char
=srcstr
[i
];
1478 if (source_char
!='\0')
1481 type
= LCM_Unicode_LUT
[-2+2*source_char
];
1482 longcode
= type
>> 4;
1484 if (!flag_stringsort
&& OLE2NLS_isPunctuation(source_char
))
1486 WORD encrypted_location
= (1<<15) + 7 + 4*count
;
1487 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
>>8);
1488 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
&255);
1489 /* big-endian is used here because it lets string comparison be
1490 compatible with numerical comparison */
1492 *delayed_punctuation_component
++ = type
;
1493 *delayed_punctuation_component
++ = LCM_Unicode_LUT
[-1+2*source_char
];
1494 /* assumption : a punctuation character is never a
1495 double or accented letter */
1499 dststr
[2*count
] = type
;
1500 dststr
[2*count
+1] = LCM_Unicode_LUT
[-1+2*source_char
];
1504 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1505 if (count
<diacritic_len
)
1506 diacritic_component
[count
] = 2; /* assumption: a double letter
1507 is never accented */
1510 dststr
[2*count
] = type
;
1511 dststr
[2*count
+1] = *(LCM_Unicode_LUT_2
- 1 + longcode
);
1512 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1513 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1514 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1518 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1519 if (count
<diacritic_len
)
1521 int ofs
= source_char
- LCM_Diacritic_Start
;
1522 diacritic_component
[count
] = (ofs
>=0 ? LCM_Diacritic_LUT
[ofs
] : 2);
1528 dststr
[room
-1] = '\0';
1533 /*************************************************************************
1534 * LCMapStringW [KERNEL32.@]
1536 * Convert a string, or generate a sort key from it.
1540 * See LCMapStringA for documentation
1542 INT WINAPI
LCMapStringW(
1543 LCID lcid
,DWORD mapflags
,LPCWSTR srcstr
,INT srclen
,LPWSTR dststr
,
1548 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
1549 lcid
, mapflags
, srcstr
, srclen
, dststr
, dstlen
);
1551 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1553 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr
, dststr
);
1554 SetLastError(ERROR_INVALID_PARAMETER
);
1558 srclen
= strlenW(srcstr
)+1;
1560 /* FIXME: Both this function and it's companion LCMapStringA()
1561 * completely ignore the "lcid" parameter. In place of the "lcid"
1562 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
1563 * environment variable prior to invoking this function. */
1564 if (mapflags
& LCMAP_SORTKEY
)
1566 /* Possible values of LC_COLLATE. */
1567 char *lc_collate_default
= 0; /* value prior to this function */
1568 char *lc_collate_env
= 0; /* value retrieved from the environment */
1570 /* General purpose index into strings of any type. */
1573 /* Lengths of various strings where the length is measured in
1574 * wide characters for wide character strings and in bytes for
1575 * native strings. The lengths include the NULL terminator. */
1576 size_t returned_len
= 0;
1577 size_t src_native_len
= 0;
1578 size_t dst_native_len
= 0;
1579 size_t dststr_libc_len
= 0;
1581 /* Native (character set determined by locale) versions of the
1582 * strings source and destination strings. */
1583 LPSTR src_native
= 0;
1584 LPSTR dst_native
= 0;
1586 /* Version of the source and destination strings using the
1587 * "wchar_t" Unicode data type needed by various libc functions. */
1588 wchar_t *srcstr_libc
= 0;
1589 wchar_t *dststr_libc
= 0;
1591 if(!(srcstr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
1592 srclen
* sizeof(wchar_t))))
1594 ERR("Unable to allocate %d bytes for srcstr_libc\n",
1595 srclen
* sizeof(wchar_t));
1596 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1600 /* Convert source string to a libc Unicode string. */
1601 for(str_idx
= 0; str_idx
< srclen
; str_idx
++)
1603 srcstr_libc
[str_idx
] = srcstr
[str_idx
];
1606 /* src_native should contain at most 3 bytes for each
1607 * multibyte characters in the original srcstr string. */
1608 src_native_len
= 3 * srclen
;
1609 if(!(src_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
1612 ERR("Unable to allocate %d bytes for src_native\n", src_native_len
);
1613 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1614 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1618 /* FIXME: Prior to to setting the LC_COLLATE locale category the
1619 * current value is backed up so it can be restored after the
1620 * last LC_COLLATE sensitive function returns.
1622 * Even though the locale is adjusted for a minimum amount of
1623 * time a race condition exists where other threads may be
1624 * affected if they invoke LC_COLLATE sensitive functions. One
1625 * possible solution is to wrap all LC_COLLATE sensitive Wine
1626 * functions, like LCMapStringW(), in a mutex.
1628 * Another enhancement to the following would be to set the
1629 * LC_COLLATE locale category as a function of the "lcid"
1630 * parameter instead of the "LC_COLLATE" environment variable. */
1631 if(!(lc_collate_default
= setlocale(LC_COLLATE
, NULL
)))
1633 ERR("Unable to query the LC_COLLATE catagory\n");
1634 SetLastError(ERROR_INVALID_PARAMETER
);
1635 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1636 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1640 if(!(lc_collate_env
= setlocale(LC_COLLATE
, "")))
1642 ERR("Unable to inherit the LC_COLLATE locale category from the "
1643 "environment. The \"LC_COLLATE\" environment variable is "
1644 "\"%s\".\n", getenv("LC_COLLATE") ?
1645 getenv("LC_COLLATE") : "<unset>");
1646 SetLastError(ERROR_INVALID_PARAMETER
);
1647 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1648 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1652 TRACE("lc_collate_default = %s\n", lc_collate_default
);
1653 TRACE("lc_collate_env = %s\n", lc_collate_env
);
1655 /* Convert the libc Unicode string to a native multibyte character
1657 returned_len
= wcstombs(src_native
, srcstr_libc
, src_native_len
) + 1;
1658 if(returned_len
== 0)
1660 ERR("wcstombs failed. The string specified (%s) may contain an invalid character.\n",
1661 debugstr_w(srcstr
));
1662 SetLastError(ERROR_INVALID_PARAMETER
);
1663 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1664 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1665 setlocale(LC_COLLATE
, lc_collate_default
);
1668 else if(returned_len
> src_native_len
)
1670 src_native
[src_native_len
- 1] = 0;
1671 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
1672 "than expected (%d bytes).\n", src_native
, returned_len
,
1675 /* Since this is an internal error I'm not sure what the correct
1677 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1679 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1680 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1681 setlocale(LC_COLLATE
, lc_collate_default
);
1684 src_native_len
= returned_len
;
1686 TRACE("src_native = %s src_native_len = %d\n",
1687 src_native
, src_native_len
);
1689 /* dst_native seems to contain at most 4 bytes for each byte in
1690 * the original src_native string. Change if need be since this
1691 * isn't documented by the strxfrm() man page. */
1692 dst_native_len
= 4 * src_native_len
;
1693 if(!(dst_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, dst_native_len
)))
1695 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len
);
1696 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1697 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1698 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1699 setlocale(LC_COLLATE
, lc_collate_default
);
1703 /* The actual translation is done by the following call to
1704 * strxfrm(). The surrounding code could have been simplified
1705 * by calling wcsxfrm() instead except that wcsxfrm() is not
1706 * available on older Linux systems (RedHat 4.1 with
1709 * Also, it is possible that the translation could be done by
1710 * various tables as it is done in LCMapStringA(). However, I'm
1711 * not sure what those tables are. */
1712 returned_len
= strxfrm(dst_native
, src_native
, dst_native_len
) + 1;
1714 if(returned_len
> dst_native_len
)
1716 dst_native
[dst_native_len
- 1] = 0;
1717 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
1718 "than expected (%d bytes).\n", dst_native
, returned_len
,
1721 /* Since this is an internal error I'm not sure what the correct
1723 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1725 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1726 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1727 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1728 setlocale(LC_COLLATE
, lc_collate_default
);
1731 dst_native_len
= returned_len
;
1733 TRACE("dst_native = %s dst_native_len = %d\n",
1734 dst_native
, dst_native_len
);
1736 dststr_libc_len
= dst_native_len
;
1737 if(!(dststr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
1738 dststr_libc_len
* sizeof(wchar_t))))
1740 ERR("Unable to allocate %d bytes for dststr_libc\n",
1741 dststr_libc_len
* sizeof(wchar_t));
1742 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1743 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1744 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1745 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1746 setlocale(LC_COLLATE
, lc_collate_default
);
1750 /* Convert the native multibyte string to a libc Unicode string. */
1751 returned_len
= mbstowcs(dststr_libc
, dst_native
, dst_native_len
) + 1;
1753 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
1754 * function has returned. */
1755 setlocale(LC_COLLATE
, lc_collate_default
);
1757 if(returned_len
== 0)
1759 ERR("mbstowcs failed. The native version of the translated string "
1760 "(%s) may contain an invalid character.\n", dst_native
);
1761 SetLastError(ERROR_INVALID_PARAMETER
);
1762 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1763 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1764 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1765 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
1770 if(returned_len
> dstlen
)
1772 ERR("mbstowcs returned a string that was longer (%d chars) "
1773 "than the buffer provided (%d chars).\n", returned_len
,
1775 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1776 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1777 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1778 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1779 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
1782 dstlen
= returned_len
;
1784 /* Convert a libc Unicode string to the destination string. */
1785 for(str_idx
= 0; str_idx
< dstlen
; str_idx
++)
1787 dststr
[str_idx
] = dststr_libc
[str_idx
];
1789 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
1790 *(((int *)dststr
) + 0),
1791 *(((int *)dststr
) + 1),
1792 *(((int *)dststr
) + 2),
1793 *(((int *)dststr
) + 3));
1797 dstlen
= returned_len
;
1799 TRACE("dstlen (return) = %d\n", dstlen
);
1800 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1801 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1802 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1803 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
1808 int (*f
)(int)=identity
;
1814 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1818 if (mapflags
& LCMAP_UPPERCASE
)
1820 else if (mapflags
& LCMAP_LOWERCASE
)
1822 for (i
=0; i
< srclen
; i
++)
1823 dststr
[i
] = (WCHAR
) f(srcstr
[i
]);
1829 /***********************************************************************
1830 * OLE2NLS_EstimateMappingLength
1832 * Estimates the number of characters required to hold the string
1833 * computed by LCMapStringA.
1835 * The size is always over-estimated, with a fixed limit on the
1836 * amount of estimation error.
1838 * Note that len == -1 is not permitted.
1840 static inline int OLE2NLS_EstimateMappingLength(LCID lcid
, DWORD dwMapFlags
,
1841 LPCSTR str
, DWORD len
)
1843 /* Estimate only for small strings to keep the estimation error from
1844 * becoming too large. */
1845 if (len
< 128) return len
* 8 + 5;
1846 else return LCMapStringA(lcid
, dwMapFlags
, str
, len
, NULL
, 0);
1849 /******************************************************************************
1850 * CompareStringA [KERNEL32.@]
1851 * Compares two strings using locale
1855 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
1860 * Defaults to a word sort, but uses a string sort if
1861 * SORT_STRINGSORT is set.
1862 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
1866 * This implementation ignores the locale
1870 * Quite inefficient.
1872 int WINAPI
CompareStringA(
1873 LCID lcid
, /* [in] locale ID */
1874 DWORD fdwStyle
, /* [in] comparison-style options */
1875 LPCSTR s1
, /* [in] first string */
1876 int l1
, /* [in] length of first string */
1877 LPCSTR s2
, /* [in] second string */
1878 int l2
) /* [in] length of second string */
1880 int mapstring_flags
;
1884 TRACE("%s and %s\n",
1885 debugstr_an (s1
,l1
), debugstr_an (s2
,l2
));
1887 if ( (s1
==NULL
) || (s2
==NULL
) )
1889 ERR("(s1=%s,s2=%s): Invalid NULL string\n",
1890 debugstr_an(s1
,l1
), debugstr_an(s2
,l2
));
1891 SetLastError(ERROR_INVALID_PARAMETER
);
1895 if(fdwStyle
& NORM_IGNORESYMBOLS
)
1896 FIXME("IGNORESYMBOLS not supported\n");
1898 if (l1
== -1) l1
= strlen(s1
);
1899 if (l2
== -1) l2
= strlen(s2
);
1901 mapstring_flags
= LCMAP_SORTKEY
| fdwStyle
;
1902 len1
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s1
, l1
);
1903 len2
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s2
, l2
);
1905 if ((len1
==0)||(len2
==0))
1906 return 0; /* something wrong happened */
1908 sk1
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, len1
+ len2
);
1910 if ( (!LCMapStringA(lcid
,mapstring_flags
,s1
,l1
,sk1
,len1
))
1911 || (!LCMapStringA(lcid
,mapstring_flags
,s2
,l2
,sk2
,len2
)) )
1913 ERR("Bug in LCmapStringA.\n");
1918 /* strcmp doesn't necessarily return -1, 0, or 1 */
1919 result
= strcmp(sk1
,sk2
);
1921 HeapFree(GetProcessHeap(),0,sk1
);
1928 /* must be greater, if we reach this point */
1932 /******************************************************************************
1933 * CompareStringW [KERNEL32.@]
1934 * This implementation ignores the locale
1935 * FIXME : Does only string sort. Should
1936 * be reimplemented the same way as CompareStringA.
1938 int WINAPI
CompareStringW(LCID lcid
, DWORD fdwStyle
,
1939 LPCWSTR s1
, int l1
, LPCWSTR s2
, int l2
)
1942 if(fdwStyle
& NORM_IGNORENONSPACE
)
1943 FIXME("IGNORENONSPACE not supported\n");
1944 if(fdwStyle
& NORM_IGNORESYMBOLS
)
1945 FIXME("IGNORESYMBOLS not supported\n");
1947 /* Is strcmp defaulting to string sort or to word sort?? */
1948 /* FIXME: Handle NORM_STRINGSORT */
1949 l1
= (l1
==-1)?strlenW(s1
):l1
;
1950 l2
= (l2
==-1)?strlenW(s2
):l2
;
1951 len
= l1
<l2
? l1
:l2
;
1952 ret
= (fdwStyle
& NORM_IGNORECASE
) ? strncmpiW(s1
,s2
,len
) : strncmpW(s1
,s2
,len
);
1953 /* not equal, return 1 or 3 */
1955 /* need to translate result */
1956 return ((int)ret
< 0) ? 1 : 3;
1958 /* same len, return 2 */
1959 if(l1
==l2
) return 2;
1960 /* the longer one is lexically greater */
1961 return (l1
<l2
)? 1 : 3;
1964 /******************************************************************************
1965 * OLE_GetFormatA [Internal]
1968 * If datelen == 0, it should return the reguired string length.
1970 This function implements stuff for GetDateFormat() and
1973 d single-digit (no leading zero) day (of month)
1974 dd two-digit day (of month)
1975 ddd short day-of-week name
1976 dddd long day-of-week name
1977 M single-digit month
1979 MMM short month name
1980 MMMM full month name
1981 y two-digit year, no leading 0
1983 yyyy four-digit year
1985 h hours with no leading zero (12-hour)
1986 hh hours with full two digits
1987 H hours with no leading zero (24-hour)
1988 HH hours with full two digits
1989 m minutes with no leading zero
1990 mm minutes with full two digits
1991 s seconds with no leading zero
1992 ss seconds with full two digits
1993 t time marker (A or P)
1994 tt time marker (AM, PM)
1995 '' used to quote literal characters
1996 '' (within a quoted string) indicates a literal '
1998 These functions REQUIRE valid locale, date, and format.
2000 static INT
OLE_GetFormatA(LCID locale
,
2003 const SYSTEMTIME
* xtime
,
2004 LPCSTR _format
, /*in*/
2009 int count
, type
, inquote
, Overflow
;
2015 const char * _dgfmt
[] = { "%d", "%02d" };
2016 const char ** dgfmt
= _dgfmt
- 1;
2018 /* report, for debugging */
2019 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",
2020 locale
, flags
, tflags
,
2021 xtime
->wYear
,xtime
->wMonth
,xtime
->wDayOfWeek
,xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2022 _format
, _format
, date
, datelen
);
2025 FIXME("datelen = 0, returning 255\n");
2029 /* initalize state variables and output buffer */
2031 count
= 0; inquote
= 0; Overflow
= 0;
2033 date
[0] = buf
[0] = '\0';
2035 strcpy(format
,_format
);
2037 /* alter the formatstring, while it works for all languages now in wine
2038 its possible that it fails when the time looks like ss:mm:hh as example*/
2039 if (tflags
& (TIME_NOMINUTESORSECONDS
))
2040 { if ((pos
= strstr ( format
, ":mm")))
2041 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2044 if (tflags
& (TIME_NOSECONDS
))
2045 { if ((pos
= strstr ( format
, ":ss")))
2046 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2050 for (inpos
= 0;; inpos
++) {
2051 /* 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]); */
2053 if (format
[inpos
] == '\'') {
2054 if (format
[inpos
+1] == '\'') {
2056 date
[outpos
++] = '\'';
2059 continue; /* we did nothing to the output */
2061 } else if (format
[inpos
] == '\0') {
2062 date
[outpos
++] = '\0';
2063 if (outpos
> datelen
) Overflow
= 1;
2066 date
[outpos
++] = format
[inpos
];
2067 if (outpos
> datelen
) {
2069 date
[outpos
-1] = '\0'; /* this is the last place where
2070 it's safe to write */
2074 } else if ( (count
&& (format
[inpos
] != type
))
2076 || (count
== 2 && strchr("ghHmst", type
)) ) {
2077 if (type
== 'h' && (tflags
& TIME_FORCE24HOURFORMAT
)) type
= 'H';
2080 GetLocaleInfoA(locale
,
2082 + (xtime
->wDayOfWeek
+6)%7,
2084 } else if (count
== 3) {
2085 GetLocaleInfoA(locale
,
2086 LOCALE_SABBREVDAYNAME1
2087 + (xtime
->wDayOfWeek
+6)%7,
2090 sprintf(buf
, dgfmt
[count
], xtime
->wDay
);
2092 } else if (type
== 'M') {
2094 GetLocaleInfoA(locale
,
2095 LOCALE_SABBREVMONTHNAME1
2096 + xtime
->wMonth
- 1,
2098 } else if (count
== 4) {
2099 GetLocaleInfoA(locale
,
2101 + xtime
->wMonth
- 1,
2104 sprintf(buf
, dgfmt
[count
], xtime
->wMonth
);
2106 } else if (type
== 'y') {
2108 sprintf(buf
, "%d", xtime
->wYear
);
2109 } else if (count
== 3) {
2111 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2113 sprintf(buf
, dgfmt
[count
], xtime
->wYear
% 100);
2115 } else if (type
== 'g') {
2117 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2121 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2123 } else if (type
== 'h') {
2124 /* gives us hours 1:00 -- 12:00 */
2125 sprintf(buf
, dgfmt
[count
], (xtime
->wHour
-1)%12 +1);
2126 } else if (type
== 'H') {
2128 sprintf(buf
, dgfmt
[count
], xtime
->wHour
);
2129 } else if ( type
== 'm') {
2130 sprintf(buf
, dgfmt
[count
], xtime
->wMinute
);
2131 } else if ( type
== 's') {
2132 sprintf(buf
, dgfmt
[count
], xtime
->wSecond
);
2133 } else if (type
== 't') {
2134 if ((tflags
& TIME_NOTIMEMARKER
))
2136 else if (count
== 1) {
2137 sprintf(buf
, "%c", (xtime
->wHour
< 12) ? 'A' : 'P');
2138 } else if (count
== 2) {
2139 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2140 GetLocaleInfoA(locale
,
2142 ? LOCALE_S1159
: LOCALE_S2359
,
2147 /* we need to check the next char in the format string
2148 again, no matter what happened */
2151 /* add the contents of buf to the output */
2152 buflen
= strlen(buf
);
2153 if (outpos
+ buflen
< datelen
) {
2154 date
[outpos
] = '\0'; /* for strcat to hook onto */
2158 date
[outpos
] = '\0';
2159 strncat(date
, buf
, datelen
- outpos
);
2160 date
[datelen
- 1] = '\0';
2161 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2162 WARN("insufficient buffer\n");
2166 /* reset the variables we used to keep track of this item */
2169 } else if (format
[inpos
] == '\0') {
2170 /* we can't check for this at the loop-head, because
2171 that breaks the printing of the last format-item */
2172 date
[outpos
] = '\0';
2175 /* continuing a code for an item */
2178 } else if (strchr("hHmstyMdg", format
[inpos
])) {
2179 type
= format
[inpos
];
2182 } else if (format
[inpos
] == '\'') {
2186 date
[outpos
++] = format
[inpos
];
2188 /* now deal with a possible buffer overflow */
2189 if (outpos
>= datelen
) {
2190 date
[datelen
- 1] = '\0';
2191 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2197 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2200 /* finish it off with a string terminator */
2203 if (outpos
> datelen
-1) outpos
= datelen
-1;
2204 date
[outpos
] = '\0';
2206 TRACE("returns string '%s', len %d\n", date
, outpos
);
2210 /******************************************************************************
2211 * OLE_GetFormatW [INTERNAL]
2213 static INT
OLE_GetFormatW(LCID locale
, DWORD flags
, DWORD tflags
,
2214 const SYSTEMTIME
* xtime
,
2216 LPWSTR output
, INT outlen
)
2219 int count
, type
=0, inquote
;
2220 int Overflow
; /* loop check */
2224 WCHAR arg0
[] = {0}, arg1
[] = {'%','d',0};
2225 WCHAR arg2
[] = {'%','0','2','d',0};
2227 int datevars
=0, timevars
=0;
2233 /* make a debug report */
2234 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2235 "%p with max len %d\n",
2236 locale
, flags
, tflags
,
2237 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2238 debugstr_w(format
), format
, output
, outlen
);
2241 FIXME("outlen = 0, returning 255\n");
2245 /* initialize state variables */
2248 inquote
= Overflow
= 0;
2249 /* this is really just a sanity check */
2250 output
[0] = buf
[0] = 0;
2252 /* this loop is the core of the function */
2253 for (inpos
= 0; /* we have several break points */ ; inpos
++) {
2255 if (format
[inpos
] == (WCHAR
) '\'') {
2256 if (format
[inpos
+1] == '\'') {
2258 output
[outpos
++] = '\'';
2263 } else if (format
[inpos
] == 0) {
2264 output
[outpos
++] = 0;
2265 if (outpos
> outlen
) Overflow
= 1;
2266 break; /* normal exit (within a quote) */
2268 output
[outpos
++] = format
[inpos
]; /* copy input */
2269 if (outpos
> outlen
) {
2271 output
[outpos
-1] = 0;
2275 } else if ( (count
&& (format
[inpos
] != type
))
2276 || ( (count
==4 && type
=='y') ||
2277 (count
==4 && type
=='M') ||
2278 (count
==4 && type
=='d') ||
2279 (count
==2 && type
=='g') ||
2280 (count
==2 && type
=='h') ||
2281 (count
==2 && type
=='H') ||
2282 (count
==2 && type
=='m') ||
2283 (count
==2 && type
=='s') ||
2284 (count
==2 && type
=='t') ) ) {
2289 GetLocaleInfoW(locale
,
2290 LOCALE_SDAYNAME1
+ (xtime
->wDayOfWeek
+6)%7,
2291 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2292 } else if (count
== 3) {
2293 GetLocaleInfoW(locale
,
2294 LOCALE_SABBREVDAYNAME1
+
2295 (xtime
->wDayOfWeek
+6)%7,
2296 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2298 sprintf( tmp
, "%.*d", count
, xtime
->wDay
);
2299 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2305 GetLocaleInfoW(locale
, LOCALE_SMONTHNAME1
+
2306 xtime
->wMonth
-1, buf
,
2307 sizeof(buf
)/sizeof(WCHAR
) );
2308 } else if (count
== 3) {
2309 GetLocaleInfoW(locale
, LOCALE_SABBREVMONTHNAME1
+
2310 xtime
->wMonth
-1, buf
,
2311 sizeof(buf
)/sizeof(WCHAR
) );
2313 sprintf( tmp
, "%.*d", count
, xtime
->wMonth
);
2314 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2319 sprintf( tmp
, "%d", xtime
->wYear
);
2320 } else if (count
== 3) {
2321 strcpy( tmp
, "yyy" );
2323 sprintf( tmp
, "%.*d", count
, xtime
->wYear
% 100 );
2325 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2330 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2331 strcpy( tmp
, "AD" );
2333 /* Win API sez we copy it verbatim */
2336 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2340 /* hours 1:00-12:00 --- is this right? */
2341 sprintf( tmp
, "%.*d", count
, (xtime
->wHour
-1)%12 +1);
2342 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2346 sprintf( tmp
, "%.*d", count
, xtime
->wHour
);
2347 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2351 sprintf( tmp
, "%.*d", count
, xtime
->wMinute
);
2352 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2356 sprintf( tmp
, "%.*d", count
, xtime
->wSecond
);
2357 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2361 GetLocaleInfoW(locale
, (xtime
->wHour
< 12) ?
2362 LOCALE_S1159
: LOCALE_S2359
,
2370 /* no matter what happened, we need to check this next
2371 character the next time we loop through */
2374 /* cat buf onto the output */
2375 outlen
= strlenW(buf
);
2376 if (outpos
+ buflen
< outlen
) {
2377 strcpyW( output
+ outpos
, buf
);
2380 lstrcpynW( output
+ outpos
, buf
, outlen
- outpos
);
2382 break; /* Abnormal exit */
2385 /* reset the variables we used this time */
2388 } else if (format
[inpos
] == 0) {
2389 /* we can't check for this at the beginning, because that
2390 would keep us from printing a format spec that ended the
2393 break; /* NORMAL EXIT */
2395 /* how we keep track of the middle of a format spec */
2398 } else if ( (datevars
&& (format
[inpos
]=='d' ||
2399 format
[inpos
]=='M' ||
2400 format
[inpos
]=='y' ||
2401 format
[inpos
]=='g') ) ||
2402 (timevars
&& (format
[inpos
]=='H' ||
2403 format
[inpos
]=='h' ||
2404 format
[inpos
]=='m' ||
2405 format
[inpos
]=='s' ||
2406 format
[inpos
]=='t') ) ) {
2407 type
= format
[inpos
];
2410 } else if (format
[inpos
] == '\'') {
2414 /* unquoted literals */
2415 output
[outpos
++] = format
[inpos
];
2420 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2421 WARN(" buffer overflow\n");
2424 /* final string terminator and sanity check */
2426 if (outpos
> outlen
-1) outpos
= outlen
-1;
2427 output
[outpos
] = '0';
2429 TRACE(" returning %s\n", debugstr_w(output
));
2431 return (!Overflow
) ? outlen
: 0;
2436 /******************************************************************************
2437 * GetDateFormatA [KERNEL32.@]
2438 * Makes an ASCII string of the date
2440 * This function uses format to format the date, or, if format
2441 * is NULL, uses the default for the locale. format is a string
2442 * of literal fields and characters as follows:
2444 * - d single-digit (no leading zero) day (of month)
2445 * - dd two-digit day (of month)
2446 * - ddd short day-of-week name
2447 * - dddd long day-of-week name
2448 * - M single-digit month
2449 * - MM two-digit month
2450 * - MMM short month name
2451 * - MMMM full month name
2452 * - y two-digit year, no leading 0
2453 * - yy two-digit year
2454 * - yyyy four-digit year
2458 INT WINAPI
GetDateFormatA(LCID locale
,DWORD flags
,
2459 const SYSTEMTIME
* xtime
,
2460 LPCSTR format
, LPSTR date
,INT datelen
)
2463 char format_buf
[40];
2466 LPSYSTEMTIME thistime
;
2472 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2473 locale
,flags
,xtime
,format
,date
,datelen
);
2476 locale
= LOCALE_SYSTEM_DEFAULT
;
2479 if (locale
== LOCALE_SYSTEM_DEFAULT
) {
2480 thislocale
= GetSystemDefaultLCID();
2481 } else if (locale
== LOCALE_USER_DEFAULT
) {
2482 thislocale
= GetUserDefaultLCID();
2484 thislocale
= locale
;
2487 if (xtime
== NULL
) {
2490 /* Silently correct wDayOfWeek by transforming to FileTime and back again */
2491 res
=SystemTimeToFileTime(xtime
,&ft
);
2492 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error */
2493 /*FIXME: SystemTimeToFileTime doesn't yet do that check */
2496 SetLastError(ERROR_INVALID_PARAMETER
);
2499 FileTimeToSystemTime(&ft
,&t
);
2504 if (format
== NULL
) {
2505 GetLocaleInfoA(thislocale
, ((flags
&DATE_LONGDATE
)
2507 : LOCALE_SSHORTDATE
),
2508 format_buf
, sizeof(format_buf
));
2509 thisformat
= format_buf
;
2511 thisformat
= format
;
2515 ret
= OLE_GetFormatA(thislocale
, flags
, 0, thistime
, thisformat
,
2520 "GetDateFormatA() returning %d, with data=%s\n",
2525 /******************************************************************************
2526 * GetDateFormatW [KERNEL32.@]
2527 * Makes a Unicode string of the date
2529 * Acts the same as GetDateFormatA(), except that it's Unicode.
2530 * Accepts & returns sizes as counts of Unicode characters.
2533 INT WINAPI
GetDateFormatW(LCID locale
,DWORD flags
,
2534 const SYSTEMTIME
* xtime
,
2536 LPWSTR date
, INT datelen
)
2538 unsigned short datearr
[] = {'1','9','9','4','-','1','-','1',0};
2540 FIXME("STUB (should call OLE_GetFormatW)\n");
2541 lstrcpynW(date
, datearr
, datelen
);
2542 return ( datelen
< 9) ? datelen
: 9;
2547 /**************************************************************************
2548 * EnumDateFormatsA (KERNEL32.@)
2550 BOOL WINAPI
EnumDateFormatsA(
2551 DATEFMT_ENUMPROCA lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2553 LCID Loc
= GetUserDefaultLCID();
2554 if(!lpDateFmtEnumProc
)
2556 SetLastError(ERROR_INVALID_PARAMETER
);
2563 case 0x00000407: /* (Loc,"de_DE") */
2567 case DATE_SHORTDATE
:
2568 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
2569 if(!(*lpDateFmtEnumProc
)("d.M.yyyy")) return TRUE
;
2570 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
2571 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2574 if(!(*lpDateFmtEnumProc
)("dddd,d. MMMM yyyy")) return TRUE
;
2575 if(!(*lpDateFmtEnumProc
)("d. MMMM yyyy")) return TRUE
;
2576 if(!(*lpDateFmtEnumProc
)("d. MMM yyyy")) return TRUE
;
2579 FIXME("Unknown date format (%ld)\n", dwFlags
);
2580 SetLastError(ERROR_INVALID_PARAMETER
);
2585 case 0x0000040c: /* (Loc,"fr_FR") */
2589 case DATE_SHORTDATE
:
2590 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2591 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
2592 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
2593 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2596 if(!(*lpDateFmtEnumProc
)("dddd d MMMM yyyy")) return TRUE
;
2597 if(!(*lpDateFmtEnumProc
)("d MMM yy")) return TRUE
;
2598 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2601 FIXME("Unknown date format (%ld)\n", dwFlags
);
2602 SetLastError(ERROR_INVALID_PARAMETER
);
2607 case 0x00000c0c: /* (Loc,"fr_CA") */
2611 case DATE_SHORTDATE
:
2612 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
2613 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
2614 if(!(*lpDateFmtEnumProc
)("yy MM dd")) return TRUE
;
2615 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2618 if(!(*lpDateFmtEnumProc
)("d MMMM, yyyy")) return TRUE
;
2619 if(!(*lpDateFmtEnumProc
)("d MMM yyyy")) return TRUE
;
2622 FIXME("Unknown date format (%ld)\n", dwFlags
);
2623 SetLastError(ERROR_INVALID_PARAMETER
);
2628 case 0x00000809: /* (Loc,"en_UK") */
2632 case DATE_SHORTDATE
:
2633 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2634 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2635 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2636 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2639 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
2640 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2643 FIXME("Unknown date format (%ld)\n", dwFlags
);
2644 SetLastError(ERROR_INVALID_PARAMETER
);
2649 case 0x00000c09: /* (Loc,"en_AU") */
2653 case DATE_SHORTDATE
:
2654 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
2655 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2656 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2659 if(!(*lpDateFmtEnumProc
)("dddd,d MMMM yyyy")) return TRUE
;
2660 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2663 FIXME("Unknown date format (%ld)\n", dwFlags
);
2664 SetLastError(ERROR_INVALID_PARAMETER
);
2669 case 0x00001009: /* (Loc,"en_CA") */
2673 case DATE_SHORTDATE
:
2674 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2675 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2676 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
2677 if(!(*lpDateFmtEnumProc
)("M/dd/yy")) return TRUE
;
2680 if(!(*lpDateFmtEnumProc
)("d-MMM-yy")) return TRUE
;
2681 if(!(*lpDateFmtEnumProc
)("MMMM d, yyyy")) return TRUE
;
2684 FIXME("Unknown date format (%ld)\n", dwFlags
);
2685 SetLastError(ERROR_INVALID_PARAMETER
);
2690 case 0x00001409: /* (Loc,"en_NZ") */
2694 case DATE_SHORTDATE
:
2695 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
2696 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2697 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
2700 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2701 if(!(*lpDateFmtEnumProc
)("dddd, d MMMM yyyy")) return TRUE
;
2704 FIXME("Unknown date format (%ld)\n", dwFlags
);
2705 SetLastError(ERROR_INVALID_PARAMETER
);
2710 case 0x00001809: /* (Loc,"en_IE") */
2714 case DATE_SHORTDATE
:
2715 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2716 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2717 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2720 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
2721 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2724 FIXME("Unknown date format (%ld)\n", dwFlags
);
2725 SetLastError(ERROR_INVALID_PARAMETER
);
2730 case 0x00001c09: /* (Loc,"en_ZA") */
2734 case DATE_SHORTDATE
:
2735 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
2738 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
2741 FIXME("Unknown date format (%ld)\n", dwFlags
);
2742 SetLastError(ERROR_INVALID_PARAMETER
);
2747 case 0x00002009: /* (Loc,"en_JM") */
2751 case DATE_SHORTDATE
:
2752 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2755 if(!(*lpDateFmtEnumProc
)("dddd,MMMM dd,yyyy")) return TRUE
;
2756 if(!(*lpDateFmtEnumProc
)("MMMM dd,yyyy")) return TRUE
;
2757 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM,yyyy")) return TRUE
;
2758 if(!(*lpDateFmtEnumProc
)("dd MMMM,yyyy")) return TRUE
;
2761 FIXME("Unknown date format (%ld)\n", dwFlags
);
2762 SetLastError(ERROR_INVALID_PARAMETER
);
2767 case 0x00002809: /* (Loc,"en_BZ") */
2768 case 0x00002c09: /* (Loc,"en_TT") */
2772 case DATE_SHORTDATE
:
2773 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2776 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM yyyy")) return TRUE
;
2779 FIXME("Unknown date format (%ld)\n", dwFlags
);
2780 SetLastError(ERROR_INVALID_PARAMETER
);
2785 default: /* default to US English "en_US" */
2789 case DATE_SHORTDATE
:
2790 if(!(*lpDateFmtEnumProc
)("M/d/yy")) return TRUE
;
2791 if(!(*lpDateFmtEnumProc
)("M/d/yyyy")) return TRUE
;
2792 if(!(*lpDateFmtEnumProc
)("MM/dd/yy")) return TRUE
;
2793 if(!(*lpDateFmtEnumProc
)("MM/dd/yyyy")) return TRUE
;
2794 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
2795 if(!(*lpDateFmtEnumProc
)("dd-MMM-yy")) return TRUE
;
2798 if(!(*lpDateFmtEnumProc
)("dddd, MMMM dd, yyyy")) return TRUE
;
2799 if(!(*lpDateFmtEnumProc
)("MMMM dd, yyyy")) return TRUE
;
2800 if(!(*lpDateFmtEnumProc
)("dddd, dd MMMM, yyyy")) return TRUE
;
2801 if(!(*lpDateFmtEnumProc
)("dd MMMM, yyyy")) return TRUE
;
2804 FIXME("Unknown date format (%ld)\n", dwFlags
);
2805 SetLastError(ERROR_INVALID_PARAMETER
);
2812 /**************************************************************************
2813 * EnumDateFormatsW (KERNEL32.@)
2815 BOOL WINAPI
EnumDateFormatsW(
2816 DATEFMT_ENUMPROCW lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2818 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc
, Locale
, dwFlags
);
2819 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2823 /**************************************************************************
2824 * EnumTimeFormatsA (KERNEL32.@)
2826 BOOL WINAPI
EnumTimeFormatsA(
2827 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2829 LCID Loc
= GetUserDefaultLCID();
2830 if(!lpTimeFmtEnumProc
)
2832 SetLastError(ERROR_INVALID_PARAMETER
);
2837 FIXME("Unknown time format (%ld)\n", dwFlags
);
2842 case 0x00000407: /* (Loc,"de_DE") */
2844 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
2845 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2846 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2847 if(!(*lpTimeFmtEnumProc
)("H.mm")) return TRUE
;
2848 if(!(*lpTimeFmtEnumProc
)("H.mm'Uhr'")) return TRUE
;
2852 case 0x0000040c: /* (Loc,"fr_FR") */
2853 case 0x00000c0c: /* (Loc,"fr_CA") */
2855 if(!(*lpTimeFmtEnumProc
)("H:mm")) return TRUE
;
2856 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2857 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2858 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
2859 if(!(*lpTimeFmtEnumProc
)("HH'h'mm")) return TRUE
;
2863 case 0x00000809: /* (Loc,"en_UK") */
2864 case 0x00000c09: /* (Loc,"en_AU") */
2865 case 0x00001409: /* (Loc,"en_NZ") */
2866 case 0x00001809: /* (Loc,"en_IE") */
2868 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
2869 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2870 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2874 case 0x00001c09: /* (Loc,"en_ZA") */
2875 case 0x00002809: /* (Loc,"en_BZ") */
2876 case 0x00002c09: /* (Loc,"en_TT") */
2878 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
2879 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
2883 default: /* default to US style "en_US" */
2885 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
2886 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
2887 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2888 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2894 /**************************************************************************
2895 * EnumTimeFormatsW (KERNEL32.@)
2897 BOOL WINAPI
EnumTimeFormatsW(
2898 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2900 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc
, Locale
, dwFlags
);
2901 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2905 /**************************************************************************
2906 * This function is used just locally !
2907 * Description: Inverts a string.
2909 static void OLE_InvertString(char* string
)
2911 char sTmpArray
[128];
2914 for (counter
= strlen(string
); counter
> 0; counter
--)
2916 memcpy(sTmpArray
+ i
, string
+ counter
-1, 1);
2919 memcpy(sTmpArray
+ i
, "\0", 1);
2920 strcpy(string
, sTmpArray
);
2923 /***************************************************************************************
2924 * This function is used just locally !
2925 * Description: Test if the given string (psNumber) is valid or not.
2926 * The valid characters are the following:
2927 * - Characters '0' through '9'.
2928 * - One decimal point (dot) if the number is a floating-point value.
2929 * - A minus sign in the first character position if the number is
2931 * If the function succeeds, psBefore/psAfter will point to the string
2932 * on the right/left of the decimal symbol. pbNegative indicates if the
2933 * number is negative.
2935 static INT
OLE_GetNumberComponents(char* pInput
, char* psBefore
, char* psAfter
, BOOL
* pbNegative
)
2937 char sNumberSet
[] = "0123456789";
2938 BOOL bInDecimal
= FALSE
;
2940 /* Test if we do have a minus sign */
2941 if ( *pInput
== '-' )
2944 pInput
++; /* Jump to the next character. */
2947 while(*pInput
!= '\0')
2949 /* Do we have a valid numeric character */
2950 if ( strchr(sNumberSet
, *pInput
) != NULL
)
2952 if (bInDecimal
== TRUE
)
2953 *psAfter
++ = *pInput
;
2955 *psBefore
++ = *pInput
;
2959 /* Is this a decimal point (dot) */
2960 if ( *pInput
== '.' )
2962 /* Is it the first time we find it */
2963 if ((bInDecimal
== FALSE
))
2966 return -1; /* ERROR: Invalid parameter */
2970 /* It's neither a numeric character, nor a decimal point.
2971 * Thus, return an error.
2979 /* Add an End of Line character to the output buffers */
2986 /**************************************************************************
2987 * This function is used just locally !
2988 * Description: A number could be formatted using different numbers
2989 * of "digits in group" (example: 4;3;2;0).
2990 * The first parameter of this function is an array
2991 * containing the rule to be used. Its format is the following:
2992 * |NDG|DG1|DG2|...|0|
2993 * where NDG is the number of used "digits in group" and DG1, DG2,
2994 * are the corresponding "digits in group".
2995 * Thus, this function returns the grouping value in the array
2996 * pointed by the second parameter.
2998 static INT
OLE_GetGrouping(char* sRule
, INT index
)
3000 char sData
[2], sRuleSize
[2];
3001 INT nData
, nRuleSize
;
3003 memcpy(sRuleSize
, sRule
, 1);
3004 memcpy(sRuleSize
+1, "\0", 1);
3005 nRuleSize
= atoi(sRuleSize
);
3007 if (index
> 0 && index
< nRuleSize
)
3009 memcpy(sData
, sRule
+index
, 1);
3010 memcpy(sData
+1, "\0", 1);
3011 nData
= atoi(sData
);
3016 memcpy(sData
, sRule
+nRuleSize
-1, 1);
3017 memcpy(sData
+1, "\0", 1);
3018 nData
= atoi(sData
);
3024 /**************************************************************************
3025 * GetNumberFormatA (KERNEL32.@)
3027 INT WINAPI
GetNumberFormatA(LCID locale
, DWORD dwflags
,
3028 LPCSTR lpvalue
, const NUMBERFMTA
* lpFormat
,
3029 LPSTR lpNumberStr
, int cchNumber
)
3031 char sNumberDigits
[3], sDecimalSymbol
[5], sDigitsInGroup
[11], sDigitGroupSymbol
[5], sILZero
[2];
3032 INT nNumberDigits
, nNumberDecimal
, i
, j
, nCounter
, nStep
, nRuleIndex
, nGrouping
, nDigits
, retVal
, nLZ
;
3033 char sNumber
[128], sDestination
[128], sDigitsAfterDecimal
[10], sDigitsBeforeDecimal
[128];
3034 char sRule
[10], sSemiColumn
[]=";", sBuffer
[5], sNegNumber
[2];
3035 char *pStr
= NULL
, *pTmpStr
= NULL
;
3036 LCID systemDefaultLCID
;
3037 BOOL bNegative
= FALSE
;
3046 strncpy(sNumber
, lpvalue
, 128);
3047 sNumber
[127] = '\0';
3049 /* Make sure we have a valid input string, get the number
3050 * of digits before and after the decimal symbol, and check
3051 * if this is a negative number.
3053 if ( OLE_GetNumberComponents(sNumber
, sDigitsBeforeDecimal
, sDigitsAfterDecimal
, &bNegative
) != -1)
3055 nNumberDecimal
= strlen(sDigitsBeforeDecimal
);
3056 nDigits
= strlen(sDigitsAfterDecimal
);
3060 SetLastError(ERROR_INVALID_PARAMETER
);
3064 /* Which source will we use to format the string */
3065 used_operation
= RETURN_ERROR
;
3066 if (lpFormat
!= NULL
)
3069 used_operation
= USE_PARAMETER
;
3073 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3074 used_operation
= USE_LOCALEINFO
;
3076 used_operation
= USE_SYSTEMDEFAULT
;
3079 /* Load the fields we need */
3080 switch(used_operation
)
3082 case USE_LOCALEINFO
:
3083 GetLocaleInfoA(locale
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3084 GetLocaleInfoA(locale
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3085 GetLocaleInfoA(locale
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3086 GetLocaleInfoA(locale
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3087 GetLocaleInfoA(locale
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3088 GetLocaleInfoA(locale
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3091 sprintf(sNumberDigits
, "%d",lpFormat
->NumDigits
);
3092 strcpy(sDecimalSymbol
, lpFormat
->lpDecimalSep
);
3093 sprintf(sDigitsInGroup
, "%d;0",lpFormat
->Grouping
);
3094 strcpy(sDigitGroupSymbol
, lpFormat
->lpThousandSep
);
3095 sprintf(sILZero
, "%d",lpFormat
->LeadingZero
);
3096 sprintf(sNegNumber
, "%d",lpFormat
->NegativeOrder
);
3098 case USE_SYSTEMDEFAULT
:
3099 systemDefaultLCID
= GetSystemDefaultLCID();
3100 GetLocaleInfoA(systemDefaultLCID
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3101 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3102 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3103 GetLocaleInfoA(systemDefaultLCID
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3104 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3105 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3108 SetLastError(ERROR_INVALID_PARAMETER
);
3112 nNumberDigits
= atoi(sNumberDigits
);
3114 /* Remove the ";" */
3117 for (nCounter
=0; nCounter
<strlen(sDigitsInGroup
); nCounter
++)
3119 if ( memcmp(sDigitsInGroup
+ nCounter
, sSemiColumn
, 1) != 0 )
3121 memcpy(sRule
+ j
, sDigitsInGroup
+ nCounter
, 1);
3126 sprintf(sBuffer
, "%d", i
);
3127 memcpy(sRule
, sBuffer
, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3128 memcpy(sRule
+ j
, "\0", 1);
3130 /* First, format the digits before the decimal. */
3131 if ((nNumberDecimal
>0) && (atoi(sDigitsBeforeDecimal
) != 0))
3133 /* Working on an inverted string is easier ! */
3134 OLE_InvertString(sDigitsBeforeDecimal
);
3136 nStep
= nCounter
= i
= j
= 0;
3138 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3140 /* Here, we will loop until we reach the end of the string.
3141 * An internal counter (j) is used in order to know when to
3142 * insert the "digit group symbol".
3144 while (nNumberDecimal
> 0)
3146 i
= nCounter
+ nStep
;
3147 memcpy(sDestination
+ i
, sDigitsBeforeDecimal
+ nCounter
, 1);
3153 if (nRuleIndex
< sRule
[0])
3155 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3156 memcpy(sDestination
+ i
+1, sDigitGroupSymbol
, strlen(sDigitGroupSymbol
));
3157 nStep
+= strlen(sDigitGroupSymbol
);
3163 memcpy(sDestination
+ i
+1, "\0", 1);
3164 /* Get the string in the right order ! */
3165 OLE_InvertString(sDestination
);
3169 nLZ
= atoi(sILZero
);
3172 /* Use 0.xxx instead of .xxx */
3173 memcpy(sDestination
, "0", 1);
3174 memcpy(sDestination
+1, "\0", 1);
3177 memcpy(sDestination
, "\0", 1);
3181 /* Second, format the digits after the decimal. */
3183 nCounter
= nNumberDigits
;
3184 if ( (nDigits
>0) && (pStr
= strstr (sNumber
, ".")) )
3186 i
= strlen(sNumber
) - strlen(pStr
) + 1;
3187 strncpy ( sDigitsAfterDecimal
, sNumber
+ i
, nNumberDigits
);
3188 j
= strlen(sDigitsAfterDecimal
);
3189 if (j
< nNumberDigits
)
3190 nCounter
= nNumberDigits
-j
;
3192 for (i
=0;i
<nCounter
;i
++)
3193 memcpy(sDigitsAfterDecimal
+i
+j
, "0", 1);
3194 memcpy(sDigitsAfterDecimal
+ nNumberDigits
, "\0", 1);
3196 i
= strlen(sDestination
);
3197 j
= strlen(sDigitsAfterDecimal
);
3198 /* Finally, construct the resulting formatted string. */
3200 for (nCounter
=0; nCounter
<i
; nCounter
++)
3201 memcpy(sNumber
+ nCounter
, sDestination
+ nCounter
, 1);
3203 memcpy(sNumber
+ nCounter
, sDecimalSymbol
, strlen(sDecimalSymbol
));
3206 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), sDigitsAfterDecimal
+ i
, 1);
3207 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), "\0", 1);
3209 /* Is it a negative number */
3210 if (bNegative
== TRUE
)
3212 i
= atoi(sNegNumber
);
3213 pStr
= sDestination
;
3219 while (*sNumber
!= '\0')
3220 *pStr
++ = *pTmpStr
++;
3225 while (*pTmpStr
!= '\0')
3226 *pStr
++ = *pTmpStr
++;
3231 while (*pTmpStr
!= '\0')
3232 *pStr
++ = *pTmpStr
++;
3235 while (*pTmpStr
!= '\0')
3236 *pStr
++ = *pTmpStr
++;
3240 while (*pTmpStr
!= '\0')
3241 *pStr
++ = *pTmpStr
++;
3246 while (*pTmpStr
!= '\0')
3247 *pStr
++ = *pTmpStr
++;
3252 strcpy(sDestination
, sNumber
);
3254 /* If cchNumber is zero, then returns the number of bytes or characters
3255 * required to hold the formatted number string
3258 retVal
= strlen(sDestination
) + 1;
3261 strncpy (lpNumberStr
, sDestination
, cchNumber
-1);
3262 *(lpNumberStr
+cchNumber
-1) = '\0'; /* ensure we got a NULL at the end */
3263 retVal
= strlen(lpNumberStr
);
3269 /**************************************************************************
3270 * GetNumberFormatW (KERNEL32.@)
3272 INT WINAPI
GetNumberFormatW(LCID locale
, DWORD dwflags
,
3273 LPCWSTR lpvalue
, const NUMBERFMTW
* lpFormat
,
3274 LPWSTR lpNumberStr
, int cchNumber
)
3276 FIXME("%s: stub, no reformatting done\n",debugstr_w(lpvalue
));
3278 lstrcpynW( lpNumberStr
, lpvalue
, cchNumber
);
3279 return cchNumber
? strlenW( lpNumberStr
) : 0;
3282 /**************************************************************************
3283 * GetCurrencyFormatA (KERNEL32.@)
3285 INT WINAPI
GetCurrencyFormatA(LCID locale
, DWORD dwflags
,
3286 LPCSTR lpvalue
, const CURRENCYFMTA
* lpFormat
,
3287 LPSTR lpCurrencyStr
, int cchCurrency
)
3289 UINT nPosOrder
, nNegOrder
;
3291 char sDestination
[128], sNegOrder
[8], sPosOrder
[8], sCurrencySymbol
[8];
3292 char *pDestination
= sDestination
;
3293 char sNumberFormated
[128];
3294 char *pNumberFormated
= sNumberFormated
;
3295 LCID systemDefaultLCID
;
3296 BOOL bIsPositive
= FALSE
, bValidFormat
= FALSE
;
3305 NUMBERFMTA numberFmt
;
3307 /* Which source will we use to format the string */
3308 used_operation
= RETURN_ERROR
;
3309 if (lpFormat
!= NULL
)
3312 used_operation
= USE_PARAMETER
;
3316 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3317 used_operation
= USE_LOCALEINFO
;
3319 used_operation
= USE_SYSTEMDEFAULT
;
3322 /* Load the fields we need */
3323 switch(used_operation
)
3325 case USE_LOCALEINFO
:
3326 /* Specific to CURRENCYFMTA */
3327 GetLocaleInfoA(locale
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3328 GetLocaleInfoA(locale
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3329 GetLocaleInfoA(locale
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3331 nPosOrder
= atoi(sPosOrder
);
3332 nNegOrder
= atoi(sNegOrder
);
3335 /* Specific to CURRENCYFMTA */
3336 nNegOrder
= lpFormat
->NegativeOrder
;
3337 nPosOrder
= lpFormat
->PositiveOrder
;
3338 strcpy(sCurrencySymbol
, lpFormat
->lpCurrencySymbol
);
3340 case USE_SYSTEMDEFAULT
:
3341 systemDefaultLCID
= GetSystemDefaultLCID();
3342 /* Specific to CURRENCYFMTA */
3343 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3344 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3345 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3347 nPosOrder
= atoi(sPosOrder
);
3348 nNegOrder
= atoi(sNegOrder
);
3351 SetLastError(ERROR_INVALID_PARAMETER
);
3355 /* Construct a temporary number format structure */
3356 if (lpFormat
!= NULL
)
3358 numberFmt
.NumDigits
= lpFormat
->NumDigits
;
3359 numberFmt
.LeadingZero
= lpFormat
->LeadingZero
;
3360 numberFmt
.Grouping
= lpFormat
->Grouping
;
3361 numberFmt
.NegativeOrder
= 0;
3362 numberFmt
.lpDecimalSep
= lpFormat
->lpDecimalSep
;
3363 numberFmt
.lpThousandSep
= lpFormat
->lpThousandSep
;
3364 bValidFormat
= TRUE
;
3367 /* Make a call to GetNumberFormatA() */
3368 if (*lpvalue
== '-')
3370 bIsPositive
= FALSE
;
3371 retVal
= GetNumberFormatA(locale
,0,lpvalue
+1,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3376 retVal
= GetNumberFormatA(locale
,0,lpvalue
,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3382 /* construct the formatted string */
3387 case 0: /* Prefix, no separation */
3388 strcpy (pDestination
, sCurrencySymbol
);
3389 strcat (pDestination
, pNumberFormated
);
3391 case 1: /* Suffix, no separation */
3392 strcpy (pDestination
, pNumberFormated
);
3393 strcat (pDestination
, sCurrencySymbol
);
3395 case 2: /* Prefix, 1 char separation */
3396 strcpy (pDestination
, sCurrencySymbol
);
3397 strcat (pDestination
, " ");
3398 strcat (pDestination
, pNumberFormated
);
3400 case 3: /* Suffix, 1 char separation */
3401 strcpy (pDestination
, pNumberFormated
);
3402 strcat (pDestination
, " ");
3403 strcat (pDestination
, sCurrencySymbol
);
3406 SetLastError(ERROR_INVALID_PARAMETER
);
3410 else /* negative number */
3414 case 0: /* format: ($1.1) */
3415 strcpy (pDestination
, "(");
3416 strcat (pDestination
, sCurrencySymbol
);
3417 strcat (pDestination
, pNumberFormated
);
3418 strcat (pDestination
, ")");
3420 case 1: /* format: -$1.1 */
3421 strcpy (pDestination
, "-");
3422 strcat (pDestination
, sCurrencySymbol
);
3423 strcat (pDestination
, pNumberFormated
);
3425 case 2: /* format: $-1.1 */
3426 strcpy (pDestination
, sCurrencySymbol
);
3427 strcat (pDestination
, "-");
3428 strcat (pDestination
, pNumberFormated
);
3430 case 3: /* format: $1.1- */
3431 strcpy (pDestination
, sCurrencySymbol
);
3432 strcat (pDestination
, pNumberFormated
);
3433 strcat (pDestination
, "-");
3435 case 4: /* format: (1.1$) */
3436 strcpy (pDestination
, "(");
3437 strcat (pDestination
, pNumberFormated
);
3438 strcat (pDestination
, sCurrencySymbol
);
3439 strcat (pDestination
, ")");
3441 case 5: /* format: -1.1$ */
3442 strcpy (pDestination
, "-");
3443 strcat (pDestination
, pNumberFormated
);
3444 strcat (pDestination
, sCurrencySymbol
);
3446 case 6: /* format: 1.1-$ */
3447 strcpy (pDestination
, pNumberFormated
);
3448 strcat (pDestination
, "-");
3449 strcat (pDestination
, sCurrencySymbol
);
3451 case 7: /* format: 1.1$- */
3452 strcpy (pDestination
, pNumberFormated
);
3453 strcat (pDestination
, sCurrencySymbol
);
3454 strcat (pDestination
, "-");
3456 case 8: /* format: -1.1 $ */
3457 strcpy (pDestination
, "-");
3458 strcat (pDestination
, pNumberFormated
);
3459 strcat (pDestination
, " ");
3460 strcat (pDestination
, sCurrencySymbol
);
3462 case 9: /* format: -$ 1.1 */
3463 strcpy (pDestination
, "-");
3464 strcat (pDestination
, sCurrencySymbol
);
3465 strcat (pDestination
, " ");
3466 strcat (pDestination
, pNumberFormated
);
3468 case 10: /* format: 1.1 $- */
3469 strcpy (pDestination
, pNumberFormated
);
3470 strcat (pDestination
, " ");
3471 strcat (pDestination
, sCurrencySymbol
);
3472 strcat (pDestination
, "-");
3474 case 11: /* format: $ 1.1- */
3475 strcpy (pDestination
, sCurrencySymbol
);
3476 strcat (pDestination
, " ");
3477 strcat (pDestination
, pNumberFormated
);
3478 strcat (pDestination
, "-");
3480 case 12: /* format: $ -1.1 */
3481 strcpy (pDestination
, sCurrencySymbol
);
3482 strcat (pDestination
, " ");
3483 strcat (pDestination
, "-");
3484 strcat (pDestination
, pNumberFormated
);
3486 case 13: /* format: 1.1- $ */
3487 strcpy (pDestination
, pNumberFormated
);
3488 strcat (pDestination
, "-");
3489 strcat (pDestination
, " ");
3490 strcat (pDestination
, sCurrencySymbol
);
3492 case 14: /* format: ($ 1.1) */
3493 strcpy (pDestination
, "(");
3494 strcat (pDestination
, sCurrencySymbol
);
3495 strcat (pDestination
, " ");
3496 strcat (pDestination
, pNumberFormated
);
3497 strcat (pDestination
, ")");
3499 case 15: /* format: (1.1 $) */
3500 strcpy (pDestination
, "(");
3501 strcat (pDestination
, pNumberFormated
);
3502 strcat (pDestination
, " ");
3503 strcat (pDestination
, sCurrencySymbol
);
3504 strcat (pDestination
, ")");
3507 SetLastError(ERROR_INVALID_PARAMETER
);
3512 if (cchCurrency
== 0)
3513 return strlen(pDestination
) + 1;
3517 strncpy (lpCurrencyStr
, pDestination
, cchCurrency
-1);
3518 *(lpCurrencyStr
+cchCurrency
-1) = '\0'; /* ensure we got a NULL at the end */
3519 return strlen(lpCurrencyStr
);
3523 /**************************************************************************
3524 * GetCurrencyFormatW (KERNEL32.@)
3526 INT WINAPI
GetCurrencyFormatW(LCID locale
, DWORD dwflags
,
3527 LPCWSTR lpvalue
, const CURRENCYFMTW
* lpFormat
,
3528 LPWSTR lpCurrencyStr
, int cchCurrency
)
3530 FIXME("This API function is NOT implemented !\n");
3534 /******************************************************************************
3535 * OLE2NLS_CheckLocale [intern]
3537 static LCID
OLE2NLS_CheckLocale (LCID locale
)
3540 { locale
= LOCALE_SYSTEM_DEFAULT
;
3543 if (locale
== LOCALE_SYSTEM_DEFAULT
)
3544 { return GetSystemDefaultLCID();
3546 else if (locale
== LOCALE_USER_DEFAULT
)
3547 { return GetUserDefaultLCID();
3553 /******************************************************************************
3554 * GetTimeFormatA [KERNEL32.@]
3555 * Makes an ASCII string of the time
3557 * Formats date according to format, or locale default if format is
3558 * NULL. The format consists of literal characters and fields as follows:
3560 * h hours with no leading zero (12-hour)
3561 * hh hours with full two digits
3562 * H hours with no leading zero (24-hour)
3563 * HH hours with full two digits
3564 * m minutes with no leading zero
3565 * mm minutes with full two digits
3566 * s seconds with no leading zero
3567 * ss seconds with full two digits
3568 * t time marker (A or P)
3569 * tt time marker (AM, PM)
3573 GetTimeFormatA(LCID locale
, /* [in] */
3574 DWORD flags
, /* [in] */
3575 const SYSTEMTIME
* xtime
, /* [in] */
3576 LPCSTR format
, /* [in] */
3577 LPSTR timestr
, /* [out] */
3578 INT timelen
/* [in] */)
3579 { char format_buf
[40];
3582 const SYSTEMTIME
* thistime
;
3584 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standard timeformat */
3587 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,xtime
,format
,timestr
,timelen
);
3589 thislocale
= OLE2NLS_CheckLocale ( locale
);
3592 { if (flags
& LOCALE_NOUSEROVERRIDE
) /* use system default */
3593 { thislocale
= GetSystemDefaultLCID();
3595 GetLocaleInfoA(thislocale
, thisflags
, format_buf
, sizeof(format_buf
));
3596 thisformat
= format_buf
;
3599 { thisformat
= format
;
3602 if (xtime
== NULL
) /* NULL means use the current local time */
3608 /* Check that hour,min and sec is in range */
3610 ret
= OLE_GetFormatA(thislocale
, thisflags
, flags
, thistime
, thisformat
,
3616 /******************************************************************************
3617 * GetTimeFormatW [KERNEL32.@]
3618 * Makes a Unicode string of the time
3621 GetTimeFormatW(LCID locale
, /* [in] */
3622 DWORD flags
, /* [in] */
3623 const SYSTEMTIME
* xtime
, /* [in] */
3624 LPCWSTR format
, /* [in] */
3625 LPWSTR timestr
, /* [out] */
3626 INT timelen
/* [in] */)
3627 { WCHAR format_buf
[40];
3630 const SYSTEMTIME
* thistime
;
3632 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standard timeformat */
3635 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,
3636 xtime
,debugstr_w(format
),timestr
,timelen
);
3638 thislocale
= OLE2NLS_CheckLocale ( locale
);
3641 { if (flags
& LOCALE_NOUSEROVERRIDE
) /* use system default */
3642 { thislocale
= GetSystemDefaultLCID();
3644 GetLocaleInfoW(thislocale
, thisflags
, format_buf
, 40);
3645 thisformat
= format_buf
;
3648 { thisformat
= format
;
3651 if (xtime
== NULL
) /* NULL means use the current local time */
3659 ret
= OLE_GetFormatW(thislocale
, thisflags
, flags
, thistime
, thisformat
,
3664 /******************************************************************************
3665 * EnumCalendarInfoA [KERNEL32.@]
3667 BOOL WINAPI
EnumCalendarInfoA(
3668 CALINFO_ENUMPROCA calinfoproc
,LCID locale
,CALID calendar
,CALTYPE caltype
3670 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc
,locale
,calendar
,caltype
);