2 * National Language Support library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
17 #include "wine/unicode.h"
18 #include "wine/winestring.h"
25 #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 lstrcpynAtoW(wbuf
,abuf
,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
/* locale identifier created with MAKELCID;
1879 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1880 predefined values. */,
1881 DWORD mapflags
/* flags */,
1882 LPCSTR srcstr
/* source buffer */,
1883 INT srclen
/* source length */,
1884 LPSTR dststr
/* destination buffer */,
1885 INT dstlen
/* 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
, /* locale ID */
2457 DWORD fdwStyle
, /* comparison-style options */
2458 LPCSTR s1
, /* first string */
2459 DWORD l1
, /* length of first string */
2460 LPCSTR s2
, /* second string */
2461 DWORD l2
) /* 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 */
2536 if(ret
!=0) return ret
+2;
2537 /* same len, return 2 */
2538 if(l1
==l2
) return 2;
2539 /* the longer one is lexically greater */
2540 return (l1
<l2
)? 1 : 3;
2543 /******************************************************************************
2544 * OLE_GetFormatA [Internal]
2547 * If datelen == 0, it should return the reguired string length.
2549 This function implements stuff for GetDateFormat() and
2552 d single-digit (no leading zero) day (of month)
2553 dd two-digit day (of month)
2554 ddd short day-of-week name
2555 dddd long day-of-week name
2556 M single-digit month
2558 MMM short month name
2559 MMMM full month name
2560 y two-digit year, no leading 0
2562 yyyy four-digit year
2564 h hours with no leading zero (12-hour)
2565 hh hours with full two digits
2566 H hours with no leading zero (24-hour)
2567 HH hours with full two digits
2568 m minutes with no leading zero
2569 mm minutes with full two digits
2570 s seconds with no leading zero
2571 ss seconds with full two digits
2572 t time marker (A or P)
2573 tt time marker (AM, PM)
2574 '' used to quote literal characters
2575 '' (within a quoted string) indicates a literal '
2577 These functions REQUIRE valid locale, date, and format.
2579 static INT
OLE_GetFormatA(LCID locale
,
2583 LPCSTR _format
, /*in*/
2588 int count
, type
, inquote
, Overflow
;
2594 const char * _dgfmt
[] = { "%d", "%02d" };
2595 const char ** dgfmt
= _dgfmt
- 1;
2597 /* report, for debugging */
2598 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",
2599 locale
, flags
, tflags
,
2600 xtime
->wYear
,xtime
->wMonth
,xtime
->wDayOfWeek
,xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2601 _format
, _format
, date
, datelen
);
2604 FIXME("datelen = 0, returning 255\n");
2608 /* initalize state variables and output buffer */
2610 count
= 0; inquote
= 0; Overflow
= 0;
2612 date
[0] = buf
[0] = '\0';
2614 strcpy(format
,_format
);
2616 /* alter the formatstring, while it works for all languages now in wine
2617 its possible that it fails when the time looks like ss:mm:hh as example*/
2618 if (tflags
& (TIME_NOMINUTESORSECONDS
))
2619 { if ((pos
= strstr ( format
, ":mm")))
2620 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2623 if (tflags
& (TIME_NOSECONDS
))
2624 { if ((pos
= strstr ( format
, ":ss")))
2625 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2629 for (inpos
= 0;; inpos
++) {
2630 /* 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]); */
2632 if (format
[inpos
] == '\'') {
2633 if (format
[inpos
+1] == '\'') {
2635 date
[outpos
++] = '\'';
2638 continue; /* we did nothing to the output */
2640 } else if (format
[inpos
] == '\0') {
2641 date
[outpos
++] = '\0';
2642 if (outpos
> datelen
) Overflow
= 1;
2645 date
[outpos
++] = format
[inpos
];
2646 if (outpos
> datelen
) {
2648 date
[outpos
-1] = '\0'; /* this is the last place where
2649 it's safe to write */
2653 } else if ( (count
&& (format
[inpos
] != type
))
2655 || (count
== 2 && strchr("ghHmst", type
)) )
2659 GetLocaleInfoA(locale
,
2661 + (xtime
->wDayOfWeek
+6)%7,
2663 } else if (count
== 3) {
2664 GetLocaleInfoA(locale
,
2665 LOCALE_SABBREVDAYNAME1
2666 + (xtime
->wDayOfWeek
+6)%7,
2669 sprintf(buf
, dgfmt
[count
], xtime
->wDay
);
2671 } else if (type
== 'M') {
2673 GetLocaleInfoA(locale
,
2674 LOCALE_SABBREVMONTHNAME1
2675 + xtime
->wMonth
- 1,
2677 } else if (count
== 4) {
2678 GetLocaleInfoA(locale
,
2680 + xtime
->wMonth
- 1,
2683 sprintf(buf
, dgfmt
[count
], xtime
->wMonth
);
2685 } else if (type
== 'y') {
2687 sprintf(buf
, "%d", xtime
->wYear
);
2688 } else if (count
== 3) {
2690 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2692 sprintf(buf
, dgfmt
[count
], xtime
->wYear
% 100);
2694 } else if (type
== 'g') {
2696 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2700 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2702 } else if (type
== 'h') {
2703 /* gives us hours 1:00 -- 12:00 */
2704 sprintf(buf
, dgfmt
[count
], (xtime
->wHour
-1)%12 +1);
2705 } else if (type
== 'H') {
2707 sprintf(buf
, dgfmt
[count
], xtime
->wHour
);
2708 } else if ( type
== 'm') {
2709 sprintf(buf
, dgfmt
[count
], xtime
->wMinute
);
2710 } else if ( type
== 's') {
2711 sprintf(buf
, dgfmt
[count
], xtime
->wSecond
);
2712 } else if (type
== 't') {
2714 sprintf(buf
, "%c", (xtime
->wHour
< 12) ? 'A' : 'P');
2715 } else if (count
== 2) {
2716 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2717 GetLocaleInfoA(locale
,
2719 ? LOCALE_S1159
: LOCALE_S2359
,
2724 /* we need to check the next char in the format string
2725 again, no matter what happened */
2728 /* add the contents of buf to the output */
2729 buflen
= strlen(buf
);
2730 if (outpos
+ buflen
< datelen
) {
2731 date
[outpos
] = '\0'; /* for strcat to hook onto */
2735 date
[outpos
] = '\0';
2736 strncat(date
, buf
, datelen
- outpos
);
2737 date
[datelen
- 1] = '\0';
2738 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2739 WARN("insufficient buffer\n");
2743 /* reset the variables we used to keep track of this item */
2746 } else if (format
[inpos
] == '\0') {
2747 /* we can't check for this at the loop-head, because
2748 that breaks the printing of the last format-item */
2749 date
[outpos
] = '\0';
2752 /* continuing a code for an item */
2755 } else if (strchr("hHmstyMdg", format
[inpos
])) {
2756 type
= format
[inpos
];
2759 } else if (format
[inpos
] == '\'') {
2763 date
[outpos
++] = format
[inpos
];
2765 /* now deal with a possible buffer overflow */
2766 if (outpos
>= datelen
) {
2767 date
[datelen
- 1] = '\0';
2768 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2774 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2777 /* finish it off with a string terminator */
2780 if (outpos
> datelen
-1) outpos
= datelen
-1;
2781 date
[outpos
] = '\0';
2783 TRACE("OLE_GetFormatA returns string '%s', len %d\n",
2788 /******************************************************************************
2789 * OLE_GetFormatW [INTERNAL]
2791 static INT
OLE_GetFormatW(LCID locale
, DWORD flags
, DWORD tflags
,
2794 LPWSTR output
, INT outlen
)
2797 int count
, type
=0, inquote
;
2798 int Overflow
; /* loop check */
2801 WCHAR arg0
[] = {0}, arg1
[] = {'%','d',0};
2802 WCHAR arg2
[] = {'%','0','2','d',0};
2804 int datevars
=0, timevars
=0;
2810 /* make a debug report */
2811 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2812 "%p with max len %d\n",
2813 locale
, flags
, tflags
,
2814 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2815 debugstr_w(format
), format
, output
, outlen
);
2818 FIXME("outlen = 0, returning 255\n");
2822 /* initialize state variables */
2825 inquote
= Overflow
= 0;
2826 /* this is really just a sanity check */
2827 output
[0] = buf
[0] = 0;
2829 /* this loop is the core of the function */
2830 for (inpos
= 0; /* we have several break points */ ; inpos
++) {
2832 if (format
[inpos
] == (WCHAR
) '\'') {
2833 if (format
[inpos
+1] == '\'') {
2835 output
[outpos
++] = '\'';
2840 } else if (format
[inpos
] == 0) {
2841 output
[outpos
++] = 0;
2842 if (outpos
> outlen
) Overflow
= 1;
2843 break; /* normal exit (within a quote) */
2845 output
[outpos
++] = format
[inpos
]; /* copy input */
2846 if (outpos
> outlen
) {
2848 output
[outpos
-1] = 0;
2852 } else if ( (count
&& (format
[inpos
] != type
))
2853 || ( (count
==4 && type
=='y') ||
2854 (count
==4 && type
=='M') ||
2855 (count
==4 && type
=='d') ||
2856 (count
==2 && type
=='g') ||
2857 (count
==2 && type
=='h') ||
2858 (count
==2 && type
=='H') ||
2859 (count
==2 && type
=='m') ||
2860 (count
==2 && type
=='s') ||
2861 (count
==2 && type
=='t') ) ) {
2864 GetLocaleInfoW(locale
,
2865 LOCALE_SDAYNAME1
+ (xtime
->wDayOfWeek
+6)%7,
2866 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2867 } else if (count
== 3) {
2868 GetLocaleInfoW(locale
,
2869 LOCALE_SABBREVDAYNAME1
+
2870 (xtime
->wDayOfWeek
+6)%7,
2871 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2873 wsnprintfW(buf
, 5, argarr
[count
], xtime
->wDay
);
2875 } else if (type
== 'M') {
2877 GetLocaleInfoW(locale
, LOCALE_SMONTHNAME1
+
2878 xtime
->wMonth
-1, buf
,
2879 sizeof(buf
)/sizeof(WCHAR
) );
2880 } else if (count
== 3) {
2881 GetLocaleInfoW(locale
, LOCALE_SABBREVMONTHNAME1
+
2882 xtime
->wMonth
-1, buf
,
2883 sizeof(buf
)/sizeof(WCHAR
) );
2885 wsnprintfW(buf
, 5, argarr
[count
], xtime
->wMonth
);
2887 } else if (type
== 'y') {
2889 wsnprintfW(buf
, 6, argarr
[1] /* "%d" */,
2891 } else if (count
== 3) {
2892 lstrcpynAtoW(buf
, "yyy", 5);
2894 wsnprintfW(buf
, 6, argarr
[count
],
2895 xtime
->wYear
% 100);
2897 } else if (type
== 'g') {
2899 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2900 lstrcpynAtoW(buf
, "AD", 5);
2902 /* Win API sez we copy it verbatim */
2903 lstrcpynAtoW(buf
, "g", 5);
2905 } else if (type
== 'h') {
2906 /* hours 1:00-12:00 --- is this right? */
2907 wsnprintfW(buf
, 5, argarr
[count
],
2908 (xtime
->wHour
-1)%12 +1);
2909 } else if (type
== 'H') {
2910 wsnprintfW(buf
, 5, argarr
[count
],
2912 } else if (type
== 'm' ) {
2913 wsnprintfW(buf
, 5, argarr
[count
],
2915 } else if (type
== 's' ) {
2916 wsnprintfW(buf
, 5, argarr
[count
],
2918 } else if (type
== 't') {
2919 GetLocaleInfoW(locale
, (xtime
->wHour
< 12) ?
2920 LOCALE_S1159
: LOCALE_S2359
,
2927 /* no matter what happened, we need to check this next
2928 character the next time we loop through */
2931 /* cat buf onto the output */
2932 outlen
= strlenW(buf
);
2933 if (outpos
+ buflen
< outlen
) {
2934 strcpyW( output
+ outpos
, buf
);
2937 lstrcpynW( output
+ outpos
, buf
, outlen
- outpos
);
2939 break; /* Abnormal exit */
2942 /* reset the variables we used this time */
2945 } else if (format
[inpos
] == 0) {
2946 /* we can't check for this at the beginning, because that
2947 would keep us from printing a format spec that ended the
2950 break; /* NORMAL EXIT */
2952 /* how we keep track of the middle of a format spec */
2955 } else if ( (datevars
&& (format
[inpos
]=='d' ||
2956 format
[inpos
]=='M' ||
2957 format
[inpos
]=='y' ||
2958 format
[inpos
]=='g') ) ||
2959 (timevars
&& (format
[inpos
]=='H' ||
2960 format
[inpos
]=='h' ||
2961 format
[inpos
]=='m' ||
2962 format
[inpos
]=='s' ||
2963 format
[inpos
]=='t') ) ) {
2964 type
= format
[inpos
];
2967 } else if (format
[inpos
] == '\'') {
2971 /* unquoted literals */
2972 output
[outpos
++] = format
[inpos
];
2977 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2978 WARN(" buffer overflow\n");
2981 /* final string terminator and sanity check */
2983 if (outpos
> outlen
-1) outpos
= outlen
-1;
2984 output
[outpos
] = '0';
2986 TRACE(" returning %s\n", debugstr_w(output
));
2988 return (!Overflow
) ? outlen
: 0;
2993 /******************************************************************************
2994 * GetDateFormatA [KERNEL32.310]
2995 * Makes an ASCII string of the date
2997 * This function uses format to format the date, or, if format
2998 * is NULL, uses the default for the locale. format is a string
2999 * of literal fields and characters as follows:
3001 * - d single-digit (no leading zero) day (of month)
3002 * - dd two-digit day (of month)
3003 * - ddd short day-of-week name
3004 * - dddd long day-of-week name
3005 * - M single-digit month
3006 * - MM two-digit month
3007 * - MMM short month name
3008 * - MMMM full month name
3009 * - y two-digit year, no leading 0
3010 * - yy two-digit year
3011 * - yyyy four-digit year
3015 INT WINAPI
GetDateFormatA(LCID locale
,DWORD flags
,
3017 LPCSTR format
, LPSTR date
,INT datelen
)
3020 char format_buf
[40];
3023 LPSYSTEMTIME thistime
;
3029 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
3030 locale
,flags
,xtime
,format
,date
,datelen
);
3033 locale
= LOCALE_SYSTEM_DEFAULT
;
3036 if (locale
== LOCALE_SYSTEM_DEFAULT
) {
3037 thislocale
= GetSystemDefaultLCID();
3038 } else if (locale
== LOCALE_USER_DEFAULT
) {
3039 thislocale
= GetUserDefaultLCID();
3041 thislocale
= locale
;
3044 if (xtime
== NULL
) {
3047 /* Silently correct wDayOfWeek by tranforming to FileTime and back again*/
3048 res
=SystemTimeToFileTime(xtime
,&ft
);
3049 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error*/
3050 /*FIXME: SystemTimeToFileTime doesn't yet do that ckeck*/
3053 SetLastError(ERROR_INVALID_PARAMETER
);
3056 FileTimeToSystemTime(&ft
,&t
);
3061 if (format
== NULL
) {
3062 GetLocaleInfoA(thislocale
, ((flags
&DATE_LONGDATE
)
3064 : LOCALE_SSHORTDATE
),
3065 format_buf
, sizeof(format_buf
));
3066 thisformat
= format_buf
;
3068 thisformat
= format
;
3072 ret
= OLE_GetFormatA(thislocale
, flags
, 0, thistime
, thisformat
,
3077 "GetDateFormatA() returning %d, with data=%s\n",
3082 /******************************************************************************
3083 * GetDateFormatW [KERNEL32.311]
3084 * Makes a Unicode string of the date
3086 * Acts the same as GetDateFormatA(), except that it's Unicode.
3087 * Accepts & returns sizes as counts of Unicode characters.
3090 INT WINAPI
GetDateFormatW(LCID locale
,DWORD flags
,
3093 LPWSTR date
, INT datelen
)
3095 unsigned short datearr
[] = {'1','9','9','4','-','1','-','1',0};
3097 FIXME("STUB (should call OLE_GetFormatW)\n");
3098 lstrcpynW(date
, datearr
, datelen
);
3099 return ( datelen
< 9) ? datelen
: 9;
3104 /**************************************************************************
3105 * EnumDateFormatsA (KERNEL32.198)
3107 BOOL WINAPI
EnumDateFormatsA(
3108 DATEFMT_ENUMPROCA lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3110 LCID Loc
= GetUserDefaultLCID();
3111 if(!lpDateFmtEnumProc
)
3113 SetLastError(ERROR_INVALID_PARAMETER
);
3120 case 0x00000407: /* (Loc,"de_DE") */
3124 case DATE_SHORTDATE
:
3125 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
3126 if(!(*lpDateFmtEnumProc
)("d.M.yyyy")) return TRUE
;
3127 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
3128 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3131 if(!(*lpDateFmtEnumProc
)("dddd,d. MMMM yyyy")) return TRUE
;
3132 if(!(*lpDateFmtEnumProc
)("d. MMMM yyyy")) return TRUE
;
3133 if(!(*lpDateFmtEnumProc
)("d. MMM yyyy")) return TRUE
;
3136 FIXME("Unknown date format (%ld)\n", dwFlags
);
3137 SetLastError(ERROR_INVALID_PARAMETER
);
3142 case 0x0000040c: /* (Loc,"fr_FR") */
3146 case DATE_SHORTDATE
:
3147 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3148 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
3149 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3150 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3153 if(!(*lpDateFmtEnumProc
)("dddd d MMMM yyyy")) return TRUE
;
3154 if(!(*lpDateFmtEnumProc
)("d MMM yy")) return TRUE
;
3155 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3158 FIXME("Unknown date format (%ld)\n", dwFlags
);
3159 SetLastError(ERROR_INVALID_PARAMETER
);
3164 case 0x00000c0c: /* (Loc,"fr_CA") */
3168 case DATE_SHORTDATE
:
3169 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3170 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3171 if(!(*lpDateFmtEnumProc
)("yy MM dd")) return TRUE
;
3172 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3175 if(!(*lpDateFmtEnumProc
)("d MMMM, yyyy")) return TRUE
;
3176 if(!(*lpDateFmtEnumProc
)("d MMM yyyy")) return TRUE
;
3179 FIXME("Unknown date format (%ld)\n", dwFlags
);
3180 SetLastError(ERROR_INVALID_PARAMETER
);
3185 case 0x00000809: /* (Loc,"en_UK") */
3189 case DATE_SHORTDATE
:
3190 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3191 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3192 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3193 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3196 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3197 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3200 FIXME("Unknown date format (%ld)\n", dwFlags
);
3201 SetLastError(ERROR_INVALID_PARAMETER
);
3206 case 0x00000c09: /* (Loc,"en_AU") */
3210 case DATE_SHORTDATE
:
3211 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3212 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3213 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3216 if(!(*lpDateFmtEnumProc
)("dddd,d MMMM yyyy")) return TRUE
;
3217 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3220 FIXME("Unknown date format (%ld)\n", dwFlags
);
3221 SetLastError(ERROR_INVALID_PARAMETER
);
3226 case 0x00001009: /* (Loc,"en_CA") */
3230 case DATE_SHORTDATE
:
3231 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3232 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3233 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3234 if(!(*lpDateFmtEnumProc
)("M/dd/yy")) return TRUE
;
3237 if(!(*lpDateFmtEnumProc
)("d-MMM-yy")) return TRUE
;
3238 if(!(*lpDateFmtEnumProc
)("MMMM d, yyyy")) return TRUE
;
3241 FIXME("Unknown date format (%ld)\n", dwFlags
);
3242 SetLastError(ERROR_INVALID_PARAMETER
);
3247 case 0x00001409: /* (Loc,"en_NZ") */
3251 case DATE_SHORTDATE
:
3252 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3253 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3254 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
3257 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3258 if(!(*lpDateFmtEnumProc
)("dddd, d MMMM yyyy")) return TRUE
;
3261 FIXME("Unknown date format (%ld)\n", dwFlags
);
3262 SetLastError(ERROR_INVALID_PARAMETER
);
3267 case 0x00001809: /* (Loc,"en_IE") */
3271 case DATE_SHORTDATE
:
3272 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3273 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3274 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3277 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3278 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3281 FIXME("Unknown date format (%ld)\n", dwFlags
);
3282 SetLastError(ERROR_INVALID_PARAMETER
);
3287 case 0x00001c09: /* (Loc,"en_ZA") */
3291 case DATE_SHORTDATE
:
3292 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3295 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3298 FIXME("Unknown date format (%ld)\n", dwFlags
);
3299 SetLastError(ERROR_INVALID_PARAMETER
);
3304 case 0x00002009: /* (Loc,"en_JM") */
3308 case DATE_SHORTDATE
:
3309 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3312 if(!(*lpDateFmtEnumProc
)("dddd,MMMM dd,yyyy")) return TRUE
;
3313 if(!(*lpDateFmtEnumProc
)("MMMM dd,yyyy")) return TRUE
;
3314 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM,yyyy")) return TRUE
;
3315 if(!(*lpDateFmtEnumProc
)("dd MMMM,yyyy")) return TRUE
;
3318 FIXME("Unknown date format (%ld)\n", dwFlags
);
3319 SetLastError(ERROR_INVALID_PARAMETER
);
3324 case 0x00002809: /* (Loc,"en_BZ") */
3325 case 0x00002c09: /* (Loc,"en_TT") */
3329 case DATE_SHORTDATE
:
3330 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3333 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM yyyy")) return TRUE
;
3336 FIXME("Unknown date format (%ld)\n", dwFlags
);
3337 SetLastError(ERROR_INVALID_PARAMETER
);
3342 default: /* default to US English "en_US" */
3346 case DATE_SHORTDATE
:
3347 if(!(*lpDateFmtEnumProc
)("M/d/yy")) return TRUE
;
3348 if(!(*lpDateFmtEnumProc
)("M/d/yyyy")) return TRUE
;
3349 if(!(*lpDateFmtEnumProc
)("MM/dd/yy")) return TRUE
;
3350 if(!(*lpDateFmtEnumProc
)("MM/dd/yyyy")) return TRUE
;
3351 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3352 if(!(*lpDateFmtEnumProc
)("dd-MMM-yy")) return TRUE
;
3355 if(!(*lpDateFmtEnumProc
)("dddd, MMMM dd, yyyy")) return TRUE
;
3356 if(!(*lpDateFmtEnumProc
)("MMMM dd, yyyy")) return TRUE
;
3357 if(!(*lpDateFmtEnumProc
)("dddd, dd MMMM, yyyy")) return TRUE
;
3358 if(!(*lpDateFmtEnumProc
)("dd MMMM, yyyy")) return TRUE
;
3361 FIXME("Unknown date format (%ld)\n", dwFlags
);
3362 SetLastError(ERROR_INVALID_PARAMETER
);
3369 /**************************************************************************
3370 * EnumDateFormatsW (KERNEL32.199)
3372 BOOL WINAPI
EnumDateFormatsW(
3373 DATEFMT_ENUMPROCW lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3375 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc
, Locale
, dwFlags
);
3376 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3380 /**************************************************************************
3381 * EnumTimeFormatsA (KERNEL32.210)
3383 BOOL WINAPI
EnumTimeFormatsA(
3384 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3386 LCID Loc
= GetUserDefaultLCID();
3387 if(!lpTimeFmtEnumProc
)
3389 SetLastError(ERROR_INVALID_PARAMETER
);
3394 FIXME("Unknown time format (%ld)\n", dwFlags
);
3399 case 0x00000407: /* (Loc,"de_DE") */
3401 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3402 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3403 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3404 if(!(*lpTimeFmtEnumProc
)("H.mm")) return TRUE
;
3405 if(!(*lpTimeFmtEnumProc
)("H.mm'Uhr'")) return TRUE
;
3409 case 0x0000040c: /* (Loc,"fr_FR") */
3410 case 0x00000c0c: /* (Loc,"fr_CA") */
3412 if(!(*lpTimeFmtEnumProc
)("H:mm")) return TRUE
;
3413 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3414 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3415 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3416 if(!(*lpTimeFmtEnumProc
)("HH'h'mm")) return TRUE
;
3420 case 0x00000809: /* (Loc,"en_UK") */
3421 case 0x00000c09: /* (Loc,"en_AU") */
3422 case 0x00001409: /* (Loc,"en_NZ") */
3423 case 0x00001809: /* (Loc,"en_IE") */
3425 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3426 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3427 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3431 case 0x00001c09: /* (Loc,"en_ZA") */
3432 case 0x00002809: /* (Loc,"en_BZ") */
3433 case 0x00002c09: /* (Loc,"en_TT") */
3435 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3436 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3440 default: /* default to US style "en_US" */
3442 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3443 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3444 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3445 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3451 /**************************************************************************
3452 * EnumTimeFormatsW (KERNEL32.211)
3454 BOOL WINAPI
EnumTimeFormatsW(
3455 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3457 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc
, Locale
, dwFlags
);
3458 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3462 /**************************************************************************
3463 * This function is used just locally !
3464 * Description: Inverts a string.
3466 static void OLE_InvertString(char* string
)
3468 char sTmpArray
[128];
3471 for (counter
= strlen(string
); counter
> 0; counter
--)
3473 memcpy(sTmpArray
+ i
, string
+ counter
-1, 1);
3476 memcpy(sTmpArray
+ i
, "\0", 1);
3477 strcpy(string
, sTmpArray
);
3480 /***************************************************************************************
3481 * This function is used just locally !
3482 * Description: Test if the given string (psNumber) is valid or not.
3483 * The valid characters are the following:
3484 * - Characters '0' through '9'.
3485 * - One decimal point (dot) if the number is a floating-point value.
3486 * - A minus sign in the first character position if the number is
3488 * If the function succeeds, psBefore/psAfter will point to the string
3489 * on the right/left of the decimal symbol. pbNegative indicates if the
3490 * number is negative.
3492 static INT
OLE_GetNumberComponents(char* pInput
, char* psBefore
, char* psAfter
, BOOL
* pbNegative
)
3494 char sNumberSet
[] = "0123456789";
3495 BOOL bInDecimal
= FALSE
;
3497 /* Test if we do have a minus sign */
3498 if ( *pInput
== '-' )
3501 pInput
++; /* Jump to the next character. */
3504 while(*pInput
!= '\0')
3506 /* Do we have a valid numeric character */
3507 if ( strchr(sNumberSet
, *pInput
) != NULL
)
3509 if (bInDecimal
== TRUE
)
3510 *psAfter
++ = *pInput
;
3512 *psBefore
++ = *pInput
;
3516 /* Is this a decimal point (dot) */
3517 if ( *pInput
== '.' )
3519 /* Is it the first time we find it */
3520 if ((bInDecimal
== FALSE
))
3523 return -1; /* ERROR: Invalid parameter */
3527 /* It's neither a numeric character, nor a decimal point.
3528 * Thus, return an error.
3536 /* Add an End of Line character to the output buffers */
3543 /**************************************************************************
3544 * This function is used just locally !
3545 * Description: A number could be formatted using different numbers
3546 * of "digits in group" (example: 4;3;2;0).
3547 * The first parameter of this function is an array
3548 * containing the rule to be used. It's format is the following:
3549 * |NDG|DG1|DG2|...|0|
3550 * where NDG is the number of used "digits in group" and DG1, DG2,
3551 * are the corresponding "digits in group".
3552 * Thus, this function returns the grouping value in the array
3553 * pointed by the second parameter.
3555 static INT
OLE_GetGrouping(char* sRule
, INT index
)
3557 char sData
[2], sRuleSize
[2];
3558 INT nData
, nRuleSize
;
3560 memcpy(sRuleSize
, sRule
, 1);
3561 memcpy(sRuleSize
+1, "\0", 1);
3562 nRuleSize
= atoi(sRuleSize
);
3564 if (index
> 0 && index
< nRuleSize
)
3566 memcpy(sData
, sRule
+index
, 1);
3567 memcpy(sData
+1, "\0", 1);
3568 nData
= atoi(sData
);
3573 memcpy(sData
, sRule
+nRuleSize
-1, 1);
3574 memcpy(sData
+1, "\0", 1);
3575 nData
= atoi(sData
);
3581 /**************************************************************************
3582 * GetNumberFormatA (KERNEL32.355)
3584 INT WINAPI
GetNumberFormatA(LCID locale
, DWORD dwflags
,
3585 LPCSTR lpvalue
, const NUMBERFMTA
* lpFormat
,
3586 LPSTR lpNumberStr
, int cchNumber
)
3588 char sNumberDigits
[3], sDecimalSymbol
[5], sDigitsInGroup
[11], sDigitGroupSymbol
[5], sILZero
[2];
3589 INT nNumberDigits
, nNumberDecimal
, i
, j
, nCounter
, nStep
, nRuleIndex
, nGrouping
, nDigits
, retVal
, nLZ
;
3590 char sNumber
[128], sDestination
[128], sDigitsAfterDecimal
[10], sDigitsBeforeDecimal
[128];
3591 char sRule
[10], sSemiColumn
[]=";", sBuffer
[5], sNegNumber
[2];
3592 char *pStr
= NULL
, *pTmpStr
= NULL
;
3593 LCID systemDefaultLCID
;
3594 BOOL bNegative
= FALSE
;
3603 strncpy(sNumber
, lpvalue
, 128);
3604 sNumber
[127] = '\0';
3606 /* Make sure we have a valid input string, get the number
3607 * of digits before and after the decimal symbol, and check
3608 * if this is a negative number.
3610 if ( OLE_GetNumberComponents(sNumber
, sDigitsBeforeDecimal
, sDigitsAfterDecimal
, &bNegative
) != -1)
3612 nNumberDecimal
= strlen(sDigitsBeforeDecimal
);
3613 nDigits
= strlen(sDigitsAfterDecimal
);
3617 SetLastError(ERROR_INVALID_PARAMETER
);
3621 /* Which source will we use to format the string */
3622 used_operation
= RETURN_ERROR
;
3623 if (lpFormat
!= NULL
)
3626 used_operation
= USE_PARAMETER
;
3630 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3631 used_operation
= USE_LOCALEINFO
;
3633 used_operation
= USE_SYSTEMDEFAULT
;
3636 /* Load the fields we need */
3637 switch(used_operation
)
3639 case USE_LOCALEINFO
:
3640 GetLocaleInfoA(locale
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3641 GetLocaleInfoA(locale
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3642 GetLocaleInfoA(locale
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3643 GetLocaleInfoA(locale
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3644 GetLocaleInfoA(locale
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3645 GetLocaleInfoA(locale
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3648 sprintf(sNumberDigits
, "%d",lpFormat
->NumDigits
);
3649 strcpy(sDecimalSymbol
, lpFormat
->lpDecimalSep
);
3650 sprintf(sDigitsInGroup
, "%d;0",lpFormat
->Grouping
);
3651 strcpy(sDigitGroupSymbol
, lpFormat
->lpThousandSep
);
3652 sprintf(sILZero
, "%d",lpFormat
->LeadingZero
);
3653 sprintf(sNegNumber
, "%d",lpFormat
->NegativeOrder
);
3655 case USE_SYSTEMDEFAULT
:
3656 systemDefaultLCID
= GetSystemDefaultLCID();
3657 GetLocaleInfoA(systemDefaultLCID
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3658 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3659 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3660 GetLocaleInfoA(systemDefaultLCID
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3661 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3662 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3665 SetLastError(ERROR_INVALID_PARAMETER
);
3669 nNumberDigits
= atoi(sNumberDigits
);
3671 /* Remove the ";" */
3674 for (nCounter
=0; nCounter
<strlen(sDigitsInGroup
); nCounter
++)
3676 if ( memcmp(sDigitsInGroup
+ nCounter
, sSemiColumn
, 1) != 0 )
3678 memcpy(sRule
+ j
, sDigitsInGroup
+ nCounter
, 1);
3683 sprintf(sBuffer
, "%d", i
);
3684 memcpy(sRule
, sBuffer
, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3685 memcpy(sRule
+ j
, "\0", 1);
3687 /* First, format the digits before the decimal. */
3688 if ((nNumberDecimal
>0) && (atoi(sDigitsBeforeDecimal
) != 0))
3690 /* Working on an inverted string is easier ! */
3691 OLE_InvertString(sDigitsBeforeDecimal
);
3693 nStep
= nCounter
= i
= j
= 0;
3695 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3697 /* Here, we will loop until we reach the end of the string.
3698 * An internal counter (j) is used in order to know when to
3699 * insert the "digit group symbol".
3701 while (nNumberDecimal
> 0)
3703 i
= nCounter
+ nStep
;
3704 memcpy(sDestination
+ i
, sDigitsBeforeDecimal
+ nCounter
, 1);
3710 if (nRuleIndex
< sRule
[0])
3712 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3713 memcpy(sDestination
+ i
+1, sDigitGroupSymbol
, strlen(sDigitGroupSymbol
));
3714 nStep
+= strlen(sDigitGroupSymbol
);
3720 memcpy(sDestination
+ i
+1, "\0", 1);
3721 /* Get the string in the right order ! */
3722 OLE_InvertString(sDestination
);
3726 nLZ
= atoi(sILZero
);
3729 /* Use 0.xxx instead of .xxx */
3730 memcpy(sDestination
, "0", 1);
3731 memcpy(sDestination
+1, "\0", 1);
3734 memcpy(sDestination
, "\0", 1);
3738 /* Second, format the digits after the decimal. */
3740 nCounter
= nNumberDigits
;
3741 if ( (nDigits
>0) && (pStr
= strstr (sNumber
, ".")) )
3743 i
= strlen(sNumber
) - strlen(pStr
) + 1;
3744 strncpy ( sDigitsAfterDecimal
, sNumber
+ i
, nNumberDigits
);
3745 j
= strlen(sDigitsAfterDecimal
);
3746 if (j
< nNumberDigits
)
3747 nCounter
= nNumberDigits
-j
;
3749 for (i
=0;i
<nCounter
;i
++)
3750 memcpy(sDigitsAfterDecimal
+i
+j
, "0", 1);
3751 memcpy(sDigitsAfterDecimal
+ nNumberDigits
, "\0", 1);
3753 i
= strlen(sDestination
);
3754 j
= strlen(sDigitsAfterDecimal
);
3755 /* Finally, construct the resulting formatted string. */
3757 for (nCounter
=0; nCounter
<i
; nCounter
++)
3758 memcpy(sNumber
+ nCounter
, sDestination
+ nCounter
, 1);
3760 memcpy(sNumber
+ nCounter
, sDecimalSymbol
, strlen(sDecimalSymbol
));
3763 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), sDigitsAfterDecimal
+ i
, 1);
3764 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), "\0", 1);
3766 /* Is it a negative number */
3767 if (bNegative
== TRUE
)
3769 i
= atoi(sNegNumber
);
3770 pStr
= sDestination
;
3776 while (*sNumber
!= '\0')
3777 *pStr
++ = *pTmpStr
++;
3782 while (*pTmpStr
!= '\0')
3783 *pStr
++ = *pTmpStr
++;
3788 while (*pTmpStr
!= '\0')
3789 *pStr
++ = *pTmpStr
++;
3792 while (*pTmpStr
!= '\0')
3793 *pStr
++ = *pTmpStr
++;
3797 while (*pTmpStr
!= '\0')
3798 *pStr
++ = *pTmpStr
++;
3803 while (*pTmpStr
!= '\0')
3804 *pStr
++ = *pTmpStr
++;
3809 strcpy(sDestination
, sNumber
);
3811 /* If cchNumber is zero, then returns the number of bytes or characters
3812 * required to hold the formatted number string
3815 retVal
= strlen(sDestination
) + 1;
3818 strncpy (lpNumberStr
, sDestination
, cchNumber
-1);
3819 *(lpNumberStr
+cchNumber
-1) = '\0'; /* ensure we got a NULL at the end */
3820 retVal
= strlen(lpNumberStr
);
3826 /**************************************************************************
3827 * GetNumberFormatW (KERNEL32.xxx)
3829 INT WINAPI
GetNumberFormatW(LCID locale
, DWORD dwflags
,
3830 LPCWSTR lpvalue
, const NUMBERFMTW
* lpFormat
,
3831 LPWSTR lpNumberStr
, int cchNumber
)
3833 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue
));
3835 lstrcpynW( lpNumberStr
, lpvalue
, cchNumber
);
3836 return cchNumber
? strlenW( lpNumberStr
) : 0;
3839 /**************************************************************************
3840 * GetCurrencyFormatA (KERNEL32.302)
3842 INT WINAPI
GetCurrencyFormatA(LCID locale
, DWORD dwflags
,
3843 LPCSTR lpvalue
, const CURRENCYFMTA
* lpFormat
,
3844 LPSTR lpCurrencyStr
, int cchCurrency
)
3846 UINT nPosOrder
, nNegOrder
;
3848 char sDestination
[128], sNegOrder
[8], sPosOrder
[8], sCurrencySymbol
[8];
3849 char *pDestination
= sDestination
;
3850 char sNumberFormated
[128];
3851 char *pNumberFormated
= sNumberFormated
;
3852 LCID systemDefaultLCID
;
3853 BOOL bIsPositive
= FALSE
, bValidFormat
= FALSE
;
3862 NUMBERFMTA numberFmt
;
3864 /* Which source will we use to format the string */
3865 used_operation
= RETURN_ERROR
;
3866 if (lpFormat
!= NULL
)
3869 used_operation
= USE_PARAMETER
;
3873 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3874 used_operation
= USE_LOCALEINFO
;
3876 used_operation
= USE_SYSTEMDEFAULT
;
3879 /* Load the fields we need */
3880 switch(used_operation
)
3882 case USE_LOCALEINFO
:
3883 /* Specific to CURRENCYFMTA*/
3884 GetLocaleInfoA(locale
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3885 GetLocaleInfoA(locale
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3886 GetLocaleInfoA(locale
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3888 nPosOrder
= atoi(sPosOrder
);
3889 nNegOrder
= atoi(sNegOrder
);
3892 /* Specific to CURRENCYFMTA*/
3893 nNegOrder
= lpFormat
->NegativeOrder
;
3894 nPosOrder
= lpFormat
->PositiveOrder
;
3895 strcpy(sCurrencySymbol
, lpFormat
->lpCurrencySymbol
);
3897 case USE_SYSTEMDEFAULT
:
3898 systemDefaultLCID
= GetSystemDefaultLCID();
3899 /* Specific to CURRENCYFMTA*/
3900 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3901 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3902 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3904 nPosOrder
= atoi(sPosOrder
);
3905 nNegOrder
= atoi(sNegOrder
);
3908 SetLastError(ERROR_INVALID_PARAMETER
);
3912 /* Construct a temporary number format structure */
3913 if (lpFormat
!= NULL
)
3915 numberFmt
.NumDigits
= lpFormat
->NumDigits
;
3916 numberFmt
.LeadingZero
= lpFormat
->LeadingZero
;
3917 numberFmt
.Grouping
= lpFormat
->Grouping
;
3918 numberFmt
.NegativeOrder
= 0;
3919 numberFmt
.lpDecimalSep
= lpFormat
->lpDecimalSep
;
3920 numberFmt
.lpThousandSep
= lpFormat
->lpThousandSep
;
3921 bValidFormat
= TRUE
;
3924 /* Make a call to GetNumberFormatA() */
3925 if (*lpvalue
== '-')
3927 bIsPositive
= FALSE
;
3928 retVal
= GetNumberFormatA(locale
,0,lpvalue
+1,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3933 retVal
= GetNumberFormatA(locale
,0,lpvalue
,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3939 /* construct the formatted string */
3944 case 0: /* Prefix, no separation */
3945 strcpy (pDestination
, sCurrencySymbol
);
3946 strcat (pDestination
, pNumberFormated
);
3948 case 1: /* Suffix, no separation */
3949 strcpy (pDestination
, pNumberFormated
);
3950 strcat (pDestination
, sCurrencySymbol
);
3952 case 2: /* Prefix, 1 char separation */
3953 strcpy (pDestination
, sCurrencySymbol
);
3954 strcat (pDestination
, " ");
3955 strcat (pDestination
, pNumberFormated
);
3957 case 3: /* Suffix, 1 char separation */
3958 strcpy (pDestination
, pNumberFormated
);
3959 strcat (pDestination
, " ");
3960 strcat (pDestination
, sCurrencySymbol
);
3963 SetLastError(ERROR_INVALID_PARAMETER
);
3967 else /* negative number */
3971 case 0: /* format: ($1.1) */
3972 strcpy (pDestination
, "(");
3973 strcat (pDestination
, sCurrencySymbol
);
3974 strcat (pDestination
, pNumberFormated
);
3975 strcat (pDestination
, ")");
3977 case 1: /* format: -$1.1 */
3978 strcpy (pDestination
, "-");
3979 strcat (pDestination
, sCurrencySymbol
);
3980 strcat (pDestination
, pNumberFormated
);
3982 case 2: /* format: $-1.1 */
3983 strcpy (pDestination
, sCurrencySymbol
);
3984 strcat (pDestination
, "-");
3985 strcat (pDestination
, pNumberFormated
);
3987 case 3: /* format: $1.1- */
3988 strcpy (pDestination
, sCurrencySymbol
);
3989 strcat (pDestination
, pNumberFormated
);
3990 strcat (pDestination
, "-");
3992 case 4: /* format: (1.1$) */
3993 strcpy (pDestination
, "(");
3994 strcat (pDestination
, pNumberFormated
);
3995 strcat (pDestination
, sCurrencySymbol
);
3996 strcat (pDestination
, ")");
3998 case 5: /* format: -1.1$ */
3999 strcpy (pDestination
, "-");
4000 strcat (pDestination
, pNumberFormated
);
4001 strcat (pDestination
, sCurrencySymbol
);
4003 case 6: /* format: 1.1-$ */
4004 strcpy (pDestination
, pNumberFormated
);
4005 strcat (pDestination
, "-");
4006 strcat (pDestination
, sCurrencySymbol
);
4008 case 7: /* format: 1.1$- */
4009 strcpy (pDestination
, pNumberFormated
);
4010 strcat (pDestination
, sCurrencySymbol
);
4011 strcat (pDestination
, "-");
4013 case 8: /* format: -1.1 $ */
4014 strcpy (pDestination
, "-");
4015 strcat (pDestination
, pNumberFormated
);
4016 strcat (pDestination
, " ");
4017 strcat (pDestination
, sCurrencySymbol
);
4019 case 9: /* format: -$ 1.1 */
4020 strcpy (pDestination
, "-");
4021 strcat (pDestination
, sCurrencySymbol
);
4022 strcat (pDestination
, " ");
4023 strcat (pDestination
, pNumberFormated
);
4025 case 10: /* format: 1.1 $- */
4026 strcpy (pDestination
, pNumberFormated
);
4027 strcat (pDestination
, " ");
4028 strcat (pDestination
, sCurrencySymbol
);
4029 strcat (pDestination
, "-");
4031 case 11: /* format: $ 1.1- */
4032 strcpy (pDestination
, sCurrencySymbol
);
4033 strcat (pDestination
, " ");
4034 strcat (pDestination
, pNumberFormated
);
4035 strcat (pDestination
, "-");
4037 case 12: /* format: $ -1.1 */
4038 strcpy (pDestination
, sCurrencySymbol
);
4039 strcat (pDestination
, " ");
4040 strcat (pDestination
, "-");
4041 strcat (pDestination
, pNumberFormated
);
4043 case 13: /* format: 1.1- $ */
4044 strcpy (pDestination
, pNumberFormated
);
4045 strcat (pDestination
, "-");
4046 strcat (pDestination
, " ");
4047 strcat (pDestination
, sCurrencySymbol
);
4049 case 14: /* format: ($ 1.1) */
4050 strcpy (pDestination
, "(");
4051 strcat (pDestination
, sCurrencySymbol
);
4052 strcat (pDestination
, " ");
4053 strcat (pDestination
, pNumberFormated
);
4054 strcat (pDestination
, ")");
4056 case 15: /* format: (1.1 $) */
4057 strcpy (pDestination
, "(");
4058 strcat (pDestination
, pNumberFormated
);
4059 strcat (pDestination
, " ");
4060 strcat (pDestination
, sCurrencySymbol
);
4061 strcat (pDestination
, ")");
4064 SetLastError(ERROR_INVALID_PARAMETER
);
4069 if (cchCurrency
== 0)
4070 return strlen(pDestination
) + 1;
4074 strncpy (lpCurrencyStr
, pDestination
, cchCurrency
-1);
4075 *(lpCurrencyStr
+cchCurrency
-1) = '\0'; /* ensure we got a NULL at the end */
4076 return strlen(lpCurrencyStr
);
4080 /**************************************************************************
4081 * GetCurrencyFormatW (KERNEL32.303)
4083 INT WINAPI
GetCurrencyFormatW(LCID locale
, DWORD dwflags
,
4084 LPCWSTR lpvalue
, const CURRENCYFMTW
* lpFormat
,
4085 LPWSTR lpCurrencyStr
, int cchCurrency
)
4087 FIXME("This API function is NOT implemented !\n");
4091 /******************************************************************************
4092 * OLE2NLS_CheckLocale [intern]
4094 static LCID
OLE2NLS_CheckLocale (LCID locale
)
4097 { locale
= LOCALE_SYSTEM_DEFAULT
;
4100 if (locale
== LOCALE_SYSTEM_DEFAULT
)
4101 { return GetSystemDefaultLCID();
4103 else if (locale
== LOCALE_USER_DEFAULT
)
4104 { return GetUserDefaultLCID();
4110 /******************************************************************************
4111 * GetTimeFormatA [KERNEL32.422]
4112 * Makes an ASCII string of the time
4114 * Formats date according to format, or locale default if format is
4115 * NULL. The format consists of literal characters and fields as follows:
4117 * h hours with no leading zero (12-hour)
4118 * hh hours with full two digits
4119 * H hours with no leading zero (24-hour)
4120 * HH hours with full two digits
4121 * m minutes with no leading zero
4122 * mm minutes with full two digits
4123 * s seconds with no leading zero
4124 * ss seconds with full two digits
4125 * t time marker (A or P)
4126 * tt time marker (AM, PM)
4130 GetTimeFormatA(LCID locale
, /* in */
4131 DWORD flags
, /* in */
4132 LPSYSTEMTIME xtime
, /* in */
4133 LPCSTR format
, /* in */
4134 LPSTR timestr
, /* out */
4135 INT timelen
/* in */)
4136 { char format_buf
[40];
4139 LPSYSTEMTIME thistime
;
4141 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4144 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,xtime
,format
,timestr
,timelen
);
4146 thislocale
= OLE2NLS_CheckLocale ( locale
);
4148 if ( flags
& (TIME_NOTIMEMARKER
| TIME_FORCE24HOURFORMAT
))
4149 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4152 flags
&= (TIME_NOSECONDS
| TIME_NOMINUTESORSECONDS
); /* mask for OLE_GetFormatA*/
4155 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4156 { thislocale
= GetSystemDefaultLCID();
4158 GetLocaleInfoA(thislocale
, thisflags
, format_buf
, sizeof(format_buf
));
4159 thisformat
= format_buf
;
4162 { thisformat
= format
;
4165 if (xtime
== NULL
) /* NULL means use the current local time*/
4171 /* Check that hour,min and sec is in range */
4173 ret
= OLE_GetFormatA(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4179 /******************************************************************************
4180 * GetTimeFormatW [KERNEL32.423]
4181 * Makes a Unicode string of the time
4184 GetTimeFormatW(LCID locale
, /* in */
4185 DWORD flags
, /* in */
4186 LPSYSTEMTIME xtime
, /* in */
4187 LPCWSTR format
, /* in */
4188 LPWSTR timestr
, /* out */
4189 INT timelen
/* in */)
4190 { WCHAR format_buf
[40];
4193 LPSYSTEMTIME thistime
;
4195 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4198 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,
4199 xtime
,debugstr_w(format
),timestr
,timelen
);
4201 thislocale
= OLE2NLS_CheckLocale ( locale
);
4203 if ( flags
& (TIME_NOTIMEMARKER
| TIME_FORCE24HOURFORMAT
))
4204 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4207 flags
&= (TIME_NOSECONDS
| TIME_NOMINUTESORSECONDS
); /* mask for OLE_GetFormatA*/
4210 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4211 { thislocale
= GetSystemDefaultLCID();
4213 GetLocaleInfoW(thislocale
, thisflags
, format_buf
, 40);
4214 thisformat
= format_buf
;
4217 { thisformat
= format
;
4220 if (xtime
== NULL
) /* NULL means use the current local time*/
4228 ret
= OLE_GetFormatW(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4233 /******************************************************************************
4234 * EnumCalendarInfoA [KERNEL32.196]
4236 BOOL WINAPI
EnumCalendarInfoA(
4237 CALINFO_ENUMPROCA calinfoproc
,LCID locale
,CALID calendar
,CALTYPE caltype
4239 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc
,locale
,calendar
,caltype
);