2 * National Language Support library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
19 #include "wine/unicode.h"
26 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(string
);
30 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
31 * MUST contain all #defines from winnls.h
32 * last entry has NULL name, 0 id.
34 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
35 static const struct tagLOCALE_NAME2ID
{
39 LOCALE_ENTRY(ILANGUAGE
),
40 LOCALE_ENTRY(SLANGUAGE
),
41 LOCALE_ENTRY(SENGLANGUAGE
),
42 LOCALE_ENTRY(SABBREVLANGNAME
),
43 LOCALE_ENTRY(SNATIVELANGNAME
),
44 LOCALE_ENTRY(ICOUNTRY
),
45 LOCALE_ENTRY(SCOUNTRY
),
46 LOCALE_ENTRY(SENGCOUNTRY
),
47 LOCALE_ENTRY(SABBREVCTRYNAME
),
48 LOCALE_ENTRY(SNATIVECTRYNAME
),
49 LOCALE_ENTRY(IDEFAULTLANGUAGE
),
50 LOCALE_ENTRY(IDEFAULTCOUNTRY
),
51 LOCALE_ENTRY(IDEFAULTCODEPAGE
),
52 LOCALE_ENTRY(IDEFAULTANSICODEPAGE
),
53 LOCALE_ENTRY(IDEFAULTMACCODEPAGE
),
55 LOCALE_ENTRY(IMEASURE
),
56 LOCALE_ENTRY(SDECIMAL
),
57 LOCALE_ENTRY(STHOUSAND
),
58 LOCALE_ENTRY(SGROUPING
),
59 LOCALE_ENTRY(IDIGITS
),
61 LOCALE_ENTRY(INEGNUMBER
),
62 LOCALE_ENTRY(SNATIVEDIGITS
),
63 LOCALE_ENTRY(SCURRENCY
),
64 LOCALE_ENTRY(SINTLSYMBOL
),
65 LOCALE_ENTRY(SMONDECIMALSEP
),
66 LOCALE_ENTRY(SMONTHOUSANDSEP
),
67 LOCALE_ENTRY(SMONGROUPING
),
68 LOCALE_ENTRY(ICURRDIGITS
),
69 LOCALE_ENTRY(IINTLCURRDIGITS
),
70 LOCALE_ENTRY(ICURRENCY
),
71 LOCALE_ENTRY(INEGCURR
),
74 LOCALE_ENTRY(SSHORTDATE
),
75 LOCALE_ENTRY(SLONGDATE
),
76 LOCALE_ENTRY(STIMEFORMAT
),
80 LOCALE_ENTRY(ITIMEMARKPOSN
),
81 LOCALE_ENTRY(ICENTURY
),
82 LOCALE_ENTRY(ITLZERO
),
83 LOCALE_ENTRY(IDAYLZERO
),
84 LOCALE_ENTRY(IMONLZERO
),
87 LOCALE_ENTRY(ICALENDARTYPE
),
88 LOCALE_ENTRY(IOPTIONALCALENDAR
),
89 LOCALE_ENTRY(IFIRSTDAYOFWEEK
),
90 LOCALE_ENTRY(IFIRSTWEEKOFYEAR
),
91 LOCALE_ENTRY(SDAYNAME1
),
92 LOCALE_ENTRY(SDAYNAME2
),
93 LOCALE_ENTRY(SDAYNAME3
),
94 LOCALE_ENTRY(SDAYNAME4
),
95 LOCALE_ENTRY(SDAYNAME5
),
96 LOCALE_ENTRY(SDAYNAME6
),
97 LOCALE_ENTRY(SDAYNAME7
),
98 LOCALE_ENTRY(SABBREVDAYNAME1
),
99 LOCALE_ENTRY(SABBREVDAYNAME2
),
100 LOCALE_ENTRY(SABBREVDAYNAME3
),
101 LOCALE_ENTRY(SABBREVDAYNAME4
),
102 LOCALE_ENTRY(SABBREVDAYNAME5
),
103 LOCALE_ENTRY(SABBREVDAYNAME6
),
104 LOCALE_ENTRY(SABBREVDAYNAME7
),
105 LOCALE_ENTRY(SMONTHNAME1
),
106 LOCALE_ENTRY(SMONTHNAME2
),
107 LOCALE_ENTRY(SMONTHNAME3
),
108 LOCALE_ENTRY(SMONTHNAME4
),
109 LOCALE_ENTRY(SMONTHNAME5
),
110 LOCALE_ENTRY(SMONTHNAME6
),
111 LOCALE_ENTRY(SMONTHNAME7
),
112 LOCALE_ENTRY(SMONTHNAME8
),
113 LOCALE_ENTRY(SMONTHNAME9
),
114 LOCALE_ENTRY(SMONTHNAME10
),
115 LOCALE_ENTRY(SMONTHNAME11
),
116 LOCALE_ENTRY(SMONTHNAME12
),
117 LOCALE_ENTRY(SMONTHNAME13
),
118 LOCALE_ENTRY(SABBREVMONTHNAME1
),
119 LOCALE_ENTRY(SABBREVMONTHNAME2
),
120 LOCALE_ENTRY(SABBREVMONTHNAME3
),
121 LOCALE_ENTRY(SABBREVMONTHNAME4
),
122 LOCALE_ENTRY(SABBREVMONTHNAME5
),
123 LOCALE_ENTRY(SABBREVMONTHNAME6
),
124 LOCALE_ENTRY(SABBREVMONTHNAME7
),
125 LOCALE_ENTRY(SABBREVMONTHNAME8
),
126 LOCALE_ENTRY(SABBREVMONTHNAME9
),
127 LOCALE_ENTRY(SABBREVMONTHNAME10
),
128 LOCALE_ENTRY(SABBREVMONTHNAME11
),
129 LOCALE_ENTRY(SABBREVMONTHNAME12
),
130 LOCALE_ENTRY(SABBREVMONTHNAME13
),
131 LOCALE_ENTRY(SPOSITIVESIGN
),
132 LOCALE_ENTRY(SNEGATIVESIGN
),
133 LOCALE_ENTRY(IPOSSIGNPOSN
),
134 LOCALE_ENTRY(INEGSIGNPOSN
),
135 LOCALE_ENTRY(IPOSSYMPRECEDES
),
136 LOCALE_ENTRY(IPOSSEPBYSPACE
),
137 LOCALE_ENTRY(INEGSYMPRECEDES
),
138 LOCALE_ENTRY(INEGSEPBYSPACE
),
139 LOCALE_ENTRY(FONTSIGNATURE
),
140 LOCALE_ENTRY(SISO639LANGNAME
),
141 LOCALE_ENTRY(SISO3166CTRYNAME
),
145 static char *GetLocaleSubkeyName( DWORD lctype
);
147 /***********************************************************************
148 * GetUserDefaultLCID [KERNEL32.425]
150 LCID WINAPI
GetUserDefaultLCID(void)
152 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT
);
155 /***********************************************************************
156 * GetSystemDefaultLCID [KERNEL32.400]
158 LCID WINAPI
GetSystemDefaultLCID(void)
160 return GetUserDefaultLCID();
163 #define NLS_MAX_LANGUAGES 20
167 LANGID found_lang_id
[NLS_MAX_LANGUAGES
];
168 char found_language
[NLS_MAX_LANGUAGES
][3];
169 char found_country
[NLS_MAX_LANGUAGES
][3];
173 static BOOL CALLBACK
NLS_FindLanguageID_ProcA(HMODULE hModule
, LPCSTR type
,
174 LPCSTR name
, WORD LangID
, LONG lParam
)
176 LANG_FIND_DATA
*l_data
= (LANG_FIND_DATA
*)lParam
;
177 LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
178 char buf_language
[128];
179 char buf_country
[128];
180 char buf_en_language
[128];
182 TRACE("%04X\n", (UINT
)LangID
);
183 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
184 return TRUE
; /* continue search */
189 GetLocaleInfoA(lcid
, LOCALE_SISO639LANGNAME
|LOCALE_NOUSEROVERRIDE
,
190 buf_language
, sizeof(buf_language
));
191 TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language
);
193 GetLocaleInfoA(lcid
, LOCALE_SISO3166CTRYNAME
|LOCALE_NOUSEROVERRIDE
,
194 buf_country
, sizeof(buf_country
));
195 TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country
);
197 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_language
))
199 if(l_data
->country
&& strlen(l_data
->country
) > 0)
201 if(!strcasecmp(l_data
->country
, buf_country
))
203 l_data
->found_lang_id
[0] = LangID
;
205 TRACE("Found lang_id %04X for %s_%s\n", LangID
, l_data
->lang
, l_data
->country
);
206 return FALSE
; /* stop enumeration */
209 else /* l_data->country not specified */
211 if(l_data
->n_found
< NLS_MAX_LANGUAGES
)
213 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
214 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
215 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
217 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
218 return TRUE
; /* continue search */
223 /* Just in case, check LOCALE_SENGLANGUAGE too,
224 * in hope that possible alias name might have that value.
226 buf_en_language
[0] = 0;
227 GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
|LOCALE_NOUSEROVERRIDE
,
228 buf_en_language
, sizeof(buf_en_language
));
229 TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language
);
231 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_en_language
))
233 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
234 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
235 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
237 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
240 return TRUE
; /* continue search */
243 /***********************************************************************
247 * Lang: a string whose two first chars are the iso name of a language.
248 * Country: a string whose two first chars are the iso name of country
249 * Charset: a string defining the chossen charset encoding
250 * Dialect: a string defining a variation of the locale
252 * all those values are from the standardized format of locale
253 * name in unix which is: Lang[_Country][.Charset][@Dialect]
256 * the numeric code of the language used by Windows
258 * FIXME: Charset and Dialect are not handled
260 static LANGID
NLS_GetLanguageID(LPCSTR Lang
, LPCSTR Country
, LPCSTR Charset
, LPCSTR Dialect
)
262 LANG_FIND_DATA l_data
;
263 char lang_string
[256];
267 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
271 memset(&l_data
, 0, sizeof(LANG_FIND_DATA
));
272 strncpy(l_data
.lang
, Lang
, sizeof(l_data
.lang
));
274 if(Country
&& strlen(Country
) > 0)
275 strncpy(l_data
.country
, Country
, sizeof(l_data
.country
));
277 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
278 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
280 strcpy(lang_string
, l_data
.lang
);
281 if(l_data
.country
&& strlen(l_data
.country
) > 0)
283 strcat(lang_string
, "_");
284 strcat(lang_string
, l_data
.country
);
289 if(l_data
.country
&& strlen(l_data
.country
) > 0)
291 MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string
);
292 l_data
.country
[0] = 0;
293 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
294 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
298 /* Re-evaluate lang_string */
299 strcpy(lang_string
, l_data
.lang
);
300 if(l_data
.country
&& strlen(l_data
.country
) > 0)
302 strcat(lang_string
, "_");
303 strcat(lang_string
, l_data
.country
);
308 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string
);
309 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
313 if(l_data
.n_found
== 1)
314 TRACE("For language '%s' lang_id %04X was found\n", lang_string
, l_data
.found_lang_id
[0]);
315 else /* l_data->n_found > 1 */
318 MESSAGE("For language '%s' several language ids were found:\n", lang_string
);
319 for(i
= 0; i
< l_data
.n_found
; i
++)
320 MESSAGE("%s_%s - %04X; ", l_data
.found_language
[i
], l_data
.found_country
[i
], l_data
.found_lang_id
[i
]);
322 MESSAGE("\nInstead of using first in the list, suggest to define\n"
323 "your LANG environment variable like this: LANG=%s_%s\n",
324 l_data
.found_language
[0], l_data
.found_country
[0]);
328 TRACE("Returning %04X\n", l_data
.found_lang_id
[0]);
329 return l_data
.found_lang_id
[0];
332 /***********************************************************************
333 * GetUserDefaultLangID [KERNEL32.426]
335 LANGID WINAPI
GetUserDefaultLangID(void)
337 /* caching result, if defined from environment, which should (?) not change during a WINE session */
338 static LANGID userLCID
= 0;
343 char *lang
,*country
,*charset
,*dialect
,*next
;
345 if (GetEnvironmentVariableA( "LANGUAGE", buf
, sizeof(buf
) )) goto ok
;
346 if (GetEnvironmentVariableA( "LANG", buf
, sizeof(buf
) )) goto ok
;
347 if (GetEnvironmentVariableA( "LC_ALL", buf
, sizeof(buf
) )) goto ok
;
348 if (GetEnvironmentVariableA( "LC_MESSAGES", buf
, sizeof(buf
) )) goto ok
;
349 if (GetEnvironmentVariableA( "LC_CTYPE", buf
, sizeof(buf
) )) goto ok
;
351 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
354 if (!strcmp(buf
,"POSIX") || !strcmp(buf
,"C"))
355 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
360 next
=strchr(lang
,':'); if (next
) *next
++='\0';
361 dialect
=strchr(lang
,'@'); if (dialect
) *dialect
++='\0';
362 charset
=strchr(lang
,'.'); if (charset
) *charset
++='\0';
363 country
=strchr(lang
,'_'); if (country
) *country
++='\0';
365 userLCID
= NLS_GetLanguageID(lang
, country
, charset
, dialect
);
368 } while (lang
&& !userLCID
);
372 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
374 userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
380 /***********************************************************************
381 * GetSystemDefaultLangID [KERNEL32.401]
383 LANGID WINAPI
GetSystemDefaultLangID(void)
385 return GetUserDefaultLangID();
388 /******************************************************************************
389 * ConvertDefaultLocale [KERNEL32.147]
391 LCID WINAPI
ConvertDefaultLocale (LCID lcid
)
393 { case LOCALE_SYSTEM_DEFAULT
:
394 return GetSystemDefaultLCID();
395 case LOCALE_USER_DEFAULT
:
396 return GetUserDefaultLCID();
398 return MAKELCID (LANG_NEUTRAL
, SUBLANG_NEUTRAL
);
400 return MAKELANGID( PRIMARYLANGID(lcid
), SUBLANG_NEUTRAL
);
403 /* Enhanced version of LoadStringW.
404 * It takes LanguageId to find and load language dependant resources.
405 * Resource is copied as is: "binary" strings are not truncated.
406 * Return: length of resource + 1 to distinguish absent resources
407 * from the resources with zero length.
409 static INT
NLS_LoadStringExW(HMODULE hModule
, LANGID lang_id
, UINT res_id
, LPWSTR buffer
, INT buflen
)
417 hrsrc
= FindResourceExW(hModule
, RT_STRINGW
, (LPCWSTR
)((res_id
>> 4) + 1), lang_id
);
420 hmem
= LoadResource(hModule
, hrsrc
);
423 p
= LockResource(hmem
);
424 string_num
= res_id
& 0x000f;
425 for(i
= 0; i
< string_num
; i
++)
428 TRACE("strlen = %d\n", (int)*p
);
430 if (buffer
== NULL
) return *p
;
431 i
= min(buflen
- 1, *p
);
433 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
434 buffer
[i
] = (WCHAR
) 0;
437 buffer
[0] = (WCHAR
) 0;
441 TRACE("\"%s\" loaded!\n", debugstr_w(buffer
));
445 /******************************************************************************
446 * GetLocaleInfoA [KERNEL32.342]
449 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
451 * MS online documentation states that the string returned is NULL terminated
452 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
453 * terminated string".
455 INT WINAPI
GetLocaleInfoA(LCID lcid
,LCTYPE LCType
,LPSTR buf
,INT len
)
457 LPCSTR retString
= NULL
;
461 DWORD dwBufferSize
=128;
464 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid
,LCType
,buf
,len
);
466 if (len
&& (! buf
) ) {
467 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
471 if (lcid
== LOCALE_NEUTRAL
|| lcid
== LANG_SYSTEM_DEFAULT
)
473 lcid
= GetSystemDefaultLCID();
475 else if (lcid
== LANG_USER_DEFAULT
) /*0x800*/
477 lcid
= GetUserDefaultLCID();
480 /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
481 from the registry. Instead, use system default values. */
482 NoUserOverride
= (LCType
& LOCALE_NOUSEROVERRIDE
) != 0;
484 LCType
&= ~(LOCALE_NOUSEROVERRIDE
|LOCALE_USE_CP_ACP
);
486 /* First, check if it's in the registry. */
487 /* All user customized values are stored in the registry by SetLocaleInfo */
488 if ( !NoUserOverride
&& (pacKey
= GetLocaleSubkeyName(LCType
)) )
493 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
495 if ( RegOpenKeyExA( HKEY_CURRENT_USER
, acRealKey
,
496 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
498 if ( RegQueryValueExA( hKey
, NULL
, NULL
, NULL
, (LPBYTE
)acBuffer
,
499 &dwBufferSize
) == ERROR_SUCCESS
)
501 retString
= acBuffer
;
508 /* If not in the registry, get it from the NLS entries. */
513 /* check if language is registered in the kernel32 resources */
514 if((res_size
= NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid
),
515 LCType
, wcBuffer
, sizeof(wcBuffer
)/sizeof(wcBuffer
[0])))) {
516 WideCharToMultiByte(CP_ACP
, 0, wcBuffer
, res_size
, acBuffer
, dwBufferSize
, NULL
, NULL
);
517 retString
= acBuffer
;
522 /* if not found report a most descriptive error */
525 /* If we are through all of this, retLen should not be zero anymore.
526 If it is, the value is not supported */
528 while (locale_name2id
[i
].name
!=NULL
) {
529 if (LCType
== locale_name2id
[i
].id
) {
530 retString
= locale_name2id
[i
].name
;
536 FIXME("Unkown LC type %lX\n", LCType
);
538 FIXME("'%s' is not defined for your language (%04X).\n"
539 "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
540 "and submit patch for inclusion into the next Wine release.\n",
541 retString
, LOWORD(lcid
));
542 SetLastError(ERROR_INVALID_PARAMETER
);
546 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
547 if (LCType
== LOCALE_FONTSIGNATURE
) {
549 len
= (len
< sizeof(FONTSIGNATURE
)) ? len
: sizeof(FONTSIGNATURE
);
550 memcpy(buf
, retString
, len
);
553 return sizeof(FONTSIGNATURE
);
555 /* if len=0 return only the length, don't touch the buffer*/
557 lstrcpynA(buf
,retString
,len
);
558 return strlen(buf
) + 1;
560 return strlen(retString
)+1;
563 /******************************************************************************
564 * GetLocaleInfoW [KERNEL32.343]
567 * MS documentation states that len "specifies the size, in bytes (ANSI version)
568 * or characters (Unicode version), of" wbuf. Thus the number returned is
569 * the same between GetLocaleInfoW and GetLocaleInfoA.
571 INT WINAPI
GetLocaleInfoW(LCID lcid
,LCTYPE LCType
,LPWSTR wbuf
,INT len
)
575 if (len
&& (! wbuf
) )
576 { SetLastError(ERROR_INSUFFICIENT_BUFFER
);
580 abuf
= (LPSTR
)HeapAlloc(GetProcessHeap(),0,len
);
581 wlen
= GetLocaleInfoA(lcid
, LCType
, abuf
, len
);
583 if (wlen
&& len
) /* if len=0 return only the length*/
584 MultiByteToWideChar( CP_ACP
, 0, abuf
, -1, wbuf
, len
);
586 HeapFree(GetProcessHeap(),0,abuf
);
590 /******************************************************************************
592 * GetLocaleSubkeyName [helper function]
594 * - For use with the registry.
595 * - Gets the registry subkey name for a given lctype.
597 static char *GetLocaleSubkeyName( DWORD lctype
)
603 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
604 * the values are stored in the registry, confirmed under Windows,
605 * for the ones that actually assign pacKey. Cases that aren't finished
606 * have not been confirmed, so that must be done before they can be
609 case LOCALE_SDATE
: /* The date separator. */
612 case LOCALE_ICURRDIGITS
:
613 pacKey
= "iCurrDigits";
615 case LOCALE_SDECIMAL
:
618 case LOCALE_ICURRENCY
:
619 pacKey
= "iCurrency";
621 case LOCALE_SGROUPING
:
622 pacKey
= "sGrouping";
630 /* case LOCALE_ICALENDARTYPE: */
631 /* case LOCALE_IFIRSTDAYOFWEEK: */
632 /* case LOCALE_IFIRSTWEEKOFYEAR: */
633 /* case LOCALE_SYEARMONTH : */
634 /* case LOCALE_SPOSITIVESIGN : */
635 /* case LOCALE_IPAPERSIZE: */
637 case LOCALE_SLONGDATE
:
638 pacKey
= "sLongDate";
640 case LOCALE_SMONDECIMALSEP
:
641 pacKey
= "sMonDecimalSep";
643 case LOCALE_SMONGROUPING
:
644 pacKey
= "sMonGrouping";
646 case LOCALE_IMEASURE
:
649 case LOCALE_SMONTHOUSANDSEP
:
650 pacKey
= "sMonThousandSep";
652 case LOCALE_INEGCURR
:
655 case LOCALE_SNEGATIVESIGN
:
656 pacKey
= "sNegativeSign";
658 case LOCALE_INEGNUMBER
:
659 pacKey
= "iNegNumber";
661 case LOCALE_SSHORTDATE
:
662 pacKey
= "sShortDate";
664 case LOCALE_ILDATE
: /* Long Date format ordering specifier. */
673 case LOCALE_ITIME
: /* Time format specifier. */
676 case LOCALE_STHOUSAND
:
677 pacKey
= "sThousand";
679 case LOCALE_S1159
: /* AM */
685 case LOCALE_S2359
: /* PM */
688 case LOCALE_STIMEFORMAT
:
689 pacKey
= "sTimeFormat";
691 case LOCALE_SCURRENCY
:
692 pacKey
= "sCurrency";
695 /* The following are not listed under MSDN as supported,
696 * but seem to be used and also stored in the registry.
702 case LOCALE_SCOUNTRY
:
705 case LOCALE_ICOUNTRY
:
708 case LOCALE_SLANGUAGE
:
709 pacKey
= "sLanguage";
719 /******************************************************************************
720 * SetLocaleInfoA [KERNEL32.656]
722 BOOL WINAPI
SetLocaleInfoA(DWORD lcid
, DWORD lctype
, LPCSTR data
)
728 if ( (pacKey
= GetLocaleSubkeyName(lctype
)) )
730 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
731 if ( RegCreateKeyA( HKEY_CURRENT_USER
, acRealKey
,
732 &hKey
) == ERROR_SUCCESS
)
734 if ( RegSetValueExA( hKey
, NULL
, 0, REG_SZ
,
735 data
, strlen(data
)+1 ) != ERROR_SUCCESS
)
737 ERR("SetLocaleInfoA: %s did not work\n", pacKey
);
744 FIXME("(%ld,%ld,%s): stub\n",lcid
,lctype
,data
);
749 /******************************************************************************
750 * IsValidLocale [KERNEL32.489]
752 BOOL WINAPI
IsValidLocale(LCID lcid
,DWORD flags
)
754 /* check if language is registered in the kernel32 resources */
755 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW
, (LPCWSTR
)LOCALE_ILANGUAGE
, LOWORD(lcid
)))
761 static BOOL CALLBACK
EnumResourceLanguagesProcW(HMODULE hModule
, LPCWSTR type
,
762 LPCWSTR name
, WORD LangID
, LONG lParam
)
766 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
767 sprintf(bufA
, "%08X", (UINT
)LangID
);
768 MultiByteToWideChar(CP_ACP
, 0, bufA
, -1, bufW
, sizeof(bufW
)/sizeof(bufW
[0]));
769 return lpfnLocaleEnum(bufW
);
772 /******************************************************************************
773 * EnumSystemLocalesW [KERNEL32.209]
775 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
,
778 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
780 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW
,
781 (LPCWSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcW
,
782 (LONG
)lpfnLocaleEnum
);
787 static BOOL CALLBACK
EnumResourceLanguagesProcA(HMODULE hModule
, LPCSTR type
,
788 LPCSTR name
, WORD LangID
, LONG lParam
)
791 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
792 sprintf(bufA
, "%08X", (UINT
)LangID
);
793 return lpfnLocaleEnum(bufA
);
796 /******************************************************************************
797 * EnumSystemLocalesA [KERNEL32.208]
799 BOOL WINAPI
EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum
,
802 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
804 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
805 (LPCSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcA
,
806 (LONG
)lpfnLocaleEnum
);
811 static const unsigned char CT_CType2_LUT
[] = {
812 C2_NOTAPPLICABLE
, /* - 0 */
813 C2_NOTAPPLICABLE
, /* - 1 */
814 C2_NOTAPPLICABLE
, /* - 2 */
815 C2_NOTAPPLICABLE
, /* - 3 */
816 C2_NOTAPPLICABLE
, /* - 4 */
817 C2_NOTAPPLICABLE
, /* - 5 */
818 C2_NOTAPPLICABLE
, /* - 6 */
819 C2_NOTAPPLICABLE
, /* - 7 */
820 C2_NOTAPPLICABLE
, /* - 8 */
821 C2_SEGMENTSEPARATOR
, /* - 9 */
822 C2_NOTAPPLICABLE
, /* - 10 */
823 C2_NOTAPPLICABLE
, /* - 11 */
824 C2_NOTAPPLICABLE
, /* - 12 */
825 C2_NOTAPPLICABLE
, /* - 13 */
826 C2_NOTAPPLICABLE
, /* - 14 */
827 C2_NOTAPPLICABLE
, /* - 15 */
828 C2_NOTAPPLICABLE
, /* - 16 */
829 C2_NOTAPPLICABLE
, /* - 17 */
830 C2_NOTAPPLICABLE
, /* - 18 */
831 C2_NOTAPPLICABLE
, /* - 19 */
832 C2_NOTAPPLICABLE
, /* - 20 */
833 C2_NOTAPPLICABLE
, /* - 21 */
834 C2_NOTAPPLICABLE
, /* - 22 */
835 C2_NOTAPPLICABLE
, /* - 23 */
836 C2_NOTAPPLICABLE
, /* - 24 */
837 C2_NOTAPPLICABLE
, /* - 25 */
838 C2_NOTAPPLICABLE
, /* - 26 */
839 C2_NOTAPPLICABLE
, /* - 27 */
840 C2_NOTAPPLICABLE
, /* - 28 */
841 C2_NOTAPPLICABLE
, /* - 29 */
842 C2_NOTAPPLICABLE
, /* - 30 */
843 C2_NOTAPPLICABLE
, /* - 31 */
844 C2_WHITESPACE
, /* - 32 */
845 C2_OTHERNEUTRAL
, /* ! - 33 */
846 C2_OTHERNEUTRAL
, /* " - 34 */ /* " */
847 C2_EUROPETERMINATOR
, /* # - 35 */
848 C2_EUROPETERMINATOR
, /* $ - 36 */
849 C2_EUROPETERMINATOR
, /* % - 37 */
850 C2_LEFTTORIGHT
, /* & - 38 */
851 C2_OTHERNEUTRAL
, /* ' - 39 */
852 C2_OTHERNEUTRAL
, /* ( - 40 */
853 C2_OTHERNEUTRAL
, /* ) - 41 */
854 C2_OTHERNEUTRAL
, /* * - 42 */
855 C2_EUROPETERMINATOR
, /* + - 43 */
856 C2_COMMONSEPARATOR
, /* , - 44 */
857 C2_EUROPETERMINATOR
, /* - - 45 */
858 C2_EUROPESEPARATOR
, /* . - 46 */
859 C2_EUROPESEPARATOR
, /* / - 47 */
860 C2_EUROPENUMBER
, /* 0 - 48 */
861 C2_EUROPENUMBER
, /* 1 - 49 */
862 C2_EUROPENUMBER
, /* 2 - 50 */
863 C2_EUROPENUMBER
, /* 3 - 51 */
864 C2_EUROPENUMBER
, /* 4 - 52 */
865 C2_EUROPENUMBER
, /* 5 - 53 */
866 C2_EUROPENUMBER
, /* 6 - 54 */
867 C2_EUROPENUMBER
, /* 7 - 55 */
868 C2_EUROPENUMBER
, /* 8 - 56 */
869 C2_EUROPENUMBER
, /* 9 - 57 */
870 C2_COMMONSEPARATOR
, /* : - 58 */
871 C2_OTHERNEUTRAL
, /* ; - 59 */
872 C2_OTHERNEUTRAL
, /* < - 60 */
873 C2_OTHERNEUTRAL
, /* = - 61 */
874 C2_OTHERNEUTRAL
, /* > - 62 */
875 C2_OTHERNEUTRAL
, /* ? - 63 */
876 C2_LEFTTORIGHT
, /* @ - 64 */
877 C2_LEFTTORIGHT
, /* A - 65 */
878 C2_LEFTTORIGHT
, /* B - 66 */
879 C2_LEFTTORIGHT
, /* C - 67 */
880 C2_LEFTTORIGHT
, /* D - 68 */
881 C2_LEFTTORIGHT
, /* E - 69 */
882 C2_LEFTTORIGHT
, /* F - 70 */
883 C2_LEFTTORIGHT
, /* G - 71 */
884 C2_LEFTTORIGHT
, /* H - 72 */
885 C2_LEFTTORIGHT
, /* I - 73 */
886 C2_LEFTTORIGHT
, /* J - 74 */
887 C2_LEFTTORIGHT
, /* K - 75 */
888 C2_LEFTTORIGHT
, /* L - 76 */
889 C2_LEFTTORIGHT
, /* M - 77 */
890 C2_LEFTTORIGHT
, /* N - 78 */
891 C2_LEFTTORIGHT
, /* O - 79 */
892 C2_LEFTTORIGHT
, /* P - 80 */
893 C2_LEFTTORIGHT
, /* Q - 81 */
894 C2_LEFTTORIGHT
, /* R - 82 */
895 C2_LEFTTORIGHT
, /* S - 83 */
896 C2_LEFTTORIGHT
, /* T - 84 */
897 C2_LEFTTORIGHT
, /* U - 85 */
898 C2_LEFTTORIGHT
, /* V - 86 */
899 C2_LEFTTORIGHT
, /* W - 87 */
900 C2_LEFTTORIGHT
, /* X - 88 */
901 C2_LEFTTORIGHT
, /* Y - 89 */
902 C2_LEFTTORIGHT
, /* Z - 90 */
903 C2_OTHERNEUTRAL
, /* [ - 91 */
904 C2_OTHERNEUTRAL
, /* \ - 92 */
905 C2_OTHERNEUTRAL
, /* ] - 93 */
906 C2_OTHERNEUTRAL
, /* ^ - 94 */
907 C2_OTHERNEUTRAL
, /* _ - 95 */
908 C2_OTHERNEUTRAL
, /* ` - 96 */
909 C2_LEFTTORIGHT
, /* a - 97 */
910 C2_LEFTTORIGHT
, /* b - 98 */
911 C2_LEFTTORIGHT
, /* c - 99 */
912 C2_LEFTTORIGHT
, /* d - 100 */
913 C2_LEFTTORIGHT
, /* e - 101 */
914 C2_LEFTTORIGHT
, /* f - 102 */
915 C2_LEFTTORIGHT
, /* g - 103 */
916 C2_LEFTTORIGHT
, /* h - 104 */
917 C2_LEFTTORIGHT
, /* i - 105 */
918 C2_LEFTTORIGHT
, /* j - 106 */
919 C2_LEFTTORIGHT
, /* k - 107 */
920 C2_LEFTTORIGHT
, /* l - 108 */
921 C2_LEFTTORIGHT
, /* m - 109 */
922 C2_LEFTTORIGHT
, /* n - 110 */
923 C2_LEFTTORIGHT
, /* o - 111 */
924 C2_LEFTTORIGHT
, /* p - 112 */
925 C2_LEFTTORIGHT
, /* q - 113 */
926 C2_LEFTTORIGHT
, /* r - 114 */
927 C2_LEFTTORIGHT
, /* s - 115 */
928 C2_LEFTTORIGHT
, /* t - 116 */
929 C2_LEFTTORIGHT
, /* u - 117 */
930 C2_LEFTTORIGHT
, /* v - 118 */
931 C2_LEFTTORIGHT
, /* w - 119 */
932 C2_LEFTTORIGHT
, /* x - 120 */
933 C2_LEFTTORIGHT
, /* y - 121 */
934 C2_LEFTTORIGHT
, /* z - 122 */
935 C2_OTHERNEUTRAL
, /* { - 123 */
936 C2_OTHERNEUTRAL
, /* | - 124 */
937 C2_OTHERNEUTRAL
, /* } - 125 */
938 C2_OTHERNEUTRAL
, /* ~ - 126 */
939 C2_NOTAPPLICABLE
, /* \x7f - 127 */
940 C2_NOTAPPLICABLE
, /* € - 128 */
941 C2_NOTAPPLICABLE
, /* � - 129 */
942 C2_OTHERNEUTRAL
, /* ‚ - 130 */
943 C2_LEFTTORIGHT
, /* ƒ - 131 */
944 C2_OTHERNEUTRAL
, /* „ - 132 */
945 C2_OTHERNEUTRAL
, /* … - 133 */
946 C2_OTHERNEUTRAL
, /* † - 134 */
947 C2_OTHERNEUTRAL
, /* ‡ - 135 */
948 C2_LEFTTORIGHT
, /* ˆ - 136 */
949 C2_EUROPETERMINATOR
, /* ‰ - 137 */
950 C2_LEFTTORIGHT
, /* Š - 138 */
951 C2_OTHERNEUTRAL
, /* ‹ - 139 */
952 C2_LEFTTORIGHT
, /* Œ - 140 */
953 C2_NOTAPPLICABLE
, /* � - 141 */
954 C2_NOTAPPLICABLE
, /* Ž - 142 */
955 C2_NOTAPPLICABLE
, /* � - 143 */
956 C2_NOTAPPLICABLE
, /* � - 144 */
957 C2_OTHERNEUTRAL
, /* ‘ - 145 */
958 C2_OTHERNEUTRAL
, /* ’ - 146 */
959 C2_OTHERNEUTRAL
, /* “ - 147 */
960 C2_OTHERNEUTRAL
, /* ” - 148 */
961 C2_OTHERNEUTRAL
, /* • - 149 */
962 C2_OTHERNEUTRAL
, /* – - 150 */
963 C2_OTHERNEUTRAL
, /* — - 151 */
964 C2_LEFTTORIGHT
, /* ˜ - 152 */
965 C2_OTHERNEUTRAL
, /* ™ - 153 */
966 C2_LEFTTORIGHT
, /* š - 154 */
967 C2_OTHERNEUTRAL
, /* › - 155 */
968 C2_LEFTTORIGHT
, /* œ - 156 */
969 C2_NOTAPPLICABLE
, /* � - 157 */
970 C2_NOTAPPLICABLE
, /* ž - 158 */
971 C2_LEFTTORIGHT
, /* Ÿ - 159 */
972 C2_WHITESPACE
, /* - 160 */
973 C2_OTHERNEUTRAL
, /* ¡ - 161 */
974 C2_EUROPETERMINATOR
, /* ¢ - 162 */
975 C2_EUROPETERMINATOR
, /* £ - 163 */
976 C2_EUROPETERMINATOR
, /* ¤ - 164 */
977 C2_EUROPETERMINATOR
, /* ¥ - 165 */
978 C2_OTHERNEUTRAL
, /* ¦ - 166 */
979 C2_OTHERNEUTRAL
, /* § - 167 */
980 C2_OTHERNEUTRAL
, /* ¨ - 168 */
981 C2_OTHERNEUTRAL
, /* © - 169 */
982 C2_OTHERNEUTRAL
, /* ª - 170 */
983 C2_OTHERNEUTRAL
, /* « - 171 */
984 C2_OTHERNEUTRAL
, /* ¬ - 172 */
985 C2_OTHERNEUTRAL
, /* - 173 */
986 C2_OTHERNEUTRAL
, /* ® - 174 */
987 C2_OTHERNEUTRAL
, /* ¯ - 175 */
988 C2_EUROPETERMINATOR
, /* ° - 176 */
989 C2_EUROPETERMINATOR
, /* ± - 177 */
990 C2_EUROPENUMBER
, /* ² - 178 */
991 C2_EUROPENUMBER
, /* ³ - 179 */
992 C2_OTHERNEUTRAL
, /* ´ - 180 */
993 C2_OTHERNEUTRAL
, /* µ - 181 */
994 C2_OTHERNEUTRAL
, /* ¶ - 182 */
995 C2_OTHERNEUTRAL
, /* · - 183 */
996 C2_OTHERNEUTRAL
, /* ¸ - 184 */
997 C2_EUROPENUMBER
, /* ¹ - 185 */
998 C2_OTHERNEUTRAL
, /* º - 186 */
999 C2_OTHERNEUTRAL
, /* » - 187 */
1000 C2_OTHERNEUTRAL
, /* ¼ - 188 */
1001 C2_OTHERNEUTRAL
, /* ½ - 189 */
1002 C2_OTHERNEUTRAL
, /* ¾ - 190 */
1003 C2_OTHERNEUTRAL
, /* ¿ - 191 */
1004 C2_LEFTTORIGHT
, /* À - 192 */
1005 C2_LEFTTORIGHT
, /* Á - 193 */
1006 C2_LEFTTORIGHT
, /* Â - 194 */
1007 C2_LEFTTORIGHT
, /* Ã - 195 */
1008 C2_LEFTTORIGHT
, /* Ä - 196 */
1009 C2_LEFTTORIGHT
, /* Å - 197 */
1010 C2_LEFTTORIGHT
, /* Æ - 198 */
1011 C2_LEFTTORIGHT
, /* Ç - 199 */
1012 C2_LEFTTORIGHT
, /* È - 200 */
1013 C2_LEFTTORIGHT
, /* É - 201 */
1014 C2_LEFTTORIGHT
, /* Ê - 202 */
1015 C2_LEFTTORIGHT
, /* Ë - 203 */
1016 C2_LEFTTORIGHT
, /* Ì - 204 */
1017 C2_LEFTTORIGHT
, /* Í - 205 */
1018 C2_LEFTTORIGHT
, /* Î - 206 */
1019 C2_LEFTTORIGHT
, /* Ï - 207 */
1020 C2_LEFTTORIGHT
, /* Ð - 208 */
1021 C2_LEFTTORIGHT
, /* Ñ - 209 */
1022 C2_LEFTTORIGHT
, /* Ò - 210 */
1023 C2_LEFTTORIGHT
, /* Ó - 211 */
1024 C2_LEFTTORIGHT
, /* Ô - 212 */
1025 C2_LEFTTORIGHT
, /* Õ - 213 */
1026 C2_LEFTTORIGHT
, /* Ö - 214 */
1027 C2_OTHERNEUTRAL
, /* × - 215 */
1028 C2_LEFTTORIGHT
, /* Ø - 216 */
1029 C2_LEFTTORIGHT
, /* Ù - 217 */
1030 C2_LEFTTORIGHT
, /* Ú - 218 */
1031 C2_LEFTTORIGHT
, /* Û - 219 */
1032 C2_LEFTTORIGHT
, /* Ü - 220 */
1033 C2_LEFTTORIGHT
, /* Ý - 221 */
1034 C2_LEFTTORIGHT
, /* Þ - 222 */
1035 C2_LEFTTORIGHT
, /* ß - 223 */
1036 C2_LEFTTORIGHT
, /* à - 224 */
1037 C2_LEFTTORIGHT
, /* á - 225 */
1038 C2_LEFTTORIGHT
, /* â - 226 */
1039 C2_LEFTTORIGHT
, /* ã - 227 */
1040 C2_LEFTTORIGHT
, /* ä - 228 */
1041 C2_LEFTTORIGHT
, /* å - 229 */
1042 C2_LEFTTORIGHT
, /* æ - 230 */
1043 C2_LEFTTORIGHT
, /* ç - 231 */
1044 C2_LEFTTORIGHT
, /* è - 232 */
1045 C2_LEFTTORIGHT
, /* é - 233 */
1046 C2_LEFTTORIGHT
, /* ê - 234 */
1047 C2_LEFTTORIGHT
, /* ë - 235 */
1048 C2_LEFTTORIGHT
, /* ì - 236 */
1049 C2_LEFTTORIGHT
, /* í - 237 */
1050 C2_LEFTTORIGHT
, /* î - 238 */
1051 C2_LEFTTORIGHT
, /* ï - 239 */
1052 C2_LEFTTORIGHT
, /* ð - 240 */
1053 C2_LEFTTORIGHT
, /* ñ - 241 */
1054 C2_LEFTTORIGHT
, /* ò - 242 */
1055 C2_LEFTTORIGHT
, /* ó - 243 */
1056 C2_LEFTTORIGHT
, /* ô - 244 */
1057 C2_LEFTTORIGHT
, /* õ - 245 */
1058 C2_LEFTTORIGHT
, /* ö - 246 */
1059 C2_OTHERNEUTRAL
, /* ÷ - 247 */
1060 C2_LEFTTORIGHT
, /* ø - 248 */
1061 C2_LEFTTORIGHT
, /* ù - 249 */
1062 C2_LEFTTORIGHT
, /* ú - 250 */
1063 C2_LEFTTORIGHT
, /* û - 251 */
1064 C2_LEFTTORIGHT
, /* ü - 252 */
1065 C2_LEFTTORIGHT
, /* ý - 253 */
1066 C2_LEFTTORIGHT
, /* þ - 254 */
1067 C2_LEFTTORIGHT
/* ÿ - 255 */
1070 const WORD OLE2NLS_CT_CType3_LUT
[] = {
1104 0x0048, /* ! - 33 */
1105 0x0448, /* " - 34 */ /* " */
1106 0x0048, /* # - 35 */
1107 0x0448, /* $ - 36 */
1108 0x0048, /* % - 37 */
1109 0x0048, /* & - 38 */
1110 0x0440, /* ' - 39 */
1111 0x0048, /* ( - 40 */
1112 0x0048, /* ) - 41 */
1113 0x0048, /* * - 42 */
1114 0x0048, /* + - 43 */
1115 0x0048, /* , - 44 */
1116 0x0440, /* - - 45 */
1117 0x0048, /* . - 46 */
1118 0x0448, /* / - 47 */
1119 0x0040, /* 0 - 48 */
1120 0x0040, /* 1 - 49 */
1121 0x0040, /* 2 - 50 */
1122 0x0040, /* 3 - 51 */
1123 0x0040, /* 4 - 52 */
1124 0x0040, /* 5 - 53 */
1125 0x0040, /* 6 - 54 */
1126 0x0040, /* 7 - 55 */
1127 0x0040, /* 8 - 56 */
1128 0x0040, /* 9 - 57 */
1129 0x0048, /* : - 58 */
1130 0x0048, /* ; - 59 */
1131 0x0048, /* < - 60 */
1132 0x0448, /* = - 61 */
1133 0x0048, /* > - 62 */
1134 0x0048, /* ? - 63 */
1135 0x0448, /* @ - 64 */
1136 0x8040, /* A - 65 */
1137 0x8040, /* B - 66 */
1138 0x8040, /* C - 67 */
1139 0x8040, /* D - 68 */
1140 0x8040, /* E - 69 */
1141 0x8040, /* F - 70 */
1142 0x8040, /* G - 71 */
1143 0x8040, /* H - 72 */
1144 0x8040, /* I - 73 */
1145 0x8040, /* J - 74 */
1146 0x8040, /* K - 75 */
1147 0x8040, /* L - 76 */
1148 0x8040, /* M - 77 */
1149 0x8040, /* N - 78 */
1150 0x8040, /* O - 79 */
1151 0x8040, /* P - 80 */
1152 0x8040, /* Q - 81 */
1153 0x8040, /* R - 82 */
1154 0x8040, /* S - 83 */
1155 0x8040, /* T - 84 */
1156 0x8040, /* U - 85 */
1157 0x8040, /* V - 86 */
1158 0x8040, /* W - 87 */
1159 0x8040, /* X - 88 */
1160 0x8040, /* Y - 89 */
1161 0x8040, /* Z - 90 */
1162 0x0048, /* [ - 91 */
1163 0x0448, /* \ - 92 */
1164 0x0048, /* ] - 93 */
1165 0x0448, /* ^ - 94 */
1166 0x0448, /* _ - 95 */
1167 0x0448, /* ` - 96 */
1168 0x8040, /* a - 97 */
1169 0x8040, /* b - 98 */
1170 0x8040, /* c - 99 */
1171 0x8040, /* d - 100 */
1172 0x8040, /* e - 101 */
1173 0x8040, /* f - 102 */
1174 0x8040, /* g - 103 */
1175 0x8040, /* h - 104 */
1176 0x8040, /* i - 105 */
1177 0x8040, /* j - 106 */
1178 0x8040, /* k - 107 */
1179 0x8040, /* l - 108 */
1180 0x8040, /* m - 109 */
1181 0x8040, /* n - 110 */
1182 0x8040, /* o - 111 */
1183 0x8040, /* p - 112 */
1184 0x8040, /* q - 113 */
1185 0x8040, /* r - 114 */
1186 0x8040, /* s - 115 */
1187 0x8040, /* t - 116 */
1188 0x8040, /* u - 117 */
1189 0x8040, /* v - 118 */
1190 0x8040, /* w - 119 */
1191 0x8040, /* x - 120 */
1192 0x8040, /* y - 121 */
1193 0x8040, /* z - 122 */
1194 0x0048, /* { - 123 */
1195 0x0048, /* | - 124 */
1196 0x0048, /* } - 125 */
1197 0x0448, /* ~ - 126 */
1198 0x0000, /* \x7f - 127 */
1199 0x0000, /* € - 128 */
1200 0x0000, /* � - 129 */
1201 0x0008, /* ‚ - 130 */
1202 0x8000, /* ƒ - 131 */
1203 0x0008, /* „ - 132 */
1204 0x0008, /* … - 133 */
1205 0x0008, /* † - 134 */
1206 0x0008, /* ‡ - 135 */
1207 0x0001, /* ˆ - 136 */
1208 0x0008, /* ‰ - 137 */
1209 0x8003, /* Š - 138 */
1210 0x0008, /* ‹ - 139 */
1211 0x8000, /* Œ - 140 */
1212 0x0000, /* � - 141 */
1213 0x0000, /* Ž - 142 */
1214 0x0000, /* � - 143 */
1215 0x0000, /* � - 144 */
1216 0x0088, /* ‘ - 145 */
1217 0x0088, /* ’ - 146 */
1218 0x0088, /* “ - 147 */
1219 0x0088, /* ” - 148 */
1220 0x0008, /* • - 149 */
1221 0x0400, /* – - 150 */
1222 0x0400, /* — - 151 */
1223 0x0408, /* ˜ - 152 */
1224 0x0000, /* ™ - 153 */
1225 0x8003, /* š - 154 */
1226 0x0008, /* › - 155 */
1227 0x8000, /* œ - 156 */
1228 0x0000, /* � - 157 */
1229 0x0000, /* ž - 158 */
1230 0x8003, /* Ÿ - 159 */
1232 0x0008, /* ¡ - 161 */
1233 0x0048, /* ¢ - 162 */
1234 0x0048, /* £ - 163 */
1235 0x0008, /* ¤ - 164 */
1236 0x0048, /* ¥ - 165 */
1237 0x0048, /* ¦ - 166 */
1238 0x0008, /* § - 167 */
1239 0x0408, /* ¨ - 168 */
1240 0x0008, /* © - 169 */
1241 0x0400, /* ª - 170 */
1242 0x0008, /* « - 171 */
1243 0x0048, /* ¬ - 172 */
1244 0x0408, /* - 173 */
1245 0x0008, /* ® - 174 */
1246 0x0448, /* ¯ - 175 */
1247 0x0008, /* ° - 176 */
1248 0x0008, /* ± - 177 */
1249 0x0000, /* ² - 178 */
1250 0x0000, /* ³ - 179 */
1251 0x0408, /* ´ - 180 */
1252 0x0008, /* µ - 181 */
1253 0x0008, /* ¶ - 182 */
1254 0x0008, /* · - 183 */
1255 0x0408, /* ¸ - 184 */
1256 0x0000, /* ¹ - 185 */
1257 0x0400, /* º - 186 */
1258 0x0008, /* » - 187 */
1259 0x0000, /* ¼ - 188 */
1260 0x0000, /* ½ - 189 */
1261 0x0000, /* ¾ - 190 */
1262 0x0008, /* ¿ - 191 */
1263 0x8003, /* À - 192 */
1264 0x8003, /* Á - 193 */
1265 0x8003, /* Â - 194 */
1266 0x8003, /* Ã - 195 */
1267 0x8003, /* Ä - 196 */
1268 0x8003, /* Å - 197 */
1269 0x8000, /* Æ - 198 */
1270 0x8003, /* Ç - 199 */
1271 0x8003, /* È - 200 */
1272 0x8003, /* É - 201 */
1273 0x8003, /* Ê - 202 */
1274 0x8003, /* Ë - 203 */
1275 0x8003, /* Ì - 204 */
1276 0x8003, /* Í - 205 */
1277 0x8003, /* Î - 206 */
1278 0x8003, /* Ï - 207 */
1279 0x8000, /* Ð - 208 */
1280 0x8003, /* Ñ - 209 */
1281 0x8003, /* Ò - 210 */
1282 0x8003, /* Ó - 211 */
1283 0x8003, /* Ô - 212 */
1284 0x8003, /* Õ - 213 */
1285 0x8003, /* Ö - 214 */
1286 0x0008, /* × - 215 */
1287 0x8003, /* Ø - 216 */
1288 0x8003, /* Ù - 217 */
1289 0x8003, /* Ú - 218 */
1290 0x8003, /* Û - 219 */
1291 0x8003, /* Ü - 220 */
1292 0x8003, /* Ý - 221 */
1293 0x8000, /* Þ - 222 */
1294 0x8000, /* ß - 223 */
1295 0x8003, /* à - 224 */
1296 0x8003, /* á - 225 */
1297 0x8003, /* â - 226 */
1298 0x8003, /* ã - 227 */
1299 0x8003, /* ä - 228 */
1300 0x8003, /* å - 229 */
1301 0x8000, /* æ - 230 */
1302 0x8003, /* ç - 231 */
1303 0x8003, /* è - 232 */
1304 0x8003, /* é - 233 */
1305 0x8003, /* ê - 234 */
1306 0x8003, /* ë - 235 */
1307 0x8003, /* ì - 236 */
1308 0x8003, /* í - 237 */
1309 0x8003, /* î - 238 */
1310 0x8003, /* ï - 239 */
1311 0x8000, /* ð - 240 */
1312 0x8003, /* ñ - 241 */
1313 0x8003, /* ò - 242 */
1314 0x8003, /* ó - 243 */
1315 0x8003, /* ô - 244 */
1316 0x8003, /* õ - 245 */
1317 0x8003, /* ö - 246 */
1318 0x0008, /* ÷ - 247 */
1319 0x8003, /* ø - 248 */
1320 0x8003, /* ù - 249 */
1321 0x8003, /* ú - 250 */
1322 0x8003, /* û - 251 */
1323 0x8003, /* ü - 252 */
1324 0x8003, /* ý - 253 */
1325 0x8000, /* þ - 254 */
1326 0x8003 /* ÿ - 255 */
1329 /******************************************************************************
1330 * GetStringTypeA [KERNEL32.396]
1332 BOOL WINAPI
GetStringTypeA(LCID locale
,DWORD dwInfoType
,LPCSTR src
,
1333 INT cchSrc
,LPWORD chartype
)
1335 return GetStringTypeExA(locale
,dwInfoType
,src
,cchSrc
,chartype
);
1338 /******************************************************************************
1339 * GetStringTypeExA [KERNEL32.397]
1341 * FIXME: Ignores the locale.
1343 BOOL WINAPI
GetStringTypeExA(LCID locale
,DWORD dwInfoType
,LPCSTR src
,
1344 INT cchSrc
,LPWORD chartype
)
1348 if ((src
==NULL
) || (chartype
==NULL
) || (src
==(LPSTR
)chartype
))
1350 SetLastError(ERROR_INVALID_PARAMETER
);
1355 cchSrc
=strlen(src
)+1;
1357 switch (dwInfoType
) {
1359 for (i
=0;i
<cchSrc
;i
++)
1362 if (isdigit(src
[i
])) chartype
[i
]|=C1_DIGIT
;
1363 if (isalpha(src
[i
])) chartype
[i
]|=C1_ALPHA
;
1364 if (islower(src
[i
])) chartype
[i
]|=C1_LOWER
;
1365 if (isupper(src
[i
])) chartype
[i
]|=C1_UPPER
;
1366 if (isspace(src
[i
])) chartype
[i
]|=C1_SPACE
;
1367 if (ispunct(src
[i
])) chartype
[i
]|=C1_PUNCT
;
1368 if (iscntrl(src
[i
])) chartype
[i
]|=C1_CNTRL
;
1369 /* FIXME: isblank() is a GNU extension */
1370 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1371 if ((src
[i
] == ' ') || (src
[i
] == '\t')) chartype
[i
]|=C1_BLANK
;
1377 for (i
=0;i
<cchSrc
;i
++)
1379 chartype
[i
]=(WORD
)CT_CType2_LUT
[i
];
1384 for (i
=0;i
<cchSrc
;i
++)
1386 chartype
[i
]=OLE2NLS_CT_CType3_LUT
[i
];
1391 ERR("Unknown dwInfoType:%ld\n",dwInfoType
);
1396 /***********************************************************************
1397 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1399 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
1404 return GetLocaleInfoA(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1407 /***********************************************************************
1408 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1410 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
1415 return GetLocaleInfoW(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1419 static const unsigned char LCM_Unicode_LUT
[] = {
1452 7 , 28, /* ! - 33 */
1453 7 , 29, /* " - 34 */ /* " */
1454 7 , 31, /* # - 35 */
1455 7 , 33, /* $ - 36 */
1456 7 , 35, /* % - 37 */
1457 7 , 37, /* & - 38 */
1458 6 , 128, /* ' - 39 */
1459 7 , 39, /* ( - 40 */
1460 7 , 42, /* ) - 41 */
1461 7 , 45, /* * - 42 */
1463 7 , 47, /* , - 44 */
1464 6 , 130, /* - - 45 */
1465 7 , 51, /* . - 46 */
1466 7 , 53, /* / - 47 */
1467 12 , 3, /* 0 - 48 */
1468 12 , 33, /* 1 - 49 */
1469 12 , 51, /* 2 - 50 */
1470 12 , 70, /* 3 - 51 */
1471 12 , 88, /* 4 - 52 */
1472 12 , 106, /* 5 - 53 */
1473 12 , 125, /* 6 - 54 */
1474 12 , 144, /* 7 - 55 */
1475 12 , 162, /* 8 - 56 */
1476 12 , 180, /* 9 - 57 */
1477 7 , 55, /* : - 58 */
1478 7 , 58, /* ; - 59 */
1479 8 , 14, /* < - 60 */
1480 8 , 18, /* = - 61 */
1481 8 , 20, /* > - 62 */
1482 7 , 60, /* ? - 63 */
1483 7 , 62, /* @ - 64 */
1484 14 , 2, /* A - 65 */
1485 14 , 9, /* B - 66 */
1486 14 , 10, /* C - 67 */
1487 14 , 26, /* D - 68 */
1488 14 , 33, /* E - 69 */
1489 14 , 35, /* F - 70 */
1490 14 , 37, /* G - 71 */
1491 14 , 44, /* H - 72 */
1492 14 , 50, /* I - 73 */
1493 14 , 53, /* J - 74 */
1494 14 , 54, /* K - 75 */
1495 14 , 72, /* L - 76 */
1496 14 , 81, /* M - 77 */
1497 14 , 112, /* N - 78 */
1498 14 , 124, /* O - 79 */
1499 14 , 126, /* P - 80 */
1500 14 , 137, /* Q - 81 */
1501 14 , 138, /* R - 82 */
1502 14 , 145, /* S - 83 */
1503 14 , 153, /* T - 84 */
1504 14 , 159, /* U - 85 */
1505 14 , 162, /* V - 86 */
1506 14 , 164, /* W - 87 */
1507 14 , 166, /* X - 88 */
1508 14 , 167, /* Y - 89 */
1509 14 , 169, /* Z - 90 */
1510 7 , 63, /* [ - 91 */
1511 7 , 65, /* \ - 92 */
1512 7 , 66, /* ] - 93 */
1513 7 , 67, /* ^ - 94 */
1514 7 , 68, /* _ - 95 */
1515 7 , 72, /* ` - 96 */
1516 14 , 2, /* a - 97 */
1517 14 , 9, /* b - 98 */
1518 14 , 10, /* c - 99 */
1519 14 , 26, /* d - 100 */
1520 14 , 33, /* e - 101 */
1521 14 , 35, /* f - 102 */
1522 14 , 37, /* g - 103 */
1523 14 , 44, /* h - 104 */
1524 14 , 50, /* i - 105 */
1525 14 , 53, /* j - 106 */
1526 14 , 54, /* k - 107 */
1527 14 , 72, /* l - 108 */
1528 14 , 81, /* m - 109 */
1529 14 , 112, /* n - 110 */
1530 14 , 124, /* o - 111 */
1531 14 , 126, /* p - 112 */
1532 14 , 137, /* q - 113 */
1533 14 , 138, /* r - 114 */
1534 14 , 145, /* s - 115 */
1535 14 , 153, /* t - 116 */
1536 14 , 159, /* u - 117 */
1537 14 , 162, /* v - 118 */
1538 14 , 164, /* w - 119 */
1539 14 , 166, /* x - 120 */
1540 14 , 167, /* y - 121 */
1541 14 , 169, /* z - 122 */
1542 7 , 74, /* { - 123 */
1543 7 , 76, /* | - 124 */
1544 7 , 78, /* } - 125 */
1545 7 , 80, /* ~ - 126 */
1546 6 , 29, /* \x7f - 127 */
1547 6 , 30, /* € - 128 */
1548 6 , 31, /* � - 129 */
1549 7 , 123, /* ‚ - 130 */
1550 14 , 35, /* ƒ - 131 */
1551 7 , 127, /* „ - 132 */
1552 10 , 21, /* … - 133 */
1553 10 , 15, /* † - 134 */
1554 10 , 16, /* ‡ - 135 */
1555 7 , 67, /* ˆ - 136 */
1556 10 , 22, /* ‰ - 137 */
1557 14 , 145, /* Š - 138 */
1558 7 , 136, /* ‹ - 139 */
1559 14 + 16 , 124, /* Œ - 140 */
1560 6 , 43, /* � - 141 */
1561 6 , 44, /* Ž - 142 */
1562 6 , 45, /* � - 143 */
1563 6 , 46, /* � - 144 */
1564 7 , 121, /* ‘ - 145 */
1565 7 , 122, /* ’ - 146 */
1566 7 , 125, /* “ - 147 */
1567 7 , 126, /* ” - 148 */
1568 10 , 17, /* • - 149 */
1569 6 , 137, /* – - 150 */
1570 6 , 139, /* — - 151 */
1571 7 , 93, /* ˜ - 152 */
1572 14 , 156, /* ™ - 153 */
1573 14 , 145, /* š - 154 */
1574 7 , 137, /* › - 155 */
1575 14 + 16 , 124, /* œ - 156 */
1576 6 , 59, /* � - 157 */
1577 6 , 60, /* ž - 158 */
1578 14 , 167, /* Ÿ - 159 */
1580 7 , 81, /* ¡ - 161 */
1581 10 , 2, /* ¢ - 162 */
1582 10 , 3, /* £ - 163 */
1583 10 , 4, /* ¤ - 164 */
1584 10 , 5, /* ¥ - 165 */
1585 7 , 82, /* ¦ - 166 */
1586 10 , 6, /* § - 167 */
1587 7 , 83, /* ¨ - 168 */
1588 10 , 7, /* © - 169 */
1589 14 , 2, /* ª - 170 */
1590 8 , 24, /* « - 171 */
1591 10 , 8, /* ¬ - 172 */
1592 6 , 131, /* - 173 */
1593 10 , 9, /* ® - 174 */
1594 7 , 84, /* ¯ - 175 */
1595 10 , 10, /* ° - 176 */
1596 8 , 23, /* ± - 177 */
1597 12 , 51, /* ² - 178 */
1598 12 , 70, /* ³ - 179 */
1599 7 , 85, /* ´ - 180 */
1600 10 , 11, /* µ - 181 */
1601 10 , 12, /* ¶ - 182 */
1602 10 , 13, /* · - 183 */
1603 7 , 86, /* ¸ - 184 */
1604 12 , 33, /* ¹ - 185 */
1605 14 , 124, /* º - 186 */
1606 8 , 26, /* » - 187 */
1607 12 , 21, /* ¼ - 188 */
1608 12 , 25, /* ½ - 189 */
1609 12 , 29, /* ¾ - 190 */
1610 7 , 87, /* ¿ - 191 */
1611 14 , 2, /* À - 192 */
1612 14 , 2, /* Á - 193 */
1613 14 , 2, /* Â - 194 */
1614 14 , 2, /* Ã - 195 */
1615 14 , 2, /* Ä - 196 */
1616 14 , 2, /* Å - 197 */
1617 14 + 16 , 2, /* Æ - 198 */
1618 14 , 10, /* Ç - 199 */
1619 14 , 33, /* È - 200 */
1620 14 , 33, /* É - 201 */
1621 14 , 33, /* Ê - 202 */
1622 14 , 33, /* Ë - 203 */
1623 14 , 50, /* Ì - 204 */
1624 14 , 50, /* Í - 205 */
1625 14 , 50, /* Î - 206 */
1626 14 , 50, /* Ï - 207 */
1627 14 , 26, /* Ð - 208 */
1628 14 , 112, /* Ñ - 209 */
1629 14 , 124, /* Ò - 210 */
1630 14 , 124, /* Ó - 211 */
1631 14 , 124, /* Ô - 212 */
1632 14 , 124, /* Õ - 213 */
1633 14 , 124, /* Ö - 214 */
1634 8 , 28, /* × - 215 */
1635 14 , 124, /* Ø - 216 */
1636 14 , 159, /* Ù - 217 */
1637 14 , 159, /* Ú - 218 */
1638 14 , 159, /* Û - 219 */
1639 14 , 159, /* Ü - 220 */
1640 14 , 167, /* Ý - 221 */
1641 14 + 32 , 153, /* Þ - 222 */
1642 14 + 48 , 145, /* ß - 223 */
1643 14 , 2, /* à - 224 */
1644 14 , 2, /* á - 225 */
1645 14 , 2, /* â - 226 */
1646 14 , 2, /* ã - 227 */
1647 14 , 2, /* ä - 228 */
1648 14 , 2, /* å - 229 */
1649 14 + 16 , 2, /* æ - 230 */
1650 14 , 10, /* ç - 231 */
1651 14 , 33, /* è - 232 */
1652 14 , 33, /* é - 233 */
1653 14 , 33, /* ê - 234 */
1654 14 , 33, /* ë - 235 */
1655 14 , 50, /* ì - 236 */
1656 14 , 50, /* í - 237 */
1657 14 , 50, /* î - 238 */
1658 14 , 50, /* ï - 239 */
1659 14 , 26, /* ð - 240 */
1660 14 , 112, /* ñ - 241 */
1661 14 , 124, /* ò - 242 */
1662 14 , 124, /* ó - 243 */
1663 14 , 124, /* ô - 244 */
1664 14 , 124, /* õ - 245 */
1665 14 , 124, /* ö - 246 */
1666 8 , 29, /* ÷ - 247 */
1667 14 , 124, /* ø - 248 */
1668 14 , 159, /* ù - 249 */
1669 14 , 159, /* ú - 250 */
1670 14 , 159, /* û - 251 */
1671 14 , 159, /* ü - 252 */
1672 14 , 167, /* ý - 253 */
1673 14 + 32 , 153, /* þ - 254 */
1674 14 , 167 /* ÿ - 255 */ };
1676 static const unsigned char LCM_Unicode_LUT_2
[] = { 33, 44, 145 };
1678 #define LCM_Diacritic_Start 131
1680 static const unsigned char LCM_Diacritic_LUT
[] = {
1808 /******************************************************************************
1809 * OLE2NLS_isPunctuation [INTERNAL]
1811 static int OLE2NLS_isPunctuation(unsigned char c
)
1813 /* "punctuation character" in this context is a character which is
1814 considered "less important" during word sort comparison.
1815 See LCMapString implementation for the precise definition
1816 of "less important". */
1818 return (LCM_Unicode_LUT
[-2+2*c
]==6);
1821 /******************************************************************************
1822 * OLE2NLS_isNonSpacing [INTERNAL]
1824 static int OLE2NLS_isNonSpacing(unsigned char c
)
1826 /* This function is used by LCMapStringA. Characters
1827 for which it returns true are ignored when mapping a
1828 string with NORM_IGNORENONSPACE */
1829 return ((c
==136) || (c
==170) || (c
==186));
1832 /******************************************************************************
1833 * OLE2NLS_isSymbol [INTERNAL]
1835 static int OLE2NLS_isSymbol(unsigned char c
)
1837 /* This function is used by LCMapStringA. Characters
1838 for which it returns true are ignored when mapping a
1839 string with NORM_IGNORESYMBOLS */
1840 return ( (c
!=0) && !IsCharAlphaNumericA(c
) );
1843 /******************************************************************************
1844 * identity [Internal]
1846 static int identity(int c
)
1851 /*************************************************************************
1852 * LCMapStringA [KERNEL32.492]
1854 * Convert a string, or generate a sort key from it.
1856 * If (mapflags & LCMAP_SORTKEY), the function will generate
1857 * a sort key for the source string. Else, it will convert it
1858 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1862 * Success : length of the result string.
1865 * If called with scrlen = -1, the function will compute the length
1866 * of the 0-terminated string strsrc by itself.
1868 * If called with dstlen = 0, returns the buffer length that
1869 * would be required.
1871 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1872 * as if they are equal.
1873 * In the only code page implemented so far, there may not be
1874 * wide characters in strings passed to LCMapStringA,
1875 * so there is nothing to be done for this flag.
1877 INT WINAPI
LCMapStringA(
1878 LCID lcid
, /* [in] locale identifier created with MAKELCID;
1879 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1880 predefined values. */
1881 DWORD mapflags
, /* [in] flags */
1882 LPCSTR srcstr
, /* [in] source buffer */
1883 INT srclen
, /* [in] source length */
1884 LPSTR dststr
, /* [out] destination buffer */
1885 INT dstlen
) /* [in] destination buffer length */
1889 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1890 lcid
,mapflags
,srcstr
,srclen
,dststr
,dstlen
);
1892 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1894 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr
, dststr
);
1895 SetLastError(ERROR_INVALID_PARAMETER
);
1899 srclen
= strlen(srcstr
) + 1 ; /* (include final '\0') */
1901 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1905 NORM_IGNORENONSPACE | \
1907 NORM_IGNOREWIDTH | \
1908 NORM_IGNOREKANATYPE)
1909 /* FIXME: as long as we don't support Kanakana nor Hirigana
1910 * characters, we can support NORM_IGNOREKANATYPE
1912 if (mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
)
1914 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1915 "unimplemented flags: 0x%08lx\n",
1922 mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
1926 if ( !(mapflags
& LCMAP_SORTKEY
) )
1929 int (*f
)(int) = identity
;
1930 int flag_ignorenonspace
= mapflags
& NORM_IGNORENONSPACE
;
1931 int flag_ignoresymbols
= mapflags
& NORM_IGNORESYMBOLS
;
1933 if (flag_ignorenonspace
|| flag_ignoresymbols
)
1935 /* For some values of mapflags, the length of the resulting
1936 string is not known at this point. Windows does map the string
1937 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1941 /* Compute required length */
1942 for (i
=j
=0; i
< srclen
; i
++)
1944 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1945 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1957 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1961 if (mapflags
& LCMAP_UPPERCASE
)
1963 else if (mapflags
& LCMAP_LOWERCASE
)
1965 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1966 for (i
=j
=0; (i
<srclen
) && (j
<dstlen
) ; i
++)
1968 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1969 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1971 dststr
[j
] = (CHAR
) f(srcstr
[i
]);
1978 /* FIXME: This function completely ignores the "lcid" parameter. */
1979 /* else ... (mapflags & LCMAP_SORTKEY) */
1983 int diacritic_len
=0;
1984 int delayed_punctuation_len
=0;
1985 char *case_component
;
1986 char *diacritic_component
;
1987 char *delayed_punctuation_component
;
1989 int flag_stringsort
= mapflags
& SORT_STRINGSORT
;
1991 /* compute how much room we will need */
1992 for (i
=0;i
<srclen
;i
++)
1995 unsigned char source_char
= srcstr
[i
];
1996 if (source_char
!='\0')
1998 if (flag_stringsort
|| !OLE2NLS_isPunctuation(source_char
))
2001 if ( LCM_Unicode_LUT
[-2+2*source_char
] & ~15 )
2002 unicode_len
++; /* double letter */
2006 delayed_punctuation_len
++;
2010 if (isupper(source_char
))
2011 case_len
=unicode_len
;
2013 ofs
= source_char
- LCM_Diacritic_Start
;
2014 if ((ofs
>=0) && (LCM_Diacritic_LUT
[ofs
]!=2))
2015 diacritic_len
=unicode_len
;
2018 if (mapflags
& NORM_IGNORECASE
)
2020 if (mapflags
& NORM_IGNORENONSPACE
)
2023 room
= 2 * unicode_len
/* "unicode" component */
2024 + diacritic_len
/* "diacritic" component */
2025 + case_len
/* "case" component */
2026 + 4 * delayed_punctuation_len
/* punctuation in word sort mode */
2027 + 4 /* four '\1' separators */
2028 + 1 ; /* terminal '\0' */
2031 else if (dstlen
<room
)
2033 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2037 /*FIXME the Pointercheck should not be nessesary */
2038 if (IsBadWritePtr (dststr
,room
))
2039 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr
,dstlen
);
2040 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2044 /* locate each component, write separators */
2045 diacritic_component
= dststr
+ 2*unicode_len
;
2046 *diacritic_component
++ = '\1';
2047 case_component
= diacritic_component
+ diacritic_len
;
2048 *case_component
++ = '\1';
2049 delayed_punctuation_component
= case_component
+ case_len
;
2050 *delayed_punctuation_component
++ = '\1';
2051 *delayed_punctuation_component
++ = '\1';
2053 /* read source string char by char, write
2054 corresponding weight in each component. */
2055 for (i
=0,count
=0;i
<srclen
;i
++)
2057 unsigned char source_char
=srcstr
[i
];
2058 if (source_char
!='\0')
2061 type
= LCM_Unicode_LUT
[-2+2*source_char
];
2062 longcode
= type
>> 4;
2064 if (!flag_stringsort
&& OLE2NLS_isPunctuation(source_char
))
2066 WORD encrypted_location
= (1<<15) + 7 + 4*count
;
2067 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
>>8);
2068 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
&255);
2069 /* big-endian is used here because it lets string comparison be
2070 compatible with numerical comparison */
2072 *delayed_punctuation_component
++ = type
;
2073 *delayed_punctuation_component
++ = LCM_Unicode_LUT
[-1+2*source_char
];
2074 /* assumption : a punctuation character is never a
2075 double or accented letter */
2079 dststr
[2*count
] = type
;
2080 dststr
[2*count
+1] = LCM_Unicode_LUT
[-1+2*source_char
];
2084 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
2085 if (count
<diacritic_len
)
2086 diacritic_component
[count
] = 2; /* assumption: a double letter
2087 is never accented */
2090 dststr
[2*count
] = type
;
2091 dststr
[2*count
+1] = *(LCM_Unicode_LUT_2
- 1 + longcode
);
2092 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
2093 32 in the first column of LCM_Unicode_LUT --> longcode = 2
2094 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
2098 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
2099 if (count
<diacritic_len
)
2101 int ofs
= source_char
- LCM_Diacritic_Start
;
2102 diacritic_component
[count
] = (ofs
>=0 ? LCM_Diacritic_LUT
[ofs
] : 2);
2108 dststr
[room
-1] = '\0';
2113 /*************************************************************************
2114 * LCMapStringW [KERNEL32.493]
2116 * Convert a string, or generate a sort key from it.
2120 * See LCMapStringA for documentation
2122 INT WINAPI
LCMapStringW(
2123 LCID lcid
,DWORD mapflags
,LPCWSTR srcstr
,INT srclen
,LPWSTR dststr
,
2128 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2129 lcid
, mapflags
, srcstr
, srclen
, dststr
, dstlen
);
2131 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
2133 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr
, dststr
);
2134 SetLastError(ERROR_INVALID_PARAMETER
);
2138 srclen
= strlenW(srcstr
)+1;
2140 /* FIXME: Both this function and it's companion LCMapStringA()
2141 * completely ignore the "lcid" parameter. In place of the "lcid"
2142 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2143 * environment variable prior to invoking this function. */
2144 if (mapflags
& LCMAP_SORTKEY
)
2146 /* Possible values of LC_COLLATE. */
2147 char *lc_collate_default
= 0; /* value prior to this function */
2148 char *lc_collate_env
= 0; /* value retrieved from the environment */
2150 /* General purpose index into strings of any type. */
2153 /* Lengths of various strings where the length is measured in
2154 * wide characters for wide character strings and in bytes for
2155 * native strings. The lengths include the NULL terminator. */
2156 size_t returned_len
= 0;
2157 size_t src_native_len
= 0;
2158 size_t dst_native_len
= 0;
2159 size_t dststr_libc_len
= 0;
2161 /* Native (character set determined by locale) versions of the
2162 * strings source and destination strings. */
2163 LPSTR src_native
= 0;
2164 LPSTR dst_native
= 0;
2166 /* Version of the source and destination strings using the
2167 * "wchar_t" Unicode data type needed by various libc functions. */
2168 wchar_t *srcstr_libc
= 0;
2169 wchar_t *dststr_libc
= 0;
2171 if(!(srcstr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2172 srclen
* sizeof(wchar_t))))
2174 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2175 srclen
* sizeof(wchar_t));
2176 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2180 /* Convert source string to a libc Unicode string. */
2181 for(str_idx
= 0; str_idx
< srclen
; str_idx
++)
2183 srcstr_libc
[str_idx
] = srcstr
[str_idx
];
2186 /* src_native should contain at most 3 bytes for each
2187 * multibyte characters in the original srcstr string. */
2188 src_native_len
= 3 * srclen
;
2189 if(!(src_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
2192 ERR("Unable to allocate %d bytes for src_native\n", src_native_len
);
2193 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2194 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2198 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2199 * current value is backed up so it can be restored after the
2200 * last LC_COLLATE sensitive function returns.
2202 * Even though the locale is adjusted for a minimum amount of
2203 * time a race condition exists where other threads may be
2204 * affected if they invoke LC_COLLATE sensitive functions. One
2205 * possible solution is to wrap all LC_COLLATE sensitive Wine
2206 * functions, like LCMapStringW(), in a mutex.
2208 * Another enhancement to the following would be to set the
2209 * LC_COLLATE locale category as a function of the "lcid"
2210 * parameter instead of the "LC_COLLATE" environment variable. */
2211 if(!(lc_collate_default
= setlocale(LC_COLLATE
, NULL
)))
2213 ERR("Unable to query the LC_COLLATE catagory\n");
2214 SetLastError(ERROR_INVALID_PARAMETER
);
2215 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2216 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2220 if(!(lc_collate_env
= setlocale(LC_COLLATE
, "")))
2222 ERR("Unable to inherit the LC_COLLATE locale category from the "
2223 "environment. The \"LC_COLLATE\" environment variable is "
2224 "\"%s\".\n", getenv("LC_COLLATE") ?
2225 getenv("LC_COLLATE") : "<unset>");
2226 SetLastError(ERROR_INVALID_PARAMETER
);
2227 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2228 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2232 TRACE("lc_collate_default = %s\n", lc_collate_default
);
2233 TRACE("lc_collate_env = %s\n", lc_collate_env
);
2235 /* Convert the libc Unicode string to a native multibyte character
2237 returned_len
= wcstombs(src_native
, srcstr_libc
, src_native_len
) + 1;
2238 if(returned_len
== 0)
2240 LPSTR srcstr_ascii
= (LPSTR
)HEAP_strdupWtoA(GetProcessHeap(),
2242 ERR("wcstombs failed. The string specified (%s) may contains an "
2243 "invalid character.\n", srcstr_ascii
);
2244 SetLastError(ERROR_INVALID_PARAMETER
);
2245 if(srcstr_ascii
) HeapFree(GetProcessHeap(), 0, srcstr_ascii
);
2246 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2247 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2248 setlocale(LC_COLLATE
, lc_collate_default
);
2251 else if(returned_len
> src_native_len
)
2253 src_native
[src_native_len
- 1] = 0;
2254 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2255 "than expected (%d bytes).\n", src_native
, returned_len
,
2258 /* Since this is an internal error I'm not sure what the correct
2260 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2262 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2263 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2264 setlocale(LC_COLLATE
, lc_collate_default
);
2267 src_native_len
= returned_len
;
2269 TRACE("src_native = %s src_native_len = %d\n",
2270 src_native
, src_native_len
);
2272 /* dst_native seems to contain at most 4 bytes for each byte in
2273 * the original src_native string. Change if need be since this
2274 * isn't documented by the strxfrm() man page. */
2275 dst_native_len
= 4 * src_native_len
;
2276 if(!(dst_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, dst_native_len
)))
2278 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len
);
2279 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2280 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2281 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2282 setlocale(LC_COLLATE
, lc_collate_default
);
2286 /* The actual translation is done by the following call to
2287 * strxfrm(). The surrounding code could have been simplified
2288 * by calling wcsxfrm() instead except that wcsxfrm() is not
2289 * available on older Linux systems (RedHat 4.1 with
2292 * Also, it is possible that the translation could be done by
2293 * various tables as it is done in LCMapStringA(). However, I'm
2294 * not sure what those tables are. */
2295 returned_len
= strxfrm(dst_native
, src_native
, dst_native_len
) + 1;
2297 if(returned_len
> dst_native_len
)
2299 dst_native
[dst_native_len
- 1] = 0;
2300 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2301 "than expected (%d bytes).\n", dst_native
, returned_len
,
2304 /* Since this is an internal error I'm not sure what the correct
2306 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2308 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2309 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2310 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2311 setlocale(LC_COLLATE
, lc_collate_default
);
2314 dst_native_len
= returned_len
;
2316 TRACE("dst_native = %s dst_native_len = %d\n",
2317 dst_native
, dst_native_len
);
2319 dststr_libc_len
= dst_native_len
;
2320 if(!(dststr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2321 dststr_libc_len
* sizeof(wchar_t))))
2323 ERR("Unable to allocate %d bytes for dststr_libc\n",
2324 dststr_libc_len
* sizeof(wchar_t));
2325 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2326 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2327 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2328 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2329 setlocale(LC_COLLATE
, lc_collate_default
);
2333 /* Convert the native multibyte string to a libc Unicode string. */
2334 returned_len
= mbstowcs(dststr_libc
, dst_native
, dst_native_len
) + 1;
2336 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2337 * function has returned. */
2338 setlocale(LC_COLLATE
, lc_collate_default
);
2340 if(returned_len
== 0)
2342 ERR("mbstowcs failed. The native version of the translated string "
2343 "(%s) may contain an invalid character.\n", dst_native
);
2344 SetLastError(ERROR_INVALID_PARAMETER
);
2345 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2346 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2347 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2348 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2353 if(returned_len
> dstlen
)
2355 ERR("mbstowcs returned a string that was longer (%d chars) "
2356 "than the buffer provided (%d chars).\n", returned_len
,
2358 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2359 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2360 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2361 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2362 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2365 dstlen
= returned_len
;
2367 /* Convert a libc Unicode string to the destination string. */
2368 for(str_idx
= 0; str_idx
< dstlen
; str_idx
++)
2370 dststr
[str_idx
] = dststr_libc
[str_idx
];
2372 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2373 *(((int *)dststr
) + 0),
2374 *(((int *)dststr
) + 1),
2375 *(((int *)dststr
) + 2),
2376 *(((int *)dststr
) + 3));
2380 dstlen
= returned_len
;
2382 TRACE("dstlen (return) = %d\n", dstlen
);
2383 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2384 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2385 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2386 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2391 int (*f
)(int)=identity
;
2397 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2401 if (mapflags
& LCMAP_UPPERCASE
)
2403 else if (mapflags
& LCMAP_LOWERCASE
)
2405 for (i
=0; i
< srclen
; i
++)
2406 dststr
[i
] = (WCHAR
) f(srcstr
[i
]);
2412 /***********************************************************************
2413 * OLE2NLS_EstimateMappingLength
2415 * Estimates the number of characters required to hold the string
2416 * computed by LCMapStringA.
2418 * The size is always over-estimated, with a fixed limit on the
2419 * amount of estimation error.
2421 * Note that len == -1 is not permitted.
2423 static inline int OLE2NLS_EstimateMappingLength(LCID lcid
, DWORD dwMapFlags
,
2424 LPCSTR str
, DWORD len
)
2426 /* Estimate only for small strings to keep the estimation error from
2427 * becoming too large. */
2428 if (len
< 128) return len
* 8 + 5;
2429 else return LCMapStringA(lcid
, dwMapFlags
, str
, len
, NULL
, 0);
2432 /******************************************************************************
2433 * CompareStringA [KERNEL32.143]
2434 * Compares two strings using locale
2438 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2443 * Defaults to a word sort, but uses a string sort if
2444 * SORT_STRINGSORT is set.
2445 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2449 * This implementation ignores the locale
2453 * Quite inefficient.
2455 UINT WINAPI
CompareStringA(
2456 DWORD lcid
, /* [in] locale ID */
2457 DWORD fdwStyle
, /* [in] comparison-style options */
2458 LPCSTR s1
, /* [in] first string */
2459 DWORD l1
, /* [in] length of first string */
2460 LPCSTR s2
, /* [in] second string */
2461 DWORD l2
) /* [in] length of second string */
2463 int mapstring_flags
;
2467 TRACE("%s and %s\n",
2468 debugstr_a (s1
), debugstr_a (s2
));
2470 if ( (s1
==NULL
) || (s2
==NULL
) )
2472 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1
, s2
);
2473 SetLastError(ERROR_INVALID_PARAMETER
);
2477 if(fdwStyle
& NORM_IGNORESYMBOLS
)
2478 FIXME("IGNORESYMBOLS not supported\n");
2480 if (l1
== -1) l1
= strlen(s1
);
2481 if (l2
== -1) l2
= strlen(s2
);
2483 mapstring_flags
= LCMAP_SORTKEY
| fdwStyle
;
2484 len1
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s1
, l1
);
2485 len2
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s2
, l2
);
2487 if ((len1
==0)||(len2
==0))
2488 return 0; /* something wrong happened */
2490 sk1
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, len1
+ len2
);
2492 if ( (!LCMapStringA(lcid
,mapstring_flags
,s1
,l1
,sk1
,len1
))
2493 || (!LCMapStringA(lcid
,mapstring_flags
,s2
,l2
,sk2
,len2
)) )
2495 ERR("Bug in LCmapStringA.\n");
2500 /* strcmp doesn't necessarily return -1, 0, or 1 */
2501 result
= strcmp(sk1
,sk2
);
2503 HeapFree(GetProcessHeap(),0,sk1
);
2510 /* must be greater, if we reach this point */
2514 /******************************************************************************
2515 * CompareStringW [KERNEL32.144]
2516 * This implementation ignores the locale
2517 * FIXME : Does only string sort. Should
2518 * be reimplemented the same way as CompareStringA.
2520 UINT WINAPI
CompareStringW(DWORD lcid
, DWORD fdwStyle
,
2521 LPCWSTR s1
, DWORD l1
, LPCWSTR s2
,DWORD l2
)
2524 if(fdwStyle
& NORM_IGNORENONSPACE
)
2525 FIXME("IGNORENONSPACE not supprted\n");
2526 if(fdwStyle
& NORM_IGNORESYMBOLS
)
2527 FIXME("IGNORESYMBOLS not supported\n");
2529 /* Is strcmp defaulting to string sort or to word sort?? */
2530 /* FIXME: Handle NORM_STRINGSORT */
2531 l1
= (l1
==-1)?strlenW(s1
):l1
;
2532 l2
= (l2
==-1)?strlenW(s2
):l2
;
2533 len
= l1
<l2
? l1
:l2
;
2534 ret
= (fdwStyle
& NORM_IGNORECASE
) ? strncmpiW(s1
,s2
,len
) : strncmpW(s1
,s2
,len
);
2535 /* not equal, return 1 or 3 */
2537 /* need to translate result */
2538 return ((int)ret
< 0) ? 1 : 3;
2540 /* same len, return 2 */
2541 if(l1
==l2
) return 2;
2542 /* the longer one is lexically greater */
2543 return (l1
<l2
)? 1 : 3;
2546 /******************************************************************************
2547 * OLE_GetFormatA [Internal]
2550 * If datelen == 0, it should return the reguired string length.
2552 This function implements stuff for GetDateFormat() and
2555 d single-digit (no leading zero) day (of month)
2556 dd two-digit day (of month)
2557 ddd short day-of-week name
2558 dddd long day-of-week name
2559 M single-digit month
2561 MMM short month name
2562 MMMM full month name
2563 y two-digit year, no leading 0
2565 yyyy four-digit year
2567 h hours with no leading zero (12-hour)
2568 hh hours with full two digits
2569 H hours with no leading zero (24-hour)
2570 HH hours with full two digits
2571 m minutes with no leading zero
2572 mm minutes with full two digits
2573 s seconds with no leading zero
2574 ss seconds with full two digits
2575 t time marker (A or P)
2576 tt time marker (AM, PM)
2577 '' used to quote literal characters
2578 '' (within a quoted string) indicates a literal '
2580 These functions REQUIRE valid locale, date, and format.
2582 static INT
OLE_GetFormatA(LCID locale
,
2586 LPCSTR _format
, /*in*/
2591 int count
, type
, inquote
, Overflow
;
2597 const char * _dgfmt
[] = { "%d", "%02d" };
2598 const char ** dgfmt
= _dgfmt
- 1;
2600 /* report, for debugging */
2601 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",
2602 locale
, flags
, tflags
,
2603 xtime
->wYear
,xtime
->wMonth
,xtime
->wDayOfWeek
,xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2604 _format
, _format
, date
, datelen
);
2607 FIXME("datelen = 0, returning 255\n");
2611 /* initalize state variables and output buffer */
2613 count
= 0; inquote
= 0; Overflow
= 0;
2615 date
[0] = buf
[0] = '\0';
2617 strcpy(format
,_format
);
2619 /* alter the formatstring, while it works for all languages now in wine
2620 its possible that it fails when the time looks like ss:mm:hh as example*/
2621 if (tflags
& (TIME_NOMINUTESORSECONDS
))
2622 { if ((pos
= strstr ( format
, ":mm")))
2623 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2626 if (tflags
& (TIME_NOSECONDS
))
2627 { if ((pos
= strstr ( format
, ":ss")))
2628 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2632 for (inpos
= 0;; inpos
++) {
2633 /* 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]); */
2635 if (format
[inpos
] == '\'') {
2636 if (format
[inpos
+1] == '\'') {
2638 date
[outpos
++] = '\'';
2641 continue; /* we did nothing to the output */
2643 } else if (format
[inpos
] == '\0') {
2644 date
[outpos
++] = '\0';
2645 if (outpos
> datelen
) Overflow
= 1;
2648 date
[outpos
++] = format
[inpos
];
2649 if (outpos
> datelen
) {
2651 date
[outpos
-1] = '\0'; /* this is the last place where
2652 it's safe to write */
2656 } else if ( (count
&& (format
[inpos
] != type
))
2658 || (count
== 2 && strchr("ghHmst", type
)) )
2662 GetLocaleInfoA(locale
,
2664 + (xtime
->wDayOfWeek
+6)%7,
2666 } else if (count
== 3) {
2667 GetLocaleInfoA(locale
,
2668 LOCALE_SABBREVDAYNAME1
2669 + (xtime
->wDayOfWeek
+6)%7,
2672 sprintf(buf
, dgfmt
[count
], xtime
->wDay
);
2674 } else if (type
== 'M') {
2676 GetLocaleInfoA(locale
,
2677 LOCALE_SABBREVMONTHNAME1
2678 + xtime
->wMonth
- 1,
2680 } else if (count
== 4) {
2681 GetLocaleInfoA(locale
,
2683 + xtime
->wMonth
- 1,
2686 sprintf(buf
, dgfmt
[count
], xtime
->wMonth
);
2688 } else if (type
== 'y') {
2690 sprintf(buf
, "%d", xtime
->wYear
);
2691 } else if (count
== 3) {
2693 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2695 sprintf(buf
, dgfmt
[count
], xtime
->wYear
% 100);
2697 } else if (type
== 'g') {
2699 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2703 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2705 } else if (type
== 'h') {
2706 /* gives us hours 1:00 -- 12:00 */
2707 sprintf(buf
, dgfmt
[count
], (xtime
->wHour
-1)%12 +1);
2708 } else if (type
== 'H') {
2710 sprintf(buf
, dgfmt
[count
], xtime
->wHour
);
2711 } else if ( type
== 'm') {
2712 sprintf(buf
, dgfmt
[count
], xtime
->wMinute
);
2713 } else if ( type
== 's') {
2714 sprintf(buf
, dgfmt
[count
], xtime
->wSecond
);
2715 } else if (type
== 't') {
2717 sprintf(buf
, "%c", (xtime
->wHour
< 12) ? 'A' : 'P');
2718 } else if (count
== 2) {
2719 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2720 GetLocaleInfoA(locale
,
2722 ? LOCALE_S1159
: LOCALE_S2359
,
2727 /* we need to check the next char in the format string
2728 again, no matter what happened */
2731 /* add the contents of buf to the output */
2732 buflen
= strlen(buf
);
2733 if (outpos
+ buflen
< datelen
) {
2734 date
[outpos
] = '\0'; /* for strcat to hook onto */
2738 date
[outpos
] = '\0';
2739 strncat(date
, buf
, datelen
- outpos
);
2740 date
[datelen
- 1] = '\0';
2741 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2742 WARN("insufficient buffer\n");
2746 /* reset the variables we used to keep track of this item */
2749 } else if (format
[inpos
] == '\0') {
2750 /* we can't check for this at the loop-head, because
2751 that breaks the printing of the last format-item */
2752 date
[outpos
] = '\0';
2755 /* continuing a code for an item */
2758 } else if (strchr("hHmstyMdg", format
[inpos
])) {
2759 type
= format
[inpos
];
2762 } else if (format
[inpos
] == '\'') {
2766 date
[outpos
++] = format
[inpos
];
2768 /* now deal with a possible buffer overflow */
2769 if (outpos
>= datelen
) {
2770 date
[datelen
- 1] = '\0';
2771 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2777 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2780 /* finish it off with a string terminator */
2783 if (outpos
> datelen
-1) outpos
= datelen
-1;
2784 date
[outpos
] = '\0';
2786 TRACE("OLE_GetFormatA returns string '%s', len %d\n",
2791 /******************************************************************************
2792 * OLE_GetFormatW [INTERNAL]
2794 static INT
OLE_GetFormatW(LCID locale
, DWORD flags
, DWORD tflags
,
2797 LPWSTR output
, INT outlen
)
2800 int count
, type
=0, inquote
;
2801 int Overflow
; /* loop check */
2805 WCHAR arg0
[] = {0}, arg1
[] = {'%','d',0};
2806 WCHAR arg2
[] = {'%','0','2','d',0};
2808 int datevars
=0, timevars
=0;
2814 /* make a debug report */
2815 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2816 "%p with max len %d\n",
2817 locale
, flags
, tflags
,
2818 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2819 debugstr_w(format
), format
, output
, outlen
);
2822 FIXME("outlen = 0, returning 255\n");
2826 /* initialize state variables */
2829 inquote
= Overflow
= 0;
2830 /* this is really just a sanity check */
2831 output
[0] = buf
[0] = 0;
2833 /* this loop is the core of the function */
2834 for (inpos
= 0; /* we have several break points */ ; inpos
++) {
2836 if (format
[inpos
] == (WCHAR
) '\'') {
2837 if (format
[inpos
+1] == '\'') {
2839 output
[outpos
++] = '\'';
2844 } else if (format
[inpos
] == 0) {
2845 output
[outpos
++] = 0;
2846 if (outpos
> outlen
) Overflow
= 1;
2847 break; /* normal exit (within a quote) */
2849 output
[outpos
++] = format
[inpos
]; /* copy input */
2850 if (outpos
> outlen
) {
2852 output
[outpos
-1] = 0;
2856 } else if ( (count
&& (format
[inpos
] != type
))
2857 || ( (count
==4 && type
=='y') ||
2858 (count
==4 && type
=='M') ||
2859 (count
==4 && type
=='d') ||
2860 (count
==2 && type
=='g') ||
2861 (count
==2 && type
=='h') ||
2862 (count
==2 && type
=='H') ||
2863 (count
==2 && type
=='m') ||
2864 (count
==2 && type
=='s') ||
2865 (count
==2 && type
=='t') ) ) {
2870 GetLocaleInfoW(locale
,
2871 LOCALE_SDAYNAME1
+ (xtime
->wDayOfWeek
+6)%7,
2872 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2873 } else if (count
== 3) {
2874 GetLocaleInfoW(locale
,
2875 LOCALE_SABBREVDAYNAME1
+
2876 (xtime
->wDayOfWeek
+6)%7,
2877 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2879 sprintf( tmp
, "%.*d", count
, xtime
->wDay
);
2880 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2886 GetLocaleInfoW(locale
, LOCALE_SMONTHNAME1
+
2887 xtime
->wMonth
-1, buf
,
2888 sizeof(buf
)/sizeof(WCHAR
) );
2889 } else if (count
== 3) {
2890 GetLocaleInfoW(locale
, LOCALE_SABBREVMONTHNAME1
+
2891 xtime
->wMonth
-1, buf
,
2892 sizeof(buf
)/sizeof(WCHAR
) );
2894 sprintf( tmp
, "%.*d", count
, xtime
->wMonth
);
2895 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2900 sprintf( tmp
, "%d", xtime
->wYear
);
2901 } else if (count
== 3) {
2902 strcpy( tmp
, "yyy" );
2904 sprintf( tmp
, "%.*d", count
, xtime
->wYear
% 100 );
2906 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2911 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2912 strcpy( tmp
, "AD" );
2914 /* Win API sez we copy it verbatim */
2917 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2921 /* hours 1:00-12:00 --- is this right? */
2922 sprintf( tmp
, "%.*d", count
, (xtime
->wHour
-1)%12 +1);
2923 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2927 sprintf( tmp
, "%.*d", count
, xtime
->wHour
);
2928 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2932 sprintf( tmp
, "%.*d", count
, xtime
->wMinute
);
2933 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2937 sprintf( tmp
, "%.*d", count
, xtime
->wSecond
);
2938 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2942 GetLocaleInfoW(locale
, (xtime
->wHour
< 12) ?
2943 LOCALE_S1159
: LOCALE_S2359
,
2951 /* no matter what happened, we need to check this next
2952 character the next time we loop through */
2955 /* cat buf onto the output */
2956 outlen
= strlenW(buf
);
2957 if (outpos
+ buflen
< outlen
) {
2958 strcpyW( output
+ outpos
, buf
);
2961 lstrcpynW( output
+ outpos
, buf
, outlen
- outpos
);
2963 break; /* Abnormal exit */
2966 /* reset the variables we used this time */
2969 } else if (format
[inpos
] == 0) {
2970 /* we can't check for this at the beginning, because that
2971 would keep us from printing a format spec that ended the
2974 break; /* NORMAL EXIT */
2976 /* how we keep track of the middle of a format spec */
2979 } else if ( (datevars
&& (format
[inpos
]=='d' ||
2980 format
[inpos
]=='M' ||
2981 format
[inpos
]=='y' ||
2982 format
[inpos
]=='g') ) ||
2983 (timevars
&& (format
[inpos
]=='H' ||
2984 format
[inpos
]=='h' ||
2985 format
[inpos
]=='m' ||
2986 format
[inpos
]=='s' ||
2987 format
[inpos
]=='t') ) ) {
2988 type
= format
[inpos
];
2991 } else if (format
[inpos
] == '\'') {
2995 /* unquoted literals */
2996 output
[outpos
++] = format
[inpos
];
3001 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3002 WARN(" buffer overflow\n");
3005 /* final string terminator and sanity check */
3007 if (outpos
> outlen
-1) outpos
= outlen
-1;
3008 output
[outpos
] = '0';
3010 TRACE(" returning %s\n", debugstr_w(output
));
3012 return (!Overflow
) ? outlen
: 0;
3017 /******************************************************************************
3018 * GetDateFormatA [KERNEL32.310]
3019 * Makes an ASCII string of the date
3021 * This function uses format to format the date, or, if format
3022 * is NULL, uses the default for the locale. format is a string
3023 * of literal fields and characters as follows:
3025 * - d single-digit (no leading zero) day (of month)
3026 * - dd two-digit day (of month)
3027 * - ddd short day-of-week name
3028 * - dddd long day-of-week name
3029 * - M single-digit month
3030 * - MM two-digit month
3031 * - MMM short month name
3032 * - MMMM full month name
3033 * - y two-digit year, no leading 0
3034 * - yy two-digit year
3035 * - yyyy four-digit year
3039 INT WINAPI
GetDateFormatA(LCID locale
,DWORD flags
,
3041 LPCSTR format
, LPSTR date
,INT datelen
)
3044 char format_buf
[40];
3047 LPSYSTEMTIME thistime
;
3053 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
3054 locale
,flags
,xtime
,format
,date
,datelen
);
3057 locale
= LOCALE_SYSTEM_DEFAULT
;
3060 if (locale
== LOCALE_SYSTEM_DEFAULT
) {
3061 thislocale
= GetSystemDefaultLCID();
3062 } else if (locale
== LOCALE_USER_DEFAULT
) {
3063 thislocale
= GetUserDefaultLCID();
3065 thislocale
= locale
;
3068 if (xtime
== NULL
) {
3071 /* Silently correct wDayOfWeek by tranforming to FileTime and back again*/
3072 res
=SystemTimeToFileTime(xtime
,&ft
);
3073 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error*/
3074 /*FIXME: SystemTimeToFileTime doesn't yet do that ckeck*/
3077 SetLastError(ERROR_INVALID_PARAMETER
);
3080 FileTimeToSystemTime(&ft
,&t
);
3085 if (format
== NULL
) {
3086 GetLocaleInfoA(thislocale
, ((flags
&DATE_LONGDATE
)
3088 : LOCALE_SSHORTDATE
),
3089 format_buf
, sizeof(format_buf
));
3090 thisformat
= format_buf
;
3092 thisformat
= format
;
3096 ret
= OLE_GetFormatA(thislocale
, flags
, 0, thistime
, thisformat
,
3101 "GetDateFormatA() returning %d, with data=%s\n",
3106 /******************************************************************************
3107 * GetDateFormatW [KERNEL32.311]
3108 * Makes a Unicode string of the date
3110 * Acts the same as GetDateFormatA(), except that it's Unicode.
3111 * Accepts & returns sizes as counts of Unicode characters.
3114 INT WINAPI
GetDateFormatW(LCID locale
,DWORD flags
,
3117 LPWSTR date
, INT datelen
)
3119 unsigned short datearr
[] = {'1','9','9','4','-','1','-','1',0};
3121 FIXME("STUB (should call OLE_GetFormatW)\n");
3122 lstrcpynW(date
, datearr
, datelen
);
3123 return ( datelen
< 9) ? datelen
: 9;
3128 /**************************************************************************
3129 * EnumDateFormatsA (KERNEL32.198)
3131 BOOL WINAPI
EnumDateFormatsA(
3132 DATEFMT_ENUMPROCA lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3134 LCID Loc
= GetUserDefaultLCID();
3135 if(!lpDateFmtEnumProc
)
3137 SetLastError(ERROR_INVALID_PARAMETER
);
3144 case 0x00000407: /* (Loc,"de_DE") */
3148 case DATE_SHORTDATE
:
3149 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
3150 if(!(*lpDateFmtEnumProc
)("d.M.yyyy")) return TRUE
;
3151 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
3152 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3155 if(!(*lpDateFmtEnumProc
)("dddd,d. MMMM yyyy")) return TRUE
;
3156 if(!(*lpDateFmtEnumProc
)("d. MMMM yyyy")) return TRUE
;
3157 if(!(*lpDateFmtEnumProc
)("d. MMM yyyy")) return TRUE
;
3160 FIXME("Unknown date format (%ld)\n", dwFlags
);
3161 SetLastError(ERROR_INVALID_PARAMETER
);
3166 case 0x0000040c: /* (Loc,"fr_FR") */
3170 case DATE_SHORTDATE
:
3171 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3172 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
3173 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3174 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3177 if(!(*lpDateFmtEnumProc
)("dddd d MMMM yyyy")) return TRUE
;
3178 if(!(*lpDateFmtEnumProc
)("d MMM yy")) return TRUE
;
3179 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3182 FIXME("Unknown date format (%ld)\n", dwFlags
);
3183 SetLastError(ERROR_INVALID_PARAMETER
);
3188 case 0x00000c0c: /* (Loc,"fr_CA") */
3192 case DATE_SHORTDATE
:
3193 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3194 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3195 if(!(*lpDateFmtEnumProc
)("yy MM dd")) return TRUE
;
3196 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3199 if(!(*lpDateFmtEnumProc
)("d MMMM, yyyy")) return TRUE
;
3200 if(!(*lpDateFmtEnumProc
)("d MMM yyyy")) return TRUE
;
3203 FIXME("Unknown date format (%ld)\n", dwFlags
);
3204 SetLastError(ERROR_INVALID_PARAMETER
);
3209 case 0x00000809: /* (Loc,"en_UK") */
3213 case DATE_SHORTDATE
:
3214 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3215 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3216 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3217 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3220 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3221 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3224 FIXME("Unknown date format (%ld)\n", dwFlags
);
3225 SetLastError(ERROR_INVALID_PARAMETER
);
3230 case 0x00000c09: /* (Loc,"en_AU") */
3234 case DATE_SHORTDATE
:
3235 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3236 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3237 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3240 if(!(*lpDateFmtEnumProc
)("dddd,d MMMM yyyy")) return TRUE
;
3241 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3244 FIXME("Unknown date format (%ld)\n", dwFlags
);
3245 SetLastError(ERROR_INVALID_PARAMETER
);
3250 case 0x00001009: /* (Loc,"en_CA") */
3254 case DATE_SHORTDATE
:
3255 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3256 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3257 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3258 if(!(*lpDateFmtEnumProc
)("M/dd/yy")) return TRUE
;
3261 if(!(*lpDateFmtEnumProc
)("d-MMM-yy")) return TRUE
;
3262 if(!(*lpDateFmtEnumProc
)("MMMM d, yyyy")) return TRUE
;
3265 FIXME("Unknown date format (%ld)\n", dwFlags
);
3266 SetLastError(ERROR_INVALID_PARAMETER
);
3271 case 0x00001409: /* (Loc,"en_NZ") */
3275 case DATE_SHORTDATE
:
3276 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3277 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3278 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
3281 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3282 if(!(*lpDateFmtEnumProc
)("dddd, d MMMM yyyy")) return TRUE
;
3285 FIXME("Unknown date format (%ld)\n", dwFlags
);
3286 SetLastError(ERROR_INVALID_PARAMETER
);
3291 case 0x00001809: /* (Loc,"en_IE") */
3295 case DATE_SHORTDATE
:
3296 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3297 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3298 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3301 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3302 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3305 FIXME("Unknown date format (%ld)\n", dwFlags
);
3306 SetLastError(ERROR_INVALID_PARAMETER
);
3311 case 0x00001c09: /* (Loc,"en_ZA") */
3315 case DATE_SHORTDATE
:
3316 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3319 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3322 FIXME("Unknown date format (%ld)\n", dwFlags
);
3323 SetLastError(ERROR_INVALID_PARAMETER
);
3328 case 0x00002009: /* (Loc,"en_JM") */
3332 case DATE_SHORTDATE
:
3333 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3336 if(!(*lpDateFmtEnumProc
)("dddd,MMMM dd,yyyy")) return TRUE
;
3337 if(!(*lpDateFmtEnumProc
)("MMMM dd,yyyy")) return TRUE
;
3338 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM,yyyy")) return TRUE
;
3339 if(!(*lpDateFmtEnumProc
)("dd MMMM,yyyy")) return TRUE
;
3342 FIXME("Unknown date format (%ld)\n", dwFlags
);
3343 SetLastError(ERROR_INVALID_PARAMETER
);
3348 case 0x00002809: /* (Loc,"en_BZ") */
3349 case 0x00002c09: /* (Loc,"en_TT") */
3353 case DATE_SHORTDATE
:
3354 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3357 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM yyyy")) return TRUE
;
3360 FIXME("Unknown date format (%ld)\n", dwFlags
);
3361 SetLastError(ERROR_INVALID_PARAMETER
);
3366 default: /* default to US English "en_US" */
3370 case DATE_SHORTDATE
:
3371 if(!(*lpDateFmtEnumProc
)("M/d/yy")) return TRUE
;
3372 if(!(*lpDateFmtEnumProc
)("M/d/yyyy")) return TRUE
;
3373 if(!(*lpDateFmtEnumProc
)("MM/dd/yy")) return TRUE
;
3374 if(!(*lpDateFmtEnumProc
)("MM/dd/yyyy")) return TRUE
;
3375 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3376 if(!(*lpDateFmtEnumProc
)("dd-MMM-yy")) return TRUE
;
3379 if(!(*lpDateFmtEnumProc
)("dddd, MMMM dd, yyyy")) return TRUE
;
3380 if(!(*lpDateFmtEnumProc
)("MMMM dd, yyyy")) return TRUE
;
3381 if(!(*lpDateFmtEnumProc
)("dddd, dd MMMM, yyyy")) return TRUE
;
3382 if(!(*lpDateFmtEnumProc
)("dd MMMM, yyyy")) return TRUE
;
3385 FIXME("Unknown date format (%ld)\n", dwFlags
);
3386 SetLastError(ERROR_INVALID_PARAMETER
);
3393 /**************************************************************************
3394 * EnumDateFormatsW (KERNEL32.199)
3396 BOOL WINAPI
EnumDateFormatsW(
3397 DATEFMT_ENUMPROCW lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3399 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc
, Locale
, dwFlags
);
3400 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3404 /**************************************************************************
3405 * EnumTimeFormatsA (KERNEL32.210)
3407 BOOL WINAPI
EnumTimeFormatsA(
3408 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3410 LCID Loc
= GetUserDefaultLCID();
3411 if(!lpTimeFmtEnumProc
)
3413 SetLastError(ERROR_INVALID_PARAMETER
);
3418 FIXME("Unknown time format (%ld)\n", dwFlags
);
3423 case 0x00000407: /* (Loc,"de_DE") */
3425 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3426 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3427 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3428 if(!(*lpTimeFmtEnumProc
)("H.mm")) return TRUE
;
3429 if(!(*lpTimeFmtEnumProc
)("H.mm'Uhr'")) return TRUE
;
3433 case 0x0000040c: /* (Loc,"fr_FR") */
3434 case 0x00000c0c: /* (Loc,"fr_CA") */
3436 if(!(*lpTimeFmtEnumProc
)("H:mm")) return TRUE
;
3437 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3438 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3439 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3440 if(!(*lpTimeFmtEnumProc
)("HH'h'mm")) return TRUE
;
3444 case 0x00000809: /* (Loc,"en_UK") */
3445 case 0x00000c09: /* (Loc,"en_AU") */
3446 case 0x00001409: /* (Loc,"en_NZ") */
3447 case 0x00001809: /* (Loc,"en_IE") */
3449 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3450 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3451 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3455 case 0x00001c09: /* (Loc,"en_ZA") */
3456 case 0x00002809: /* (Loc,"en_BZ") */
3457 case 0x00002c09: /* (Loc,"en_TT") */
3459 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3460 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3464 default: /* default to US style "en_US" */
3466 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3467 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3468 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3469 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3475 /**************************************************************************
3476 * EnumTimeFormatsW (KERNEL32.211)
3478 BOOL WINAPI
EnumTimeFormatsW(
3479 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3481 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc
, Locale
, dwFlags
);
3482 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3486 /**************************************************************************
3487 * This function is used just locally !
3488 * Description: Inverts a string.
3490 static void OLE_InvertString(char* string
)
3492 char sTmpArray
[128];
3495 for (counter
= strlen(string
); counter
> 0; counter
--)
3497 memcpy(sTmpArray
+ i
, string
+ counter
-1, 1);
3500 memcpy(sTmpArray
+ i
, "\0", 1);
3501 strcpy(string
, sTmpArray
);
3504 /***************************************************************************************
3505 * This function is used just locally !
3506 * Description: Test if the given string (psNumber) is valid or not.
3507 * The valid characters are the following:
3508 * - Characters '0' through '9'.
3509 * - One decimal point (dot) if the number is a floating-point value.
3510 * - A minus sign in the first character position if the number is
3512 * If the function succeeds, psBefore/psAfter will point to the string
3513 * on the right/left of the decimal symbol. pbNegative indicates if the
3514 * number is negative.
3516 static INT
OLE_GetNumberComponents(char* pInput
, char* psBefore
, char* psAfter
, BOOL
* pbNegative
)
3518 char sNumberSet
[] = "0123456789";
3519 BOOL bInDecimal
= FALSE
;
3521 /* Test if we do have a minus sign */
3522 if ( *pInput
== '-' )
3525 pInput
++; /* Jump to the next character. */
3528 while(*pInput
!= '\0')
3530 /* Do we have a valid numeric character */
3531 if ( strchr(sNumberSet
, *pInput
) != NULL
)
3533 if (bInDecimal
== TRUE
)
3534 *psAfter
++ = *pInput
;
3536 *psBefore
++ = *pInput
;
3540 /* Is this a decimal point (dot) */
3541 if ( *pInput
== '.' )
3543 /* Is it the first time we find it */
3544 if ((bInDecimal
== FALSE
))
3547 return -1; /* ERROR: Invalid parameter */
3551 /* It's neither a numeric character, nor a decimal point.
3552 * Thus, return an error.
3560 /* Add an End of Line character to the output buffers */
3567 /**************************************************************************
3568 * This function is used just locally !
3569 * Description: A number could be formatted using different numbers
3570 * of "digits in group" (example: 4;3;2;0).
3571 * The first parameter of this function is an array
3572 * containing the rule to be used. It's format is the following:
3573 * |NDG|DG1|DG2|...|0|
3574 * where NDG is the number of used "digits in group" and DG1, DG2,
3575 * are the corresponding "digits in group".
3576 * Thus, this function returns the grouping value in the array
3577 * pointed by the second parameter.
3579 static INT
OLE_GetGrouping(char* sRule
, INT index
)
3581 char sData
[2], sRuleSize
[2];
3582 INT nData
, nRuleSize
;
3584 memcpy(sRuleSize
, sRule
, 1);
3585 memcpy(sRuleSize
+1, "\0", 1);
3586 nRuleSize
= atoi(sRuleSize
);
3588 if (index
> 0 && index
< nRuleSize
)
3590 memcpy(sData
, sRule
+index
, 1);
3591 memcpy(sData
+1, "\0", 1);
3592 nData
= atoi(sData
);
3597 memcpy(sData
, sRule
+nRuleSize
-1, 1);
3598 memcpy(sData
+1, "\0", 1);
3599 nData
= atoi(sData
);
3605 /**************************************************************************
3606 * GetNumberFormatA (KERNEL32.355)
3608 INT WINAPI
GetNumberFormatA(LCID locale
, DWORD dwflags
,
3609 LPCSTR lpvalue
, const NUMBERFMTA
* lpFormat
,
3610 LPSTR lpNumberStr
, int cchNumber
)
3612 char sNumberDigits
[3], sDecimalSymbol
[5], sDigitsInGroup
[11], sDigitGroupSymbol
[5], sILZero
[2];
3613 INT nNumberDigits
, nNumberDecimal
, i
, j
, nCounter
, nStep
, nRuleIndex
, nGrouping
, nDigits
, retVal
, nLZ
;
3614 char sNumber
[128], sDestination
[128], sDigitsAfterDecimal
[10], sDigitsBeforeDecimal
[128];
3615 char sRule
[10], sSemiColumn
[]=";", sBuffer
[5], sNegNumber
[2];
3616 char *pStr
= NULL
, *pTmpStr
= NULL
;
3617 LCID systemDefaultLCID
;
3618 BOOL bNegative
= FALSE
;
3627 strncpy(sNumber
, lpvalue
, 128);
3628 sNumber
[127] = '\0';
3630 /* Make sure we have a valid input string, get the number
3631 * of digits before and after the decimal symbol, and check
3632 * if this is a negative number.
3634 if ( OLE_GetNumberComponents(sNumber
, sDigitsBeforeDecimal
, sDigitsAfterDecimal
, &bNegative
) != -1)
3636 nNumberDecimal
= strlen(sDigitsBeforeDecimal
);
3637 nDigits
= strlen(sDigitsAfterDecimal
);
3641 SetLastError(ERROR_INVALID_PARAMETER
);
3645 /* Which source will we use to format the string */
3646 used_operation
= RETURN_ERROR
;
3647 if (lpFormat
!= NULL
)
3650 used_operation
= USE_PARAMETER
;
3654 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3655 used_operation
= USE_LOCALEINFO
;
3657 used_operation
= USE_SYSTEMDEFAULT
;
3660 /* Load the fields we need */
3661 switch(used_operation
)
3663 case USE_LOCALEINFO
:
3664 GetLocaleInfoA(locale
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3665 GetLocaleInfoA(locale
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3666 GetLocaleInfoA(locale
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3667 GetLocaleInfoA(locale
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3668 GetLocaleInfoA(locale
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3669 GetLocaleInfoA(locale
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3672 sprintf(sNumberDigits
, "%d",lpFormat
->NumDigits
);
3673 strcpy(sDecimalSymbol
, lpFormat
->lpDecimalSep
);
3674 sprintf(sDigitsInGroup
, "%d;0",lpFormat
->Grouping
);
3675 strcpy(sDigitGroupSymbol
, lpFormat
->lpThousandSep
);
3676 sprintf(sILZero
, "%d",lpFormat
->LeadingZero
);
3677 sprintf(sNegNumber
, "%d",lpFormat
->NegativeOrder
);
3679 case USE_SYSTEMDEFAULT
:
3680 systemDefaultLCID
= GetSystemDefaultLCID();
3681 GetLocaleInfoA(systemDefaultLCID
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3682 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3683 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3684 GetLocaleInfoA(systemDefaultLCID
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3685 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3686 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3689 SetLastError(ERROR_INVALID_PARAMETER
);
3693 nNumberDigits
= atoi(sNumberDigits
);
3695 /* Remove the ";" */
3698 for (nCounter
=0; nCounter
<strlen(sDigitsInGroup
); nCounter
++)
3700 if ( memcmp(sDigitsInGroup
+ nCounter
, sSemiColumn
, 1) != 0 )
3702 memcpy(sRule
+ j
, sDigitsInGroup
+ nCounter
, 1);
3707 sprintf(sBuffer
, "%d", i
);
3708 memcpy(sRule
, sBuffer
, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3709 memcpy(sRule
+ j
, "\0", 1);
3711 /* First, format the digits before the decimal. */
3712 if ((nNumberDecimal
>0) && (atoi(sDigitsBeforeDecimal
) != 0))
3714 /* Working on an inverted string is easier ! */
3715 OLE_InvertString(sDigitsBeforeDecimal
);
3717 nStep
= nCounter
= i
= j
= 0;
3719 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3721 /* Here, we will loop until we reach the end of the string.
3722 * An internal counter (j) is used in order to know when to
3723 * insert the "digit group symbol".
3725 while (nNumberDecimal
> 0)
3727 i
= nCounter
+ nStep
;
3728 memcpy(sDestination
+ i
, sDigitsBeforeDecimal
+ nCounter
, 1);
3734 if (nRuleIndex
< sRule
[0])
3736 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3737 memcpy(sDestination
+ i
+1, sDigitGroupSymbol
, strlen(sDigitGroupSymbol
));
3738 nStep
+= strlen(sDigitGroupSymbol
);
3744 memcpy(sDestination
+ i
+1, "\0", 1);
3745 /* Get the string in the right order ! */
3746 OLE_InvertString(sDestination
);
3750 nLZ
= atoi(sILZero
);
3753 /* Use 0.xxx instead of .xxx */
3754 memcpy(sDestination
, "0", 1);
3755 memcpy(sDestination
+1, "\0", 1);
3758 memcpy(sDestination
, "\0", 1);
3762 /* Second, format the digits after the decimal. */
3764 nCounter
= nNumberDigits
;
3765 if ( (nDigits
>0) && (pStr
= strstr (sNumber
, ".")) )
3767 i
= strlen(sNumber
) - strlen(pStr
) + 1;
3768 strncpy ( sDigitsAfterDecimal
, sNumber
+ i
, nNumberDigits
);
3769 j
= strlen(sDigitsAfterDecimal
);
3770 if (j
< nNumberDigits
)
3771 nCounter
= nNumberDigits
-j
;
3773 for (i
=0;i
<nCounter
;i
++)
3774 memcpy(sDigitsAfterDecimal
+i
+j
, "0", 1);
3775 memcpy(sDigitsAfterDecimal
+ nNumberDigits
, "\0", 1);
3777 i
= strlen(sDestination
);
3778 j
= strlen(sDigitsAfterDecimal
);
3779 /* Finally, construct the resulting formatted string. */
3781 for (nCounter
=0; nCounter
<i
; nCounter
++)
3782 memcpy(sNumber
+ nCounter
, sDestination
+ nCounter
, 1);
3784 memcpy(sNumber
+ nCounter
, sDecimalSymbol
, strlen(sDecimalSymbol
));
3787 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), sDigitsAfterDecimal
+ i
, 1);
3788 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), "\0", 1);
3790 /* Is it a negative number */
3791 if (bNegative
== TRUE
)
3793 i
= atoi(sNegNumber
);
3794 pStr
= sDestination
;
3800 while (*sNumber
!= '\0')
3801 *pStr
++ = *pTmpStr
++;
3806 while (*pTmpStr
!= '\0')
3807 *pStr
++ = *pTmpStr
++;
3812 while (*pTmpStr
!= '\0')
3813 *pStr
++ = *pTmpStr
++;
3816 while (*pTmpStr
!= '\0')
3817 *pStr
++ = *pTmpStr
++;
3821 while (*pTmpStr
!= '\0')
3822 *pStr
++ = *pTmpStr
++;
3827 while (*pTmpStr
!= '\0')
3828 *pStr
++ = *pTmpStr
++;
3833 strcpy(sDestination
, sNumber
);
3835 /* If cchNumber is zero, then returns the number of bytes or characters
3836 * required to hold the formatted number string
3839 retVal
= strlen(sDestination
) + 1;
3842 strncpy (lpNumberStr
, sDestination
, cchNumber
-1);
3843 *(lpNumberStr
+cchNumber
-1) = '\0'; /* ensure we got a NULL at the end */
3844 retVal
= strlen(lpNumberStr
);
3850 /**************************************************************************
3851 * GetNumberFormatW (KERNEL32.xxx)
3853 INT WINAPI
GetNumberFormatW(LCID locale
, DWORD dwflags
,
3854 LPCWSTR lpvalue
, const NUMBERFMTW
* lpFormat
,
3855 LPWSTR lpNumberStr
, int cchNumber
)
3857 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue
));
3859 lstrcpynW( lpNumberStr
, lpvalue
, cchNumber
);
3860 return cchNumber
? strlenW( lpNumberStr
) : 0;
3863 /**************************************************************************
3864 * GetCurrencyFormatA (KERNEL32.302)
3866 INT WINAPI
GetCurrencyFormatA(LCID locale
, DWORD dwflags
,
3867 LPCSTR lpvalue
, const CURRENCYFMTA
* lpFormat
,
3868 LPSTR lpCurrencyStr
, int cchCurrency
)
3870 UINT nPosOrder
, nNegOrder
;
3872 char sDestination
[128], sNegOrder
[8], sPosOrder
[8], sCurrencySymbol
[8];
3873 char *pDestination
= sDestination
;
3874 char sNumberFormated
[128];
3875 char *pNumberFormated
= sNumberFormated
;
3876 LCID systemDefaultLCID
;
3877 BOOL bIsPositive
= FALSE
, bValidFormat
= FALSE
;
3886 NUMBERFMTA numberFmt
;
3888 /* Which source will we use to format the string */
3889 used_operation
= RETURN_ERROR
;
3890 if (lpFormat
!= NULL
)
3893 used_operation
= USE_PARAMETER
;
3897 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3898 used_operation
= USE_LOCALEINFO
;
3900 used_operation
= USE_SYSTEMDEFAULT
;
3903 /* Load the fields we need */
3904 switch(used_operation
)
3906 case USE_LOCALEINFO
:
3907 /* Specific to CURRENCYFMTA*/
3908 GetLocaleInfoA(locale
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3909 GetLocaleInfoA(locale
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3910 GetLocaleInfoA(locale
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3912 nPosOrder
= atoi(sPosOrder
);
3913 nNegOrder
= atoi(sNegOrder
);
3916 /* Specific to CURRENCYFMTA*/
3917 nNegOrder
= lpFormat
->NegativeOrder
;
3918 nPosOrder
= lpFormat
->PositiveOrder
;
3919 strcpy(sCurrencySymbol
, lpFormat
->lpCurrencySymbol
);
3921 case USE_SYSTEMDEFAULT
:
3922 systemDefaultLCID
= GetSystemDefaultLCID();
3923 /* Specific to CURRENCYFMTA*/
3924 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3925 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3926 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3928 nPosOrder
= atoi(sPosOrder
);
3929 nNegOrder
= atoi(sNegOrder
);
3932 SetLastError(ERROR_INVALID_PARAMETER
);
3936 /* Construct a temporary number format structure */
3937 if (lpFormat
!= NULL
)
3939 numberFmt
.NumDigits
= lpFormat
->NumDigits
;
3940 numberFmt
.LeadingZero
= lpFormat
->LeadingZero
;
3941 numberFmt
.Grouping
= lpFormat
->Grouping
;
3942 numberFmt
.NegativeOrder
= 0;
3943 numberFmt
.lpDecimalSep
= lpFormat
->lpDecimalSep
;
3944 numberFmt
.lpThousandSep
= lpFormat
->lpThousandSep
;
3945 bValidFormat
= TRUE
;
3948 /* Make a call to GetNumberFormatA() */
3949 if (*lpvalue
== '-')
3951 bIsPositive
= FALSE
;
3952 retVal
= GetNumberFormatA(locale
,0,lpvalue
+1,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3957 retVal
= GetNumberFormatA(locale
,0,lpvalue
,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3963 /* construct the formatted string */
3968 case 0: /* Prefix, no separation */
3969 strcpy (pDestination
, sCurrencySymbol
);
3970 strcat (pDestination
, pNumberFormated
);
3972 case 1: /* Suffix, no separation */
3973 strcpy (pDestination
, pNumberFormated
);
3974 strcat (pDestination
, sCurrencySymbol
);
3976 case 2: /* Prefix, 1 char separation */
3977 strcpy (pDestination
, sCurrencySymbol
);
3978 strcat (pDestination
, " ");
3979 strcat (pDestination
, pNumberFormated
);
3981 case 3: /* Suffix, 1 char separation */
3982 strcpy (pDestination
, pNumberFormated
);
3983 strcat (pDestination
, " ");
3984 strcat (pDestination
, sCurrencySymbol
);
3987 SetLastError(ERROR_INVALID_PARAMETER
);
3991 else /* negative number */
3995 case 0: /* format: ($1.1) */
3996 strcpy (pDestination
, "(");
3997 strcat (pDestination
, sCurrencySymbol
);
3998 strcat (pDestination
, pNumberFormated
);
3999 strcat (pDestination
, ")");
4001 case 1: /* format: -$1.1 */
4002 strcpy (pDestination
, "-");
4003 strcat (pDestination
, sCurrencySymbol
);
4004 strcat (pDestination
, pNumberFormated
);
4006 case 2: /* format: $-1.1 */
4007 strcpy (pDestination
, sCurrencySymbol
);
4008 strcat (pDestination
, "-");
4009 strcat (pDestination
, pNumberFormated
);
4011 case 3: /* format: $1.1- */
4012 strcpy (pDestination
, sCurrencySymbol
);
4013 strcat (pDestination
, pNumberFormated
);
4014 strcat (pDestination
, "-");
4016 case 4: /* format: (1.1$) */
4017 strcpy (pDestination
, "(");
4018 strcat (pDestination
, pNumberFormated
);
4019 strcat (pDestination
, sCurrencySymbol
);
4020 strcat (pDestination
, ")");
4022 case 5: /* format: -1.1$ */
4023 strcpy (pDestination
, "-");
4024 strcat (pDestination
, pNumberFormated
);
4025 strcat (pDestination
, sCurrencySymbol
);
4027 case 6: /* format: 1.1-$ */
4028 strcpy (pDestination
, pNumberFormated
);
4029 strcat (pDestination
, "-");
4030 strcat (pDestination
, sCurrencySymbol
);
4032 case 7: /* format: 1.1$- */
4033 strcpy (pDestination
, pNumberFormated
);
4034 strcat (pDestination
, sCurrencySymbol
);
4035 strcat (pDestination
, "-");
4037 case 8: /* format: -1.1 $ */
4038 strcpy (pDestination
, "-");
4039 strcat (pDestination
, pNumberFormated
);
4040 strcat (pDestination
, " ");
4041 strcat (pDestination
, sCurrencySymbol
);
4043 case 9: /* format: -$ 1.1 */
4044 strcpy (pDestination
, "-");
4045 strcat (pDestination
, sCurrencySymbol
);
4046 strcat (pDestination
, " ");
4047 strcat (pDestination
, pNumberFormated
);
4049 case 10: /* format: 1.1 $- */
4050 strcpy (pDestination
, pNumberFormated
);
4051 strcat (pDestination
, " ");
4052 strcat (pDestination
, sCurrencySymbol
);
4053 strcat (pDestination
, "-");
4055 case 11: /* format: $ 1.1- */
4056 strcpy (pDestination
, sCurrencySymbol
);
4057 strcat (pDestination
, " ");
4058 strcat (pDestination
, pNumberFormated
);
4059 strcat (pDestination
, "-");
4061 case 12: /* format: $ -1.1 */
4062 strcpy (pDestination
, sCurrencySymbol
);
4063 strcat (pDestination
, " ");
4064 strcat (pDestination
, "-");
4065 strcat (pDestination
, pNumberFormated
);
4067 case 13: /* format: 1.1- $ */
4068 strcpy (pDestination
, pNumberFormated
);
4069 strcat (pDestination
, "-");
4070 strcat (pDestination
, " ");
4071 strcat (pDestination
, sCurrencySymbol
);
4073 case 14: /* format: ($ 1.1) */
4074 strcpy (pDestination
, "(");
4075 strcat (pDestination
, sCurrencySymbol
);
4076 strcat (pDestination
, " ");
4077 strcat (pDestination
, pNumberFormated
);
4078 strcat (pDestination
, ")");
4080 case 15: /* format: (1.1 $) */
4081 strcpy (pDestination
, "(");
4082 strcat (pDestination
, pNumberFormated
);
4083 strcat (pDestination
, " ");
4084 strcat (pDestination
, sCurrencySymbol
);
4085 strcat (pDestination
, ")");
4088 SetLastError(ERROR_INVALID_PARAMETER
);
4093 if (cchCurrency
== 0)
4094 return strlen(pDestination
) + 1;
4098 strncpy (lpCurrencyStr
, pDestination
, cchCurrency
-1);
4099 *(lpCurrencyStr
+cchCurrency
-1) = '\0'; /* ensure we got a NULL at the end */
4100 return strlen(lpCurrencyStr
);
4104 /**************************************************************************
4105 * GetCurrencyFormatW (KERNEL32.303)
4107 INT WINAPI
GetCurrencyFormatW(LCID locale
, DWORD dwflags
,
4108 LPCWSTR lpvalue
, const CURRENCYFMTW
* lpFormat
,
4109 LPWSTR lpCurrencyStr
, int cchCurrency
)
4111 FIXME("This API function is NOT implemented !\n");
4115 /******************************************************************************
4116 * OLE2NLS_CheckLocale [intern]
4118 static LCID
OLE2NLS_CheckLocale (LCID locale
)
4121 { locale
= LOCALE_SYSTEM_DEFAULT
;
4124 if (locale
== LOCALE_SYSTEM_DEFAULT
)
4125 { return GetSystemDefaultLCID();
4127 else if (locale
== LOCALE_USER_DEFAULT
)
4128 { return GetUserDefaultLCID();
4134 /******************************************************************************
4135 * GetTimeFormatA [KERNEL32.422]
4136 * Makes an ASCII string of the time
4138 * Formats date according to format, or locale default if format is
4139 * NULL. The format consists of literal characters and fields as follows:
4141 * h hours with no leading zero (12-hour)
4142 * hh hours with full two digits
4143 * H hours with no leading zero (24-hour)
4144 * HH hours with full two digits
4145 * m minutes with no leading zero
4146 * mm minutes with full two digits
4147 * s seconds with no leading zero
4148 * ss seconds with full two digits
4149 * t time marker (A or P)
4150 * tt time marker (AM, PM)
4154 GetTimeFormatA(LCID locale
, /* [in] */
4155 DWORD flags
, /* [in] */
4156 LPSYSTEMTIME xtime
, /* [in] */
4157 LPCSTR format
, /* [in] */
4158 LPSTR timestr
, /* [out] */
4159 INT timelen
/* [in] */)
4160 { char format_buf
[40];
4163 LPSYSTEMTIME thistime
;
4165 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4168 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,xtime
,format
,timestr
,timelen
);
4170 thislocale
= OLE2NLS_CheckLocale ( locale
);
4172 if ( flags
& (TIME_NOTIMEMARKER
| TIME_FORCE24HOURFORMAT
))
4173 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4176 flags
&= (TIME_NOSECONDS
| TIME_NOMINUTESORSECONDS
); /* mask for OLE_GetFormatA*/
4179 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4180 { thislocale
= GetSystemDefaultLCID();
4182 GetLocaleInfoA(thislocale
, thisflags
, format_buf
, sizeof(format_buf
));
4183 thisformat
= format_buf
;
4186 { thisformat
= format
;
4189 if (xtime
== NULL
) /* NULL means use the current local time*/
4195 /* Check that hour,min and sec is in range */
4197 ret
= OLE_GetFormatA(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4203 /******************************************************************************
4204 * GetTimeFormatW [KERNEL32.423]
4205 * Makes a Unicode string of the time
4208 GetTimeFormatW(LCID locale
, /* [in] */
4209 DWORD flags
, /* [in] */
4210 LPSYSTEMTIME xtime
, /* [in] */
4211 LPCWSTR format
, /* [in] */
4212 LPWSTR timestr
, /* [out] */
4213 INT timelen
/* [in] */)
4214 { WCHAR format_buf
[40];
4217 LPSYSTEMTIME thistime
;
4219 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4222 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,
4223 xtime
,debugstr_w(format
),timestr
,timelen
);
4225 thislocale
= OLE2NLS_CheckLocale ( locale
);
4227 if ( flags
& (TIME_NOTIMEMARKER
| TIME_FORCE24HOURFORMAT
))
4228 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4231 flags
&= (TIME_NOSECONDS
| TIME_NOMINUTESORSECONDS
); /* mask for OLE_GetFormatA*/
4234 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4235 { thislocale
= GetSystemDefaultLCID();
4237 GetLocaleInfoW(thislocale
, thisflags
, format_buf
, 40);
4238 thisformat
= format_buf
;
4241 { thisformat
= format
;
4244 if (xtime
== NULL
) /* NULL means use the current local time*/
4252 ret
= OLE_GetFormatW(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4257 /******************************************************************************
4258 * EnumCalendarInfoA [KERNEL32.196]
4260 BOOL WINAPI
EnumCalendarInfoA(
4261 CALINFO_ENUMPROCA calinfoproc
,LCID locale
,CALID calendar
,CALTYPE caltype
4263 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc
,locale
,calendar
,caltype
);