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
24 #include "wine/port.h"
36 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(string
);
46 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
47 * MUST contain all #defines from winnls.h
48 * last entry has NULL name, 0 id.
50 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
51 static const struct tagLOCALE_NAME2ID
{
55 LOCALE_ENTRY(ILANGUAGE
),
56 LOCALE_ENTRY(SLANGUAGE
),
57 LOCALE_ENTRY(SENGLANGUAGE
),
58 LOCALE_ENTRY(SABBREVLANGNAME
),
59 LOCALE_ENTRY(SNATIVELANGNAME
),
60 LOCALE_ENTRY(ICOUNTRY
),
61 LOCALE_ENTRY(SCOUNTRY
),
62 LOCALE_ENTRY(SENGCOUNTRY
),
63 LOCALE_ENTRY(SABBREVCTRYNAME
),
64 LOCALE_ENTRY(SNATIVECTRYNAME
),
65 LOCALE_ENTRY(IDEFAULTLANGUAGE
),
66 LOCALE_ENTRY(IDEFAULTCOUNTRY
),
67 LOCALE_ENTRY(IDEFAULTCODEPAGE
),
68 LOCALE_ENTRY(IDEFAULTANSICODEPAGE
),
69 LOCALE_ENTRY(IDEFAULTMACCODEPAGE
),
71 LOCALE_ENTRY(IMEASURE
),
72 LOCALE_ENTRY(SDECIMAL
),
73 LOCALE_ENTRY(STHOUSAND
),
74 LOCALE_ENTRY(SGROUPING
),
75 LOCALE_ENTRY(IDIGITS
),
77 LOCALE_ENTRY(INEGNUMBER
),
78 LOCALE_ENTRY(SNATIVEDIGITS
),
79 LOCALE_ENTRY(SCURRENCY
),
80 LOCALE_ENTRY(SINTLSYMBOL
),
81 LOCALE_ENTRY(SMONDECIMALSEP
),
82 LOCALE_ENTRY(SMONTHOUSANDSEP
),
83 LOCALE_ENTRY(SMONGROUPING
),
84 LOCALE_ENTRY(ICURRDIGITS
),
85 LOCALE_ENTRY(IINTLCURRDIGITS
),
86 LOCALE_ENTRY(ICURRENCY
),
87 LOCALE_ENTRY(INEGCURR
),
90 LOCALE_ENTRY(SSHORTDATE
),
91 LOCALE_ENTRY(SLONGDATE
),
92 LOCALE_ENTRY(STIMEFORMAT
),
96 LOCALE_ENTRY(ITIMEMARKPOSN
),
97 LOCALE_ENTRY(ICENTURY
),
98 LOCALE_ENTRY(ITLZERO
),
99 LOCALE_ENTRY(IDAYLZERO
),
100 LOCALE_ENTRY(IMONLZERO
),
103 LOCALE_ENTRY(ICALENDARTYPE
),
104 LOCALE_ENTRY(IOPTIONALCALENDAR
),
105 LOCALE_ENTRY(IFIRSTDAYOFWEEK
),
106 LOCALE_ENTRY(IFIRSTWEEKOFYEAR
),
107 LOCALE_ENTRY(SDAYNAME1
),
108 LOCALE_ENTRY(SDAYNAME2
),
109 LOCALE_ENTRY(SDAYNAME3
),
110 LOCALE_ENTRY(SDAYNAME4
),
111 LOCALE_ENTRY(SDAYNAME5
),
112 LOCALE_ENTRY(SDAYNAME6
),
113 LOCALE_ENTRY(SDAYNAME7
),
114 LOCALE_ENTRY(SABBREVDAYNAME1
),
115 LOCALE_ENTRY(SABBREVDAYNAME2
),
116 LOCALE_ENTRY(SABBREVDAYNAME3
),
117 LOCALE_ENTRY(SABBREVDAYNAME4
),
118 LOCALE_ENTRY(SABBREVDAYNAME5
),
119 LOCALE_ENTRY(SABBREVDAYNAME6
),
120 LOCALE_ENTRY(SABBREVDAYNAME7
),
121 LOCALE_ENTRY(SMONTHNAME1
),
122 LOCALE_ENTRY(SMONTHNAME2
),
123 LOCALE_ENTRY(SMONTHNAME3
),
124 LOCALE_ENTRY(SMONTHNAME4
),
125 LOCALE_ENTRY(SMONTHNAME5
),
126 LOCALE_ENTRY(SMONTHNAME6
),
127 LOCALE_ENTRY(SMONTHNAME7
),
128 LOCALE_ENTRY(SMONTHNAME8
),
129 LOCALE_ENTRY(SMONTHNAME9
),
130 LOCALE_ENTRY(SMONTHNAME10
),
131 LOCALE_ENTRY(SMONTHNAME11
),
132 LOCALE_ENTRY(SMONTHNAME12
),
133 LOCALE_ENTRY(SMONTHNAME13
),
134 LOCALE_ENTRY(SABBREVMONTHNAME1
),
135 LOCALE_ENTRY(SABBREVMONTHNAME2
),
136 LOCALE_ENTRY(SABBREVMONTHNAME3
),
137 LOCALE_ENTRY(SABBREVMONTHNAME4
),
138 LOCALE_ENTRY(SABBREVMONTHNAME5
),
139 LOCALE_ENTRY(SABBREVMONTHNAME6
),
140 LOCALE_ENTRY(SABBREVMONTHNAME7
),
141 LOCALE_ENTRY(SABBREVMONTHNAME8
),
142 LOCALE_ENTRY(SABBREVMONTHNAME9
),
143 LOCALE_ENTRY(SABBREVMONTHNAME10
),
144 LOCALE_ENTRY(SABBREVMONTHNAME11
),
145 LOCALE_ENTRY(SABBREVMONTHNAME12
),
146 LOCALE_ENTRY(SABBREVMONTHNAME13
),
147 LOCALE_ENTRY(SPOSITIVESIGN
),
148 LOCALE_ENTRY(SNEGATIVESIGN
),
149 LOCALE_ENTRY(IPOSSIGNPOSN
),
150 LOCALE_ENTRY(INEGSIGNPOSN
),
151 LOCALE_ENTRY(IPOSSYMPRECEDES
),
152 LOCALE_ENTRY(IPOSSEPBYSPACE
),
153 LOCALE_ENTRY(INEGSYMPRECEDES
),
154 LOCALE_ENTRY(INEGSEPBYSPACE
),
155 LOCALE_ENTRY(FONTSIGNATURE
),
156 LOCALE_ENTRY(SISO639LANGNAME
),
157 LOCALE_ENTRY(SISO3166CTRYNAME
),
161 static char *GetLocaleSubkeyName( DWORD lctype
);
163 /***********************************************************************
164 * GetUserDefaultLCID (KERNEL32.@)
166 LCID WINAPI
GetUserDefaultLCID(void)
168 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT
);
171 /***********************************************************************
172 * GetSystemDefaultLCID (KERNEL32.@)
174 LCID WINAPI
GetSystemDefaultLCID(void)
176 return GetUserDefaultLCID();
179 #define NLS_MAX_LANGUAGES 20
183 LANGID found_lang_id
[NLS_MAX_LANGUAGES
];
184 char found_language
[NLS_MAX_LANGUAGES
][3];
185 char found_country
[NLS_MAX_LANGUAGES
][3];
189 static BOOL CALLBACK
NLS_FindLanguageID_ProcA(HMODULE hModule
, LPCSTR type
,
190 LPCSTR name
, WORD LangID
, LONG lParam
)
192 LANG_FIND_DATA
*l_data
= (LANG_FIND_DATA
*)lParam
;
193 LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
194 char buf_language
[128];
195 char buf_country
[128];
196 char buf_en_language
[128];
198 TRACE("%04X\n", (UINT
)LangID
);
199 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
200 return TRUE
; /* continue search */
205 GetLocaleInfoA(lcid
, LOCALE_SISO639LANGNAME
|LOCALE_NOUSEROVERRIDE
,
206 buf_language
, sizeof(buf_language
));
207 TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language
);
209 GetLocaleInfoA(lcid
, LOCALE_SISO3166CTRYNAME
|LOCALE_NOUSEROVERRIDE
,
210 buf_country
, sizeof(buf_country
));
211 TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country
);
213 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_language
))
215 if(l_data
->country
&& strlen(l_data
->country
) > 0)
217 if(!strcasecmp(l_data
->country
, buf_country
))
219 l_data
->found_lang_id
[0] = LangID
;
221 TRACE("Found lang_id %04X for %s_%s\n", LangID
, l_data
->lang
, l_data
->country
);
222 return FALSE
; /* stop enumeration */
225 else /* l_data->country not specified */
227 if(l_data
->n_found
< NLS_MAX_LANGUAGES
)
229 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
230 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
231 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
233 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
234 return TRUE
; /* continue search */
239 /* Just in case, check LOCALE_SENGLANGUAGE too,
240 * in hope that possible alias name might have that value.
242 buf_en_language
[0] = 0;
243 GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
|LOCALE_NOUSEROVERRIDE
,
244 buf_en_language
, sizeof(buf_en_language
));
245 TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language
);
247 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_en_language
))
249 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
250 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
251 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
253 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
256 return TRUE
; /* continue search */
259 /***********************************************************************
263 * Lang: a string whose two first chars are the iso name of a language.
264 * Country: a string whose two first chars are the iso name of country
265 * Charset: a string defining the chossen charset encoding
266 * Dialect: a string defining a variation of the locale
268 * all those values are from the standardized format of locale
269 * name in unix which is: Lang[_Country][.Charset][@Dialect]
272 * the numeric code of the language used by Windows
274 * FIXME: Charset and Dialect are not handled
276 static LANGID
NLS_GetLanguageID(LPCSTR Lang
, LPCSTR Country
, LPCSTR Charset
, LPCSTR Dialect
)
278 LANG_FIND_DATA l_data
;
279 char lang_string
[256];
283 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
287 memset(&l_data
, 0, sizeof(LANG_FIND_DATA
));
288 strncpy(l_data
.lang
, Lang
, sizeof(l_data
.lang
));
290 if(Country
&& strlen(Country
) > 0)
291 strncpy(l_data
.country
, Country
, sizeof(l_data
.country
));
293 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
294 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
296 strcpy(lang_string
, l_data
.lang
);
297 if(l_data
.country
&& strlen(l_data
.country
) > 0)
299 strcat(lang_string
, "_");
300 strcat(lang_string
, l_data
.country
);
305 if(l_data
.country
&& strlen(l_data
.country
) > 0)
307 MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string
);
308 l_data
.country
[0] = 0;
309 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
310 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
314 /* Re-evaluate lang_string */
315 strcpy(lang_string
, l_data
.lang
);
316 if(l_data
.country
&& strlen(l_data
.country
) > 0)
318 strcat(lang_string
, "_");
319 strcat(lang_string
, l_data
.country
);
324 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string
);
325 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
329 if(l_data
.n_found
== 1)
330 TRACE("For language '%s' lang_id %04X was found\n", lang_string
, l_data
.found_lang_id
[0]);
331 else /* l_data->n_found > 1 */
334 MESSAGE("For language '%s' several language ids were found:\n", lang_string
);
335 for(i
= 0; i
< l_data
.n_found
; i
++)
336 MESSAGE("%s_%s - %04X; ", l_data
.found_language
[i
], l_data
.found_country
[i
], l_data
.found_lang_id
[i
]);
338 MESSAGE("\nInstead of using first in the list, suggest to define\n"
339 "your LANG environment variable like this: LANG=%s_%s\n",
340 l_data
.found_language
[0], l_data
.found_country
[0]);
344 TRACE("Returning %04X\n", l_data
.found_lang_id
[0]);
345 return l_data
.found_lang_id
[0];
348 /***********************************************************************
349 * GetUserDefaultLangID (KERNEL32.@)
351 LANGID WINAPI
GetUserDefaultLangID(void)
353 /* caching result, if defined from environment, which should (?) not change during a WINE session */
354 static LANGID userLCID
= 0;
359 char *lang
,*country
,*charset
,*dialect
,*next
;
361 if (GetEnvironmentVariableA( "LANGUAGE", buf
, sizeof(buf
) )) goto ok
;
362 if (GetEnvironmentVariableA( "LANG", buf
, sizeof(buf
) )) goto ok
;
363 if (GetEnvironmentVariableA( "LC_ALL", buf
, sizeof(buf
) )) goto ok
;
364 if (GetEnvironmentVariableA( "LC_MESSAGES", buf
, sizeof(buf
) )) goto ok
;
365 if (GetEnvironmentVariableA( "LC_CTYPE", buf
, sizeof(buf
) )) goto ok
;
367 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
370 if (!strcmp(buf
,"POSIX") || !strcmp(buf
,"C"))
371 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
376 next
=strchr(lang
,':'); if (next
) *next
++='\0';
377 dialect
=strchr(lang
,'@'); if (dialect
) *dialect
++='\0';
378 charset
=strchr(lang
,'.'); if (charset
) *charset
++='\0';
379 country
=strchr(lang
,'_'); if (country
) *country
++='\0';
381 userLCID
= NLS_GetLanguageID(lang
, country
, charset
, dialect
);
384 } while (lang
&& !userLCID
);
388 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
390 userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
396 /***********************************************************************
397 * GetSystemDefaultLangID (KERNEL32.@)
399 LANGID WINAPI
GetSystemDefaultLangID(void)
401 return GetUserDefaultLangID();
404 /******************************************************************************
405 * ConvertDefaultLocale (KERNEL32.@)
407 LCID WINAPI
ConvertDefaultLocale (LCID lcid
)
409 { case LOCALE_SYSTEM_DEFAULT
:
410 return GetSystemDefaultLCID();
411 case LOCALE_USER_DEFAULT
:
412 return GetUserDefaultLCID();
414 return MAKELCID (LANG_NEUTRAL
, SUBLANG_NEUTRAL
);
416 return MAKELANGID( PRIMARYLANGID(lcid
), SUBLANG_NEUTRAL
);
419 /* Enhanced version of LoadStringW.
420 * It takes LanguageId to find and load language dependant resources.
421 * Resource is copied as is: "binary" strings are not truncated.
422 * Return: length of resource + 1 to distinguish absent resources
423 * from the resources with zero length.
425 static INT
NLS_LoadStringExW(HMODULE hModule
, LANGID lang_id
, UINT res_id
, LPWSTR buffer
, INT buflen
)
433 /* Replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
434 if(SUBLANGID(lang_id
) == SUBLANG_NEUTRAL
)
435 lang_id
= MAKELANGID(PRIMARYLANGID(lang_id
), SUBLANG_DEFAULT
);
437 hrsrc
= FindResourceExW(hModule
, RT_STRINGW
, (LPCWSTR
)((res_id
>> 4) + 1), lang_id
);
440 hmem
= LoadResource(hModule
, hrsrc
);
443 p
= LockResource(hmem
);
444 string_num
= res_id
& 0x000f;
445 for(i
= 0; i
< string_num
; i
++)
448 TRACE("strlen = %d\n", (int)*p
);
450 if (buffer
== NULL
) return *p
;
451 i
= min(buflen
- 1, *p
);
453 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
454 buffer
[i
] = (WCHAR
) 0;
457 buffer
[0] = (WCHAR
) 0;
461 TRACE("%s loaded!\n", debugstr_w(buffer
));
465 /******************************************************************************
466 * GetLocaleInfoA (KERNEL32.@)
469 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
471 * MS online documentation states that the string returned is NULL terminated
472 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
473 * terminated string".
475 INT WINAPI
GetLocaleInfoA(LCID lcid
,LCTYPE LCType
,LPSTR buf
,INT len
)
477 LPCSTR retString
= NULL
;
481 DWORD dwBufferSize
=128;
484 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid
,LCType
,buf
,len
);
486 if (len
&& (! buf
) ) {
487 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
491 if (lcid
== LOCALE_NEUTRAL
|| lcid
== LANG_SYSTEM_DEFAULT
)
493 lcid
= GetSystemDefaultLCID();
495 else if (lcid
== LANG_USER_DEFAULT
) /*0x800*/
497 lcid
= GetUserDefaultLCID();
500 /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
501 from the registry. Instead, use system default values. */
502 NoUserOverride
= (LCType
& LOCALE_NOUSEROVERRIDE
) != 0;
504 LCType
&= ~(LOCALE_NOUSEROVERRIDE
|LOCALE_USE_CP_ACP
);
506 /* First, check if it's in the registry. */
507 /* All user customized values are stored in the registry by SetLocaleInfo */
508 if ( !NoUserOverride
&& (pacKey
= GetLocaleSubkeyName(LCType
)) )
513 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
515 if ( RegOpenKeyExA( HKEY_CURRENT_USER
, acRealKey
,
516 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
518 if ( RegQueryValueExA( hKey
, NULL
, NULL
, NULL
, (LPBYTE
)acBuffer
,
519 &dwBufferSize
) == ERROR_SUCCESS
)
521 retString
= acBuffer
;
528 /* If not in the registry, get it from the NLS entries. */
533 /* check if language is registered in the kernel32 resources */
534 if((res_size
= NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid
),
535 LCType
, wcBuffer
, sizeof(wcBuffer
)/sizeof(wcBuffer
[0])))) {
536 WideCharToMultiByte(CP_ACP
, 0, wcBuffer
, res_size
, acBuffer
, dwBufferSize
, NULL
, NULL
);
537 retString
= acBuffer
;
542 /* if not found report a most descriptive error */
545 /* If we are through all of this, retLen should not be zero anymore.
546 If it is, the value is not supported */
548 while (locale_name2id
[i
].name
!=NULL
) {
549 if (LCType
== locale_name2id
[i
].id
) {
550 retString
= locale_name2id
[i
].name
;
556 FIXME("Unkown LC type %lX\n", LCType
);
558 FIXME("'%s' is not defined for your language (%04X).\n"
559 "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
560 "and submit patch for inclusion into the next Wine release.\n",
561 retString
, LOWORD(lcid
));
562 SetLastError(ERROR_INVALID_PARAMETER
);
566 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
567 if (LCType
== LOCALE_FONTSIGNATURE
) {
569 len
= (len
< sizeof(FONTSIGNATURE
)) ? len
: sizeof(FONTSIGNATURE
);
570 memcpy(buf
, retString
, len
);
573 return sizeof(FONTSIGNATURE
);
575 /* if len=0 return only the length, don't touch the buffer*/
577 lstrcpynA(buf
,retString
,len
);
578 return strlen(buf
) + 1;
580 return strlen(retString
)+1;
583 /******************************************************************************
584 * GetLocaleInfoW (KERNEL32.@)
587 * MS documentation states that len "specifies the size, in bytes (ANSI version)
588 * or characters (Unicode version), of" wbuf. Thus the number returned is
589 * the same between GetLocaleInfoW and GetLocaleInfoA.
591 INT WINAPI
GetLocaleInfoW(LCID lcid
,LCTYPE LCType
,LPWSTR wbuf
,INT len
)
595 if (len
&& (! wbuf
) )
596 { SetLastError(ERROR_INSUFFICIENT_BUFFER
);
600 abuf
= (LPSTR
)HeapAlloc(GetProcessHeap(),0,len
);
601 wlen
= GetLocaleInfoA(lcid
, LCType
, abuf
, len
);
603 if (wlen
&& len
) /* if len=0 return only the length*/
604 MultiByteToWideChar( CP_ACP
, 0, abuf
, -1, wbuf
, len
);
606 HeapFree(GetProcessHeap(),0,abuf
);
610 /******************************************************************************
612 * GetLocaleSubkeyName [helper function]
614 * - For use with the registry.
615 * - Gets the registry subkey name for a given lctype.
617 static char *GetLocaleSubkeyName( DWORD lctype
)
623 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
624 * the values are stored in the registry, confirmed under Windows,
625 * for the ones that actually assign pacKey. Cases that aren't finished
626 * have not been confirmed, so that must be done before they can be
629 case LOCALE_SDATE
: /* The date separator. */
632 case LOCALE_ICURRDIGITS
:
633 pacKey
= "iCurrDigits";
635 case LOCALE_SDECIMAL
:
638 case LOCALE_ICURRENCY
:
639 pacKey
= "iCurrency";
641 case LOCALE_SGROUPING
:
642 pacKey
= "sGrouping";
650 /* case LOCALE_ICALENDARTYPE: */
651 /* case LOCALE_IFIRSTDAYOFWEEK: */
652 /* case LOCALE_IFIRSTWEEKOFYEAR: */
653 /* case LOCALE_SYEARMONTH : */
654 /* case LOCALE_SPOSITIVESIGN : */
655 /* case LOCALE_IPAPERSIZE: */
657 case LOCALE_SLONGDATE
:
658 pacKey
= "sLongDate";
660 case LOCALE_SMONDECIMALSEP
:
661 pacKey
= "sMonDecimalSep";
663 case LOCALE_SMONGROUPING
:
664 pacKey
= "sMonGrouping";
666 case LOCALE_IMEASURE
:
669 case LOCALE_SMONTHOUSANDSEP
:
670 pacKey
= "sMonThousandSep";
672 case LOCALE_INEGCURR
:
675 case LOCALE_SNEGATIVESIGN
:
676 pacKey
= "sNegativeSign";
678 case LOCALE_INEGNUMBER
:
679 pacKey
= "iNegNumber";
681 case LOCALE_SSHORTDATE
:
682 pacKey
= "sShortDate";
684 case LOCALE_ILDATE
: /* Long Date format ordering specifier. */
693 case LOCALE_ITIME
: /* Time format specifier. */
696 case LOCALE_STHOUSAND
:
697 pacKey
= "sThousand";
699 case LOCALE_S1159
: /* AM */
705 case LOCALE_S2359
: /* PM */
708 case LOCALE_STIMEFORMAT
:
709 pacKey
= "sTimeFormat";
711 case LOCALE_SCURRENCY
:
712 pacKey
= "sCurrency";
715 /* The following are not listed under MSDN as supported,
716 * but seem to be used and also stored in the registry.
722 case LOCALE_SCOUNTRY
:
725 case LOCALE_ICOUNTRY
:
728 case LOCALE_SLANGUAGE
:
729 pacKey
= "sLanguage";
739 /******************************************************************************
740 * SetLocaleInfoA [KERNEL32.@]
742 BOOL WINAPI
SetLocaleInfoA(LCID lcid
, LCTYPE lctype
, LPCSTR data
)
748 if ( (pacKey
= GetLocaleSubkeyName(lctype
)) )
750 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
751 if ( RegCreateKeyA( HKEY_CURRENT_USER
, acRealKey
,
752 &hKey
) == ERROR_SUCCESS
)
754 if ( RegSetValueExA( hKey
, NULL
, 0, REG_SZ
,
755 data
, strlen(data
)+1 ) != ERROR_SUCCESS
)
757 ERR("SetLocaleInfoA: %s did not work\n", pacKey
);
764 FIXME("(%ld,%ld,%s): stub\n",lcid
,lctype
,data
);
769 /******************************************************************************
770 * IsValidLocale [KERNEL32.@]
772 BOOL WINAPI
IsValidLocale(LCID lcid
,DWORD flags
)
774 /* check if language is registered in the kernel32 resources */
775 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW
, (LPCWSTR
)LOCALE_ILANGUAGE
, LOWORD(lcid
)))
781 static BOOL CALLBACK
EnumResourceLanguagesProcW(HMODULE hModule
, LPCWSTR type
,
782 LPCWSTR name
, WORD LangID
, LONG lParam
)
786 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
787 sprintf(bufA
, "%08X", (UINT
)LangID
);
788 MultiByteToWideChar(CP_ACP
, 0, bufA
, -1, bufW
, sizeof(bufW
)/sizeof(bufW
[0]));
789 return lpfnLocaleEnum(bufW
);
792 /******************************************************************************
793 * EnumSystemLocalesW [KERNEL32.@]
795 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
,
798 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
800 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW
,
801 (LPCWSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcW
,
802 (LONG
)lpfnLocaleEnum
);
807 static BOOL CALLBACK
EnumResourceLanguagesProcA(HMODULE hModule
, LPCSTR type
,
808 LPCSTR name
, WORD LangID
, LONG lParam
)
811 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
812 sprintf(bufA
, "%08X", (UINT
)LangID
);
813 return lpfnLocaleEnum(bufA
);
816 /******************************************************************************
817 * EnumSystemLocalesA [KERNEL32.@]
819 BOOL WINAPI
EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum
,
822 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
824 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
825 (LPCSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcA
,
826 (LONG
)lpfnLocaleEnum
);
831 /***********************************************************************
832 * VerLanguageNameA [KERNEL32.@]
834 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
839 return GetLocaleInfoA(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
842 /***********************************************************************
843 * VerLanguageNameW [KERNEL32.@]
845 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
850 return GetLocaleInfoW(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
854 static const unsigned char LCM_Unicode_LUT
[] = {
888 7 , 29, /* " - 34 */ /* " */
893 6 , 128, /* ' - 39 */
899 6 , 130, /* - - 45 */
903 12 , 33, /* 1 - 49 */
904 12 , 51, /* 2 - 50 */
905 12 , 70, /* 3 - 51 */
906 12 , 88, /* 4 - 52 */
907 12 , 106, /* 5 - 53 */
908 12 , 125, /* 6 - 54 */
909 12 , 144, /* 7 - 55 */
910 12 , 162, /* 8 - 56 */
911 12 , 180, /* 9 - 57 */
921 14 , 10, /* C - 67 */
922 14 , 26, /* D - 68 */
923 14 , 33, /* E - 69 */
924 14 , 35, /* F - 70 */
925 14 , 37, /* G - 71 */
926 14 , 44, /* H - 72 */
927 14 , 50, /* I - 73 */
928 14 , 53, /* J - 74 */
929 14 , 54, /* K - 75 */
930 14 , 72, /* L - 76 */
931 14 , 81, /* M - 77 */
932 14 , 112, /* N - 78 */
933 14 , 124, /* O - 79 */
934 14 , 126, /* P - 80 */
935 14 , 137, /* Q - 81 */
936 14 , 138, /* R - 82 */
937 14 , 145, /* S - 83 */
938 14 , 153, /* T - 84 */
939 14 , 159, /* U - 85 */
940 14 , 162, /* V - 86 */
941 14 , 164, /* W - 87 */
942 14 , 166, /* X - 88 */
943 14 , 167, /* Y - 89 */
944 14 , 169, /* Z - 90 */
953 14 , 10, /* c - 99 */
954 14 , 26, /* d - 100 */
955 14 , 33, /* e - 101 */
956 14 , 35, /* f - 102 */
957 14 , 37, /* g - 103 */
958 14 , 44, /* h - 104 */
959 14 , 50, /* i - 105 */
960 14 , 53, /* j - 106 */
961 14 , 54, /* k - 107 */
962 14 , 72, /* l - 108 */
963 14 , 81, /* m - 109 */
964 14 , 112, /* n - 110 */
965 14 , 124, /* o - 111 */
966 14 , 126, /* p - 112 */
967 14 , 137, /* q - 113 */
968 14 , 138, /* r - 114 */
969 14 , 145, /* s - 115 */
970 14 , 153, /* t - 116 */
971 14 , 159, /* u - 117 */
972 14 , 162, /* v - 118 */
973 14 , 164, /* w - 119 */
974 14 , 166, /* x - 120 */
975 14 , 167, /* y - 121 */
976 14 , 169, /* z - 122 */
977 7 , 74, /* { - 123 */
978 7 , 76, /* | - 124 */
979 7 , 78, /* } - 125 */
980 7 , 80, /* ~ - 126 */
981 6 , 29, /* \x7f - 127 */
982 6 , 30, /* € - 128 */
983 6 , 31, /* � - 129 */
984 7 , 123, /* ‚ - 130 */
985 14 , 35, /* ƒ - 131 */
986 7 , 127, /* „ - 132 */
987 10 , 21, /* … - 133 */
988 10 , 15, /* † - 134 */
989 10 , 16, /* ‡ - 135 */
990 7 , 67, /* ˆ - 136 */
991 10 , 22, /* ‰ - 137 */
992 14 , 145, /* Š - 138 */
993 7 , 136, /* ‹ - 139 */
994 14 + 16 , 124, /* Œ - 140 */
995 6 , 43, /* � - 141 */
996 6 , 44, /* Ž - 142 */
997 6 , 45, /* � - 143 */
998 6 , 46, /* � - 144 */
999 7 , 121, /* ‘ - 145 */
1000 7 , 122, /* ’ - 146 */
1001 7 , 125, /* “ - 147 */
1002 7 , 126, /* ” - 148 */
1003 10 , 17, /* • - 149 */
1004 6 , 137, /* – - 150 */
1005 6 , 139, /* — - 151 */
1006 7 , 93, /* ˜ - 152 */
1007 14 , 156, /* ™ - 153 */
1008 14 , 145, /* š - 154 */
1009 7 , 137, /* › - 155 */
1010 14 + 16 , 124, /* œ - 156 */
1011 6 , 59, /* � - 157 */
1012 6 , 60, /* ž - 158 */
1013 14 , 167, /* Ÿ - 159 */
1015 7 , 81, /* ¡ - 161 */
1016 10 , 2, /* ¢ - 162 */
1017 10 , 3, /* £ - 163 */
1018 10 , 4, /* ¤ - 164 */
1019 10 , 5, /* ¥ - 165 */
1020 7 , 82, /* ¦ - 166 */
1021 10 , 6, /* § - 167 */
1022 7 , 83, /* ¨ - 168 */
1023 10 , 7, /* © - 169 */
1024 14 , 2, /* ª - 170 */
1025 8 , 24, /* « - 171 */
1026 10 , 8, /* ¬ - 172 */
1027 6 , 131, /* - 173 */
1028 10 , 9, /* ® - 174 */
1029 7 , 84, /* ¯ - 175 */
1030 10 , 10, /* ° - 176 */
1031 8 , 23, /* ± - 177 */
1032 12 , 51, /* ² - 178 */
1033 12 , 70, /* ³ - 179 */
1034 7 , 85, /* ´ - 180 */
1035 10 , 11, /* µ - 181 */
1036 10 , 12, /* ¶ - 182 */
1037 10 , 13, /* · - 183 */
1038 7 , 86, /* ¸ - 184 */
1039 12 , 33, /* ¹ - 185 */
1040 14 , 124, /* º - 186 */
1041 8 , 26, /* » - 187 */
1042 12 , 21, /* ¼ - 188 */
1043 12 , 25, /* ½ - 189 */
1044 12 , 29, /* ¾ - 190 */
1045 7 , 87, /* ¿ - 191 */
1046 14 , 2, /* À - 192 */
1047 14 , 2, /* Á - 193 */
1048 14 , 2, /* Â - 194 */
1049 14 , 2, /* Ã - 195 */
1050 14 , 2, /* Ä - 196 */
1051 14 , 2, /* Å - 197 */
1052 14 + 16 , 2, /* Æ - 198 */
1053 14 , 10, /* Ç - 199 */
1054 14 , 33, /* È - 200 */
1055 14 , 33, /* É - 201 */
1056 14 , 33, /* Ê - 202 */
1057 14 , 33, /* Ë - 203 */
1058 14 , 50, /* Ì - 204 */
1059 14 , 50, /* Í - 205 */
1060 14 , 50, /* Î - 206 */
1061 14 , 50, /* Ï - 207 */
1062 14 , 26, /* Ð - 208 */
1063 14 , 112, /* Ñ - 209 */
1064 14 , 124, /* Ò - 210 */
1065 14 , 124, /* Ó - 211 */
1066 14 , 124, /* Ô - 212 */
1067 14 , 124, /* Õ - 213 */
1068 14 , 124, /* Ö - 214 */
1069 8 , 28, /* × - 215 */
1070 14 , 124, /* Ø - 216 */
1071 14 , 159, /* Ù - 217 */
1072 14 , 159, /* Ú - 218 */
1073 14 , 159, /* Û - 219 */
1074 14 , 159, /* Ü - 220 */
1075 14 , 167, /* Ý - 221 */
1076 14 + 32 , 153, /* Þ - 222 */
1077 14 + 48 , 145, /* ß - 223 */
1078 14 , 2, /* à - 224 */
1079 14 , 2, /* á - 225 */
1080 14 , 2, /* â - 226 */
1081 14 , 2, /* ã - 227 */
1082 14 , 2, /* ä - 228 */
1083 14 , 2, /* å - 229 */
1084 14 + 16 , 2, /* æ - 230 */
1085 14 , 10, /* ç - 231 */
1086 14 , 33, /* è - 232 */
1087 14 , 33, /* é - 233 */
1088 14 , 33, /* ê - 234 */
1089 14 , 33, /* ë - 235 */
1090 14 , 50, /* ì - 236 */
1091 14 , 50, /* í - 237 */
1092 14 , 50, /* î - 238 */
1093 14 , 50, /* ï - 239 */
1094 14 , 26, /* ð - 240 */
1095 14 , 112, /* ñ - 241 */
1096 14 , 124, /* ò - 242 */
1097 14 , 124, /* ó - 243 */
1098 14 , 124, /* ô - 244 */
1099 14 , 124, /* õ - 245 */
1100 14 , 124, /* ö - 246 */
1101 8 , 29, /* ÷ - 247 */
1102 14 , 124, /* ø - 248 */
1103 14 , 159, /* ù - 249 */
1104 14 , 159, /* ú - 250 */
1105 14 , 159, /* û - 251 */
1106 14 , 159, /* ü - 252 */
1107 14 , 167, /* ý - 253 */
1108 14 + 32 , 153, /* þ - 254 */
1109 14 , 167 /* ÿ - 255 */ };
1111 static const unsigned char LCM_Unicode_LUT_2
[] = { 33, 44, 145 };
1113 #define LCM_Diacritic_Start 131
1115 static const unsigned char LCM_Diacritic_LUT
[] = {
1243 /******************************************************************************
1244 * OLE2NLS_isPunctuation [INTERNAL]
1246 static int OLE2NLS_isPunctuation(unsigned char c
)
1248 /* "punctuation character" in this context is a character which is
1249 considered "less important" during word sort comparison.
1250 See LCMapString implementation for the precise definition
1251 of "less important". */
1253 return (LCM_Unicode_LUT
[-2+2*c
]==6);
1256 /******************************************************************************
1257 * OLE2NLS_isNonSpacing [INTERNAL]
1259 static int OLE2NLS_isNonSpacing(unsigned char c
)
1261 /* This function is used by LCMapStringA. Characters
1262 for which it returns true are ignored when mapping a
1263 string with NORM_IGNORENONSPACE */
1264 return ((c
==136) || (c
==170) || (c
==186));
1267 /******************************************************************************
1268 * OLE2NLS_isSymbol [INTERNAL]
1269 * FIXME: handle current locale
1271 static int OLE2NLS_isSymbol(unsigned char c
)
1273 /* This function is used by LCMapStringA. Characters
1274 for which it returns true are ignored when mapping a
1275 string with NORM_IGNORESYMBOLS */
1276 return ( (c
!=0) && !(isalpha(c
) || isdigit(c
)) );
1279 /******************************************************************************
1280 * identity [Internal]
1282 static int identity(int c
)
1287 /*************************************************************************
1288 * LCMapStringA [KERNEL32.@]
1290 * Convert a string, or generate a sort key from it.
1292 * If (mapflags & LCMAP_SORTKEY), the function will generate
1293 * a sort key for the source string. Else, it will convert it
1294 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1298 * Success : length of the result string.
1301 * If called with scrlen = -1, the function will compute the length
1302 * of the 0-terminated string strsrc by itself.
1304 * If called with dstlen = 0, returns the buffer length that
1305 * would be required.
1307 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1308 * as if they are equal.
1309 * In the only code page implemented so far, there may not be
1310 * wide characters in strings passed to LCMapStringA,
1311 * so there is nothing to be done for this flag.
1313 INT WINAPI
LCMapStringA(
1314 LCID lcid
, /* [in] locale identifier created with MAKELCID;
1315 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1316 predefined values. */
1317 DWORD mapflags
, /* [in] flags */
1318 LPCSTR srcstr
, /* [in] source buffer */
1319 INT srclen
, /* [in] source length */
1320 LPSTR dststr
, /* [out] destination buffer */
1321 INT dstlen
) /* [in] destination buffer length */
1325 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1326 lcid
,mapflags
,debugstr_an(srcstr
,srclen
),srclen
,dststr
,dstlen
);
1328 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1330 ERR("(src=%s,dest=%s): Invalid NULL string\n",
1331 debugstr_an(srcstr
,srclen
), dststr
);
1332 SetLastError(ERROR_INVALID_PARAMETER
);
1336 srclen
= strlen(srcstr
) + 1 ; /* (include final '\0') */
1338 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1342 NORM_IGNORENONSPACE | \
1344 NORM_IGNOREWIDTH | \
1345 NORM_IGNOREKANATYPE)
1346 /* FIXME: as long as we don't support Katakana nor Hiragana
1347 * characters, we can support NORM_IGNOREKANATYPE
1349 if (mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
)
1351 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1352 "unimplemented flags: 0x%08lx\n",
1359 mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
1363 if ( !(mapflags
& LCMAP_SORTKEY
) )
1366 int (*f
)(int) = identity
;
1367 int flag_ignorenonspace
= mapflags
& NORM_IGNORENONSPACE
;
1368 int flag_ignoresymbols
= mapflags
& NORM_IGNORESYMBOLS
;
1370 if (flag_ignorenonspace
|| flag_ignoresymbols
)
1372 /* For some values of mapflags, the length of the resulting
1373 string is not known at this point. Windows does map the string
1374 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1378 /* Compute required length */
1379 for (i
=j
=0; i
< srclen
; i
++)
1381 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1382 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1394 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1398 if (mapflags
& LCMAP_UPPERCASE
)
1400 else if (mapflags
& LCMAP_LOWERCASE
)
1402 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1403 for (i
=j
=0; (i
<srclen
) && (j
<dstlen
) ; i
++)
1405 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1406 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1408 dststr
[j
] = (CHAR
) f(srcstr
[i
]);
1415 /* FIXME: This function completely ignores the "lcid" parameter. */
1416 /* else ... (mapflags & LCMAP_SORTKEY) */
1420 int diacritic_len
=0;
1421 int delayed_punctuation_len
=0;
1422 char *case_component
;
1423 char *diacritic_component
;
1424 char *delayed_punctuation_component
;
1426 int flag_stringsort
= mapflags
& SORT_STRINGSORT
;
1428 /* compute how much room we will need */
1429 for (i
=0;i
<srclen
;i
++)
1432 unsigned char source_char
= srcstr
[i
];
1433 if (source_char
!='\0')
1435 if (flag_stringsort
|| !OLE2NLS_isPunctuation(source_char
))
1438 if ( LCM_Unicode_LUT
[-2+2*source_char
] & ~15 )
1439 unicode_len
++; /* double letter */
1443 delayed_punctuation_len
++;
1447 if (isupper(source_char
))
1448 case_len
=unicode_len
;
1450 ofs
= source_char
- LCM_Diacritic_Start
;
1451 if ((ofs
>=0) && (LCM_Diacritic_LUT
[ofs
]!=2))
1452 diacritic_len
=unicode_len
;
1455 if (mapflags
& NORM_IGNORECASE
)
1457 if (mapflags
& NORM_IGNORENONSPACE
)
1460 room
= 2 * unicode_len
/* "unicode" component */
1461 + diacritic_len
/* "diacritic" component */
1462 + case_len
/* "case" component */
1463 + 4 * delayed_punctuation_len
/* punctuation in word sort mode */
1464 + 4 /* four '\1' separators */
1465 + 1 ; /* terminal '\0' */
1468 else if (dstlen
<room
)
1470 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1474 /*FIXME the Pointercheck should not be nessesary */
1475 if (IsBadWritePtr (dststr
,room
))
1476 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr
,dstlen
);
1477 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1481 /* locate each component, write separators */
1482 diacritic_component
= dststr
+ 2*unicode_len
;
1483 *diacritic_component
++ = '\1';
1484 case_component
= diacritic_component
+ diacritic_len
;
1485 *case_component
++ = '\1';
1486 delayed_punctuation_component
= case_component
+ case_len
;
1487 *delayed_punctuation_component
++ = '\1';
1488 *delayed_punctuation_component
++ = '\1';
1490 /* read source string char by char, write
1491 corresponding weight in each component. */
1492 for (i
=0,count
=0;i
<srclen
;i
++)
1494 unsigned char source_char
=srcstr
[i
];
1495 if (source_char
!='\0')
1498 type
= LCM_Unicode_LUT
[-2+2*source_char
];
1499 longcode
= type
>> 4;
1501 if (!flag_stringsort
&& OLE2NLS_isPunctuation(source_char
))
1503 WORD encrypted_location
= (1<<15) + 7 + 4*count
;
1504 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
>>8);
1505 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
&255);
1506 /* big-endian is used here because it lets string comparison be
1507 compatible with numerical comparison */
1509 *delayed_punctuation_component
++ = type
;
1510 *delayed_punctuation_component
++ = LCM_Unicode_LUT
[-1+2*source_char
];
1511 /* assumption : a punctuation character is never a
1512 double or accented letter */
1516 dststr
[2*count
] = type
;
1517 dststr
[2*count
+1] = LCM_Unicode_LUT
[-1+2*source_char
];
1521 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1522 if (count
<diacritic_len
)
1523 diacritic_component
[count
] = 2; /* assumption: a double letter
1524 is never accented */
1527 dststr
[2*count
] = type
;
1528 dststr
[2*count
+1] = *(LCM_Unicode_LUT_2
- 1 + longcode
);
1529 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1530 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1531 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1535 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1536 if (count
<diacritic_len
)
1538 int ofs
= source_char
- LCM_Diacritic_Start
;
1539 diacritic_component
[count
] = (ofs
>=0 ? LCM_Diacritic_LUT
[ofs
] : 2);
1545 dststr
[room
-1] = '\0';
1550 /*************************************************************************
1551 * LCMapStringW [KERNEL32.@]
1553 * Convert a string, or generate a sort key from it.
1557 * See LCMapStringA for documentation
1559 INT WINAPI
LCMapStringW(
1560 LCID lcid
,DWORD mapflags
,LPCWSTR srcstr
,INT srclen
,LPWSTR dststr
,
1565 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
1566 lcid
, mapflags
, srcstr
, srclen
, dststr
, dstlen
);
1568 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1570 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr
, dststr
);
1571 SetLastError(ERROR_INVALID_PARAMETER
);
1575 srclen
= strlenW(srcstr
)+1;
1577 /* FIXME: Both this function and it's companion LCMapStringA()
1578 * completely ignore the "lcid" parameter. In place of the "lcid"
1579 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
1580 * environment variable prior to invoking this function. */
1581 if (mapflags
& LCMAP_SORTKEY
)
1583 /* Possible values of LC_COLLATE. */
1584 char *lc_collate_default
= 0; /* value prior to this function */
1585 char *lc_collate_env
= 0; /* value retrieved from the environment */
1587 /* General purpose index into strings of any type. */
1590 /* Lengths of various strings where the length is measured in
1591 * wide characters for wide character strings and in bytes for
1592 * native strings. The lengths include the NULL terminator. */
1593 size_t returned_len
= 0;
1594 size_t src_native_len
= 0;
1595 size_t dst_native_len
= 0;
1596 size_t dststr_libc_len
= 0;
1598 /* Native (character set determined by locale) versions of the
1599 * strings source and destination strings. */
1600 LPSTR src_native
= 0;
1601 LPSTR dst_native
= 0;
1603 /* Version of the source and destination strings using the
1604 * "wchar_t" Unicode data type needed by various libc functions. */
1605 wchar_t *srcstr_libc
= 0;
1606 wchar_t *dststr_libc
= 0;
1608 if(!(srcstr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
1609 srclen
* sizeof(wchar_t))))
1611 ERR("Unable to allocate %d bytes for srcstr_libc\n",
1612 srclen
* sizeof(wchar_t));
1613 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1617 /* Convert source string to a libc Unicode string. */
1618 for(str_idx
= 0; str_idx
< srclen
; str_idx
++)
1620 srcstr_libc
[str_idx
] = srcstr
[str_idx
];
1623 /* src_native should contain at most 3 bytes for each
1624 * multibyte characters in the original srcstr string. */
1625 src_native_len
= 3 * srclen
;
1626 if(!(src_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
1629 ERR("Unable to allocate %d bytes for src_native\n", src_native_len
);
1630 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1631 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1635 /* FIXME: Prior to to setting the LC_COLLATE locale category the
1636 * current value is backed up so it can be restored after the
1637 * last LC_COLLATE sensitive function returns.
1639 * Even though the locale is adjusted for a minimum amount of
1640 * time a race condition exists where other threads may be
1641 * affected if they invoke LC_COLLATE sensitive functions. One
1642 * possible solution is to wrap all LC_COLLATE sensitive Wine
1643 * functions, like LCMapStringW(), in a mutex.
1645 * Another enhancement to the following would be to set the
1646 * LC_COLLATE locale category as a function of the "lcid"
1647 * parameter instead of the "LC_COLLATE" environment variable. */
1648 if(!(lc_collate_default
= setlocale(LC_COLLATE
, NULL
)))
1650 ERR("Unable to query the LC_COLLATE catagory\n");
1651 SetLastError(ERROR_INVALID_PARAMETER
);
1652 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1653 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1657 if(!(lc_collate_env
= setlocale(LC_COLLATE
, "")))
1659 ERR("Unable to inherit the LC_COLLATE locale category from the "
1660 "environment. The \"LC_COLLATE\" environment variable is "
1661 "\"%s\".\n", getenv("LC_COLLATE") ?
1662 getenv("LC_COLLATE") : "<unset>");
1663 SetLastError(ERROR_INVALID_PARAMETER
);
1664 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1665 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1669 TRACE("lc_collate_default = %s\n", lc_collate_default
);
1670 TRACE("lc_collate_env = %s\n", lc_collate_env
);
1672 /* Convert the libc Unicode string to a native multibyte character
1674 returned_len
= wcstombs(src_native
, srcstr_libc
, src_native_len
) + 1;
1675 if(returned_len
== 0)
1677 ERR("wcstombs failed. The string specified (%s) may contain an invalid character.\n",
1678 debugstr_w(srcstr
));
1679 SetLastError(ERROR_INVALID_PARAMETER
);
1680 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1681 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1682 setlocale(LC_COLLATE
, lc_collate_default
);
1685 else if(returned_len
> src_native_len
)
1687 src_native
[src_native_len
- 1] = 0;
1688 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
1689 "than expected (%d bytes).\n", src_native
, returned_len
,
1692 /* Since this is an internal error I'm not sure what the correct
1694 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1696 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1697 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1698 setlocale(LC_COLLATE
, lc_collate_default
);
1701 src_native_len
= returned_len
;
1703 TRACE("src_native = %s src_native_len = %d\n",
1704 src_native
, src_native_len
);
1706 /* dst_native seems to contain at most 4 bytes for each byte in
1707 * the original src_native string. Change if need be since this
1708 * isn't documented by the strxfrm() man page. */
1709 dst_native_len
= 4 * src_native_len
;
1710 if(!(dst_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, dst_native_len
)))
1712 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len
);
1713 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1714 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1715 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1716 setlocale(LC_COLLATE
, lc_collate_default
);
1720 /* The actual translation is done by the following call to
1721 * strxfrm(). The surrounding code could have been simplified
1722 * by calling wcsxfrm() instead except that wcsxfrm() is not
1723 * available on older Linux systems (RedHat 4.1 with
1726 * Also, it is possible that the translation could be done by
1727 * various tables as it is done in LCMapStringA(). However, I'm
1728 * not sure what those tables are. */
1729 returned_len
= strxfrm(dst_native
, src_native
, dst_native_len
) + 1;
1731 if(returned_len
> dst_native_len
)
1733 dst_native
[dst_native_len
- 1] = 0;
1734 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
1735 "than expected (%d bytes).\n", dst_native
, returned_len
,
1738 /* Since this is an internal error I'm not sure what the correct
1740 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1742 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1743 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1744 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1745 setlocale(LC_COLLATE
, lc_collate_default
);
1748 dst_native_len
= returned_len
;
1750 TRACE("dst_native = %s dst_native_len = %d\n",
1751 dst_native
, dst_native_len
);
1753 dststr_libc_len
= dst_native_len
;
1754 if(!(dststr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
1755 dststr_libc_len
* sizeof(wchar_t))))
1757 ERR("Unable to allocate %d bytes for dststr_libc\n",
1758 dststr_libc_len
* sizeof(wchar_t));
1759 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1760 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1761 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1762 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1763 setlocale(LC_COLLATE
, lc_collate_default
);
1767 /* Convert the native multibyte string to a libc Unicode string. */
1768 returned_len
= mbstowcs(dststr_libc
, dst_native
, dst_native_len
) + 1;
1770 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
1771 * function has returned. */
1772 setlocale(LC_COLLATE
, lc_collate_default
);
1774 if(returned_len
== 0)
1776 ERR("mbstowcs failed. The native version of the translated string "
1777 "(%s) may contain an invalid character.\n", dst_native
);
1778 SetLastError(ERROR_INVALID_PARAMETER
);
1779 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1780 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1781 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1782 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
1787 if(returned_len
> dstlen
)
1789 ERR("mbstowcs returned a string that was longer (%d chars) "
1790 "than the buffer provided (%d chars).\n", returned_len
,
1792 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1793 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1794 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1795 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1796 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
1799 dstlen
= returned_len
;
1801 /* Convert a libc Unicode string to the destination string. */
1802 for(str_idx
= 0; str_idx
< dstlen
; str_idx
++)
1804 dststr
[str_idx
] = dststr_libc
[str_idx
];
1806 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
1807 *(((int *)dststr
) + 0),
1808 *(((int *)dststr
) + 1),
1809 *(((int *)dststr
) + 2),
1810 *(((int *)dststr
) + 3));
1814 dstlen
= returned_len
;
1816 TRACE("dstlen (return) = %d\n", dstlen
);
1817 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1818 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1819 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1820 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
1825 int (*f
)(int)=identity
;
1831 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1835 if (mapflags
& LCMAP_UPPERCASE
)
1837 else if (mapflags
& LCMAP_LOWERCASE
)
1839 for (i
=0; i
< srclen
; i
++)
1840 dststr
[i
] = (WCHAR
) f(srcstr
[i
]);
1846 /***********************************************************************
1847 * OLE2NLS_EstimateMappingLength
1849 * Estimates the number of characters required to hold the string
1850 * computed by LCMapStringA.
1852 * The size is always over-estimated, with a fixed limit on the
1853 * amount of estimation error.
1855 * Note that len == -1 is not permitted.
1857 static inline int OLE2NLS_EstimateMappingLength(LCID lcid
, DWORD dwMapFlags
,
1858 LPCSTR str
, DWORD len
)
1860 /* Estimate only for small strings to keep the estimation error from
1861 * becoming too large. */
1862 if (len
< 128) return len
* 8 + 5;
1863 else return LCMapStringA(lcid
, dwMapFlags
, str
, len
, NULL
, 0);
1866 /******************************************************************************
1867 * CompareStringA [KERNEL32.@]
1868 * Compares two strings using locale
1872 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
1877 * Defaults to a word sort, but uses a string sort if
1878 * SORT_STRINGSORT is set.
1879 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
1883 * This implementation ignores the locale
1887 * Quite inefficient.
1889 int WINAPI
CompareStringA(
1890 LCID lcid
, /* [in] locale ID */
1891 DWORD fdwStyle
, /* [in] comparison-style options */
1892 LPCSTR s1
, /* [in] first string */
1893 int l1
, /* [in] length of first string */
1894 LPCSTR s2
, /* [in] second string */
1895 int l2
) /* [in] length of second string */
1897 int mapstring_flags
;
1901 TRACE("%s and %s\n",
1902 debugstr_an (s1
,l1
), debugstr_an (s2
,l2
));
1904 if ( (s1
==NULL
) || (s2
==NULL
) )
1906 ERR("(s1=%s,s2=%s): Invalid NULL string\n",
1907 debugstr_an(s1
,l1
), debugstr_an(s2
,l2
));
1908 SetLastError(ERROR_INVALID_PARAMETER
);
1912 if(fdwStyle
& NORM_IGNORESYMBOLS
)
1913 FIXME("IGNORESYMBOLS not supported\n");
1915 if (l1
== -1) l1
= strlen(s1
);
1916 if (l2
== -1) l2
= strlen(s2
);
1918 mapstring_flags
= LCMAP_SORTKEY
| fdwStyle
;
1919 len1
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s1
, l1
);
1920 len2
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s2
, l2
);
1922 if ((len1
==0)||(len2
==0))
1923 return 0; /* something wrong happened */
1925 sk1
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, len1
+ len2
);
1927 if ( (!LCMapStringA(lcid
,mapstring_flags
,s1
,l1
,sk1
,len1
))
1928 || (!LCMapStringA(lcid
,mapstring_flags
,s2
,l2
,sk2
,len2
)) )
1930 ERR("Bug in LCmapStringA.\n");
1935 /* strcmp doesn't necessarily return -1, 0, or 1 */
1936 result
= strcmp(sk1
,sk2
);
1938 HeapFree(GetProcessHeap(),0,sk1
);
1945 /* must be greater, if we reach this point */
1949 /******************************************************************************
1950 * CompareStringW [KERNEL32.@]
1951 * This implementation ignores the locale
1952 * FIXME : Does only string sort. Should
1953 * be reimplemented the same way as CompareStringA.
1955 int WINAPI
CompareStringW(LCID lcid
, DWORD fdwStyle
,
1956 LPCWSTR s1
, int l1
, LPCWSTR s2
, int l2
)
1959 if(fdwStyle
& NORM_IGNORENONSPACE
)
1960 FIXME("IGNORENONSPACE not supported\n");
1961 if(fdwStyle
& NORM_IGNORESYMBOLS
)
1962 FIXME("IGNORESYMBOLS not supported\n");
1964 /* Is strcmp defaulting to string sort or to word sort?? */
1965 /* FIXME: Handle NORM_STRINGSORT */
1966 l1
= (l1
==-1)?strlenW(s1
):l1
;
1967 l2
= (l2
==-1)?strlenW(s2
):l2
;
1968 len
= l1
<l2
? l1
:l2
;
1969 ret
= (fdwStyle
& NORM_IGNORECASE
) ? strncmpiW(s1
,s2
,len
) : strncmpW(s1
,s2
,len
);
1970 /* not equal, return 1 or 3 */
1972 /* need to translate result */
1973 return ((int)ret
< 0) ? 1 : 3;
1975 /* same len, return 2 */
1976 if(l1
==l2
) return 2;
1977 /* the longer one is lexically greater */
1978 return (l1
<l2
)? 1 : 3;
1981 /******************************************************************************
1982 * OLE_GetFormatA [Internal]
1985 * If datelen == 0, it should return the reguired string length.
1987 This function implements stuff for GetDateFormat() and
1990 d single-digit (no leading zero) day (of month)
1991 dd two-digit day (of month)
1992 ddd short day-of-week name
1993 dddd long day-of-week name
1994 M single-digit month
1996 MMM short month name
1997 MMMM full month name
1998 y two-digit year, no leading 0
2000 yyyy four-digit year
2002 h hours with no leading zero (12-hour)
2003 hh hours with full two digits
2004 H hours with no leading zero (24-hour)
2005 HH hours with full two digits
2006 m minutes with no leading zero
2007 mm minutes with full two digits
2008 s seconds with no leading zero
2009 ss seconds with full two digits
2010 t time marker (A or P)
2011 tt time marker (AM, PM)
2012 '' used to quote literal characters
2013 '' (within a quoted string) indicates a literal '
2015 These functions REQUIRE valid locale, date, and format.
2017 static INT
OLE_GetFormatA(LCID locale
,
2020 const SYSTEMTIME
* xtime
,
2021 LPCSTR _format
, /*in*/
2026 int count
, type
, inquote
, Overflow
;
2032 const char * _dgfmt
[] = { "%d", "%02d" };
2033 const char ** dgfmt
= _dgfmt
- 1;
2035 /* report, for debugging */
2036 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",
2037 locale
, flags
, tflags
,
2038 xtime
->wYear
,xtime
->wMonth
,xtime
->wDayOfWeek
,xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2039 _format
, _format
, date
, datelen
);
2042 FIXME("datelen = 0, returning 255\n");
2046 /* initalize state variables and output buffer */
2048 count
= 0; inquote
= 0; Overflow
= 0;
2050 date
[0] = buf
[0] = '\0';
2052 strcpy(format
,_format
);
2054 /* alter the formatstring, while it works for all languages now in wine
2055 its possible that it fails when the time looks like ss:mm:hh as example*/
2056 if (tflags
& (TIME_NOMINUTESORSECONDS
))
2057 { if ((pos
= strstr ( format
, ":mm")))
2058 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2061 if (tflags
& (TIME_NOSECONDS
))
2062 { if ((pos
= strstr ( format
, ":ss")))
2063 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2067 for (inpos
= 0;; inpos
++) {
2068 /* 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]); */
2070 if (format
[inpos
] == '\'') {
2071 if (format
[inpos
+1] == '\'') {
2073 date
[outpos
++] = '\'';
2076 continue; /* we did nothing to the output */
2078 } else if (format
[inpos
] == '\0') {
2079 date
[outpos
++] = '\0';
2080 if (outpos
> datelen
) Overflow
= 1;
2083 date
[outpos
++] = format
[inpos
];
2084 if (outpos
> datelen
) {
2086 date
[outpos
-1] = '\0'; /* this is the last place where
2087 it's safe to write */
2091 } else if ( (count
&& (format
[inpos
] != type
))
2093 || (count
== 2 && strchr("ghHmst", type
)) ) {
2094 if (type
== 'h' && (tflags
& TIME_FORCE24HOURFORMAT
)) type
= 'H';
2097 GetLocaleInfoA(locale
,
2099 + (xtime
->wDayOfWeek
+6)%7,
2101 } else if (count
== 3) {
2102 GetLocaleInfoA(locale
,
2103 LOCALE_SABBREVDAYNAME1
2104 + (xtime
->wDayOfWeek
+6)%7,
2107 sprintf(buf
, dgfmt
[count
], xtime
->wDay
);
2109 } else if (type
== 'M') {
2111 GetLocaleInfoA(locale
,
2112 LOCALE_SABBREVMONTHNAME1
2113 + xtime
->wMonth
- 1,
2115 } else if (count
== 4) {
2116 GetLocaleInfoA(locale
,
2118 + xtime
->wMonth
- 1,
2121 sprintf(buf
, dgfmt
[count
], xtime
->wMonth
);
2123 } else if (type
== 'y') {
2125 sprintf(buf
, "%d", xtime
->wYear
);
2126 } else if (count
== 3) {
2128 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2130 sprintf(buf
, dgfmt
[count
], xtime
->wYear
% 100);
2132 } else if (type
== 'g') {
2134 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2138 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2140 } else if (type
== 'h') {
2141 /* gives us hours 1:00 -- 12:00 */
2142 sprintf(buf
, dgfmt
[count
], (xtime
->wHour
-1)%12 +1);
2143 } else if (type
== 'H') {
2145 sprintf(buf
, dgfmt
[count
], xtime
->wHour
);
2146 } else if ( type
== 'm') {
2147 sprintf(buf
, dgfmt
[count
], xtime
->wMinute
);
2148 } else if ( type
== 's') {
2149 sprintf(buf
, dgfmt
[count
], xtime
->wSecond
);
2150 } else if (type
== 't') {
2151 if ((tflags
& TIME_NOTIMEMARKER
))
2153 else if (count
== 1) {
2154 sprintf(buf
, "%c", (xtime
->wHour
< 12) ? 'A' : 'P');
2155 } else if (count
== 2) {
2156 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2157 GetLocaleInfoA(locale
,
2159 ? LOCALE_S1159
: LOCALE_S2359
,
2164 /* we need to check the next char in the format string
2165 again, no matter what happened */
2168 /* add the contents of buf to the output */
2169 buflen
= strlen(buf
);
2170 if (outpos
+ buflen
< datelen
) {
2171 date
[outpos
] = '\0'; /* for strcat to hook onto */
2175 date
[outpos
] = '\0';
2176 strncat(date
, buf
, datelen
- outpos
);
2177 date
[datelen
- 1] = '\0';
2178 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2179 WARN("insufficient buffer\n");
2183 /* reset the variables we used to keep track of this item */
2186 } else if (format
[inpos
] == '\0') {
2187 /* we can't check for this at the loop-head, because
2188 that breaks the printing of the last format-item */
2189 date
[outpos
] = '\0';
2192 /* continuing a code for an item */
2195 } else if (strchr("hHmstyMdg", format
[inpos
])) {
2196 type
= format
[inpos
];
2199 } else if (format
[inpos
] == '\'') {
2203 date
[outpos
++] = format
[inpos
];
2205 /* now deal with a possible buffer overflow */
2206 if (outpos
>= datelen
) {
2207 date
[datelen
- 1] = '\0';
2208 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2214 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2217 /* finish it off with a string terminator */
2220 if (outpos
> datelen
-1) outpos
= datelen
-1;
2221 date
[outpos
] = '\0';
2223 TRACE("returns string '%s', len %d\n", date
, outpos
);
2227 /******************************************************************************
2228 * OLE_GetFormatW [INTERNAL]
2230 static INT
OLE_GetFormatW(LCID locale
, DWORD flags
, DWORD tflags
,
2231 const SYSTEMTIME
* xtime
,
2233 LPWSTR output
, INT outlen
)
2236 int count
, type
=0, inquote
;
2237 int Overflow
; /* loop check */
2241 WCHAR arg0
[] = {0}, arg1
[] = {'%','d',0};
2242 WCHAR arg2
[] = {'%','0','2','d',0};
2244 int datevars
=0, timevars
=0;
2250 /* make a debug report */
2251 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2252 "%p with max len %d\n",
2253 locale
, flags
, tflags
,
2254 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2255 debugstr_w(format
), format
, output
, outlen
);
2258 FIXME("outlen = 0, returning 255\n");
2262 /* initialize state variables */
2265 inquote
= Overflow
= 0;
2266 /* this is really just a sanity check */
2267 output
[0] = buf
[0] = 0;
2269 /* this loop is the core of the function */
2270 for (inpos
= 0; /* we have several break points */ ; inpos
++) {
2272 if (format
[inpos
] == (WCHAR
) '\'') {
2273 if (format
[inpos
+1] == '\'') {
2275 output
[outpos
++] = '\'';
2280 } else if (format
[inpos
] == 0) {
2281 output
[outpos
++] = 0;
2282 if (outpos
> outlen
) Overflow
= 1;
2283 break; /* normal exit (within a quote) */
2285 output
[outpos
++] = format
[inpos
]; /* copy input */
2286 if (outpos
> outlen
) {
2288 output
[outpos
-1] = 0;
2292 } else if ( (count
&& (format
[inpos
] != type
))
2293 || ( (count
==4 && type
=='y') ||
2294 (count
==4 && type
=='M') ||
2295 (count
==4 && type
=='d') ||
2296 (count
==2 && type
=='g') ||
2297 (count
==2 && type
=='h') ||
2298 (count
==2 && type
=='H') ||
2299 (count
==2 && type
=='m') ||
2300 (count
==2 && type
=='s') ||
2301 (count
==2 && type
=='t') ) ) {
2306 GetLocaleInfoW(locale
,
2307 LOCALE_SDAYNAME1
+ (xtime
->wDayOfWeek
+6)%7,
2308 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2309 } else if (count
== 3) {
2310 GetLocaleInfoW(locale
,
2311 LOCALE_SABBREVDAYNAME1
+
2312 (xtime
->wDayOfWeek
+6)%7,
2313 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2315 sprintf( tmp
, "%.*d", count
, xtime
->wDay
);
2316 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2322 GetLocaleInfoW(locale
, LOCALE_SMONTHNAME1
+
2323 xtime
->wMonth
-1, buf
,
2324 sizeof(buf
)/sizeof(WCHAR
) );
2325 } else if (count
== 3) {
2326 GetLocaleInfoW(locale
, LOCALE_SABBREVMONTHNAME1
+
2327 xtime
->wMonth
-1, buf
,
2328 sizeof(buf
)/sizeof(WCHAR
) );
2330 sprintf( tmp
, "%.*d", count
, xtime
->wMonth
);
2331 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2336 sprintf( tmp
, "%d", xtime
->wYear
);
2337 } else if (count
== 3) {
2338 strcpy( tmp
, "yyy" );
2340 sprintf( tmp
, "%.*d", count
, xtime
->wYear
% 100 );
2342 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2347 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2348 strcpy( tmp
, "AD" );
2350 /* Win API sez we copy it verbatim */
2353 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2357 /* hours 1:00-12:00 --- is this right? */
2358 sprintf( tmp
, "%.*d", count
, (xtime
->wHour
-1)%12 +1);
2359 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2363 sprintf( tmp
, "%.*d", count
, xtime
->wHour
);
2364 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2368 sprintf( tmp
, "%.*d", count
, xtime
->wMinute
);
2369 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2373 sprintf( tmp
, "%.*d", count
, xtime
->wSecond
);
2374 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2378 GetLocaleInfoW(locale
, (xtime
->wHour
< 12) ?
2379 LOCALE_S1159
: LOCALE_S2359
,
2387 /* no matter what happened, we need to check this next
2388 character the next time we loop through */
2391 /* cat buf onto the output */
2392 outlen
= strlenW(buf
);
2393 if (outpos
+ buflen
< outlen
) {
2394 strcpyW( output
+ outpos
, buf
);
2397 lstrcpynW( output
+ outpos
, buf
, outlen
- outpos
);
2399 break; /* Abnormal exit */
2402 /* reset the variables we used this time */
2405 } else if (format
[inpos
] == 0) {
2406 /* we can't check for this at the beginning, because that
2407 would keep us from printing a format spec that ended the
2410 break; /* NORMAL EXIT */
2412 /* how we keep track of the middle of a format spec */
2415 } else if ( (datevars
&& (format
[inpos
]=='d' ||
2416 format
[inpos
]=='M' ||
2417 format
[inpos
]=='y' ||
2418 format
[inpos
]=='g') ) ||
2419 (timevars
&& (format
[inpos
]=='H' ||
2420 format
[inpos
]=='h' ||
2421 format
[inpos
]=='m' ||
2422 format
[inpos
]=='s' ||
2423 format
[inpos
]=='t') ) ) {
2424 type
= format
[inpos
];
2427 } else if (format
[inpos
] == '\'') {
2431 /* unquoted literals */
2432 output
[outpos
++] = format
[inpos
];
2437 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2438 WARN(" buffer overflow\n");
2441 /* final string terminator and sanity check */
2443 if (outpos
> outlen
-1) outpos
= outlen
-1;
2444 output
[outpos
] = '0';
2446 TRACE(" returning %s\n", debugstr_w(output
));
2448 return (!Overflow
) ? outlen
: 0;
2453 /******************************************************************************
2454 * GetDateFormatA [KERNEL32.@]
2455 * Makes an ASCII string of the date
2457 * This function uses format to format the date, or, if format
2458 * is NULL, uses the default for the locale. format is a string
2459 * of literal fields and characters as follows:
2461 * - d single-digit (no leading zero) day (of month)
2462 * - dd two-digit day (of month)
2463 * - ddd short day-of-week name
2464 * - dddd long day-of-week name
2465 * - M single-digit month
2466 * - MM two-digit month
2467 * - MMM short month name
2468 * - MMMM full month name
2469 * - y two-digit year, no leading 0
2470 * - yy two-digit year
2471 * - yyyy four-digit year
2475 INT WINAPI
GetDateFormatA(LCID locale
,DWORD flags
,
2476 const SYSTEMTIME
* xtime
,
2477 LPCSTR format
, LPSTR date
,INT datelen
)
2480 char format_buf
[40];
2483 LPSYSTEMTIME thistime
;
2489 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2490 locale
,flags
,xtime
,format
,date
,datelen
);
2493 locale
= LOCALE_SYSTEM_DEFAULT
;
2496 if (locale
== LOCALE_SYSTEM_DEFAULT
) {
2497 thislocale
= GetSystemDefaultLCID();
2498 } else if (locale
== LOCALE_USER_DEFAULT
) {
2499 thislocale
= GetUserDefaultLCID();
2501 thislocale
= locale
;
2504 if (xtime
== NULL
) {
2507 /* Silently correct wDayOfWeek by transforming to FileTime and back again */
2508 res
=SystemTimeToFileTime(xtime
,&ft
);
2509 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error */
2510 /*FIXME: SystemTimeToFileTime doesn't yet do that check */
2513 SetLastError(ERROR_INVALID_PARAMETER
);
2516 FileTimeToSystemTime(&ft
,&t
);
2521 if (format
== NULL
) {
2522 GetLocaleInfoA(thislocale
, ((flags
&DATE_LONGDATE
)
2524 : LOCALE_SSHORTDATE
),
2525 format_buf
, sizeof(format_buf
));
2526 thisformat
= format_buf
;
2528 thisformat
= format
;
2532 ret
= OLE_GetFormatA(thislocale
, flags
, 0, thistime
, thisformat
,
2537 "GetDateFormatA() returning %d, with data=%s\n",
2542 /******************************************************************************
2543 * GetDateFormatW [KERNEL32.@]
2544 * Makes a Unicode string of the date
2546 * Acts the same as GetDateFormatA(), except that it's Unicode.
2547 * Accepts & returns sizes as counts of Unicode characters.
2550 INT WINAPI
GetDateFormatW(LCID locale
,DWORD flags
,
2551 const SYSTEMTIME
* xtime
,
2553 LPWSTR date
, INT datelen
)
2555 unsigned short datearr
[] = {'1','9','9','4','-','1','-','1',0};
2557 FIXME("STUB (should call OLE_GetFormatW)\n");
2558 lstrcpynW(date
, datearr
, datelen
);
2559 return ( datelen
< 9) ? datelen
: 9;
2564 /**************************************************************************
2565 * EnumDateFormatsA (KERNEL32.@)
2567 BOOL WINAPI
EnumDateFormatsA(
2568 DATEFMT_ENUMPROCA lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2570 LCID Loc
= GetUserDefaultLCID();
2571 if(!lpDateFmtEnumProc
)
2573 SetLastError(ERROR_INVALID_PARAMETER
);
2580 case 0x00000407: /* (Loc,"de_DE") */
2584 case DATE_SHORTDATE
:
2585 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
2586 if(!(*lpDateFmtEnumProc
)("d.M.yyyy")) return TRUE
;
2587 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
2588 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2591 if(!(*lpDateFmtEnumProc
)("dddd,d. MMMM yyyy")) return TRUE
;
2592 if(!(*lpDateFmtEnumProc
)("d. MMMM yyyy")) return TRUE
;
2593 if(!(*lpDateFmtEnumProc
)("d. MMM yyyy")) return TRUE
;
2596 FIXME("Unknown date format (%ld)\n", dwFlags
);
2597 SetLastError(ERROR_INVALID_PARAMETER
);
2602 case 0x0000040c: /* (Loc,"fr_FR") */
2606 case DATE_SHORTDATE
:
2607 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2608 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
2609 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
2610 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2613 if(!(*lpDateFmtEnumProc
)("dddd d MMMM yyyy")) return TRUE
;
2614 if(!(*lpDateFmtEnumProc
)("d MMM yy")) return TRUE
;
2615 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2618 FIXME("Unknown date format (%ld)\n", dwFlags
);
2619 SetLastError(ERROR_INVALID_PARAMETER
);
2624 case 0x00000c0c: /* (Loc,"fr_CA") */
2628 case DATE_SHORTDATE
:
2629 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
2630 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
2631 if(!(*lpDateFmtEnumProc
)("yy MM dd")) return TRUE
;
2632 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2635 if(!(*lpDateFmtEnumProc
)("d MMMM, yyyy")) return TRUE
;
2636 if(!(*lpDateFmtEnumProc
)("d MMM yyyy")) return TRUE
;
2639 FIXME("Unknown date format (%ld)\n", dwFlags
);
2640 SetLastError(ERROR_INVALID_PARAMETER
);
2645 case 0x00000809: /* (Loc,"en_UK") */
2649 case DATE_SHORTDATE
:
2650 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2651 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2652 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2653 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2656 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
2657 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2660 FIXME("Unknown date format (%ld)\n", dwFlags
);
2661 SetLastError(ERROR_INVALID_PARAMETER
);
2666 case 0x00000c09: /* (Loc,"en_AU") */
2670 case DATE_SHORTDATE
:
2671 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
2672 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2673 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2676 if(!(*lpDateFmtEnumProc
)("dddd,d MMMM yyyy")) return TRUE
;
2677 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2680 FIXME("Unknown date format (%ld)\n", dwFlags
);
2681 SetLastError(ERROR_INVALID_PARAMETER
);
2686 case 0x00001009: /* (Loc,"en_CA") */
2690 case DATE_SHORTDATE
:
2691 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2692 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2693 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
2694 if(!(*lpDateFmtEnumProc
)("M/dd/yy")) return TRUE
;
2697 if(!(*lpDateFmtEnumProc
)("d-MMM-yy")) return TRUE
;
2698 if(!(*lpDateFmtEnumProc
)("MMMM d, yyyy")) return TRUE
;
2701 FIXME("Unknown date format (%ld)\n", dwFlags
);
2702 SetLastError(ERROR_INVALID_PARAMETER
);
2707 case 0x00001409: /* (Loc,"en_NZ") */
2711 case DATE_SHORTDATE
:
2712 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
2713 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2714 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
2717 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2718 if(!(*lpDateFmtEnumProc
)("dddd, d MMMM yyyy")) return TRUE
;
2721 FIXME("Unknown date format (%ld)\n", dwFlags
);
2722 SetLastError(ERROR_INVALID_PARAMETER
);
2727 case 0x00001809: /* (Loc,"en_IE") */
2731 case DATE_SHORTDATE
:
2732 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2733 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2734 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2737 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
2738 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2741 FIXME("Unknown date format (%ld)\n", dwFlags
);
2742 SetLastError(ERROR_INVALID_PARAMETER
);
2747 case 0x00001c09: /* (Loc,"en_ZA") */
2751 case DATE_SHORTDATE
:
2752 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
2755 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
2758 FIXME("Unknown date format (%ld)\n", dwFlags
);
2759 SetLastError(ERROR_INVALID_PARAMETER
);
2764 case 0x00002009: /* (Loc,"en_JM") */
2768 case DATE_SHORTDATE
:
2769 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2772 if(!(*lpDateFmtEnumProc
)("dddd,MMMM dd,yyyy")) return TRUE
;
2773 if(!(*lpDateFmtEnumProc
)("MMMM dd,yyyy")) return TRUE
;
2774 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM,yyyy")) return TRUE
;
2775 if(!(*lpDateFmtEnumProc
)("dd MMMM,yyyy")) return TRUE
;
2778 FIXME("Unknown date format (%ld)\n", dwFlags
);
2779 SetLastError(ERROR_INVALID_PARAMETER
);
2784 case 0x00002809: /* (Loc,"en_BZ") */
2785 case 0x00002c09: /* (Loc,"en_TT") */
2789 case DATE_SHORTDATE
:
2790 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2793 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM yyyy")) return TRUE
;
2796 FIXME("Unknown date format (%ld)\n", dwFlags
);
2797 SetLastError(ERROR_INVALID_PARAMETER
);
2802 default: /* default to US English "en_US" */
2806 case DATE_SHORTDATE
:
2807 if(!(*lpDateFmtEnumProc
)("M/d/yy")) return TRUE
;
2808 if(!(*lpDateFmtEnumProc
)("M/d/yyyy")) return TRUE
;
2809 if(!(*lpDateFmtEnumProc
)("MM/dd/yy")) return TRUE
;
2810 if(!(*lpDateFmtEnumProc
)("MM/dd/yyyy")) return TRUE
;
2811 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
2812 if(!(*lpDateFmtEnumProc
)("dd-MMM-yy")) return TRUE
;
2815 if(!(*lpDateFmtEnumProc
)("dddd, MMMM dd, yyyy")) return TRUE
;
2816 if(!(*lpDateFmtEnumProc
)("MMMM dd, yyyy")) return TRUE
;
2817 if(!(*lpDateFmtEnumProc
)("dddd, dd MMMM, yyyy")) return TRUE
;
2818 if(!(*lpDateFmtEnumProc
)("dd MMMM, yyyy")) return TRUE
;
2821 FIXME("Unknown date format (%ld)\n", dwFlags
);
2822 SetLastError(ERROR_INVALID_PARAMETER
);
2829 /**************************************************************************
2830 * EnumDateFormatsW (KERNEL32.@)
2832 BOOL WINAPI
EnumDateFormatsW(
2833 DATEFMT_ENUMPROCW lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2835 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc
, Locale
, dwFlags
);
2836 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2840 /**************************************************************************
2841 * EnumTimeFormatsA (KERNEL32.@)
2843 BOOL WINAPI
EnumTimeFormatsA(
2844 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2846 LCID Loc
= GetUserDefaultLCID();
2847 if(!lpTimeFmtEnumProc
)
2849 SetLastError(ERROR_INVALID_PARAMETER
);
2854 FIXME("Unknown time format (%ld)\n", dwFlags
);
2859 case 0x00000407: /* (Loc,"de_DE") */
2861 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
2862 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2863 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2864 if(!(*lpTimeFmtEnumProc
)("H.mm")) return TRUE
;
2865 if(!(*lpTimeFmtEnumProc
)("H.mm'Uhr'")) return TRUE
;
2869 case 0x0000040c: /* (Loc,"fr_FR") */
2870 case 0x00000c0c: /* (Loc,"fr_CA") */
2872 if(!(*lpTimeFmtEnumProc
)("H:mm")) return TRUE
;
2873 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2874 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2875 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
2876 if(!(*lpTimeFmtEnumProc
)("HH'h'mm")) return TRUE
;
2880 case 0x00000809: /* (Loc,"en_UK") */
2881 case 0x00000c09: /* (Loc,"en_AU") */
2882 case 0x00001409: /* (Loc,"en_NZ") */
2883 case 0x00001809: /* (Loc,"en_IE") */
2885 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
2886 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2887 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2891 case 0x00001c09: /* (Loc,"en_ZA") */
2892 case 0x00002809: /* (Loc,"en_BZ") */
2893 case 0x00002c09: /* (Loc,"en_TT") */
2895 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
2896 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
2900 default: /* default to US style "en_US" */
2902 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
2903 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
2904 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2905 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2911 /**************************************************************************
2912 * EnumTimeFormatsW (KERNEL32.@)
2914 BOOL WINAPI
EnumTimeFormatsW(
2915 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2917 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc
, Locale
, dwFlags
);
2918 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2922 /**************************************************************************
2923 * This function is used just locally !
2924 * Description: Inverts a string.
2926 static void OLE_InvertString(char* string
)
2928 char sTmpArray
[128];
2931 for (counter
= strlen(string
); counter
> 0; counter
--)
2933 memcpy(sTmpArray
+ i
, string
+ counter
-1, 1);
2936 memcpy(sTmpArray
+ i
, "\0", 1);
2937 strcpy(string
, sTmpArray
);
2940 /***************************************************************************************
2941 * This function is used just locally !
2942 * Description: Test if the given string (psNumber) is valid or not.
2943 * The valid characters are the following:
2944 * - Characters '0' through '9'.
2945 * - One decimal point (dot) if the number is a floating-point value.
2946 * - A minus sign in the first character position if the number is
2948 * If the function succeeds, psBefore/psAfter will point to the string
2949 * on the right/left of the decimal symbol. pbNegative indicates if the
2950 * number is negative.
2952 static INT
OLE_GetNumberComponents(char* pInput
, char* psBefore
, char* psAfter
, BOOL
* pbNegative
)
2954 char sNumberSet
[] = "0123456789";
2955 BOOL bInDecimal
= FALSE
;
2957 /* Test if we do have a minus sign */
2958 if ( *pInput
== '-' )
2961 pInput
++; /* Jump to the next character. */
2964 while(*pInput
!= '\0')
2966 /* Do we have a valid numeric character */
2967 if ( strchr(sNumberSet
, *pInput
) != NULL
)
2969 if (bInDecimal
== TRUE
)
2970 *psAfter
++ = *pInput
;
2972 *psBefore
++ = *pInput
;
2976 /* Is this a decimal point (dot) */
2977 if ( *pInput
== '.' )
2979 /* Is it the first time we find it */
2980 if ((bInDecimal
== FALSE
))
2983 return -1; /* ERROR: Invalid parameter */
2987 /* It's neither a numeric character, nor a decimal point.
2988 * Thus, return an error.
2996 /* Add an End of Line character to the output buffers */
3003 /**************************************************************************
3004 * This function is used just locally !
3005 * Description: A number could be formatted using different numbers
3006 * of "digits in group" (example: 4;3;2;0).
3007 * The first parameter of this function is an array
3008 * containing the rule to be used. Its format is the following:
3009 * |NDG|DG1|DG2|...|0|
3010 * where NDG is the number of used "digits in group" and DG1, DG2,
3011 * are the corresponding "digits in group".
3012 * Thus, this function returns the grouping value in the array
3013 * pointed by the second parameter.
3015 static INT
OLE_GetGrouping(char* sRule
, INT index
)
3017 char sData
[2], sRuleSize
[2];
3018 INT nData
, nRuleSize
;
3020 memcpy(sRuleSize
, sRule
, 1);
3021 memcpy(sRuleSize
+1, "\0", 1);
3022 nRuleSize
= atoi(sRuleSize
);
3024 if (index
> 0 && index
< nRuleSize
)
3026 memcpy(sData
, sRule
+index
, 1);
3027 memcpy(sData
+1, "\0", 1);
3028 nData
= atoi(sData
);
3033 memcpy(sData
, sRule
+nRuleSize
-1, 1);
3034 memcpy(sData
+1, "\0", 1);
3035 nData
= atoi(sData
);
3041 /**************************************************************************
3042 * GetNumberFormatA (KERNEL32.@)
3044 INT WINAPI
GetNumberFormatA(LCID locale
, DWORD dwflags
,
3045 LPCSTR lpvalue
, const NUMBERFMTA
* lpFormat
,
3046 LPSTR lpNumberStr
, int cchNumber
)
3048 char sNumberDigits
[3], sDecimalSymbol
[5], sDigitsInGroup
[11], sDigitGroupSymbol
[5], sILZero
[2];
3049 INT nNumberDigits
, nNumberDecimal
, i
, j
, nCounter
, nStep
, nRuleIndex
, nGrouping
, nDigits
, retVal
, nLZ
;
3050 char sNumber
[128], sDestination
[128], sDigitsAfterDecimal
[10], sDigitsBeforeDecimal
[128];
3051 char sRule
[10], sSemiColumn
[]=";", sBuffer
[5], sNegNumber
[2];
3052 char *pStr
= NULL
, *pTmpStr
= NULL
;
3053 LCID systemDefaultLCID
;
3054 BOOL bNegative
= FALSE
;
3063 strncpy(sNumber
, lpvalue
, 128);
3064 sNumber
[127] = '\0';
3066 /* Make sure we have a valid input string, get the number
3067 * of digits before and after the decimal symbol, and check
3068 * if this is a negative number.
3070 if ( OLE_GetNumberComponents(sNumber
, sDigitsBeforeDecimal
, sDigitsAfterDecimal
, &bNegative
) != -1)
3072 nNumberDecimal
= strlen(sDigitsBeforeDecimal
);
3073 nDigits
= strlen(sDigitsAfterDecimal
);
3077 SetLastError(ERROR_INVALID_PARAMETER
);
3081 /* Which source will we use to format the string */
3082 used_operation
= RETURN_ERROR
;
3083 if (lpFormat
!= NULL
)
3086 used_operation
= USE_PARAMETER
;
3090 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3091 used_operation
= USE_LOCALEINFO
;
3093 used_operation
= USE_SYSTEMDEFAULT
;
3096 /* Load the fields we need */
3097 switch(used_operation
)
3099 case USE_LOCALEINFO
:
3100 GetLocaleInfoA(locale
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3101 GetLocaleInfoA(locale
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3102 GetLocaleInfoA(locale
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3103 GetLocaleInfoA(locale
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3104 GetLocaleInfoA(locale
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3105 GetLocaleInfoA(locale
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3108 sprintf(sNumberDigits
, "%d",lpFormat
->NumDigits
);
3109 strcpy(sDecimalSymbol
, lpFormat
->lpDecimalSep
);
3110 sprintf(sDigitsInGroup
, "%d;0",lpFormat
->Grouping
);
3111 strcpy(sDigitGroupSymbol
, lpFormat
->lpThousandSep
);
3112 sprintf(sILZero
, "%d",lpFormat
->LeadingZero
);
3113 sprintf(sNegNumber
, "%d",lpFormat
->NegativeOrder
);
3115 case USE_SYSTEMDEFAULT
:
3116 systemDefaultLCID
= GetSystemDefaultLCID();
3117 GetLocaleInfoA(systemDefaultLCID
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3118 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3119 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3120 GetLocaleInfoA(systemDefaultLCID
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3121 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3122 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3125 SetLastError(ERROR_INVALID_PARAMETER
);
3129 nNumberDigits
= atoi(sNumberDigits
);
3131 /* Remove the ";" */
3134 for (nCounter
=0; nCounter
<strlen(sDigitsInGroup
); nCounter
++)
3136 if ( memcmp(sDigitsInGroup
+ nCounter
, sSemiColumn
, 1) != 0 )
3138 memcpy(sRule
+ j
, sDigitsInGroup
+ nCounter
, 1);
3143 sprintf(sBuffer
, "%d", i
);
3144 memcpy(sRule
, sBuffer
, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3145 memcpy(sRule
+ j
, "\0", 1);
3147 /* First, format the digits before the decimal. */
3148 if ((nNumberDecimal
>0) && (atoi(sDigitsBeforeDecimal
) != 0))
3150 /* Working on an inverted string is easier ! */
3151 OLE_InvertString(sDigitsBeforeDecimal
);
3153 nStep
= nCounter
= i
= j
= 0;
3155 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3157 /* Here, we will loop until we reach the end of the string.
3158 * An internal counter (j) is used in order to know when to
3159 * insert the "digit group symbol".
3161 while (nNumberDecimal
> 0)
3163 i
= nCounter
+ nStep
;
3164 memcpy(sDestination
+ i
, sDigitsBeforeDecimal
+ nCounter
, 1);
3170 if (nRuleIndex
< sRule
[0])
3172 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3173 memcpy(sDestination
+ i
+1, sDigitGroupSymbol
, strlen(sDigitGroupSymbol
));
3174 nStep
+= strlen(sDigitGroupSymbol
);
3180 memcpy(sDestination
+ i
+1, "\0", 1);
3181 /* Get the string in the right order ! */
3182 OLE_InvertString(sDestination
);
3186 nLZ
= atoi(sILZero
);
3189 /* Use 0.xxx instead of .xxx */
3190 memcpy(sDestination
, "0", 1);
3191 memcpy(sDestination
+1, "\0", 1);
3194 memcpy(sDestination
, "\0", 1);
3198 /* Second, format the digits after the decimal. */
3200 nCounter
= nNumberDigits
;
3201 if ( (nDigits
>0) && (pStr
= strstr (sNumber
, ".")) )
3203 i
= strlen(sNumber
) - strlen(pStr
) + 1;
3204 strncpy ( sDigitsAfterDecimal
, sNumber
+ i
, nNumberDigits
);
3205 j
= strlen(sDigitsAfterDecimal
);
3206 if (j
< nNumberDigits
)
3207 nCounter
= nNumberDigits
-j
;
3209 for (i
=0;i
<nCounter
;i
++)
3210 memcpy(sDigitsAfterDecimal
+i
+j
, "0", 1);
3211 memcpy(sDigitsAfterDecimal
+ nNumberDigits
, "\0", 1);
3213 i
= strlen(sDestination
);
3214 j
= strlen(sDigitsAfterDecimal
);
3215 /* Finally, construct the resulting formatted string. */
3217 for (nCounter
=0; nCounter
<i
; nCounter
++)
3218 memcpy(sNumber
+ nCounter
, sDestination
+ nCounter
, 1);
3220 memcpy(sNumber
+ nCounter
, sDecimalSymbol
, strlen(sDecimalSymbol
));
3223 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), sDigitsAfterDecimal
+ i
, 1);
3224 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), "\0", 1);
3226 /* Is it a negative number */
3227 if (bNegative
== TRUE
)
3229 i
= atoi(sNegNumber
);
3230 pStr
= sDestination
;
3236 while (*sNumber
!= '\0')
3237 *pStr
++ = *pTmpStr
++;
3242 while (*pTmpStr
!= '\0')
3243 *pStr
++ = *pTmpStr
++;
3248 while (*pTmpStr
!= '\0')
3249 *pStr
++ = *pTmpStr
++;
3252 while (*pTmpStr
!= '\0')
3253 *pStr
++ = *pTmpStr
++;
3257 while (*pTmpStr
!= '\0')
3258 *pStr
++ = *pTmpStr
++;
3263 while (*pTmpStr
!= '\0')
3264 *pStr
++ = *pTmpStr
++;
3269 strcpy(sDestination
, sNumber
);
3271 /* If cchNumber is zero, then returns the number of bytes or characters
3272 * required to hold the formatted number string
3275 retVal
= strlen(sDestination
) + 1;
3278 strncpy (lpNumberStr
, sDestination
, cchNumber
-1);
3279 *(lpNumberStr
+cchNumber
-1) = '\0'; /* ensure we got a NULL at the end */
3280 retVal
= strlen(lpNumberStr
);
3286 /**************************************************************************
3287 * GetNumberFormatW (KERNEL32.@)
3289 INT WINAPI
GetNumberFormatW(LCID locale
, DWORD dwflags
,
3290 LPCWSTR lpvalue
, const NUMBERFMTW
* lpFormat
,
3291 LPWSTR lpNumberStr
, int cchNumber
)
3293 FIXME("%s: stub, no reformatting done\n",debugstr_w(lpvalue
));
3295 lstrcpynW( lpNumberStr
, lpvalue
, cchNumber
);
3296 return cchNumber
? strlenW( lpNumberStr
) : 0;
3299 /**************************************************************************
3300 * GetCurrencyFormatA (KERNEL32.@)
3302 INT WINAPI
GetCurrencyFormatA(LCID locale
, DWORD dwflags
,
3303 LPCSTR lpvalue
, const CURRENCYFMTA
* lpFormat
,
3304 LPSTR lpCurrencyStr
, int cchCurrency
)
3306 UINT nPosOrder
, nNegOrder
;
3308 char sDestination
[128], sNegOrder
[8], sPosOrder
[8], sCurrencySymbol
[8];
3309 char *pDestination
= sDestination
;
3310 char sNumberFormated
[128];
3311 char *pNumberFormated
= sNumberFormated
;
3312 LCID systemDefaultLCID
;
3313 BOOL bIsPositive
= FALSE
, bValidFormat
= FALSE
;
3322 NUMBERFMTA numberFmt
;
3324 /* Which source will we use to format the string */
3325 used_operation
= RETURN_ERROR
;
3326 if (lpFormat
!= NULL
)
3329 used_operation
= USE_PARAMETER
;
3333 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3334 used_operation
= USE_LOCALEINFO
;
3336 used_operation
= USE_SYSTEMDEFAULT
;
3339 /* Load the fields we need */
3340 switch(used_operation
)
3342 case USE_LOCALEINFO
:
3343 /* Specific to CURRENCYFMTA */
3344 GetLocaleInfoA(locale
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3345 GetLocaleInfoA(locale
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3346 GetLocaleInfoA(locale
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3348 nPosOrder
= atoi(sPosOrder
);
3349 nNegOrder
= atoi(sNegOrder
);
3352 /* Specific to CURRENCYFMTA */
3353 nNegOrder
= lpFormat
->NegativeOrder
;
3354 nPosOrder
= lpFormat
->PositiveOrder
;
3355 strcpy(sCurrencySymbol
, lpFormat
->lpCurrencySymbol
);
3357 case USE_SYSTEMDEFAULT
:
3358 systemDefaultLCID
= GetSystemDefaultLCID();
3359 /* Specific to CURRENCYFMTA */
3360 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3361 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3362 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3364 nPosOrder
= atoi(sPosOrder
);
3365 nNegOrder
= atoi(sNegOrder
);
3368 SetLastError(ERROR_INVALID_PARAMETER
);
3372 /* Construct a temporary number format structure */
3373 if (lpFormat
!= NULL
)
3375 numberFmt
.NumDigits
= lpFormat
->NumDigits
;
3376 numberFmt
.LeadingZero
= lpFormat
->LeadingZero
;
3377 numberFmt
.Grouping
= lpFormat
->Grouping
;
3378 numberFmt
.NegativeOrder
= 0;
3379 numberFmt
.lpDecimalSep
= lpFormat
->lpDecimalSep
;
3380 numberFmt
.lpThousandSep
= lpFormat
->lpThousandSep
;
3381 bValidFormat
= TRUE
;
3384 /* Make a call to GetNumberFormatA() */
3385 if (*lpvalue
== '-')
3387 bIsPositive
= FALSE
;
3388 retVal
= GetNumberFormatA(locale
,0,lpvalue
+1,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3393 retVal
= GetNumberFormatA(locale
,0,lpvalue
,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3399 /* construct the formatted string */
3404 case 0: /* Prefix, no separation */
3405 strcpy (pDestination
, sCurrencySymbol
);
3406 strcat (pDestination
, pNumberFormated
);
3408 case 1: /* Suffix, no separation */
3409 strcpy (pDestination
, pNumberFormated
);
3410 strcat (pDestination
, sCurrencySymbol
);
3412 case 2: /* Prefix, 1 char separation */
3413 strcpy (pDestination
, sCurrencySymbol
);
3414 strcat (pDestination
, " ");
3415 strcat (pDestination
, pNumberFormated
);
3417 case 3: /* Suffix, 1 char separation */
3418 strcpy (pDestination
, pNumberFormated
);
3419 strcat (pDestination
, " ");
3420 strcat (pDestination
, sCurrencySymbol
);
3423 SetLastError(ERROR_INVALID_PARAMETER
);
3427 else /* negative number */
3431 case 0: /* format: ($1.1) */
3432 strcpy (pDestination
, "(");
3433 strcat (pDestination
, sCurrencySymbol
);
3434 strcat (pDestination
, pNumberFormated
);
3435 strcat (pDestination
, ")");
3437 case 1: /* format: -$1.1 */
3438 strcpy (pDestination
, "-");
3439 strcat (pDestination
, sCurrencySymbol
);
3440 strcat (pDestination
, pNumberFormated
);
3442 case 2: /* format: $-1.1 */
3443 strcpy (pDestination
, sCurrencySymbol
);
3444 strcat (pDestination
, "-");
3445 strcat (pDestination
, pNumberFormated
);
3447 case 3: /* format: $1.1- */
3448 strcpy (pDestination
, sCurrencySymbol
);
3449 strcat (pDestination
, pNumberFormated
);
3450 strcat (pDestination
, "-");
3452 case 4: /* format: (1.1$) */
3453 strcpy (pDestination
, "(");
3454 strcat (pDestination
, pNumberFormated
);
3455 strcat (pDestination
, sCurrencySymbol
);
3456 strcat (pDestination
, ")");
3458 case 5: /* format: -1.1$ */
3459 strcpy (pDestination
, "-");
3460 strcat (pDestination
, pNumberFormated
);
3461 strcat (pDestination
, sCurrencySymbol
);
3463 case 6: /* format: 1.1-$ */
3464 strcpy (pDestination
, pNumberFormated
);
3465 strcat (pDestination
, "-");
3466 strcat (pDestination
, sCurrencySymbol
);
3468 case 7: /* format: 1.1$- */
3469 strcpy (pDestination
, pNumberFormated
);
3470 strcat (pDestination
, sCurrencySymbol
);
3471 strcat (pDestination
, "-");
3473 case 8: /* format: -1.1 $ */
3474 strcpy (pDestination
, "-");
3475 strcat (pDestination
, pNumberFormated
);
3476 strcat (pDestination
, " ");
3477 strcat (pDestination
, sCurrencySymbol
);
3479 case 9: /* format: -$ 1.1 */
3480 strcpy (pDestination
, "-");
3481 strcat (pDestination
, sCurrencySymbol
);
3482 strcat (pDestination
, " ");
3483 strcat (pDestination
, pNumberFormated
);
3485 case 10: /* format: 1.1 $- */
3486 strcpy (pDestination
, pNumberFormated
);
3487 strcat (pDestination
, " ");
3488 strcat (pDestination
, sCurrencySymbol
);
3489 strcat (pDestination
, "-");
3491 case 11: /* format: $ 1.1- */
3492 strcpy (pDestination
, sCurrencySymbol
);
3493 strcat (pDestination
, " ");
3494 strcat (pDestination
, pNumberFormated
);
3495 strcat (pDestination
, "-");
3497 case 12: /* format: $ -1.1 */
3498 strcpy (pDestination
, sCurrencySymbol
);
3499 strcat (pDestination
, " ");
3500 strcat (pDestination
, "-");
3501 strcat (pDestination
, pNumberFormated
);
3503 case 13: /* format: 1.1- $ */
3504 strcpy (pDestination
, pNumberFormated
);
3505 strcat (pDestination
, "-");
3506 strcat (pDestination
, " ");
3507 strcat (pDestination
, sCurrencySymbol
);
3509 case 14: /* format: ($ 1.1) */
3510 strcpy (pDestination
, "(");
3511 strcat (pDestination
, sCurrencySymbol
);
3512 strcat (pDestination
, " ");
3513 strcat (pDestination
, pNumberFormated
);
3514 strcat (pDestination
, ")");
3516 case 15: /* format: (1.1 $) */
3517 strcpy (pDestination
, "(");
3518 strcat (pDestination
, pNumberFormated
);
3519 strcat (pDestination
, " ");
3520 strcat (pDestination
, sCurrencySymbol
);
3521 strcat (pDestination
, ")");
3524 SetLastError(ERROR_INVALID_PARAMETER
);
3529 if (cchCurrency
== 0)
3530 return strlen(pDestination
) + 1;
3534 strncpy (lpCurrencyStr
, pDestination
, cchCurrency
-1);
3535 *(lpCurrencyStr
+cchCurrency
-1) = '\0'; /* ensure we got a NULL at the end */
3536 return strlen(lpCurrencyStr
);
3540 /**************************************************************************
3541 * GetCurrencyFormatW (KERNEL32.@)
3543 INT WINAPI
GetCurrencyFormatW(LCID locale
, DWORD dwflags
,
3544 LPCWSTR lpvalue
, const CURRENCYFMTW
* lpFormat
,
3545 LPWSTR lpCurrencyStr
, int cchCurrency
)
3547 FIXME("This API function is NOT implemented !\n");
3551 /******************************************************************************
3552 * OLE2NLS_CheckLocale [intern]
3554 static LCID
OLE2NLS_CheckLocale (LCID locale
)
3557 { locale
= LOCALE_SYSTEM_DEFAULT
;
3560 if (locale
== LOCALE_SYSTEM_DEFAULT
)
3561 { return GetSystemDefaultLCID();
3563 else if (locale
== LOCALE_USER_DEFAULT
)
3564 { return GetUserDefaultLCID();
3570 /******************************************************************************
3571 * GetTimeFormatA [KERNEL32.@]
3572 * Makes an ASCII string of the time
3574 * Formats date according to format, or locale default if format is
3575 * NULL. The format consists of literal characters and fields as follows:
3577 * h hours with no leading zero (12-hour)
3578 * hh hours with full two digits
3579 * H hours with no leading zero (24-hour)
3580 * HH hours with full two digits
3581 * m minutes with no leading zero
3582 * mm minutes with full two digits
3583 * s seconds with no leading zero
3584 * ss seconds with full two digits
3585 * t time marker (A or P)
3586 * tt time marker (AM, PM)
3590 GetTimeFormatA(LCID locale
, /* [in] */
3591 DWORD flags
, /* [in] */
3592 const SYSTEMTIME
* xtime
, /* [in] */
3593 LPCSTR format
, /* [in] */
3594 LPSTR timestr
, /* [out] */
3595 INT timelen
/* [in] */)
3596 { char format_buf
[40];
3599 const SYSTEMTIME
* thistime
;
3601 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standard timeformat */
3604 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,xtime
,format
,timestr
,timelen
);
3606 thislocale
= OLE2NLS_CheckLocale ( locale
);
3609 { if (flags
& LOCALE_NOUSEROVERRIDE
) /* use system default */
3610 { thislocale
= GetSystemDefaultLCID();
3612 GetLocaleInfoA(thislocale
, thisflags
, format_buf
, sizeof(format_buf
));
3613 thisformat
= format_buf
;
3616 { thisformat
= format
;
3619 if (xtime
== NULL
) /* NULL means use the current local time */
3625 /* Check that hour,min and sec is in range */
3627 ret
= OLE_GetFormatA(thislocale
, thisflags
, flags
, thistime
, thisformat
,
3633 /******************************************************************************
3634 * GetTimeFormatW [KERNEL32.@]
3635 * Makes a Unicode string of the time
3638 GetTimeFormatW(LCID locale
, /* [in] */
3639 DWORD flags
, /* [in] */
3640 const SYSTEMTIME
* xtime
, /* [in] */
3641 LPCWSTR format
, /* [in] */
3642 LPWSTR timestr
, /* [out] */
3643 INT timelen
/* [in] */)
3644 { WCHAR format_buf
[40];
3647 const SYSTEMTIME
* thistime
;
3649 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standard timeformat */
3652 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,
3653 xtime
,debugstr_w(format
),timestr
,timelen
);
3655 thislocale
= OLE2NLS_CheckLocale ( locale
);
3658 { if (flags
& LOCALE_NOUSEROVERRIDE
) /* use system default */
3659 { thislocale
= GetSystemDefaultLCID();
3661 GetLocaleInfoW(thislocale
, thisflags
, format_buf
, 40);
3662 thisformat
= format_buf
;
3665 { thisformat
= format
;
3668 if (xtime
== NULL
) /* NULL means use the current local time */
3676 ret
= OLE_GetFormatW(thislocale
, thisflags
, flags
, thistime
, thisformat
,
3681 /******************************************************************************
3682 * EnumCalendarInfoA [KERNEL32.@]
3684 BOOL WINAPI
EnumCalendarInfoA(
3685 CALINFO_ENUMPROCA calinfoproc
,LCID locale
,CALID calendar
,CALTYPE caltype
3687 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc
,locale
,calendar
,caltype
);