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"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(string
);
45 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
46 * MUST contain all #defines from winnls.h
47 * last entry has NULL name, 0 id.
49 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
50 static const struct tagLOCALE_NAME2ID
{
54 LOCALE_ENTRY(ILANGUAGE
),
55 LOCALE_ENTRY(SLANGUAGE
),
56 LOCALE_ENTRY(SENGLANGUAGE
),
57 LOCALE_ENTRY(SABBREVLANGNAME
),
58 LOCALE_ENTRY(SNATIVELANGNAME
),
59 LOCALE_ENTRY(ICOUNTRY
),
60 LOCALE_ENTRY(SCOUNTRY
),
61 LOCALE_ENTRY(SENGCOUNTRY
),
62 LOCALE_ENTRY(SABBREVCTRYNAME
),
63 LOCALE_ENTRY(SNATIVECTRYNAME
),
64 LOCALE_ENTRY(IDEFAULTLANGUAGE
),
65 LOCALE_ENTRY(IDEFAULTCOUNTRY
),
66 LOCALE_ENTRY(IDEFAULTCODEPAGE
),
67 LOCALE_ENTRY(IDEFAULTANSICODEPAGE
),
68 LOCALE_ENTRY(IDEFAULTMACCODEPAGE
),
70 LOCALE_ENTRY(IMEASURE
),
71 LOCALE_ENTRY(SDECIMAL
),
72 LOCALE_ENTRY(STHOUSAND
),
73 LOCALE_ENTRY(SGROUPING
),
74 LOCALE_ENTRY(IDIGITS
),
76 LOCALE_ENTRY(INEGNUMBER
),
77 LOCALE_ENTRY(SNATIVEDIGITS
),
78 LOCALE_ENTRY(SCURRENCY
),
79 LOCALE_ENTRY(SINTLSYMBOL
),
80 LOCALE_ENTRY(SMONDECIMALSEP
),
81 LOCALE_ENTRY(SMONTHOUSANDSEP
),
82 LOCALE_ENTRY(SMONGROUPING
),
83 LOCALE_ENTRY(ICURRDIGITS
),
84 LOCALE_ENTRY(IINTLCURRDIGITS
),
85 LOCALE_ENTRY(ICURRENCY
),
86 LOCALE_ENTRY(INEGCURR
),
89 LOCALE_ENTRY(SSHORTDATE
),
90 LOCALE_ENTRY(SLONGDATE
),
91 LOCALE_ENTRY(STIMEFORMAT
),
95 LOCALE_ENTRY(ITIMEMARKPOSN
),
96 LOCALE_ENTRY(ICENTURY
),
97 LOCALE_ENTRY(ITLZERO
),
98 LOCALE_ENTRY(IDAYLZERO
),
99 LOCALE_ENTRY(IMONLZERO
),
102 LOCALE_ENTRY(ICALENDARTYPE
),
103 LOCALE_ENTRY(IOPTIONALCALENDAR
),
104 LOCALE_ENTRY(IFIRSTDAYOFWEEK
),
105 LOCALE_ENTRY(IFIRSTWEEKOFYEAR
),
106 LOCALE_ENTRY(SDAYNAME1
),
107 LOCALE_ENTRY(SDAYNAME2
),
108 LOCALE_ENTRY(SDAYNAME3
),
109 LOCALE_ENTRY(SDAYNAME4
),
110 LOCALE_ENTRY(SDAYNAME5
),
111 LOCALE_ENTRY(SDAYNAME6
),
112 LOCALE_ENTRY(SDAYNAME7
),
113 LOCALE_ENTRY(SABBREVDAYNAME1
),
114 LOCALE_ENTRY(SABBREVDAYNAME2
),
115 LOCALE_ENTRY(SABBREVDAYNAME3
),
116 LOCALE_ENTRY(SABBREVDAYNAME4
),
117 LOCALE_ENTRY(SABBREVDAYNAME5
),
118 LOCALE_ENTRY(SABBREVDAYNAME6
),
119 LOCALE_ENTRY(SABBREVDAYNAME7
),
120 LOCALE_ENTRY(SMONTHNAME1
),
121 LOCALE_ENTRY(SMONTHNAME2
),
122 LOCALE_ENTRY(SMONTHNAME3
),
123 LOCALE_ENTRY(SMONTHNAME4
),
124 LOCALE_ENTRY(SMONTHNAME5
),
125 LOCALE_ENTRY(SMONTHNAME6
),
126 LOCALE_ENTRY(SMONTHNAME7
),
127 LOCALE_ENTRY(SMONTHNAME8
),
128 LOCALE_ENTRY(SMONTHNAME9
),
129 LOCALE_ENTRY(SMONTHNAME10
),
130 LOCALE_ENTRY(SMONTHNAME11
),
131 LOCALE_ENTRY(SMONTHNAME12
),
132 LOCALE_ENTRY(SMONTHNAME13
),
133 LOCALE_ENTRY(SABBREVMONTHNAME1
),
134 LOCALE_ENTRY(SABBREVMONTHNAME2
),
135 LOCALE_ENTRY(SABBREVMONTHNAME3
),
136 LOCALE_ENTRY(SABBREVMONTHNAME4
),
137 LOCALE_ENTRY(SABBREVMONTHNAME5
),
138 LOCALE_ENTRY(SABBREVMONTHNAME6
),
139 LOCALE_ENTRY(SABBREVMONTHNAME7
),
140 LOCALE_ENTRY(SABBREVMONTHNAME8
),
141 LOCALE_ENTRY(SABBREVMONTHNAME9
),
142 LOCALE_ENTRY(SABBREVMONTHNAME10
),
143 LOCALE_ENTRY(SABBREVMONTHNAME11
),
144 LOCALE_ENTRY(SABBREVMONTHNAME12
),
145 LOCALE_ENTRY(SABBREVMONTHNAME13
),
146 LOCALE_ENTRY(SPOSITIVESIGN
),
147 LOCALE_ENTRY(SNEGATIVESIGN
),
148 LOCALE_ENTRY(IPOSSIGNPOSN
),
149 LOCALE_ENTRY(INEGSIGNPOSN
),
150 LOCALE_ENTRY(IPOSSYMPRECEDES
),
151 LOCALE_ENTRY(IPOSSEPBYSPACE
),
152 LOCALE_ENTRY(INEGSYMPRECEDES
),
153 LOCALE_ENTRY(INEGSEPBYSPACE
),
154 LOCALE_ENTRY(FONTSIGNATURE
),
155 LOCALE_ENTRY(SISO639LANGNAME
),
156 LOCALE_ENTRY(SISO3166CTRYNAME
),
160 static char *GetLocaleSubkeyName( DWORD lctype
);
162 /***********************************************************************
163 * GetUserDefaultLCID (KERNEL32.@)
165 LCID WINAPI
GetUserDefaultLCID(void)
167 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT
);
170 /***********************************************************************
171 * GetSystemDefaultLCID (KERNEL32.@)
173 LCID WINAPI
GetSystemDefaultLCID(void)
175 return GetUserDefaultLCID();
178 #define NLS_MAX_LANGUAGES 20
182 LANGID found_lang_id
[NLS_MAX_LANGUAGES
];
183 char found_language
[NLS_MAX_LANGUAGES
][3];
184 char found_country
[NLS_MAX_LANGUAGES
][3];
188 static BOOL CALLBACK
NLS_FindLanguageID_ProcA(HMODULE hModule
, LPCSTR type
,
189 LPCSTR name
, WORD LangID
, LONG lParam
)
191 LANG_FIND_DATA
*l_data
= (LANG_FIND_DATA
*)lParam
;
192 LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
193 char buf_language
[128];
194 char buf_country
[128];
195 char buf_en_language
[128];
197 TRACE("%04X\n", (UINT
)LangID
);
198 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
199 return TRUE
; /* continue search */
204 GetLocaleInfoA(lcid
, LOCALE_SISO639LANGNAME
|LOCALE_NOUSEROVERRIDE
,
205 buf_language
, sizeof(buf_language
));
206 TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language
);
208 GetLocaleInfoA(lcid
, LOCALE_SISO3166CTRYNAME
|LOCALE_NOUSEROVERRIDE
,
209 buf_country
, sizeof(buf_country
));
210 TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country
);
212 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_language
))
214 if(l_data
->country
&& strlen(l_data
->country
) > 0)
216 if(!strcasecmp(l_data
->country
, buf_country
))
218 l_data
->found_lang_id
[0] = LangID
;
220 TRACE("Found lang_id %04X for %s_%s\n", LangID
, l_data
->lang
, l_data
->country
);
221 return FALSE
; /* stop enumeration */
224 else /* l_data->country not specified */
226 if(l_data
->n_found
< NLS_MAX_LANGUAGES
)
228 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
229 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
230 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
232 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
233 return TRUE
; /* continue search */
238 /* Just in case, check LOCALE_SENGLANGUAGE too,
239 * in hope that possible alias name might have that value.
241 buf_en_language
[0] = 0;
242 GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
|LOCALE_NOUSEROVERRIDE
,
243 buf_en_language
, sizeof(buf_en_language
));
244 TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language
);
246 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_en_language
))
248 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
249 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
250 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
252 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
255 return TRUE
; /* continue search */
258 /***********************************************************************
262 * Lang: a string whose two first chars are the iso name of a language.
263 * Country: a string whose two first chars are the iso name of country
264 * Charset: a string defining the chossen charset encoding
265 * Dialect: a string defining a variation of the locale
267 * all those values are from the standardized format of locale
268 * name in unix which is: Lang[_Country][.Charset][@Dialect]
271 * the numeric code of the language used by Windows
273 * FIXME: Charset and Dialect are not handled
275 static LANGID
NLS_GetLanguageID(LPCSTR Lang
, LPCSTR Country
, LPCSTR Charset
, LPCSTR Dialect
)
277 LANG_FIND_DATA l_data
;
278 char lang_string
[256];
282 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
286 memset(&l_data
, 0, sizeof(LANG_FIND_DATA
));
287 strncpy(l_data
.lang
, Lang
, sizeof(l_data
.lang
));
289 if(Country
&& strlen(Country
) > 0)
290 strncpy(l_data
.country
, Country
, sizeof(l_data
.country
));
292 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
293 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
295 strcpy(lang_string
, l_data
.lang
);
296 if(l_data
.country
&& strlen(l_data
.country
) > 0)
298 strcat(lang_string
, "_");
299 strcat(lang_string
, l_data
.country
);
304 if(l_data
.country
&& strlen(l_data
.country
) > 0)
306 MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string
);
307 l_data
.country
[0] = 0;
308 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
309 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
313 /* Re-evaluate lang_string */
314 strcpy(lang_string
, l_data
.lang
);
315 if(l_data
.country
&& strlen(l_data
.country
) > 0)
317 strcat(lang_string
, "_");
318 strcat(lang_string
, l_data
.country
);
323 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string
);
324 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
328 if(l_data
.n_found
== 1)
329 TRACE("For language '%s' lang_id %04X was found\n", lang_string
, l_data
.found_lang_id
[0]);
330 else /* l_data->n_found > 1 */
333 MESSAGE("For language '%s' several language ids were found:\n", lang_string
);
334 for(i
= 0; i
< l_data
.n_found
; i
++)
335 MESSAGE("%s_%s - %04X; ", l_data
.found_language
[i
], l_data
.found_country
[i
], l_data
.found_lang_id
[i
]);
337 MESSAGE("\nInstead of using first in the list, suggest to define\n"
338 "your LANG environment variable like this: LANG=%s_%s\n",
339 l_data
.found_language
[0], l_data
.found_country
[0]);
343 TRACE("Returning %04X\n", l_data
.found_lang_id
[0]);
344 return l_data
.found_lang_id
[0];
347 /***********************************************************************
348 * GetUserDefaultLangID (KERNEL32.@)
350 LANGID WINAPI
GetUserDefaultLangID(void)
352 /* caching result, if defined from environment, which should (?) not change during a WINE session */
353 static LANGID userLCID
= 0;
358 char *lang
,*country
,*charset
,*dialect
,*next
;
360 if (GetEnvironmentVariableA( "LANGUAGE", buf
, sizeof(buf
) )) goto ok
;
361 if (GetEnvironmentVariableA( "LANG", buf
, sizeof(buf
) )) goto ok
;
362 if (GetEnvironmentVariableA( "LC_ALL", buf
, sizeof(buf
) )) goto ok
;
363 if (GetEnvironmentVariableA( "LC_MESSAGES", buf
, sizeof(buf
) )) goto ok
;
364 if (GetEnvironmentVariableA( "LC_CTYPE", buf
, sizeof(buf
) )) goto ok
;
366 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
369 if (!strcmp(buf
,"POSIX") || !strcmp(buf
,"C"))
370 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
375 next
=strchr(lang
,':'); if (next
) *next
++='\0';
376 dialect
=strchr(lang
,'@'); if (dialect
) *dialect
++='\0';
377 charset
=strchr(lang
,'.'); if (charset
) *charset
++='\0';
378 country
=strchr(lang
,'_'); if (country
) *country
++='\0';
380 userLCID
= NLS_GetLanguageID(lang
, country
, charset
, dialect
);
383 } while (lang
&& !userLCID
);
387 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
389 userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
395 /***********************************************************************
396 * GetSystemDefaultLangID (KERNEL32.@)
398 LANGID WINAPI
GetSystemDefaultLangID(void)
400 return GetUserDefaultLangID();
403 /******************************************************************************
404 * ConvertDefaultLocale (KERNEL32.@)
406 LCID WINAPI
ConvertDefaultLocale (LCID lcid
)
408 { case LOCALE_SYSTEM_DEFAULT
:
409 return GetSystemDefaultLCID();
410 case LOCALE_USER_DEFAULT
:
411 return GetUserDefaultLCID();
413 return MAKELCID (LANG_NEUTRAL
, SUBLANG_NEUTRAL
);
415 return MAKELANGID( PRIMARYLANGID(lcid
), SUBLANG_NEUTRAL
);
418 /* Enhanced version of LoadStringW.
419 * It takes LanguageId to find and load language dependant resources.
420 * Resource is copied as is: "binary" strings are not truncated.
421 * Return: length of resource + 1 to distinguish absent resources
422 * from the resources with zero length.
424 static INT
NLS_LoadStringExW(HMODULE hModule
, LANGID lang_id
, UINT res_id
, LPWSTR buffer
, INT buflen
)
432 /* Replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
433 if(SUBLANGID(lang_id
) == SUBLANG_NEUTRAL
)
434 lang_id
= MAKELANGID(PRIMARYLANGID(lang_id
), SUBLANG_DEFAULT
);
436 hrsrc
= FindResourceExW(hModule
, RT_STRINGW
, (LPCWSTR
)((res_id
>> 4) + 1), lang_id
);
439 hmem
= LoadResource(hModule
, hrsrc
);
442 p
= LockResource(hmem
);
443 string_num
= res_id
& 0x000f;
444 for(i
= 0; i
< string_num
; i
++)
447 TRACE("strlen = %d\n", (int)*p
);
449 if (buffer
== NULL
) return *p
;
450 i
= min(buflen
- 1, *p
);
452 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
453 buffer
[i
] = (WCHAR
) 0;
456 buffer
[0] = (WCHAR
) 0;
460 TRACE("%s loaded!\n", debugstr_w(buffer
));
464 /******************************************************************************
465 * GetLocaleInfoA (KERNEL32.@)
468 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
470 * MS online documentation states that the string returned is NULL terminated
471 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
472 * terminated string".
474 INT WINAPI
GetLocaleInfoA(LCID lcid
,LCTYPE LCType
,LPSTR buf
,INT len
)
476 LPCSTR retString
= NULL
;
480 DWORD dwBufferSize
=128;
483 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid
,LCType
,buf
,len
);
485 if (len
&& (! buf
) ) {
486 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
490 if (lcid
== LOCALE_NEUTRAL
|| lcid
== LANG_SYSTEM_DEFAULT
)
492 lcid
= GetSystemDefaultLCID();
494 else if (lcid
== LANG_USER_DEFAULT
) /*0x800*/
496 lcid
= GetUserDefaultLCID();
499 /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
500 from the registry. Instead, use system default values. */
501 NoUserOverride
= (LCType
& LOCALE_NOUSEROVERRIDE
) != 0;
503 LCType
&= ~(LOCALE_NOUSEROVERRIDE
|LOCALE_USE_CP_ACP
);
505 /* First, check if it's in the registry. */
506 /* All user customized values are stored in the registry by SetLocaleInfo */
507 if ( !NoUserOverride
&& (pacKey
= GetLocaleSubkeyName(LCType
)) )
512 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
514 if ( RegOpenKeyExA( HKEY_CURRENT_USER
, acRealKey
,
515 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
517 if ( RegQueryValueExA( hKey
, NULL
, NULL
, NULL
, (LPBYTE
)acBuffer
,
518 &dwBufferSize
) == ERROR_SUCCESS
)
520 retString
= acBuffer
;
527 /* If not in the registry, get it from the NLS entries. */
532 /* check if language is registered in the kernel32 resources */
533 if((res_size
= NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid
),
534 LCType
, wcBuffer
, sizeof(wcBuffer
)/sizeof(wcBuffer
[0])))) {
535 WideCharToMultiByte(CP_ACP
, 0, wcBuffer
, res_size
, acBuffer
, dwBufferSize
, NULL
, NULL
);
536 retString
= acBuffer
;
541 /* if not found report a most descriptive error */
544 /* If we are through all of this, retLen should not be zero anymore.
545 If it is, the value is not supported */
547 while (locale_name2id
[i
].name
!=NULL
) {
548 if (LCType
== locale_name2id
[i
].id
) {
549 retString
= locale_name2id
[i
].name
;
555 FIXME("Unkown LC type %lX\n", LCType
);
557 FIXME("'%s' is not defined for your language (%04X).\n"
558 "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
559 "and submit patch for inclusion into the next Wine release.\n",
560 retString
, LOWORD(lcid
));
561 SetLastError(ERROR_INVALID_PARAMETER
);
565 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
566 if (LCType
== LOCALE_FONTSIGNATURE
) {
568 len
= (len
< sizeof(FONTSIGNATURE
)) ? len
: sizeof(FONTSIGNATURE
);
569 memcpy(buf
, retString
, len
);
572 return sizeof(FONTSIGNATURE
);
574 /* if len=0 return only the length, don't touch the buffer*/
576 /* Like Windows we copy len bytes to buffer and we check len after */
577 INT ret
= strlen(retString
) + 1;
578 memcpy( buf
, retString
, min(len
, ret
) );
579 return (len
< ret
) ? 0 : ret
;
581 return strlen(retString
)+1;
584 /******************************************************************************
585 * GetLocaleInfoW (KERNEL32.@)
588 * MS documentation states that len "specifies the size, in bytes (ANSI version)
589 * or characters (Unicode version), of" wbuf. Thus the number returned is
590 * the same between GetLocaleInfoW and GetLocaleInfoA.
592 INT WINAPI
GetLocaleInfoW(LCID lcid
,LCTYPE LCType
,LPWSTR wbuf
,INT len
)
596 if (len
&& (! wbuf
) )
597 { SetLastError(ERROR_INSUFFICIENT_BUFFER
);
601 abuf
= (LPSTR
)HeapAlloc(GetProcessHeap(),0,len
);
602 wlen
= GetLocaleInfoA(lcid
, LCType
, abuf
, len
);
604 if (wlen
&& len
) /* if len=0 return only the length*/
605 MultiByteToWideChar( CP_ACP
, 0, abuf
, -1, wbuf
, len
);
607 HeapFree(GetProcessHeap(),0,abuf
);
611 /******************************************************************************
613 * GetLocaleSubkeyName [helper function]
615 * - For use with the registry.
616 * - Gets the registry subkey name for a given lctype.
618 static char *GetLocaleSubkeyName( DWORD lctype
)
624 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
625 * the values are stored in the registry, confirmed under Windows,
626 * for the ones that actually assign pacKey. Cases that aren't finished
627 * have not been confirmed, so that must be done before they can be
630 case LOCALE_SDATE
: /* The date separator. */
633 case LOCALE_ICURRDIGITS
:
634 pacKey
= "iCurrDigits";
636 case LOCALE_SDECIMAL
:
639 case LOCALE_ICURRENCY
:
640 pacKey
= "iCurrency";
642 case LOCALE_SGROUPING
:
643 pacKey
= "sGrouping";
651 /* case LOCALE_ICALENDARTYPE: */
652 /* case LOCALE_IFIRSTDAYOFWEEK: */
653 /* case LOCALE_IFIRSTWEEKOFYEAR: */
654 /* case LOCALE_SYEARMONTH : */
655 /* case LOCALE_SPOSITIVESIGN : */
656 /* case LOCALE_IPAPERSIZE: */
658 case LOCALE_SLONGDATE
:
659 pacKey
= "sLongDate";
661 case LOCALE_SMONDECIMALSEP
:
662 pacKey
= "sMonDecimalSep";
664 case LOCALE_SMONGROUPING
:
665 pacKey
= "sMonGrouping";
667 case LOCALE_IMEASURE
:
670 case LOCALE_SMONTHOUSANDSEP
:
671 pacKey
= "sMonThousandSep";
673 case LOCALE_INEGCURR
:
676 case LOCALE_SNEGATIVESIGN
:
677 pacKey
= "sNegativeSign";
679 case LOCALE_INEGNUMBER
:
680 pacKey
= "iNegNumber";
682 case LOCALE_SSHORTDATE
:
683 pacKey
= "sShortDate";
685 case LOCALE_ILDATE
: /* Long Date format ordering specifier. */
694 case LOCALE_ITIME
: /* Time format specifier. */
697 case LOCALE_STHOUSAND
:
698 pacKey
= "sThousand";
700 case LOCALE_S1159
: /* AM */
706 case LOCALE_S2359
: /* PM */
709 case LOCALE_STIMEFORMAT
:
710 pacKey
= "sTimeFormat";
712 case LOCALE_SCURRENCY
:
713 pacKey
= "sCurrency";
716 /* The following are not listed under MSDN as supported,
717 * but seem to be used and also stored in the registry.
723 case LOCALE_SCOUNTRY
:
726 case LOCALE_ICOUNTRY
:
729 case LOCALE_SLANGUAGE
:
730 pacKey
= "sLanguage";
740 /******************************************************************************
741 * SetLocaleInfoA [KERNEL32.@]
743 BOOL WINAPI
SetLocaleInfoA(LCID lcid
, LCTYPE lctype
, LPCSTR data
)
749 if ( (pacKey
= GetLocaleSubkeyName(lctype
)) )
751 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
752 if ( RegCreateKeyA( HKEY_CURRENT_USER
, acRealKey
,
753 &hKey
) == ERROR_SUCCESS
)
755 if ( RegSetValueExA( hKey
, NULL
, 0, REG_SZ
,
756 data
, strlen(data
)+1 ) != ERROR_SUCCESS
)
758 ERR("SetLocaleInfoA: %s did not work\n", pacKey
);
765 FIXME("(%ld,%ld,%s): stub\n",lcid
,lctype
,data
);
770 /******************************************************************************
771 * IsValidLocale [KERNEL32.@]
773 BOOL WINAPI
IsValidLocale(LCID lcid
,DWORD flags
)
775 /* check if language is registered in the kernel32 resources */
776 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW
, (LPCWSTR
)LOCALE_ILANGUAGE
, LOWORD(lcid
)))
782 static BOOL CALLBACK
EnumResourceLanguagesProcW(HMODULE hModule
, LPCWSTR type
,
783 LPCWSTR name
, WORD LangID
, LONG lParam
)
787 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
788 sprintf(bufA
, "%08X", (UINT
)LangID
);
789 MultiByteToWideChar(CP_ACP
, 0, bufA
, -1, bufW
, sizeof(bufW
)/sizeof(bufW
[0]));
790 return lpfnLocaleEnum(bufW
);
793 /******************************************************************************
794 * EnumSystemLocalesW [KERNEL32.@]
796 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
,
799 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
801 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW
,
802 (LPCWSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcW
,
803 (LONG
)lpfnLocaleEnum
);
808 static BOOL CALLBACK
EnumResourceLanguagesProcA(HMODULE hModule
, LPCSTR type
,
809 LPCSTR name
, WORD LangID
, LONG lParam
)
812 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
813 sprintf(bufA
, "%08X", (UINT
)LangID
);
814 return lpfnLocaleEnum(bufA
);
817 /******************************************************************************
818 * EnumSystemLocalesA [KERNEL32.@]
820 BOOL WINAPI
EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum
,
823 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
825 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
826 (LPCSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcA
,
827 (LONG
)lpfnLocaleEnum
);
832 /***********************************************************************
833 * VerLanguageNameA [KERNEL32.@]
835 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
840 return GetLocaleInfoA(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
843 /***********************************************************************
844 * VerLanguageNameW [KERNEL32.@]
846 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
851 return GetLocaleInfoW(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
855 static const unsigned char LCM_Unicode_LUT
[] = {
889 7 , 29, /* " - 34 */ /* " */
894 6 , 128, /* ' - 39 */
900 6 , 130, /* - - 45 */
904 12 , 33, /* 1 - 49 */
905 12 , 51, /* 2 - 50 */
906 12 , 70, /* 3 - 51 */
907 12 , 88, /* 4 - 52 */
908 12 , 106, /* 5 - 53 */
909 12 , 125, /* 6 - 54 */
910 12 , 144, /* 7 - 55 */
911 12 , 162, /* 8 - 56 */
912 12 , 180, /* 9 - 57 */
922 14 , 10, /* C - 67 */
923 14 , 26, /* D - 68 */
924 14 , 33, /* E - 69 */
925 14 , 35, /* F - 70 */
926 14 , 37, /* G - 71 */
927 14 , 44, /* H - 72 */
928 14 , 50, /* I - 73 */
929 14 , 53, /* J - 74 */
930 14 , 54, /* K - 75 */
931 14 , 72, /* L - 76 */
932 14 , 81, /* M - 77 */
933 14 , 112, /* N - 78 */
934 14 , 124, /* O - 79 */
935 14 , 126, /* P - 80 */
936 14 , 137, /* Q - 81 */
937 14 , 138, /* R - 82 */
938 14 , 145, /* S - 83 */
939 14 , 153, /* T - 84 */
940 14 , 159, /* U - 85 */
941 14 , 162, /* V - 86 */
942 14 , 164, /* W - 87 */
943 14 , 166, /* X - 88 */
944 14 , 167, /* Y - 89 */
945 14 , 169, /* Z - 90 */
954 14 , 10, /* c - 99 */
955 14 , 26, /* d - 100 */
956 14 , 33, /* e - 101 */
957 14 , 35, /* f - 102 */
958 14 , 37, /* g - 103 */
959 14 , 44, /* h - 104 */
960 14 , 50, /* i - 105 */
961 14 , 53, /* j - 106 */
962 14 , 54, /* k - 107 */
963 14 , 72, /* l - 108 */
964 14 , 81, /* m - 109 */
965 14 , 112, /* n - 110 */
966 14 , 124, /* o - 111 */
967 14 , 126, /* p - 112 */
968 14 , 137, /* q - 113 */
969 14 , 138, /* r - 114 */
970 14 , 145, /* s - 115 */
971 14 , 153, /* t - 116 */
972 14 , 159, /* u - 117 */
973 14 , 162, /* v - 118 */
974 14 , 164, /* w - 119 */
975 14 , 166, /* x - 120 */
976 14 , 167, /* y - 121 */
977 14 , 169, /* z - 122 */
978 7 , 74, /* { - 123 */
979 7 , 76, /* | - 124 */
980 7 , 78, /* } - 125 */
981 7 , 80, /* ~ - 126 */
982 6 , 29, /* \x7f - 127 */
983 6 , 30, /* € - 128 */
984 6 , 31, /* � - 129 */
985 7 , 123, /* ‚ - 130 */
986 14 , 35, /* ƒ - 131 */
987 7 , 127, /* „ - 132 */
988 10 , 21, /* … - 133 */
989 10 , 15, /* † - 134 */
990 10 , 16, /* ‡ - 135 */
991 7 , 67, /* ˆ - 136 */
992 10 , 22, /* ‰ - 137 */
993 14 , 145, /* Š - 138 */
994 7 , 136, /* ‹ - 139 */
995 14 + 16 , 124, /* Œ - 140 */
996 6 , 43, /* � - 141 */
997 6 , 44, /* Ž - 142 */
998 6 , 45, /* � - 143 */
999 6 , 46, /* � - 144 */
1000 7 , 121, /* ‘ - 145 */
1001 7 , 122, /* ’ - 146 */
1002 7 , 125, /* “ - 147 */
1003 7 , 126, /* ” - 148 */
1004 10 , 17, /* • - 149 */
1005 6 , 137, /* – - 150 */
1006 6 , 139, /* — - 151 */
1007 7 , 93, /* ˜ - 152 */
1008 14 , 156, /* ™ - 153 */
1009 14 , 145, /* š - 154 */
1010 7 , 137, /* › - 155 */
1011 14 + 16 , 124, /* œ - 156 */
1012 6 , 59, /* � - 157 */
1013 6 , 60, /* ž - 158 */
1014 14 , 167, /* Ÿ - 159 */
1016 7 , 81, /* ¡ - 161 */
1017 10 , 2, /* ¢ - 162 */
1018 10 , 3, /* £ - 163 */
1019 10 , 4, /* ¤ - 164 */
1020 10 , 5, /* ¥ - 165 */
1021 7 , 82, /* ¦ - 166 */
1022 10 , 6, /* § - 167 */
1023 7 , 83, /* ¨ - 168 */
1024 10 , 7, /* © - 169 */
1025 14 , 2, /* ª - 170 */
1026 8 , 24, /* « - 171 */
1027 10 , 8, /* ¬ - 172 */
1028 6 , 131, /* - 173 */
1029 10 , 9, /* ® - 174 */
1030 7 , 84, /* ¯ - 175 */
1031 10 , 10, /* ° - 176 */
1032 8 , 23, /* ± - 177 */
1033 12 , 51, /* ² - 178 */
1034 12 , 70, /* ³ - 179 */
1035 7 , 85, /* ´ - 180 */
1036 10 , 11, /* µ - 181 */
1037 10 , 12, /* ¶ - 182 */
1038 10 , 13, /* · - 183 */
1039 7 , 86, /* ¸ - 184 */
1040 12 , 33, /* ¹ - 185 */
1041 14 , 124, /* º - 186 */
1042 8 , 26, /* » - 187 */
1043 12 , 21, /* ¼ - 188 */
1044 12 , 25, /* ½ - 189 */
1045 12 , 29, /* ¾ - 190 */
1046 7 , 87, /* ¿ - 191 */
1047 14 , 2, /* À - 192 */
1048 14 , 2, /* Á - 193 */
1049 14 , 2, /* Â - 194 */
1050 14 , 2, /* Ã - 195 */
1051 14 , 2, /* Ä - 196 */
1052 14 , 2, /* Å - 197 */
1053 14 + 16 , 2, /* Æ - 198 */
1054 14 , 10, /* Ç - 199 */
1055 14 , 33, /* È - 200 */
1056 14 , 33, /* É - 201 */
1057 14 , 33, /* Ê - 202 */
1058 14 , 33, /* Ë - 203 */
1059 14 , 50, /* Ì - 204 */
1060 14 , 50, /* Í - 205 */
1061 14 , 50, /* Î - 206 */
1062 14 , 50, /* Ï - 207 */
1063 14 , 26, /* Ð - 208 */
1064 14 , 112, /* Ñ - 209 */
1065 14 , 124, /* Ò - 210 */
1066 14 , 124, /* Ó - 211 */
1067 14 , 124, /* Ô - 212 */
1068 14 , 124, /* Õ - 213 */
1069 14 , 124, /* Ö - 214 */
1070 8 , 28, /* × - 215 */
1071 14 , 124, /* Ø - 216 */
1072 14 , 159, /* Ù - 217 */
1073 14 , 159, /* Ú - 218 */
1074 14 , 159, /* Û - 219 */
1075 14 , 159, /* Ü - 220 */
1076 14 , 167, /* Ý - 221 */
1077 14 + 32 , 153, /* Þ - 222 */
1078 14 + 48 , 145, /* ß - 223 */
1079 14 , 2, /* à - 224 */
1080 14 , 2, /* á - 225 */
1081 14 , 2, /* â - 226 */
1082 14 , 2, /* ã - 227 */
1083 14 , 2, /* ä - 228 */
1084 14 , 2, /* å - 229 */
1085 14 + 16 , 2, /* æ - 230 */
1086 14 , 10, /* ç - 231 */
1087 14 , 33, /* è - 232 */
1088 14 , 33, /* é - 233 */
1089 14 , 33, /* ê - 234 */
1090 14 , 33, /* ë - 235 */
1091 14 , 50, /* ì - 236 */
1092 14 , 50, /* í - 237 */
1093 14 , 50, /* î - 238 */
1094 14 , 50, /* ï - 239 */
1095 14 , 26, /* ð - 240 */
1096 14 , 112, /* ñ - 241 */
1097 14 , 124, /* ò - 242 */
1098 14 , 124, /* ó - 243 */
1099 14 , 124, /* ô - 244 */
1100 14 , 124, /* õ - 245 */
1101 14 , 124, /* ö - 246 */
1102 8 , 29, /* ÷ - 247 */
1103 14 , 124, /* ø - 248 */
1104 14 , 159, /* ù - 249 */
1105 14 , 159, /* ú - 250 */
1106 14 , 159, /* û - 251 */
1107 14 , 159, /* ü - 252 */
1108 14 , 167, /* ý - 253 */
1109 14 + 32 , 153, /* þ - 254 */
1110 14 , 167 /* ÿ - 255 */ };
1112 static const unsigned char LCM_Unicode_LUT_2
[] = { 33, 44, 145 };
1114 #define LCM_Diacritic_Start 131
1116 static const unsigned char LCM_Diacritic_LUT
[] = {
1244 /******************************************************************************
1245 * OLE2NLS_isPunctuation [INTERNAL]
1247 static int OLE2NLS_isPunctuation(unsigned char c
)
1249 /* "punctuation character" in this context is a character which is
1250 considered "less important" during word sort comparison.
1251 See LCMapString implementation for the precise definition
1252 of "less important". */
1254 return (LCM_Unicode_LUT
[-2+2*c
]==6);
1257 /******************************************************************************
1258 * OLE2NLS_isNonSpacing [INTERNAL]
1260 static int OLE2NLS_isNonSpacing(unsigned char c
)
1262 /* This function is used by LCMapStringA. Characters
1263 for which it returns true are ignored when mapping a
1264 string with NORM_IGNORENONSPACE */
1265 return ((c
==136) || (c
==170) || (c
==186));
1268 /******************************************************************************
1269 * OLE2NLS_isSymbol [INTERNAL]
1270 * FIXME: handle current locale
1272 static int OLE2NLS_isSymbol(unsigned char c
)
1274 /* This function is used by LCMapStringA. Characters
1275 for which it returns true are ignored when mapping a
1276 string with NORM_IGNORESYMBOLS */
1277 return ( (c
!=0) && !(isalpha(c
) || isdigit(c
)) );
1280 /******************************************************************************
1281 * identity [Internal]
1283 static int identity(int c
)
1288 /*************************************************************************
1289 * LCMapStringA [KERNEL32.@]
1291 * Convert a string, or generate a sort key from it.
1293 * If (mapflags & LCMAP_SORTKEY), the function will generate
1294 * a sort key for the source string. Else, it will convert it
1295 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1299 * Success : length of the result string.
1302 * If called with scrlen = -1, the function will compute the length
1303 * of the 0-terminated string strsrc by itself.
1305 * If called with dstlen = 0, returns the buffer length that
1306 * would be required.
1308 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1309 * as if they are equal.
1310 * In the only code page implemented so far, there may not be
1311 * wide characters in strings passed to LCMapStringA,
1312 * so there is nothing to be done for this flag.
1314 INT WINAPI
LCMapStringA(
1315 LCID lcid
, /* [in] locale identifier created with MAKELCID;
1316 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1317 predefined values. */
1318 DWORD mapflags
, /* [in] flags */
1319 LPCSTR srcstr
, /* [in] source buffer */
1320 INT srclen
, /* [in] source length */
1321 LPSTR dststr
, /* [out] destination buffer */
1322 INT dstlen
) /* [in] destination buffer length */
1326 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1327 lcid
,mapflags
,debugstr_an(srcstr
,srclen
),srclen
,dststr
,dstlen
);
1329 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1331 ERR("(src=%s,dest=%s): Invalid NULL string\n",
1332 debugstr_an(srcstr
,srclen
), dststr
);
1333 SetLastError(ERROR_INVALID_PARAMETER
);
1337 srclen
= strlen(srcstr
) + 1 ; /* (include final '\0') */
1339 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1343 NORM_IGNORENONSPACE | \
1345 NORM_IGNOREWIDTH | \
1346 NORM_IGNOREKANATYPE)
1347 /* FIXME: as long as we don't support Katakana nor Hiragana
1348 * characters, we can support NORM_IGNOREKANATYPE
1350 if (mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
)
1352 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1353 "unimplemented flags: 0x%08lx\n",
1360 mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
1364 if ( !(mapflags
& LCMAP_SORTKEY
) )
1367 int (*f
)(int) = identity
;
1368 int flag_ignorenonspace
= mapflags
& NORM_IGNORENONSPACE
;
1369 int flag_ignoresymbols
= mapflags
& NORM_IGNORESYMBOLS
;
1371 if (flag_ignorenonspace
|| flag_ignoresymbols
)
1373 /* For some values of mapflags, the length of the resulting
1374 string is not known at this point. Windows does map the string
1375 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1379 /* Compute required length */
1380 for (i
=j
=0; i
< srclen
; i
++)
1382 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1383 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1395 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1399 if (mapflags
& LCMAP_UPPERCASE
)
1401 else if (mapflags
& LCMAP_LOWERCASE
)
1403 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1404 for (i
=j
=0; (i
<srclen
) && (j
<dstlen
) ; i
++)
1406 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1407 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1409 dststr
[j
] = (CHAR
) f(srcstr
[i
]);
1416 /* FIXME: This function completely ignores the "lcid" parameter. */
1417 /* else ... (mapflags & LCMAP_SORTKEY) */
1421 int diacritic_len
=0;
1422 int delayed_punctuation_len
=0;
1423 char *case_component
;
1424 char *diacritic_component
;
1425 char *delayed_punctuation_component
;
1427 int flag_stringsort
= mapflags
& SORT_STRINGSORT
;
1429 /* compute how much room we will need */
1430 for (i
=0;i
<srclen
;i
++)
1433 unsigned char source_char
= srcstr
[i
];
1434 if (source_char
!='\0')
1436 if (flag_stringsort
|| !OLE2NLS_isPunctuation(source_char
))
1439 if ( LCM_Unicode_LUT
[-2+2*source_char
] & ~15 )
1440 unicode_len
++; /* double letter */
1444 delayed_punctuation_len
++;
1448 if (isupper(source_char
))
1449 case_len
=unicode_len
;
1451 ofs
= source_char
- LCM_Diacritic_Start
;
1452 if ((ofs
>=0) && (LCM_Diacritic_LUT
[ofs
]!=2))
1453 diacritic_len
=unicode_len
;
1456 if (mapflags
& NORM_IGNORECASE
)
1458 if (mapflags
& NORM_IGNORENONSPACE
)
1461 room
= 2 * unicode_len
/* "unicode" component */
1462 + diacritic_len
/* "diacritic" component */
1463 + case_len
/* "case" component */
1464 + 4 * delayed_punctuation_len
/* punctuation in word sort mode */
1465 + 4 /* four '\1' separators */
1466 + 1 ; /* terminal '\0' */
1469 else if (dstlen
<room
)
1471 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1475 /*FIXME the Pointercheck should not be nessesary */
1476 if (IsBadWritePtr (dststr
,room
))
1477 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr
,dstlen
);
1478 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1482 /* locate each component, write separators */
1483 diacritic_component
= dststr
+ 2*unicode_len
;
1484 *diacritic_component
++ = '\1';
1485 case_component
= diacritic_component
+ diacritic_len
;
1486 *case_component
++ = '\1';
1487 delayed_punctuation_component
= case_component
+ case_len
;
1488 *delayed_punctuation_component
++ = '\1';
1489 *delayed_punctuation_component
++ = '\1';
1491 /* read source string char by char, write
1492 corresponding weight in each component. */
1493 for (i
=0,count
=0;i
<srclen
;i
++)
1495 unsigned char source_char
=srcstr
[i
];
1496 if (source_char
!='\0')
1499 type
= LCM_Unicode_LUT
[-2+2*source_char
];
1500 longcode
= type
>> 4;
1502 if (!flag_stringsort
&& OLE2NLS_isPunctuation(source_char
))
1504 WORD encrypted_location
= (1<<15) + 7 + 4*count
;
1505 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
>>8);
1506 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
&255);
1507 /* big-endian is used here because it lets string comparison be
1508 compatible with numerical comparison */
1510 *delayed_punctuation_component
++ = type
;
1511 *delayed_punctuation_component
++ = LCM_Unicode_LUT
[-1+2*source_char
];
1512 /* assumption : a punctuation character is never a
1513 double or accented letter */
1517 dststr
[2*count
] = type
;
1518 dststr
[2*count
+1] = LCM_Unicode_LUT
[-1+2*source_char
];
1522 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1523 if (count
<diacritic_len
)
1524 diacritic_component
[count
] = 2; /* assumption: a double letter
1525 is never accented */
1528 dststr
[2*count
] = type
;
1529 dststr
[2*count
+1] = *(LCM_Unicode_LUT_2
- 1 + longcode
);
1530 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1531 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1532 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1536 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
1537 if (count
<diacritic_len
)
1539 int ofs
= source_char
- LCM_Diacritic_Start
;
1540 diacritic_component
[count
] = (ofs
>=0 ? LCM_Diacritic_LUT
[ofs
] : 2);
1546 dststr
[room
-1] = '\0';
1551 /*************************************************************************
1552 * LCMapStringW [KERNEL32.@]
1554 * Convert a string, or generate a sort key from it.
1558 * See LCMapStringA for documentation
1560 INT WINAPI
LCMapStringW(
1561 LCID lcid
,DWORD mapflags
,LPCWSTR srcstr
,INT srclen
,LPWSTR dststr
,
1566 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
1567 lcid
, mapflags
, srcstr
, srclen
, dststr
, dstlen
);
1569 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1571 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr
, dststr
);
1572 SetLastError(ERROR_INVALID_PARAMETER
);
1576 srclen
= strlenW(srcstr
)+1;
1578 /* FIXME: Both this function and it's companion LCMapStringA()
1579 * completely ignore the "lcid" parameter. In place of the "lcid"
1580 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
1581 * environment variable prior to invoking this function. */
1582 if (mapflags
& LCMAP_SORTKEY
)
1584 /* Possible values of LC_COLLATE. */
1585 char *lc_collate_default
= 0; /* value prior to this function */
1586 char *lc_collate_env
= 0; /* value retrieved from the environment */
1588 /* General purpose index into strings of any type. */
1591 /* Lengths of various strings where the length is measured in
1592 * wide characters for wide character strings and in bytes for
1593 * native strings. The lengths include the NULL terminator. */
1594 size_t returned_len
= 0;
1595 size_t src_native_len
= 0;
1596 size_t dst_native_len
= 0;
1597 size_t dststr_libc_len
= 0;
1599 /* Native (character set determined by locale) versions of the
1600 * strings source and destination strings. */
1601 LPSTR src_native
= 0;
1602 LPSTR dst_native
= 0;
1604 /* Version of the source and destination strings using the
1605 * "wchar_t" Unicode data type needed by various libc functions. */
1606 wchar_t *srcstr_libc
= 0;
1607 wchar_t *dststr_libc
= 0;
1609 if(!(srcstr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
1610 srclen
* sizeof(wchar_t))))
1612 ERR("Unable to allocate %d bytes for srcstr_libc\n",
1613 srclen
* sizeof(wchar_t));
1614 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1618 /* Convert source string to a libc Unicode string. */
1619 for(str_idx
= 0; str_idx
< srclen
; str_idx
++)
1621 srcstr_libc
[str_idx
] = srcstr
[str_idx
];
1624 /* src_native should contain at most 3 bytes for each
1625 * multibyte characters in the original srcstr string. */
1626 src_native_len
= 3 * srclen
;
1627 if(!(src_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
1630 ERR("Unable to allocate %d bytes for src_native\n", src_native_len
);
1631 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1632 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1636 /* FIXME: Prior to to setting the LC_COLLATE locale category the
1637 * current value is backed up so it can be restored after the
1638 * last LC_COLLATE sensitive function returns.
1640 * Even though the locale is adjusted for a minimum amount of
1641 * time a race condition exists where other threads may be
1642 * affected if they invoke LC_COLLATE sensitive functions. One
1643 * possible solution is to wrap all LC_COLLATE sensitive Wine
1644 * functions, like LCMapStringW(), in a mutex.
1646 * Another enhancement to the following would be to set the
1647 * LC_COLLATE locale category as a function of the "lcid"
1648 * parameter instead of the "LC_COLLATE" environment variable. */
1649 if(!(lc_collate_default
= setlocale(LC_COLLATE
, NULL
)))
1651 ERR("Unable to query the LC_COLLATE catagory\n");
1652 SetLastError(ERROR_INVALID_PARAMETER
);
1653 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1654 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1658 if(!(lc_collate_env
= setlocale(LC_COLLATE
, "")))
1660 ERR("Unable to inherit the LC_COLLATE locale category from the "
1661 "environment. The \"LC_COLLATE\" environment variable is "
1662 "\"%s\".\n", getenv("LC_COLLATE") ?
1663 getenv("LC_COLLATE") : "<unset>");
1664 SetLastError(ERROR_INVALID_PARAMETER
);
1665 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1666 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1670 TRACE("lc_collate_default = %s\n", lc_collate_default
);
1671 TRACE("lc_collate_env = %s\n", lc_collate_env
);
1673 /* Convert the libc Unicode string to a native multibyte character
1675 returned_len
= wcstombs(src_native
, srcstr_libc
, src_native_len
) + 1;
1676 if(returned_len
== 0)
1678 ERR("wcstombs failed. The string specified (%s) may contain an invalid character.\n",
1679 debugstr_w(srcstr
));
1680 SetLastError(ERROR_INVALID_PARAMETER
);
1681 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1682 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1683 setlocale(LC_COLLATE
, lc_collate_default
);
1686 else if(returned_len
> src_native_len
)
1688 src_native
[src_native_len
- 1] = 0;
1689 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
1690 "than expected (%d bytes).\n", src_native
, returned_len
,
1693 /* Since this is an internal error I'm not sure what the correct
1695 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1697 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1698 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1699 setlocale(LC_COLLATE
, lc_collate_default
);
1702 src_native_len
= returned_len
;
1704 TRACE("src_native = %s src_native_len = %d\n",
1705 src_native
, src_native_len
);
1707 /* dst_native seems to contain at most 4 bytes for each byte in
1708 * the original src_native string. Change if need be since this
1709 * isn't documented by the strxfrm() man page. */
1710 dst_native_len
= 4 * src_native_len
;
1711 if(!(dst_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, dst_native_len
)))
1713 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len
);
1714 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1715 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1716 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1717 setlocale(LC_COLLATE
, lc_collate_default
);
1721 /* The actual translation is done by the following call to
1722 * strxfrm(). The surrounding code could have been simplified
1723 * by calling wcsxfrm() instead except that wcsxfrm() is not
1724 * available on older Linux systems (RedHat 4.1 with
1727 * Also, it is possible that the translation could be done by
1728 * various tables as it is done in LCMapStringA(). However, I'm
1729 * not sure what those tables are. */
1730 returned_len
= strxfrm(dst_native
, src_native
, dst_native_len
) + 1;
1732 if(returned_len
> dst_native_len
)
1734 dst_native
[dst_native_len
- 1] = 0;
1735 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
1736 "than expected (%d bytes).\n", dst_native
, returned_len
,
1739 /* Since this is an internal error I'm not sure what the correct
1741 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1743 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1744 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1745 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1746 setlocale(LC_COLLATE
, lc_collate_default
);
1749 dst_native_len
= returned_len
;
1751 TRACE("dst_native = %s dst_native_len = %d\n",
1752 dst_native
, dst_native_len
);
1754 dststr_libc_len
= dst_native_len
;
1755 if(!(dststr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
1756 dststr_libc_len
* sizeof(wchar_t))))
1758 ERR("Unable to allocate %d bytes for dststr_libc\n",
1759 dststr_libc_len
* sizeof(wchar_t));
1760 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1761 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1762 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1763 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1764 setlocale(LC_COLLATE
, lc_collate_default
);
1768 /* Convert the native multibyte string to a libc Unicode string. */
1769 returned_len
= mbstowcs(dststr_libc
, dst_native
, dst_native_len
) + 1;
1771 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
1772 * function has returned. */
1773 setlocale(LC_COLLATE
, lc_collate_default
);
1775 if(returned_len
== 0)
1777 ERR("mbstowcs failed. The native version of the translated string "
1778 "(%s) may contain an invalid character.\n", dst_native
);
1779 SetLastError(ERROR_INVALID_PARAMETER
);
1780 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1781 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1782 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1783 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
1788 if(returned_len
> dstlen
)
1790 ERR("mbstowcs returned a string that was longer (%d chars) "
1791 "than the buffer provided (%d chars).\n", returned_len
,
1793 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1794 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1795 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1796 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1797 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
1800 dstlen
= returned_len
;
1802 /* Convert a libc Unicode string to the destination string. */
1803 for(str_idx
= 0; str_idx
< dstlen
; str_idx
++)
1805 dststr
[str_idx
] = dststr_libc
[str_idx
];
1807 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
1808 *(((int *)dststr
) + 0),
1809 *(((int *)dststr
) + 1),
1810 *(((int *)dststr
) + 2),
1811 *(((int *)dststr
) + 3));
1815 dstlen
= returned_len
;
1817 TRACE("dstlen (return) = %d\n", dstlen
);
1818 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
1819 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
1820 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
1821 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
1826 int (*f
)(int)=identity
;
1832 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1836 if (mapflags
& LCMAP_UPPERCASE
)
1838 else if (mapflags
& LCMAP_LOWERCASE
)
1840 for (i
=0; i
< srclen
; i
++)
1841 dststr
[i
] = (WCHAR
) f(srcstr
[i
]);
1847 /***********************************************************************
1848 * OLE2NLS_EstimateMappingLength
1850 * Estimates the number of characters required to hold the string
1851 * computed by LCMapStringA.
1853 * The size is always over-estimated, with a fixed limit on the
1854 * amount of estimation error.
1856 * Note that len == -1 is not permitted.
1858 static inline int OLE2NLS_EstimateMappingLength(LCID lcid
, DWORD dwMapFlags
,
1859 LPCSTR str
, DWORD len
)
1861 /* Estimate only for small strings to keep the estimation error from
1862 * becoming too large. */
1863 if (len
< 128) return len
* 8 + 5;
1864 else return LCMapStringA(lcid
, dwMapFlags
, str
, len
, NULL
, 0);
1867 /******************************************************************************
1868 * CompareStringA [KERNEL32.@]
1869 * Compares two strings using locale
1873 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
1878 * Defaults to a word sort, but uses a string sort if
1879 * SORT_STRINGSORT is set.
1880 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
1884 * This implementation ignores the locale
1888 * Quite inefficient.
1890 int WINAPI
CompareStringA(
1891 LCID lcid
, /* [in] locale ID */
1892 DWORD fdwStyle
, /* [in] comparison-style options */
1893 LPCSTR s1
, /* [in] first string */
1894 int l1
, /* [in] length of first string */
1895 LPCSTR s2
, /* [in] second string */
1896 int l2
) /* [in] length of second string */
1898 int mapstring_flags
;
1902 TRACE("%s and %s\n",
1903 debugstr_an (s1
,l1
), debugstr_an (s2
,l2
));
1905 if ( (s1
==NULL
) || (s2
==NULL
) )
1907 ERR("(s1=%s,s2=%s): Invalid NULL string\n",
1908 debugstr_an(s1
,l1
), debugstr_an(s2
,l2
));
1909 SetLastError(ERROR_INVALID_PARAMETER
);
1913 if(fdwStyle
& NORM_IGNORESYMBOLS
)
1914 FIXME("IGNORESYMBOLS not supported\n");
1916 if (l1
== -1) l1
= strlen(s1
);
1917 if (l2
== -1) l2
= strlen(s2
);
1919 mapstring_flags
= LCMAP_SORTKEY
| fdwStyle
;
1920 len1
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s1
, l1
);
1921 len2
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s2
, l2
);
1923 if ((len1
==0)||(len2
==0))
1924 return 0; /* something wrong happened */
1926 sk1
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, len1
+ len2
);
1928 if ( (!LCMapStringA(lcid
,mapstring_flags
,s1
,l1
,sk1
,len1
))
1929 || (!LCMapStringA(lcid
,mapstring_flags
,s2
,l2
,sk2
,len2
)) )
1931 ERR("Bug in LCmapStringA.\n");
1936 /* strcmp doesn't necessarily return -1, 0, or 1 */
1937 result
= strcmp(sk1
,sk2
);
1939 HeapFree(GetProcessHeap(),0,sk1
);
1946 /* must be greater, if we reach this point */
1950 /******************************************************************************
1951 * CompareStringW [KERNEL32.@]
1952 * This implementation ignores the locale
1953 * FIXME : Does only string sort. Should
1954 * be reimplemented the same way as CompareStringA.
1956 int WINAPI
CompareStringW(LCID lcid
, DWORD fdwStyle
,
1957 LPCWSTR s1
, int l1
, LPCWSTR s2
, int l2
)
1960 if(fdwStyle
& NORM_IGNORENONSPACE
)
1961 FIXME("IGNORENONSPACE not supported\n");
1962 if(fdwStyle
& NORM_IGNORESYMBOLS
)
1963 FIXME("IGNORESYMBOLS not supported\n");
1965 /* Is strcmp defaulting to string sort or to word sort?? */
1966 /* FIXME: Handle NORM_STRINGSORT */
1967 l1
= (l1
==-1)?strlenW(s1
):l1
;
1968 l2
= (l2
==-1)?strlenW(s2
):l2
;
1969 len
= l1
<l2
? l1
:l2
;
1970 ret
= (fdwStyle
& NORM_IGNORECASE
) ? strncmpiW(s1
,s2
,len
) : strncmpW(s1
,s2
,len
);
1971 /* not equal, return 1 or 3 */
1973 /* need to translate result */
1974 return ((int)ret
< 0) ? 1 : 3;
1976 /* same len, return 2 */
1977 if(l1
==l2
) return 2;
1978 /* the longer one is lexically greater */
1979 return (l1
<l2
)? 1 : 3;
1982 /******************************************************************************
1983 * OLE_GetFormatA [Internal]
1986 * If datelen == 0, it should return the reguired string length.
1988 This function implements stuff for GetDateFormat() and
1991 d single-digit (no leading zero) day (of month)
1992 dd two-digit day (of month)
1993 ddd short day-of-week name
1994 dddd long day-of-week name
1995 M single-digit month
1997 MMM short month name
1998 MMMM full month name
1999 y two-digit year, no leading 0
2001 yyyy four-digit year
2003 h hours with no leading zero (12-hour)
2004 hh hours with full two digits
2005 H hours with no leading zero (24-hour)
2006 HH hours with full two digits
2007 m minutes with no leading zero
2008 mm minutes with full two digits
2009 s seconds with no leading zero
2010 ss seconds with full two digits
2011 t time marker (A or P)
2012 tt time marker (AM, PM)
2013 '' used to quote literal characters
2014 '' (within a quoted string) indicates a literal '
2016 These functions REQUIRE valid locale, date, and format.
2018 static INT
OLE_GetFormatA(LCID locale
,
2021 const SYSTEMTIME
* xtime
,
2022 LPCSTR _format
, /*in*/
2027 int count
, type
, inquote
, Overflow
;
2033 const char * _dgfmt
[] = { "%d", "%02d" };
2034 const char ** dgfmt
= _dgfmt
- 1;
2036 /* report, for debugging */
2037 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",
2038 locale
, flags
, tflags
,
2039 xtime
->wYear
,xtime
->wMonth
,xtime
->wDayOfWeek
,xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2040 _format
, _format
, date
, datelen
);
2043 FIXME("datelen = 0, returning 255\n");
2047 /* initalize state variables and output buffer */
2049 count
= 0; inquote
= 0; Overflow
= 0;
2051 date
[0] = buf
[0] = '\0';
2053 strcpy(format
,_format
);
2055 /* alter the formatstring, while it works for all languages now in wine
2056 its possible that it fails when the time looks like ss:mm:hh as example*/
2057 if (tflags
& (TIME_NOMINUTESORSECONDS
))
2058 { if ((pos
= strstr ( format
, ":mm")))
2059 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2062 if (tflags
& (TIME_NOSECONDS
))
2063 { if ((pos
= strstr ( format
, ":ss")))
2064 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2068 for (inpos
= 0;; inpos
++) {
2069 /* 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]); */
2071 if (format
[inpos
] == '\'') {
2072 if (format
[inpos
+1] == '\'') {
2074 date
[outpos
++] = '\'';
2077 continue; /* we did nothing to the output */
2079 } else if (format
[inpos
] == '\0') {
2080 date
[outpos
++] = '\0';
2081 if (outpos
> datelen
) Overflow
= 1;
2084 date
[outpos
++] = format
[inpos
];
2085 if (outpos
> datelen
) {
2087 date
[outpos
-1] = '\0'; /* this is the last place where
2088 it's safe to write */
2092 } else if ( (count
&& (format
[inpos
] != type
))
2094 || (count
== 2 && strchr("ghHmst", type
)) ) {
2095 if (type
== 'h' && (tflags
& TIME_FORCE24HOURFORMAT
)) type
= 'H';
2098 GetLocaleInfoA(locale
,
2100 + (xtime
->wDayOfWeek
+6)%7,
2102 } else if (count
== 3) {
2103 GetLocaleInfoA(locale
,
2104 LOCALE_SABBREVDAYNAME1
2105 + (xtime
->wDayOfWeek
+6)%7,
2108 sprintf(buf
, dgfmt
[count
], xtime
->wDay
);
2110 } else if (type
== 'M') {
2112 GetLocaleInfoA(locale
,
2113 LOCALE_SABBREVMONTHNAME1
2114 + xtime
->wMonth
- 1,
2116 } else if (count
== 4) {
2117 GetLocaleInfoA(locale
,
2119 + xtime
->wMonth
- 1,
2122 sprintf(buf
, dgfmt
[count
], xtime
->wMonth
);
2124 } else if (type
== 'y') {
2126 sprintf(buf
, "%d", xtime
->wYear
);
2127 } else if (count
== 3) {
2129 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2131 sprintf(buf
, dgfmt
[count
], xtime
->wYear
% 100);
2133 } else if (type
== 'g') {
2135 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2139 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2141 } else if (type
== 'h') {
2142 /* gives us hours 1:00 -- 12:00 */
2143 sprintf(buf
, dgfmt
[count
], (xtime
->wHour
-1)%12 +1);
2144 } else if (type
== 'H') {
2146 sprintf(buf
, dgfmt
[count
], xtime
->wHour
);
2147 } else if ( type
== 'm') {
2148 sprintf(buf
, dgfmt
[count
], xtime
->wMinute
);
2149 } else if ( type
== 's') {
2150 sprintf(buf
, dgfmt
[count
], xtime
->wSecond
);
2151 } else if (type
== 't') {
2152 if ((tflags
& TIME_NOTIMEMARKER
))
2154 else if (count
== 1) {
2155 sprintf(buf
, "%c", (xtime
->wHour
< 12) ? 'A' : 'P');
2156 } else if (count
== 2) {
2157 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2158 GetLocaleInfoA(locale
,
2160 ? LOCALE_S1159
: LOCALE_S2359
,
2165 /* we need to check the next char in the format string
2166 again, no matter what happened */
2169 /* add the contents of buf to the output */
2170 buflen
= strlen(buf
);
2171 if (outpos
+ buflen
< datelen
) {
2172 date
[outpos
] = '\0'; /* for strcat to hook onto */
2176 date
[outpos
] = '\0';
2177 strncat(date
, buf
, datelen
- outpos
);
2178 date
[datelen
- 1] = '\0';
2179 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2180 WARN("insufficient buffer\n");
2184 /* reset the variables we used to keep track of this item */
2187 } else if (format
[inpos
] == '\0') {
2188 /* we can't check for this at the loop-head, because
2189 that breaks the printing of the last format-item */
2190 date
[outpos
] = '\0';
2193 /* continuing a code for an item */
2196 } else if (strchr("hHmstyMdg", format
[inpos
])) {
2197 type
= format
[inpos
];
2200 } else if (format
[inpos
] == '\'') {
2204 date
[outpos
++] = format
[inpos
];
2206 /* now deal with a possible buffer overflow */
2207 if (outpos
>= datelen
) {
2208 date
[datelen
- 1] = '\0';
2209 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2215 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2218 /* finish it off with a string terminator */
2221 if (outpos
> datelen
-1) outpos
= datelen
-1;
2222 date
[outpos
] = '\0';
2224 TRACE("returns string '%s', len %d\n", date
, outpos
);
2228 /******************************************************************************
2229 * OLE_GetFormatW [INTERNAL]
2231 static INT
OLE_GetFormatW(LCID locale
, DWORD flags
, DWORD tflags
,
2232 const SYSTEMTIME
* xtime
,
2234 LPWSTR output
, INT outlen
)
2237 int count
, type
=0, inquote
;
2238 int Overflow
; /* loop check */
2242 WCHAR arg0
[] = {0}, arg1
[] = {'%','d',0};
2243 WCHAR arg2
[] = {'%','0','2','d',0};
2245 int datevars
=0, timevars
=0;
2251 /* make a debug report */
2252 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2253 "%p with max len %d\n",
2254 locale
, flags
, tflags
,
2255 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2256 debugstr_w(format
), format
, output
, outlen
);
2259 FIXME("outlen = 0, returning 255\n");
2263 /* initialize state variables */
2266 inquote
= Overflow
= 0;
2267 /* this is really just a sanity check */
2268 output
[0] = buf
[0] = 0;
2270 /* this loop is the core of the function */
2271 for (inpos
= 0; /* we have several break points */ ; inpos
++) {
2273 if (format
[inpos
] == (WCHAR
) '\'') {
2274 if (format
[inpos
+1] == '\'') {
2276 output
[outpos
++] = '\'';
2281 } else if (format
[inpos
] == 0) {
2282 output
[outpos
++] = 0;
2283 if (outpos
> outlen
) Overflow
= 1;
2284 break; /* normal exit (within a quote) */
2286 output
[outpos
++] = format
[inpos
]; /* copy input */
2287 if (outpos
> outlen
) {
2289 output
[outpos
-1] = 0;
2293 } else if ( (count
&& (format
[inpos
] != type
))
2294 || ( (count
==4 && type
=='y') ||
2295 (count
==4 && type
=='M') ||
2296 (count
==4 && type
=='d') ||
2297 (count
==2 && type
=='g') ||
2298 (count
==2 && type
=='h') ||
2299 (count
==2 && type
=='H') ||
2300 (count
==2 && type
=='m') ||
2301 (count
==2 && type
=='s') ||
2302 (count
==2 && type
=='t') ) ) {
2307 GetLocaleInfoW(locale
,
2308 LOCALE_SDAYNAME1
+ (xtime
->wDayOfWeek
+6)%7,
2309 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2310 } else if (count
== 3) {
2311 GetLocaleInfoW(locale
,
2312 LOCALE_SABBREVDAYNAME1
+
2313 (xtime
->wDayOfWeek
+6)%7,
2314 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2316 sprintf( tmp
, "%.*d", count
, xtime
->wDay
);
2317 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2323 GetLocaleInfoW(locale
, LOCALE_SMONTHNAME1
+
2324 xtime
->wMonth
-1, buf
,
2325 sizeof(buf
)/sizeof(WCHAR
) );
2326 } else if (count
== 3) {
2327 GetLocaleInfoW(locale
, LOCALE_SABBREVMONTHNAME1
+
2328 xtime
->wMonth
-1, buf
,
2329 sizeof(buf
)/sizeof(WCHAR
) );
2331 sprintf( tmp
, "%.*d", count
, xtime
->wMonth
);
2332 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2337 sprintf( tmp
, "%d", xtime
->wYear
);
2338 } else if (count
== 3) {
2339 strcpy( tmp
, "yyy" );
2341 sprintf( tmp
, "%.*d", count
, xtime
->wYear
% 100 );
2343 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2348 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2349 strcpy( tmp
, "AD" );
2351 /* Win API sez we copy it verbatim */
2354 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2358 /* hours 1:00-12:00 --- is this right? */
2359 sprintf( tmp
, "%.*d", count
, (xtime
->wHour
-1)%12 +1);
2360 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2364 sprintf( tmp
, "%.*d", count
, xtime
->wHour
);
2365 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2369 sprintf( tmp
, "%.*d", count
, xtime
->wMinute
);
2370 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2374 sprintf( tmp
, "%.*d", count
, xtime
->wSecond
);
2375 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2379 GetLocaleInfoW(locale
, (xtime
->wHour
< 12) ?
2380 LOCALE_S1159
: LOCALE_S2359
,
2388 /* no matter what happened, we need to check this next
2389 character the next time we loop through */
2392 /* cat buf onto the output */
2393 outlen
= strlenW(buf
);
2394 if (outpos
+ buflen
< outlen
) {
2395 strcpyW( output
+ outpos
, buf
);
2398 lstrcpynW( output
+ outpos
, buf
, outlen
- outpos
);
2400 break; /* Abnormal exit */
2403 /* reset the variables we used this time */
2406 } else if (format
[inpos
] == 0) {
2407 /* we can't check for this at the beginning, because that
2408 would keep us from printing a format spec that ended the
2411 break; /* NORMAL EXIT */
2413 /* how we keep track of the middle of a format spec */
2416 } else if ( (datevars
&& (format
[inpos
]=='d' ||
2417 format
[inpos
]=='M' ||
2418 format
[inpos
]=='y' ||
2419 format
[inpos
]=='g') ) ||
2420 (timevars
&& (format
[inpos
]=='H' ||
2421 format
[inpos
]=='h' ||
2422 format
[inpos
]=='m' ||
2423 format
[inpos
]=='s' ||
2424 format
[inpos
]=='t') ) ) {
2425 type
= format
[inpos
];
2428 } else if (format
[inpos
] == '\'') {
2432 /* unquoted literals */
2433 output
[outpos
++] = format
[inpos
];
2438 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2439 WARN(" buffer overflow\n");
2442 /* final string terminator and sanity check */
2444 if (outpos
> outlen
-1) outpos
= outlen
-1;
2445 output
[outpos
] = '0';
2447 TRACE(" returning %s\n", debugstr_w(output
));
2449 return (!Overflow
) ? outlen
: 0;
2454 /******************************************************************************
2455 * GetDateFormatA [KERNEL32.@]
2456 * Makes an ASCII string of the date
2458 * This function uses format to format the date, or, if format
2459 * is NULL, uses the default for the locale. format is a string
2460 * of literal fields and characters as follows:
2462 * - d single-digit (no leading zero) day (of month)
2463 * - dd two-digit day (of month)
2464 * - ddd short day-of-week name
2465 * - dddd long day-of-week name
2466 * - M single-digit month
2467 * - MM two-digit month
2468 * - MMM short month name
2469 * - MMMM full month name
2470 * - y two-digit year, no leading 0
2471 * - yy two-digit year
2472 * - yyyy four-digit year
2476 INT WINAPI
GetDateFormatA(LCID locale
,DWORD flags
,
2477 const SYSTEMTIME
* xtime
,
2478 LPCSTR format
, LPSTR date
,INT datelen
)
2481 char format_buf
[40];
2484 LPSYSTEMTIME thistime
;
2490 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2491 locale
,flags
,xtime
,format
,date
,datelen
);
2494 locale
= LOCALE_SYSTEM_DEFAULT
;
2497 if (locale
== LOCALE_SYSTEM_DEFAULT
) {
2498 thislocale
= GetSystemDefaultLCID();
2499 } else if (locale
== LOCALE_USER_DEFAULT
) {
2500 thislocale
= GetUserDefaultLCID();
2502 thislocale
= locale
;
2505 if (xtime
== NULL
) {
2508 /* Silently correct wDayOfWeek by transforming to FileTime and back again */
2509 res
=SystemTimeToFileTime(xtime
,&ft
);
2510 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error */
2511 /*FIXME: SystemTimeToFileTime doesn't yet do that check */
2514 SetLastError(ERROR_INVALID_PARAMETER
);
2517 FileTimeToSystemTime(&ft
,&t
);
2522 if (format
== NULL
) {
2523 GetLocaleInfoA(thislocale
, ((flags
&DATE_LONGDATE
)
2525 : LOCALE_SSHORTDATE
),
2526 format_buf
, sizeof(format_buf
));
2527 thisformat
= format_buf
;
2529 thisformat
= format
;
2533 ret
= OLE_GetFormatA(thislocale
, flags
, 0, thistime
, thisformat
,
2538 "GetDateFormatA() returning %d, with data=%s\n",
2543 /******************************************************************************
2544 * GetDateFormatW [KERNEL32.@]
2545 * Makes a Unicode string of the date
2547 * Acts the same as GetDateFormatA(), except that it's Unicode.
2548 * Accepts & returns sizes as counts of Unicode characters.
2551 INT WINAPI
GetDateFormatW(LCID locale
,DWORD flags
,
2552 const SYSTEMTIME
* xtime
,
2554 LPWSTR date
, INT datelen
)
2556 unsigned short datearr
[] = {'1','9','9','4','-','1','-','1',0};
2558 FIXME("STUB (should call OLE_GetFormatW)\n");
2559 lstrcpynW(date
, datearr
, datelen
);
2560 return ( datelen
< 9) ? datelen
: 9;
2565 /**************************************************************************
2566 * EnumDateFormatsA (KERNEL32.@)
2568 BOOL WINAPI
EnumDateFormatsA(
2569 DATEFMT_ENUMPROCA lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2571 LCID Loc
= GetUserDefaultLCID();
2572 if(!lpDateFmtEnumProc
)
2574 SetLastError(ERROR_INVALID_PARAMETER
);
2581 case 0x00000407: /* (Loc,"de_DE") */
2585 case DATE_SHORTDATE
:
2586 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
2587 if(!(*lpDateFmtEnumProc
)("d.M.yyyy")) return TRUE
;
2588 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
2589 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2592 if(!(*lpDateFmtEnumProc
)("dddd,d. MMMM yyyy")) return TRUE
;
2593 if(!(*lpDateFmtEnumProc
)("d. MMMM yyyy")) return TRUE
;
2594 if(!(*lpDateFmtEnumProc
)("d. MMM yyyy")) return TRUE
;
2597 FIXME("Unknown date format (%ld)\n", dwFlags
);
2598 SetLastError(ERROR_INVALID_PARAMETER
);
2603 case 0x0000040c: /* (Loc,"fr_FR") */
2607 case DATE_SHORTDATE
:
2608 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2609 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
2610 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
2611 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2614 if(!(*lpDateFmtEnumProc
)("dddd d MMMM yyyy")) return TRUE
;
2615 if(!(*lpDateFmtEnumProc
)("d MMM yy")) return TRUE
;
2616 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2619 FIXME("Unknown date format (%ld)\n", dwFlags
);
2620 SetLastError(ERROR_INVALID_PARAMETER
);
2625 case 0x00000c0c: /* (Loc,"fr_CA") */
2629 case DATE_SHORTDATE
:
2630 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
2631 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
2632 if(!(*lpDateFmtEnumProc
)("yy MM dd")) return TRUE
;
2633 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2636 if(!(*lpDateFmtEnumProc
)("d MMMM, yyyy")) return TRUE
;
2637 if(!(*lpDateFmtEnumProc
)("d MMM yyyy")) return TRUE
;
2640 FIXME("Unknown date format (%ld)\n", dwFlags
);
2641 SetLastError(ERROR_INVALID_PARAMETER
);
2646 case 0x00000809: /* (Loc,"en_UK") */
2650 case DATE_SHORTDATE
:
2651 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2652 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2653 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2654 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2657 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
2658 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2661 FIXME("Unknown date format (%ld)\n", dwFlags
);
2662 SetLastError(ERROR_INVALID_PARAMETER
);
2667 case 0x00000c09: /* (Loc,"en_AU") */
2671 case DATE_SHORTDATE
:
2672 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
2673 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2674 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2677 if(!(*lpDateFmtEnumProc
)("dddd,d MMMM yyyy")) return TRUE
;
2678 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2681 FIXME("Unknown date format (%ld)\n", dwFlags
);
2682 SetLastError(ERROR_INVALID_PARAMETER
);
2687 case 0x00001009: /* (Loc,"en_CA") */
2691 case DATE_SHORTDATE
:
2692 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2693 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2694 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
2695 if(!(*lpDateFmtEnumProc
)("M/dd/yy")) return TRUE
;
2698 if(!(*lpDateFmtEnumProc
)("d-MMM-yy")) return TRUE
;
2699 if(!(*lpDateFmtEnumProc
)("MMMM d, yyyy")) return TRUE
;
2702 FIXME("Unknown date format (%ld)\n", dwFlags
);
2703 SetLastError(ERROR_INVALID_PARAMETER
);
2708 case 0x00001409: /* (Loc,"en_NZ") */
2712 case DATE_SHORTDATE
:
2713 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
2714 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2715 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
2718 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2719 if(!(*lpDateFmtEnumProc
)("dddd, d MMMM yyyy")) return TRUE
;
2722 FIXME("Unknown date format (%ld)\n", dwFlags
);
2723 SetLastError(ERROR_INVALID_PARAMETER
);
2728 case 0x00001809: /* (Loc,"en_IE") */
2732 case DATE_SHORTDATE
:
2733 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
2734 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
2735 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
2738 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
2739 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
2742 FIXME("Unknown date format (%ld)\n", dwFlags
);
2743 SetLastError(ERROR_INVALID_PARAMETER
);
2748 case 0x00001c09: /* (Loc,"en_ZA") */
2752 case DATE_SHORTDATE
:
2753 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
2756 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
2759 FIXME("Unknown date format (%ld)\n", dwFlags
);
2760 SetLastError(ERROR_INVALID_PARAMETER
);
2765 case 0x00002009: /* (Loc,"en_JM") */
2769 case DATE_SHORTDATE
:
2770 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2773 if(!(*lpDateFmtEnumProc
)("dddd,MMMM dd,yyyy")) return TRUE
;
2774 if(!(*lpDateFmtEnumProc
)("MMMM dd,yyyy")) return TRUE
;
2775 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM,yyyy")) return TRUE
;
2776 if(!(*lpDateFmtEnumProc
)("dd MMMM,yyyy")) return TRUE
;
2779 FIXME("Unknown date format (%ld)\n", dwFlags
);
2780 SetLastError(ERROR_INVALID_PARAMETER
);
2785 case 0x00002809: /* (Loc,"en_BZ") */
2786 case 0x00002c09: /* (Loc,"en_TT") */
2790 case DATE_SHORTDATE
:
2791 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
2794 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM yyyy")) return TRUE
;
2797 FIXME("Unknown date format (%ld)\n", dwFlags
);
2798 SetLastError(ERROR_INVALID_PARAMETER
);
2803 default: /* default to US English "en_US" */
2807 case DATE_SHORTDATE
:
2808 if(!(*lpDateFmtEnumProc
)("M/d/yy")) return TRUE
;
2809 if(!(*lpDateFmtEnumProc
)("M/d/yyyy")) return TRUE
;
2810 if(!(*lpDateFmtEnumProc
)("MM/dd/yy")) return TRUE
;
2811 if(!(*lpDateFmtEnumProc
)("MM/dd/yyyy")) return TRUE
;
2812 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
2813 if(!(*lpDateFmtEnumProc
)("dd-MMM-yy")) return TRUE
;
2816 if(!(*lpDateFmtEnumProc
)("dddd, MMMM dd, yyyy")) return TRUE
;
2817 if(!(*lpDateFmtEnumProc
)("MMMM dd, yyyy")) return TRUE
;
2818 if(!(*lpDateFmtEnumProc
)("dddd, dd MMMM, yyyy")) return TRUE
;
2819 if(!(*lpDateFmtEnumProc
)("dd MMMM, yyyy")) return TRUE
;
2822 FIXME("Unknown date format (%ld)\n", dwFlags
);
2823 SetLastError(ERROR_INVALID_PARAMETER
);
2830 /**************************************************************************
2831 * EnumDateFormatsW (KERNEL32.@)
2833 BOOL WINAPI
EnumDateFormatsW(
2834 DATEFMT_ENUMPROCW lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2836 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc
, Locale
, dwFlags
);
2837 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2841 /**************************************************************************
2842 * EnumTimeFormatsA (KERNEL32.@)
2844 BOOL WINAPI
EnumTimeFormatsA(
2845 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2847 LCID Loc
= GetUserDefaultLCID();
2848 if(!lpTimeFmtEnumProc
)
2850 SetLastError(ERROR_INVALID_PARAMETER
);
2855 FIXME("Unknown time format (%ld)\n", dwFlags
);
2860 case 0x00000407: /* (Loc,"de_DE") */
2862 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
2863 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2864 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2865 if(!(*lpTimeFmtEnumProc
)("H.mm")) return TRUE
;
2866 if(!(*lpTimeFmtEnumProc
)("H.mm'Uhr'")) return TRUE
;
2870 case 0x0000040c: /* (Loc,"fr_FR") */
2871 case 0x00000c0c: /* (Loc,"fr_CA") */
2873 if(!(*lpTimeFmtEnumProc
)("H:mm")) return TRUE
;
2874 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2875 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2876 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
2877 if(!(*lpTimeFmtEnumProc
)("HH'h'mm")) return TRUE
;
2881 case 0x00000809: /* (Loc,"en_UK") */
2882 case 0x00000c09: /* (Loc,"en_AU") */
2883 case 0x00001409: /* (Loc,"en_NZ") */
2884 case 0x00001809: /* (Loc,"en_IE") */
2886 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
2887 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2888 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2892 case 0x00001c09: /* (Loc,"en_ZA") */
2893 case 0x00002809: /* (Loc,"en_BZ") */
2894 case 0x00002c09: /* (Loc,"en_TT") */
2896 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
2897 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
2901 default: /* default to US style "en_US" */
2903 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
2904 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
2905 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
2906 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
2912 /**************************************************************************
2913 * EnumTimeFormatsW (KERNEL32.@)
2915 BOOL WINAPI
EnumTimeFormatsW(
2916 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
2918 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc
, Locale
, dwFlags
);
2919 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2923 /**************************************************************************
2924 * This function is used just locally !
2925 * Description: Inverts a string.
2927 static void OLE_InvertString(char* string
)
2929 char sTmpArray
[128];
2932 for (counter
= strlen(string
); counter
> 0; counter
--)
2934 memcpy(sTmpArray
+ i
, string
+ counter
-1, 1);
2937 memcpy(sTmpArray
+ i
, "\0", 1);
2938 strcpy(string
, sTmpArray
);
2941 /***************************************************************************************
2942 * This function is used just locally !
2943 * Description: Test if the given string (psNumber) is valid or not.
2944 * The valid characters are the following:
2945 * - Characters '0' through '9'.
2946 * - One decimal point (dot) if the number is a floating-point value.
2947 * - A minus sign in the first character position if the number is
2949 * If the function succeeds, psBefore/psAfter will point to the string
2950 * on the right/left of the decimal symbol. pbNegative indicates if the
2951 * number is negative.
2953 static INT
OLE_GetNumberComponents(char* pInput
, char* psBefore
, char* psAfter
, BOOL
* pbNegative
)
2955 char sNumberSet
[] = "0123456789";
2956 BOOL bInDecimal
= FALSE
;
2958 /* Test if we do have a minus sign */
2959 if ( *pInput
== '-' )
2962 pInput
++; /* Jump to the next character. */
2965 while(*pInput
!= '\0')
2967 /* Do we have a valid numeric character */
2968 if ( strchr(sNumberSet
, *pInput
) != NULL
)
2970 if (bInDecimal
== TRUE
)
2971 *psAfter
++ = *pInput
;
2973 *psBefore
++ = *pInput
;
2977 /* Is this a decimal point (dot) */
2978 if ( *pInput
== '.' )
2980 /* Is it the first time we find it */
2981 if ((bInDecimal
== FALSE
))
2984 return -1; /* ERROR: Invalid parameter */
2988 /* It's neither a numeric character, nor a decimal point.
2989 * Thus, return an error.
2997 /* Add an End of Line character to the output buffers */
3004 /**************************************************************************
3005 * This function is used just locally !
3006 * Description: A number could be formatted using different numbers
3007 * of "digits in group" (example: 4;3;2;0).
3008 * The first parameter of this function is an array
3009 * containing the rule to be used. Its format is the following:
3010 * |NDG|DG1|DG2|...|0|
3011 * where NDG is the number of used "digits in group" and DG1, DG2,
3012 * are the corresponding "digits in group".
3013 * Thus, this function returns the grouping value in the array
3014 * pointed by the second parameter.
3016 static INT
OLE_GetGrouping(char* sRule
, INT index
)
3018 char sData
[2], sRuleSize
[2];
3019 INT nData
, nRuleSize
;
3021 memcpy(sRuleSize
, sRule
, 1);
3022 memcpy(sRuleSize
+1, "\0", 1);
3023 nRuleSize
= atoi(sRuleSize
);
3025 if (index
> 0 && index
< nRuleSize
)
3027 memcpy(sData
, sRule
+index
, 1);
3028 memcpy(sData
+1, "\0", 1);
3029 nData
= atoi(sData
);
3034 memcpy(sData
, sRule
+nRuleSize
-1, 1);
3035 memcpy(sData
+1, "\0", 1);
3036 nData
= atoi(sData
);
3042 /**************************************************************************
3043 * GetNumberFormatA (KERNEL32.@)
3045 INT WINAPI
GetNumberFormatA(LCID locale
, DWORD dwflags
,
3046 LPCSTR lpvalue
, const NUMBERFMTA
* lpFormat
,
3047 LPSTR lpNumberStr
, int cchNumber
)
3049 char sNumberDigits
[3], sDecimalSymbol
[5], sDigitsInGroup
[11], sDigitGroupSymbol
[5], sILZero
[2];
3050 INT nNumberDigits
, nNumberDecimal
, i
, j
, nCounter
, nStep
, nRuleIndex
, nGrouping
, nDigits
, retVal
, nLZ
;
3051 char sNumber
[128], sDestination
[128], sDigitsAfterDecimal
[10], sDigitsBeforeDecimal
[128];
3052 char sRule
[10], sSemiColumn
[]=";", sBuffer
[5], sNegNumber
[2];
3053 char *pStr
= NULL
, *pTmpStr
= NULL
;
3054 LCID systemDefaultLCID
;
3055 BOOL bNegative
= FALSE
;
3064 strncpy(sNumber
, lpvalue
, 128);
3065 sNumber
[127] = '\0';
3067 /* Make sure we have a valid input string, get the number
3068 * of digits before and after the decimal symbol, and check
3069 * if this is a negative number.
3071 if ( OLE_GetNumberComponents(sNumber
, sDigitsBeforeDecimal
, sDigitsAfterDecimal
, &bNegative
) != -1)
3073 nNumberDecimal
= strlen(sDigitsBeforeDecimal
);
3074 nDigits
= strlen(sDigitsAfterDecimal
);
3078 SetLastError(ERROR_INVALID_PARAMETER
);
3082 /* Which source will we use to format the string */
3083 used_operation
= RETURN_ERROR
;
3084 if (lpFormat
!= NULL
)
3087 used_operation
= USE_PARAMETER
;
3091 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3092 used_operation
= USE_SYSTEMDEFAULT
;
3094 used_operation
= USE_LOCALEINFO
;
3097 /* Load the fields we need */
3098 switch(used_operation
)
3100 case USE_LOCALEINFO
:
3101 GetLocaleInfoA(locale
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3102 GetLocaleInfoA(locale
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3103 GetLocaleInfoA(locale
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3104 GetLocaleInfoA(locale
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3105 GetLocaleInfoA(locale
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3106 GetLocaleInfoA(locale
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3109 sprintf(sNumberDigits
, "%d",lpFormat
->NumDigits
);
3110 strcpy(sDecimalSymbol
, lpFormat
->lpDecimalSep
);
3111 sprintf(sDigitsInGroup
, "%d;0",lpFormat
->Grouping
);
3112 strcpy(sDigitGroupSymbol
, lpFormat
->lpThousandSep
);
3113 sprintf(sILZero
, "%d",lpFormat
->LeadingZero
);
3114 sprintf(sNegNumber
, "%d",lpFormat
->NegativeOrder
);
3116 case USE_SYSTEMDEFAULT
:
3117 systemDefaultLCID
= GetSystemDefaultLCID();
3118 GetLocaleInfoA(systemDefaultLCID
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3119 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3120 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3121 GetLocaleInfoA(systemDefaultLCID
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3122 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3123 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3126 SetLastError(ERROR_INVALID_PARAMETER
);
3130 nNumberDigits
= atoi(sNumberDigits
);
3132 /* Remove the ";" */
3135 for (nCounter
=0; nCounter
<strlen(sDigitsInGroup
); nCounter
++)
3137 if ( memcmp(sDigitsInGroup
+ nCounter
, sSemiColumn
, 1) != 0 )
3139 memcpy(sRule
+ j
, sDigitsInGroup
+ nCounter
, 1);
3144 sprintf(sBuffer
, "%d", i
);
3145 memcpy(sRule
, sBuffer
, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3146 memcpy(sRule
+ j
, "\0", 1);
3148 /* First, format the digits before the decimal. */
3149 if ((nNumberDecimal
>0) && (atoi(sDigitsBeforeDecimal
) != 0))
3151 /* Working on an inverted string is easier ! */
3152 OLE_InvertString(sDigitsBeforeDecimal
);
3154 nStep
= nCounter
= i
= j
= 0;
3156 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3158 /* Here, we will loop until we reach the end of the string.
3159 * An internal counter (j) is used in order to know when to
3160 * insert the "digit group symbol".
3162 while (nNumberDecimal
> 0)
3164 i
= nCounter
+ nStep
;
3165 memcpy(sDestination
+ i
, sDigitsBeforeDecimal
+ nCounter
, 1);
3171 if (nRuleIndex
< sRule
[0])
3173 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3174 memcpy(sDestination
+ i
+1, sDigitGroupSymbol
, strlen(sDigitGroupSymbol
));
3175 nStep
+= strlen(sDigitGroupSymbol
);
3181 memcpy(sDestination
+ i
+1, "\0", 1);
3182 /* Get the string in the right order ! */
3183 OLE_InvertString(sDestination
);
3187 nLZ
= atoi(sILZero
);
3190 /* Use 0.xxx instead of .xxx */
3191 memcpy(sDestination
, "0", 1);
3192 memcpy(sDestination
+1, "\0", 1);
3195 memcpy(sDestination
, "\0", 1);
3199 /* Second, format the digits after the decimal. */
3201 nCounter
= nNumberDigits
;
3202 if ( (nDigits
>0) && (pStr
= strstr (sNumber
, ".")) )
3204 i
= strlen(sNumber
) - strlen(pStr
) + 1;
3205 strncpy ( sDigitsAfterDecimal
, sNumber
+ i
, nNumberDigits
);
3206 j
= strlen(sDigitsAfterDecimal
);
3207 if (j
< nNumberDigits
)
3208 nCounter
= nNumberDigits
-j
;
3210 for (i
=0;i
<nCounter
;i
++)
3211 memcpy(sDigitsAfterDecimal
+i
+j
, "0", 1);
3212 memcpy(sDigitsAfterDecimal
+ nNumberDigits
, "\0", 1);
3214 i
= strlen(sDestination
);
3215 j
= strlen(sDigitsAfterDecimal
);
3216 /* Finally, construct the resulting formatted string. */
3218 for (nCounter
=0; nCounter
<i
; nCounter
++)
3219 memcpy(sNumber
+ nCounter
, sDestination
+ nCounter
, 1);
3221 memcpy(sNumber
+ nCounter
, sDecimalSymbol
, strlen(sDecimalSymbol
));
3224 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), sDigitsAfterDecimal
+ i
, 1);
3225 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), "\0", 1);
3227 /* Is it a negative number */
3228 if (bNegative
== TRUE
)
3230 i
= atoi(sNegNumber
);
3231 pStr
= sDestination
;
3237 while (*sNumber
!= '\0')
3238 *pStr
++ = *pTmpStr
++;
3243 while (*pTmpStr
!= '\0')
3244 *pStr
++ = *pTmpStr
++;
3249 while (*pTmpStr
!= '\0')
3250 *pStr
++ = *pTmpStr
++;
3253 while (*pTmpStr
!= '\0')
3254 *pStr
++ = *pTmpStr
++;
3258 while (*pTmpStr
!= '\0')
3259 *pStr
++ = *pTmpStr
++;
3264 while (*pTmpStr
!= '\0')
3265 *pStr
++ = *pTmpStr
++;
3270 strcpy(sDestination
, sNumber
);
3272 /* If cchNumber is zero, then returns the number of bytes or characters
3273 * required to hold the formatted number string
3275 retVal
= strlen(sDestination
) + 1;
3278 memcpy( lpNumberStr
, sDestination
, min(cchNumber
, retVal
) );
3279 if (cchNumber
< retVal
) retVal
= 0;
3284 /**************************************************************************
3285 * GetNumberFormatW (KERNEL32.@)
3287 INT WINAPI
GetNumberFormatW(LCID locale
, DWORD dwflags
,
3288 LPCWSTR lpvalue
, const NUMBERFMTW
* lpFormat
,
3289 LPWSTR lpNumberStr
, int cchNumber
)
3291 FIXME("%s: stub, no reformatting done\n",debugstr_w(lpvalue
));
3293 lstrcpynW( lpNumberStr
, lpvalue
, cchNumber
);
3294 return cchNumber
? strlenW( lpNumberStr
) : 0;
3297 /**************************************************************************
3298 * GetCurrencyFormatA (KERNEL32.@)
3300 INT WINAPI
GetCurrencyFormatA(LCID locale
, DWORD dwflags
,
3301 LPCSTR lpvalue
, const CURRENCYFMTA
* lpFormat
,
3302 LPSTR lpCurrencyStr
, int cchCurrency
)
3304 UINT nPosOrder
, nNegOrder
;
3306 char sDestination
[128], sNegOrder
[8], sPosOrder
[8], sCurrencySymbol
[8];
3307 char *pDestination
= sDestination
;
3308 char sNumberFormated
[128];
3309 char *pNumberFormated
= sNumberFormated
;
3310 LCID systemDefaultLCID
;
3311 BOOL bIsPositive
= FALSE
, bValidFormat
= FALSE
;
3320 NUMBERFMTA numberFmt
;
3322 /* Which source will we use to format the string */
3323 used_operation
= RETURN_ERROR
;
3324 if (lpFormat
!= NULL
)
3327 used_operation
= USE_PARAMETER
;
3331 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3332 used_operation
= USE_SYSTEMDEFAULT
;
3334 used_operation
= USE_LOCALEINFO
;
3337 /* Load the fields we need */
3338 switch(used_operation
)
3340 case USE_LOCALEINFO
:
3341 /* Specific to CURRENCYFMTA */
3342 GetLocaleInfoA(locale
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3343 GetLocaleInfoA(locale
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3344 GetLocaleInfoA(locale
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3346 nPosOrder
= atoi(sPosOrder
);
3347 nNegOrder
= atoi(sNegOrder
);
3350 /* Specific to CURRENCYFMTA */
3351 nNegOrder
= lpFormat
->NegativeOrder
;
3352 nPosOrder
= lpFormat
->PositiveOrder
;
3353 strcpy(sCurrencySymbol
, lpFormat
->lpCurrencySymbol
);
3355 case USE_SYSTEMDEFAULT
:
3356 systemDefaultLCID
= GetSystemDefaultLCID();
3357 /* Specific to CURRENCYFMTA */
3358 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3359 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3360 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3362 nPosOrder
= atoi(sPosOrder
);
3363 nNegOrder
= atoi(sNegOrder
);
3366 SetLastError(ERROR_INVALID_PARAMETER
);
3370 /* Construct a temporary number format structure */
3371 if (lpFormat
!= NULL
)
3373 numberFmt
.NumDigits
= lpFormat
->NumDigits
;
3374 numberFmt
.LeadingZero
= lpFormat
->LeadingZero
;
3375 numberFmt
.Grouping
= lpFormat
->Grouping
;
3376 numberFmt
.NegativeOrder
= 0;
3377 numberFmt
.lpDecimalSep
= lpFormat
->lpDecimalSep
;
3378 numberFmt
.lpThousandSep
= lpFormat
->lpThousandSep
;
3379 bValidFormat
= TRUE
;
3382 /* Make a call to GetNumberFormatA() */
3383 if (*lpvalue
== '-')
3385 bIsPositive
= FALSE
;
3386 retVal
= GetNumberFormatA(locale
,0,lpvalue
+1,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3391 retVal
= GetNumberFormatA(locale
,0,lpvalue
,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3397 /* construct the formatted string */
3402 case 0: /* Prefix, no separation */
3403 strcpy (pDestination
, sCurrencySymbol
);
3404 strcat (pDestination
, pNumberFormated
);
3406 case 1: /* Suffix, no separation */
3407 strcpy (pDestination
, pNumberFormated
);
3408 strcat (pDestination
, sCurrencySymbol
);
3410 case 2: /* Prefix, 1 char separation */
3411 strcpy (pDestination
, sCurrencySymbol
);
3412 strcat (pDestination
, " ");
3413 strcat (pDestination
, pNumberFormated
);
3415 case 3: /* Suffix, 1 char separation */
3416 strcpy (pDestination
, pNumberFormated
);
3417 strcat (pDestination
, " ");
3418 strcat (pDestination
, sCurrencySymbol
);
3421 SetLastError(ERROR_INVALID_PARAMETER
);
3425 else /* negative number */
3429 case 0: /* format: ($1.1) */
3430 strcpy (pDestination
, "(");
3431 strcat (pDestination
, sCurrencySymbol
);
3432 strcat (pDestination
, pNumberFormated
);
3433 strcat (pDestination
, ")");
3435 case 1: /* format: -$1.1 */
3436 strcpy (pDestination
, "-");
3437 strcat (pDestination
, sCurrencySymbol
);
3438 strcat (pDestination
, pNumberFormated
);
3440 case 2: /* format: $-1.1 */
3441 strcpy (pDestination
, sCurrencySymbol
);
3442 strcat (pDestination
, "-");
3443 strcat (pDestination
, pNumberFormated
);
3445 case 3: /* format: $1.1- */
3446 strcpy (pDestination
, sCurrencySymbol
);
3447 strcat (pDestination
, pNumberFormated
);
3448 strcat (pDestination
, "-");
3450 case 4: /* format: (1.1$) */
3451 strcpy (pDestination
, "(");
3452 strcat (pDestination
, pNumberFormated
);
3453 strcat (pDestination
, sCurrencySymbol
);
3454 strcat (pDestination
, ")");
3456 case 5: /* format: -1.1$ */
3457 strcpy (pDestination
, "-");
3458 strcat (pDestination
, pNumberFormated
);
3459 strcat (pDestination
, sCurrencySymbol
);
3461 case 6: /* format: 1.1-$ */
3462 strcpy (pDestination
, pNumberFormated
);
3463 strcat (pDestination
, "-");
3464 strcat (pDestination
, sCurrencySymbol
);
3466 case 7: /* format: 1.1$- */
3467 strcpy (pDestination
, pNumberFormated
);
3468 strcat (pDestination
, sCurrencySymbol
);
3469 strcat (pDestination
, "-");
3471 case 8: /* format: -1.1 $ */
3472 strcpy (pDestination
, "-");
3473 strcat (pDestination
, pNumberFormated
);
3474 strcat (pDestination
, " ");
3475 strcat (pDestination
, sCurrencySymbol
);
3477 case 9: /* format: -$ 1.1 */
3478 strcpy (pDestination
, "-");
3479 strcat (pDestination
, sCurrencySymbol
);
3480 strcat (pDestination
, " ");
3481 strcat (pDestination
, pNumberFormated
);
3483 case 10: /* format: 1.1 $- */
3484 strcpy (pDestination
, pNumberFormated
);
3485 strcat (pDestination
, " ");
3486 strcat (pDestination
, sCurrencySymbol
);
3487 strcat (pDestination
, "-");
3489 case 11: /* format: $ 1.1- */
3490 strcpy (pDestination
, sCurrencySymbol
);
3491 strcat (pDestination
, " ");
3492 strcat (pDestination
, pNumberFormated
);
3493 strcat (pDestination
, "-");
3495 case 12: /* format: $ -1.1 */
3496 strcpy (pDestination
, sCurrencySymbol
);
3497 strcat (pDestination
, " ");
3498 strcat (pDestination
, "-");
3499 strcat (pDestination
, pNumberFormated
);
3501 case 13: /* format: 1.1- $ */
3502 strcpy (pDestination
, pNumberFormated
);
3503 strcat (pDestination
, "-");
3504 strcat (pDestination
, " ");
3505 strcat (pDestination
, sCurrencySymbol
);
3507 case 14: /* format: ($ 1.1) */
3508 strcpy (pDestination
, "(");
3509 strcat (pDestination
, sCurrencySymbol
);
3510 strcat (pDestination
, " ");
3511 strcat (pDestination
, pNumberFormated
);
3512 strcat (pDestination
, ")");
3514 case 15: /* format: (1.1 $) */
3515 strcpy (pDestination
, "(");
3516 strcat (pDestination
, pNumberFormated
);
3517 strcat (pDestination
, " ");
3518 strcat (pDestination
, sCurrencySymbol
);
3519 strcat (pDestination
, ")");
3522 SetLastError(ERROR_INVALID_PARAMETER
);
3527 retVal
= strlen(pDestination
) + 1;
3531 memcpy( lpCurrencyStr
, pDestination
, min(cchCurrency
, retVal
) );
3532 if (cchCurrency
< retVal
) retVal
= 0;
3537 /**************************************************************************
3538 * GetCurrencyFormatW (KERNEL32.@)
3540 INT WINAPI
GetCurrencyFormatW(LCID locale
, DWORD dwflags
,
3541 LPCWSTR lpvalue
, const CURRENCYFMTW
* lpFormat
,
3542 LPWSTR lpCurrencyStr
, int cchCurrency
)
3544 FIXME("This API function is NOT implemented !\n");
3548 /******************************************************************************
3549 * OLE2NLS_CheckLocale [intern]
3551 static LCID
OLE2NLS_CheckLocale (LCID locale
)
3554 { locale
= LOCALE_SYSTEM_DEFAULT
;
3557 if (locale
== LOCALE_SYSTEM_DEFAULT
)
3558 { return GetSystemDefaultLCID();
3560 else if (locale
== LOCALE_USER_DEFAULT
)
3561 { return GetUserDefaultLCID();
3567 /******************************************************************************
3568 * GetTimeFormatA [KERNEL32.@]
3569 * Makes an ASCII string of the time
3571 * Formats date according to format, or locale default if format is
3572 * NULL. The format consists of literal characters and fields as follows:
3574 * h hours with no leading zero (12-hour)
3575 * hh hours with full two digits
3576 * H hours with no leading zero (24-hour)
3577 * HH hours with full two digits
3578 * m minutes with no leading zero
3579 * mm minutes with full two digits
3580 * s seconds with no leading zero
3581 * ss seconds with full two digits
3582 * t time marker (A or P)
3583 * tt time marker (AM, PM)
3587 GetTimeFormatA(LCID locale
, /* [in] */
3588 DWORD flags
, /* [in] */
3589 const SYSTEMTIME
* xtime
, /* [in] */
3590 LPCSTR format
, /* [in] */
3591 LPSTR timestr
, /* [out] */
3592 INT timelen
/* [in] */)
3593 { char format_buf
[40];
3596 const SYSTEMTIME
* thistime
;
3598 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standard timeformat */
3601 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,xtime
,format
,timestr
,timelen
);
3603 thislocale
= OLE2NLS_CheckLocale ( locale
);
3606 { if (flags
& LOCALE_NOUSEROVERRIDE
) /* use system default */
3607 { thislocale
= GetSystemDefaultLCID();
3609 GetLocaleInfoA(thislocale
, thisflags
, format_buf
, sizeof(format_buf
));
3610 thisformat
= format_buf
;
3613 { thisformat
= format
;
3616 if (xtime
== NULL
) /* NULL means use the current local time */
3622 /* Check that hour,min and sec is in range */
3624 ret
= OLE_GetFormatA(thislocale
, thisflags
, flags
, thistime
, thisformat
,
3630 /******************************************************************************
3631 * GetTimeFormatW [KERNEL32.@]
3632 * Makes a Unicode string of the time
3635 GetTimeFormatW(LCID locale
, /* [in] */
3636 DWORD flags
, /* [in] */
3637 const SYSTEMTIME
* xtime
, /* [in] */
3638 LPCWSTR format
, /* [in] */
3639 LPWSTR timestr
, /* [out] */
3640 INT timelen
/* [in] */)
3641 { WCHAR format_buf
[40];
3644 const SYSTEMTIME
* thistime
;
3646 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standard timeformat */
3649 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,
3650 xtime
,debugstr_w(format
),timestr
,timelen
);
3652 thislocale
= OLE2NLS_CheckLocale ( locale
);
3655 { if (flags
& LOCALE_NOUSEROVERRIDE
) /* use system default */
3656 { thislocale
= GetSystemDefaultLCID();
3658 GetLocaleInfoW(thislocale
, thisflags
, format_buf
, 40);
3659 thisformat
= format_buf
;
3662 { thisformat
= format
;
3665 if (xtime
== NULL
) /* NULL means use the current local time */
3673 ret
= OLE_GetFormatW(thislocale
, thisflags
, flags
, thistime
, thisformat
,
3678 /******************************************************************************
3679 * EnumCalendarInfoA [KERNEL32.@]
3681 BOOL WINAPI
EnumCalendarInfoA(
3682 CALINFO_ENUMPROCA calinfoproc
,LCID locale
,CALID calendar
,CALTYPE caltype
3684 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc
,locale
,calendar
,caltype
);