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
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(string
);
43 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
44 * MUST contain all #defines from winnls.h
45 * last entry has NULL name, 0 id.
47 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
48 static const struct tagLOCALE_NAME2ID
{
52 LOCALE_ENTRY(ILANGUAGE
),
53 LOCALE_ENTRY(SLANGUAGE
),
54 LOCALE_ENTRY(SENGLANGUAGE
),
55 LOCALE_ENTRY(SABBREVLANGNAME
),
56 LOCALE_ENTRY(SNATIVELANGNAME
),
57 LOCALE_ENTRY(ICOUNTRY
),
58 LOCALE_ENTRY(SCOUNTRY
),
59 LOCALE_ENTRY(SENGCOUNTRY
),
60 LOCALE_ENTRY(SABBREVCTRYNAME
),
61 LOCALE_ENTRY(SNATIVECTRYNAME
),
62 LOCALE_ENTRY(IDEFAULTLANGUAGE
),
63 LOCALE_ENTRY(IDEFAULTCOUNTRY
),
64 LOCALE_ENTRY(IDEFAULTCODEPAGE
),
65 LOCALE_ENTRY(IDEFAULTANSICODEPAGE
),
66 LOCALE_ENTRY(IDEFAULTMACCODEPAGE
),
68 LOCALE_ENTRY(IMEASURE
),
69 LOCALE_ENTRY(SDECIMAL
),
70 LOCALE_ENTRY(STHOUSAND
),
71 LOCALE_ENTRY(SGROUPING
),
72 LOCALE_ENTRY(IDIGITS
),
74 LOCALE_ENTRY(INEGNUMBER
),
75 LOCALE_ENTRY(SNATIVEDIGITS
),
76 LOCALE_ENTRY(SCURRENCY
),
77 LOCALE_ENTRY(SINTLSYMBOL
),
78 LOCALE_ENTRY(SMONDECIMALSEP
),
79 LOCALE_ENTRY(SMONTHOUSANDSEP
),
80 LOCALE_ENTRY(SMONGROUPING
),
81 LOCALE_ENTRY(ICURRDIGITS
),
82 LOCALE_ENTRY(IINTLCURRDIGITS
),
83 LOCALE_ENTRY(ICURRENCY
),
84 LOCALE_ENTRY(INEGCURR
),
87 LOCALE_ENTRY(SSHORTDATE
),
88 LOCALE_ENTRY(SLONGDATE
),
89 LOCALE_ENTRY(STIMEFORMAT
),
93 LOCALE_ENTRY(ITIMEMARKPOSN
),
94 LOCALE_ENTRY(ICENTURY
),
95 LOCALE_ENTRY(ITLZERO
),
96 LOCALE_ENTRY(IDAYLZERO
),
97 LOCALE_ENTRY(IMONLZERO
),
100 LOCALE_ENTRY(ICALENDARTYPE
),
101 LOCALE_ENTRY(IOPTIONALCALENDAR
),
102 LOCALE_ENTRY(IFIRSTDAYOFWEEK
),
103 LOCALE_ENTRY(IFIRSTWEEKOFYEAR
),
104 LOCALE_ENTRY(SDAYNAME1
),
105 LOCALE_ENTRY(SDAYNAME2
),
106 LOCALE_ENTRY(SDAYNAME3
),
107 LOCALE_ENTRY(SDAYNAME4
),
108 LOCALE_ENTRY(SDAYNAME5
),
109 LOCALE_ENTRY(SDAYNAME6
),
110 LOCALE_ENTRY(SDAYNAME7
),
111 LOCALE_ENTRY(SABBREVDAYNAME1
),
112 LOCALE_ENTRY(SABBREVDAYNAME2
),
113 LOCALE_ENTRY(SABBREVDAYNAME3
),
114 LOCALE_ENTRY(SABBREVDAYNAME4
),
115 LOCALE_ENTRY(SABBREVDAYNAME5
),
116 LOCALE_ENTRY(SABBREVDAYNAME6
),
117 LOCALE_ENTRY(SABBREVDAYNAME7
),
118 LOCALE_ENTRY(SMONTHNAME1
),
119 LOCALE_ENTRY(SMONTHNAME2
),
120 LOCALE_ENTRY(SMONTHNAME3
),
121 LOCALE_ENTRY(SMONTHNAME4
),
122 LOCALE_ENTRY(SMONTHNAME5
),
123 LOCALE_ENTRY(SMONTHNAME6
),
124 LOCALE_ENTRY(SMONTHNAME7
),
125 LOCALE_ENTRY(SMONTHNAME8
),
126 LOCALE_ENTRY(SMONTHNAME9
),
127 LOCALE_ENTRY(SMONTHNAME10
),
128 LOCALE_ENTRY(SMONTHNAME11
),
129 LOCALE_ENTRY(SMONTHNAME12
),
130 LOCALE_ENTRY(SMONTHNAME13
),
131 LOCALE_ENTRY(SABBREVMONTHNAME1
),
132 LOCALE_ENTRY(SABBREVMONTHNAME2
),
133 LOCALE_ENTRY(SABBREVMONTHNAME3
),
134 LOCALE_ENTRY(SABBREVMONTHNAME4
),
135 LOCALE_ENTRY(SABBREVMONTHNAME5
),
136 LOCALE_ENTRY(SABBREVMONTHNAME6
),
137 LOCALE_ENTRY(SABBREVMONTHNAME7
),
138 LOCALE_ENTRY(SABBREVMONTHNAME8
),
139 LOCALE_ENTRY(SABBREVMONTHNAME9
),
140 LOCALE_ENTRY(SABBREVMONTHNAME10
),
141 LOCALE_ENTRY(SABBREVMONTHNAME11
),
142 LOCALE_ENTRY(SABBREVMONTHNAME12
),
143 LOCALE_ENTRY(SABBREVMONTHNAME13
),
144 LOCALE_ENTRY(SPOSITIVESIGN
),
145 LOCALE_ENTRY(SNEGATIVESIGN
),
146 LOCALE_ENTRY(IPOSSIGNPOSN
),
147 LOCALE_ENTRY(INEGSIGNPOSN
),
148 LOCALE_ENTRY(IPOSSYMPRECEDES
),
149 LOCALE_ENTRY(IPOSSEPBYSPACE
),
150 LOCALE_ENTRY(INEGSYMPRECEDES
),
151 LOCALE_ENTRY(INEGSEPBYSPACE
),
152 LOCALE_ENTRY(FONTSIGNATURE
),
153 LOCALE_ENTRY(SISO639LANGNAME
),
154 LOCALE_ENTRY(SISO3166CTRYNAME
),
158 static char *GetLocaleSubkeyName( DWORD lctype
);
160 /***********************************************************************
161 * GetUserDefaultLCID (KERNEL32.@)
163 LCID WINAPI
GetUserDefaultLCID(void)
165 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT
);
168 /***********************************************************************
169 * GetSystemDefaultLCID (KERNEL32.@)
171 LCID WINAPI
GetSystemDefaultLCID(void)
173 return GetUserDefaultLCID();
176 #define NLS_MAX_LANGUAGES 20
180 LANGID found_lang_id
[NLS_MAX_LANGUAGES
];
181 char found_language
[NLS_MAX_LANGUAGES
][3];
182 char found_country
[NLS_MAX_LANGUAGES
][3];
186 static BOOL CALLBACK
NLS_FindLanguageID_ProcA(HMODULE hModule
, LPCSTR type
,
187 LPCSTR name
, WORD LangID
, LONG lParam
)
189 LANG_FIND_DATA
*l_data
= (LANG_FIND_DATA
*)lParam
;
190 LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
191 char buf_language
[128];
192 char buf_country
[128];
193 char buf_en_language
[128];
195 TRACE("%04X\n", (UINT
)LangID
);
196 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
197 return TRUE
; /* continue search */
202 GetLocaleInfoA(lcid
, LOCALE_SISO639LANGNAME
|LOCALE_NOUSEROVERRIDE
,
203 buf_language
, sizeof(buf_language
));
204 TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language
);
206 GetLocaleInfoA(lcid
, LOCALE_SISO3166CTRYNAME
|LOCALE_NOUSEROVERRIDE
,
207 buf_country
, sizeof(buf_country
));
208 TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country
);
210 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_language
))
212 if(l_data
->country
&& strlen(l_data
->country
) > 0)
214 if(!strcasecmp(l_data
->country
, buf_country
))
216 l_data
->found_lang_id
[0] = LangID
;
218 TRACE("Found lang_id %04X for %s_%s\n", LangID
, l_data
->lang
, l_data
->country
);
219 return FALSE
; /* stop enumeration */
222 else /* l_data->country not specified */
224 if(l_data
->n_found
< NLS_MAX_LANGUAGES
)
226 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
227 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
228 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
230 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
231 return TRUE
; /* continue search */
236 /* Just in case, check LOCALE_SENGLANGUAGE too,
237 * in hope that possible alias name might have that value.
239 buf_en_language
[0] = 0;
240 GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
|LOCALE_NOUSEROVERRIDE
,
241 buf_en_language
, sizeof(buf_en_language
));
242 TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language
);
244 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_en_language
))
246 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
247 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
248 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
250 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
253 return TRUE
; /* continue search */
256 /***********************************************************************
260 * Lang: a string whose two first chars are the iso name of a language.
261 * Country: a string whose two first chars are the iso name of country
262 * Charset: a string defining the chossen charset encoding
263 * Dialect: a string defining a variation of the locale
265 * all those values are from the standardized format of locale
266 * name in unix which is: Lang[_Country][.Charset][@Dialect]
269 * the numeric code of the language used by Windows
271 * FIXME: Charset and Dialect are not handled
273 static LANGID
NLS_GetLanguageID(LPCSTR Lang
, LPCSTR Country
, LPCSTR Charset
, LPCSTR Dialect
)
275 LANG_FIND_DATA l_data
;
276 char lang_string
[256];
280 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
284 memset(&l_data
, 0, sizeof(LANG_FIND_DATA
));
285 strncpy(l_data
.lang
, Lang
, sizeof(l_data
.lang
));
287 if(Country
&& strlen(Country
) > 0)
288 strncpy(l_data
.country
, Country
, sizeof(l_data
.country
));
290 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
291 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
293 strcpy(lang_string
, l_data
.lang
);
294 if(l_data
.country
&& strlen(l_data
.country
) > 0)
296 strcat(lang_string
, "_");
297 strcat(lang_string
, l_data
.country
);
302 if(l_data
.country
&& strlen(l_data
.country
) > 0)
304 MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string
);
305 l_data
.country
[0] = 0;
306 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
307 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
311 /* Re-evaluate lang_string */
312 strcpy(lang_string
, l_data
.lang
);
313 if(l_data
.country
&& strlen(l_data
.country
) > 0)
315 strcat(lang_string
, "_");
316 strcat(lang_string
, l_data
.country
);
321 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string
);
322 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
326 if(l_data
.n_found
== 1)
327 TRACE("For language '%s' lang_id %04X was found\n", lang_string
, l_data
.found_lang_id
[0]);
328 else /* l_data->n_found > 1 */
331 MESSAGE("For language '%s' several language ids were found:\n", lang_string
);
332 for(i
= 0; i
< l_data
.n_found
; i
++)
333 MESSAGE("%s_%s - %04X; ", l_data
.found_language
[i
], l_data
.found_country
[i
], l_data
.found_lang_id
[i
]);
335 MESSAGE("\nInstead of using first in the list, suggest to define\n"
336 "your LANG environment variable like this: LANG=%s_%s\n",
337 l_data
.found_language
[0], l_data
.found_country
[0]);
341 TRACE("Returning %04X\n", l_data
.found_lang_id
[0]);
342 return l_data
.found_lang_id
[0];
345 /***********************************************************************
346 * GetUserDefaultLangID (KERNEL32.@)
348 LANGID WINAPI
GetUserDefaultLangID(void)
350 /* caching result, if defined from environment, which should (?) not change during a WINE session */
351 static LANGID userLCID
= 0;
356 char *lang
,*country
,*charset
,*dialect
,*next
;
358 if (GetEnvironmentVariableA( "LANGUAGE", buf
, sizeof(buf
) )) goto ok
;
359 if (GetEnvironmentVariableA( "LANG", buf
, sizeof(buf
) )) goto ok
;
360 if (GetEnvironmentVariableA( "LC_ALL", buf
, sizeof(buf
) )) goto ok
;
361 if (GetEnvironmentVariableA( "LC_MESSAGES", buf
, sizeof(buf
) )) goto ok
;
362 if (GetEnvironmentVariableA( "LC_CTYPE", buf
, sizeof(buf
) )) goto ok
;
364 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
367 if (!strcmp(buf
,"POSIX") || !strcmp(buf
,"C"))
368 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
373 next
=strchr(lang
,':'); if (next
) *next
++='\0';
374 dialect
=strchr(lang
,'@'); if (dialect
) *dialect
++='\0';
375 charset
=strchr(lang
,'.'); if (charset
) *charset
++='\0';
376 country
=strchr(lang
,'_'); if (country
) *country
++='\0';
378 userLCID
= NLS_GetLanguageID(lang
, country
, charset
, dialect
);
381 } while (lang
&& !userLCID
);
385 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
387 userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
393 /***********************************************************************
394 * GetSystemDefaultLangID (KERNEL32.@)
396 LANGID WINAPI
GetSystemDefaultLangID(void)
398 return GetUserDefaultLangID();
401 /******************************************************************************
402 * ConvertDefaultLocale (KERNEL32.@)
404 LCID WINAPI
ConvertDefaultLocale (LCID lcid
)
406 { case LOCALE_SYSTEM_DEFAULT
:
407 return GetSystemDefaultLCID();
408 case LOCALE_USER_DEFAULT
:
409 return GetUserDefaultLCID();
411 return MAKELCID (LANG_NEUTRAL
, SUBLANG_NEUTRAL
);
413 return MAKELANGID( PRIMARYLANGID(lcid
), SUBLANG_NEUTRAL
);
416 /* Enhanced version of LoadStringW.
417 * It takes LanguageId to find and load language dependant resources.
418 * Resource is copied as is: "binary" strings are not truncated.
419 * Return: length of resource + 1 to distinguish absent resources
420 * from the resources with zero length.
422 static INT
NLS_LoadStringExW(HMODULE hModule
, LANGID lang_id
, UINT res_id
, LPWSTR buffer
, INT buflen
)
430 /* Replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
431 if(SUBLANGID(lang_id
) == SUBLANG_NEUTRAL
)
432 lang_id
= MAKELANGID(PRIMARYLANGID(lang_id
), SUBLANG_DEFAULT
);
434 hrsrc
= FindResourceExW(hModule
, RT_STRINGW
, (LPCWSTR
)((res_id
>> 4) + 1), lang_id
);
437 hmem
= LoadResource(hModule
, hrsrc
);
440 p
= LockResource(hmem
);
441 string_num
= res_id
& 0x000f;
442 for(i
= 0; i
< string_num
; i
++)
445 TRACE("strlen = %d\n", (int)*p
);
447 if (buffer
== NULL
) return *p
;
448 i
= min(buflen
- 1, *p
);
450 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
451 buffer
[i
] = (WCHAR
) 0;
454 buffer
[0] = (WCHAR
) 0;
458 TRACE("%s loaded!\n", debugstr_w(buffer
));
462 /******************************************************************************
463 * GetLocaleInfoA (KERNEL32.@)
466 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
468 * MS online documentation states that the string returned is NULL terminated
469 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
470 * terminated string".
472 INT WINAPI
GetLocaleInfoA(LCID lcid
,LCTYPE LCType
,LPSTR buf
,INT len
)
474 LPCSTR retString
= NULL
;
478 DWORD dwBufferSize
=128;
481 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid
,LCType
,buf
,len
);
483 if (len
&& (! buf
) ) {
484 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
488 if (lcid
== LOCALE_NEUTRAL
|| lcid
== LANG_SYSTEM_DEFAULT
)
490 lcid
= GetSystemDefaultLCID();
492 else if (lcid
== LANG_USER_DEFAULT
) /*0x800*/
494 lcid
= GetUserDefaultLCID();
497 /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
498 from the registry. Instead, use system default values. */
499 NoUserOverride
= (LCType
& LOCALE_NOUSEROVERRIDE
) != 0;
501 LCType
&= ~(LOCALE_NOUSEROVERRIDE
|LOCALE_USE_CP_ACP
);
503 /* First, check if it's in the registry. */
504 /* All user customized values are stored in the registry by SetLocaleInfo */
505 if ( !NoUserOverride
&& (pacKey
= GetLocaleSubkeyName(LCType
)) )
510 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
512 if ( RegOpenKeyExA( HKEY_CURRENT_USER
, acRealKey
,
513 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
515 if ( RegQueryValueExA( hKey
, NULL
, NULL
, NULL
, (LPBYTE
)acBuffer
,
516 &dwBufferSize
) == ERROR_SUCCESS
)
518 retString
= acBuffer
;
525 /* If not in the registry, get it from the NLS entries. */
530 /* check if language is registered in the kernel32 resources */
531 if((res_size
= NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid
),
532 LCType
, wcBuffer
, sizeof(wcBuffer
)/sizeof(wcBuffer
[0])))) {
533 WideCharToMultiByte(CP_ACP
, 0, wcBuffer
, res_size
, acBuffer
, dwBufferSize
, NULL
, NULL
);
534 retString
= acBuffer
;
539 /* if not found report a most descriptive error */
542 /* If we are through all of this, retLen should not be zero anymore.
543 If it is, the value is not supported */
545 while (locale_name2id
[i
].name
!=NULL
) {
546 if (LCType
== locale_name2id
[i
].id
) {
547 retString
= locale_name2id
[i
].name
;
553 FIXME("Unkown LC type %lX\n", LCType
);
555 FIXME("'%s' is not defined for your language (%04X).\n"
556 "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
557 "and submit patch for inclusion into the next Wine release.\n",
558 retString
, LOWORD(lcid
));
559 SetLastError(ERROR_INVALID_PARAMETER
);
563 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
564 if (LCType
== LOCALE_FONTSIGNATURE
) {
566 len
= (len
< sizeof(FONTSIGNATURE
)) ? len
: sizeof(FONTSIGNATURE
);
567 memcpy(buf
, retString
, len
);
570 return sizeof(FONTSIGNATURE
);
572 /* if len=0 return only the length, don't touch the buffer*/
574 lstrcpynA(buf
,retString
,len
);
575 return strlen(buf
) + 1;
577 return strlen(retString
)+1;
580 /******************************************************************************
581 * GetLocaleInfoW (KERNEL32.@)
584 * MS documentation states that len "specifies the size, in bytes (ANSI version)
585 * or characters (Unicode version), of" wbuf. Thus the number returned is
586 * the same between GetLocaleInfoW and GetLocaleInfoA.
588 INT WINAPI
GetLocaleInfoW(LCID lcid
,LCTYPE LCType
,LPWSTR wbuf
,INT len
)
592 if (len
&& (! wbuf
) )
593 { SetLastError(ERROR_INSUFFICIENT_BUFFER
);
597 abuf
= (LPSTR
)HeapAlloc(GetProcessHeap(),0,len
);
598 wlen
= GetLocaleInfoA(lcid
, LCType
, abuf
, len
);
600 if (wlen
&& len
) /* if len=0 return only the length*/
601 MultiByteToWideChar( CP_ACP
, 0, abuf
, -1, wbuf
, len
);
603 HeapFree(GetProcessHeap(),0,abuf
);
607 /******************************************************************************
609 * GetLocaleSubkeyName [helper function]
611 * - For use with the registry.
612 * - Gets the registry subkey name for a given lctype.
614 static char *GetLocaleSubkeyName( DWORD lctype
)
620 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
621 * the values are stored in the registry, confirmed under Windows,
622 * for the ones that actually assign pacKey. Cases that aren't finished
623 * have not been confirmed, so that must be done before they can be
626 case LOCALE_SDATE
: /* The date separator. */
629 case LOCALE_ICURRDIGITS
:
630 pacKey
= "iCurrDigits";
632 case LOCALE_SDECIMAL
:
635 case LOCALE_ICURRENCY
:
636 pacKey
= "iCurrency";
638 case LOCALE_SGROUPING
:
639 pacKey
= "sGrouping";
647 /* case LOCALE_ICALENDARTYPE: */
648 /* case LOCALE_IFIRSTDAYOFWEEK: */
649 /* case LOCALE_IFIRSTWEEKOFYEAR: */
650 /* case LOCALE_SYEARMONTH : */
651 /* case LOCALE_SPOSITIVESIGN : */
652 /* case LOCALE_IPAPERSIZE: */
654 case LOCALE_SLONGDATE
:
655 pacKey
= "sLongDate";
657 case LOCALE_SMONDECIMALSEP
:
658 pacKey
= "sMonDecimalSep";
660 case LOCALE_SMONGROUPING
:
661 pacKey
= "sMonGrouping";
663 case LOCALE_IMEASURE
:
666 case LOCALE_SMONTHOUSANDSEP
:
667 pacKey
= "sMonThousandSep";
669 case LOCALE_INEGCURR
:
672 case LOCALE_SNEGATIVESIGN
:
673 pacKey
= "sNegativeSign";
675 case LOCALE_INEGNUMBER
:
676 pacKey
= "iNegNumber";
678 case LOCALE_SSHORTDATE
:
679 pacKey
= "sShortDate";
681 case LOCALE_ILDATE
: /* Long Date format ordering specifier. */
690 case LOCALE_ITIME
: /* Time format specifier. */
693 case LOCALE_STHOUSAND
:
694 pacKey
= "sThousand";
696 case LOCALE_S1159
: /* AM */
702 case LOCALE_S2359
: /* PM */
705 case LOCALE_STIMEFORMAT
:
706 pacKey
= "sTimeFormat";
708 case LOCALE_SCURRENCY
:
709 pacKey
= "sCurrency";
712 /* The following are not listed under MSDN as supported,
713 * but seem to be used and also stored in the registry.
719 case LOCALE_SCOUNTRY
:
722 case LOCALE_ICOUNTRY
:
725 case LOCALE_SLANGUAGE
:
726 pacKey
= "sLanguage";
736 /******************************************************************************
737 * SetLocaleInfoA [KERNEL32.@]
739 BOOL WINAPI
SetLocaleInfoA(LCID lcid
, LCTYPE lctype
, LPCSTR data
)
745 if ( (pacKey
= GetLocaleSubkeyName(lctype
)) )
747 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
748 if ( RegCreateKeyA( HKEY_CURRENT_USER
, acRealKey
,
749 &hKey
) == ERROR_SUCCESS
)
751 if ( RegSetValueExA( hKey
, NULL
, 0, REG_SZ
,
752 data
, strlen(data
)+1 ) != ERROR_SUCCESS
)
754 ERR("SetLocaleInfoA: %s did not work\n", pacKey
);
761 FIXME("(%ld,%ld,%s): stub\n",lcid
,lctype
,data
);
766 /******************************************************************************
767 * IsValidLocale [KERNEL32.@]
769 BOOL WINAPI
IsValidLocale(LCID lcid
,DWORD flags
)
771 /* check if language is registered in the kernel32 resources */
772 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW
, (LPCWSTR
)LOCALE_ILANGUAGE
, LOWORD(lcid
)))
778 static BOOL CALLBACK
EnumResourceLanguagesProcW(HMODULE hModule
, LPCWSTR type
,
779 LPCWSTR name
, WORD LangID
, LONG lParam
)
783 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
784 sprintf(bufA
, "%08X", (UINT
)LangID
);
785 MultiByteToWideChar(CP_ACP
, 0, bufA
, -1, bufW
, sizeof(bufW
)/sizeof(bufW
[0]));
786 return lpfnLocaleEnum(bufW
);
789 /******************************************************************************
790 * EnumSystemLocalesW [KERNEL32.@]
792 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
,
795 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
797 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW
,
798 (LPCWSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcW
,
799 (LONG
)lpfnLocaleEnum
);
804 static BOOL CALLBACK
EnumResourceLanguagesProcA(HMODULE hModule
, LPCSTR type
,
805 LPCSTR name
, WORD LangID
, LONG lParam
)
808 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
809 sprintf(bufA
, "%08X", (UINT
)LangID
);
810 return lpfnLocaleEnum(bufA
);
813 /******************************************************************************
814 * EnumSystemLocalesA [KERNEL32.@]
816 BOOL WINAPI
EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum
,
819 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
821 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
822 (LPCSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcA
,
823 (LONG
)lpfnLocaleEnum
);
828 /***********************************************************************
829 * VerLanguageNameA [KERNEL32.@]
831 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
836 return GetLocaleInfoA(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
839 /***********************************************************************
840 * VerLanguageNameW [KERNEL32.@]
842 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
847 return GetLocaleInfoW(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
851 static const unsigned char LCM_Unicode_LUT
[] = {
885 7 , 29, /* " - 34 */ /* " */
890 6 , 128, /* ' - 39 */
896 6 , 130, /* - - 45 */
900 12 , 33, /* 1 - 49 */
901 12 , 51, /* 2 - 50 */
902 12 , 70, /* 3 - 51 */
903 12 , 88, /* 4 - 52 */
904 12 , 106, /* 5 - 53 */
905 12 , 125, /* 6 - 54 */
906 12 , 144, /* 7 - 55 */
907 12 , 162, /* 8 - 56 */
908 12 , 180, /* 9 - 57 */
918 14 , 10, /* C - 67 */
919 14 , 26, /* D - 68 */
920 14 , 33, /* E - 69 */
921 14 , 35, /* F - 70 */
922 14 , 37, /* G - 71 */
923 14 , 44, /* H - 72 */
924 14 , 50, /* I - 73 */
925 14 , 53, /* J - 74 */
926 14 , 54, /* K - 75 */
927 14 , 72, /* L - 76 */
928 14 , 81, /* M - 77 */
929 14 , 112, /* N - 78 */
930 14 , 124, /* O - 79 */
931 14 , 126, /* P - 80 */
932 14 , 137, /* Q - 81 */
933 14 , 138, /* R - 82 */
934 14 , 145, /* S - 83 */
935 14 , 153, /* T - 84 */
936 14 , 159, /* U - 85 */
937 14 , 162, /* V - 86 */
938 14 , 164, /* W - 87 */
939 14 , 166, /* X - 88 */
940 14 , 167, /* Y - 89 */
941 14 , 169, /* Z - 90 */
950 14 , 10, /* c - 99 */
951 14 , 26, /* d - 100 */
952 14 , 33, /* e - 101 */
953 14 , 35, /* f - 102 */
954 14 , 37, /* g - 103 */
955 14 , 44, /* h - 104 */
956 14 , 50, /* i - 105 */
957 14 , 53, /* j - 106 */
958 14 , 54, /* k - 107 */
959 14 , 72, /* l - 108 */
960 14 , 81, /* m - 109 */
961 14 , 112, /* n - 110 */
962 14 , 124, /* o - 111 */
963 14 , 126, /* p - 112 */
964 14 , 137, /* q - 113 */
965 14 , 138, /* r - 114 */
966 14 , 145, /* s - 115 */
967 14 , 153, /* t - 116 */
968 14 , 159, /* u - 117 */
969 14 , 162, /* v - 118 */
970 14 , 164, /* w - 119 */
971 14 , 166, /* x - 120 */
972 14 , 167, /* y - 121 */
973 14 , 169, /* z - 122 */
974 7 , 74, /* { - 123 */
975 7 , 76, /* | - 124 */
976 7 , 78, /* } - 125 */
977 7 , 80, /* ~ - 126 */
978 6 , 29, /* \x7f - 127 */
979 6 , 30, /* € - 128 */
980 6 , 31, /* � - 129 */
981 7 , 123, /* ‚ - 130 */
982 14 , 35, /* ƒ - 131 */
983 7 , 127, /* „ - 132 */
984 10 , 21, /* … - 133 */
985 10 , 15, /* † - 134 */
986 10 , 16, /* ‡ - 135 */
987 7 , 67, /* ˆ - 136 */
988 10 , 22, /* ‰ - 137 */
989 14 , 145, /* Š - 138 */
990 7 , 136, /* ‹ - 139 */
991 14 + 16 , 124, /* Œ - 140 */
992 6 , 43, /* � - 141 */
993 6 , 44, /* Ž - 142 */
994 6 , 45, /* � - 143 */
995 6 , 46, /* � - 144 */
996 7 , 121, /* ‘ - 145 */
997 7 , 122, /* ’ - 146 */
998 7 , 125, /* “ - 147 */
999 7 , 126, /* ” - 148 */
1000 10 , 17, /* • - 149 */
1001 6 , 137, /* – - 150 */
1002 6 , 139, /* — - 151 */
1003 7 , 93, /* ˜ - 152 */
1004 14 , 156, /* ™ - 153 */
1005 14 , 145, /* š - 154 */
1006 7 , 137, /* › - 155 */
1007 14 + 16 , 124, /* œ - 156 */
1008 6 , 59, /* � - 157 */
1009 6 , 60, /* ž - 158 */
1010 14 , 167, /* Ÿ - 159 */
1012 7 , 81, /* ¡ - 161 */
1013 10 , 2, /* ¢ - 162 */
1014 10 , 3, /* £ - 163 */
1015 10 , 4, /* ¤ - 164 */
1016 10 , 5, /* ¥ - 165 */
1017 7 , 82, /* ¦ - 166 */
1018 10 , 6, /* § - 167 */
1019 7 , 83, /* ¨ - 168 */
1020 10 , 7, /* © - 169 */
1021 14 , 2, /* ª - 170 */
1022 8 , 24, /* « - 171 */
1023 10 , 8, /* ¬ - 172 */
1024 6 , 131, /* - 173 */
1025 10 , 9, /* ® - 174 */
1026 7 , 84, /* ¯ - 175 */
1027 10 , 10, /* ° - 176 */
1028 8 , 23, /* ± - 177 */
1029 12 , 51, /* ² - 178 */
1030 12 , 70, /* ³ - 179 */
1031 7 , 85, /* ´ - 180 */
1032 10 , 11, /* µ - 181 */
1033 10 , 12, /* ¶ - 182 */
1034 10 , 13, /* · - 183 */
1035 7 , 86, /* ¸ - 184 */
1036 12 , 33, /* ¹ - 185 */
1037 14 , 124, /* º - 186 */
1038 8 , 26, /* » - 187 */
1039 12 , 21, /* ¼ - 188 */
1040 12 , 25, /* ½ - 189 */
1041 12 , 29, /* ¾ - 190 */
1042 7 , 87, /* ¿ - 191 */
1043 14 , 2, /* À - 192 */
1044 14 , 2, /* Á - 193 */
1045 14 , 2, /* Â - 194 */
1046 14 , 2, /* Ã - 195 */
1047 14 , 2, /* Ä - 196 */
1048 14 , 2, /* Å - 197 */
1049 14 + 16 , 2, /* Æ - 198 */
1050 14 , 10, /* Ç - 199 */
1051 14 , 33, /* È - 200 */
1052 14 , 33, /* É - 201 */
1053 14 , 33, /* Ê - 202 */
1054 14 , 33, /* Ë - 203 */
1055 14 , 50, /* Ì - 204 */
1056 14 , 50, /* Í - 205 */
1057 14 , 50, /* Î - 206 */
1058 14 , 50, /* Ï - 207 */
1059 14 , 26, /* Ð - 208 */
1060 14 , 112, /* Ñ - 209 */
1061 14 , 124, /* Ò - 210 */
1062 14 , 124, /* Ó - 211 */
1063 14 , 124, /* Ô - 212 */
1064 14 , 124, /* Õ - 213 */
1065 14 , 124, /* Ö - 214 */
1066 8 , 28, /* × - 215 */
1067 14 , 124, /* Ø - 216 */
1068 14 , 159, /* Ù - 217 */
1069 14 , 159, /* Ú - 218 */
1070 14 , 159, /* Û - 219 */
1071 14 , 159, /* Ü - 220 */
1072 14 , 167, /* Ý - 221 */
1073 14 + 32 , 153, /* Þ - 222 */
1074 14 + 48 , 145, /* ß - 223 */
1075 14 , 2, /* à - 224 */
1076 14 , 2, /* á - 225 */
1077 14 , 2, /* â - 226 */
1078 14 , 2, /* ã - 227 */
1079 14 , 2, /* ä - 228 */
1080 14 , 2, /* å - 229 */
1081 14 + 16 , 2, /* æ - 230 */
1082 14 , 10, /* ç - 231 */
1083 14 , 33, /* è - 232 */
1084 14 , 33, /* é - 233 */
1085 14 , 33, /* ê - 234 */
1086 14 , 33, /* ë - 235 */
1087 14 , 50, /* ì - 236 */
1088 14 , 50, /* í - 237 */
1089 14 , 50, /* î - 238 */
1090 14 , 50, /* ï - 239 */
1091 14 , 26, /* ð - 240 */
1092 14 , 112, /* ñ - 241 */
1093 14 , 124, /* ò - 242 */
1094 14 , 124, /* ó - 243 */
1095 14 , 124, /* ô - 244 */
1096 14 , 124, /* õ - 245 */
1097 14 , 124, /* ö - 246 */
1098 8 , 29, /* ÷ - 247 */
1099 14 , 124, /* ø - 248 */
1100 14 , 159, /* ù - 249 */
1101 14 , 159, /* ú - 250 */
1102 14 , 159, /* û - 251 */
1103 14 , 159, /* ü - 252 */
1104 14 , 167, /* ý - 253 */
1105 14 + 32 , 153, /* þ - 254 */
1106 14 , 167 /* ÿ - 255 */ };
1108 static const unsigned char LCM_Unicode_LUT_2
[] = { 33, 44, 145 };
1110 #define LCM_Diacritic_Start 131
1112 static const unsigned char LCM_Diacritic_LUT
[] = {
1240 /******************************************************************************
1241 * OLE2NLS_isPunctuation [INTERNAL]
1243 static int OLE2NLS_isPunctuation(unsigned char c
)
1245 /* "punctuation character" in this context is a character which is
1246 considered "less important" during word sort comparison.
1247 See LCMapString implementation for the precise definition
1248 of "less important". */
1250 return (LCM_Unicode_LUT
[-2+2*c
]==6);
1253 /******************************************************************************
1254 * OLE2NLS_isNonSpacing [INTERNAL]
1256 static int OLE2NLS_isNonSpacing(unsigned char c
)
1258 /* This function is used by LCMapStringA. Characters
1259 for which it returns true are ignored when mapping a
1260 string with NORM_IGNORENONSPACE */
1261 return ((c
==136) || (c
==170) || (c
==186));
1264 /******************************************************************************
1265 * OLE2NLS_isSymbol [INTERNAL]
1266 * FIXME: handle current locale
1268 static int OLE2NLS_isSymbol(unsigned char c
)
1270 /* This function is used by LCMapStringA. Characters
1271 for which it returns true are ignored when mapping a
1272 string with NORM_IGNORESYMBOLS */
1273 return ( (c
!=0) && !(isalpha(c
) || isdigit(c
)) );
1276 /******************************************************************************
1277 * identity [Internal]
1279 static int identity(int c
)
1284 /*************************************************************************
1285 * LCMapStringA [KERNEL32.@]
1287 * Convert a string, or generate a sort key from it.
1289 * If (mapflags & LCMAP_SORTKEY), the function will generate
1290 * a sort key for the source string. Else, it will convert it
1291 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1295 * Success : length of the result string.
1298 * If called with scrlen = -1, the function will compute the length
1299 * of the 0-terminated string strsrc by itself.
1301 * If called with dstlen = 0, returns the buffer length that
1302 * would be required.
1304 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1305 * as if they are equal.
1306 * In the only code page implemented so far, there may not be
1307 * wide characters in strings passed to LCMapStringA,
1308 * so there is nothing to be done for this flag.
1310 INT WINAPI
LCMapStringA(
1311 LCID lcid
, /* [in] locale identifier created with MAKELCID;
1312 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1313 predefined values. */
1314 DWORD mapflags
, /* [in] flags */
1315 LPCSTR srcstr
, /* [in] source buffer */
1316 INT srclen
, /* [in] source length */
1317 LPSTR dststr
, /* [out] destination buffer */
1318 INT dstlen
) /* [in] destination buffer length */
1322 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1323 lcid
,mapflags
,debugstr_an(srcstr
,srclen
),srclen
,dststr
,dstlen
);
1325 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1327 ERR("(src=%s,dest=%s): Invalid NULL string\n",
1328 debugstr_an(srcstr
,srclen
), dststr
);
1329 SetLastError(ERROR_INVALID_PARAMETER
);
1333 srclen
= strlen(srcstr
) + 1 ; /* (include final '\0') */
1335 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1339 NORM_IGNORENONSPACE | \
1341 NORM_IGNOREWIDTH | \
1342 NORM_IGNOREKANATYPE)
1343 /* FIXME: as long as we don't support Katakana nor Hiragana
1344 * characters, we can support NORM_IGNOREKANATYPE
1346 if (mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
)
1348 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1349 "unimplemented flags: 0x%08lx\n",
1356 mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
1360 if ( !(mapflags
& LCMAP_SORTKEY
) )
1363 int (*f
)(int) = identity
;
1364 int flag_ignorenonspace
= mapflags
& NORM_IGNORENONSPACE
;
1365 int flag_ignoresymbols
= mapflags
& NORM_IGNORESYMBOLS
;
1367 if (flag_ignorenonspace
|| flag_ignoresymbols
)
1369 /* For some values of mapflags, the length of the resulting
1370 string is not known at this point. Windows does map the string
1371 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1375 /* Compute required length */
1376 for (i
=j
=0; i
< srclen
; i
++)
1378 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1379 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1391 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1395 if (mapflags
& LCMAP_UPPERCASE
)
1397 else if (mapflags
& LCMAP_LOWERCASE
)
1399 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1400 for (i
=j
=0; (i
<srclen
) && (j
<dstlen
) ; i
++)
1402 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1403 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1405 dststr
[j
] = (CHAR
) f(srcstr
[i
]);
1412 /* FIXME: This function completely ignores the "lcid" parameter. */
1413 /* else ... (mapflags & LCMAP_SORTKEY) */
1417 int diacritic_len
=0;
1418 int delayed_punctuation_len
=0;
1419 char *case_component
;
1420 char *diacritic_component
;
1421 char *delayed_punctuation_component
;
1423 int flag_stringsort
= mapflags
& SORT_STRINGSORT
;
1425 /* compute how much room we will need */
1426 for (i
=0;i
<srclen
;i
++)
1429 unsigned char source_char
= srcstr
[i
];
1430 if (source_char
!='\0')
1432 if (flag_stringsort
|| !OLE2NLS_isPunctuation(source_char
))
1435 if ( LCM_Unicode_LUT
[-2+2*source_char
] & ~15 )
1436 unicode_len
++; /* double letter */
1440 delayed_punctuation_len
++;
1444 if (isupper(source_char
))
1445 case_len
=unicode_len
;
1447 ofs
= source_char
- LCM_Diacritic_Start
;
1448 if ((ofs
>=0) && (LCM_Diacritic_LUT
[ofs
]!=2))
1449 diacritic_len
=unicode_len
;
1452 if (mapflags
& NORM_IGNORECASE
)
1454 if (mapflags
& NORM_IGNORENONSPACE
)
1457 room
= 2 * unicode_len
/* "unicode" component */
1458 + diacritic_len
/* "diacritic" component */
1459 + case_len
/* "case" component */
1460 + 4 * delayed_punctuation_len
/* punctuation in word sort mode */
1461 + 4 /* four '\1' separators */
1462 + 1 ; /* terminal '\0' */
1465 else if (dstlen
<room
)
1467 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1471 /*FIXME the Pointercheck should not be nessesary */
1472 if (IsBadWritePtr (dststr
,room
))
1473 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr
,dstlen
);
1474 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1478 /* locate each component, write separators */
1479 diacritic_component
= dststr
+ 2*unicode_len
;
1480 *diacritic_component
++ = '\1';
1481 case_component
= diacritic_component
+ diacritic_len
;
1482 *case_component
++ = '\1';
1483 delayed_punctuation_component
= case_component
+ case_len
;
1484 *delayed_punctuation_component
++ = '\1';
1485 *delayed_punctuation_component
++ = '\1';
1487 /* read source string char by char, write
1488 corresponding weight in each component. */
1489 for (i
=0,count
=0;i
<srclen
;i
++)
1491 unsigned char source_char
=srcstr
[i
];
1492 if (source_char
!='\0')
1495 type
= LCM_Unicode_LUT
[-2+2*source_char
];
1496 longcode
= type
>> 4;
1498 if (!flag_stringsort
&& OLE2NLS_isPunctuation(source_char
))
1500 WORD encrypted_location
= (1<<15) + 7 + 4*count
;
1501 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
>>8);
1502 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
&255);
1503 /* big-endian is used here because it lets string comparison be
1504 compatible with numerical comparison */
1506 *delayed_punctuation_component
++ = type
;
1507 *delayed_punctuation_component
++ = LCM_Unicode_LUT
[-1+2*source_char
];
1508 /* assumption : a punctuation character is never a
1509 double or accented letter */
1513 dststr
[2*count
] = type
;
1514 dststr
[2*count
+1] = LCM_Unicode_LUT
[-1+2*source_char
];
1518 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1519 if (count
<diacritic_len
)
1520 diacritic_component
[count
] = 2; /* assumption: a double letter
1521 is never accented */
1524 dststr
[2*count
] = type
;
1525 dststr
[2*count
+1] = *(LCM_Unicode_LUT_2
- 1 + longcode
);
1526 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1527 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1528 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1532 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1533 if (count
<diacritic_len
)
1535 int ofs
= source_char
- LCM_Diacritic_Start
;
1536 diacritic_component
[count
] = (ofs
>=0 ? LCM_Diacritic_LUT
[ofs
] : 2);
1542 dststr
[room
-1] = '\0';
1547 /*************************************************************************
1548 * LCMapStringW [KERNEL32.@]
1550 * Convert a string, or generate a sort key from it.
1554 * See LCMapStringA for documentation
1556 INT WINAPI
LCMapStringW(
1557 LCID lcid
,DWORD mapflags
,LPCWSTR srcstr
,INT srclen
,LPWSTR dststr
,
1562 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
1563 lcid
, mapflags
, srcstr
, srclen
, dststr
, dstlen
);
1565 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1567 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr
, dststr
);
1568 SetLastError(ERROR_INVALID_PARAMETER
);
1572 srclen
= strlenW(srcstr
)+1;
1574 /* FIXME: Both this function and it's companion LCMapStringA()
1575 * completely ignore the "lcid" parameter. In place of the "lcid"
1576 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
1577 * environment variable prior to invoking this function. */
1578 if (mapflags
& LCMAP_SORTKEY
)
1580 /* Possible values of LC_COLLATE. */
1581 char *lc_collate_default
= 0; /* value prior to this function */
1582 char *lc_collate_env
= 0; /* value retrieved from the environment */
1584 /* General purpose index into strings of any type. */
1587 /* Lengths of various strings where the length is measured in
1588 * wide characters for wide character strings and in bytes for
1589 * native strings. The lengths include the NULL terminator. */
1590 size_t returned_len
= 0;
1591 size_t src_native_len
= 0;
1592 size_t dst_native_len
= 0;
1593 size_t dststr_libc_len
= 0;
1595 /* Native (character set determined by locale) versions of the
1596 * strings source and destination strings. */
1597 LPSTR src_native
= 0;
1598 LPSTR dst_native
= 0;
1600 /* Version of the source and destination strings using the
1601 * "wchar_t" Unicode data type needed by various libc functions. */
1602 wchar_t *srcstr_libc
= 0;
1603 wchar_t *dststr_libc
= 0;
1605 if(!(srcstr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
1606 srclen
* sizeof(wchar_t))))
1608 ERR("Unable to allocate %d bytes for srcstr_libc\n",
1609 srclen
* sizeof(wchar_t));
1610 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1614 /* Convert source string to a libc Unicode string. */
1615 for(str_idx
= 0; str_idx
< srclen
; str_idx
++)
1617 srcstr_libc
[str_idx
] = srcstr
[str_idx
];
1620 /* src_native should contain at most 3 bytes for each
1621 * multibyte characters in the original srcstr string. */
1622 src_native_len
= 3 * srclen
;
1623 if(!(src_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
1626 ERR("Unable to allocate %d bytes for src_native\n", src_native_len
);
1627 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1628 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1632 /* FIXME: Prior to to setting the LC_COLLATE locale category the
1633 * current value is backed up so it can be restored after the
1634 * last LC_COLLATE sensitive function returns.
1636 * Even though the locale is adjusted for a minimum amount of
1637 * time a race condition exists where other threads may be
1638 * affected if they invoke LC_COLLATE sensitive functions. One
1639 * possible solution is to wrap all LC_COLLATE sensitive Wine
1640 * functions, like LCMapStringW(), in a mutex.
1642 * Another enhancement to the following would be to set the
1643 * LC_COLLATE locale category as a function of the "lcid"
1644 * parameter instead of the "LC_COLLATE" environment variable. */
1645 if(!(lc_collate_default
= setlocale(LC_COLLATE
, NULL
)))
1647 ERR("Unable to query the LC_COLLATE catagory\n");
1648 SetLastError(ERROR_INVALID_PARAMETER
);
1649 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1650 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1654 if(!(lc_collate_env
= setlocale(LC_COLLATE
, "")))
1656 ERR("Unable to inherit the LC_COLLATE locale category from the "
1657 "environment. The \"LC_COLLATE\" environment variable is "
1658 "\"%s\".\n", getenv("LC_COLLATE") ?
1659 getenv("LC_COLLATE") : "<unset>");
1660 SetLastError(ERROR_INVALID_PARAMETER
);
1661 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1662 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1666 TRACE("lc_collate_default = %s\n", lc_collate_default
);
1667 TRACE("lc_collate_env = %s\n", lc_collate_env
);
1669 /* Convert the libc Unicode string to a native multibyte character
1671 returned_len
= wcstombs(src_native
, srcstr_libc
, src_native_len
) + 1;
1672 if(returned_len
== 0)
1674 ERR("wcstombs failed. The string specified (%s) may contain an invalid character.\n",
1675 debugstr_w(srcstr
));
1676 SetLastError(ERROR_INVALID_PARAMETER
);
1677 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1678 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1679 setlocale(LC_COLLATE
, lc_collate_default
);
1682 else if(returned_len
> src_native_len
)
1684 src_native
[src_native_len
- 1] = 0;
1685 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
1686 "than expected (%d bytes).\n", src_native
, returned_len
,
1689 /* Since this is an internal error I'm not sure what the correct
1691 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1693 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1694 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1695 setlocale(LC_COLLATE
, lc_collate_default
);
1698 src_native_len
= returned_len
;
1700 TRACE("src_native = %s src_native_len = %d\n",
1701 src_native
, src_native_len
);
1703 /* dst_native seems to contain at most 4 bytes for each byte in
1704 * the original src_native string. Change if need be since this
1705 * isn't documented by the strxfrm() man page. */
1706 dst_native_len
= 4 * src_native_len
;
1707 if(!(dst_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, dst_native_len
)))
1709 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len
);
1710 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1711 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1712 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1713 setlocale(LC_COLLATE
, lc_collate_default
);
1717 /* The actual translation is done by the following call to
1718 * strxfrm(). The surrounding code could have been simplified
1719 * by calling wcsxfrm() instead except that wcsxfrm() is not
1720 * available on older Linux systems (RedHat 4.1 with
1723 * Also, it is possible that the translation could be done by
1724 * various tables as it is done in LCMapStringA(). However, I'm
1725 * not sure what those tables are. */
1726 returned_len
= strxfrm(dst_native
, src_native
, dst_native_len
) + 1;
1728 if(returned_len
> dst_native_len
)
1730 dst_native
[dst_native_len
- 1] = 0;
1731 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
1732 "than expected (%d bytes).\n", dst_native
, returned_len
,
1735 /* Since this is an internal error I'm not sure what the correct
1737 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1739 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1740 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1741 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1742 setlocale(LC_COLLATE
, lc_collate_default
);
1745 dst_native_len
= returned_len
;
1747 TRACE("dst_native = %s dst_native_len = %d\n",
1748 dst_native
, dst_native_len
);
1750 dststr_libc_len
= dst_native_len
;
1751 if(!(dststr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
1752 dststr_libc_len
* sizeof(wchar_t))))
1754 ERR("Unable to allocate %d bytes for dststr_libc\n",
1755 dststr_libc_len
* sizeof(wchar_t));
1756 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1757 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1758 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1759 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1760 setlocale(LC_COLLATE
, lc_collate_default
);
1764 /* Convert the native multibyte string to a libc Unicode string. */
1765 returned_len
= mbstowcs(dststr_libc
, dst_native
, dst_native_len
) + 1;
1767 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
1768 * function has returned. */
1769 setlocale(LC_COLLATE
, lc_collate_default
);
1771 if(returned_len
== 0)
1773 ERR("mbstowcs failed. The native version of the translated string "
1774 "(%s) may contain an invalid character.\n", dst_native
);
1775 SetLastError(ERROR_INVALID_PARAMETER
);
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
);
1784 if(returned_len
> dstlen
)
1786 ERR("mbstowcs returned a string that was longer (%d chars) "
1787 "than the buffer provided (%d chars).\n", returned_len
,
1789 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1790 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1791 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1792 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1793 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
1796 dstlen
= returned_len
;
1798 /* Convert a libc Unicode string to the destination string. */
1799 for(str_idx
= 0; str_idx
< dstlen
; str_idx
++)
1801 dststr
[str_idx
] = dststr_libc
[str_idx
];
1803 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
1804 *(((int *)dststr
) + 0),
1805 *(((int *)dststr
) + 1),
1806 *(((int *)dststr
) + 2),
1807 *(((int *)dststr
) + 3));
1811 dstlen
= returned_len
;
1813 TRACE("dstlen (return) = %d\n", dstlen
);
1814 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1815 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1816 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1817 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
1822 int (*f
)(int)=identity
;
1828 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1832 if (mapflags
& LCMAP_UPPERCASE
)
1834 else if (mapflags
& LCMAP_LOWERCASE
)
1836 for (i
=0; i
< srclen
; i
++)
1837 dststr
[i
] = (WCHAR
) f(srcstr
[i
]);
1843 /***********************************************************************
1844 * OLE2NLS_EstimateMappingLength
1846 * Estimates the number of characters required to hold the string
1847 * computed by LCMapStringA.
1849 * The size is always over-estimated, with a fixed limit on the
1850 * amount of estimation error.
1852 * Note that len == -1 is not permitted.
1854 static inline int OLE2NLS_EstimateMappingLength(LCID lcid
, DWORD dwMapFlags
,
1855 LPCSTR str
, DWORD len
)
1857 /* Estimate only for small strings to keep the estimation error from
1858 * becoming too large. */
1859 if (len
< 128) return len
* 8 + 5;
1860 else return LCMapStringA(lcid
, dwMapFlags
, str
, len
, NULL
, 0);
1863 /******************************************************************************
1864 * CompareStringA [KERNEL32.@]
1865 * Compares two strings using locale
1869 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
1874 * Defaults to a word sort, but uses a string sort if
1875 * SORT_STRINGSORT is set.
1876 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
1880 * This implementation ignores the locale
1884 * Quite inefficient.
1886 int WINAPI
CompareStringA(
1887 LCID lcid
, /* [in] locale ID */
1888 DWORD fdwStyle
, /* [in] comparison-style options */
1889 LPCSTR s1
, /* [in] first string */
1890 int l1
, /* [in] length of first string */
1891 LPCSTR s2
, /* [in] second string */
1892 int l2
) /* [in] length of second string */
1894 int mapstring_flags
;
1898 TRACE("%s and %s\n",
1899 debugstr_an (s1
,l1
), debugstr_an (s2
,l2
));
1901 if ( (s1
==NULL
) || (s2
==NULL
) )
1903 ERR("(s1=%s,s2=%s): Invalid NULL string\n",
1904 debugstr_an(s1
,l1
), debugstr_an(s2
,l2
));
1905 SetLastError(ERROR_INVALID_PARAMETER
);
1909 if(fdwStyle
& NORM_IGNORESYMBOLS
)
1910 FIXME("IGNORESYMBOLS not supported\n");
1912 if (l1
== -1) l1
= strlen(s1
);
1913 if (l2
== -1) l2
= strlen(s2
);
1915 mapstring_flags
= LCMAP_SORTKEY
| fdwStyle
;
1916 len1
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s1
, l1
);
1917 len2
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s2
, l2
);
1919 if ((len1
==0)||(len2
==0))
1920 return 0; /* something wrong happened */
1922 sk1
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, len1
+ len2
);
1924 if ( (!LCMapStringA(lcid
,mapstring_flags
,s1
,l1
,sk1
,len1
))
1925 || (!LCMapStringA(lcid
,mapstring_flags
,s2
,l2
,sk2
,len2
)) )
1927 ERR("Bug in LCmapStringA.\n");
1932 /* strcmp doesn't necessarily return -1, 0, or 1 */
1933 result
= strcmp(sk1
,sk2
);
1935 HeapFree(GetProcessHeap(),0,sk1
);
1942 /* must be greater, if we reach this point */
1946 /******************************************************************************
1947 * CompareStringW [KERNEL32.@]
1948 * This implementation ignores the locale
1949 * FIXME : Does only string sort. Should
1950 * be reimplemented the same way as CompareStringA.
1952 int WINAPI
CompareStringW(LCID lcid
, DWORD fdwStyle
,
1953 LPCWSTR s1
, int l1
, LPCWSTR s2
, int l2
)
1956 if(fdwStyle
& NORM_IGNORENONSPACE
)
1957 FIXME("IGNORENONSPACE not supported\n");
1958 if(fdwStyle
& NORM_IGNORESYMBOLS
)
1959 FIXME("IGNORESYMBOLS not supported\n");
1961 /* Is strcmp defaulting to string sort or to word sort?? */
1962 /* FIXME: Handle NORM_STRINGSORT */
1963 l1
= (l1
==-1)?strlenW(s1
):l1
;
1964 l2
= (l2
==-1)?strlenW(s2
):l2
;
1965 len
= l1
<l2
? l1
:l2
;
1966 ret
= (fdwStyle
& NORM_IGNORECASE
) ? strncmpiW(s1
,s2
,len
) : strncmpW(s1
,s2
,len
);
1967 /* not equal, return 1 or 3 */
1969 /* need to translate result */
1970 return ((int)ret
< 0) ? 1 : 3;
1972 /* same len, return 2 */
1973 if(l1
==l2
) return 2;
1974 /* the longer one is lexically greater */
1975 return (l1
<l2
)? 1 : 3;
1978 /******************************************************************************
1979 * OLE_GetFormatA [Internal]
1982 * If datelen == 0, it should return the reguired string length.
1984 This function implements stuff for GetDateFormat() and
1987 d single-digit (no leading zero) day (of month)
1988 dd two-digit day (of month)
1989 ddd short day-of-week name
1990 dddd long day-of-week name
1991 M single-digit month
1993 MMM short month name
1994 MMMM full month name
1995 y two-digit year, no leading 0
1997 yyyy four-digit year
1999 h hours with no leading zero (12-hour)
2000 hh hours with full two digits
2001 H hours with no leading zero (24-hour)
2002 HH hours with full two digits
2003 m minutes with no leading zero
2004 mm minutes with full two digits
2005 s seconds with no leading zero
2006 ss seconds with full two digits
2007 t time marker (A or P)
2008 tt time marker (AM, PM)
2009 '' used to quote literal characters
2010 '' (within a quoted string) indicates a literal '
2012 These functions REQUIRE valid locale, date, and format.
2014 static INT
OLE_GetFormatA(LCID locale
,
2017 const SYSTEMTIME
* xtime
,
2018 LPCSTR _format
, /*in*/
2023 int count
, type
, inquote
, Overflow
;
2029 const char * _dgfmt
[] = { "%d", "%02d" };
2030 const char ** dgfmt
= _dgfmt
- 1;
2032 /* report, for debugging */
2033 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",
2034 locale
, flags
, tflags
,
2035 xtime
->wYear
,xtime
->wMonth
,xtime
->wDayOfWeek
,xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2036 _format
, _format
, date
, datelen
);
2039 FIXME("datelen = 0, returning 255\n");
2043 /* initalize state variables and output buffer */
2045 count
= 0; inquote
= 0; Overflow
= 0;
2047 date
[0] = buf
[0] = '\0';
2049 strcpy(format
,_format
);
2051 /* alter the formatstring, while it works for all languages now in wine
2052 its possible that it fails when the time looks like ss:mm:hh as example*/
2053 if (tflags
& (TIME_NOMINUTESORSECONDS
))
2054 { if ((pos
= strstr ( format
, ":mm")))
2055 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2058 if (tflags
& (TIME_NOSECONDS
))
2059 { if ((pos
= strstr ( format
, ":ss")))
2060 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2064 for (inpos
= 0;; inpos
++) {
2065 /* 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]); */
2067 if (format
[inpos
] == '\'') {
2068 if (format
[inpos
+1] == '\'') {
2070 date
[outpos
++] = '\'';
2073 continue; /* we did nothing to the output */
2075 } else if (format
[inpos
] == '\0') {
2076 date
[outpos
++] = '\0';
2077 if (outpos
> datelen
) Overflow
= 1;
2080 date
[outpos
++] = format
[inpos
];
2081 if (outpos
> datelen
) {
2083 date
[outpos
-1] = '\0'; /* this is the last place where
2084 it's safe to write */
2088 } else if ( (count
&& (format
[inpos
] != type
))
2090 || (count
== 2 && strchr("ghHmst", type
)) ) {
2091 if (type
== 'h' && (tflags
& TIME_FORCE24HOURFORMAT
)) type
= 'H';
2094 GetLocaleInfoA(locale
,
2096 + (xtime
->wDayOfWeek
+6)%7,
2098 } else if (count
== 3) {
2099 GetLocaleInfoA(locale
,
2100 LOCALE_SABBREVDAYNAME1
2101 + (xtime
->wDayOfWeek
+6)%7,
2104 sprintf(buf
, dgfmt
[count
], xtime
->wDay
);
2106 } else if (type
== 'M') {
2108 GetLocaleInfoA(locale
,
2109 LOCALE_SABBREVMONTHNAME1
2110 + xtime
->wMonth
- 1,
2112 } else if (count
== 4) {
2113 GetLocaleInfoA(locale
,
2115 + xtime
->wMonth
- 1,
2118 sprintf(buf
, dgfmt
[count
], xtime
->wMonth
);
2120 } else if (type
== 'y') {
2122 sprintf(buf
, "%d", xtime
->wYear
);
2123 } else if (count
== 3) {
2125 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2127 sprintf(buf
, dgfmt
[count
], xtime
->wYear
% 100);
2129 } else if (type
== 'g') {
2131 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2135 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2137 } else if (type
== 'h') {
2138 /* gives us hours 1:00 -- 12:00 */
2139 sprintf(buf
, dgfmt
[count
], (xtime
->wHour
-1)%12 +1);
2140 } else if (type
== 'H') {
2142 sprintf(buf
, dgfmt
[count
], xtime
->wHour
);
2143 } else if ( type
== 'm') {
2144 sprintf(buf
, dgfmt
[count
], xtime
->wMinute
);
2145 } else if ( type
== 's') {
2146 sprintf(buf
, dgfmt
[count
], xtime
->wSecond
);
2147 } else if (type
== 't') {
2148 if ((tflags
& TIME_NOTIMEMARKER
))
2150 else if (count
== 1) {
2151 sprintf(buf
, "%c", (xtime
->wHour
< 12) ? 'A' : 'P');
2152 } else if (count
== 2) {
2153 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2154 GetLocaleInfoA(locale
,
2156 ? LOCALE_S1159
: LOCALE_S2359
,
2161 /* we need to check the next char in the format string
2162 again, no matter what happened */
2165 /* add the contents of buf to the output */
2166 buflen
= strlen(buf
);
2167 if (outpos
+ buflen
< datelen
) {
2168 date
[outpos
] = '\0'; /* for strcat to hook onto */
2172 date
[outpos
] = '\0';
2173 strncat(date
, buf
, datelen
- outpos
);
2174 date
[datelen
- 1] = '\0';
2175 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2176 WARN("insufficient buffer\n");
2180 /* reset the variables we used to keep track of this item */
2183 } else if (format
[inpos
] == '\0') {
2184 /* we can't check for this at the loop-head, because
2185 that breaks the printing of the last format-item */
2186 date
[outpos
] = '\0';
2189 /* continuing a code for an item */
2192 } else if (strchr("hHmstyMdg", format
[inpos
])) {
2193 type
= format
[inpos
];
2196 } else if (format
[inpos
] == '\'') {
2200 date
[outpos
++] = format
[inpos
];
2202 /* now deal with a possible buffer overflow */
2203 if (outpos
>= datelen
) {
2204 date
[datelen
- 1] = '\0';
2205 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2211 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2214 /* finish it off with a string terminator */
2217 if (outpos
> datelen
-1) outpos
= datelen
-1;
2218 date
[outpos
] = '\0';
2220 TRACE("returns string '%s', len %d\n", date
, outpos
);
2224 /******************************************************************************
2225 * OLE_GetFormatW [INTERNAL]
2227 static INT
OLE_GetFormatW(LCID locale
, DWORD flags
, DWORD tflags
,
2228 const SYSTEMTIME
* xtime
,
2230 LPWSTR output
, INT outlen
)
2233 int count
, type
=0, inquote
;
2234 int Overflow
; /* loop check */
2238 WCHAR arg0
[] = {0}, arg1
[] = {'%','d',0};
2239 WCHAR arg2
[] = {'%','0','2','d',0};
2241 int datevars
=0, timevars
=0;
2247 /* make a debug report */
2248 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2249 "%p with max len %d\n",
2250 locale
, flags
, tflags
,
2251 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2252 debugstr_w(format
), format
, output
, outlen
);
2255 FIXME("outlen = 0, returning 255\n");
2259 /* initialize state variables */
2262 inquote
= Overflow
= 0;
2263 /* this is really just a sanity check */
2264 output
[0] = buf
[0] = 0;
2266 /* this loop is the core of the function */
2267 for (inpos
= 0; /* we have several break points */ ; inpos
++) {
2269 if (format
[inpos
] == (WCHAR
) '\'') {
2270 if (format
[inpos
+1] == '\'') {
2272 output
[outpos
++] = '\'';
2277 } else if (format
[inpos
] == 0) {
2278 output
[outpos
++] = 0;
2279 if (outpos
> outlen
) Overflow
= 1;
2280 break; /* normal exit (within a quote) */
2282 output
[outpos
++] = format
[inpos
]; /* copy input */
2283 if (outpos
> outlen
) {
2285 output
[outpos
-1] = 0;
2289 } else if ( (count
&& (format
[inpos
] != type
))
2290 || ( (count
==4 && type
=='y') ||
2291 (count
==4 && type
=='M') ||
2292 (count
==4 && type
=='d') ||
2293 (count
==2 && type
=='g') ||
2294 (count
==2 && type
=='h') ||
2295 (count
==2 && type
=='H') ||
2296 (count
==2 && type
=='m') ||
2297 (count
==2 && type
=='s') ||
2298 (count
==2 && type
=='t') ) ) {
2303 GetLocaleInfoW(locale
,
2304 LOCALE_SDAYNAME1
+ (xtime
->wDayOfWeek
+6)%7,
2305 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2306 } else if (count
== 3) {
2307 GetLocaleInfoW(locale
,
2308 LOCALE_SABBREVDAYNAME1
+
2309 (xtime
->wDayOfWeek
+6)%7,
2310 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2312 sprintf( tmp
, "%.*d", count
, xtime
->wDay
);
2313 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2319 GetLocaleInfoW(locale
, LOCALE_SMONTHNAME1
+
2320 xtime
->wMonth
-1, buf
,
2321 sizeof(buf
)/sizeof(WCHAR
) );
2322 } else if (count
== 3) {
2323 GetLocaleInfoW(locale
, LOCALE_SABBREVMONTHNAME1
+
2324 xtime
->wMonth
-1, buf
,
2325 sizeof(buf
)/sizeof(WCHAR
) );
2327 sprintf( tmp
, "%.*d", count
, xtime
->wMonth
);
2328 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2333 sprintf( tmp
, "%d", xtime
->wYear
);
2334 } else if (count
== 3) {
2335 strcpy( tmp
, "yyy" );
2337 sprintf( tmp
, "%.*d", count
, xtime
->wYear
% 100 );
2339 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2344 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2345 strcpy( tmp
, "AD" );
2347 /* Win API sez we copy it verbatim */
2350 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2354 /* hours 1:00-12:00 --- is this right? */
2355 sprintf( tmp
, "%.*d", count
, (xtime
->wHour
-1)%12 +1);
2356 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2360 sprintf( tmp
, "%.*d", count
, xtime
->wHour
);
2361 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2365 sprintf( tmp
, "%.*d", count
, xtime
->wMinute
);
2366 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2370 sprintf( tmp
, "%.*d", count
, xtime
->wSecond
);
2371 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2375 GetLocaleInfoW(locale
, (xtime
->wHour
< 12) ?
2376 LOCALE_S1159
: LOCALE_S2359
,
2384 /* no matter what happened, we need to check this next
2385 character the next time we loop through */
2388 /* cat buf onto the output */
2389 outlen
= strlenW(buf
);
2390 if (outpos
+ buflen
< outlen
) {
2391 strcpyW( output
+ outpos
, buf
);
2394 lstrcpynW( output
+ outpos
, buf
, outlen
- outpos
);
2396 break; /* Abnormal exit */
2399 /* reset the variables we used this time */
2402 } else if (format
[inpos
] == 0) {
2403 /* we can't check for this at the beginning, because that
2404 would keep us from printing a format spec that ended the
2407 break; /* NORMAL EXIT */
2409 /* how we keep track of the middle of a format spec */
2412 } else if ( (datevars
&& (format
[inpos
]=='d' ||
2413 format
[inpos
]=='M' ||
2414 format
[inpos
]=='y' ||
2415 format
[inpos
]=='g') ) ||
2416 (timevars
&& (format
[inpos
]=='H' ||
2417 format
[inpos
]=='h' ||
2418 format
[inpos
]=='m' ||
2419 format
[inpos
]=='s' ||
2420 format
[inpos
]=='t') ) ) {
2421 type
= format
[inpos
];
2424 } else if (format
[inpos
] == '\'') {
2428 /* unquoted literals */
2429 output
[outpos
++] = format
[inpos
];
2434 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2435 WARN(" buffer overflow\n");
2438 /* final string terminator and sanity check */
2440 if (outpos
> outlen
-1) outpos
= outlen
-1;
2441 output
[outpos
] = '0';
2443 TRACE(" returning %s\n", debugstr_w(output
));
2445 return (!Overflow
) ? outlen
: 0;
2450 /******************************************************************************
2451 * GetDateFormatA [KERNEL32.@]
2452 * Makes an ASCII string of the date
2454 * This function uses format to format the date, or, if format
2455 * is NULL, uses the default for the locale. format is a string
2456 * of literal fields and characters as follows:
2458 * - d single-digit (no leading zero) day (of month)
2459 * - dd two-digit day (of month)
2460 * - ddd short day-of-week name
2461 * - dddd long day-of-week name
2462 * - M single-digit month
2463 * - MM two-digit month
2464 * - MMM short month name
2465 * - MMMM full month name
2466 * - y two-digit year, no leading 0
2467 * - yy two-digit year
2468 * - yyyy four-digit year
2472 INT WINAPI
GetDateFormatA(LCID locale
,DWORD flags
,
2473 const SYSTEMTIME
* xtime
,
2474 LPCSTR format
, LPSTR date
,INT datelen
)
2477 char format_buf
[40];
2480 LPSYSTEMTIME thistime
;
2486 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2487 locale
,flags
,xtime
,format
,date
,datelen
);
2490 locale
= LOCALE_SYSTEM_DEFAULT
;
2493 if (locale
== LOCALE_SYSTEM_DEFAULT
) {
2494 thislocale
= GetSystemDefaultLCID();
2495 } else if (locale
== LOCALE_USER_DEFAULT
) {
2496 thislocale
= GetUserDefaultLCID();
2498 thislocale
= locale
;
2501 if (xtime
== NULL
) {
2504 /* Silently correct wDayOfWeek by transforming to FileTime and back again */
2505 res
=SystemTimeToFileTime(xtime
,&ft
);
2506 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error */
2507 /*FIXME: SystemTimeToFileTime doesn't yet do that check */
2510 SetLastError(ERROR_INVALID_PARAMETER
);
2513 FileTimeToSystemTime(&ft
,&t
);
2518 if (format
== NULL
) {
2519 GetLocaleInfoA(thislocale
, ((flags
&DATE_LONGDATE
)
2521 : LOCALE_SSHORTDATE
),
2522 format_buf
, sizeof(format_buf
));
2523 thisformat
= format_buf
;
2525 thisformat
= format
;
2529 ret
= OLE_GetFormatA(thislocale
, flags
, 0, thistime
, thisformat
,
2534 "GetDateFormatA() returning %d, with data=%s\n",
2539 /******************************************************************************
2540 * GetDateFormatW [KERNEL32.@]
2541 * Makes a Unicode string of the date
2543 * Acts the same as GetDateFormatA(), except that it's Unicode.
2544 * Accepts & returns sizes as counts of Unicode characters.
2547 INT WINAPI
GetDateFormatW(LCID locale
,DWORD flags
,
2548 const SYSTEMTIME
* xtime
,
2550 LPWSTR date
, INT datelen
)
2552 unsigned short datearr
[] = {'1','9','9','4','-','1','-','1',0};
2554 FIXME("STUB (should call OLE_GetFormatW)\n");
2555 lstrcpynW(date
, datearr
, datelen
);
2556 return ( datelen
< 9) ? datelen
: 9;
2561 /**************************************************************************
2562 * EnumDateFormatsA (KERNEL32.@)
2564 BOOL WINAPI
EnumDateFormatsA(
2565 DATEFMT_ENUMPROCA lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2567 LCID Loc
= GetUserDefaultLCID();
2568 if(!lpDateFmtEnumProc
)
2570 SetLastError(ERROR_INVALID_PARAMETER
);
2577 case 0x00000407: /* (Loc,"de_DE") */
2581 case DATE_SHORTDATE
:
2582 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
2583 if(!(*lpDateFmtEnumProc
)("d.M.yyyy")) return TRUE
;
2584 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
2585 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2588 if(!(*lpDateFmtEnumProc
)("dddd,d. MMMM yyyy")) return TRUE
;
2589 if(!(*lpDateFmtEnumProc
)("d. MMMM yyyy")) return TRUE
;
2590 if(!(*lpDateFmtEnumProc
)("d. MMM yyyy")) return TRUE
;
2593 FIXME("Unknown date format (%ld)\n", dwFlags
);
2594 SetLastError(ERROR_INVALID_PARAMETER
);
2599 case 0x0000040c: /* (Loc,"fr_FR") */
2603 case DATE_SHORTDATE
:
2604 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2605 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
2606 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
2607 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2610 if(!(*lpDateFmtEnumProc
)("dddd d MMMM yyyy")) return TRUE
;
2611 if(!(*lpDateFmtEnumProc
)("d MMM yy")) return TRUE
;
2612 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2615 FIXME("Unknown date format (%ld)\n", dwFlags
);
2616 SetLastError(ERROR_INVALID_PARAMETER
);
2621 case 0x00000c0c: /* (Loc,"fr_CA") */
2625 case DATE_SHORTDATE
:
2626 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
2627 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
2628 if(!(*lpDateFmtEnumProc
)("yy MM dd")) return TRUE
;
2629 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2632 if(!(*lpDateFmtEnumProc
)("d MMMM, yyyy")) return TRUE
;
2633 if(!(*lpDateFmtEnumProc
)("d MMM yyyy")) return TRUE
;
2636 FIXME("Unknown date format (%ld)\n", dwFlags
);
2637 SetLastError(ERROR_INVALID_PARAMETER
);
2642 case 0x00000809: /* (Loc,"en_UK") */
2646 case DATE_SHORTDATE
:
2647 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2648 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2649 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2650 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2653 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
2654 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2657 FIXME("Unknown date format (%ld)\n", dwFlags
);
2658 SetLastError(ERROR_INVALID_PARAMETER
);
2663 case 0x00000c09: /* (Loc,"en_AU") */
2667 case DATE_SHORTDATE
:
2668 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
2669 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2670 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2673 if(!(*lpDateFmtEnumProc
)("dddd,d MMMM yyyy")) return TRUE
;
2674 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2677 FIXME("Unknown date format (%ld)\n", dwFlags
);
2678 SetLastError(ERROR_INVALID_PARAMETER
);
2683 case 0x00001009: /* (Loc,"en_CA") */
2687 case DATE_SHORTDATE
:
2688 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2689 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2690 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
2691 if(!(*lpDateFmtEnumProc
)("M/dd/yy")) return TRUE
;
2694 if(!(*lpDateFmtEnumProc
)("d-MMM-yy")) return TRUE
;
2695 if(!(*lpDateFmtEnumProc
)("MMMM d, yyyy")) return TRUE
;
2698 FIXME("Unknown date format (%ld)\n", dwFlags
);
2699 SetLastError(ERROR_INVALID_PARAMETER
);
2704 case 0x00001409: /* (Loc,"en_NZ") */
2708 case DATE_SHORTDATE
:
2709 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
2710 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2711 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
2714 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2715 if(!(*lpDateFmtEnumProc
)("dddd, d MMMM yyyy")) return TRUE
;
2718 FIXME("Unknown date format (%ld)\n", dwFlags
);
2719 SetLastError(ERROR_INVALID_PARAMETER
);
2724 case 0x00001809: /* (Loc,"en_IE") */
2728 case DATE_SHORTDATE
:
2729 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2730 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2731 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2734 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
2735 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2738 FIXME("Unknown date format (%ld)\n", dwFlags
);
2739 SetLastError(ERROR_INVALID_PARAMETER
);
2744 case 0x00001c09: /* (Loc,"en_ZA") */
2748 case DATE_SHORTDATE
:
2749 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
2752 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
2755 FIXME("Unknown date format (%ld)\n", dwFlags
);
2756 SetLastError(ERROR_INVALID_PARAMETER
);
2761 case 0x00002009: /* (Loc,"en_JM") */
2765 case DATE_SHORTDATE
:
2766 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2769 if(!(*lpDateFmtEnumProc
)("dddd,MMMM dd,yyyy")) return TRUE
;
2770 if(!(*lpDateFmtEnumProc
)("MMMM dd,yyyy")) return TRUE
;
2771 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM,yyyy")) return TRUE
;
2772 if(!(*lpDateFmtEnumProc
)("dd MMMM,yyyy")) return TRUE
;
2775 FIXME("Unknown date format (%ld)\n", dwFlags
);
2776 SetLastError(ERROR_INVALID_PARAMETER
);
2781 case 0x00002809: /* (Loc,"en_BZ") */
2782 case 0x00002c09: /* (Loc,"en_TT") */
2786 case DATE_SHORTDATE
:
2787 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2790 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM yyyy")) return TRUE
;
2793 FIXME("Unknown date format (%ld)\n", dwFlags
);
2794 SetLastError(ERROR_INVALID_PARAMETER
);
2799 default: /* default to US English "en_US" */
2803 case DATE_SHORTDATE
:
2804 if(!(*lpDateFmtEnumProc
)("M/d/yy")) return TRUE
;
2805 if(!(*lpDateFmtEnumProc
)("M/d/yyyy")) return TRUE
;
2806 if(!(*lpDateFmtEnumProc
)("MM/dd/yy")) return TRUE
;
2807 if(!(*lpDateFmtEnumProc
)("MM/dd/yyyy")) return TRUE
;
2808 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
2809 if(!(*lpDateFmtEnumProc
)("dd-MMM-yy")) return TRUE
;
2812 if(!(*lpDateFmtEnumProc
)("dddd, MMMM dd, yyyy")) return TRUE
;
2813 if(!(*lpDateFmtEnumProc
)("MMMM dd, yyyy")) return TRUE
;
2814 if(!(*lpDateFmtEnumProc
)("dddd, dd MMMM, yyyy")) return TRUE
;
2815 if(!(*lpDateFmtEnumProc
)("dd MMMM, yyyy")) return TRUE
;
2818 FIXME("Unknown date format (%ld)\n", dwFlags
);
2819 SetLastError(ERROR_INVALID_PARAMETER
);
2826 /**************************************************************************
2827 * EnumDateFormatsW (KERNEL32.@)
2829 BOOL WINAPI
EnumDateFormatsW(
2830 DATEFMT_ENUMPROCW lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2832 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc
, Locale
, dwFlags
);
2833 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2837 /**************************************************************************
2838 * EnumTimeFormatsA (KERNEL32.@)
2840 BOOL WINAPI
EnumTimeFormatsA(
2841 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2843 LCID Loc
= GetUserDefaultLCID();
2844 if(!lpTimeFmtEnumProc
)
2846 SetLastError(ERROR_INVALID_PARAMETER
);
2851 FIXME("Unknown time format (%ld)\n", dwFlags
);
2856 case 0x00000407: /* (Loc,"de_DE") */
2858 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
2859 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2860 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2861 if(!(*lpTimeFmtEnumProc
)("H.mm")) return TRUE
;
2862 if(!(*lpTimeFmtEnumProc
)("H.mm'Uhr'")) return TRUE
;
2866 case 0x0000040c: /* (Loc,"fr_FR") */
2867 case 0x00000c0c: /* (Loc,"fr_CA") */
2869 if(!(*lpTimeFmtEnumProc
)("H:mm")) return TRUE
;
2870 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2871 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2872 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
2873 if(!(*lpTimeFmtEnumProc
)("HH'h'mm")) return TRUE
;
2877 case 0x00000809: /* (Loc,"en_UK") */
2878 case 0x00000c09: /* (Loc,"en_AU") */
2879 case 0x00001409: /* (Loc,"en_NZ") */
2880 case 0x00001809: /* (Loc,"en_IE") */
2882 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
2883 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2884 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2888 case 0x00001c09: /* (Loc,"en_ZA") */
2889 case 0x00002809: /* (Loc,"en_BZ") */
2890 case 0x00002c09: /* (Loc,"en_TT") */
2892 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
2893 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
2897 default: /* default to US style "en_US" */
2899 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
2900 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
2901 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2902 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2908 /**************************************************************************
2909 * EnumTimeFormatsW (KERNEL32.@)
2911 BOOL WINAPI
EnumTimeFormatsW(
2912 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2914 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc
, Locale
, dwFlags
);
2915 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2919 /**************************************************************************
2920 * This function is used just locally !
2921 * Description: Inverts a string.
2923 static void OLE_InvertString(char* string
)
2925 char sTmpArray
[128];
2928 for (counter
= strlen(string
); counter
> 0; counter
--)
2930 memcpy(sTmpArray
+ i
, string
+ counter
-1, 1);
2933 memcpy(sTmpArray
+ i
, "\0", 1);
2934 strcpy(string
, sTmpArray
);
2937 /***************************************************************************************
2938 * This function is used just locally !
2939 * Description: Test if the given string (psNumber) is valid or not.
2940 * The valid characters are the following:
2941 * - Characters '0' through '9'.
2942 * - One decimal point (dot) if the number is a floating-point value.
2943 * - A minus sign in the first character position if the number is
2945 * If the function succeeds, psBefore/psAfter will point to the string
2946 * on the right/left of the decimal symbol. pbNegative indicates if the
2947 * number is negative.
2949 static INT
OLE_GetNumberComponents(char* pInput
, char* psBefore
, char* psAfter
, BOOL
* pbNegative
)
2951 char sNumberSet
[] = "0123456789";
2952 BOOL bInDecimal
= FALSE
;
2954 /* Test if we do have a minus sign */
2955 if ( *pInput
== '-' )
2958 pInput
++; /* Jump to the next character. */
2961 while(*pInput
!= '\0')
2963 /* Do we have a valid numeric character */
2964 if ( strchr(sNumberSet
, *pInput
) != NULL
)
2966 if (bInDecimal
== TRUE
)
2967 *psAfter
++ = *pInput
;
2969 *psBefore
++ = *pInput
;
2973 /* Is this a decimal point (dot) */
2974 if ( *pInput
== '.' )
2976 /* Is it the first time we find it */
2977 if ((bInDecimal
== FALSE
))
2980 return -1; /* ERROR: Invalid parameter */
2984 /* It's neither a numeric character, nor a decimal point.
2985 * Thus, return an error.
2993 /* Add an End of Line character to the output buffers */
3000 /**************************************************************************
3001 * This function is used just locally !
3002 * Description: A number could be formatted using different numbers
3003 * of "digits in group" (example: 4;3;2;0).
3004 * The first parameter of this function is an array
3005 * containing the rule to be used. Its format is the following:
3006 * |NDG|DG1|DG2|...|0|
3007 * where NDG is the number of used "digits in group" and DG1, DG2,
3008 * are the corresponding "digits in group".
3009 * Thus, this function returns the grouping value in the array
3010 * pointed by the second parameter.
3012 static INT
OLE_GetGrouping(char* sRule
, INT index
)
3014 char sData
[2], sRuleSize
[2];
3015 INT nData
, nRuleSize
;
3017 memcpy(sRuleSize
, sRule
, 1);
3018 memcpy(sRuleSize
+1, "\0", 1);
3019 nRuleSize
= atoi(sRuleSize
);
3021 if (index
> 0 && index
< nRuleSize
)
3023 memcpy(sData
, sRule
+index
, 1);
3024 memcpy(sData
+1, "\0", 1);
3025 nData
= atoi(sData
);
3030 memcpy(sData
, sRule
+nRuleSize
-1, 1);
3031 memcpy(sData
+1, "\0", 1);
3032 nData
= atoi(sData
);
3038 /**************************************************************************
3039 * GetNumberFormatA (KERNEL32.@)
3041 INT WINAPI
GetNumberFormatA(LCID locale
, DWORD dwflags
,
3042 LPCSTR lpvalue
, const NUMBERFMTA
* lpFormat
,
3043 LPSTR lpNumberStr
, int cchNumber
)
3045 char sNumberDigits
[3], sDecimalSymbol
[5], sDigitsInGroup
[11], sDigitGroupSymbol
[5], sILZero
[2];
3046 INT nNumberDigits
, nNumberDecimal
, i
, j
, nCounter
, nStep
, nRuleIndex
, nGrouping
, nDigits
, retVal
, nLZ
;
3047 char sNumber
[128], sDestination
[128], sDigitsAfterDecimal
[10], sDigitsBeforeDecimal
[128];
3048 char sRule
[10], sSemiColumn
[]=";", sBuffer
[5], sNegNumber
[2];
3049 char *pStr
= NULL
, *pTmpStr
= NULL
;
3050 LCID systemDefaultLCID
;
3051 BOOL bNegative
= FALSE
;
3060 strncpy(sNumber
, lpvalue
, 128);
3061 sNumber
[127] = '\0';
3063 /* Make sure we have a valid input string, get the number
3064 * of digits before and after the decimal symbol, and check
3065 * if this is a negative number.
3067 if ( OLE_GetNumberComponents(sNumber
, sDigitsBeforeDecimal
, sDigitsAfterDecimal
, &bNegative
) != -1)
3069 nNumberDecimal
= strlen(sDigitsBeforeDecimal
);
3070 nDigits
= strlen(sDigitsAfterDecimal
);
3074 SetLastError(ERROR_INVALID_PARAMETER
);
3078 /* Which source will we use to format the string */
3079 used_operation
= RETURN_ERROR
;
3080 if (lpFormat
!= NULL
)
3083 used_operation
= USE_PARAMETER
;
3087 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3088 used_operation
= USE_LOCALEINFO
;
3090 used_operation
= USE_SYSTEMDEFAULT
;
3093 /* Load the fields we need */
3094 switch(used_operation
)
3096 case USE_LOCALEINFO
:
3097 GetLocaleInfoA(locale
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3098 GetLocaleInfoA(locale
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3099 GetLocaleInfoA(locale
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3100 GetLocaleInfoA(locale
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3101 GetLocaleInfoA(locale
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3102 GetLocaleInfoA(locale
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3105 sprintf(sNumberDigits
, "%d",lpFormat
->NumDigits
);
3106 strcpy(sDecimalSymbol
, lpFormat
->lpDecimalSep
);
3107 sprintf(sDigitsInGroup
, "%d;0",lpFormat
->Grouping
);
3108 strcpy(sDigitGroupSymbol
, lpFormat
->lpThousandSep
);
3109 sprintf(sILZero
, "%d",lpFormat
->LeadingZero
);
3110 sprintf(sNegNumber
, "%d",lpFormat
->NegativeOrder
);
3112 case USE_SYSTEMDEFAULT
:
3113 systemDefaultLCID
= GetSystemDefaultLCID();
3114 GetLocaleInfoA(systemDefaultLCID
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3115 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3116 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3117 GetLocaleInfoA(systemDefaultLCID
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3118 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3119 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3122 SetLastError(ERROR_INVALID_PARAMETER
);
3126 nNumberDigits
= atoi(sNumberDigits
);
3128 /* Remove the ";" */
3131 for (nCounter
=0; nCounter
<strlen(sDigitsInGroup
); nCounter
++)
3133 if ( memcmp(sDigitsInGroup
+ nCounter
, sSemiColumn
, 1) != 0 )
3135 memcpy(sRule
+ j
, sDigitsInGroup
+ nCounter
, 1);
3140 sprintf(sBuffer
, "%d", i
);
3141 memcpy(sRule
, sBuffer
, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3142 memcpy(sRule
+ j
, "\0", 1);
3144 /* First, format the digits before the decimal. */
3145 if ((nNumberDecimal
>0) && (atoi(sDigitsBeforeDecimal
) != 0))
3147 /* Working on an inverted string is easier ! */
3148 OLE_InvertString(sDigitsBeforeDecimal
);
3150 nStep
= nCounter
= i
= j
= 0;
3152 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3154 /* Here, we will loop until we reach the end of the string.
3155 * An internal counter (j) is used in order to know when to
3156 * insert the "digit group symbol".
3158 while (nNumberDecimal
> 0)
3160 i
= nCounter
+ nStep
;
3161 memcpy(sDestination
+ i
, sDigitsBeforeDecimal
+ nCounter
, 1);
3167 if (nRuleIndex
< sRule
[0])
3169 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3170 memcpy(sDestination
+ i
+1, sDigitGroupSymbol
, strlen(sDigitGroupSymbol
));
3171 nStep
+= strlen(sDigitGroupSymbol
);
3177 memcpy(sDestination
+ i
+1, "\0", 1);
3178 /* Get the string in the right order ! */
3179 OLE_InvertString(sDestination
);
3183 nLZ
= atoi(sILZero
);
3186 /* Use 0.xxx instead of .xxx */
3187 memcpy(sDestination
, "0", 1);
3188 memcpy(sDestination
+1, "\0", 1);
3191 memcpy(sDestination
, "\0", 1);
3195 /* Second, format the digits after the decimal. */
3197 nCounter
= nNumberDigits
;
3198 if ( (nDigits
>0) && (pStr
= strstr (sNumber
, ".")) )
3200 i
= strlen(sNumber
) - strlen(pStr
) + 1;
3201 strncpy ( sDigitsAfterDecimal
, sNumber
+ i
, nNumberDigits
);
3202 j
= strlen(sDigitsAfterDecimal
);
3203 if (j
< nNumberDigits
)
3204 nCounter
= nNumberDigits
-j
;
3206 for (i
=0;i
<nCounter
;i
++)
3207 memcpy(sDigitsAfterDecimal
+i
+j
, "0", 1);
3208 memcpy(sDigitsAfterDecimal
+ nNumberDigits
, "\0", 1);
3210 i
= strlen(sDestination
);
3211 j
= strlen(sDigitsAfterDecimal
);
3212 /* Finally, construct the resulting formatted string. */
3214 for (nCounter
=0; nCounter
<i
; nCounter
++)
3215 memcpy(sNumber
+ nCounter
, sDestination
+ nCounter
, 1);
3217 memcpy(sNumber
+ nCounter
, sDecimalSymbol
, strlen(sDecimalSymbol
));
3220 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), sDigitsAfterDecimal
+ i
, 1);
3221 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), "\0", 1);
3223 /* Is it a negative number */
3224 if (bNegative
== TRUE
)
3226 i
= atoi(sNegNumber
);
3227 pStr
= sDestination
;
3233 while (*sNumber
!= '\0')
3234 *pStr
++ = *pTmpStr
++;
3239 while (*pTmpStr
!= '\0')
3240 *pStr
++ = *pTmpStr
++;
3245 while (*pTmpStr
!= '\0')
3246 *pStr
++ = *pTmpStr
++;
3249 while (*pTmpStr
!= '\0')
3250 *pStr
++ = *pTmpStr
++;
3254 while (*pTmpStr
!= '\0')
3255 *pStr
++ = *pTmpStr
++;
3260 while (*pTmpStr
!= '\0')
3261 *pStr
++ = *pTmpStr
++;
3266 strcpy(sDestination
, sNumber
);
3268 /* If cchNumber is zero, then returns the number of bytes or characters
3269 * required to hold the formatted number string
3272 retVal
= strlen(sDestination
) + 1;
3275 strncpy (lpNumberStr
, sDestination
, cchNumber
-1);
3276 *(lpNumberStr
+cchNumber
-1) = '\0'; /* ensure we got a NULL at the end */
3277 retVal
= strlen(lpNumberStr
);
3283 /**************************************************************************
3284 * GetNumberFormatW (KERNEL32.@)
3286 INT WINAPI
GetNumberFormatW(LCID locale
, DWORD dwflags
,
3287 LPCWSTR lpvalue
, const NUMBERFMTW
* lpFormat
,
3288 LPWSTR lpNumberStr
, int cchNumber
)
3290 FIXME("%s: stub, no reformatting done\n",debugstr_w(lpvalue
));
3292 lstrcpynW( lpNumberStr
, lpvalue
, cchNumber
);
3293 return cchNumber
? strlenW( lpNumberStr
) : 0;
3296 /**************************************************************************
3297 * GetCurrencyFormatA (KERNEL32.@)
3299 INT WINAPI
GetCurrencyFormatA(LCID locale
, DWORD dwflags
,
3300 LPCSTR lpvalue
, const CURRENCYFMTA
* lpFormat
,
3301 LPSTR lpCurrencyStr
, int cchCurrency
)
3303 UINT nPosOrder
, nNegOrder
;
3305 char sDestination
[128], sNegOrder
[8], sPosOrder
[8], sCurrencySymbol
[8];
3306 char *pDestination
= sDestination
;
3307 char sNumberFormated
[128];
3308 char *pNumberFormated
= sNumberFormated
;
3309 LCID systemDefaultLCID
;
3310 BOOL bIsPositive
= FALSE
, bValidFormat
= FALSE
;
3319 NUMBERFMTA numberFmt
;
3321 /* Which source will we use to format the string */
3322 used_operation
= RETURN_ERROR
;
3323 if (lpFormat
!= NULL
)
3326 used_operation
= USE_PARAMETER
;
3330 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3331 used_operation
= USE_LOCALEINFO
;
3333 used_operation
= USE_SYSTEMDEFAULT
;
3336 /* Load the fields we need */
3337 switch(used_operation
)
3339 case USE_LOCALEINFO
:
3340 /* Specific to CURRENCYFMTA */
3341 GetLocaleInfoA(locale
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3342 GetLocaleInfoA(locale
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3343 GetLocaleInfoA(locale
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3345 nPosOrder
= atoi(sPosOrder
);
3346 nNegOrder
= atoi(sNegOrder
);
3349 /* Specific to CURRENCYFMTA */
3350 nNegOrder
= lpFormat
->NegativeOrder
;
3351 nPosOrder
= lpFormat
->PositiveOrder
;
3352 strcpy(sCurrencySymbol
, lpFormat
->lpCurrencySymbol
);
3354 case USE_SYSTEMDEFAULT
:
3355 systemDefaultLCID
= GetSystemDefaultLCID();
3356 /* Specific to CURRENCYFMTA */
3357 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3358 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3359 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3361 nPosOrder
= atoi(sPosOrder
);
3362 nNegOrder
= atoi(sNegOrder
);
3365 SetLastError(ERROR_INVALID_PARAMETER
);
3369 /* Construct a temporary number format structure */
3370 if (lpFormat
!= NULL
)
3372 numberFmt
.NumDigits
= lpFormat
->NumDigits
;
3373 numberFmt
.LeadingZero
= lpFormat
->LeadingZero
;
3374 numberFmt
.Grouping
= lpFormat
->Grouping
;
3375 numberFmt
.NegativeOrder
= 0;
3376 numberFmt
.lpDecimalSep
= lpFormat
->lpDecimalSep
;
3377 numberFmt
.lpThousandSep
= lpFormat
->lpThousandSep
;
3378 bValidFormat
= TRUE
;
3381 /* Make a call to GetNumberFormatA() */
3382 if (*lpvalue
== '-')
3384 bIsPositive
= FALSE
;
3385 retVal
= GetNumberFormatA(locale
,0,lpvalue
+1,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3390 retVal
= GetNumberFormatA(locale
,0,lpvalue
,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3396 /* construct the formatted string */
3401 case 0: /* Prefix, no separation */
3402 strcpy (pDestination
, sCurrencySymbol
);
3403 strcat (pDestination
, pNumberFormated
);
3405 case 1: /* Suffix, no separation */
3406 strcpy (pDestination
, pNumberFormated
);
3407 strcat (pDestination
, sCurrencySymbol
);
3409 case 2: /* Prefix, 1 char separation */
3410 strcpy (pDestination
, sCurrencySymbol
);
3411 strcat (pDestination
, " ");
3412 strcat (pDestination
, pNumberFormated
);
3414 case 3: /* Suffix, 1 char separation */
3415 strcpy (pDestination
, pNumberFormated
);
3416 strcat (pDestination
, " ");
3417 strcat (pDestination
, sCurrencySymbol
);
3420 SetLastError(ERROR_INVALID_PARAMETER
);
3424 else /* negative number */
3428 case 0: /* format: ($1.1) */
3429 strcpy (pDestination
, "(");
3430 strcat (pDestination
, sCurrencySymbol
);
3431 strcat (pDestination
, pNumberFormated
);
3432 strcat (pDestination
, ")");
3434 case 1: /* format: -$1.1 */
3435 strcpy (pDestination
, "-");
3436 strcat (pDestination
, sCurrencySymbol
);
3437 strcat (pDestination
, pNumberFormated
);
3439 case 2: /* format: $-1.1 */
3440 strcpy (pDestination
, sCurrencySymbol
);
3441 strcat (pDestination
, "-");
3442 strcat (pDestination
, pNumberFormated
);
3444 case 3: /* format: $1.1- */
3445 strcpy (pDestination
, sCurrencySymbol
);
3446 strcat (pDestination
, pNumberFormated
);
3447 strcat (pDestination
, "-");
3449 case 4: /* format: (1.1$) */
3450 strcpy (pDestination
, "(");
3451 strcat (pDestination
, pNumberFormated
);
3452 strcat (pDestination
, sCurrencySymbol
);
3453 strcat (pDestination
, ")");
3455 case 5: /* format: -1.1$ */
3456 strcpy (pDestination
, "-");
3457 strcat (pDestination
, pNumberFormated
);
3458 strcat (pDestination
, sCurrencySymbol
);
3460 case 6: /* format: 1.1-$ */
3461 strcpy (pDestination
, pNumberFormated
);
3462 strcat (pDestination
, "-");
3463 strcat (pDestination
, sCurrencySymbol
);
3465 case 7: /* format: 1.1$- */
3466 strcpy (pDestination
, pNumberFormated
);
3467 strcat (pDestination
, sCurrencySymbol
);
3468 strcat (pDestination
, "-");
3470 case 8: /* format: -1.1 $ */
3471 strcpy (pDestination
, "-");
3472 strcat (pDestination
, pNumberFormated
);
3473 strcat (pDestination
, " ");
3474 strcat (pDestination
, sCurrencySymbol
);
3476 case 9: /* format: -$ 1.1 */
3477 strcpy (pDestination
, "-");
3478 strcat (pDestination
, sCurrencySymbol
);
3479 strcat (pDestination
, " ");
3480 strcat (pDestination
, pNumberFormated
);
3482 case 10: /* format: 1.1 $- */
3483 strcpy (pDestination
, pNumberFormated
);
3484 strcat (pDestination
, " ");
3485 strcat (pDestination
, sCurrencySymbol
);
3486 strcat (pDestination
, "-");
3488 case 11: /* format: $ 1.1- */
3489 strcpy (pDestination
, sCurrencySymbol
);
3490 strcat (pDestination
, " ");
3491 strcat (pDestination
, pNumberFormated
);
3492 strcat (pDestination
, "-");
3494 case 12: /* format: $ -1.1 */
3495 strcpy (pDestination
, sCurrencySymbol
);
3496 strcat (pDestination
, " ");
3497 strcat (pDestination
, "-");
3498 strcat (pDestination
, pNumberFormated
);
3500 case 13: /* format: 1.1- $ */
3501 strcpy (pDestination
, pNumberFormated
);
3502 strcat (pDestination
, "-");
3503 strcat (pDestination
, " ");
3504 strcat (pDestination
, sCurrencySymbol
);
3506 case 14: /* format: ($ 1.1) */
3507 strcpy (pDestination
, "(");
3508 strcat (pDestination
, sCurrencySymbol
);
3509 strcat (pDestination
, " ");
3510 strcat (pDestination
, pNumberFormated
);
3511 strcat (pDestination
, ")");
3513 case 15: /* format: (1.1 $) */
3514 strcpy (pDestination
, "(");
3515 strcat (pDestination
, pNumberFormated
);
3516 strcat (pDestination
, " ");
3517 strcat (pDestination
, sCurrencySymbol
);
3518 strcat (pDestination
, ")");
3521 SetLastError(ERROR_INVALID_PARAMETER
);
3526 if (cchCurrency
== 0)
3527 return strlen(pDestination
) + 1;
3531 strncpy (lpCurrencyStr
, pDestination
, cchCurrency
-1);
3532 *(lpCurrencyStr
+cchCurrency
-1) = '\0'; /* ensure we got a NULL at the end */
3533 return strlen(lpCurrencyStr
);
3537 /**************************************************************************
3538 * GetCurrencyFormatW (KERNEL32.@)
3540 INT WINAPI
GetCurrencyFormatW(LCID locale
, DWORD dwflags
,
3541 LPCWSTR lpvalue
, const CURRENCYFMTW
* lpFormat
,
3542 LPWSTR lpCurrencyStr
, int cchCurrency
)
3544 FIXME("This API function is NOT implemented !\n");
3548 /******************************************************************************
3549 * OLE2NLS_CheckLocale [intern]
3551 static LCID
OLE2NLS_CheckLocale (LCID locale
)
3554 { locale
= LOCALE_SYSTEM_DEFAULT
;
3557 if (locale
== LOCALE_SYSTEM_DEFAULT
)
3558 { return GetSystemDefaultLCID();
3560 else if (locale
== LOCALE_USER_DEFAULT
)
3561 { return GetUserDefaultLCID();
3567 /******************************************************************************
3568 * GetTimeFormatA [KERNEL32.@]
3569 * Makes an ASCII string of the time
3571 * Formats date according to format, or locale default if format is
3572 * NULL. The format consists of literal characters and fields as follows:
3574 * h hours with no leading zero (12-hour)
3575 * hh hours with full two digits
3576 * H hours with no leading zero (24-hour)
3577 * HH hours with full two digits
3578 * m minutes with no leading zero
3579 * mm minutes with full two digits
3580 * s seconds with no leading zero
3581 * ss seconds with full two digits
3582 * t time marker (A or P)
3583 * tt time marker (AM, PM)
3587 GetTimeFormatA(LCID locale
, /* [in] */
3588 DWORD flags
, /* [in] */
3589 const SYSTEMTIME
* xtime
, /* [in] */
3590 LPCSTR format
, /* [in] */
3591 LPSTR timestr
, /* [out] */
3592 INT timelen
/* [in] */)
3593 { char format_buf
[40];
3596 const SYSTEMTIME
* thistime
;
3598 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standard timeformat */
3601 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,xtime
,format
,timestr
,timelen
);
3603 thislocale
= OLE2NLS_CheckLocale ( locale
);
3606 { if (flags
& LOCALE_NOUSEROVERRIDE
) /* use system default */
3607 { thislocale
= GetSystemDefaultLCID();
3609 GetLocaleInfoA(thislocale
, thisflags
, format_buf
, sizeof(format_buf
));
3610 thisformat
= format_buf
;
3613 { thisformat
= format
;
3616 if (xtime
== NULL
) /* NULL means use the current local time */
3622 /* Check that hour,min and sec is in range */
3624 ret
= OLE_GetFormatA(thislocale
, thisflags
, flags
, thistime
, thisformat
,
3630 /******************************************************************************
3631 * GetTimeFormatW [KERNEL32.@]
3632 * Makes a Unicode string of the time
3635 GetTimeFormatW(LCID locale
, /* [in] */
3636 DWORD flags
, /* [in] */
3637 const SYSTEMTIME
* xtime
, /* [in] */
3638 LPCWSTR format
, /* [in] */
3639 LPWSTR timestr
, /* [out] */
3640 INT timelen
/* [in] */)
3641 { WCHAR format_buf
[40];
3644 const SYSTEMTIME
* thistime
;
3646 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standard timeformat */
3649 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,
3650 xtime
,debugstr_w(format
),timestr
,timelen
);
3652 thislocale
= OLE2NLS_CheckLocale ( locale
);
3655 { if (flags
& LOCALE_NOUSEROVERRIDE
) /* use system default */
3656 { thislocale
= GetSystemDefaultLCID();
3658 GetLocaleInfoW(thislocale
, thisflags
, format_buf
, 40);
3659 thisformat
= format_buf
;
3662 { thisformat
= format
;
3665 if (xtime
== NULL
) /* NULL means use the current local time */
3673 ret
= OLE_GetFormatW(thislocale
, thisflags
, flags
, thistime
, thisformat
,
3678 /******************************************************************************
3679 * EnumCalendarInfoA [KERNEL32.@]
3681 BOOL WINAPI
EnumCalendarInfoA(
3682 CALINFO_ENUMPROCA calinfoproc
,LCID locale
,CALID calendar
,CALTYPE caltype
3684 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc
,locale
,calendar
,caltype
);