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
17 #include "wine/unicode.h"
24 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(string
);
29 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
30 * MUST contain all #defines from winnls.h
31 * last entry has NULL name, 0 id.
33 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
34 static const struct tagLOCALE_NAME2ID
{
38 LOCALE_ENTRY(ILANGUAGE
),
39 LOCALE_ENTRY(SLANGUAGE
),
40 LOCALE_ENTRY(SENGLANGUAGE
),
41 LOCALE_ENTRY(SABBREVLANGNAME
),
42 LOCALE_ENTRY(SNATIVELANGNAME
),
43 LOCALE_ENTRY(ICOUNTRY
),
44 LOCALE_ENTRY(SCOUNTRY
),
45 LOCALE_ENTRY(SENGCOUNTRY
),
46 LOCALE_ENTRY(SABBREVCTRYNAME
),
47 LOCALE_ENTRY(SNATIVECTRYNAME
),
48 LOCALE_ENTRY(IDEFAULTLANGUAGE
),
49 LOCALE_ENTRY(IDEFAULTCOUNTRY
),
50 LOCALE_ENTRY(IDEFAULTCODEPAGE
),
51 LOCALE_ENTRY(IDEFAULTANSICODEPAGE
),
52 LOCALE_ENTRY(IDEFAULTMACCODEPAGE
),
54 LOCALE_ENTRY(IMEASURE
),
55 LOCALE_ENTRY(SDECIMAL
),
56 LOCALE_ENTRY(STHOUSAND
),
57 LOCALE_ENTRY(SGROUPING
),
58 LOCALE_ENTRY(IDIGITS
),
60 LOCALE_ENTRY(INEGNUMBER
),
61 LOCALE_ENTRY(SNATIVEDIGITS
),
62 LOCALE_ENTRY(SCURRENCY
),
63 LOCALE_ENTRY(SINTLSYMBOL
),
64 LOCALE_ENTRY(SMONDECIMALSEP
),
65 LOCALE_ENTRY(SMONTHOUSANDSEP
),
66 LOCALE_ENTRY(SMONGROUPING
),
67 LOCALE_ENTRY(ICURRDIGITS
),
68 LOCALE_ENTRY(IINTLCURRDIGITS
),
69 LOCALE_ENTRY(ICURRENCY
),
70 LOCALE_ENTRY(INEGCURR
),
73 LOCALE_ENTRY(SSHORTDATE
),
74 LOCALE_ENTRY(SLONGDATE
),
75 LOCALE_ENTRY(STIMEFORMAT
),
79 LOCALE_ENTRY(ITIMEMARKPOSN
),
80 LOCALE_ENTRY(ICENTURY
),
81 LOCALE_ENTRY(ITLZERO
),
82 LOCALE_ENTRY(IDAYLZERO
),
83 LOCALE_ENTRY(IMONLZERO
),
86 LOCALE_ENTRY(ICALENDARTYPE
),
87 LOCALE_ENTRY(IOPTIONALCALENDAR
),
88 LOCALE_ENTRY(IFIRSTDAYOFWEEK
),
89 LOCALE_ENTRY(IFIRSTWEEKOFYEAR
),
90 LOCALE_ENTRY(SDAYNAME1
),
91 LOCALE_ENTRY(SDAYNAME2
),
92 LOCALE_ENTRY(SDAYNAME3
),
93 LOCALE_ENTRY(SDAYNAME4
),
94 LOCALE_ENTRY(SDAYNAME5
),
95 LOCALE_ENTRY(SDAYNAME6
),
96 LOCALE_ENTRY(SDAYNAME7
),
97 LOCALE_ENTRY(SABBREVDAYNAME1
),
98 LOCALE_ENTRY(SABBREVDAYNAME2
),
99 LOCALE_ENTRY(SABBREVDAYNAME3
),
100 LOCALE_ENTRY(SABBREVDAYNAME4
),
101 LOCALE_ENTRY(SABBREVDAYNAME5
),
102 LOCALE_ENTRY(SABBREVDAYNAME6
),
103 LOCALE_ENTRY(SABBREVDAYNAME7
),
104 LOCALE_ENTRY(SMONTHNAME1
),
105 LOCALE_ENTRY(SMONTHNAME2
),
106 LOCALE_ENTRY(SMONTHNAME3
),
107 LOCALE_ENTRY(SMONTHNAME4
),
108 LOCALE_ENTRY(SMONTHNAME5
),
109 LOCALE_ENTRY(SMONTHNAME6
),
110 LOCALE_ENTRY(SMONTHNAME7
),
111 LOCALE_ENTRY(SMONTHNAME8
),
112 LOCALE_ENTRY(SMONTHNAME9
),
113 LOCALE_ENTRY(SMONTHNAME10
),
114 LOCALE_ENTRY(SMONTHNAME11
),
115 LOCALE_ENTRY(SMONTHNAME12
),
116 LOCALE_ENTRY(SMONTHNAME13
),
117 LOCALE_ENTRY(SABBREVMONTHNAME1
),
118 LOCALE_ENTRY(SABBREVMONTHNAME2
),
119 LOCALE_ENTRY(SABBREVMONTHNAME3
),
120 LOCALE_ENTRY(SABBREVMONTHNAME4
),
121 LOCALE_ENTRY(SABBREVMONTHNAME5
),
122 LOCALE_ENTRY(SABBREVMONTHNAME6
),
123 LOCALE_ENTRY(SABBREVMONTHNAME7
),
124 LOCALE_ENTRY(SABBREVMONTHNAME8
),
125 LOCALE_ENTRY(SABBREVMONTHNAME9
),
126 LOCALE_ENTRY(SABBREVMONTHNAME10
),
127 LOCALE_ENTRY(SABBREVMONTHNAME11
),
128 LOCALE_ENTRY(SABBREVMONTHNAME12
),
129 LOCALE_ENTRY(SABBREVMONTHNAME13
),
130 LOCALE_ENTRY(SPOSITIVESIGN
),
131 LOCALE_ENTRY(SNEGATIVESIGN
),
132 LOCALE_ENTRY(IPOSSIGNPOSN
),
133 LOCALE_ENTRY(INEGSIGNPOSN
),
134 LOCALE_ENTRY(IPOSSYMPRECEDES
),
135 LOCALE_ENTRY(IPOSSEPBYSPACE
),
136 LOCALE_ENTRY(INEGSYMPRECEDES
),
137 LOCALE_ENTRY(INEGSEPBYSPACE
),
138 LOCALE_ENTRY(FONTSIGNATURE
),
139 LOCALE_ENTRY(SISO639LANGNAME
),
140 LOCALE_ENTRY(SISO3166CTRYNAME
),
144 static char *GetLocaleSubkeyName( DWORD lctype
);
146 /***********************************************************************
147 * GetUserDefaultLCID [KERNEL32.425]
149 LCID WINAPI
GetUserDefaultLCID(void)
151 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT
);
154 /***********************************************************************
155 * GetSystemDefaultLCID [KERNEL32.400]
157 LCID WINAPI
GetSystemDefaultLCID(void)
159 return GetUserDefaultLCID();
162 #define NLS_MAX_LANGUAGES 20
166 LANGID found_lang_id
[NLS_MAX_LANGUAGES
];
167 char found_language
[NLS_MAX_LANGUAGES
][3];
168 char found_country
[NLS_MAX_LANGUAGES
][3];
172 static BOOL CALLBACK
NLS_FindLanguageID_ProcA(HMODULE hModule
, LPCSTR type
,
173 LPCSTR name
, WORD LangID
, LONG lParam
)
175 LANG_FIND_DATA
*l_data
= (LANG_FIND_DATA
*)lParam
;
176 LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
177 char buf_language
[128];
178 char buf_country
[128];
179 char buf_en_language
[128];
181 TRACE("%04X\n", (UINT
)LangID
);
182 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
183 return TRUE
; /* continue search */
188 GetLocaleInfoA(lcid
, LOCALE_SISO639LANGNAME
|LOCALE_NOUSEROVERRIDE
,
189 buf_language
, sizeof(buf_language
));
190 TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language
);
192 GetLocaleInfoA(lcid
, LOCALE_SISO3166CTRYNAME
|LOCALE_NOUSEROVERRIDE
,
193 buf_country
, sizeof(buf_country
));
194 TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country
);
196 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_language
))
198 if(l_data
->country
&& strlen(l_data
->country
) > 0)
200 if(!strcasecmp(l_data
->country
, buf_country
))
202 l_data
->found_lang_id
[0] = LangID
;
204 TRACE("Found lang_id %04X for %s_%s\n", LangID
, l_data
->lang
, l_data
->country
);
205 return FALSE
; /* stop enumeration */
208 else /* l_data->country not specified */
210 if(l_data
->n_found
< NLS_MAX_LANGUAGES
)
212 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
213 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
214 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
216 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
217 return TRUE
; /* continue search */
222 /* Just in case, check LOCALE_SENGLANGUAGE too,
223 * in hope that possible alias name might have that value.
225 buf_en_language
[0] = 0;
226 GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
|LOCALE_NOUSEROVERRIDE
,
227 buf_en_language
, sizeof(buf_en_language
));
228 TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language
);
230 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_en_language
))
232 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
233 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
234 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
236 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
239 return TRUE
; /* continue search */
242 /***********************************************************************
246 * Lang: a string whose two first chars are the iso name of a language.
247 * Country: a string whose two first chars are the iso name of country
248 * Charset: a string defining the chossen charset encoding
249 * Dialect: a string defining a variation of the locale
251 * all those values are from the standardized format of locale
252 * name in unix which is: Lang[_Country][.Charset][@Dialect]
255 * the numeric code of the language used by Windows
257 * FIXME: Charset and Dialect are not handled
259 static LANGID
NLS_GetLanguageID(LPCSTR Lang
, LPCSTR Country
, LPCSTR Charset
, LPCSTR Dialect
)
261 LANG_FIND_DATA l_data
;
262 char lang_string
[256];
266 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
270 memset(&l_data
, 0, sizeof(LANG_FIND_DATA
));
271 strncpy(l_data
.lang
, Lang
, sizeof(l_data
.lang
));
273 if(Country
&& strlen(Country
) > 0)
274 strncpy(l_data
.country
, Country
, sizeof(l_data
.country
));
276 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
277 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
279 strcpy(lang_string
, l_data
.lang
);
280 if(l_data
.country
&& strlen(l_data
.country
) > 0)
282 strcat(lang_string
, "_");
283 strcat(lang_string
, l_data
.country
);
288 if(l_data
.country
&& strlen(l_data
.country
) > 0)
290 MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string
);
291 l_data
.country
[0] = 0;
292 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
293 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
297 /* Re-evaluate lang_string */
298 strcpy(lang_string
, l_data
.lang
);
299 if(l_data
.country
&& strlen(l_data
.country
) > 0)
301 strcat(lang_string
, "_");
302 strcat(lang_string
, l_data
.country
);
307 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string
);
308 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
312 if(l_data
.n_found
== 1)
313 TRACE("For language '%s' lang_id %04X was found\n", lang_string
, l_data
.found_lang_id
[0]);
314 else /* l_data->n_found > 1 */
317 MESSAGE("For language '%s' several language ids were found:\n", lang_string
);
318 for(i
= 0; i
< l_data
.n_found
; i
++)
319 MESSAGE("%s_%s - %04X; ", l_data
.found_language
[i
], l_data
.found_country
[i
], l_data
.found_lang_id
[i
]);
321 MESSAGE("\nInstead of using first in the list, suggest to define\n"
322 "your LANG environment variable like this: LANG=%s_%s\n",
323 l_data
.found_language
[0], l_data
.found_country
[0]);
327 TRACE("Returning %04X\n", l_data
.found_lang_id
[0]);
328 return l_data
.found_lang_id
[0];
331 /***********************************************************************
332 * GetUserDefaultLangID [KERNEL32.426]
334 LANGID WINAPI
GetUserDefaultLangID(void)
336 /* caching result, if defined from environment, which should (?) not change during a WINE session */
337 static LANGID userLCID
= 0;
342 char *lang
,*country
,*charset
,*dialect
,*next
;
344 if (GetEnvironmentVariableA( "LANGUAGE", buf
, sizeof(buf
) )) goto ok
;
345 if (GetEnvironmentVariableA( "LANG", buf
, sizeof(buf
) )) goto ok
;
346 if (GetEnvironmentVariableA( "LC_ALL", buf
, sizeof(buf
) )) goto ok
;
347 if (GetEnvironmentVariableA( "LC_MESSAGES", buf
, sizeof(buf
) )) goto ok
;
348 if (GetEnvironmentVariableA( "LC_CTYPE", buf
, sizeof(buf
) )) goto ok
;
350 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
353 if (!strcmp(buf
,"POSIX") || !strcmp(buf
,"C"))
354 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
359 next
=strchr(lang
,':'); if (next
) *next
++='\0';
360 dialect
=strchr(lang
,'@'); if (dialect
) *dialect
++='\0';
361 charset
=strchr(lang
,'.'); if (charset
) *charset
++='\0';
362 country
=strchr(lang
,'_'); if (country
) *country
++='\0';
364 userLCID
= NLS_GetLanguageID(lang
, country
, charset
, dialect
);
367 } while (lang
&& !userLCID
);
371 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
373 userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
379 /***********************************************************************
380 * GetSystemDefaultLangID [KERNEL32.401]
382 LANGID WINAPI
GetSystemDefaultLangID(void)
384 return GetUserDefaultLangID();
387 /******************************************************************************
388 * ConvertDefaultLocale [KERNEL32.147]
390 LCID WINAPI
ConvertDefaultLocale (LCID lcid
)
392 { case LOCALE_SYSTEM_DEFAULT
:
393 return GetSystemDefaultLCID();
394 case LOCALE_USER_DEFAULT
:
395 return GetUserDefaultLCID();
397 return MAKELCID (LANG_NEUTRAL
, SUBLANG_NEUTRAL
);
399 return MAKELANGID( PRIMARYLANGID(lcid
), SUBLANG_NEUTRAL
);
402 /* Enhanced version of LoadStringW.
403 * It takes LanguageId to find and load language dependant resources.
404 * Resource is copied as is: "binary" strings are not truncated.
405 * Return: length of resource + 1 to distinguish absent resources
406 * from the resources with zero length.
408 static INT
NLS_LoadStringExW(HMODULE hModule
, LANGID lang_id
, UINT res_id
, LPWSTR buffer
, INT buflen
)
416 hrsrc
= FindResourceExW(hModule
, RT_STRINGW
, (LPCWSTR
)((res_id
>> 4) + 1), lang_id
);
419 hmem
= LoadResource(hModule
, hrsrc
);
422 p
= LockResource(hmem
);
423 string_num
= res_id
& 0x000f;
424 for(i
= 0; i
< string_num
; i
++)
427 TRACE("strlen = %d\n", (int)*p
);
429 if (buffer
== NULL
) return *p
;
430 i
= min(buflen
- 1, *p
);
432 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
433 buffer
[i
] = (WCHAR
) 0;
436 buffer
[0] = (WCHAR
) 0;
440 TRACE("\"%s\" loaded!\n", debugstr_w(buffer
));
444 /******************************************************************************
445 * GetLocaleInfoA [KERNEL32.342]
448 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
450 * MS online documentation states that the string returned is NULL terminated
451 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
452 * terminated string".
454 INT WINAPI
GetLocaleInfoA(LCID lcid
,LCTYPE LCType
,LPSTR buf
,INT len
)
456 LPCSTR retString
= NULL
;
460 DWORD dwBufferSize
=128;
463 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid
,LCType
,buf
,len
);
465 if (len
&& (! buf
) ) {
466 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
470 if (lcid
== LOCALE_NEUTRAL
|| lcid
== LANG_SYSTEM_DEFAULT
)
472 lcid
= GetSystemDefaultLCID();
474 else if (lcid
== LANG_USER_DEFAULT
) /*0x800*/
476 lcid
= GetUserDefaultLCID();
479 /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
480 from the registry. Instead, use system default values. */
481 NoUserOverride
= (LCType
& LOCALE_NOUSEROVERRIDE
) != 0;
483 LCType
&= ~(LOCALE_NOUSEROVERRIDE
|LOCALE_USE_CP_ACP
);
485 /* First, check if it's in the registry. */
486 /* All user customized values are stored in the registry by SetLocaleInfo */
487 if ( !NoUserOverride
&& (pacKey
= GetLocaleSubkeyName(LCType
)) )
492 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
494 if ( RegOpenKeyExA( HKEY_CURRENT_USER
, acRealKey
,
495 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
497 if ( RegQueryValueExA( hKey
, NULL
, NULL
, NULL
, (LPBYTE
)acBuffer
,
498 &dwBufferSize
) == ERROR_SUCCESS
)
500 retString
= acBuffer
;
507 /* If not in the registry, get it from the NLS entries. */
512 /* check if language is registered in the kernel32 resources */
513 if((res_size
= NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid
),
514 LCType
, wcBuffer
, sizeof(wcBuffer
)/sizeof(wcBuffer
[0])))) {
515 WideCharToMultiByte(CP_ACP
, 0, wcBuffer
, res_size
, acBuffer
, dwBufferSize
, NULL
, NULL
);
516 retString
= acBuffer
;
521 /* if not found report a most descriptive error */
524 /* If we are through all of this, retLen should not be zero anymore.
525 If it is, the value is not supported */
527 while (locale_name2id
[i
].name
!=NULL
) {
528 if (LCType
== locale_name2id
[i
].id
) {
529 retString
= locale_name2id
[i
].name
;
535 FIXME("Unkown LC type %lX\n", LCType
);
537 FIXME("'%s' is not defined for your language (%04X).\n"
538 "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
539 "and submit patch for inclusion into the next Wine release.\n",
540 retString
, LOWORD(lcid
));
541 SetLastError(ERROR_INVALID_PARAMETER
);
545 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
546 if (LCType
== LOCALE_FONTSIGNATURE
) {
548 len
= (len
< sizeof(FONTSIGNATURE
)) ? len
: sizeof(FONTSIGNATURE
);
549 memcpy(buf
, retString
, len
);
552 return sizeof(FONTSIGNATURE
);
554 /* if len=0 return only the length, don't touch the buffer*/
556 lstrcpynA(buf
,retString
,len
);
557 return strlen(buf
) + 1;
559 return strlen(retString
)+1;
562 /******************************************************************************
563 * GetLocaleInfoW [KERNEL32.343]
566 * MS documentation states that len "specifies the size, in bytes (ANSI version)
567 * or characters (Unicode version), of" wbuf. Thus the number returned is
568 * the same between GetLocaleInfoW and GetLocaleInfoA.
570 INT WINAPI
GetLocaleInfoW(LCID lcid
,LCTYPE LCType
,LPWSTR wbuf
,INT len
)
574 if (len
&& (! wbuf
) )
575 { SetLastError(ERROR_INSUFFICIENT_BUFFER
);
579 abuf
= (LPSTR
)HeapAlloc(GetProcessHeap(),0,len
);
580 wlen
= GetLocaleInfoA(lcid
, LCType
, abuf
, len
);
582 if (wlen
&& len
) /* if len=0 return only the length*/
583 MultiByteToWideChar( CP_ACP
, 0, abuf
, -1, wbuf
, len
);
585 HeapFree(GetProcessHeap(),0,abuf
);
589 /******************************************************************************
591 * GetLocaleSubkeyName [helper function]
593 * - For use with the registry.
594 * - Gets the registry subkey name for a given lctype.
596 static char *GetLocaleSubkeyName( DWORD lctype
)
602 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
603 * the values are stored in the registry, confirmed under Windows,
604 * for the ones that actually assign pacKey. Cases that aren't finished
605 * have not been confirmed, so that must be done before they can be
608 case LOCALE_SDATE
: /* The date separator. */
611 case LOCALE_ICURRDIGITS
:
612 pacKey
= "iCurrDigits";
614 case LOCALE_SDECIMAL
:
617 case LOCALE_ICURRENCY
:
618 pacKey
= "iCurrency";
620 case LOCALE_SGROUPING
:
621 pacKey
= "sGrouping";
629 /* case LOCALE_ICALENDARTYPE: */
630 /* case LOCALE_IFIRSTDAYOFWEEK: */
631 /* case LOCALE_IFIRSTWEEKOFYEAR: */
632 /* case LOCALE_SYEARMONTH : */
633 /* case LOCALE_SPOSITIVESIGN : */
634 /* case LOCALE_IPAPERSIZE: */
636 case LOCALE_SLONGDATE
:
637 pacKey
= "sLongDate";
639 case LOCALE_SMONDECIMALSEP
:
640 pacKey
= "sMonDecimalSep";
642 case LOCALE_SMONGROUPING
:
643 pacKey
= "sMonGrouping";
645 case LOCALE_IMEASURE
:
648 case LOCALE_SMONTHOUSANDSEP
:
649 pacKey
= "sMonThousandSep";
651 case LOCALE_INEGCURR
:
654 case LOCALE_SNEGATIVESIGN
:
655 pacKey
= "sNegativeSign";
657 case LOCALE_INEGNUMBER
:
658 pacKey
= "iNegNumber";
660 case LOCALE_SSHORTDATE
:
661 pacKey
= "sShortDate";
663 case LOCALE_ILDATE
: /* Long Date format ordering specifier. */
672 case LOCALE_ITIME
: /* Time format specifier. */
675 case LOCALE_STHOUSAND
:
676 pacKey
= "sThousand";
678 case LOCALE_S1159
: /* AM */
684 case LOCALE_S2359
: /* PM */
687 case LOCALE_STIMEFORMAT
:
688 pacKey
= "sTimeFormat";
690 case LOCALE_SCURRENCY
:
691 pacKey
= "sCurrency";
694 /* The following are not listed under MSDN as supported,
695 * but seem to be used and also stored in the registry.
701 case LOCALE_SCOUNTRY
:
704 case LOCALE_ICOUNTRY
:
707 case LOCALE_SLANGUAGE
:
708 pacKey
= "sLanguage";
718 /******************************************************************************
719 * SetLocaleInfoA [KERNEL32.656]
721 BOOL WINAPI
SetLocaleInfoA(DWORD lcid
, DWORD lctype
, LPCSTR data
)
727 if ( (pacKey
= GetLocaleSubkeyName(lctype
)) )
729 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
730 if ( RegCreateKeyA( HKEY_CURRENT_USER
, acRealKey
,
731 &hKey
) == ERROR_SUCCESS
)
733 if ( RegSetValueExA( hKey
, NULL
, 0, REG_SZ
,
734 data
, strlen(data
)+1 ) != ERROR_SUCCESS
)
736 ERR("SetLocaleInfoA: %s did not work\n", pacKey
);
743 FIXME("(%ld,%ld,%s): stub\n",lcid
,lctype
,data
);
748 /******************************************************************************
749 * IsValidLocale [KERNEL32.489]
751 BOOL WINAPI
IsValidLocale(LCID lcid
,DWORD flags
)
753 /* check if language is registered in the kernel32 resources */
754 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW
, (LPCWSTR
)LOCALE_ILANGUAGE
, LOWORD(lcid
)))
760 static BOOL CALLBACK
EnumResourceLanguagesProcW(HMODULE hModule
, LPCWSTR type
,
761 LPCWSTR name
, WORD LangID
, LONG lParam
)
765 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
766 sprintf(bufA
, "%08X", (UINT
)LangID
);
767 MultiByteToWideChar(CP_ACP
, 0, bufA
, -1, bufW
, sizeof(bufW
)/sizeof(bufW
[0]));
768 return lpfnLocaleEnum(bufW
);
771 /******************************************************************************
772 * EnumSystemLocalesW [KERNEL32.209]
774 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
,
777 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
779 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW
,
780 (LPCWSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcW
,
781 (LONG
)lpfnLocaleEnum
);
786 static BOOL CALLBACK
EnumResourceLanguagesProcA(HMODULE hModule
, LPCSTR type
,
787 LPCSTR name
, WORD LangID
, LONG lParam
)
790 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
791 sprintf(bufA
, "%08X", (UINT
)LangID
);
792 return lpfnLocaleEnum(bufA
);
795 /******************************************************************************
796 * EnumSystemLocalesA [KERNEL32.208]
798 BOOL WINAPI
EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum
,
801 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
803 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
804 (LPCSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcA
,
805 (LONG
)lpfnLocaleEnum
);
810 static const unsigned char CT_CType2_LUT
[] = {
811 C2_NOTAPPLICABLE
, /* - 0 */
812 C2_NOTAPPLICABLE
, /* - 1 */
813 C2_NOTAPPLICABLE
, /* - 2 */
814 C2_NOTAPPLICABLE
, /* - 3 */
815 C2_NOTAPPLICABLE
, /* - 4 */
816 C2_NOTAPPLICABLE
, /* - 5 */
817 C2_NOTAPPLICABLE
, /* - 6 */
818 C2_NOTAPPLICABLE
, /* - 7 */
819 C2_NOTAPPLICABLE
, /* - 8 */
820 C2_SEGMENTSEPARATOR
, /* - 9 */
821 C2_NOTAPPLICABLE
, /* - 10 */
822 C2_NOTAPPLICABLE
, /* - 11 */
823 C2_NOTAPPLICABLE
, /* - 12 */
824 C2_NOTAPPLICABLE
, /* - 13 */
825 C2_NOTAPPLICABLE
, /* - 14 */
826 C2_NOTAPPLICABLE
, /* - 15 */
827 C2_NOTAPPLICABLE
, /* - 16 */
828 C2_NOTAPPLICABLE
, /* - 17 */
829 C2_NOTAPPLICABLE
, /* - 18 */
830 C2_NOTAPPLICABLE
, /* - 19 */
831 C2_NOTAPPLICABLE
, /* - 20 */
832 C2_NOTAPPLICABLE
, /* - 21 */
833 C2_NOTAPPLICABLE
, /* - 22 */
834 C2_NOTAPPLICABLE
, /* - 23 */
835 C2_NOTAPPLICABLE
, /* - 24 */
836 C2_NOTAPPLICABLE
, /* - 25 */
837 C2_NOTAPPLICABLE
, /* - 26 */
838 C2_NOTAPPLICABLE
, /* - 27 */
839 C2_NOTAPPLICABLE
, /* - 28 */
840 C2_NOTAPPLICABLE
, /* - 29 */
841 C2_NOTAPPLICABLE
, /* - 30 */
842 C2_NOTAPPLICABLE
, /* - 31 */
843 C2_WHITESPACE
, /* - 32 */
844 C2_OTHERNEUTRAL
, /* ! - 33 */
845 C2_OTHERNEUTRAL
, /* " - 34 */ /* " */
846 C2_EUROPETERMINATOR
, /* # - 35 */
847 C2_EUROPETERMINATOR
, /* $ - 36 */
848 C2_EUROPETERMINATOR
, /* % - 37 */
849 C2_LEFTTORIGHT
, /* & - 38 */
850 C2_OTHERNEUTRAL
, /* ' - 39 */
851 C2_OTHERNEUTRAL
, /* ( - 40 */
852 C2_OTHERNEUTRAL
, /* ) - 41 */
853 C2_OTHERNEUTRAL
, /* * - 42 */
854 C2_EUROPETERMINATOR
, /* + - 43 */
855 C2_COMMONSEPARATOR
, /* , - 44 */
856 C2_EUROPETERMINATOR
, /* - - 45 */
857 C2_EUROPESEPARATOR
, /* . - 46 */
858 C2_EUROPESEPARATOR
, /* / - 47 */
859 C2_EUROPENUMBER
, /* 0 - 48 */
860 C2_EUROPENUMBER
, /* 1 - 49 */
861 C2_EUROPENUMBER
, /* 2 - 50 */
862 C2_EUROPENUMBER
, /* 3 - 51 */
863 C2_EUROPENUMBER
, /* 4 - 52 */
864 C2_EUROPENUMBER
, /* 5 - 53 */
865 C2_EUROPENUMBER
, /* 6 - 54 */
866 C2_EUROPENUMBER
, /* 7 - 55 */
867 C2_EUROPENUMBER
, /* 8 - 56 */
868 C2_EUROPENUMBER
, /* 9 - 57 */
869 C2_COMMONSEPARATOR
, /* : - 58 */
870 C2_OTHERNEUTRAL
, /* ; - 59 */
871 C2_OTHERNEUTRAL
, /* < - 60 */
872 C2_OTHERNEUTRAL
, /* = - 61 */
873 C2_OTHERNEUTRAL
, /* > - 62 */
874 C2_OTHERNEUTRAL
, /* ? - 63 */
875 C2_LEFTTORIGHT
, /* @ - 64 */
876 C2_LEFTTORIGHT
, /* A - 65 */
877 C2_LEFTTORIGHT
, /* B - 66 */
878 C2_LEFTTORIGHT
, /* C - 67 */
879 C2_LEFTTORIGHT
, /* D - 68 */
880 C2_LEFTTORIGHT
, /* E - 69 */
881 C2_LEFTTORIGHT
, /* F - 70 */
882 C2_LEFTTORIGHT
, /* G - 71 */
883 C2_LEFTTORIGHT
, /* H - 72 */
884 C2_LEFTTORIGHT
, /* I - 73 */
885 C2_LEFTTORIGHT
, /* J - 74 */
886 C2_LEFTTORIGHT
, /* K - 75 */
887 C2_LEFTTORIGHT
, /* L - 76 */
888 C2_LEFTTORIGHT
, /* M - 77 */
889 C2_LEFTTORIGHT
, /* N - 78 */
890 C2_LEFTTORIGHT
, /* O - 79 */
891 C2_LEFTTORIGHT
, /* P - 80 */
892 C2_LEFTTORIGHT
, /* Q - 81 */
893 C2_LEFTTORIGHT
, /* R - 82 */
894 C2_LEFTTORIGHT
, /* S - 83 */
895 C2_LEFTTORIGHT
, /* T - 84 */
896 C2_LEFTTORIGHT
, /* U - 85 */
897 C2_LEFTTORIGHT
, /* V - 86 */
898 C2_LEFTTORIGHT
, /* W - 87 */
899 C2_LEFTTORIGHT
, /* X - 88 */
900 C2_LEFTTORIGHT
, /* Y - 89 */
901 C2_LEFTTORIGHT
, /* Z - 90 */
902 C2_OTHERNEUTRAL
, /* [ - 91 */
903 C2_OTHERNEUTRAL
, /* \ - 92 */
904 C2_OTHERNEUTRAL
, /* ] - 93 */
905 C2_OTHERNEUTRAL
, /* ^ - 94 */
906 C2_OTHERNEUTRAL
, /* _ - 95 */
907 C2_OTHERNEUTRAL
, /* ` - 96 */
908 C2_LEFTTORIGHT
, /* a - 97 */
909 C2_LEFTTORIGHT
, /* b - 98 */
910 C2_LEFTTORIGHT
, /* c - 99 */
911 C2_LEFTTORIGHT
, /* d - 100 */
912 C2_LEFTTORIGHT
, /* e - 101 */
913 C2_LEFTTORIGHT
, /* f - 102 */
914 C2_LEFTTORIGHT
, /* g - 103 */
915 C2_LEFTTORIGHT
, /* h - 104 */
916 C2_LEFTTORIGHT
, /* i - 105 */
917 C2_LEFTTORIGHT
, /* j - 106 */
918 C2_LEFTTORIGHT
, /* k - 107 */
919 C2_LEFTTORIGHT
, /* l - 108 */
920 C2_LEFTTORIGHT
, /* m - 109 */
921 C2_LEFTTORIGHT
, /* n - 110 */
922 C2_LEFTTORIGHT
, /* o - 111 */
923 C2_LEFTTORIGHT
, /* p - 112 */
924 C2_LEFTTORIGHT
, /* q - 113 */
925 C2_LEFTTORIGHT
, /* r - 114 */
926 C2_LEFTTORIGHT
, /* s - 115 */
927 C2_LEFTTORIGHT
, /* t - 116 */
928 C2_LEFTTORIGHT
, /* u - 117 */
929 C2_LEFTTORIGHT
, /* v - 118 */
930 C2_LEFTTORIGHT
, /* w - 119 */
931 C2_LEFTTORIGHT
, /* x - 120 */
932 C2_LEFTTORIGHT
, /* y - 121 */
933 C2_LEFTTORIGHT
, /* z - 122 */
934 C2_OTHERNEUTRAL
, /* { - 123 */
935 C2_OTHERNEUTRAL
, /* | - 124 */
936 C2_OTHERNEUTRAL
, /* } - 125 */
937 C2_OTHERNEUTRAL
, /* ~ - 126 */
938 C2_NOTAPPLICABLE
, /* \x7f - 127 */
939 C2_NOTAPPLICABLE
, /* € - 128 */
940 C2_NOTAPPLICABLE
, /* � - 129 */
941 C2_OTHERNEUTRAL
, /* ‚ - 130 */
942 C2_LEFTTORIGHT
, /* ƒ - 131 */
943 C2_OTHERNEUTRAL
, /* „ - 132 */
944 C2_OTHERNEUTRAL
, /* … - 133 */
945 C2_OTHERNEUTRAL
, /* † - 134 */
946 C2_OTHERNEUTRAL
, /* ‡ - 135 */
947 C2_LEFTTORIGHT
, /* ˆ - 136 */
948 C2_EUROPETERMINATOR
, /* ‰ - 137 */
949 C2_LEFTTORIGHT
, /* Š - 138 */
950 C2_OTHERNEUTRAL
, /* ‹ - 139 */
951 C2_LEFTTORIGHT
, /* Œ - 140 */
952 C2_NOTAPPLICABLE
, /* � - 141 */
953 C2_NOTAPPLICABLE
, /* Ž - 142 */
954 C2_NOTAPPLICABLE
, /* � - 143 */
955 C2_NOTAPPLICABLE
, /* � - 144 */
956 C2_OTHERNEUTRAL
, /* ‘ - 145 */
957 C2_OTHERNEUTRAL
, /* ’ - 146 */
958 C2_OTHERNEUTRAL
, /* “ - 147 */
959 C2_OTHERNEUTRAL
, /* ” - 148 */
960 C2_OTHERNEUTRAL
, /* • - 149 */
961 C2_OTHERNEUTRAL
, /* – - 150 */
962 C2_OTHERNEUTRAL
, /* — - 151 */
963 C2_LEFTTORIGHT
, /* ˜ - 152 */
964 C2_OTHERNEUTRAL
, /* ™ - 153 */
965 C2_LEFTTORIGHT
, /* š - 154 */
966 C2_OTHERNEUTRAL
, /* › - 155 */
967 C2_LEFTTORIGHT
, /* œ - 156 */
968 C2_NOTAPPLICABLE
, /* � - 157 */
969 C2_NOTAPPLICABLE
, /* ž - 158 */
970 C2_LEFTTORIGHT
, /* Ÿ - 159 */
971 C2_WHITESPACE
, /* - 160 */
972 C2_OTHERNEUTRAL
, /* ¡ - 161 */
973 C2_EUROPETERMINATOR
, /* ¢ - 162 */
974 C2_EUROPETERMINATOR
, /* £ - 163 */
975 C2_EUROPETERMINATOR
, /* ¤ - 164 */
976 C2_EUROPETERMINATOR
, /* ¥ - 165 */
977 C2_OTHERNEUTRAL
, /* ¦ - 166 */
978 C2_OTHERNEUTRAL
, /* § - 167 */
979 C2_OTHERNEUTRAL
, /* ¨ - 168 */
980 C2_OTHERNEUTRAL
, /* © - 169 */
981 C2_OTHERNEUTRAL
, /* ª - 170 */
982 C2_OTHERNEUTRAL
, /* « - 171 */
983 C2_OTHERNEUTRAL
, /* ¬ - 172 */
984 C2_OTHERNEUTRAL
, /* - 173 */
985 C2_OTHERNEUTRAL
, /* ® - 174 */
986 C2_OTHERNEUTRAL
, /* ¯ - 175 */
987 C2_EUROPETERMINATOR
, /* ° - 176 */
988 C2_EUROPETERMINATOR
, /* ± - 177 */
989 C2_EUROPENUMBER
, /* ² - 178 */
990 C2_EUROPENUMBER
, /* ³ - 179 */
991 C2_OTHERNEUTRAL
, /* ´ - 180 */
992 C2_OTHERNEUTRAL
, /* µ - 181 */
993 C2_OTHERNEUTRAL
, /* ¶ - 182 */
994 C2_OTHERNEUTRAL
, /* · - 183 */
995 C2_OTHERNEUTRAL
, /* ¸ - 184 */
996 C2_EUROPENUMBER
, /* ¹ - 185 */
997 C2_OTHERNEUTRAL
, /* º - 186 */
998 C2_OTHERNEUTRAL
, /* » - 187 */
999 C2_OTHERNEUTRAL
, /* ¼ - 188 */
1000 C2_OTHERNEUTRAL
, /* ½ - 189 */
1001 C2_OTHERNEUTRAL
, /* ¾ - 190 */
1002 C2_OTHERNEUTRAL
, /* ¿ - 191 */
1003 C2_LEFTTORIGHT
, /* À - 192 */
1004 C2_LEFTTORIGHT
, /* Á - 193 */
1005 C2_LEFTTORIGHT
, /* Â - 194 */
1006 C2_LEFTTORIGHT
, /* Ã - 195 */
1007 C2_LEFTTORIGHT
, /* Ä - 196 */
1008 C2_LEFTTORIGHT
, /* Å - 197 */
1009 C2_LEFTTORIGHT
, /* Æ - 198 */
1010 C2_LEFTTORIGHT
, /* Ç - 199 */
1011 C2_LEFTTORIGHT
, /* È - 200 */
1012 C2_LEFTTORIGHT
, /* É - 201 */
1013 C2_LEFTTORIGHT
, /* Ê - 202 */
1014 C2_LEFTTORIGHT
, /* Ë - 203 */
1015 C2_LEFTTORIGHT
, /* Ì - 204 */
1016 C2_LEFTTORIGHT
, /* Í - 205 */
1017 C2_LEFTTORIGHT
, /* Î - 206 */
1018 C2_LEFTTORIGHT
, /* Ï - 207 */
1019 C2_LEFTTORIGHT
, /* Ð - 208 */
1020 C2_LEFTTORIGHT
, /* Ñ - 209 */
1021 C2_LEFTTORIGHT
, /* Ò - 210 */
1022 C2_LEFTTORIGHT
, /* Ó - 211 */
1023 C2_LEFTTORIGHT
, /* Ô - 212 */
1024 C2_LEFTTORIGHT
, /* Õ - 213 */
1025 C2_LEFTTORIGHT
, /* Ö - 214 */
1026 C2_OTHERNEUTRAL
, /* × - 215 */
1027 C2_LEFTTORIGHT
, /* Ø - 216 */
1028 C2_LEFTTORIGHT
, /* Ù - 217 */
1029 C2_LEFTTORIGHT
, /* Ú - 218 */
1030 C2_LEFTTORIGHT
, /* Û - 219 */
1031 C2_LEFTTORIGHT
, /* Ü - 220 */
1032 C2_LEFTTORIGHT
, /* Ý - 221 */
1033 C2_LEFTTORIGHT
, /* Þ - 222 */
1034 C2_LEFTTORIGHT
, /* ß - 223 */
1035 C2_LEFTTORIGHT
, /* à - 224 */
1036 C2_LEFTTORIGHT
, /* á - 225 */
1037 C2_LEFTTORIGHT
, /* â - 226 */
1038 C2_LEFTTORIGHT
, /* ã - 227 */
1039 C2_LEFTTORIGHT
, /* ä - 228 */
1040 C2_LEFTTORIGHT
, /* å - 229 */
1041 C2_LEFTTORIGHT
, /* æ - 230 */
1042 C2_LEFTTORIGHT
, /* ç - 231 */
1043 C2_LEFTTORIGHT
, /* è - 232 */
1044 C2_LEFTTORIGHT
, /* é - 233 */
1045 C2_LEFTTORIGHT
, /* ê - 234 */
1046 C2_LEFTTORIGHT
, /* ë - 235 */
1047 C2_LEFTTORIGHT
, /* ì - 236 */
1048 C2_LEFTTORIGHT
, /* í - 237 */
1049 C2_LEFTTORIGHT
, /* î - 238 */
1050 C2_LEFTTORIGHT
, /* ï - 239 */
1051 C2_LEFTTORIGHT
, /* ð - 240 */
1052 C2_LEFTTORIGHT
, /* ñ - 241 */
1053 C2_LEFTTORIGHT
, /* ò - 242 */
1054 C2_LEFTTORIGHT
, /* ó - 243 */
1055 C2_LEFTTORIGHT
, /* ô - 244 */
1056 C2_LEFTTORIGHT
, /* õ - 245 */
1057 C2_LEFTTORIGHT
, /* ö - 246 */
1058 C2_OTHERNEUTRAL
, /* ÷ - 247 */
1059 C2_LEFTTORIGHT
, /* ø - 248 */
1060 C2_LEFTTORIGHT
, /* ù - 249 */
1061 C2_LEFTTORIGHT
, /* ú - 250 */
1062 C2_LEFTTORIGHT
, /* û - 251 */
1063 C2_LEFTTORIGHT
, /* ü - 252 */
1064 C2_LEFTTORIGHT
, /* ý - 253 */
1065 C2_LEFTTORIGHT
, /* þ - 254 */
1066 C2_LEFTTORIGHT
/* ÿ - 255 */
1069 const WORD OLE2NLS_CT_CType3_LUT
[] = {
1103 0x0048, /* ! - 33 */
1104 0x0448, /* " - 34 */ /* " */
1105 0x0048, /* # - 35 */
1106 0x0448, /* $ - 36 */
1107 0x0048, /* % - 37 */
1108 0x0048, /* & - 38 */
1109 0x0440, /* ' - 39 */
1110 0x0048, /* ( - 40 */
1111 0x0048, /* ) - 41 */
1112 0x0048, /* * - 42 */
1113 0x0048, /* + - 43 */
1114 0x0048, /* , - 44 */
1115 0x0440, /* - - 45 */
1116 0x0048, /* . - 46 */
1117 0x0448, /* / - 47 */
1118 0x0040, /* 0 - 48 */
1119 0x0040, /* 1 - 49 */
1120 0x0040, /* 2 - 50 */
1121 0x0040, /* 3 - 51 */
1122 0x0040, /* 4 - 52 */
1123 0x0040, /* 5 - 53 */
1124 0x0040, /* 6 - 54 */
1125 0x0040, /* 7 - 55 */
1126 0x0040, /* 8 - 56 */
1127 0x0040, /* 9 - 57 */
1128 0x0048, /* : - 58 */
1129 0x0048, /* ; - 59 */
1130 0x0048, /* < - 60 */
1131 0x0448, /* = - 61 */
1132 0x0048, /* > - 62 */
1133 0x0048, /* ? - 63 */
1134 0x0448, /* @ - 64 */
1135 0x8040, /* A - 65 */
1136 0x8040, /* B - 66 */
1137 0x8040, /* C - 67 */
1138 0x8040, /* D - 68 */
1139 0x8040, /* E - 69 */
1140 0x8040, /* F - 70 */
1141 0x8040, /* G - 71 */
1142 0x8040, /* H - 72 */
1143 0x8040, /* I - 73 */
1144 0x8040, /* J - 74 */
1145 0x8040, /* K - 75 */
1146 0x8040, /* L - 76 */
1147 0x8040, /* M - 77 */
1148 0x8040, /* N - 78 */
1149 0x8040, /* O - 79 */
1150 0x8040, /* P - 80 */
1151 0x8040, /* Q - 81 */
1152 0x8040, /* R - 82 */
1153 0x8040, /* S - 83 */
1154 0x8040, /* T - 84 */
1155 0x8040, /* U - 85 */
1156 0x8040, /* V - 86 */
1157 0x8040, /* W - 87 */
1158 0x8040, /* X - 88 */
1159 0x8040, /* Y - 89 */
1160 0x8040, /* Z - 90 */
1161 0x0048, /* [ - 91 */
1162 0x0448, /* \ - 92 */
1163 0x0048, /* ] - 93 */
1164 0x0448, /* ^ - 94 */
1165 0x0448, /* _ - 95 */
1166 0x0448, /* ` - 96 */
1167 0x8040, /* a - 97 */
1168 0x8040, /* b - 98 */
1169 0x8040, /* c - 99 */
1170 0x8040, /* d - 100 */
1171 0x8040, /* e - 101 */
1172 0x8040, /* f - 102 */
1173 0x8040, /* g - 103 */
1174 0x8040, /* h - 104 */
1175 0x8040, /* i - 105 */
1176 0x8040, /* j - 106 */
1177 0x8040, /* k - 107 */
1178 0x8040, /* l - 108 */
1179 0x8040, /* m - 109 */
1180 0x8040, /* n - 110 */
1181 0x8040, /* o - 111 */
1182 0x8040, /* p - 112 */
1183 0x8040, /* q - 113 */
1184 0x8040, /* r - 114 */
1185 0x8040, /* s - 115 */
1186 0x8040, /* t - 116 */
1187 0x8040, /* u - 117 */
1188 0x8040, /* v - 118 */
1189 0x8040, /* w - 119 */
1190 0x8040, /* x - 120 */
1191 0x8040, /* y - 121 */
1192 0x8040, /* z - 122 */
1193 0x0048, /* { - 123 */
1194 0x0048, /* | - 124 */
1195 0x0048, /* } - 125 */
1196 0x0448, /* ~ - 126 */
1197 0x0000, /* \x7f - 127 */
1198 0x0000, /* € - 128 */
1199 0x0000, /* � - 129 */
1200 0x0008, /* ‚ - 130 */
1201 0x8000, /* ƒ - 131 */
1202 0x0008, /* „ - 132 */
1203 0x0008, /* … - 133 */
1204 0x0008, /* † - 134 */
1205 0x0008, /* ‡ - 135 */
1206 0x0001, /* ˆ - 136 */
1207 0x0008, /* ‰ - 137 */
1208 0x8003, /* Š - 138 */
1209 0x0008, /* ‹ - 139 */
1210 0x8000, /* Œ - 140 */
1211 0x0000, /* � - 141 */
1212 0x0000, /* Ž - 142 */
1213 0x0000, /* � - 143 */
1214 0x0000, /* � - 144 */
1215 0x0088, /* ‘ - 145 */
1216 0x0088, /* ’ - 146 */
1217 0x0088, /* “ - 147 */
1218 0x0088, /* ” - 148 */
1219 0x0008, /* • - 149 */
1220 0x0400, /* – - 150 */
1221 0x0400, /* — - 151 */
1222 0x0408, /* ˜ - 152 */
1223 0x0000, /* ™ - 153 */
1224 0x8003, /* š - 154 */
1225 0x0008, /* › - 155 */
1226 0x8000, /* œ - 156 */
1227 0x0000, /* � - 157 */
1228 0x0000, /* ž - 158 */
1229 0x8003, /* Ÿ - 159 */
1231 0x0008, /* ¡ - 161 */
1232 0x0048, /* ¢ - 162 */
1233 0x0048, /* £ - 163 */
1234 0x0008, /* ¤ - 164 */
1235 0x0048, /* ¥ - 165 */
1236 0x0048, /* ¦ - 166 */
1237 0x0008, /* § - 167 */
1238 0x0408, /* ¨ - 168 */
1239 0x0008, /* © - 169 */
1240 0x0400, /* ª - 170 */
1241 0x0008, /* « - 171 */
1242 0x0048, /* ¬ - 172 */
1243 0x0408, /* - 173 */
1244 0x0008, /* ® - 174 */
1245 0x0448, /* ¯ - 175 */
1246 0x0008, /* ° - 176 */
1247 0x0008, /* ± - 177 */
1248 0x0000, /* ² - 178 */
1249 0x0000, /* ³ - 179 */
1250 0x0408, /* ´ - 180 */
1251 0x0008, /* µ - 181 */
1252 0x0008, /* ¶ - 182 */
1253 0x0008, /* · - 183 */
1254 0x0408, /* ¸ - 184 */
1255 0x0000, /* ¹ - 185 */
1256 0x0400, /* º - 186 */
1257 0x0008, /* » - 187 */
1258 0x0000, /* ¼ - 188 */
1259 0x0000, /* ½ - 189 */
1260 0x0000, /* ¾ - 190 */
1261 0x0008, /* ¿ - 191 */
1262 0x8003, /* À - 192 */
1263 0x8003, /* Á - 193 */
1264 0x8003, /* Â - 194 */
1265 0x8003, /* Ã - 195 */
1266 0x8003, /* Ä - 196 */
1267 0x8003, /* Å - 197 */
1268 0x8000, /* Æ - 198 */
1269 0x8003, /* Ç - 199 */
1270 0x8003, /* È - 200 */
1271 0x8003, /* É - 201 */
1272 0x8003, /* Ê - 202 */
1273 0x8003, /* Ë - 203 */
1274 0x8003, /* Ì - 204 */
1275 0x8003, /* Í - 205 */
1276 0x8003, /* Î - 206 */
1277 0x8003, /* Ï - 207 */
1278 0x8000, /* Ð - 208 */
1279 0x8003, /* Ñ - 209 */
1280 0x8003, /* Ò - 210 */
1281 0x8003, /* Ó - 211 */
1282 0x8003, /* Ô - 212 */
1283 0x8003, /* Õ - 213 */
1284 0x8003, /* Ö - 214 */
1285 0x0008, /* × - 215 */
1286 0x8003, /* Ø - 216 */
1287 0x8003, /* Ù - 217 */
1288 0x8003, /* Ú - 218 */
1289 0x8003, /* Û - 219 */
1290 0x8003, /* Ü - 220 */
1291 0x8003, /* Ý - 221 */
1292 0x8000, /* Þ - 222 */
1293 0x8000, /* ß - 223 */
1294 0x8003, /* à - 224 */
1295 0x8003, /* á - 225 */
1296 0x8003, /* â - 226 */
1297 0x8003, /* ã - 227 */
1298 0x8003, /* ä - 228 */
1299 0x8003, /* å - 229 */
1300 0x8000, /* æ - 230 */
1301 0x8003, /* ç - 231 */
1302 0x8003, /* è - 232 */
1303 0x8003, /* é - 233 */
1304 0x8003, /* ê - 234 */
1305 0x8003, /* ë - 235 */
1306 0x8003, /* ì - 236 */
1307 0x8003, /* í - 237 */
1308 0x8003, /* î - 238 */
1309 0x8003, /* ï - 239 */
1310 0x8000, /* ð - 240 */
1311 0x8003, /* ñ - 241 */
1312 0x8003, /* ò - 242 */
1313 0x8003, /* ó - 243 */
1314 0x8003, /* ô - 244 */
1315 0x8003, /* õ - 245 */
1316 0x8003, /* ö - 246 */
1317 0x0008, /* ÷ - 247 */
1318 0x8003, /* ø - 248 */
1319 0x8003, /* ù - 249 */
1320 0x8003, /* ú - 250 */
1321 0x8003, /* û - 251 */
1322 0x8003, /* ü - 252 */
1323 0x8003, /* ý - 253 */
1324 0x8000, /* þ - 254 */
1325 0x8003 /* ÿ - 255 */
1328 /******************************************************************************
1329 * GetStringTypeA [KERNEL32.396]
1331 BOOL WINAPI
GetStringTypeA(LCID locale
,DWORD dwInfoType
,LPCSTR src
,
1332 INT cchSrc
,LPWORD chartype
)
1334 return GetStringTypeExA(locale
,dwInfoType
,src
,cchSrc
,chartype
);
1337 /******************************************************************************
1338 * GetStringTypeExA [KERNEL32.397]
1340 * FIXME: Ignores the locale.
1342 BOOL WINAPI
GetStringTypeExA(LCID locale
,DWORD dwInfoType
,LPCSTR src
,
1343 INT cchSrc
,LPWORD chartype
)
1347 if ((src
==NULL
) || (chartype
==NULL
) || (src
==(LPSTR
)chartype
))
1349 SetLastError(ERROR_INVALID_PARAMETER
);
1354 cchSrc
=strlen(src
)+1;
1356 switch (dwInfoType
) {
1358 for (i
=0;i
<cchSrc
;i
++)
1361 if (isdigit(src
[i
])) chartype
[i
]|=C1_DIGIT
;
1362 if (isalpha(src
[i
])) chartype
[i
]|=C1_ALPHA
;
1363 if (islower(src
[i
])) chartype
[i
]|=C1_LOWER
;
1364 if (isupper(src
[i
])) chartype
[i
]|=C1_UPPER
;
1365 if (isspace(src
[i
])) chartype
[i
]|=C1_SPACE
;
1366 if (ispunct(src
[i
])) chartype
[i
]|=C1_PUNCT
;
1367 if (iscntrl(src
[i
])) chartype
[i
]|=C1_CNTRL
;
1368 /* FIXME: isblank() is a GNU extension */
1369 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1370 if ((src
[i
] == ' ') || (src
[i
] == '\t')) chartype
[i
]|=C1_BLANK
;
1376 for (i
=0;i
<cchSrc
;i
++)
1378 chartype
[i
]=(WORD
)CT_CType2_LUT
[i
];
1383 for (i
=0;i
<cchSrc
;i
++)
1385 chartype
[i
]=OLE2NLS_CT_CType3_LUT
[i
];
1390 ERR("Unknown dwInfoType:%ld\n",dwInfoType
);
1395 /***********************************************************************
1396 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1398 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
1403 return GetLocaleInfoA(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1406 /***********************************************************************
1407 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1409 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
1414 return GetLocaleInfoW(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1418 static const unsigned char LCM_Unicode_LUT
[] = {
1451 7 , 28, /* ! - 33 */
1452 7 , 29, /* " - 34 */ /* " */
1453 7 , 31, /* # - 35 */
1454 7 , 33, /* $ - 36 */
1455 7 , 35, /* % - 37 */
1456 7 , 37, /* & - 38 */
1457 6 , 128, /* ' - 39 */
1458 7 , 39, /* ( - 40 */
1459 7 , 42, /* ) - 41 */
1460 7 , 45, /* * - 42 */
1462 7 , 47, /* , - 44 */
1463 6 , 130, /* - - 45 */
1464 7 , 51, /* . - 46 */
1465 7 , 53, /* / - 47 */
1466 12 , 3, /* 0 - 48 */
1467 12 , 33, /* 1 - 49 */
1468 12 , 51, /* 2 - 50 */
1469 12 , 70, /* 3 - 51 */
1470 12 , 88, /* 4 - 52 */
1471 12 , 106, /* 5 - 53 */
1472 12 , 125, /* 6 - 54 */
1473 12 , 144, /* 7 - 55 */
1474 12 , 162, /* 8 - 56 */
1475 12 , 180, /* 9 - 57 */
1476 7 , 55, /* : - 58 */
1477 7 , 58, /* ; - 59 */
1478 8 , 14, /* < - 60 */
1479 8 , 18, /* = - 61 */
1480 8 , 20, /* > - 62 */
1481 7 , 60, /* ? - 63 */
1482 7 , 62, /* @ - 64 */
1483 14 , 2, /* A - 65 */
1484 14 , 9, /* B - 66 */
1485 14 , 10, /* C - 67 */
1486 14 , 26, /* D - 68 */
1487 14 , 33, /* E - 69 */
1488 14 , 35, /* F - 70 */
1489 14 , 37, /* G - 71 */
1490 14 , 44, /* H - 72 */
1491 14 , 50, /* I - 73 */
1492 14 , 53, /* J - 74 */
1493 14 , 54, /* K - 75 */
1494 14 , 72, /* L - 76 */
1495 14 , 81, /* M - 77 */
1496 14 , 112, /* N - 78 */
1497 14 , 124, /* O - 79 */
1498 14 , 126, /* P - 80 */
1499 14 , 137, /* Q - 81 */
1500 14 , 138, /* R - 82 */
1501 14 , 145, /* S - 83 */
1502 14 , 153, /* T - 84 */
1503 14 , 159, /* U - 85 */
1504 14 , 162, /* V - 86 */
1505 14 , 164, /* W - 87 */
1506 14 , 166, /* X - 88 */
1507 14 , 167, /* Y - 89 */
1508 14 , 169, /* Z - 90 */
1509 7 , 63, /* [ - 91 */
1510 7 , 65, /* \ - 92 */
1511 7 , 66, /* ] - 93 */
1512 7 , 67, /* ^ - 94 */
1513 7 , 68, /* _ - 95 */
1514 7 , 72, /* ` - 96 */
1515 14 , 2, /* a - 97 */
1516 14 , 9, /* b - 98 */
1517 14 , 10, /* c - 99 */
1518 14 , 26, /* d - 100 */
1519 14 , 33, /* e - 101 */
1520 14 , 35, /* f - 102 */
1521 14 , 37, /* g - 103 */
1522 14 , 44, /* h - 104 */
1523 14 , 50, /* i - 105 */
1524 14 , 53, /* j - 106 */
1525 14 , 54, /* k - 107 */
1526 14 , 72, /* l - 108 */
1527 14 , 81, /* m - 109 */
1528 14 , 112, /* n - 110 */
1529 14 , 124, /* o - 111 */
1530 14 , 126, /* p - 112 */
1531 14 , 137, /* q - 113 */
1532 14 , 138, /* r - 114 */
1533 14 , 145, /* s - 115 */
1534 14 , 153, /* t - 116 */
1535 14 , 159, /* u - 117 */
1536 14 , 162, /* v - 118 */
1537 14 , 164, /* w - 119 */
1538 14 , 166, /* x - 120 */
1539 14 , 167, /* y - 121 */
1540 14 , 169, /* z - 122 */
1541 7 , 74, /* { - 123 */
1542 7 , 76, /* | - 124 */
1543 7 , 78, /* } - 125 */
1544 7 , 80, /* ~ - 126 */
1545 6 , 29, /* \x7f - 127 */
1546 6 , 30, /* € - 128 */
1547 6 , 31, /* � - 129 */
1548 7 , 123, /* ‚ - 130 */
1549 14 , 35, /* ƒ - 131 */
1550 7 , 127, /* „ - 132 */
1551 10 , 21, /* … - 133 */
1552 10 , 15, /* † - 134 */
1553 10 , 16, /* ‡ - 135 */
1554 7 , 67, /* ˆ - 136 */
1555 10 , 22, /* ‰ - 137 */
1556 14 , 145, /* Š - 138 */
1557 7 , 136, /* ‹ - 139 */
1558 14 + 16 , 124, /* Œ - 140 */
1559 6 , 43, /* � - 141 */
1560 6 , 44, /* Ž - 142 */
1561 6 , 45, /* � - 143 */
1562 6 , 46, /* � - 144 */
1563 7 , 121, /* ‘ - 145 */
1564 7 , 122, /* ’ - 146 */
1565 7 , 125, /* “ - 147 */
1566 7 , 126, /* ” - 148 */
1567 10 , 17, /* • - 149 */
1568 6 , 137, /* – - 150 */
1569 6 , 139, /* — - 151 */
1570 7 , 93, /* ˜ - 152 */
1571 14 , 156, /* ™ - 153 */
1572 14 , 145, /* š - 154 */
1573 7 , 137, /* › - 155 */
1574 14 + 16 , 124, /* œ - 156 */
1575 6 , 59, /* � - 157 */
1576 6 , 60, /* ž - 158 */
1577 14 , 167, /* Ÿ - 159 */
1579 7 , 81, /* ¡ - 161 */
1580 10 , 2, /* ¢ - 162 */
1581 10 , 3, /* £ - 163 */
1582 10 , 4, /* ¤ - 164 */
1583 10 , 5, /* ¥ - 165 */
1584 7 , 82, /* ¦ - 166 */
1585 10 , 6, /* § - 167 */
1586 7 , 83, /* ¨ - 168 */
1587 10 , 7, /* © - 169 */
1588 14 , 2, /* ª - 170 */
1589 8 , 24, /* « - 171 */
1590 10 , 8, /* ¬ - 172 */
1591 6 , 131, /* - 173 */
1592 10 , 9, /* ® - 174 */
1593 7 , 84, /* ¯ - 175 */
1594 10 , 10, /* ° - 176 */
1595 8 , 23, /* ± - 177 */
1596 12 , 51, /* ² - 178 */
1597 12 , 70, /* ³ - 179 */
1598 7 , 85, /* ´ - 180 */
1599 10 , 11, /* µ - 181 */
1600 10 , 12, /* ¶ - 182 */
1601 10 , 13, /* · - 183 */
1602 7 , 86, /* ¸ - 184 */
1603 12 , 33, /* ¹ - 185 */
1604 14 , 124, /* º - 186 */
1605 8 , 26, /* » - 187 */
1606 12 , 21, /* ¼ - 188 */
1607 12 , 25, /* ½ - 189 */
1608 12 , 29, /* ¾ - 190 */
1609 7 , 87, /* ¿ - 191 */
1610 14 , 2, /* À - 192 */
1611 14 , 2, /* Á - 193 */
1612 14 , 2, /* Â - 194 */
1613 14 , 2, /* Ã - 195 */
1614 14 , 2, /* Ä - 196 */
1615 14 , 2, /* Å - 197 */
1616 14 + 16 , 2, /* Æ - 198 */
1617 14 , 10, /* Ç - 199 */
1618 14 , 33, /* È - 200 */
1619 14 , 33, /* É - 201 */
1620 14 , 33, /* Ê - 202 */
1621 14 , 33, /* Ë - 203 */
1622 14 , 50, /* Ì - 204 */
1623 14 , 50, /* Í - 205 */
1624 14 , 50, /* Î - 206 */
1625 14 , 50, /* Ï - 207 */
1626 14 , 26, /* Ð - 208 */
1627 14 , 112, /* Ñ - 209 */
1628 14 , 124, /* Ò - 210 */
1629 14 , 124, /* Ó - 211 */
1630 14 , 124, /* Ô - 212 */
1631 14 , 124, /* Õ - 213 */
1632 14 , 124, /* Ö - 214 */
1633 8 , 28, /* × - 215 */
1634 14 , 124, /* Ø - 216 */
1635 14 , 159, /* Ù - 217 */
1636 14 , 159, /* Ú - 218 */
1637 14 , 159, /* Û - 219 */
1638 14 , 159, /* Ü - 220 */
1639 14 , 167, /* Ý - 221 */
1640 14 + 32 , 153, /* Þ - 222 */
1641 14 + 48 , 145, /* ß - 223 */
1642 14 , 2, /* à - 224 */
1643 14 , 2, /* á - 225 */
1644 14 , 2, /* â - 226 */
1645 14 , 2, /* ã - 227 */
1646 14 , 2, /* ä - 228 */
1647 14 , 2, /* å - 229 */
1648 14 + 16 , 2, /* æ - 230 */
1649 14 , 10, /* ç - 231 */
1650 14 , 33, /* è - 232 */
1651 14 , 33, /* é - 233 */
1652 14 , 33, /* ê - 234 */
1653 14 , 33, /* ë - 235 */
1654 14 , 50, /* ì - 236 */
1655 14 , 50, /* í - 237 */
1656 14 , 50, /* î - 238 */
1657 14 , 50, /* ï - 239 */
1658 14 , 26, /* ð - 240 */
1659 14 , 112, /* ñ - 241 */
1660 14 , 124, /* ò - 242 */
1661 14 , 124, /* ó - 243 */
1662 14 , 124, /* ô - 244 */
1663 14 , 124, /* õ - 245 */
1664 14 , 124, /* ö - 246 */
1665 8 , 29, /* ÷ - 247 */
1666 14 , 124, /* ø - 248 */
1667 14 , 159, /* ù - 249 */
1668 14 , 159, /* ú - 250 */
1669 14 , 159, /* û - 251 */
1670 14 , 159, /* ü - 252 */
1671 14 , 167, /* ý - 253 */
1672 14 + 32 , 153, /* þ - 254 */
1673 14 , 167 /* ÿ - 255 */ };
1675 static const unsigned char LCM_Unicode_LUT_2
[] = { 33, 44, 145 };
1677 #define LCM_Diacritic_Start 131
1679 static const unsigned char LCM_Diacritic_LUT
[] = {
1807 /******************************************************************************
1808 * OLE2NLS_isPunctuation [INTERNAL]
1810 static int OLE2NLS_isPunctuation(unsigned char c
)
1812 /* "punctuation character" in this context is a character which is
1813 considered "less important" during word sort comparison.
1814 See LCMapString implementation for the precise definition
1815 of "less important". */
1817 return (LCM_Unicode_LUT
[-2+2*c
]==6);
1820 /******************************************************************************
1821 * OLE2NLS_isNonSpacing [INTERNAL]
1823 static int OLE2NLS_isNonSpacing(unsigned char c
)
1825 /* This function is used by LCMapStringA. Characters
1826 for which it returns true are ignored when mapping a
1827 string with NORM_IGNORENONSPACE */
1828 return ((c
==136) || (c
==170) || (c
==186));
1831 /******************************************************************************
1832 * OLE2NLS_isSymbol [INTERNAL]
1834 static int OLE2NLS_isSymbol(unsigned char c
)
1836 /* This function is used by LCMapStringA. Characters
1837 for which it returns true are ignored when mapping a
1838 string with NORM_IGNORESYMBOLS */
1839 return ( (c
!=0) && !IsCharAlphaNumericA(c
) );
1842 /******************************************************************************
1843 * identity [Internal]
1845 static int identity(int c
)
1850 /*************************************************************************
1851 * LCMapStringA [KERNEL32.492]
1853 * Convert a string, or generate a sort key from it.
1855 * If (mapflags & LCMAP_SORTKEY), the function will generate
1856 * a sort key for the source string. Else, it will convert it
1857 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1861 * Success : length of the result string.
1864 * If called with scrlen = -1, the function will compute the length
1865 * of the 0-terminated string strsrc by itself.
1867 * If called with dstlen = 0, returns the buffer length that
1868 * would be required.
1870 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1871 * as if they are equal.
1872 * In the only code page implemented so far, there may not be
1873 * wide characters in strings passed to LCMapStringA,
1874 * so there is nothing to be done for this flag.
1876 INT WINAPI
LCMapStringA(
1877 LCID lcid
/* locale identifier created with MAKELCID;
1878 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1879 predefined values. */,
1880 DWORD mapflags
/* flags */,
1881 LPCSTR srcstr
/* source buffer */,
1882 INT srclen
/* source length */,
1883 LPSTR dststr
/* destination buffer */,
1884 INT dstlen
/* destination buffer length */)
1888 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1889 lcid
,mapflags
,srcstr
,srclen
,dststr
,dstlen
);
1891 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1893 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr
, dststr
);
1894 SetLastError(ERROR_INVALID_PARAMETER
);
1898 srclen
= strlen(srcstr
) + 1 ; /* (include final '\0') */
1900 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1904 NORM_IGNORENONSPACE | \
1906 NORM_IGNOREWIDTH | \
1907 NORM_IGNOREKANATYPE)
1908 /* FIXME: as long as we don't support Kanakana nor Hirigana
1909 * characters, we can support NORM_IGNOREKANATYPE
1911 if (mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
)
1913 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1914 "unimplemented flags: 0x%08lx\n",
1921 mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
1925 if ( !(mapflags
& LCMAP_SORTKEY
) )
1928 int (*f
)(int) = identity
;
1929 int flag_ignorenonspace
= mapflags
& NORM_IGNORENONSPACE
;
1930 int flag_ignoresymbols
= mapflags
& NORM_IGNORESYMBOLS
;
1932 if (flag_ignorenonspace
|| flag_ignoresymbols
)
1934 /* For some values of mapflags, the length of the resulting
1935 string is not known at this point. Windows does map the string
1936 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1940 /* Compute required length */
1941 for (i
=j
=0; i
< srclen
; i
++)
1943 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1944 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1956 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1960 if (mapflags
& LCMAP_UPPERCASE
)
1962 else if (mapflags
& LCMAP_LOWERCASE
)
1964 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1965 for (i
=j
=0; (i
<srclen
) && (j
<dstlen
) ; i
++)
1967 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1968 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1970 dststr
[j
] = (CHAR
) f(srcstr
[i
]);
1977 /* FIXME: This function completely ignores the "lcid" parameter. */
1978 /* else ... (mapflags & LCMAP_SORTKEY) */
1982 int diacritic_len
=0;
1983 int delayed_punctuation_len
=0;
1984 char *case_component
;
1985 char *diacritic_component
;
1986 char *delayed_punctuation_component
;
1988 int flag_stringsort
= mapflags
& SORT_STRINGSORT
;
1990 /* compute how much room we will need */
1991 for (i
=0;i
<srclen
;i
++)
1994 unsigned char source_char
= srcstr
[i
];
1995 if (source_char
!='\0')
1997 if (flag_stringsort
|| !OLE2NLS_isPunctuation(source_char
))
2000 if ( LCM_Unicode_LUT
[-2+2*source_char
] & ~15 )
2001 unicode_len
++; /* double letter */
2005 delayed_punctuation_len
++;
2009 if (isupper(source_char
))
2010 case_len
=unicode_len
;
2012 ofs
= source_char
- LCM_Diacritic_Start
;
2013 if ((ofs
>=0) && (LCM_Diacritic_LUT
[ofs
]!=2))
2014 diacritic_len
=unicode_len
;
2017 if (mapflags
& NORM_IGNORECASE
)
2019 if (mapflags
& NORM_IGNORENONSPACE
)
2022 room
= 2 * unicode_len
/* "unicode" component */
2023 + diacritic_len
/* "diacritic" component */
2024 + case_len
/* "case" component */
2025 + 4 * delayed_punctuation_len
/* punctuation in word sort mode */
2026 + 4 /* four '\1' separators */
2027 + 1 ; /* terminal '\0' */
2030 else if (dstlen
<room
)
2032 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2036 /*FIXME the Pointercheck should not be nessesary */
2037 if (IsBadWritePtr (dststr
,room
))
2038 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr
,dstlen
);
2039 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2043 /* locate each component, write separators */
2044 diacritic_component
= dststr
+ 2*unicode_len
;
2045 *diacritic_component
++ = '\1';
2046 case_component
= diacritic_component
+ diacritic_len
;
2047 *case_component
++ = '\1';
2048 delayed_punctuation_component
= case_component
+ case_len
;
2049 *delayed_punctuation_component
++ = '\1';
2050 *delayed_punctuation_component
++ = '\1';
2052 /* read source string char by char, write
2053 corresponding weight in each component. */
2054 for (i
=0,count
=0;i
<srclen
;i
++)
2056 unsigned char source_char
=srcstr
[i
];
2057 if (source_char
!='\0')
2060 type
= LCM_Unicode_LUT
[-2+2*source_char
];
2061 longcode
= type
>> 4;
2063 if (!flag_stringsort
&& OLE2NLS_isPunctuation(source_char
))
2065 WORD encrypted_location
= (1<<15) + 7 + 4*count
;
2066 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
>>8);
2067 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
&255);
2068 /* big-endian is used here because it lets string comparison be
2069 compatible with numerical comparison */
2071 *delayed_punctuation_component
++ = type
;
2072 *delayed_punctuation_component
++ = LCM_Unicode_LUT
[-1+2*source_char
];
2073 /* assumption : a punctuation character is never a
2074 double or accented letter */
2078 dststr
[2*count
] = type
;
2079 dststr
[2*count
+1] = LCM_Unicode_LUT
[-1+2*source_char
];
2083 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
2084 if (count
<diacritic_len
)
2085 diacritic_component
[count
] = 2; /* assumption: a double letter
2086 is never accented */
2089 dststr
[2*count
] = type
;
2090 dststr
[2*count
+1] = *(LCM_Unicode_LUT_2
- 1 + longcode
);
2091 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
2092 32 in the first column of LCM_Unicode_LUT --> longcode = 2
2093 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
2097 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
2098 if (count
<diacritic_len
)
2100 int ofs
= source_char
- LCM_Diacritic_Start
;
2101 diacritic_component
[count
] = (ofs
>=0 ? LCM_Diacritic_LUT
[ofs
] : 2);
2107 dststr
[room
-1] = '\0';
2112 /*************************************************************************
2113 * LCMapStringW [KERNEL32.493]
2115 * Convert a string, or generate a sort key from it.
2119 * See LCMapStringA for documentation
2121 INT WINAPI
LCMapStringW(
2122 LCID lcid
,DWORD mapflags
,LPCWSTR srcstr
,INT srclen
,LPWSTR dststr
,
2127 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2128 lcid
, mapflags
, srcstr
, srclen
, dststr
, dstlen
);
2130 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
2132 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr
, dststr
);
2133 SetLastError(ERROR_INVALID_PARAMETER
);
2137 srclen
= strlenW(srcstr
)+1;
2139 /* FIXME: Both this function and it's companion LCMapStringA()
2140 * completely ignore the "lcid" parameter. In place of the "lcid"
2141 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2142 * environment variable prior to invoking this function. */
2143 if (mapflags
& LCMAP_SORTKEY
)
2145 /* Possible values of LC_COLLATE. */
2146 char *lc_collate_default
= 0; /* value prior to this function */
2147 char *lc_collate_env
= 0; /* value retrieved from the environment */
2149 /* General purpose index into strings of any type. */
2152 /* Lengths of various strings where the length is measured in
2153 * wide characters for wide character strings and in bytes for
2154 * native strings. The lengths include the NULL terminator. */
2155 size_t returned_len
= 0;
2156 size_t src_native_len
= 0;
2157 size_t dst_native_len
= 0;
2158 size_t dststr_libc_len
= 0;
2160 /* Native (character set determined by locale) versions of the
2161 * strings source and destination strings. */
2162 LPSTR src_native
= 0;
2163 LPSTR dst_native
= 0;
2165 /* Version of the source and destination strings using the
2166 * "wchar_t" Unicode data type needed by various libc functions. */
2167 wchar_t *srcstr_libc
= 0;
2168 wchar_t *dststr_libc
= 0;
2170 if(!(srcstr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2171 srclen
* sizeof(wchar_t))))
2173 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2174 srclen
* sizeof(wchar_t));
2175 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2179 /* Convert source string to a libc Unicode string. */
2180 for(str_idx
= 0; str_idx
< srclen
; str_idx
++)
2182 srcstr_libc
[str_idx
] = srcstr
[str_idx
];
2185 /* src_native should contain at most 3 bytes for each
2186 * multibyte characters in the original srcstr string. */
2187 src_native_len
= 3 * srclen
;
2188 if(!(src_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
2191 ERR("Unable to allocate %d bytes for src_native\n", src_native_len
);
2192 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2193 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2197 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2198 * current value is backed up so it can be restored after the
2199 * last LC_COLLATE sensitive function returns.
2201 * Even though the locale is adjusted for a minimum amount of
2202 * time a race condition exists where other threads may be
2203 * affected if they invoke LC_COLLATE sensitive functions. One
2204 * possible solution is to wrap all LC_COLLATE sensitive Wine
2205 * functions, like LCMapStringW(), in a mutex.
2207 * Another enhancement to the following would be to set the
2208 * LC_COLLATE locale category as a function of the "lcid"
2209 * parameter instead of the "LC_COLLATE" environment variable. */
2210 if(!(lc_collate_default
= setlocale(LC_COLLATE
, NULL
)))
2212 ERR("Unable to query the LC_COLLATE catagory\n");
2213 SetLastError(ERROR_INVALID_PARAMETER
);
2214 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2215 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2219 if(!(lc_collate_env
= setlocale(LC_COLLATE
, "")))
2221 ERR("Unable to inherit the LC_COLLATE locale category from the "
2222 "environment. The \"LC_COLLATE\" environment variable is "
2223 "\"%s\".\n", getenv("LC_COLLATE") ?
2224 getenv("LC_COLLATE") : "<unset>");
2225 SetLastError(ERROR_INVALID_PARAMETER
);
2226 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2227 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2231 TRACE("lc_collate_default = %s\n", lc_collate_default
);
2232 TRACE("lc_collate_env = %s\n", lc_collate_env
);
2234 /* Convert the libc Unicode string to a native multibyte character
2236 returned_len
= wcstombs(src_native
, srcstr_libc
, src_native_len
) + 1;
2237 if(returned_len
== 0)
2239 LPSTR srcstr_ascii
= (LPSTR
)HEAP_strdupWtoA(GetProcessHeap(),
2241 ERR("wcstombs failed. The string specified (%s) may contains an "
2242 "invalid character.\n", srcstr_ascii
);
2243 SetLastError(ERROR_INVALID_PARAMETER
);
2244 if(srcstr_ascii
) HeapFree(GetProcessHeap(), 0, srcstr_ascii
);
2245 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2246 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2247 setlocale(LC_COLLATE
, lc_collate_default
);
2250 else if(returned_len
> src_native_len
)
2252 src_native
[src_native_len
- 1] = 0;
2253 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2254 "than expected (%d bytes).\n", src_native
, returned_len
,
2257 /* Since this is an internal error I'm not sure what the correct
2259 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2261 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2262 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2263 setlocale(LC_COLLATE
, lc_collate_default
);
2266 src_native_len
= returned_len
;
2268 TRACE("src_native = %s src_native_len = %d\n",
2269 src_native
, src_native_len
);
2271 /* dst_native seems to contain at most 4 bytes for each byte in
2272 * the original src_native string. Change if need be since this
2273 * isn't documented by the strxfrm() man page. */
2274 dst_native_len
= 4 * src_native_len
;
2275 if(!(dst_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, dst_native_len
)))
2277 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len
);
2278 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2279 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2280 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2281 setlocale(LC_COLLATE
, lc_collate_default
);
2285 /* The actual translation is done by the following call to
2286 * strxfrm(). The surrounding code could have been simplified
2287 * by calling wcsxfrm() instead except that wcsxfrm() is not
2288 * available on older Linux systems (RedHat 4.1 with
2291 * Also, it is possible that the translation could be done by
2292 * various tables as it is done in LCMapStringA(). However, I'm
2293 * not sure what those tables are. */
2294 returned_len
= strxfrm(dst_native
, src_native
, dst_native_len
) + 1;
2296 if(returned_len
> dst_native_len
)
2298 dst_native
[dst_native_len
- 1] = 0;
2299 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2300 "than expected (%d bytes).\n", dst_native
, returned_len
,
2303 /* Since this is an internal error I'm not sure what the correct
2305 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2307 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2308 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2309 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2310 setlocale(LC_COLLATE
, lc_collate_default
);
2313 dst_native_len
= returned_len
;
2315 TRACE("dst_native = %s dst_native_len = %d\n",
2316 dst_native
, dst_native_len
);
2318 dststr_libc_len
= dst_native_len
;
2319 if(!(dststr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2320 dststr_libc_len
* sizeof(wchar_t))))
2322 ERR("Unable to allocate %d bytes for dststr_libc\n",
2323 dststr_libc_len
* sizeof(wchar_t));
2324 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2325 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2326 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2327 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2328 setlocale(LC_COLLATE
, lc_collate_default
);
2332 /* Convert the native multibyte string to a libc Unicode string. */
2333 returned_len
= mbstowcs(dststr_libc
, dst_native
, dst_native_len
) + 1;
2335 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2336 * function has returned. */
2337 setlocale(LC_COLLATE
, lc_collate_default
);
2339 if(returned_len
== 0)
2341 ERR("mbstowcs failed. The native version of the translated string "
2342 "(%s) may contain an invalid character.\n", dst_native
);
2343 SetLastError(ERROR_INVALID_PARAMETER
);
2344 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2345 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2346 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2347 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2352 if(returned_len
> dstlen
)
2354 ERR("mbstowcs returned a string that was longer (%d chars) "
2355 "than the buffer provided (%d chars).\n", returned_len
,
2357 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2358 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2359 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2360 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2361 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2364 dstlen
= returned_len
;
2366 /* Convert a libc Unicode string to the destination string. */
2367 for(str_idx
= 0; str_idx
< dstlen
; str_idx
++)
2369 dststr
[str_idx
] = dststr_libc
[str_idx
];
2371 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2372 *(((int *)dststr
) + 0),
2373 *(((int *)dststr
) + 1),
2374 *(((int *)dststr
) + 2),
2375 *(((int *)dststr
) + 3));
2379 dstlen
= returned_len
;
2381 TRACE("dstlen (return) = %d\n", dstlen
);
2382 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2383 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2384 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2385 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2390 int (*f
)(int)=identity
;
2396 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2400 if (mapflags
& LCMAP_UPPERCASE
)
2402 else if (mapflags
& LCMAP_LOWERCASE
)
2404 for (i
=0; i
< srclen
; i
++)
2405 dststr
[i
] = (WCHAR
) f(srcstr
[i
]);
2411 /***********************************************************************
2412 * OLE2NLS_EstimateMappingLength
2414 * Estimates the number of characters required to hold the string
2415 * computed by LCMapStringA.
2417 * The size is always over-estimated, with a fixed limit on the
2418 * amount of estimation error.
2420 * Note that len == -1 is not permitted.
2422 static inline int OLE2NLS_EstimateMappingLength(LCID lcid
, DWORD dwMapFlags
,
2423 LPCSTR str
, DWORD len
)
2425 /* Estimate only for small strings to keep the estimation error from
2426 * becoming too large. */
2427 if (len
< 128) return len
* 8 + 5;
2428 else return LCMapStringA(lcid
, dwMapFlags
, str
, len
, NULL
, 0);
2431 /******************************************************************************
2432 * CompareStringA [KERNEL32.143]
2433 * Compares two strings using locale
2437 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2442 * Defaults to a word sort, but uses a string sort if
2443 * SORT_STRINGSORT is set.
2444 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2448 * This implementation ignores the locale
2452 * Quite inefficient.
2454 UINT WINAPI
CompareStringA(
2455 DWORD lcid
, /* locale ID */
2456 DWORD fdwStyle
, /* comparison-style options */
2457 LPCSTR s1
, /* first string */
2458 DWORD l1
, /* length of first string */
2459 LPCSTR s2
, /* second string */
2460 DWORD l2
) /* length of second string */
2462 int mapstring_flags
;
2466 TRACE("%s and %s\n",
2467 debugstr_a (s1
), debugstr_a (s2
));
2469 if ( (s1
==NULL
) || (s2
==NULL
) )
2471 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1
, s2
);
2472 SetLastError(ERROR_INVALID_PARAMETER
);
2476 if(fdwStyle
& NORM_IGNORESYMBOLS
)
2477 FIXME("IGNORESYMBOLS not supported\n");
2479 if (l1
== -1) l1
= strlen(s1
);
2480 if (l2
== -1) l2
= strlen(s2
);
2482 mapstring_flags
= LCMAP_SORTKEY
| fdwStyle
;
2483 len1
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s1
, l1
);
2484 len2
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s2
, l2
);
2486 if ((len1
==0)||(len2
==0))
2487 return 0; /* something wrong happened */
2489 sk1
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, len1
+ len2
);
2491 if ( (!LCMapStringA(lcid
,mapstring_flags
,s1
,l1
,sk1
,len1
))
2492 || (!LCMapStringA(lcid
,mapstring_flags
,s2
,l2
,sk2
,len2
)) )
2494 ERR("Bug in LCmapStringA.\n");
2499 /* strcmp doesn't necessarily return -1, 0, or 1 */
2500 result
= strcmp(sk1
,sk2
);
2502 HeapFree(GetProcessHeap(),0,sk1
);
2509 /* must be greater, if we reach this point */
2513 /******************************************************************************
2514 * CompareStringW [KERNEL32.144]
2515 * This implementation ignores the locale
2516 * FIXME : Does only string sort. Should
2517 * be reimplemented the same way as CompareStringA.
2519 UINT WINAPI
CompareStringW(DWORD lcid
, DWORD fdwStyle
,
2520 LPCWSTR s1
, DWORD l1
, LPCWSTR s2
,DWORD l2
)
2523 if(fdwStyle
& NORM_IGNORENONSPACE
)
2524 FIXME("IGNORENONSPACE not supprted\n");
2525 if(fdwStyle
& NORM_IGNORESYMBOLS
)
2526 FIXME("IGNORESYMBOLS not supported\n");
2528 /* Is strcmp defaulting to string sort or to word sort?? */
2529 /* FIXME: Handle NORM_STRINGSORT */
2530 l1
= (l1
==-1)?strlenW(s1
):l1
;
2531 l2
= (l2
==-1)?strlenW(s2
):l2
;
2532 len
= l1
<l2
? l1
:l2
;
2533 ret
= (fdwStyle
& NORM_IGNORECASE
) ? strncmpiW(s1
,s2
,len
) : strncmpW(s1
,s2
,len
);
2534 /* not equal, return 1 or 3 */
2536 /* need to translate result */
2537 return ((int)ret
< 0) ? 1 : 3;
2539 /* same len, return 2 */
2540 if(l1
==l2
) return 2;
2541 /* the longer one is lexically greater */
2542 return (l1
<l2
)? 1 : 3;
2545 /******************************************************************************
2546 * OLE_GetFormatA [Internal]
2549 * If datelen == 0, it should return the reguired string length.
2551 This function implements stuff for GetDateFormat() and
2554 d single-digit (no leading zero) day (of month)
2555 dd two-digit day (of month)
2556 ddd short day-of-week name
2557 dddd long day-of-week name
2558 M single-digit month
2560 MMM short month name
2561 MMMM full month name
2562 y two-digit year, no leading 0
2564 yyyy four-digit year
2566 h hours with no leading zero (12-hour)
2567 hh hours with full two digits
2568 H hours with no leading zero (24-hour)
2569 HH hours with full two digits
2570 m minutes with no leading zero
2571 mm minutes with full two digits
2572 s seconds with no leading zero
2573 ss seconds with full two digits
2574 t time marker (A or P)
2575 tt time marker (AM, PM)
2576 '' used to quote literal characters
2577 '' (within a quoted string) indicates a literal '
2579 These functions REQUIRE valid locale, date, and format.
2581 static INT
OLE_GetFormatA(LCID locale
,
2585 LPCSTR _format
, /*in*/
2590 int count
, type
, inquote
, Overflow
;
2596 const char * _dgfmt
[] = { "%d", "%02d" };
2597 const char ** dgfmt
= _dgfmt
- 1;
2599 /* report, for debugging */
2600 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",
2601 locale
, flags
, tflags
,
2602 xtime
->wYear
,xtime
->wMonth
,xtime
->wDayOfWeek
,xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2603 _format
, _format
, date
, datelen
);
2606 FIXME("datelen = 0, returning 255\n");
2610 /* initalize state variables and output buffer */
2612 count
= 0; inquote
= 0; Overflow
= 0;
2614 date
[0] = buf
[0] = '\0';
2616 strcpy(format
,_format
);
2618 /* alter the formatstring, while it works for all languages now in wine
2619 its possible that it fails when the time looks like ss:mm:hh as example*/
2620 if (tflags
& (TIME_NOMINUTESORSECONDS
))
2621 { if ((pos
= strstr ( format
, ":mm")))
2622 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2625 if (tflags
& (TIME_NOSECONDS
))
2626 { if ((pos
= strstr ( format
, ":ss")))
2627 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2631 for (inpos
= 0;; inpos
++) {
2632 /* 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]); */
2634 if (format
[inpos
] == '\'') {
2635 if (format
[inpos
+1] == '\'') {
2637 date
[outpos
++] = '\'';
2640 continue; /* we did nothing to the output */
2642 } else if (format
[inpos
] == '\0') {
2643 date
[outpos
++] = '\0';
2644 if (outpos
> datelen
) Overflow
= 1;
2647 date
[outpos
++] = format
[inpos
];
2648 if (outpos
> datelen
) {
2650 date
[outpos
-1] = '\0'; /* this is the last place where
2651 it's safe to write */
2655 } else if ( (count
&& (format
[inpos
] != type
))
2657 || (count
== 2 && strchr("ghHmst", type
)) )
2661 GetLocaleInfoA(locale
,
2663 + (xtime
->wDayOfWeek
+6)%7,
2665 } else if (count
== 3) {
2666 GetLocaleInfoA(locale
,
2667 LOCALE_SABBREVDAYNAME1
2668 + (xtime
->wDayOfWeek
+6)%7,
2671 sprintf(buf
, dgfmt
[count
], xtime
->wDay
);
2673 } else if (type
== 'M') {
2675 GetLocaleInfoA(locale
,
2676 LOCALE_SABBREVMONTHNAME1
2677 + xtime
->wMonth
- 1,
2679 } else if (count
== 4) {
2680 GetLocaleInfoA(locale
,
2682 + xtime
->wMonth
- 1,
2685 sprintf(buf
, dgfmt
[count
], xtime
->wMonth
);
2687 } else if (type
== 'y') {
2689 sprintf(buf
, "%d", xtime
->wYear
);
2690 } else if (count
== 3) {
2692 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2694 sprintf(buf
, dgfmt
[count
], xtime
->wYear
% 100);
2696 } else if (type
== 'g') {
2698 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2702 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2704 } else if (type
== 'h') {
2705 /* gives us hours 1:00 -- 12:00 */
2706 sprintf(buf
, dgfmt
[count
], (xtime
->wHour
-1)%12 +1);
2707 } else if (type
== 'H') {
2709 sprintf(buf
, dgfmt
[count
], xtime
->wHour
);
2710 } else if ( type
== 'm') {
2711 sprintf(buf
, dgfmt
[count
], xtime
->wMinute
);
2712 } else if ( type
== 's') {
2713 sprintf(buf
, dgfmt
[count
], xtime
->wSecond
);
2714 } else if (type
== 't') {
2716 sprintf(buf
, "%c", (xtime
->wHour
< 12) ? 'A' : 'P');
2717 } else if (count
== 2) {
2718 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2719 GetLocaleInfoA(locale
,
2721 ? LOCALE_S1159
: LOCALE_S2359
,
2726 /* we need to check the next char in the format string
2727 again, no matter what happened */
2730 /* add the contents of buf to the output */
2731 buflen
= strlen(buf
);
2732 if (outpos
+ buflen
< datelen
) {
2733 date
[outpos
] = '\0'; /* for strcat to hook onto */
2737 date
[outpos
] = '\0';
2738 strncat(date
, buf
, datelen
- outpos
);
2739 date
[datelen
- 1] = '\0';
2740 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2741 WARN("insufficient buffer\n");
2745 /* reset the variables we used to keep track of this item */
2748 } else if (format
[inpos
] == '\0') {
2749 /* we can't check for this at the loop-head, because
2750 that breaks the printing of the last format-item */
2751 date
[outpos
] = '\0';
2754 /* continuing a code for an item */
2757 } else if (strchr("hHmstyMdg", format
[inpos
])) {
2758 type
= format
[inpos
];
2761 } else if (format
[inpos
] == '\'') {
2765 date
[outpos
++] = format
[inpos
];
2767 /* now deal with a possible buffer overflow */
2768 if (outpos
>= datelen
) {
2769 date
[datelen
- 1] = '\0';
2770 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2776 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2779 /* finish it off with a string terminator */
2782 if (outpos
> datelen
-1) outpos
= datelen
-1;
2783 date
[outpos
] = '\0';
2785 TRACE("OLE_GetFormatA returns string '%s', len %d\n",
2790 /******************************************************************************
2791 * OLE_GetFormatW [INTERNAL]
2793 static INT
OLE_GetFormatW(LCID locale
, DWORD flags
, DWORD tflags
,
2796 LPWSTR output
, INT outlen
)
2799 int count
, type
=0, inquote
;
2800 int Overflow
; /* loop check */
2804 WCHAR arg0
[] = {0}, arg1
[] = {'%','d',0};
2805 WCHAR arg2
[] = {'%','0','2','d',0};
2807 int datevars
=0, timevars
=0;
2813 /* make a debug report */
2814 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2815 "%p with max len %d\n",
2816 locale
, flags
, tflags
,
2817 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2818 debugstr_w(format
), format
, output
, outlen
);
2821 FIXME("outlen = 0, returning 255\n");
2825 /* initialize state variables */
2828 inquote
= Overflow
= 0;
2829 /* this is really just a sanity check */
2830 output
[0] = buf
[0] = 0;
2832 /* this loop is the core of the function */
2833 for (inpos
= 0; /* we have several break points */ ; inpos
++) {
2835 if (format
[inpos
] == (WCHAR
) '\'') {
2836 if (format
[inpos
+1] == '\'') {
2838 output
[outpos
++] = '\'';
2843 } else if (format
[inpos
] == 0) {
2844 output
[outpos
++] = 0;
2845 if (outpos
> outlen
) Overflow
= 1;
2846 break; /* normal exit (within a quote) */
2848 output
[outpos
++] = format
[inpos
]; /* copy input */
2849 if (outpos
> outlen
) {
2851 output
[outpos
-1] = 0;
2855 } else if ( (count
&& (format
[inpos
] != type
))
2856 || ( (count
==4 && type
=='y') ||
2857 (count
==4 && type
=='M') ||
2858 (count
==4 && type
=='d') ||
2859 (count
==2 && type
=='g') ||
2860 (count
==2 && type
=='h') ||
2861 (count
==2 && type
=='H') ||
2862 (count
==2 && type
=='m') ||
2863 (count
==2 && type
=='s') ||
2864 (count
==2 && type
=='t') ) ) {
2869 GetLocaleInfoW(locale
,
2870 LOCALE_SDAYNAME1
+ (xtime
->wDayOfWeek
+6)%7,
2871 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2872 } else if (count
== 3) {
2873 GetLocaleInfoW(locale
,
2874 LOCALE_SABBREVDAYNAME1
+
2875 (xtime
->wDayOfWeek
+6)%7,
2876 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2878 sprintf( tmp
, "%.*d", count
, xtime
->wDay
);
2879 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2885 GetLocaleInfoW(locale
, LOCALE_SMONTHNAME1
+
2886 xtime
->wMonth
-1, buf
,
2887 sizeof(buf
)/sizeof(WCHAR
) );
2888 } else if (count
== 3) {
2889 GetLocaleInfoW(locale
, LOCALE_SABBREVMONTHNAME1
+
2890 xtime
->wMonth
-1, buf
,
2891 sizeof(buf
)/sizeof(WCHAR
) );
2893 sprintf( tmp
, "%.*d", count
, xtime
->wMonth
);
2894 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2899 sprintf( tmp
, "%d", xtime
->wYear
);
2900 } else if (count
== 3) {
2901 strcpy( tmp
, "yyy" );
2903 sprintf( tmp
, "%.*d", count
, xtime
->wYear
% 100 );
2905 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2910 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2911 strcpy( tmp
, "AD" );
2913 /* Win API sez we copy it verbatim */
2916 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2920 /* hours 1:00-12:00 --- is this right? */
2921 sprintf( tmp
, "%.*d", count
, (xtime
->wHour
-1)%12 +1);
2922 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2926 sprintf( tmp
, "%.*d", count
, xtime
->wHour
);
2927 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2931 sprintf( tmp
, "%.*d", count
, xtime
->wMinute
);
2932 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2936 sprintf( tmp
, "%.*d", count
, xtime
->wSecond
);
2937 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2941 GetLocaleInfoW(locale
, (xtime
->wHour
< 12) ?
2942 LOCALE_S1159
: LOCALE_S2359
,
2950 /* no matter what happened, we need to check this next
2951 character the next time we loop through */
2954 /* cat buf onto the output */
2955 outlen
= strlenW(buf
);
2956 if (outpos
+ buflen
< outlen
) {
2957 strcpyW( output
+ outpos
, buf
);
2960 lstrcpynW( output
+ outpos
, buf
, outlen
- outpos
);
2962 break; /* Abnormal exit */
2965 /* reset the variables we used this time */
2968 } else if (format
[inpos
] == 0) {
2969 /* we can't check for this at the beginning, because that
2970 would keep us from printing a format spec that ended the
2973 break; /* NORMAL EXIT */
2975 /* how we keep track of the middle of a format spec */
2978 } else if ( (datevars
&& (format
[inpos
]=='d' ||
2979 format
[inpos
]=='M' ||
2980 format
[inpos
]=='y' ||
2981 format
[inpos
]=='g') ) ||
2982 (timevars
&& (format
[inpos
]=='H' ||
2983 format
[inpos
]=='h' ||
2984 format
[inpos
]=='m' ||
2985 format
[inpos
]=='s' ||
2986 format
[inpos
]=='t') ) ) {
2987 type
= format
[inpos
];
2990 } else if (format
[inpos
] == '\'') {
2994 /* unquoted literals */
2995 output
[outpos
++] = format
[inpos
];
3000 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3001 WARN(" buffer overflow\n");
3004 /* final string terminator and sanity check */
3006 if (outpos
> outlen
-1) outpos
= outlen
-1;
3007 output
[outpos
] = '0';
3009 TRACE(" returning %s\n", debugstr_w(output
));
3011 return (!Overflow
) ? outlen
: 0;
3016 /******************************************************************************
3017 * GetDateFormatA [KERNEL32.310]
3018 * Makes an ASCII string of the date
3020 * This function uses format to format the date, or, if format
3021 * is NULL, uses the default for the locale. format is a string
3022 * of literal fields and characters as follows:
3024 * - d single-digit (no leading zero) day (of month)
3025 * - dd two-digit day (of month)
3026 * - ddd short day-of-week name
3027 * - dddd long day-of-week name
3028 * - M single-digit month
3029 * - MM two-digit month
3030 * - MMM short month name
3031 * - MMMM full month name
3032 * - y two-digit year, no leading 0
3033 * - yy two-digit year
3034 * - yyyy four-digit year
3038 INT WINAPI
GetDateFormatA(LCID locale
,DWORD flags
,
3040 LPCSTR format
, LPSTR date
,INT datelen
)
3043 char format_buf
[40];
3046 LPSYSTEMTIME thistime
;
3052 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
3053 locale
,flags
,xtime
,format
,date
,datelen
);
3056 locale
= LOCALE_SYSTEM_DEFAULT
;
3059 if (locale
== LOCALE_SYSTEM_DEFAULT
) {
3060 thislocale
= GetSystemDefaultLCID();
3061 } else if (locale
== LOCALE_USER_DEFAULT
) {
3062 thislocale
= GetUserDefaultLCID();
3064 thislocale
= locale
;
3067 if (xtime
== NULL
) {
3070 /* Silently correct wDayOfWeek by tranforming to FileTime and back again*/
3071 res
=SystemTimeToFileTime(xtime
,&ft
);
3072 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error*/
3073 /*FIXME: SystemTimeToFileTime doesn't yet do that ckeck*/
3076 SetLastError(ERROR_INVALID_PARAMETER
);
3079 FileTimeToSystemTime(&ft
,&t
);
3084 if (format
== NULL
) {
3085 GetLocaleInfoA(thislocale
, ((flags
&DATE_LONGDATE
)
3087 : LOCALE_SSHORTDATE
),
3088 format_buf
, sizeof(format_buf
));
3089 thisformat
= format_buf
;
3091 thisformat
= format
;
3095 ret
= OLE_GetFormatA(thislocale
, flags
, 0, thistime
, thisformat
,
3100 "GetDateFormatA() returning %d, with data=%s\n",
3105 /******************************************************************************
3106 * GetDateFormatW [KERNEL32.311]
3107 * Makes a Unicode string of the date
3109 * Acts the same as GetDateFormatA(), except that it's Unicode.
3110 * Accepts & returns sizes as counts of Unicode characters.
3113 INT WINAPI
GetDateFormatW(LCID locale
,DWORD flags
,
3116 LPWSTR date
, INT datelen
)
3118 unsigned short datearr
[] = {'1','9','9','4','-','1','-','1',0};
3120 FIXME("STUB (should call OLE_GetFormatW)\n");
3121 lstrcpynW(date
, datearr
, datelen
);
3122 return ( datelen
< 9) ? datelen
: 9;
3127 /**************************************************************************
3128 * EnumDateFormatsA (KERNEL32.198)
3130 BOOL WINAPI
EnumDateFormatsA(
3131 DATEFMT_ENUMPROCA lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3133 LCID Loc
= GetUserDefaultLCID();
3134 if(!lpDateFmtEnumProc
)
3136 SetLastError(ERROR_INVALID_PARAMETER
);
3143 case 0x00000407: /* (Loc,"de_DE") */
3147 case DATE_SHORTDATE
:
3148 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
3149 if(!(*lpDateFmtEnumProc
)("d.M.yyyy")) return TRUE
;
3150 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
3151 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3154 if(!(*lpDateFmtEnumProc
)("dddd,d. MMMM yyyy")) return TRUE
;
3155 if(!(*lpDateFmtEnumProc
)("d. MMMM yyyy")) return TRUE
;
3156 if(!(*lpDateFmtEnumProc
)("d. MMM yyyy")) return TRUE
;
3159 FIXME("Unknown date format (%ld)\n", dwFlags
);
3160 SetLastError(ERROR_INVALID_PARAMETER
);
3165 case 0x0000040c: /* (Loc,"fr_FR") */
3169 case DATE_SHORTDATE
:
3170 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3171 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
3172 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3173 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3176 if(!(*lpDateFmtEnumProc
)("dddd d MMMM yyyy")) return TRUE
;
3177 if(!(*lpDateFmtEnumProc
)("d MMM yy")) return TRUE
;
3178 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3181 FIXME("Unknown date format (%ld)\n", dwFlags
);
3182 SetLastError(ERROR_INVALID_PARAMETER
);
3187 case 0x00000c0c: /* (Loc,"fr_CA") */
3191 case DATE_SHORTDATE
:
3192 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3193 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3194 if(!(*lpDateFmtEnumProc
)("yy MM dd")) return TRUE
;
3195 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3198 if(!(*lpDateFmtEnumProc
)("d MMMM, yyyy")) return TRUE
;
3199 if(!(*lpDateFmtEnumProc
)("d MMM yyyy")) return TRUE
;
3202 FIXME("Unknown date format (%ld)\n", dwFlags
);
3203 SetLastError(ERROR_INVALID_PARAMETER
);
3208 case 0x00000809: /* (Loc,"en_UK") */
3212 case DATE_SHORTDATE
:
3213 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3214 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3215 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3216 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3219 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3220 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3223 FIXME("Unknown date format (%ld)\n", dwFlags
);
3224 SetLastError(ERROR_INVALID_PARAMETER
);
3229 case 0x00000c09: /* (Loc,"en_AU") */
3233 case DATE_SHORTDATE
:
3234 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3235 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3236 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3239 if(!(*lpDateFmtEnumProc
)("dddd,d MMMM yyyy")) return TRUE
;
3240 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3243 FIXME("Unknown date format (%ld)\n", dwFlags
);
3244 SetLastError(ERROR_INVALID_PARAMETER
);
3249 case 0x00001009: /* (Loc,"en_CA") */
3253 case DATE_SHORTDATE
:
3254 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3255 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3256 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3257 if(!(*lpDateFmtEnumProc
)("M/dd/yy")) return TRUE
;
3260 if(!(*lpDateFmtEnumProc
)("d-MMM-yy")) return TRUE
;
3261 if(!(*lpDateFmtEnumProc
)("MMMM d, yyyy")) return TRUE
;
3264 FIXME("Unknown date format (%ld)\n", dwFlags
);
3265 SetLastError(ERROR_INVALID_PARAMETER
);
3270 case 0x00001409: /* (Loc,"en_NZ") */
3274 case DATE_SHORTDATE
:
3275 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3276 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3277 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
3280 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3281 if(!(*lpDateFmtEnumProc
)("dddd, d MMMM yyyy")) return TRUE
;
3284 FIXME("Unknown date format (%ld)\n", dwFlags
);
3285 SetLastError(ERROR_INVALID_PARAMETER
);
3290 case 0x00001809: /* (Loc,"en_IE") */
3294 case DATE_SHORTDATE
:
3295 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3296 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3297 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3300 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3301 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3304 FIXME("Unknown date format (%ld)\n", dwFlags
);
3305 SetLastError(ERROR_INVALID_PARAMETER
);
3310 case 0x00001c09: /* (Loc,"en_ZA") */
3314 case DATE_SHORTDATE
:
3315 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3318 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3321 FIXME("Unknown date format (%ld)\n", dwFlags
);
3322 SetLastError(ERROR_INVALID_PARAMETER
);
3327 case 0x00002009: /* (Loc,"en_JM") */
3331 case DATE_SHORTDATE
:
3332 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3335 if(!(*lpDateFmtEnumProc
)("dddd,MMMM dd,yyyy")) return TRUE
;
3336 if(!(*lpDateFmtEnumProc
)("MMMM dd,yyyy")) return TRUE
;
3337 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM,yyyy")) return TRUE
;
3338 if(!(*lpDateFmtEnumProc
)("dd MMMM,yyyy")) return TRUE
;
3341 FIXME("Unknown date format (%ld)\n", dwFlags
);
3342 SetLastError(ERROR_INVALID_PARAMETER
);
3347 case 0x00002809: /* (Loc,"en_BZ") */
3348 case 0x00002c09: /* (Loc,"en_TT") */
3352 case DATE_SHORTDATE
:
3353 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3356 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM yyyy")) return TRUE
;
3359 FIXME("Unknown date format (%ld)\n", dwFlags
);
3360 SetLastError(ERROR_INVALID_PARAMETER
);
3365 default: /* default to US English "en_US" */
3369 case DATE_SHORTDATE
:
3370 if(!(*lpDateFmtEnumProc
)("M/d/yy")) return TRUE
;
3371 if(!(*lpDateFmtEnumProc
)("M/d/yyyy")) return TRUE
;
3372 if(!(*lpDateFmtEnumProc
)("MM/dd/yy")) return TRUE
;
3373 if(!(*lpDateFmtEnumProc
)("MM/dd/yyyy")) return TRUE
;
3374 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3375 if(!(*lpDateFmtEnumProc
)("dd-MMM-yy")) return TRUE
;
3378 if(!(*lpDateFmtEnumProc
)("dddd, MMMM dd, yyyy")) return TRUE
;
3379 if(!(*lpDateFmtEnumProc
)("MMMM dd, yyyy")) return TRUE
;
3380 if(!(*lpDateFmtEnumProc
)("dddd, dd MMMM, yyyy")) return TRUE
;
3381 if(!(*lpDateFmtEnumProc
)("dd MMMM, yyyy")) return TRUE
;
3384 FIXME("Unknown date format (%ld)\n", dwFlags
);
3385 SetLastError(ERROR_INVALID_PARAMETER
);
3392 /**************************************************************************
3393 * EnumDateFormatsW (KERNEL32.199)
3395 BOOL WINAPI
EnumDateFormatsW(
3396 DATEFMT_ENUMPROCW lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3398 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc
, Locale
, dwFlags
);
3399 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3403 /**************************************************************************
3404 * EnumTimeFormatsA (KERNEL32.210)
3406 BOOL WINAPI
EnumTimeFormatsA(
3407 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3409 LCID Loc
= GetUserDefaultLCID();
3410 if(!lpTimeFmtEnumProc
)
3412 SetLastError(ERROR_INVALID_PARAMETER
);
3417 FIXME("Unknown time format (%ld)\n", dwFlags
);
3422 case 0x00000407: /* (Loc,"de_DE") */
3424 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3425 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3426 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3427 if(!(*lpTimeFmtEnumProc
)("H.mm")) return TRUE
;
3428 if(!(*lpTimeFmtEnumProc
)("H.mm'Uhr'")) return TRUE
;
3432 case 0x0000040c: /* (Loc,"fr_FR") */
3433 case 0x00000c0c: /* (Loc,"fr_CA") */
3435 if(!(*lpTimeFmtEnumProc
)("H:mm")) return TRUE
;
3436 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3437 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3438 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3439 if(!(*lpTimeFmtEnumProc
)("HH'h'mm")) return TRUE
;
3443 case 0x00000809: /* (Loc,"en_UK") */
3444 case 0x00000c09: /* (Loc,"en_AU") */
3445 case 0x00001409: /* (Loc,"en_NZ") */
3446 case 0x00001809: /* (Loc,"en_IE") */
3448 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3449 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3450 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3454 case 0x00001c09: /* (Loc,"en_ZA") */
3455 case 0x00002809: /* (Loc,"en_BZ") */
3456 case 0x00002c09: /* (Loc,"en_TT") */
3458 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3459 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3463 default: /* default to US style "en_US" */
3465 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3466 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3467 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3468 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3474 /**************************************************************************
3475 * EnumTimeFormatsW (KERNEL32.211)
3477 BOOL WINAPI
EnumTimeFormatsW(
3478 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3480 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc
, Locale
, dwFlags
);
3481 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3485 /**************************************************************************
3486 * This function is used just locally !
3487 * Description: Inverts a string.
3489 static void OLE_InvertString(char* string
)
3491 char sTmpArray
[128];
3494 for (counter
= strlen(string
); counter
> 0; counter
--)
3496 memcpy(sTmpArray
+ i
, string
+ counter
-1, 1);
3499 memcpy(sTmpArray
+ i
, "\0", 1);
3500 strcpy(string
, sTmpArray
);
3503 /***************************************************************************************
3504 * This function is used just locally !
3505 * Description: Test if the given string (psNumber) is valid or not.
3506 * The valid characters are the following:
3507 * - Characters '0' through '9'.
3508 * - One decimal point (dot) if the number is a floating-point value.
3509 * - A minus sign in the first character position if the number is
3511 * If the function succeeds, psBefore/psAfter will point to the string
3512 * on the right/left of the decimal symbol. pbNegative indicates if the
3513 * number is negative.
3515 static INT
OLE_GetNumberComponents(char* pInput
, char* psBefore
, char* psAfter
, BOOL
* pbNegative
)
3517 char sNumberSet
[] = "0123456789";
3518 BOOL bInDecimal
= FALSE
;
3520 /* Test if we do have a minus sign */
3521 if ( *pInput
== '-' )
3524 pInput
++; /* Jump to the next character. */
3527 while(*pInput
!= '\0')
3529 /* Do we have a valid numeric character */
3530 if ( strchr(sNumberSet
, *pInput
) != NULL
)
3532 if (bInDecimal
== TRUE
)
3533 *psAfter
++ = *pInput
;
3535 *psBefore
++ = *pInput
;
3539 /* Is this a decimal point (dot) */
3540 if ( *pInput
== '.' )
3542 /* Is it the first time we find it */
3543 if ((bInDecimal
== FALSE
))
3546 return -1; /* ERROR: Invalid parameter */
3550 /* It's neither a numeric character, nor a decimal point.
3551 * Thus, return an error.
3559 /* Add an End of Line character to the output buffers */
3566 /**************************************************************************
3567 * This function is used just locally !
3568 * Description: A number could be formatted using different numbers
3569 * of "digits in group" (example: 4;3;2;0).
3570 * The first parameter of this function is an array
3571 * containing the rule to be used. It's format is the following:
3572 * |NDG|DG1|DG2|...|0|
3573 * where NDG is the number of used "digits in group" and DG1, DG2,
3574 * are the corresponding "digits in group".
3575 * Thus, this function returns the grouping value in the array
3576 * pointed by the second parameter.
3578 static INT
OLE_GetGrouping(char* sRule
, INT index
)
3580 char sData
[2], sRuleSize
[2];
3581 INT nData
, nRuleSize
;
3583 memcpy(sRuleSize
, sRule
, 1);
3584 memcpy(sRuleSize
+1, "\0", 1);
3585 nRuleSize
= atoi(sRuleSize
);
3587 if (index
> 0 && index
< nRuleSize
)
3589 memcpy(sData
, sRule
+index
, 1);
3590 memcpy(sData
+1, "\0", 1);
3591 nData
= atoi(sData
);
3596 memcpy(sData
, sRule
+nRuleSize
-1, 1);
3597 memcpy(sData
+1, "\0", 1);
3598 nData
= atoi(sData
);
3604 /**************************************************************************
3605 * GetNumberFormatA (KERNEL32.355)
3607 INT WINAPI
GetNumberFormatA(LCID locale
, DWORD dwflags
,
3608 LPCSTR lpvalue
, const NUMBERFMTA
* lpFormat
,
3609 LPSTR lpNumberStr
, int cchNumber
)
3611 char sNumberDigits
[3], sDecimalSymbol
[5], sDigitsInGroup
[11], sDigitGroupSymbol
[5], sILZero
[2];
3612 INT nNumberDigits
, nNumberDecimal
, i
, j
, nCounter
, nStep
, nRuleIndex
, nGrouping
, nDigits
, retVal
, nLZ
;
3613 char sNumber
[128], sDestination
[128], sDigitsAfterDecimal
[10], sDigitsBeforeDecimal
[128];
3614 char sRule
[10], sSemiColumn
[]=";", sBuffer
[5], sNegNumber
[2];
3615 char *pStr
= NULL
, *pTmpStr
= NULL
;
3616 LCID systemDefaultLCID
;
3617 BOOL bNegative
= FALSE
;
3626 strncpy(sNumber
, lpvalue
, 128);
3627 sNumber
[127] = '\0';
3629 /* Make sure we have a valid input string, get the number
3630 * of digits before and after the decimal symbol, and check
3631 * if this is a negative number.
3633 if ( OLE_GetNumberComponents(sNumber
, sDigitsBeforeDecimal
, sDigitsAfterDecimal
, &bNegative
) != -1)
3635 nNumberDecimal
= strlen(sDigitsBeforeDecimal
);
3636 nDigits
= strlen(sDigitsAfterDecimal
);
3640 SetLastError(ERROR_INVALID_PARAMETER
);
3644 /* Which source will we use to format the string */
3645 used_operation
= RETURN_ERROR
;
3646 if (lpFormat
!= NULL
)
3649 used_operation
= USE_PARAMETER
;
3653 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3654 used_operation
= USE_LOCALEINFO
;
3656 used_operation
= USE_SYSTEMDEFAULT
;
3659 /* Load the fields we need */
3660 switch(used_operation
)
3662 case USE_LOCALEINFO
:
3663 GetLocaleInfoA(locale
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3664 GetLocaleInfoA(locale
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3665 GetLocaleInfoA(locale
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3666 GetLocaleInfoA(locale
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3667 GetLocaleInfoA(locale
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3668 GetLocaleInfoA(locale
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3671 sprintf(sNumberDigits
, "%d",lpFormat
->NumDigits
);
3672 strcpy(sDecimalSymbol
, lpFormat
->lpDecimalSep
);
3673 sprintf(sDigitsInGroup
, "%d;0",lpFormat
->Grouping
);
3674 strcpy(sDigitGroupSymbol
, lpFormat
->lpThousandSep
);
3675 sprintf(sILZero
, "%d",lpFormat
->LeadingZero
);
3676 sprintf(sNegNumber
, "%d",lpFormat
->NegativeOrder
);
3678 case USE_SYSTEMDEFAULT
:
3679 systemDefaultLCID
= GetSystemDefaultLCID();
3680 GetLocaleInfoA(systemDefaultLCID
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3681 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3682 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3683 GetLocaleInfoA(systemDefaultLCID
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3684 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3685 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3688 SetLastError(ERROR_INVALID_PARAMETER
);
3692 nNumberDigits
= atoi(sNumberDigits
);
3694 /* Remove the ";" */
3697 for (nCounter
=0; nCounter
<strlen(sDigitsInGroup
); nCounter
++)
3699 if ( memcmp(sDigitsInGroup
+ nCounter
, sSemiColumn
, 1) != 0 )
3701 memcpy(sRule
+ j
, sDigitsInGroup
+ nCounter
, 1);
3706 sprintf(sBuffer
, "%d", i
);
3707 memcpy(sRule
, sBuffer
, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3708 memcpy(sRule
+ j
, "\0", 1);
3710 /* First, format the digits before the decimal. */
3711 if ((nNumberDecimal
>0) && (atoi(sDigitsBeforeDecimal
) != 0))
3713 /* Working on an inverted string is easier ! */
3714 OLE_InvertString(sDigitsBeforeDecimal
);
3716 nStep
= nCounter
= i
= j
= 0;
3718 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3720 /* Here, we will loop until we reach the end of the string.
3721 * An internal counter (j) is used in order to know when to
3722 * insert the "digit group symbol".
3724 while (nNumberDecimal
> 0)
3726 i
= nCounter
+ nStep
;
3727 memcpy(sDestination
+ i
, sDigitsBeforeDecimal
+ nCounter
, 1);
3733 if (nRuleIndex
< sRule
[0])
3735 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3736 memcpy(sDestination
+ i
+1, sDigitGroupSymbol
, strlen(sDigitGroupSymbol
));
3737 nStep
+= strlen(sDigitGroupSymbol
);
3743 memcpy(sDestination
+ i
+1, "\0", 1);
3744 /* Get the string in the right order ! */
3745 OLE_InvertString(sDestination
);
3749 nLZ
= atoi(sILZero
);
3752 /* Use 0.xxx instead of .xxx */
3753 memcpy(sDestination
, "0", 1);
3754 memcpy(sDestination
+1, "\0", 1);
3757 memcpy(sDestination
, "\0", 1);
3761 /* Second, format the digits after the decimal. */
3763 nCounter
= nNumberDigits
;
3764 if ( (nDigits
>0) && (pStr
= strstr (sNumber
, ".")) )
3766 i
= strlen(sNumber
) - strlen(pStr
) + 1;
3767 strncpy ( sDigitsAfterDecimal
, sNumber
+ i
, nNumberDigits
);
3768 j
= strlen(sDigitsAfterDecimal
);
3769 if (j
< nNumberDigits
)
3770 nCounter
= nNumberDigits
-j
;
3772 for (i
=0;i
<nCounter
;i
++)
3773 memcpy(sDigitsAfterDecimal
+i
+j
, "0", 1);
3774 memcpy(sDigitsAfterDecimal
+ nNumberDigits
, "\0", 1);
3776 i
= strlen(sDestination
);
3777 j
= strlen(sDigitsAfterDecimal
);
3778 /* Finally, construct the resulting formatted string. */
3780 for (nCounter
=0; nCounter
<i
; nCounter
++)
3781 memcpy(sNumber
+ nCounter
, sDestination
+ nCounter
, 1);
3783 memcpy(sNumber
+ nCounter
, sDecimalSymbol
, strlen(sDecimalSymbol
));
3786 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), sDigitsAfterDecimal
+ i
, 1);
3787 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), "\0", 1);
3789 /* Is it a negative number */
3790 if (bNegative
== TRUE
)
3792 i
= atoi(sNegNumber
);
3793 pStr
= sDestination
;
3799 while (*sNumber
!= '\0')
3800 *pStr
++ = *pTmpStr
++;
3805 while (*pTmpStr
!= '\0')
3806 *pStr
++ = *pTmpStr
++;
3811 while (*pTmpStr
!= '\0')
3812 *pStr
++ = *pTmpStr
++;
3815 while (*pTmpStr
!= '\0')
3816 *pStr
++ = *pTmpStr
++;
3820 while (*pTmpStr
!= '\0')
3821 *pStr
++ = *pTmpStr
++;
3826 while (*pTmpStr
!= '\0')
3827 *pStr
++ = *pTmpStr
++;
3832 strcpy(sDestination
, sNumber
);
3834 /* If cchNumber is zero, then returns the number of bytes or characters
3835 * required to hold the formatted number string
3838 retVal
= strlen(sDestination
) + 1;
3841 strncpy (lpNumberStr
, sDestination
, cchNumber
-1);
3842 *(lpNumberStr
+cchNumber
-1) = '\0'; /* ensure we got a NULL at the end */
3843 retVal
= strlen(lpNumberStr
);
3849 /**************************************************************************
3850 * GetNumberFormatW (KERNEL32.xxx)
3852 INT WINAPI
GetNumberFormatW(LCID locale
, DWORD dwflags
,
3853 LPCWSTR lpvalue
, const NUMBERFMTW
* lpFormat
,
3854 LPWSTR lpNumberStr
, int cchNumber
)
3856 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue
));
3858 lstrcpynW( lpNumberStr
, lpvalue
, cchNumber
);
3859 return cchNumber
? strlenW( lpNumberStr
) : 0;
3862 /**************************************************************************
3863 * GetCurrencyFormatA (KERNEL32.302)
3865 INT WINAPI
GetCurrencyFormatA(LCID locale
, DWORD dwflags
,
3866 LPCSTR lpvalue
, const CURRENCYFMTA
* lpFormat
,
3867 LPSTR lpCurrencyStr
, int cchCurrency
)
3869 UINT nPosOrder
, nNegOrder
;
3871 char sDestination
[128], sNegOrder
[8], sPosOrder
[8], sCurrencySymbol
[8];
3872 char *pDestination
= sDestination
;
3873 char sNumberFormated
[128];
3874 char *pNumberFormated
= sNumberFormated
;
3875 LCID systemDefaultLCID
;
3876 BOOL bIsPositive
= FALSE
, bValidFormat
= FALSE
;
3885 NUMBERFMTA numberFmt
;
3887 /* Which source will we use to format the string */
3888 used_operation
= RETURN_ERROR
;
3889 if (lpFormat
!= NULL
)
3892 used_operation
= USE_PARAMETER
;
3896 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3897 used_operation
= USE_LOCALEINFO
;
3899 used_operation
= USE_SYSTEMDEFAULT
;
3902 /* Load the fields we need */
3903 switch(used_operation
)
3905 case USE_LOCALEINFO
:
3906 /* Specific to CURRENCYFMTA*/
3907 GetLocaleInfoA(locale
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3908 GetLocaleInfoA(locale
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3909 GetLocaleInfoA(locale
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3911 nPosOrder
= atoi(sPosOrder
);
3912 nNegOrder
= atoi(sNegOrder
);
3915 /* Specific to CURRENCYFMTA*/
3916 nNegOrder
= lpFormat
->NegativeOrder
;
3917 nPosOrder
= lpFormat
->PositiveOrder
;
3918 strcpy(sCurrencySymbol
, lpFormat
->lpCurrencySymbol
);
3920 case USE_SYSTEMDEFAULT
:
3921 systemDefaultLCID
= GetSystemDefaultLCID();
3922 /* Specific to CURRENCYFMTA*/
3923 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3924 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3925 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3927 nPosOrder
= atoi(sPosOrder
);
3928 nNegOrder
= atoi(sNegOrder
);
3931 SetLastError(ERROR_INVALID_PARAMETER
);
3935 /* Construct a temporary number format structure */
3936 if (lpFormat
!= NULL
)
3938 numberFmt
.NumDigits
= lpFormat
->NumDigits
;
3939 numberFmt
.LeadingZero
= lpFormat
->LeadingZero
;
3940 numberFmt
.Grouping
= lpFormat
->Grouping
;
3941 numberFmt
.NegativeOrder
= 0;
3942 numberFmt
.lpDecimalSep
= lpFormat
->lpDecimalSep
;
3943 numberFmt
.lpThousandSep
= lpFormat
->lpThousandSep
;
3944 bValidFormat
= TRUE
;
3947 /* Make a call to GetNumberFormatA() */
3948 if (*lpvalue
== '-')
3950 bIsPositive
= FALSE
;
3951 retVal
= GetNumberFormatA(locale
,0,lpvalue
+1,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3956 retVal
= GetNumberFormatA(locale
,0,lpvalue
,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3962 /* construct the formatted string */
3967 case 0: /* Prefix, no separation */
3968 strcpy (pDestination
, sCurrencySymbol
);
3969 strcat (pDestination
, pNumberFormated
);
3971 case 1: /* Suffix, no separation */
3972 strcpy (pDestination
, pNumberFormated
);
3973 strcat (pDestination
, sCurrencySymbol
);
3975 case 2: /* Prefix, 1 char separation */
3976 strcpy (pDestination
, sCurrencySymbol
);
3977 strcat (pDestination
, " ");
3978 strcat (pDestination
, pNumberFormated
);
3980 case 3: /* Suffix, 1 char separation */
3981 strcpy (pDestination
, pNumberFormated
);
3982 strcat (pDestination
, " ");
3983 strcat (pDestination
, sCurrencySymbol
);
3986 SetLastError(ERROR_INVALID_PARAMETER
);
3990 else /* negative number */
3994 case 0: /* format: ($1.1) */
3995 strcpy (pDestination
, "(");
3996 strcat (pDestination
, sCurrencySymbol
);
3997 strcat (pDestination
, pNumberFormated
);
3998 strcat (pDestination
, ")");
4000 case 1: /* format: -$1.1 */
4001 strcpy (pDestination
, "-");
4002 strcat (pDestination
, sCurrencySymbol
);
4003 strcat (pDestination
, pNumberFormated
);
4005 case 2: /* format: $-1.1 */
4006 strcpy (pDestination
, sCurrencySymbol
);
4007 strcat (pDestination
, "-");
4008 strcat (pDestination
, pNumberFormated
);
4010 case 3: /* format: $1.1- */
4011 strcpy (pDestination
, sCurrencySymbol
);
4012 strcat (pDestination
, pNumberFormated
);
4013 strcat (pDestination
, "-");
4015 case 4: /* format: (1.1$) */
4016 strcpy (pDestination
, "(");
4017 strcat (pDestination
, pNumberFormated
);
4018 strcat (pDestination
, sCurrencySymbol
);
4019 strcat (pDestination
, ")");
4021 case 5: /* format: -1.1$ */
4022 strcpy (pDestination
, "-");
4023 strcat (pDestination
, pNumberFormated
);
4024 strcat (pDestination
, sCurrencySymbol
);
4026 case 6: /* format: 1.1-$ */
4027 strcpy (pDestination
, pNumberFormated
);
4028 strcat (pDestination
, "-");
4029 strcat (pDestination
, sCurrencySymbol
);
4031 case 7: /* format: 1.1$- */
4032 strcpy (pDestination
, pNumberFormated
);
4033 strcat (pDestination
, sCurrencySymbol
);
4034 strcat (pDestination
, "-");
4036 case 8: /* format: -1.1 $ */
4037 strcpy (pDestination
, "-");
4038 strcat (pDestination
, pNumberFormated
);
4039 strcat (pDestination
, " ");
4040 strcat (pDestination
, sCurrencySymbol
);
4042 case 9: /* format: -$ 1.1 */
4043 strcpy (pDestination
, "-");
4044 strcat (pDestination
, sCurrencySymbol
);
4045 strcat (pDestination
, " ");
4046 strcat (pDestination
, pNumberFormated
);
4048 case 10: /* format: 1.1 $- */
4049 strcpy (pDestination
, pNumberFormated
);
4050 strcat (pDestination
, " ");
4051 strcat (pDestination
, sCurrencySymbol
);
4052 strcat (pDestination
, "-");
4054 case 11: /* format: $ 1.1- */
4055 strcpy (pDestination
, sCurrencySymbol
);
4056 strcat (pDestination
, " ");
4057 strcat (pDestination
, pNumberFormated
);
4058 strcat (pDestination
, "-");
4060 case 12: /* format: $ -1.1 */
4061 strcpy (pDestination
, sCurrencySymbol
);
4062 strcat (pDestination
, " ");
4063 strcat (pDestination
, "-");
4064 strcat (pDestination
, pNumberFormated
);
4066 case 13: /* format: 1.1- $ */
4067 strcpy (pDestination
, pNumberFormated
);
4068 strcat (pDestination
, "-");
4069 strcat (pDestination
, " ");
4070 strcat (pDestination
, sCurrencySymbol
);
4072 case 14: /* format: ($ 1.1) */
4073 strcpy (pDestination
, "(");
4074 strcat (pDestination
, sCurrencySymbol
);
4075 strcat (pDestination
, " ");
4076 strcat (pDestination
, pNumberFormated
);
4077 strcat (pDestination
, ")");
4079 case 15: /* format: (1.1 $) */
4080 strcpy (pDestination
, "(");
4081 strcat (pDestination
, pNumberFormated
);
4082 strcat (pDestination
, " ");
4083 strcat (pDestination
, sCurrencySymbol
);
4084 strcat (pDestination
, ")");
4087 SetLastError(ERROR_INVALID_PARAMETER
);
4092 if (cchCurrency
== 0)
4093 return strlen(pDestination
) + 1;
4097 strncpy (lpCurrencyStr
, pDestination
, cchCurrency
-1);
4098 *(lpCurrencyStr
+cchCurrency
-1) = '\0'; /* ensure we got a NULL at the end */
4099 return strlen(lpCurrencyStr
);
4103 /**************************************************************************
4104 * GetCurrencyFormatW (KERNEL32.303)
4106 INT WINAPI
GetCurrencyFormatW(LCID locale
, DWORD dwflags
,
4107 LPCWSTR lpvalue
, const CURRENCYFMTW
* lpFormat
,
4108 LPWSTR lpCurrencyStr
, int cchCurrency
)
4110 FIXME("This API function is NOT implemented !\n");
4114 /******************************************************************************
4115 * OLE2NLS_CheckLocale [intern]
4117 static LCID
OLE2NLS_CheckLocale (LCID locale
)
4120 { locale
= LOCALE_SYSTEM_DEFAULT
;
4123 if (locale
== LOCALE_SYSTEM_DEFAULT
)
4124 { return GetSystemDefaultLCID();
4126 else if (locale
== LOCALE_USER_DEFAULT
)
4127 { return GetUserDefaultLCID();
4133 /******************************************************************************
4134 * GetTimeFormatA [KERNEL32.422]
4135 * Makes an ASCII string of the time
4137 * Formats date according to format, or locale default if format is
4138 * NULL. The format consists of literal characters and fields as follows:
4140 * h hours with no leading zero (12-hour)
4141 * hh hours with full two digits
4142 * H hours with no leading zero (24-hour)
4143 * HH hours with full two digits
4144 * m minutes with no leading zero
4145 * mm minutes with full two digits
4146 * s seconds with no leading zero
4147 * ss seconds with full two digits
4148 * t time marker (A or P)
4149 * tt time marker (AM, PM)
4153 GetTimeFormatA(LCID locale
, /* in */
4154 DWORD flags
, /* in */
4155 LPSYSTEMTIME xtime
, /* in */
4156 LPCSTR format
, /* in */
4157 LPSTR timestr
, /* out */
4158 INT timelen
/* in */)
4159 { char format_buf
[40];
4162 LPSYSTEMTIME thistime
;
4164 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4167 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,xtime
,format
,timestr
,timelen
);
4169 thislocale
= OLE2NLS_CheckLocale ( locale
);
4171 if ( flags
& (TIME_NOTIMEMARKER
| TIME_FORCE24HOURFORMAT
))
4172 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4175 flags
&= (TIME_NOSECONDS
| TIME_NOMINUTESORSECONDS
); /* mask for OLE_GetFormatA*/
4178 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4179 { thislocale
= GetSystemDefaultLCID();
4181 GetLocaleInfoA(thislocale
, thisflags
, format_buf
, sizeof(format_buf
));
4182 thisformat
= format_buf
;
4185 { thisformat
= format
;
4188 if (xtime
== NULL
) /* NULL means use the current local time*/
4194 /* Check that hour,min and sec is in range */
4196 ret
= OLE_GetFormatA(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4202 /******************************************************************************
4203 * GetTimeFormatW [KERNEL32.423]
4204 * Makes a Unicode string of the time
4207 GetTimeFormatW(LCID locale
, /* in */
4208 DWORD flags
, /* in */
4209 LPSYSTEMTIME xtime
, /* in */
4210 LPCWSTR format
, /* in */
4211 LPWSTR timestr
, /* out */
4212 INT timelen
/* in */)
4213 { WCHAR format_buf
[40];
4216 LPSYSTEMTIME thistime
;
4218 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4221 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,
4222 xtime
,debugstr_w(format
),timestr
,timelen
);
4224 thislocale
= OLE2NLS_CheckLocale ( locale
);
4226 if ( flags
& (TIME_NOTIMEMARKER
| TIME_FORCE24HOURFORMAT
))
4227 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4230 flags
&= (TIME_NOSECONDS
| TIME_NOMINUTESORSECONDS
); /* mask for OLE_GetFormatA*/
4233 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4234 { thislocale
= GetSystemDefaultLCID();
4236 GetLocaleInfoW(thislocale
, thisflags
, format_buf
, 40);
4237 thisformat
= format_buf
;
4240 { thisformat
= format
;
4243 if (xtime
== NULL
) /* NULL means use the current local time*/
4251 ret
= OLE_GetFormatW(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4256 /******************************************************************************
4257 * EnumCalendarInfoA [KERNEL32.196]
4259 BOOL WINAPI
EnumCalendarInfoA(
4260 CALINFO_ENUMPROCA calinfoproc
,LCID locale
,CALID calendar
,CALTYPE caltype
4262 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc
,locale
,calendar
,caltype
);