2 * National Language Support library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
19 #include "wine/unicode.h"
26 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(string
);
30 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
31 * MUST contain all #defines from winnls.h
32 * last entry has NULL name, 0 id.
34 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
35 static const struct tagLOCALE_NAME2ID
{
39 LOCALE_ENTRY(ILANGUAGE
),
40 LOCALE_ENTRY(SLANGUAGE
),
41 LOCALE_ENTRY(SENGLANGUAGE
),
42 LOCALE_ENTRY(SABBREVLANGNAME
),
43 LOCALE_ENTRY(SNATIVELANGNAME
),
44 LOCALE_ENTRY(ICOUNTRY
),
45 LOCALE_ENTRY(SCOUNTRY
),
46 LOCALE_ENTRY(SENGCOUNTRY
),
47 LOCALE_ENTRY(SABBREVCTRYNAME
),
48 LOCALE_ENTRY(SNATIVECTRYNAME
),
49 LOCALE_ENTRY(IDEFAULTLANGUAGE
),
50 LOCALE_ENTRY(IDEFAULTCOUNTRY
),
51 LOCALE_ENTRY(IDEFAULTCODEPAGE
),
52 LOCALE_ENTRY(IDEFAULTANSICODEPAGE
),
53 LOCALE_ENTRY(IDEFAULTMACCODEPAGE
),
55 LOCALE_ENTRY(IMEASURE
),
56 LOCALE_ENTRY(SDECIMAL
),
57 LOCALE_ENTRY(STHOUSAND
),
58 LOCALE_ENTRY(SGROUPING
),
59 LOCALE_ENTRY(IDIGITS
),
61 LOCALE_ENTRY(INEGNUMBER
),
62 LOCALE_ENTRY(SNATIVEDIGITS
),
63 LOCALE_ENTRY(SCURRENCY
),
64 LOCALE_ENTRY(SINTLSYMBOL
),
65 LOCALE_ENTRY(SMONDECIMALSEP
),
66 LOCALE_ENTRY(SMONTHOUSANDSEP
),
67 LOCALE_ENTRY(SMONGROUPING
),
68 LOCALE_ENTRY(ICURRDIGITS
),
69 LOCALE_ENTRY(IINTLCURRDIGITS
),
70 LOCALE_ENTRY(ICURRENCY
),
71 LOCALE_ENTRY(INEGCURR
),
74 LOCALE_ENTRY(SSHORTDATE
),
75 LOCALE_ENTRY(SLONGDATE
),
76 LOCALE_ENTRY(STIMEFORMAT
),
80 LOCALE_ENTRY(ITIMEMARKPOSN
),
81 LOCALE_ENTRY(ICENTURY
),
82 LOCALE_ENTRY(ITLZERO
),
83 LOCALE_ENTRY(IDAYLZERO
),
84 LOCALE_ENTRY(IMONLZERO
),
87 LOCALE_ENTRY(ICALENDARTYPE
),
88 LOCALE_ENTRY(IOPTIONALCALENDAR
),
89 LOCALE_ENTRY(IFIRSTDAYOFWEEK
),
90 LOCALE_ENTRY(IFIRSTWEEKOFYEAR
),
91 LOCALE_ENTRY(SDAYNAME1
),
92 LOCALE_ENTRY(SDAYNAME2
),
93 LOCALE_ENTRY(SDAYNAME3
),
94 LOCALE_ENTRY(SDAYNAME4
),
95 LOCALE_ENTRY(SDAYNAME5
),
96 LOCALE_ENTRY(SDAYNAME6
),
97 LOCALE_ENTRY(SDAYNAME7
),
98 LOCALE_ENTRY(SABBREVDAYNAME1
),
99 LOCALE_ENTRY(SABBREVDAYNAME2
),
100 LOCALE_ENTRY(SABBREVDAYNAME3
),
101 LOCALE_ENTRY(SABBREVDAYNAME4
),
102 LOCALE_ENTRY(SABBREVDAYNAME5
),
103 LOCALE_ENTRY(SABBREVDAYNAME6
),
104 LOCALE_ENTRY(SABBREVDAYNAME7
),
105 LOCALE_ENTRY(SMONTHNAME1
),
106 LOCALE_ENTRY(SMONTHNAME2
),
107 LOCALE_ENTRY(SMONTHNAME3
),
108 LOCALE_ENTRY(SMONTHNAME4
),
109 LOCALE_ENTRY(SMONTHNAME5
),
110 LOCALE_ENTRY(SMONTHNAME6
),
111 LOCALE_ENTRY(SMONTHNAME7
),
112 LOCALE_ENTRY(SMONTHNAME8
),
113 LOCALE_ENTRY(SMONTHNAME9
),
114 LOCALE_ENTRY(SMONTHNAME10
),
115 LOCALE_ENTRY(SMONTHNAME11
),
116 LOCALE_ENTRY(SMONTHNAME12
),
117 LOCALE_ENTRY(SMONTHNAME13
),
118 LOCALE_ENTRY(SABBREVMONTHNAME1
),
119 LOCALE_ENTRY(SABBREVMONTHNAME2
),
120 LOCALE_ENTRY(SABBREVMONTHNAME3
),
121 LOCALE_ENTRY(SABBREVMONTHNAME4
),
122 LOCALE_ENTRY(SABBREVMONTHNAME5
),
123 LOCALE_ENTRY(SABBREVMONTHNAME6
),
124 LOCALE_ENTRY(SABBREVMONTHNAME7
),
125 LOCALE_ENTRY(SABBREVMONTHNAME8
),
126 LOCALE_ENTRY(SABBREVMONTHNAME9
),
127 LOCALE_ENTRY(SABBREVMONTHNAME10
),
128 LOCALE_ENTRY(SABBREVMONTHNAME11
),
129 LOCALE_ENTRY(SABBREVMONTHNAME12
),
130 LOCALE_ENTRY(SABBREVMONTHNAME13
),
131 LOCALE_ENTRY(SPOSITIVESIGN
),
132 LOCALE_ENTRY(SNEGATIVESIGN
),
133 LOCALE_ENTRY(IPOSSIGNPOSN
),
134 LOCALE_ENTRY(INEGSIGNPOSN
),
135 LOCALE_ENTRY(IPOSSYMPRECEDES
),
136 LOCALE_ENTRY(IPOSSEPBYSPACE
),
137 LOCALE_ENTRY(INEGSYMPRECEDES
),
138 LOCALE_ENTRY(INEGSEPBYSPACE
),
139 LOCALE_ENTRY(FONTSIGNATURE
),
140 LOCALE_ENTRY(SISO639LANGNAME
),
141 LOCALE_ENTRY(SISO3166CTRYNAME
),
145 static char *GetLocaleSubkeyName( DWORD lctype
);
147 /***********************************************************************
148 * GetUserDefaultLCID (KERNEL32.@)
149 * GetUserDefaultLCID (OLE2NLS.1)
151 LCID WINAPI
GetUserDefaultLCID(void)
153 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT
);
156 /***********************************************************************
157 * GetSystemDefaultLCID (KERNEL32.@)
158 * GetSystemDefaultLCID (OLE2NLS.2)
160 LCID WINAPI
GetSystemDefaultLCID(void)
162 return GetUserDefaultLCID();
165 #define NLS_MAX_LANGUAGES 20
169 LANGID found_lang_id
[NLS_MAX_LANGUAGES
];
170 char found_language
[NLS_MAX_LANGUAGES
][3];
171 char found_country
[NLS_MAX_LANGUAGES
][3];
175 static BOOL CALLBACK
NLS_FindLanguageID_ProcA(HMODULE hModule
, LPCSTR type
,
176 LPCSTR name
, WORD LangID
, LONG lParam
)
178 LANG_FIND_DATA
*l_data
= (LANG_FIND_DATA
*)lParam
;
179 LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
180 char buf_language
[128];
181 char buf_country
[128];
182 char buf_en_language
[128];
184 TRACE("%04X\n", (UINT
)LangID
);
185 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
186 return TRUE
; /* continue search */
191 GetLocaleInfoA(lcid
, LOCALE_SISO639LANGNAME
|LOCALE_NOUSEROVERRIDE
,
192 buf_language
, sizeof(buf_language
));
193 TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language
);
195 GetLocaleInfoA(lcid
, LOCALE_SISO3166CTRYNAME
|LOCALE_NOUSEROVERRIDE
,
196 buf_country
, sizeof(buf_country
));
197 TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country
);
199 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_language
))
201 if(l_data
->country
&& strlen(l_data
->country
) > 0)
203 if(!strcasecmp(l_data
->country
, buf_country
))
205 l_data
->found_lang_id
[0] = LangID
;
207 TRACE("Found lang_id %04X for %s_%s\n", LangID
, l_data
->lang
, l_data
->country
);
208 return FALSE
; /* stop enumeration */
211 else /* l_data->country not specified */
213 if(l_data
->n_found
< NLS_MAX_LANGUAGES
)
215 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
216 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
217 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
219 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
220 return TRUE
; /* continue search */
225 /* Just in case, check LOCALE_SENGLANGUAGE too,
226 * in hope that possible alias name might have that value.
228 buf_en_language
[0] = 0;
229 GetLocaleInfoA(lcid
, LOCALE_SENGLANGUAGE
|LOCALE_NOUSEROVERRIDE
,
230 buf_en_language
, sizeof(buf_en_language
));
231 TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language
);
233 if(l_data
->lang
&& strlen(l_data
->lang
) > 0 && !strcasecmp(l_data
->lang
, buf_en_language
))
235 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
236 strncpy(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
237 strncpy(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
239 TRACE("Found lang_id %04X for %s\n", LangID
, l_data
->lang
);
242 return TRUE
; /* continue search */
245 /***********************************************************************
249 * Lang: a string whose two first chars are the iso name of a language.
250 * Country: a string whose two first chars are the iso name of country
251 * Charset: a string defining the chossen charset encoding
252 * Dialect: a string defining a variation of the locale
254 * all those values are from the standardized format of locale
255 * name in unix which is: Lang[_Country][.Charset][@Dialect]
258 * the numeric code of the language used by Windows
260 * FIXME: Charset and Dialect are not handled
262 static LANGID
NLS_GetLanguageID(LPCSTR Lang
, LPCSTR Country
, LPCSTR Charset
, LPCSTR Dialect
)
264 LANG_FIND_DATA l_data
;
265 char lang_string
[256];
269 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
273 memset(&l_data
, 0, sizeof(LANG_FIND_DATA
));
274 strncpy(l_data
.lang
, Lang
, sizeof(l_data
.lang
));
276 if(Country
&& strlen(Country
) > 0)
277 strncpy(l_data
.country
, Country
, sizeof(l_data
.country
));
279 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
280 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
282 strcpy(lang_string
, l_data
.lang
);
283 if(l_data
.country
&& strlen(l_data
.country
) > 0)
285 strcat(lang_string
, "_");
286 strcat(lang_string
, l_data
.country
);
291 if(l_data
.country
&& strlen(l_data
.country
) > 0)
293 MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string
);
294 l_data
.country
[0] = 0;
295 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
296 (LPCSTR
)LOCALE_ILANGUAGE
, NLS_FindLanguageID_ProcA
, (LONG
)&l_data
);
300 /* Re-evaluate lang_string */
301 strcpy(lang_string
, l_data
.lang
);
302 if(l_data
.country
&& strlen(l_data
.country
) > 0)
304 strcat(lang_string
, "_");
305 strcat(lang_string
, l_data
.country
);
310 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string
);
311 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
315 if(l_data
.n_found
== 1)
316 TRACE("For language '%s' lang_id %04X was found\n", lang_string
, l_data
.found_lang_id
[0]);
317 else /* l_data->n_found > 1 */
320 MESSAGE("For language '%s' several language ids were found:\n", lang_string
);
321 for(i
= 0; i
< l_data
.n_found
; i
++)
322 MESSAGE("%s_%s - %04X; ", l_data
.found_language
[i
], l_data
.found_country
[i
], l_data
.found_lang_id
[i
]);
324 MESSAGE("\nInstead of using first in the list, suggest to define\n"
325 "your LANG environment variable like this: LANG=%s_%s\n",
326 l_data
.found_language
[0], l_data
.found_country
[0]);
330 TRACE("Returning %04X\n", l_data
.found_lang_id
[0]);
331 return l_data
.found_lang_id
[0];
334 /***********************************************************************
335 * GetUserDefaultLangID (KERNEL32.@)
336 * GetUserDefaultLangID (OLE2NLS.3)
338 LANGID WINAPI
GetUserDefaultLangID(void)
340 /* caching result, if defined from environment, which should (?) not change during a WINE session */
341 static LANGID userLCID
= 0;
346 char *lang
,*country
,*charset
,*dialect
,*next
;
348 if (GetEnvironmentVariableA( "LANGUAGE", buf
, sizeof(buf
) )) goto ok
;
349 if (GetEnvironmentVariableA( "LANG", buf
, sizeof(buf
) )) goto ok
;
350 if (GetEnvironmentVariableA( "LC_ALL", buf
, sizeof(buf
) )) goto ok
;
351 if (GetEnvironmentVariableA( "LC_MESSAGES", buf
, sizeof(buf
) )) goto ok
;
352 if (GetEnvironmentVariableA( "LC_CTYPE", buf
, sizeof(buf
) )) goto ok
;
354 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
357 if (!strcmp(buf
,"POSIX") || !strcmp(buf
,"C"))
358 return userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
363 next
=strchr(lang
,':'); if (next
) *next
++='\0';
364 dialect
=strchr(lang
,'@'); if (dialect
) *dialect
++='\0';
365 charset
=strchr(lang
,'.'); if (charset
) *charset
++='\0';
366 country
=strchr(lang
,'_'); if (country
) *country
++='\0';
368 userLCID
= NLS_GetLanguageID(lang
, country
, charset
, dialect
);
371 } while (lang
&& !userLCID
);
375 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
377 userLCID
= MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
383 /***********************************************************************
384 * GetSystemDefaultLangID (KERNEL32.@)
385 * GetSystemDefaultLangID (OLE2NLS.4)
387 LANGID WINAPI
GetSystemDefaultLangID(void)
389 return GetUserDefaultLangID();
392 /******************************************************************************
393 * ConvertDefaultLocale (KERNEL32.@)
395 LCID WINAPI
ConvertDefaultLocale (LCID lcid
)
397 { case LOCALE_SYSTEM_DEFAULT
:
398 return GetSystemDefaultLCID();
399 case LOCALE_USER_DEFAULT
:
400 return GetUserDefaultLCID();
402 return MAKELCID (LANG_NEUTRAL
, SUBLANG_NEUTRAL
);
404 return MAKELANGID( PRIMARYLANGID(lcid
), SUBLANG_NEUTRAL
);
407 /* Enhanced version of LoadStringW.
408 * It takes LanguageId to find and load language dependant resources.
409 * Resource is copied as is: "binary" strings are not truncated.
410 * Return: length of resource + 1 to distinguish absent resources
411 * from the resources with zero length.
413 static INT
NLS_LoadStringExW(HMODULE hModule
, LANGID lang_id
, UINT res_id
, LPWSTR buffer
, INT buflen
)
421 /* Replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
422 if(SUBLANGID(lang_id
) == SUBLANG_NEUTRAL
)
423 lang_id
= MAKELANGID(PRIMARYLANGID(lang_id
), SUBLANG_DEFAULT
);
425 hrsrc
= FindResourceExW(hModule
, RT_STRINGW
, (LPCWSTR
)((res_id
>> 4) + 1), lang_id
);
428 hmem
= LoadResource(hModule
, hrsrc
);
431 p
= LockResource(hmem
);
432 string_num
= res_id
& 0x000f;
433 for(i
= 0; i
< string_num
; i
++)
436 TRACE("strlen = %d\n", (int)*p
);
438 if (buffer
== NULL
) return *p
;
439 i
= min(buflen
- 1, *p
);
441 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
442 buffer
[i
] = (WCHAR
) 0;
445 buffer
[0] = (WCHAR
) 0;
449 TRACE("%s loaded!\n", debugstr_w(buffer
));
453 /******************************************************************************
454 * GetLocaleInfoA (KERNEL32.@)
457 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
459 * MS online documentation states that the string returned is NULL terminated
460 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
461 * terminated string".
463 INT WINAPI
GetLocaleInfoA(LCID lcid
,LCTYPE LCType
,LPSTR buf
,INT len
)
465 LPCSTR retString
= NULL
;
469 DWORD dwBufferSize
=128;
472 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid
,LCType
,buf
,len
);
474 if (len
&& (! buf
) ) {
475 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
479 if (lcid
== LOCALE_NEUTRAL
|| lcid
== LANG_SYSTEM_DEFAULT
)
481 lcid
= GetSystemDefaultLCID();
483 else if (lcid
== LANG_USER_DEFAULT
) /*0x800*/
485 lcid
= GetUserDefaultLCID();
488 /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
489 from the registry. Instead, use system default values. */
490 NoUserOverride
= (LCType
& LOCALE_NOUSEROVERRIDE
) != 0;
492 LCType
&= ~(LOCALE_NOUSEROVERRIDE
|LOCALE_USE_CP_ACP
);
494 /* First, check if it's in the registry. */
495 /* All user customized values are stored in the registry by SetLocaleInfo */
496 if ( !NoUserOverride
&& (pacKey
= GetLocaleSubkeyName(LCType
)) )
501 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
503 if ( RegOpenKeyExA( HKEY_CURRENT_USER
, acRealKey
,
504 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
506 if ( RegQueryValueExA( hKey
, NULL
, NULL
, NULL
, (LPBYTE
)acBuffer
,
507 &dwBufferSize
) == ERROR_SUCCESS
)
509 retString
= acBuffer
;
516 /* If not in the registry, get it from the NLS entries. */
521 /* check if language is registered in the kernel32 resources */
522 if((res_size
= NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid
),
523 LCType
, wcBuffer
, sizeof(wcBuffer
)/sizeof(wcBuffer
[0])))) {
524 WideCharToMultiByte(CP_ACP
, 0, wcBuffer
, res_size
, acBuffer
, dwBufferSize
, NULL
, NULL
);
525 retString
= acBuffer
;
530 /* if not found report a most descriptive error */
533 /* If we are through all of this, retLen should not be zero anymore.
534 If it is, the value is not supported */
536 while (locale_name2id
[i
].name
!=NULL
) {
537 if (LCType
== locale_name2id
[i
].id
) {
538 retString
= locale_name2id
[i
].name
;
544 FIXME("Unkown LC type %lX\n", LCType
);
546 FIXME("'%s' is not defined for your language (%04X).\n"
547 "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
548 "and submit patch for inclusion into the next Wine release.\n",
549 retString
, LOWORD(lcid
));
550 SetLastError(ERROR_INVALID_PARAMETER
);
554 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
555 if (LCType
== LOCALE_FONTSIGNATURE
) {
557 len
= (len
< sizeof(FONTSIGNATURE
)) ? len
: sizeof(FONTSIGNATURE
);
558 memcpy(buf
, retString
, len
);
561 return sizeof(FONTSIGNATURE
);
563 /* if len=0 return only the length, don't touch the buffer*/
565 lstrcpynA(buf
,retString
,len
);
566 return strlen(buf
) + 1;
568 return strlen(retString
)+1;
571 /******************************************************************************
572 * GetLocaleInfoW (KERNEL32.@)
575 * MS documentation states that len "specifies the size, in bytes (ANSI version)
576 * or characters (Unicode version), of" wbuf. Thus the number returned is
577 * the same between GetLocaleInfoW and GetLocaleInfoA.
579 INT WINAPI
GetLocaleInfoW(LCID lcid
,LCTYPE LCType
,LPWSTR wbuf
,INT len
)
583 if (len
&& (! wbuf
) )
584 { SetLastError(ERROR_INSUFFICIENT_BUFFER
);
588 abuf
= (LPSTR
)HeapAlloc(GetProcessHeap(),0,len
);
589 wlen
= GetLocaleInfoA(lcid
, LCType
, abuf
, len
);
591 if (wlen
&& len
) /* if len=0 return only the length*/
592 MultiByteToWideChar( CP_ACP
, 0, abuf
, -1, wbuf
, len
);
594 HeapFree(GetProcessHeap(),0,abuf
);
598 /******************************************************************************
600 * GetLocaleSubkeyName [helper function]
602 * - For use with the registry.
603 * - Gets the registry subkey name for a given lctype.
605 static char *GetLocaleSubkeyName( DWORD lctype
)
611 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
612 * the values are stored in the registry, confirmed under Windows,
613 * for the ones that actually assign pacKey. Cases that aren't finished
614 * have not been confirmed, so that must be done before they can be
617 case LOCALE_SDATE
: /* The date separator. */
620 case LOCALE_ICURRDIGITS
:
621 pacKey
= "iCurrDigits";
623 case LOCALE_SDECIMAL
:
626 case LOCALE_ICURRENCY
:
627 pacKey
= "iCurrency";
629 case LOCALE_SGROUPING
:
630 pacKey
= "sGrouping";
638 /* case LOCALE_ICALENDARTYPE: */
639 /* case LOCALE_IFIRSTDAYOFWEEK: */
640 /* case LOCALE_IFIRSTWEEKOFYEAR: */
641 /* case LOCALE_SYEARMONTH : */
642 /* case LOCALE_SPOSITIVESIGN : */
643 /* case LOCALE_IPAPERSIZE: */
645 case LOCALE_SLONGDATE
:
646 pacKey
= "sLongDate";
648 case LOCALE_SMONDECIMALSEP
:
649 pacKey
= "sMonDecimalSep";
651 case LOCALE_SMONGROUPING
:
652 pacKey
= "sMonGrouping";
654 case LOCALE_IMEASURE
:
657 case LOCALE_SMONTHOUSANDSEP
:
658 pacKey
= "sMonThousandSep";
660 case LOCALE_INEGCURR
:
663 case LOCALE_SNEGATIVESIGN
:
664 pacKey
= "sNegativeSign";
666 case LOCALE_INEGNUMBER
:
667 pacKey
= "iNegNumber";
669 case LOCALE_SSHORTDATE
:
670 pacKey
= "sShortDate";
672 case LOCALE_ILDATE
: /* Long Date format ordering specifier. */
681 case LOCALE_ITIME
: /* Time format specifier. */
684 case LOCALE_STHOUSAND
:
685 pacKey
= "sThousand";
687 case LOCALE_S1159
: /* AM */
693 case LOCALE_S2359
: /* PM */
696 case LOCALE_STIMEFORMAT
:
697 pacKey
= "sTimeFormat";
699 case LOCALE_SCURRENCY
:
700 pacKey
= "sCurrency";
703 /* The following are not listed under MSDN as supported,
704 * but seem to be used and also stored in the registry.
710 case LOCALE_SCOUNTRY
:
713 case LOCALE_ICOUNTRY
:
716 case LOCALE_SLANGUAGE
:
717 pacKey
= "sLanguage";
727 /******************************************************************************
728 * SetLocaleInfoA [KERNEL32.@]
730 BOOL WINAPI
SetLocaleInfoA(DWORD lcid
, DWORD lctype
, LPCSTR data
)
736 if ( (pacKey
= GetLocaleSubkeyName(lctype
)) )
738 sprintf( acRealKey
, "Control Panel\\International\\%s", pacKey
);
739 if ( RegCreateKeyA( HKEY_CURRENT_USER
, acRealKey
,
740 &hKey
) == ERROR_SUCCESS
)
742 if ( RegSetValueExA( hKey
, NULL
, 0, REG_SZ
,
743 data
, strlen(data
)+1 ) != ERROR_SUCCESS
)
745 ERR("SetLocaleInfoA: %s did not work\n", pacKey
);
752 FIXME("(%ld,%ld,%s): stub\n",lcid
,lctype
,data
);
757 /******************************************************************************
758 * IsValidLocale [KERNEL32.@]
760 BOOL WINAPI
IsValidLocale(LCID lcid
,DWORD flags
)
762 /* check if language is registered in the kernel32 resources */
763 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW
, (LPCWSTR
)LOCALE_ILANGUAGE
, LOWORD(lcid
)))
769 static BOOL CALLBACK
EnumResourceLanguagesProcW(HMODULE hModule
, LPCWSTR type
,
770 LPCWSTR name
, WORD LangID
, LONG lParam
)
774 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
775 sprintf(bufA
, "%08X", (UINT
)LangID
);
776 MultiByteToWideChar(CP_ACP
, 0, bufA
, -1, bufW
, sizeof(bufW
)/sizeof(bufW
[0]));
777 return lpfnLocaleEnum(bufW
);
780 /******************************************************************************
781 * EnumSystemLocalesW [KERNEL32.@]
783 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
,
786 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
788 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW
,
789 (LPCWSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcW
,
790 (LONG
)lpfnLocaleEnum
);
795 static BOOL CALLBACK
EnumResourceLanguagesProcA(HMODULE hModule
, LPCSTR type
,
796 LPCSTR name
, WORD LangID
, LONG lParam
)
799 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
800 sprintf(bufA
, "%08X", (UINT
)LangID
);
801 return lpfnLocaleEnum(bufA
);
804 /******************************************************************************
805 * EnumSystemLocalesA [KERNEL32.@]
807 BOOL WINAPI
EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum
,
810 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
,flags
);
812 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA
,
813 (LPCSTR
)LOCALE_ILANGUAGE
, EnumResourceLanguagesProcA
,
814 (LONG
)lpfnLocaleEnum
);
819 static const unsigned char CT_CType2_LUT
[] = {
820 C2_NOTAPPLICABLE
, /* - 0 */
821 C2_NOTAPPLICABLE
, /* - 1 */
822 C2_NOTAPPLICABLE
, /* - 2 */
823 C2_NOTAPPLICABLE
, /* - 3 */
824 C2_NOTAPPLICABLE
, /* - 4 */
825 C2_NOTAPPLICABLE
, /* - 5 */
826 C2_NOTAPPLICABLE
, /* - 6 */
827 C2_NOTAPPLICABLE
, /* - 7 */
828 C2_NOTAPPLICABLE
, /* - 8 */
829 C2_SEGMENTSEPARATOR
, /* - 9 */
830 C2_NOTAPPLICABLE
, /* - 10 */
831 C2_NOTAPPLICABLE
, /* - 11 */
832 C2_NOTAPPLICABLE
, /* - 12 */
833 C2_NOTAPPLICABLE
, /* - 13 */
834 C2_NOTAPPLICABLE
, /* - 14 */
835 C2_NOTAPPLICABLE
, /* - 15 */
836 C2_NOTAPPLICABLE
, /* - 16 */
837 C2_NOTAPPLICABLE
, /* - 17 */
838 C2_NOTAPPLICABLE
, /* - 18 */
839 C2_NOTAPPLICABLE
, /* - 19 */
840 C2_NOTAPPLICABLE
, /* - 20 */
841 C2_NOTAPPLICABLE
, /* - 21 */
842 C2_NOTAPPLICABLE
, /* - 22 */
843 C2_NOTAPPLICABLE
, /* - 23 */
844 C2_NOTAPPLICABLE
, /* - 24 */
845 C2_NOTAPPLICABLE
, /* - 25 */
846 C2_NOTAPPLICABLE
, /* - 26 */
847 C2_NOTAPPLICABLE
, /* - 27 */
848 C2_NOTAPPLICABLE
, /* - 28 */
849 C2_NOTAPPLICABLE
, /* - 29 */
850 C2_NOTAPPLICABLE
, /* - 30 */
851 C2_NOTAPPLICABLE
, /* - 31 */
852 C2_WHITESPACE
, /* - 32 */
853 C2_OTHERNEUTRAL
, /* ! - 33 */
854 C2_OTHERNEUTRAL
, /* " - 34 */ /* " */
855 C2_EUROPETERMINATOR
, /* # - 35 */
856 C2_EUROPETERMINATOR
, /* $ - 36 */
857 C2_EUROPETERMINATOR
, /* % - 37 */
858 C2_LEFTTORIGHT
, /* & - 38 */
859 C2_OTHERNEUTRAL
, /* ' - 39 */
860 C2_OTHERNEUTRAL
, /* ( - 40 */
861 C2_OTHERNEUTRAL
, /* ) - 41 */
862 C2_OTHERNEUTRAL
, /* * - 42 */
863 C2_EUROPETERMINATOR
, /* + - 43 */
864 C2_COMMONSEPARATOR
, /* , - 44 */
865 C2_EUROPETERMINATOR
, /* - - 45 */
866 C2_EUROPESEPARATOR
, /* . - 46 */
867 C2_EUROPESEPARATOR
, /* / - 47 */
868 C2_EUROPENUMBER
, /* 0 - 48 */
869 C2_EUROPENUMBER
, /* 1 - 49 */
870 C2_EUROPENUMBER
, /* 2 - 50 */
871 C2_EUROPENUMBER
, /* 3 - 51 */
872 C2_EUROPENUMBER
, /* 4 - 52 */
873 C2_EUROPENUMBER
, /* 5 - 53 */
874 C2_EUROPENUMBER
, /* 6 - 54 */
875 C2_EUROPENUMBER
, /* 7 - 55 */
876 C2_EUROPENUMBER
, /* 8 - 56 */
877 C2_EUROPENUMBER
, /* 9 - 57 */
878 C2_COMMONSEPARATOR
, /* : - 58 */
879 C2_OTHERNEUTRAL
, /* ; - 59 */
880 C2_OTHERNEUTRAL
, /* < - 60 */
881 C2_OTHERNEUTRAL
, /* = - 61 */
882 C2_OTHERNEUTRAL
, /* > - 62 */
883 C2_OTHERNEUTRAL
, /* ? - 63 */
884 C2_LEFTTORIGHT
, /* @ - 64 */
885 C2_LEFTTORIGHT
, /* A - 65 */
886 C2_LEFTTORIGHT
, /* B - 66 */
887 C2_LEFTTORIGHT
, /* C - 67 */
888 C2_LEFTTORIGHT
, /* D - 68 */
889 C2_LEFTTORIGHT
, /* E - 69 */
890 C2_LEFTTORIGHT
, /* F - 70 */
891 C2_LEFTTORIGHT
, /* G - 71 */
892 C2_LEFTTORIGHT
, /* H - 72 */
893 C2_LEFTTORIGHT
, /* I - 73 */
894 C2_LEFTTORIGHT
, /* J - 74 */
895 C2_LEFTTORIGHT
, /* K - 75 */
896 C2_LEFTTORIGHT
, /* L - 76 */
897 C2_LEFTTORIGHT
, /* M - 77 */
898 C2_LEFTTORIGHT
, /* N - 78 */
899 C2_LEFTTORIGHT
, /* O - 79 */
900 C2_LEFTTORIGHT
, /* P - 80 */
901 C2_LEFTTORIGHT
, /* Q - 81 */
902 C2_LEFTTORIGHT
, /* R - 82 */
903 C2_LEFTTORIGHT
, /* S - 83 */
904 C2_LEFTTORIGHT
, /* T - 84 */
905 C2_LEFTTORIGHT
, /* U - 85 */
906 C2_LEFTTORIGHT
, /* V - 86 */
907 C2_LEFTTORIGHT
, /* W - 87 */
908 C2_LEFTTORIGHT
, /* X - 88 */
909 C2_LEFTTORIGHT
, /* Y - 89 */
910 C2_LEFTTORIGHT
, /* Z - 90 */
911 C2_OTHERNEUTRAL
, /* [ - 91 */
912 C2_OTHERNEUTRAL
, /* \ - 92 */
913 C2_OTHERNEUTRAL
, /* ] - 93 */
914 C2_OTHERNEUTRAL
, /* ^ - 94 */
915 C2_OTHERNEUTRAL
, /* _ - 95 */
916 C2_OTHERNEUTRAL
, /* ` - 96 */
917 C2_LEFTTORIGHT
, /* a - 97 */
918 C2_LEFTTORIGHT
, /* b - 98 */
919 C2_LEFTTORIGHT
, /* c - 99 */
920 C2_LEFTTORIGHT
, /* d - 100 */
921 C2_LEFTTORIGHT
, /* e - 101 */
922 C2_LEFTTORIGHT
, /* f - 102 */
923 C2_LEFTTORIGHT
, /* g - 103 */
924 C2_LEFTTORIGHT
, /* h - 104 */
925 C2_LEFTTORIGHT
, /* i - 105 */
926 C2_LEFTTORIGHT
, /* j - 106 */
927 C2_LEFTTORIGHT
, /* k - 107 */
928 C2_LEFTTORIGHT
, /* l - 108 */
929 C2_LEFTTORIGHT
, /* m - 109 */
930 C2_LEFTTORIGHT
, /* n - 110 */
931 C2_LEFTTORIGHT
, /* o - 111 */
932 C2_LEFTTORIGHT
, /* p - 112 */
933 C2_LEFTTORIGHT
, /* q - 113 */
934 C2_LEFTTORIGHT
, /* r - 114 */
935 C2_LEFTTORIGHT
, /* s - 115 */
936 C2_LEFTTORIGHT
, /* t - 116 */
937 C2_LEFTTORIGHT
, /* u - 117 */
938 C2_LEFTTORIGHT
, /* v - 118 */
939 C2_LEFTTORIGHT
, /* w - 119 */
940 C2_LEFTTORIGHT
, /* x - 120 */
941 C2_LEFTTORIGHT
, /* y - 121 */
942 C2_LEFTTORIGHT
, /* z - 122 */
943 C2_OTHERNEUTRAL
, /* { - 123 */
944 C2_OTHERNEUTRAL
, /* | - 124 */
945 C2_OTHERNEUTRAL
, /* } - 125 */
946 C2_OTHERNEUTRAL
, /* ~ - 126 */
947 C2_NOTAPPLICABLE
, /* \x7f - 127 */
948 C2_NOTAPPLICABLE
, /* € - 128 */
949 C2_NOTAPPLICABLE
, /* � - 129 */
950 C2_OTHERNEUTRAL
, /* ‚ - 130 */
951 C2_LEFTTORIGHT
, /* ƒ - 131 */
952 C2_OTHERNEUTRAL
, /* „ - 132 */
953 C2_OTHERNEUTRAL
, /* … - 133 */
954 C2_OTHERNEUTRAL
, /* † - 134 */
955 C2_OTHERNEUTRAL
, /* ‡ - 135 */
956 C2_LEFTTORIGHT
, /* ˆ - 136 */
957 C2_EUROPETERMINATOR
, /* ‰ - 137 */
958 C2_LEFTTORIGHT
, /* Š - 138 */
959 C2_OTHERNEUTRAL
, /* ‹ - 139 */
960 C2_LEFTTORIGHT
, /* Œ - 140 */
961 C2_NOTAPPLICABLE
, /* � - 141 */
962 C2_NOTAPPLICABLE
, /* Ž - 142 */
963 C2_NOTAPPLICABLE
, /* � - 143 */
964 C2_NOTAPPLICABLE
, /* � - 144 */
965 C2_OTHERNEUTRAL
, /* ‘ - 145 */
966 C2_OTHERNEUTRAL
, /* ’ - 146 */
967 C2_OTHERNEUTRAL
, /* “ - 147 */
968 C2_OTHERNEUTRAL
, /* ” - 148 */
969 C2_OTHERNEUTRAL
, /* • - 149 */
970 C2_OTHERNEUTRAL
, /* – - 150 */
971 C2_OTHERNEUTRAL
, /* — - 151 */
972 C2_LEFTTORIGHT
, /* ˜ - 152 */
973 C2_OTHERNEUTRAL
, /* ™ - 153 */
974 C2_LEFTTORIGHT
, /* š - 154 */
975 C2_OTHERNEUTRAL
, /* › - 155 */
976 C2_LEFTTORIGHT
, /* œ - 156 */
977 C2_NOTAPPLICABLE
, /* � - 157 */
978 C2_NOTAPPLICABLE
, /* ž - 158 */
979 C2_LEFTTORIGHT
, /* Ÿ - 159 */
980 C2_WHITESPACE
, /* - 160 */
981 C2_OTHERNEUTRAL
, /* ¡ - 161 */
982 C2_EUROPETERMINATOR
, /* ¢ - 162 */
983 C2_EUROPETERMINATOR
, /* £ - 163 */
984 C2_EUROPETERMINATOR
, /* ¤ - 164 */
985 C2_EUROPETERMINATOR
, /* ¥ - 165 */
986 C2_OTHERNEUTRAL
, /* ¦ - 166 */
987 C2_OTHERNEUTRAL
, /* § - 167 */
988 C2_OTHERNEUTRAL
, /* ¨ - 168 */
989 C2_OTHERNEUTRAL
, /* © - 169 */
990 C2_OTHERNEUTRAL
, /* ª - 170 */
991 C2_OTHERNEUTRAL
, /* « - 171 */
992 C2_OTHERNEUTRAL
, /* ¬ - 172 */
993 C2_OTHERNEUTRAL
, /* - 173 */
994 C2_OTHERNEUTRAL
, /* ® - 174 */
995 C2_OTHERNEUTRAL
, /* ¯ - 175 */
996 C2_EUROPETERMINATOR
, /* ° - 176 */
997 C2_EUROPETERMINATOR
, /* ± - 177 */
998 C2_EUROPENUMBER
, /* ² - 178 */
999 C2_EUROPENUMBER
, /* ³ - 179 */
1000 C2_OTHERNEUTRAL
, /* ´ - 180 */
1001 C2_OTHERNEUTRAL
, /* µ - 181 */
1002 C2_OTHERNEUTRAL
, /* ¶ - 182 */
1003 C2_OTHERNEUTRAL
, /* · - 183 */
1004 C2_OTHERNEUTRAL
, /* ¸ - 184 */
1005 C2_EUROPENUMBER
, /* ¹ - 185 */
1006 C2_OTHERNEUTRAL
, /* º - 186 */
1007 C2_OTHERNEUTRAL
, /* » - 187 */
1008 C2_OTHERNEUTRAL
, /* ¼ - 188 */
1009 C2_OTHERNEUTRAL
, /* ½ - 189 */
1010 C2_OTHERNEUTRAL
, /* ¾ - 190 */
1011 C2_OTHERNEUTRAL
, /* ¿ - 191 */
1012 C2_LEFTTORIGHT
, /* À - 192 */
1013 C2_LEFTTORIGHT
, /* Á - 193 */
1014 C2_LEFTTORIGHT
, /* Â - 194 */
1015 C2_LEFTTORIGHT
, /* Ã - 195 */
1016 C2_LEFTTORIGHT
, /* Ä - 196 */
1017 C2_LEFTTORIGHT
, /* Å - 197 */
1018 C2_LEFTTORIGHT
, /* Æ - 198 */
1019 C2_LEFTTORIGHT
, /* Ç - 199 */
1020 C2_LEFTTORIGHT
, /* È - 200 */
1021 C2_LEFTTORIGHT
, /* É - 201 */
1022 C2_LEFTTORIGHT
, /* Ê - 202 */
1023 C2_LEFTTORIGHT
, /* Ë - 203 */
1024 C2_LEFTTORIGHT
, /* Ì - 204 */
1025 C2_LEFTTORIGHT
, /* Í - 205 */
1026 C2_LEFTTORIGHT
, /* Î - 206 */
1027 C2_LEFTTORIGHT
, /* Ï - 207 */
1028 C2_LEFTTORIGHT
, /* Ð - 208 */
1029 C2_LEFTTORIGHT
, /* Ñ - 209 */
1030 C2_LEFTTORIGHT
, /* Ò - 210 */
1031 C2_LEFTTORIGHT
, /* Ó - 211 */
1032 C2_LEFTTORIGHT
, /* Ô - 212 */
1033 C2_LEFTTORIGHT
, /* Õ - 213 */
1034 C2_LEFTTORIGHT
, /* Ö - 214 */
1035 C2_OTHERNEUTRAL
, /* × - 215 */
1036 C2_LEFTTORIGHT
, /* Ø - 216 */
1037 C2_LEFTTORIGHT
, /* Ù - 217 */
1038 C2_LEFTTORIGHT
, /* Ú - 218 */
1039 C2_LEFTTORIGHT
, /* Û - 219 */
1040 C2_LEFTTORIGHT
, /* Ü - 220 */
1041 C2_LEFTTORIGHT
, /* Ý - 221 */
1042 C2_LEFTTORIGHT
, /* Þ - 222 */
1043 C2_LEFTTORIGHT
, /* ß - 223 */
1044 C2_LEFTTORIGHT
, /* à - 224 */
1045 C2_LEFTTORIGHT
, /* á - 225 */
1046 C2_LEFTTORIGHT
, /* â - 226 */
1047 C2_LEFTTORIGHT
, /* ã - 227 */
1048 C2_LEFTTORIGHT
, /* ä - 228 */
1049 C2_LEFTTORIGHT
, /* å - 229 */
1050 C2_LEFTTORIGHT
, /* æ - 230 */
1051 C2_LEFTTORIGHT
, /* ç - 231 */
1052 C2_LEFTTORIGHT
, /* è - 232 */
1053 C2_LEFTTORIGHT
, /* é - 233 */
1054 C2_LEFTTORIGHT
, /* ê - 234 */
1055 C2_LEFTTORIGHT
, /* ë - 235 */
1056 C2_LEFTTORIGHT
, /* ì - 236 */
1057 C2_LEFTTORIGHT
, /* í - 237 */
1058 C2_LEFTTORIGHT
, /* î - 238 */
1059 C2_LEFTTORIGHT
, /* ï - 239 */
1060 C2_LEFTTORIGHT
, /* ð - 240 */
1061 C2_LEFTTORIGHT
, /* ñ - 241 */
1062 C2_LEFTTORIGHT
, /* ò - 242 */
1063 C2_LEFTTORIGHT
, /* ó - 243 */
1064 C2_LEFTTORIGHT
, /* ô - 244 */
1065 C2_LEFTTORIGHT
, /* õ - 245 */
1066 C2_LEFTTORIGHT
, /* ö - 246 */
1067 C2_OTHERNEUTRAL
, /* ÷ - 247 */
1068 C2_LEFTTORIGHT
, /* ø - 248 */
1069 C2_LEFTTORIGHT
, /* ù - 249 */
1070 C2_LEFTTORIGHT
, /* ú - 250 */
1071 C2_LEFTTORIGHT
, /* û - 251 */
1072 C2_LEFTTORIGHT
, /* ü - 252 */
1073 C2_LEFTTORIGHT
, /* ý - 253 */
1074 C2_LEFTTORIGHT
, /* þ - 254 */
1075 C2_LEFTTORIGHT
/* ÿ - 255 */
1078 static const WORD OLE2NLS_CT_CType3_LUT
[] = {
1112 0x0048, /* ! - 33 */
1113 0x0448, /* " - 34 */ /* " */
1114 0x0048, /* # - 35 */
1115 0x0448, /* $ - 36 */
1116 0x0048, /* % - 37 */
1117 0x0048, /* & - 38 */
1118 0x0440, /* ' - 39 */
1119 0x0048, /* ( - 40 */
1120 0x0048, /* ) - 41 */
1121 0x0048, /* * - 42 */
1122 0x0048, /* + - 43 */
1123 0x0048, /* , - 44 */
1124 0x0440, /* - - 45 */
1125 0x0048, /* . - 46 */
1126 0x0448, /* / - 47 */
1127 0x0040, /* 0 - 48 */
1128 0x0040, /* 1 - 49 */
1129 0x0040, /* 2 - 50 */
1130 0x0040, /* 3 - 51 */
1131 0x0040, /* 4 - 52 */
1132 0x0040, /* 5 - 53 */
1133 0x0040, /* 6 - 54 */
1134 0x0040, /* 7 - 55 */
1135 0x0040, /* 8 - 56 */
1136 0x0040, /* 9 - 57 */
1137 0x0048, /* : - 58 */
1138 0x0048, /* ; - 59 */
1139 0x0048, /* < - 60 */
1140 0x0448, /* = - 61 */
1141 0x0048, /* > - 62 */
1142 0x0048, /* ? - 63 */
1143 0x0448, /* @ - 64 */
1144 0x8040, /* A - 65 */
1145 0x8040, /* B - 66 */
1146 0x8040, /* C - 67 */
1147 0x8040, /* D - 68 */
1148 0x8040, /* E - 69 */
1149 0x8040, /* F - 70 */
1150 0x8040, /* G - 71 */
1151 0x8040, /* H - 72 */
1152 0x8040, /* I - 73 */
1153 0x8040, /* J - 74 */
1154 0x8040, /* K - 75 */
1155 0x8040, /* L - 76 */
1156 0x8040, /* M - 77 */
1157 0x8040, /* N - 78 */
1158 0x8040, /* O - 79 */
1159 0x8040, /* P - 80 */
1160 0x8040, /* Q - 81 */
1161 0x8040, /* R - 82 */
1162 0x8040, /* S - 83 */
1163 0x8040, /* T - 84 */
1164 0x8040, /* U - 85 */
1165 0x8040, /* V - 86 */
1166 0x8040, /* W - 87 */
1167 0x8040, /* X - 88 */
1168 0x8040, /* Y - 89 */
1169 0x8040, /* Z - 90 */
1170 0x0048, /* [ - 91 */
1171 0x0448, /* \ - 92 */
1172 0x0048, /* ] - 93 */
1173 0x0448, /* ^ - 94 */
1174 0x0448, /* _ - 95 */
1175 0x0448, /* ` - 96 */
1176 0x8040, /* a - 97 */
1177 0x8040, /* b - 98 */
1178 0x8040, /* c - 99 */
1179 0x8040, /* d - 100 */
1180 0x8040, /* e - 101 */
1181 0x8040, /* f - 102 */
1182 0x8040, /* g - 103 */
1183 0x8040, /* h - 104 */
1184 0x8040, /* i - 105 */
1185 0x8040, /* j - 106 */
1186 0x8040, /* k - 107 */
1187 0x8040, /* l - 108 */
1188 0x8040, /* m - 109 */
1189 0x8040, /* n - 110 */
1190 0x8040, /* o - 111 */
1191 0x8040, /* p - 112 */
1192 0x8040, /* q - 113 */
1193 0x8040, /* r - 114 */
1194 0x8040, /* s - 115 */
1195 0x8040, /* t - 116 */
1196 0x8040, /* u - 117 */
1197 0x8040, /* v - 118 */
1198 0x8040, /* w - 119 */
1199 0x8040, /* x - 120 */
1200 0x8040, /* y - 121 */
1201 0x8040, /* z - 122 */
1202 0x0048, /* { - 123 */
1203 0x0048, /* | - 124 */
1204 0x0048, /* } - 125 */
1205 0x0448, /* ~ - 126 */
1206 0x0000, /* \x7f - 127 */
1207 0x0000, /* € - 128 */
1208 0x0000, /* � - 129 */
1209 0x0008, /* ‚ - 130 */
1210 0x8000, /* ƒ - 131 */
1211 0x0008, /* „ - 132 */
1212 0x0008, /* … - 133 */
1213 0x0008, /* † - 134 */
1214 0x0008, /* ‡ - 135 */
1215 0x0001, /* ˆ - 136 */
1216 0x0008, /* ‰ - 137 */
1217 0x8003, /* Š - 138 */
1218 0x0008, /* ‹ - 139 */
1219 0x8000, /* Œ - 140 */
1220 0x0000, /* � - 141 */
1221 0x0000, /* Ž - 142 */
1222 0x0000, /* � - 143 */
1223 0x0000, /* � - 144 */
1224 0x0088, /* ‘ - 145 */
1225 0x0088, /* ’ - 146 */
1226 0x0088, /* “ - 147 */
1227 0x0088, /* ” - 148 */
1228 0x0008, /* • - 149 */
1229 0x0400, /* – - 150 */
1230 0x0400, /* — - 151 */
1231 0x0408, /* ˜ - 152 */
1232 0x0000, /* ™ - 153 */
1233 0x8003, /* š - 154 */
1234 0x0008, /* › - 155 */
1235 0x8000, /* œ - 156 */
1236 0x0000, /* � - 157 */
1237 0x0000, /* ž - 158 */
1238 0x8003, /* Ÿ - 159 */
1240 0x0008, /* ¡ - 161 */
1241 0x0048, /* ¢ - 162 */
1242 0x0048, /* £ - 163 */
1243 0x0008, /* ¤ - 164 */
1244 0x0048, /* ¥ - 165 */
1245 0x0048, /* ¦ - 166 */
1246 0x0008, /* § - 167 */
1247 0x0408, /* ¨ - 168 */
1248 0x0008, /* © - 169 */
1249 0x0400, /* ª - 170 */
1250 0x0008, /* « - 171 */
1251 0x0048, /* ¬ - 172 */
1252 0x0408, /* - 173 */
1253 0x0008, /* ® - 174 */
1254 0x0448, /* ¯ - 175 */
1255 0x0008, /* ° - 176 */
1256 0x0008, /* ± - 177 */
1257 0x0000, /* ² - 178 */
1258 0x0000, /* ³ - 179 */
1259 0x0408, /* ´ - 180 */
1260 0x0008, /* µ - 181 */
1261 0x0008, /* ¶ - 182 */
1262 0x0008, /* · - 183 */
1263 0x0408, /* ¸ - 184 */
1264 0x0000, /* ¹ - 185 */
1265 0x0400, /* º - 186 */
1266 0x0008, /* » - 187 */
1267 0x0000, /* ¼ - 188 */
1268 0x0000, /* ½ - 189 */
1269 0x0000, /* ¾ - 190 */
1270 0x0008, /* ¿ - 191 */
1271 0x8003, /* À - 192 */
1272 0x8003, /* Á - 193 */
1273 0x8003, /* Â - 194 */
1274 0x8003, /* Ã - 195 */
1275 0x8003, /* Ä - 196 */
1276 0x8003, /* Å - 197 */
1277 0x8000, /* Æ - 198 */
1278 0x8003, /* Ç - 199 */
1279 0x8003, /* È - 200 */
1280 0x8003, /* É - 201 */
1281 0x8003, /* Ê - 202 */
1282 0x8003, /* Ë - 203 */
1283 0x8003, /* Ì - 204 */
1284 0x8003, /* Í - 205 */
1285 0x8003, /* Î - 206 */
1286 0x8003, /* Ï - 207 */
1287 0x8000, /* Ð - 208 */
1288 0x8003, /* Ñ - 209 */
1289 0x8003, /* Ò - 210 */
1290 0x8003, /* Ó - 211 */
1291 0x8003, /* Ô - 212 */
1292 0x8003, /* Õ - 213 */
1293 0x8003, /* Ö - 214 */
1294 0x0008, /* × - 215 */
1295 0x8003, /* Ø - 216 */
1296 0x8003, /* Ù - 217 */
1297 0x8003, /* Ú - 218 */
1298 0x8003, /* Û - 219 */
1299 0x8003, /* Ü - 220 */
1300 0x8003, /* Ý - 221 */
1301 0x8000, /* Þ - 222 */
1302 0x8000, /* ß - 223 */
1303 0x8003, /* à - 224 */
1304 0x8003, /* á - 225 */
1305 0x8003, /* â - 226 */
1306 0x8003, /* ã - 227 */
1307 0x8003, /* ä - 228 */
1308 0x8003, /* å - 229 */
1309 0x8000, /* æ - 230 */
1310 0x8003, /* ç - 231 */
1311 0x8003, /* è - 232 */
1312 0x8003, /* é - 233 */
1313 0x8003, /* ê - 234 */
1314 0x8003, /* ë - 235 */
1315 0x8003, /* ì - 236 */
1316 0x8003, /* í - 237 */
1317 0x8003, /* î - 238 */
1318 0x8003, /* ï - 239 */
1319 0x8000, /* ð - 240 */
1320 0x8003, /* ñ - 241 */
1321 0x8003, /* ò - 242 */
1322 0x8003, /* ó - 243 */
1323 0x8003, /* ô - 244 */
1324 0x8003, /* õ - 245 */
1325 0x8003, /* ö - 246 */
1326 0x0008, /* ÷ - 247 */
1327 0x8003, /* ø - 248 */
1328 0x8003, /* ù - 249 */
1329 0x8003, /* ú - 250 */
1330 0x8003, /* û - 251 */
1331 0x8003, /* ü - 252 */
1332 0x8003, /* ý - 253 */
1333 0x8000, /* þ - 254 */
1334 0x8003 /* ÿ - 255 */
1337 /******************************************************************************
1338 * GetStringTypeA [KERNEL32.@]
1340 BOOL WINAPI
GetStringTypeA(LCID locale
,DWORD dwInfoType
,LPCSTR src
,
1341 INT cchSrc
,LPWORD chartype
)
1343 return GetStringTypeExA(locale
,dwInfoType
,src
,cchSrc
,chartype
);
1346 /******************************************************************************
1347 * GetStringTypeExA [KERNEL32.@]
1349 * FIXME: Ignores the locale.
1351 BOOL WINAPI
GetStringTypeExA(LCID locale
,DWORD dwInfoType
,LPCSTR src
,
1352 INT cchSrc
,LPWORD chartype
)
1356 if ((src
==NULL
) || (chartype
==NULL
) || (src
==(LPSTR
)chartype
))
1358 SetLastError(ERROR_INVALID_PARAMETER
);
1363 cchSrc
=strlen(src
)+1;
1365 switch (dwInfoType
) {
1367 for (i
=0;i
<cchSrc
;i
++)
1370 if (isdigit(src
[i
])) chartype
[i
]|=C1_DIGIT
;
1371 if (isalpha(src
[i
])) chartype
[i
]|=C1_ALPHA
;
1372 if (islower(src
[i
])) chartype
[i
]|=C1_LOWER
;
1373 if (isupper(src
[i
])) chartype
[i
]|=C1_UPPER
;
1374 if (isspace(src
[i
])) chartype
[i
]|=C1_SPACE
;
1375 if (ispunct(src
[i
])) chartype
[i
]|=C1_PUNCT
;
1376 if (iscntrl(src
[i
])) chartype
[i
]|=C1_CNTRL
;
1377 /* FIXME: isblank() is a GNU extension */
1378 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1379 if ((src
[i
] == ' ') || (src
[i
] == '\t')) chartype
[i
]|=C1_BLANK
;
1385 for (i
=0;i
<cchSrc
;i
++)
1387 chartype
[i
]=(WORD
)CT_CType2_LUT
[i
];
1392 for (i
=0;i
<cchSrc
;i
++)
1394 chartype
[i
]=OLE2NLS_CT_CType3_LUT
[i
];
1399 ERR("Unknown dwInfoType:%ld\n",dwInfoType
);
1404 /***********************************************************************
1405 * VerLanguageNameA [KERNEL32.@]
1406 * VerLanguageNameA [VERSION.9]
1408 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
1413 return GetLocaleInfoA(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1416 /***********************************************************************
1417 * VerLanguageNameW [KERNEL32.@]
1418 * VerLanguageNameW [VERSION.10]
1420 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
1425 return GetLocaleInfoW(MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1429 static const unsigned char LCM_Unicode_LUT
[] = {
1462 7 , 28, /* ! - 33 */
1463 7 , 29, /* " - 34 */ /* " */
1464 7 , 31, /* # - 35 */
1465 7 , 33, /* $ - 36 */
1466 7 , 35, /* % - 37 */
1467 7 , 37, /* & - 38 */
1468 6 , 128, /* ' - 39 */
1469 7 , 39, /* ( - 40 */
1470 7 , 42, /* ) - 41 */
1471 7 , 45, /* * - 42 */
1473 7 , 47, /* , - 44 */
1474 6 , 130, /* - - 45 */
1475 7 , 51, /* . - 46 */
1476 7 , 53, /* / - 47 */
1477 12 , 3, /* 0 - 48 */
1478 12 , 33, /* 1 - 49 */
1479 12 , 51, /* 2 - 50 */
1480 12 , 70, /* 3 - 51 */
1481 12 , 88, /* 4 - 52 */
1482 12 , 106, /* 5 - 53 */
1483 12 , 125, /* 6 - 54 */
1484 12 , 144, /* 7 - 55 */
1485 12 , 162, /* 8 - 56 */
1486 12 , 180, /* 9 - 57 */
1487 7 , 55, /* : - 58 */
1488 7 , 58, /* ; - 59 */
1489 8 , 14, /* < - 60 */
1490 8 , 18, /* = - 61 */
1491 8 , 20, /* > - 62 */
1492 7 , 60, /* ? - 63 */
1493 7 , 62, /* @ - 64 */
1494 14 , 2, /* A - 65 */
1495 14 , 9, /* B - 66 */
1496 14 , 10, /* C - 67 */
1497 14 , 26, /* D - 68 */
1498 14 , 33, /* E - 69 */
1499 14 , 35, /* F - 70 */
1500 14 , 37, /* G - 71 */
1501 14 , 44, /* H - 72 */
1502 14 , 50, /* I - 73 */
1503 14 , 53, /* J - 74 */
1504 14 , 54, /* K - 75 */
1505 14 , 72, /* L - 76 */
1506 14 , 81, /* M - 77 */
1507 14 , 112, /* N - 78 */
1508 14 , 124, /* O - 79 */
1509 14 , 126, /* P - 80 */
1510 14 , 137, /* Q - 81 */
1511 14 , 138, /* R - 82 */
1512 14 , 145, /* S - 83 */
1513 14 , 153, /* T - 84 */
1514 14 , 159, /* U - 85 */
1515 14 , 162, /* V - 86 */
1516 14 , 164, /* W - 87 */
1517 14 , 166, /* X - 88 */
1518 14 , 167, /* Y - 89 */
1519 14 , 169, /* Z - 90 */
1520 7 , 63, /* [ - 91 */
1521 7 , 65, /* \ - 92 */
1522 7 , 66, /* ] - 93 */
1523 7 , 67, /* ^ - 94 */
1524 7 , 68, /* _ - 95 */
1525 7 , 72, /* ` - 96 */
1526 14 , 2, /* a - 97 */
1527 14 , 9, /* b - 98 */
1528 14 , 10, /* c - 99 */
1529 14 , 26, /* d - 100 */
1530 14 , 33, /* e - 101 */
1531 14 , 35, /* f - 102 */
1532 14 , 37, /* g - 103 */
1533 14 , 44, /* h - 104 */
1534 14 , 50, /* i - 105 */
1535 14 , 53, /* j - 106 */
1536 14 , 54, /* k - 107 */
1537 14 , 72, /* l - 108 */
1538 14 , 81, /* m - 109 */
1539 14 , 112, /* n - 110 */
1540 14 , 124, /* o - 111 */
1541 14 , 126, /* p - 112 */
1542 14 , 137, /* q - 113 */
1543 14 , 138, /* r - 114 */
1544 14 , 145, /* s - 115 */
1545 14 , 153, /* t - 116 */
1546 14 , 159, /* u - 117 */
1547 14 , 162, /* v - 118 */
1548 14 , 164, /* w - 119 */
1549 14 , 166, /* x - 120 */
1550 14 , 167, /* y - 121 */
1551 14 , 169, /* z - 122 */
1552 7 , 74, /* { - 123 */
1553 7 , 76, /* | - 124 */
1554 7 , 78, /* } - 125 */
1555 7 , 80, /* ~ - 126 */
1556 6 , 29, /* \x7f - 127 */
1557 6 , 30, /* € - 128 */
1558 6 , 31, /* � - 129 */
1559 7 , 123, /* ‚ - 130 */
1560 14 , 35, /* ƒ - 131 */
1561 7 , 127, /* „ - 132 */
1562 10 , 21, /* … - 133 */
1563 10 , 15, /* † - 134 */
1564 10 , 16, /* ‡ - 135 */
1565 7 , 67, /* ˆ - 136 */
1566 10 , 22, /* ‰ - 137 */
1567 14 , 145, /* Š - 138 */
1568 7 , 136, /* ‹ - 139 */
1569 14 + 16 , 124, /* Œ - 140 */
1570 6 , 43, /* � - 141 */
1571 6 , 44, /* Ž - 142 */
1572 6 , 45, /* � - 143 */
1573 6 , 46, /* � - 144 */
1574 7 , 121, /* ‘ - 145 */
1575 7 , 122, /* ’ - 146 */
1576 7 , 125, /* “ - 147 */
1577 7 , 126, /* ” - 148 */
1578 10 , 17, /* • - 149 */
1579 6 , 137, /* – - 150 */
1580 6 , 139, /* — - 151 */
1581 7 , 93, /* ˜ - 152 */
1582 14 , 156, /* ™ - 153 */
1583 14 , 145, /* š - 154 */
1584 7 , 137, /* › - 155 */
1585 14 + 16 , 124, /* œ - 156 */
1586 6 , 59, /* � - 157 */
1587 6 , 60, /* ž - 158 */
1588 14 , 167, /* Ÿ - 159 */
1590 7 , 81, /* ¡ - 161 */
1591 10 , 2, /* ¢ - 162 */
1592 10 , 3, /* £ - 163 */
1593 10 , 4, /* ¤ - 164 */
1594 10 , 5, /* ¥ - 165 */
1595 7 , 82, /* ¦ - 166 */
1596 10 , 6, /* § - 167 */
1597 7 , 83, /* ¨ - 168 */
1598 10 , 7, /* © - 169 */
1599 14 , 2, /* ª - 170 */
1600 8 , 24, /* « - 171 */
1601 10 , 8, /* ¬ - 172 */
1602 6 , 131, /* - 173 */
1603 10 , 9, /* ® - 174 */
1604 7 , 84, /* ¯ - 175 */
1605 10 , 10, /* ° - 176 */
1606 8 , 23, /* ± - 177 */
1607 12 , 51, /* ² - 178 */
1608 12 , 70, /* ³ - 179 */
1609 7 , 85, /* ´ - 180 */
1610 10 , 11, /* µ - 181 */
1611 10 , 12, /* ¶ - 182 */
1612 10 , 13, /* · - 183 */
1613 7 , 86, /* ¸ - 184 */
1614 12 , 33, /* ¹ - 185 */
1615 14 , 124, /* º - 186 */
1616 8 , 26, /* » - 187 */
1617 12 , 21, /* ¼ - 188 */
1618 12 , 25, /* ½ - 189 */
1619 12 , 29, /* ¾ - 190 */
1620 7 , 87, /* ¿ - 191 */
1621 14 , 2, /* À - 192 */
1622 14 , 2, /* Á - 193 */
1623 14 , 2, /* Â - 194 */
1624 14 , 2, /* Ã - 195 */
1625 14 , 2, /* Ä - 196 */
1626 14 , 2, /* Å - 197 */
1627 14 + 16 , 2, /* Æ - 198 */
1628 14 , 10, /* Ç - 199 */
1629 14 , 33, /* È - 200 */
1630 14 , 33, /* É - 201 */
1631 14 , 33, /* Ê - 202 */
1632 14 , 33, /* Ë - 203 */
1633 14 , 50, /* Ì - 204 */
1634 14 , 50, /* Í - 205 */
1635 14 , 50, /* Î - 206 */
1636 14 , 50, /* Ï - 207 */
1637 14 , 26, /* Ð - 208 */
1638 14 , 112, /* Ñ - 209 */
1639 14 , 124, /* Ò - 210 */
1640 14 , 124, /* Ó - 211 */
1641 14 , 124, /* Ô - 212 */
1642 14 , 124, /* Õ - 213 */
1643 14 , 124, /* Ö - 214 */
1644 8 , 28, /* × - 215 */
1645 14 , 124, /* Ø - 216 */
1646 14 , 159, /* Ù - 217 */
1647 14 , 159, /* Ú - 218 */
1648 14 , 159, /* Û - 219 */
1649 14 , 159, /* Ü - 220 */
1650 14 , 167, /* Ý - 221 */
1651 14 + 32 , 153, /* Þ - 222 */
1652 14 + 48 , 145, /* ß - 223 */
1653 14 , 2, /* à - 224 */
1654 14 , 2, /* á - 225 */
1655 14 , 2, /* â - 226 */
1656 14 , 2, /* ã - 227 */
1657 14 , 2, /* ä - 228 */
1658 14 , 2, /* å - 229 */
1659 14 + 16 , 2, /* æ - 230 */
1660 14 , 10, /* ç - 231 */
1661 14 , 33, /* è - 232 */
1662 14 , 33, /* é - 233 */
1663 14 , 33, /* ê - 234 */
1664 14 , 33, /* ë - 235 */
1665 14 , 50, /* ì - 236 */
1666 14 , 50, /* í - 237 */
1667 14 , 50, /* î - 238 */
1668 14 , 50, /* ï - 239 */
1669 14 , 26, /* ð - 240 */
1670 14 , 112, /* ñ - 241 */
1671 14 , 124, /* ò - 242 */
1672 14 , 124, /* ó - 243 */
1673 14 , 124, /* ô - 244 */
1674 14 , 124, /* õ - 245 */
1675 14 , 124, /* ö - 246 */
1676 8 , 29, /* ÷ - 247 */
1677 14 , 124, /* ø - 248 */
1678 14 , 159, /* ù - 249 */
1679 14 , 159, /* ú - 250 */
1680 14 , 159, /* û - 251 */
1681 14 , 159, /* ü - 252 */
1682 14 , 167, /* ý - 253 */
1683 14 + 32 , 153, /* þ - 254 */
1684 14 , 167 /* ÿ - 255 */ };
1686 static const unsigned char LCM_Unicode_LUT_2
[] = { 33, 44, 145 };
1688 #define LCM_Diacritic_Start 131
1690 static const unsigned char LCM_Diacritic_LUT
[] = {
1818 /******************************************************************************
1819 * OLE2NLS_isPunctuation [INTERNAL]
1821 static int OLE2NLS_isPunctuation(unsigned char c
)
1823 /* "punctuation character" in this context is a character which is
1824 considered "less important" during word sort comparison.
1825 See LCMapString implementation for the precise definition
1826 of "less important". */
1828 return (LCM_Unicode_LUT
[-2+2*c
]==6);
1831 /******************************************************************************
1832 * OLE2NLS_isNonSpacing [INTERNAL]
1834 static int OLE2NLS_isNonSpacing(unsigned char c
)
1836 /* This function is used by LCMapStringA. Characters
1837 for which it returns true are ignored when mapping a
1838 string with NORM_IGNORENONSPACE */
1839 return ((c
==136) || (c
==170) || (c
==186));
1842 /******************************************************************************
1843 * OLE2NLS_isSymbol [INTERNAL]
1844 * FIXME: handle current locale
1846 static int OLE2NLS_isSymbol(unsigned char c
)
1848 /* This function is used by LCMapStringA. Characters
1849 for which it returns true are ignored when mapping a
1850 string with NORM_IGNORESYMBOLS */
1851 return ( (c
!=0) && !(isalpha(c
) || isdigit(c
)) );
1854 /******************************************************************************
1855 * identity [Internal]
1857 static int identity(int c
)
1862 /*************************************************************************
1863 * LCMapStringA [KERNEL32.@]
1865 * Convert a string, or generate a sort key from it.
1867 * If (mapflags & LCMAP_SORTKEY), the function will generate
1868 * a sort key for the source string. Else, it will convert it
1869 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1873 * Success : length of the result string.
1876 * If called with scrlen = -1, the function will compute the length
1877 * of the 0-terminated string strsrc by itself.
1879 * If called with dstlen = 0, returns the buffer length that
1880 * would be required.
1882 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1883 * as if they are equal.
1884 * In the only code page implemented so far, there may not be
1885 * wide characters in strings passed to LCMapStringA,
1886 * so there is nothing to be done for this flag.
1888 INT WINAPI
LCMapStringA(
1889 LCID lcid
, /* [in] locale identifier created with MAKELCID;
1890 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1891 predefined values. */
1892 DWORD mapflags
, /* [in] flags */
1893 LPCSTR srcstr
, /* [in] source buffer */
1894 INT srclen
, /* [in] source length */
1895 LPSTR dststr
, /* [out] destination buffer */
1896 INT dstlen
) /* [in] destination buffer length */
1900 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1901 lcid
,mapflags
,srcstr
,srclen
,dststr
,dstlen
);
1903 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
1905 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr
, dststr
);
1906 SetLastError(ERROR_INVALID_PARAMETER
);
1910 srclen
= strlen(srcstr
) + 1 ; /* (include final '\0') */
1912 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1916 NORM_IGNORENONSPACE | \
1918 NORM_IGNOREWIDTH | \
1919 NORM_IGNOREKANATYPE)
1920 /* FIXME: as long as we don't support Katakana nor Hiragana
1921 * characters, we can support NORM_IGNOREKANATYPE
1923 if (mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
)
1925 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1926 "unimplemented flags: 0x%08lx\n",
1933 mapflags
& ~LCMAPSTRINGA_SUPPORTED_FLAGS
1937 if ( !(mapflags
& LCMAP_SORTKEY
) )
1940 int (*f
)(int) = identity
;
1941 int flag_ignorenonspace
= mapflags
& NORM_IGNORENONSPACE
;
1942 int flag_ignoresymbols
= mapflags
& NORM_IGNORESYMBOLS
;
1944 if (flag_ignorenonspace
|| flag_ignoresymbols
)
1946 /* For some values of mapflags, the length of the resulting
1947 string is not known at this point. Windows does map the string
1948 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1952 /* Compute required length */
1953 for (i
=j
=0; i
< srclen
; i
++)
1955 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1956 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1968 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1972 if (mapflags
& LCMAP_UPPERCASE
)
1974 else if (mapflags
& LCMAP_LOWERCASE
)
1976 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1977 for (i
=j
=0; (i
<srclen
) && (j
<dstlen
) ; i
++)
1979 if ( !(flag_ignorenonspace
&& OLE2NLS_isNonSpacing(srcstr
[i
]))
1980 && !(flag_ignoresymbols
&& OLE2NLS_isSymbol(srcstr
[i
])) )
1982 dststr
[j
] = (CHAR
) f(srcstr
[i
]);
1989 /* FIXME: This function completely ignores the "lcid" parameter. */
1990 /* else ... (mapflags & LCMAP_SORTKEY) */
1994 int diacritic_len
=0;
1995 int delayed_punctuation_len
=0;
1996 char *case_component
;
1997 char *diacritic_component
;
1998 char *delayed_punctuation_component
;
2000 int flag_stringsort
= mapflags
& SORT_STRINGSORT
;
2002 /* compute how much room we will need */
2003 for (i
=0;i
<srclen
;i
++)
2006 unsigned char source_char
= srcstr
[i
];
2007 if (source_char
!='\0')
2009 if (flag_stringsort
|| !OLE2NLS_isPunctuation(source_char
))
2012 if ( LCM_Unicode_LUT
[-2+2*source_char
] & ~15 )
2013 unicode_len
++; /* double letter */
2017 delayed_punctuation_len
++;
2021 if (isupper(source_char
))
2022 case_len
=unicode_len
;
2024 ofs
= source_char
- LCM_Diacritic_Start
;
2025 if ((ofs
>=0) && (LCM_Diacritic_LUT
[ofs
]!=2))
2026 diacritic_len
=unicode_len
;
2029 if (mapflags
& NORM_IGNORECASE
)
2031 if (mapflags
& NORM_IGNORENONSPACE
)
2034 room
= 2 * unicode_len
/* "unicode" component */
2035 + diacritic_len
/* "diacritic" component */
2036 + case_len
/* "case" component */
2037 + 4 * delayed_punctuation_len
/* punctuation in word sort mode */
2038 + 4 /* four '\1' separators */
2039 + 1 ; /* terminal '\0' */
2042 else if (dstlen
<room
)
2044 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2048 /*FIXME the Pointercheck should not be nessesary */
2049 if (IsBadWritePtr (dststr
,room
))
2050 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr
,dstlen
);
2051 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2055 /* locate each component, write separators */
2056 diacritic_component
= dststr
+ 2*unicode_len
;
2057 *diacritic_component
++ = '\1';
2058 case_component
= diacritic_component
+ diacritic_len
;
2059 *case_component
++ = '\1';
2060 delayed_punctuation_component
= case_component
+ case_len
;
2061 *delayed_punctuation_component
++ = '\1';
2062 *delayed_punctuation_component
++ = '\1';
2064 /* read source string char by char, write
2065 corresponding weight in each component. */
2066 for (i
=0,count
=0;i
<srclen
;i
++)
2068 unsigned char source_char
=srcstr
[i
];
2069 if (source_char
!='\0')
2072 type
= LCM_Unicode_LUT
[-2+2*source_char
];
2073 longcode
= type
>> 4;
2075 if (!flag_stringsort
&& OLE2NLS_isPunctuation(source_char
))
2077 WORD encrypted_location
= (1<<15) + 7 + 4*count
;
2078 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
>>8);
2079 *delayed_punctuation_component
++ = (unsigned char) (encrypted_location
&255);
2080 /* big-endian is used here because it lets string comparison be
2081 compatible with numerical comparison */
2083 *delayed_punctuation_component
++ = type
;
2084 *delayed_punctuation_component
++ = LCM_Unicode_LUT
[-1+2*source_char
];
2085 /* assumption : a punctuation character is never a
2086 double or accented letter */
2090 dststr
[2*count
] = type
;
2091 dststr
[2*count
+1] = LCM_Unicode_LUT
[-1+2*source_char
];
2095 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
2096 if (count
<diacritic_len
)
2097 diacritic_component
[count
] = 2; /* assumption: a double letter
2098 is never accented */
2101 dststr
[2*count
] = type
;
2102 dststr
[2*count
+1] = *(LCM_Unicode_LUT_2
- 1 + longcode
);
2103 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
2104 32 in the first column of LCM_Unicode_LUT --> longcode = 2
2105 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
2109 case_component
[count
] = ( isupper(source_char
) ? 18 : 2 ) ;
2110 if (count
<diacritic_len
)
2112 int ofs
= source_char
- LCM_Diacritic_Start
;
2113 diacritic_component
[count
] = (ofs
>=0 ? LCM_Diacritic_LUT
[ofs
] : 2);
2119 dststr
[room
-1] = '\0';
2124 /*************************************************************************
2125 * LCMapStringW [KERNEL32.@]
2127 * Convert a string, or generate a sort key from it.
2131 * See LCMapStringA for documentation
2133 INT WINAPI
LCMapStringW(
2134 LCID lcid
,DWORD mapflags
,LPCWSTR srcstr
,INT srclen
,LPWSTR dststr
,
2139 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2140 lcid
, mapflags
, srcstr
, srclen
, dststr
, dstlen
);
2142 if ( ((dstlen
!=0) && (dststr
==NULL
)) || (srcstr
==NULL
) )
2144 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr
, dststr
);
2145 SetLastError(ERROR_INVALID_PARAMETER
);
2149 srclen
= strlenW(srcstr
)+1;
2151 /* FIXME: Both this function and it's companion LCMapStringA()
2152 * completely ignore the "lcid" parameter. In place of the "lcid"
2153 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2154 * environment variable prior to invoking this function. */
2155 if (mapflags
& LCMAP_SORTKEY
)
2157 /* Possible values of LC_COLLATE. */
2158 char *lc_collate_default
= 0; /* value prior to this function */
2159 char *lc_collate_env
= 0; /* value retrieved from the environment */
2161 /* General purpose index into strings of any type. */
2164 /* Lengths of various strings where the length is measured in
2165 * wide characters for wide character strings and in bytes for
2166 * native strings. The lengths include the NULL terminator. */
2167 size_t returned_len
= 0;
2168 size_t src_native_len
= 0;
2169 size_t dst_native_len
= 0;
2170 size_t dststr_libc_len
= 0;
2172 /* Native (character set determined by locale) versions of the
2173 * strings source and destination strings. */
2174 LPSTR src_native
= 0;
2175 LPSTR dst_native
= 0;
2177 /* Version of the source and destination strings using the
2178 * "wchar_t" Unicode data type needed by various libc functions. */
2179 wchar_t *srcstr_libc
= 0;
2180 wchar_t *dststr_libc
= 0;
2182 if(!(srcstr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2183 srclen
* sizeof(wchar_t))))
2185 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2186 srclen
* sizeof(wchar_t));
2187 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2191 /* Convert source string to a libc Unicode string. */
2192 for(str_idx
= 0; str_idx
< srclen
; str_idx
++)
2194 srcstr_libc
[str_idx
] = srcstr
[str_idx
];
2197 /* src_native should contain at most 3 bytes for each
2198 * multibyte characters in the original srcstr string. */
2199 src_native_len
= 3 * srclen
;
2200 if(!(src_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
2203 ERR("Unable to allocate %d bytes for src_native\n", src_native_len
);
2204 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2205 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2209 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2210 * current value is backed up so it can be restored after the
2211 * last LC_COLLATE sensitive function returns.
2213 * Even though the locale is adjusted for a minimum amount of
2214 * time a race condition exists where other threads may be
2215 * affected if they invoke LC_COLLATE sensitive functions. One
2216 * possible solution is to wrap all LC_COLLATE sensitive Wine
2217 * functions, like LCMapStringW(), in a mutex.
2219 * Another enhancement to the following would be to set the
2220 * LC_COLLATE locale category as a function of the "lcid"
2221 * parameter instead of the "LC_COLLATE" environment variable. */
2222 if(!(lc_collate_default
= setlocale(LC_COLLATE
, NULL
)))
2224 ERR("Unable to query the LC_COLLATE catagory\n");
2225 SetLastError(ERROR_INVALID_PARAMETER
);
2226 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2227 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2231 if(!(lc_collate_env
= setlocale(LC_COLLATE
, "")))
2233 ERR("Unable to inherit the LC_COLLATE locale category from the "
2234 "environment. The \"LC_COLLATE\" environment variable is "
2235 "\"%s\".\n", getenv("LC_COLLATE") ?
2236 getenv("LC_COLLATE") : "<unset>");
2237 SetLastError(ERROR_INVALID_PARAMETER
);
2238 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2239 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2243 TRACE("lc_collate_default = %s\n", lc_collate_default
);
2244 TRACE("lc_collate_env = %s\n", lc_collate_env
);
2246 /* Convert the libc Unicode string to a native multibyte character
2248 returned_len
= wcstombs(src_native
, srcstr_libc
, src_native_len
) + 1;
2249 if(returned_len
== 0)
2251 LPSTR srcstr_ascii
= (LPSTR
)HEAP_strdupWtoA(GetProcessHeap(),
2253 ERR("wcstombs failed. The string specified (%s) may contains an "
2254 "invalid character.\n", srcstr_ascii
);
2255 SetLastError(ERROR_INVALID_PARAMETER
);
2256 if(srcstr_ascii
) HeapFree(GetProcessHeap(), 0, srcstr_ascii
);
2257 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2258 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2259 setlocale(LC_COLLATE
, lc_collate_default
);
2262 else if(returned_len
> src_native_len
)
2264 src_native
[src_native_len
- 1] = 0;
2265 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2266 "than expected (%d bytes).\n", src_native
, returned_len
,
2269 /* Since this is an internal error I'm not sure what the correct
2271 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2273 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2274 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2275 setlocale(LC_COLLATE
, lc_collate_default
);
2278 src_native_len
= returned_len
;
2280 TRACE("src_native = %s src_native_len = %d\n",
2281 src_native
, src_native_len
);
2283 /* dst_native seems to contain at most 4 bytes for each byte in
2284 * the original src_native string. Change if need be since this
2285 * isn't documented by the strxfrm() man page. */
2286 dst_native_len
= 4 * src_native_len
;
2287 if(!(dst_native
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, dst_native_len
)))
2289 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len
);
2290 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2291 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2292 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2293 setlocale(LC_COLLATE
, lc_collate_default
);
2297 /* The actual translation is done by the following call to
2298 * strxfrm(). The surrounding code could have been simplified
2299 * by calling wcsxfrm() instead except that wcsxfrm() is not
2300 * available on older Linux systems (RedHat 4.1 with
2303 * Also, it is possible that the translation could be done by
2304 * various tables as it is done in LCMapStringA(). However, I'm
2305 * not sure what those tables are. */
2306 returned_len
= strxfrm(dst_native
, src_native
, dst_native_len
) + 1;
2308 if(returned_len
> dst_native_len
)
2310 dst_native
[dst_native_len
- 1] = 0;
2311 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2312 "than expected (%d bytes).\n", dst_native
, returned_len
,
2315 /* Since this is an internal error I'm not sure what the correct
2317 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2319 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2320 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2321 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2322 setlocale(LC_COLLATE
, lc_collate_default
);
2325 dst_native_len
= returned_len
;
2327 TRACE("dst_native = %s dst_native_len = %d\n",
2328 dst_native
, dst_native_len
);
2330 dststr_libc_len
= dst_native_len
;
2331 if(!(dststr_libc
= (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2332 dststr_libc_len
* sizeof(wchar_t))))
2334 ERR("Unable to allocate %d bytes for dststr_libc\n",
2335 dststr_libc_len
* sizeof(wchar_t));
2336 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2337 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2338 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2339 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2340 setlocale(LC_COLLATE
, lc_collate_default
);
2344 /* Convert the native multibyte string to a libc Unicode string. */
2345 returned_len
= mbstowcs(dststr_libc
, dst_native
, dst_native_len
) + 1;
2347 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2348 * function has returned. */
2349 setlocale(LC_COLLATE
, lc_collate_default
);
2351 if(returned_len
== 0)
2353 ERR("mbstowcs failed. The native version of the translated string "
2354 "(%s) may contain an invalid character.\n", dst_native
);
2355 SetLastError(ERROR_INVALID_PARAMETER
);
2356 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2357 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2358 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2359 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2364 if(returned_len
> dstlen
)
2366 ERR("mbstowcs returned a string that was longer (%d chars) "
2367 "than the buffer provided (%d chars).\n", returned_len
,
2369 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2370 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2371 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2372 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2373 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2376 dstlen
= returned_len
;
2378 /* Convert a libc Unicode string to the destination string. */
2379 for(str_idx
= 0; str_idx
< dstlen
; str_idx
++)
2381 dststr
[str_idx
] = dststr_libc
[str_idx
];
2383 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2384 *(((int *)dststr
) + 0),
2385 *(((int *)dststr
) + 1),
2386 *(((int *)dststr
) + 2),
2387 *(((int *)dststr
) + 3));
2391 dstlen
= returned_len
;
2393 TRACE("dstlen (return) = %d\n", dstlen
);
2394 if(srcstr_libc
) HeapFree(GetProcessHeap(), 0, srcstr_libc
);
2395 if(src_native
) HeapFree(GetProcessHeap(), 0, src_native
);
2396 if(dst_native
) HeapFree(GetProcessHeap(), 0, dst_native
);
2397 if(dststr_libc
) HeapFree(GetProcessHeap(), 0, dststr_libc
);
2402 int (*f
)(int)=identity
;
2408 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2412 if (mapflags
& LCMAP_UPPERCASE
)
2414 else if (mapflags
& LCMAP_LOWERCASE
)
2416 for (i
=0; i
< srclen
; i
++)
2417 dststr
[i
] = (WCHAR
) f(srcstr
[i
]);
2423 /***********************************************************************
2424 * OLE2NLS_EstimateMappingLength
2426 * Estimates the number of characters required to hold the string
2427 * computed by LCMapStringA.
2429 * The size is always over-estimated, with a fixed limit on the
2430 * amount of estimation error.
2432 * Note that len == -1 is not permitted.
2434 static inline int OLE2NLS_EstimateMappingLength(LCID lcid
, DWORD dwMapFlags
,
2435 LPCSTR str
, DWORD len
)
2437 /* Estimate only for small strings to keep the estimation error from
2438 * becoming too large. */
2439 if (len
< 128) return len
* 8 + 5;
2440 else return LCMapStringA(lcid
, dwMapFlags
, str
, len
, NULL
, 0);
2443 /******************************************************************************
2444 * CompareStringA [KERNEL32.@]
2445 * Compares two strings using locale
2449 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2454 * Defaults to a word sort, but uses a string sort if
2455 * SORT_STRINGSORT is set.
2456 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2460 * This implementation ignores the locale
2464 * Quite inefficient.
2466 UINT WINAPI
CompareStringA(
2467 DWORD lcid
, /* [in] locale ID */
2468 DWORD fdwStyle
, /* [in] comparison-style options */
2469 LPCSTR s1
, /* [in] first string */
2470 DWORD l1
, /* [in] length of first string */
2471 LPCSTR s2
, /* [in] second string */
2472 DWORD l2
) /* [in] length of second string */
2474 int mapstring_flags
;
2478 TRACE("%s and %s\n",
2479 debugstr_a (s1
), debugstr_a (s2
));
2481 if ( (s1
==NULL
) || (s2
==NULL
) )
2483 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1
, s2
);
2484 SetLastError(ERROR_INVALID_PARAMETER
);
2488 if(fdwStyle
& NORM_IGNORESYMBOLS
)
2489 FIXME("IGNORESYMBOLS not supported\n");
2491 if (l1
== -1) l1
= strlen(s1
);
2492 if (l2
== -1) l2
= strlen(s2
);
2494 mapstring_flags
= LCMAP_SORTKEY
| fdwStyle
;
2495 len1
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s1
, l1
);
2496 len2
= OLE2NLS_EstimateMappingLength(lcid
, mapstring_flags
, s2
, l2
);
2498 if ((len1
==0)||(len2
==0))
2499 return 0; /* something wrong happened */
2501 sk1
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, len1
+ len2
);
2503 if ( (!LCMapStringA(lcid
,mapstring_flags
,s1
,l1
,sk1
,len1
))
2504 || (!LCMapStringA(lcid
,mapstring_flags
,s2
,l2
,sk2
,len2
)) )
2506 ERR("Bug in LCmapStringA.\n");
2511 /* strcmp doesn't necessarily return -1, 0, or 1 */
2512 result
= strcmp(sk1
,sk2
);
2514 HeapFree(GetProcessHeap(),0,sk1
);
2521 /* must be greater, if we reach this point */
2525 /******************************************************************************
2526 * CompareStringW [KERNEL32.@]
2527 * This implementation ignores the locale
2528 * FIXME : Does only string sort. Should
2529 * be reimplemented the same way as CompareStringA.
2531 UINT WINAPI
CompareStringW(DWORD lcid
, DWORD fdwStyle
,
2532 LPCWSTR s1
, DWORD l1
, LPCWSTR s2
,DWORD l2
)
2535 if(fdwStyle
& NORM_IGNORENONSPACE
)
2536 FIXME("IGNORENONSPACE not supprted\n");
2537 if(fdwStyle
& NORM_IGNORESYMBOLS
)
2538 FIXME("IGNORESYMBOLS not supported\n");
2540 /* Is strcmp defaulting to string sort or to word sort?? */
2541 /* FIXME: Handle NORM_STRINGSORT */
2542 l1
= (l1
==-1)?strlenW(s1
):l1
;
2543 l2
= (l2
==-1)?strlenW(s2
):l2
;
2544 len
= l1
<l2
? l1
:l2
;
2545 ret
= (fdwStyle
& NORM_IGNORECASE
) ? strncmpiW(s1
,s2
,len
) : strncmpW(s1
,s2
,len
);
2546 /* not equal, return 1 or 3 */
2548 /* need to translate result */
2549 return ((int)ret
< 0) ? 1 : 3;
2551 /* same len, return 2 */
2552 if(l1
==l2
) return 2;
2553 /* the longer one is lexically greater */
2554 return (l1
<l2
)? 1 : 3;
2557 /******************************************************************************
2558 * OLE_GetFormatA [Internal]
2561 * If datelen == 0, it should return the reguired string length.
2563 This function implements stuff for GetDateFormat() and
2566 d single-digit (no leading zero) day (of month)
2567 dd two-digit day (of month)
2568 ddd short day-of-week name
2569 dddd long day-of-week name
2570 M single-digit month
2572 MMM short month name
2573 MMMM full month name
2574 y two-digit year, no leading 0
2576 yyyy four-digit year
2578 h hours with no leading zero (12-hour)
2579 hh hours with full two digits
2580 H hours with no leading zero (24-hour)
2581 HH hours with full two digits
2582 m minutes with no leading zero
2583 mm minutes with full two digits
2584 s seconds with no leading zero
2585 ss seconds with full two digits
2586 t time marker (A or P)
2587 tt time marker (AM, PM)
2588 '' used to quote literal characters
2589 '' (within a quoted string) indicates a literal '
2591 These functions REQUIRE valid locale, date, and format.
2593 static INT
OLE_GetFormatA(LCID locale
,
2597 LPCSTR _format
, /*in*/
2602 int count
, type
, inquote
, Overflow
;
2608 const char * _dgfmt
[] = { "%d", "%02d" };
2609 const char ** dgfmt
= _dgfmt
- 1;
2611 /* report, for debugging */
2612 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",
2613 locale
, flags
, tflags
,
2614 xtime
->wYear
,xtime
->wMonth
,xtime
->wDayOfWeek
,xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2615 _format
, _format
, date
, datelen
);
2618 FIXME("datelen = 0, returning 255\n");
2622 /* initalize state variables and output buffer */
2624 count
= 0; inquote
= 0; Overflow
= 0;
2626 date
[0] = buf
[0] = '\0';
2628 strcpy(format
,_format
);
2630 /* alter the formatstring, while it works for all languages now in wine
2631 its possible that it fails when the time looks like ss:mm:hh as example*/
2632 if (tflags
& (TIME_NOMINUTESORSECONDS
))
2633 { if ((pos
= strstr ( format
, ":mm")))
2634 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2637 if (tflags
& (TIME_NOSECONDS
))
2638 { if ((pos
= strstr ( format
, ":ss")))
2639 { memcpy ( pos
, pos
+3, strlen(format
)-(pos
-format
)-2 );
2643 for (inpos
= 0;; inpos
++) {
2644 /* 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]); */
2646 if (format
[inpos
] == '\'') {
2647 if (format
[inpos
+1] == '\'') {
2649 date
[outpos
++] = '\'';
2652 continue; /* we did nothing to the output */
2654 } else if (format
[inpos
] == '\0') {
2655 date
[outpos
++] = '\0';
2656 if (outpos
> datelen
) Overflow
= 1;
2659 date
[outpos
++] = format
[inpos
];
2660 if (outpos
> datelen
) {
2662 date
[outpos
-1] = '\0'; /* this is the last place where
2663 it's safe to write */
2667 } else if ( (count
&& (format
[inpos
] != type
))
2669 || (count
== 2 && strchr("ghHmst", type
)) ) {
2670 if (type
== 'h' && (tflags
& TIME_FORCE24HOURFORMAT
)) type
= 'H';
2673 GetLocaleInfoA(locale
,
2675 + (xtime
->wDayOfWeek
+6)%7,
2677 } else if (count
== 3) {
2678 GetLocaleInfoA(locale
,
2679 LOCALE_SABBREVDAYNAME1
2680 + (xtime
->wDayOfWeek
+6)%7,
2683 sprintf(buf
, dgfmt
[count
], xtime
->wDay
);
2685 } else if (type
== 'M') {
2687 GetLocaleInfoA(locale
,
2688 LOCALE_SABBREVMONTHNAME1
2689 + xtime
->wMonth
- 1,
2691 } else if (count
== 4) {
2692 GetLocaleInfoA(locale
,
2694 + xtime
->wMonth
- 1,
2697 sprintf(buf
, dgfmt
[count
], xtime
->wMonth
);
2699 } else if (type
== 'y') {
2701 sprintf(buf
, "%d", xtime
->wYear
);
2702 } else if (count
== 3) {
2704 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2706 sprintf(buf
, dgfmt
[count
], xtime
->wYear
% 100);
2708 } else if (type
== 'g') {
2710 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2714 WARN("unknown format, c=%c, n=%d\n", type
, count
);
2716 } else if (type
== 'h') {
2717 /* gives us hours 1:00 -- 12:00 */
2718 sprintf(buf
, dgfmt
[count
], (xtime
->wHour
-1)%12 +1);
2719 } else if (type
== 'H') {
2721 sprintf(buf
, dgfmt
[count
], xtime
->wHour
);
2722 } else if ( type
== 'm') {
2723 sprintf(buf
, dgfmt
[count
], xtime
->wMinute
);
2724 } else if ( type
== 's') {
2725 sprintf(buf
, dgfmt
[count
], xtime
->wSecond
);
2726 } else if (type
== 't') {
2727 if ((tflags
& TIME_NOTIMEMARKER
))
2729 else if (count
== 1) {
2730 sprintf(buf
, "%c", (xtime
->wHour
< 12) ? 'A' : 'P');
2731 } else if (count
== 2) {
2732 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2733 GetLocaleInfoA(locale
,
2735 ? LOCALE_S1159
: LOCALE_S2359
,
2740 /* we need to check the next char in the format string
2741 again, no matter what happened */
2744 /* add the contents of buf to the output */
2745 buflen
= strlen(buf
);
2746 if (outpos
+ buflen
< datelen
) {
2747 date
[outpos
] = '\0'; /* for strcat to hook onto */
2751 date
[outpos
] = '\0';
2752 strncat(date
, buf
, datelen
- outpos
);
2753 date
[datelen
- 1] = '\0';
2754 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2755 WARN("insufficient buffer\n");
2759 /* reset the variables we used to keep track of this item */
2762 } else if (format
[inpos
] == '\0') {
2763 /* we can't check for this at the loop-head, because
2764 that breaks the printing of the last format-item */
2765 date
[outpos
] = '\0';
2768 /* continuing a code for an item */
2771 } else if (strchr("hHmstyMdg", format
[inpos
])) {
2772 type
= format
[inpos
];
2775 } else if (format
[inpos
] == '\'') {
2779 date
[outpos
++] = format
[inpos
];
2781 /* now deal with a possible buffer overflow */
2782 if (outpos
>= datelen
) {
2783 date
[datelen
- 1] = '\0';
2784 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2790 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2793 /* finish it off with a string terminator */
2796 if (outpos
> datelen
-1) outpos
= datelen
-1;
2797 date
[outpos
] = '\0';
2799 TRACE("returns string '%s', len %d\n", date
, outpos
);
2803 /******************************************************************************
2804 * OLE_GetFormatW [INTERNAL]
2806 static INT
OLE_GetFormatW(LCID locale
, DWORD flags
, DWORD tflags
,
2809 LPWSTR output
, INT outlen
)
2812 int count
, type
=0, inquote
;
2813 int Overflow
; /* loop check */
2817 WCHAR arg0
[] = {0}, arg1
[] = {'%','d',0};
2818 WCHAR arg2
[] = {'%','0','2','d',0};
2820 int datevars
=0, timevars
=0;
2826 /* make a debug report */
2827 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2828 "%p with max len %d\n",
2829 locale
, flags
, tflags
,
2830 xtime
->wDay
, xtime
->wHour
, xtime
->wMinute
, xtime
->wSecond
,
2831 debugstr_w(format
), format
, output
, outlen
);
2834 FIXME("outlen = 0, returning 255\n");
2838 /* initialize state variables */
2841 inquote
= Overflow
= 0;
2842 /* this is really just a sanity check */
2843 output
[0] = buf
[0] = 0;
2845 /* this loop is the core of the function */
2846 for (inpos
= 0; /* we have several break points */ ; inpos
++) {
2848 if (format
[inpos
] == (WCHAR
) '\'') {
2849 if (format
[inpos
+1] == '\'') {
2851 output
[outpos
++] = '\'';
2856 } else if (format
[inpos
] == 0) {
2857 output
[outpos
++] = 0;
2858 if (outpos
> outlen
) Overflow
= 1;
2859 break; /* normal exit (within a quote) */
2861 output
[outpos
++] = format
[inpos
]; /* copy input */
2862 if (outpos
> outlen
) {
2864 output
[outpos
-1] = 0;
2868 } else if ( (count
&& (format
[inpos
] != type
))
2869 || ( (count
==4 && type
=='y') ||
2870 (count
==4 && type
=='M') ||
2871 (count
==4 && type
=='d') ||
2872 (count
==2 && type
=='g') ||
2873 (count
==2 && type
=='h') ||
2874 (count
==2 && type
=='H') ||
2875 (count
==2 && type
=='m') ||
2876 (count
==2 && type
=='s') ||
2877 (count
==2 && type
=='t') ) ) {
2882 GetLocaleInfoW(locale
,
2883 LOCALE_SDAYNAME1
+ (xtime
->wDayOfWeek
+6)%7,
2884 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2885 } else if (count
== 3) {
2886 GetLocaleInfoW(locale
,
2887 LOCALE_SABBREVDAYNAME1
+
2888 (xtime
->wDayOfWeek
+6)%7,
2889 buf
, sizeof(buf
)/sizeof(WCHAR
) );
2891 sprintf( tmp
, "%.*d", count
, xtime
->wDay
);
2892 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2898 GetLocaleInfoW(locale
, LOCALE_SMONTHNAME1
+
2899 xtime
->wMonth
-1, buf
,
2900 sizeof(buf
)/sizeof(WCHAR
) );
2901 } else if (count
== 3) {
2902 GetLocaleInfoW(locale
, LOCALE_SABBREVMONTHNAME1
+
2903 xtime
->wMonth
-1, buf
,
2904 sizeof(buf
)/sizeof(WCHAR
) );
2906 sprintf( tmp
, "%.*d", count
, xtime
->wMonth
);
2907 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2912 sprintf( tmp
, "%d", xtime
->wYear
);
2913 } else if (count
== 3) {
2914 strcpy( tmp
, "yyy" );
2916 sprintf( tmp
, "%.*d", count
, xtime
->wYear
% 100 );
2918 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2923 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2924 strcpy( tmp
, "AD" );
2926 /* Win API sez we copy it verbatim */
2929 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2933 /* hours 1:00-12:00 --- is this right? */
2934 sprintf( tmp
, "%.*d", count
, (xtime
->wHour
-1)%12 +1);
2935 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2939 sprintf( tmp
, "%.*d", count
, xtime
->wHour
);
2940 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2944 sprintf( tmp
, "%.*d", count
, xtime
->wMinute
);
2945 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2949 sprintf( tmp
, "%.*d", count
, xtime
->wSecond
);
2950 MultiByteToWideChar( CP_ACP
, 0, tmp
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
) );
2954 GetLocaleInfoW(locale
, (xtime
->wHour
< 12) ?
2955 LOCALE_S1159
: LOCALE_S2359
,
2963 /* no matter what happened, we need to check this next
2964 character the next time we loop through */
2967 /* cat buf onto the output */
2968 outlen
= strlenW(buf
);
2969 if (outpos
+ buflen
< outlen
) {
2970 strcpyW( output
+ outpos
, buf
);
2973 lstrcpynW( output
+ outpos
, buf
, outlen
- outpos
);
2975 break; /* Abnormal exit */
2978 /* reset the variables we used this time */
2981 } else if (format
[inpos
] == 0) {
2982 /* we can't check for this at the beginning, because that
2983 would keep us from printing a format spec that ended the
2986 break; /* NORMAL EXIT */
2988 /* how we keep track of the middle of a format spec */
2991 } else if ( (datevars
&& (format
[inpos
]=='d' ||
2992 format
[inpos
]=='M' ||
2993 format
[inpos
]=='y' ||
2994 format
[inpos
]=='g') ) ||
2995 (timevars
&& (format
[inpos
]=='H' ||
2996 format
[inpos
]=='h' ||
2997 format
[inpos
]=='m' ||
2998 format
[inpos
]=='s' ||
2999 format
[inpos
]=='t') ) ) {
3000 type
= format
[inpos
];
3003 } else if (format
[inpos
] == '\'') {
3007 /* unquoted literals */
3008 output
[outpos
++] = format
[inpos
];
3013 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3014 WARN(" buffer overflow\n");
3017 /* final string terminator and sanity check */
3019 if (outpos
> outlen
-1) outpos
= outlen
-1;
3020 output
[outpos
] = '0';
3022 TRACE(" returning %s\n", debugstr_w(output
));
3024 return (!Overflow
) ? outlen
: 0;
3029 /******************************************************************************
3030 * GetDateFormatA [KERNEL32.@]
3031 * Makes an ASCII string of the date
3033 * This function uses format to format the date, or, if format
3034 * is NULL, uses the default for the locale. format is a string
3035 * of literal fields and characters as follows:
3037 * - d single-digit (no leading zero) day (of month)
3038 * - dd two-digit day (of month)
3039 * - ddd short day-of-week name
3040 * - dddd long day-of-week name
3041 * - M single-digit month
3042 * - MM two-digit month
3043 * - MMM short month name
3044 * - MMMM full month name
3045 * - y two-digit year, no leading 0
3046 * - yy two-digit year
3047 * - yyyy four-digit year
3051 INT WINAPI
GetDateFormatA(LCID locale
,DWORD flags
,
3053 LPCSTR format
, LPSTR date
,INT datelen
)
3056 char format_buf
[40];
3059 LPSYSTEMTIME thistime
;
3065 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
3066 locale
,flags
,xtime
,format
,date
,datelen
);
3069 locale
= LOCALE_SYSTEM_DEFAULT
;
3072 if (locale
== LOCALE_SYSTEM_DEFAULT
) {
3073 thislocale
= GetSystemDefaultLCID();
3074 } else if (locale
== LOCALE_USER_DEFAULT
) {
3075 thislocale
= GetUserDefaultLCID();
3077 thislocale
= locale
;
3080 if (xtime
== NULL
) {
3083 /* Silently correct wDayOfWeek by tranforming to FileTime and back again*/
3084 res
=SystemTimeToFileTime(xtime
,&ft
);
3085 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error*/
3086 /*FIXME: SystemTimeToFileTime doesn't yet do that ckeck*/
3089 SetLastError(ERROR_INVALID_PARAMETER
);
3092 FileTimeToSystemTime(&ft
,&t
);
3097 if (format
== NULL
) {
3098 GetLocaleInfoA(thislocale
, ((flags
&DATE_LONGDATE
)
3100 : LOCALE_SSHORTDATE
),
3101 format_buf
, sizeof(format_buf
));
3102 thisformat
= format_buf
;
3104 thisformat
= format
;
3108 ret
= OLE_GetFormatA(thislocale
, flags
, 0, thistime
, thisformat
,
3113 "GetDateFormatA() returning %d, with data=%s\n",
3118 /******************************************************************************
3119 * GetDateFormatW [KERNEL32.@]
3120 * Makes a Unicode string of the date
3122 * Acts the same as GetDateFormatA(), except that it's Unicode.
3123 * Accepts & returns sizes as counts of Unicode characters.
3126 INT WINAPI
GetDateFormatW(LCID locale
,DWORD flags
,
3129 LPWSTR date
, INT datelen
)
3131 unsigned short datearr
[] = {'1','9','9','4','-','1','-','1',0};
3133 FIXME("STUB (should call OLE_GetFormatW)\n");
3134 lstrcpynW(date
, datearr
, datelen
);
3135 return ( datelen
< 9) ? datelen
: 9;
3140 /**************************************************************************
3141 * EnumDateFormatsA (KERNEL32.@)
3143 BOOL WINAPI
EnumDateFormatsA(
3144 DATEFMT_ENUMPROCA lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3146 LCID Loc
= GetUserDefaultLCID();
3147 if(!lpDateFmtEnumProc
)
3149 SetLastError(ERROR_INVALID_PARAMETER
);
3156 case 0x00000407: /* (Loc,"de_DE") */
3160 case DATE_SHORTDATE
:
3161 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
3162 if(!(*lpDateFmtEnumProc
)("d.M.yyyy")) return TRUE
;
3163 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
3164 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3167 if(!(*lpDateFmtEnumProc
)("dddd,d. MMMM yyyy")) return TRUE
;
3168 if(!(*lpDateFmtEnumProc
)("d. MMMM yyyy")) return TRUE
;
3169 if(!(*lpDateFmtEnumProc
)("d. MMM yyyy")) return TRUE
;
3172 FIXME("Unknown date format (%ld)\n", dwFlags
);
3173 SetLastError(ERROR_INVALID_PARAMETER
);
3178 case 0x0000040c: /* (Loc,"fr_FR") */
3182 case DATE_SHORTDATE
:
3183 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3184 if(!(*lpDateFmtEnumProc
)("dd.MM.yy")) return TRUE
;
3185 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3186 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3189 if(!(*lpDateFmtEnumProc
)("dddd d MMMM yyyy")) return TRUE
;
3190 if(!(*lpDateFmtEnumProc
)("d MMM yy")) return TRUE
;
3191 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3194 FIXME("Unknown date format (%ld)\n", dwFlags
);
3195 SetLastError(ERROR_INVALID_PARAMETER
);
3200 case 0x00000c0c: /* (Loc,"fr_CA") */
3204 case DATE_SHORTDATE
:
3205 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3206 if(!(*lpDateFmtEnumProc
)("dd-MM-yy")) return TRUE
;
3207 if(!(*lpDateFmtEnumProc
)("yy MM dd")) return TRUE
;
3208 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3211 if(!(*lpDateFmtEnumProc
)("d MMMM, yyyy")) return TRUE
;
3212 if(!(*lpDateFmtEnumProc
)("d MMM yyyy")) return TRUE
;
3215 FIXME("Unknown date format (%ld)\n", dwFlags
);
3216 SetLastError(ERROR_INVALID_PARAMETER
);
3221 case 0x00000809: /* (Loc,"en_UK") */
3225 case DATE_SHORTDATE
:
3226 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3227 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3228 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3229 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3232 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3233 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3236 FIXME("Unknown date format (%ld)\n", dwFlags
);
3237 SetLastError(ERROR_INVALID_PARAMETER
);
3242 case 0x00000c09: /* (Loc,"en_AU") */
3246 case DATE_SHORTDATE
:
3247 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3248 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3249 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3252 if(!(*lpDateFmtEnumProc
)("dddd,d MMMM yyyy")) return TRUE
;
3253 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3256 FIXME("Unknown date format (%ld)\n", dwFlags
);
3257 SetLastError(ERROR_INVALID_PARAMETER
);
3262 case 0x00001009: /* (Loc,"en_CA") */
3266 case DATE_SHORTDATE
:
3267 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3268 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3269 if(!(*lpDateFmtEnumProc
)("yy-MM-dd")) return TRUE
;
3270 if(!(*lpDateFmtEnumProc
)("M/dd/yy")) return TRUE
;
3273 if(!(*lpDateFmtEnumProc
)("d-MMM-yy")) return TRUE
;
3274 if(!(*lpDateFmtEnumProc
)("MMMM d, yyyy")) return TRUE
;
3277 FIXME("Unknown date format (%ld)\n", dwFlags
);
3278 SetLastError(ERROR_INVALID_PARAMETER
);
3283 case 0x00001409: /* (Loc,"en_NZ") */
3287 case DATE_SHORTDATE
:
3288 if(!(*lpDateFmtEnumProc
)("d/MM/yy")) return TRUE
;
3289 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3290 if(!(*lpDateFmtEnumProc
)("d.MM.yy")) return TRUE
;
3293 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3294 if(!(*lpDateFmtEnumProc
)("dddd, d MMMM yyyy")) return TRUE
;
3297 FIXME("Unknown date format (%ld)\n", dwFlags
);
3298 SetLastError(ERROR_INVALID_PARAMETER
);
3303 case 0x00001809: /* (Loc,"en_IE") */
3307 case DATE_SHORTDATE
:
3308 if(!(*lpDateFmtEnumProc
)("dd/MM/yy")) return TRUE
;
3309 if(!(*lpDateFmtEnumProc
)("d/M/yy")) return TRUE
;
3310 if(!(*lpDateFmtEnumProc
)("d.M.yy")) return TRUE
;
3313 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3314 if(!(*lpDateFmtEnumProc
)("d MMMM yyyy")) return TRUE
;
3317 FIXME("Unknown date format (%ld)\n", dwFlags
);
3318 SetLastError(ERROR_INVALID_PARAMETER
);
3323 case 0x00001c09: /* (Loc,"en_ZA") */
3327 case DATE_SHORTDATE
:
3328 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3331 if(!(*lpDateFmtEnumProc
)("dd MMMM yyyy")) return TRUE
;
3334 FIXME("Unknown date format (%ld)\n", dwFlags
);
3335 SetLastError(ERROR_INVALID_PARAMETER
);
3340 case 0x00002009: /* (Loc,"en_JM") */
3344 case DATE_SHORTDATE
:
3345 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3348 if(!(*lpDateFmtEnumProc
)("dddd,MMMM dd,yyyy")) return TRUE
;
3349 if(!(*lpDateFmtEnumProc
)("MMMM dd,yyyy")) return TRUE
;
3350 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM,yyyy")) return TRUE
;
3351 if(!(*lpDateFmtEnumProc
)("dd MMMM,yyyy")) return TRUE
;
3354 FIXME("Unknown date format (%ld)\n", dwFlags
);
3355 SetLastError(ERROR_INVALID_PARAMETER
);
3360 case 0x00002809: /* (Loc,"en_BZ") */
3361 case 0x00002c09: /* (Loc,"en_TT") */
3365 case DATE_SHORTDATE
:
3366 if(!(*lpDateFmtEnumProc
)("dd/MM/yyyy")) return TRUE
;
3369 if(!(*lpDateFmtEnumProc
)("dddd,dd MMMM yyyy")) return TRUE
;
3372 FIXME("Unknown date format (%ld)\n", dwFlags
);
3373 SetLastError(ERROR_INVALID_PARAMETER
);
3378 default: /* default to US English "en_US" */
3382 case DATE_SHORTDATE
:
3383 if(!(*lpDateFmtEnumProc
)("M/d/yy")) return TRUE
;
3384 if(!(*lpDateFmtEnumProc
)("M/d/yyyy")) return TRUE
;
3385 if(!(*lpDateFmtEnumProc
)("MM/dd/yy")) return TRUE
;
3386 if(!(*lpDateFmtEnumProc
)("MM/dd/yyyy")) return TRUE
;
3387 if(!(*lpDateFmtEnumProc
)("yy/MM/dd")) return TRUE
;
3388 if(!(*lpDateFmtEnumProc
)("dd-MMM-yy")) return TRUE
;
3391 if(!(*lpDateFmtEnumProc
)("dddd, MMMM dd, yyyy")) return TRUE
;
3392 if(!(*lpDateFmtEnumProc
)("MMMM dd, yyyy")) return TRUE
;
3393 if(!(*lpDateFmtEnumProc
)("dddd, dd MMMM, yyyy")) return TRUE
;
3394 if(!(*lpDateFmtEnumProc
)("dd MMMM, yyyy")) return TRUE
;
3397 FIXME("Unknown date format (%ld)\n", dwFlags
);
3398 SetLastError(ERROR_INVALID_PARAMETER
);
3405 /**************************************************************************
3406 * EnumDateFormatsW (KERNEL32.@)
3408 BOOL WINAPI
EnumDateFormatsW(
3409 DATEFMT_ENUMPROCW lpDateFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3411 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc
, Locale
, dwFlags
);
3412 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3416 /**************************************************************************
3417 * EnumTimeFormatsA (KERNEL32.@)
3419 BOOL WINAPI
EnumTimeFormatsA(
3420 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3422 LCID Loc
= GetUserDefaultLCID();
3423 if(!lpTimeFmtEnumProc
)
3425 SetLastError(ERROR_INVALID_PARAMETER
);
3430 FIXME("Unknown time format (%ld)\n", dwFlags
);
3435 case 0x00000407: /* (Loc,"de_DE") */
3437 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3438 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3439 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3440 if(!(*lpTimeFmtEnumProc
)("H.mm")) return TRUE
;
3441 if(!(*lpTimeFmtEnumProc
)("H.mm'Uhr'")) return TRUE
;
3445 case 0x0000040c: /* (Loc,"fr_FR") */
3446 case 0x00000c0c: /* (Loc,"fr_CA") */
3448 if(!(*lpTimeFmtEnumProc
)("H:mm")) return TRUE
;
3449 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3450 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3451 if(!(*lpTimeFmtEnumProc
)("HH.mm")) return TRUE
;
3452 if(!(*lpTimeFmtEnumProc
)("HH'h'mm")) return TRUE
;
3456 case 0x00000809: /* (Loc,"en_UK") */
3457 case 0x00000c09: /* (Loc,"en_AU") */
3458 case 0x00001409: /* (Loc,"en_NZ") */
3459 case 0x00001809: /* (Loc,"en_IE") */
3461 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3462 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3463 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3467 case 0x00001c09: /* (Loc,"en_ZA") */
3468 case 0x00002809: /* (Loc,"en_BZ") */
3469 case 0x00002c09: /* (Loc,"en_TT") */
3471 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3472 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3476 default: /* default to US style "en_US" */
3478 if(!(*lpTimeFmtEnumProc
)("h:mm:ss tt")) return TRUE
;
3479 if(!(*lpTimeFmtEnumProc
)("hh:mm:ss tt")) return TRUE
;
3480 if(!(*lpTimeFmtEnumProc
)("H:mm:ss")) return TRUE
;
3481 if(!(*lpTimeFmtEnumProc
)("HH:mm:ss")) return TRUE
;
3487 /**************************************************************************
3488 * EnumTimeFormatsW (KERNEL32.@)
3490 BOOL WINAPI
EnumTimeFormatsW(
3491 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc
, LCID Locale
, DWORD dwFlags
)
3493 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc
, Locale
, dwFlags
);
3494 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3498 /**************************************************************************
3499 * This function is used just locally !
3500 * Description: Inverts a string.
3502 static void OLE_InvertString(char* string
)
3504 char sTmpArray
[128];
3507 for (counter
= strlen(string
); counter
> 0; counter
--)
3509 memcpy(sTmpArray
+ i
, string
+ counter
-1, 1);
3512 memcpy(sTmpArray
+ i
, "\0", 1);
3513 strcpy(string
, sTmpArray
);
3516 /***************************************************************************************
3517 * This function is used just locally !
3518 * Description: Test if the given string (psNumber) is valid or not.
3519 * The valid characters are the following:
3520 * - Characters '0' through '9'.
3521 * - One decimal point (dot) if the number is a floating-point value.
3522 * - A minus sign in the first character position if the number is
3524 * If the function succeeds, psBefore/psAfter will point to the string
3525 * on the right/left of the decimal symbol. pbNegative indicates if the
3526 * number is negative.
3528 static INT
OLE_GetNumberComponents(char* pInput
, char* psBefore
, char* psAfter
, BOOL
* pbNegative
)
3530 char sNumberSet
[] = "0123456789";
3531 BOOL bInDecimal
= FALSE
;
3533 /* Test if we do have a minus sign */
3534 if ( *pInput
== '-' )
3537 pInput
++; /* Jump to the next character. */
3540 while(*pInput
!= '\0')
3542 /* Do we have a valid numeric character */
3543 if ( strchr(sNumberSet
, *pInput
) != NULL
)
3545 if (bInDecimal
== TRUE
)
3546 *psAfter
++ = *pInput
;
3548 *psBefore
++ = *pInput
;
3552 /* Is this a decimal point (dot) */
3553 if ( *pInput
== '.' )
3555 /* Is it the first time we find it */
3556 if ((bInDecimal
== FALSE
))
3559 return -1; /* ERROR: Invalid parameter */
3563 /* It's neither a numeric character, nor a decimal point.
3564 * Thus, return an error.
3572 /* Add an End of Line character to the output buffers */
3579 /**************************************************************************
3580 * This function is used just locally !
3581 * Description: A number could be formatted using different numbers
3582 * of "digits in group" (example: 4;3;2;0).
3583 * The first parameter of this function is an array
3584 * containing the rule to be used. It's format is the following:
3585 * |NDG|DG1|DG2|...|0|
3586 * where NDG is the number of used "digits in group" and DG1, DG2,
3587 * are the corresponding "digits in group".
3588 * Thus, this function returns the grouping value in the array
3589 * pointed by the second parameter.
3591 static INT
OLE_GetGrouping(char* sRule
, INT index
)
3593 char sData
[2], sRuleSize
[2];
3594 INT nData
, nRuleSize
;
3596 memcpy(sRuleSize
, sRule
, 1);
3597 memcpy(sRuleSize
+1, "\0", 1);
3598 nRuleSize
= atoi(sRuleSize
);
3600 if (index
> 0 && index
< nRuleSize
)
3602 memcpy(sData
, sRule
+index
, 1);
3603 memcpy(sData
+1, "\0", 1);
3604 nData
= atoi(sData
);
3609 memcpy(sData
, sRule
+nRuleSize
-1, 1);
3610 memcpy(sData
+1, "\0", 1);
3611 nData
= atoi(sData
);
3617 /**************************************************************************
3618 * GetNumberFormatA (KERNEL32.@)
3620 INT WINAPI
GetNumberFormatA(LCID locale
, DWORD dwflags
,
3621 LPCSTR lpvalue
, const NUMBERFMTA
* lpFormat
,
3622 LPSTR lpNumberStr
, int cchNumber
)
3624 char sNumberDigits
[3], sDecimalSymbol
[5], sDigitsInGroup
[11], sDigitGroupSymbol
[5], sILZero
[2];
3625 INT nNumberDigits
, nNumberDecimal
, i
, j
, nCounter
, nStep
, nRuleIndex
, nGrouping
, nDigits
, retVal
, nLZ
;
3626 char sNumber
[128], sDestination
[128], sDigitsAfterDecimal
[10], sDigitsBeforeDecimal
[128];
3627 char sRule
[10], sSemiColumn
[]=";", sBuffer
[5], sNegNumber
[2];
3628 char *pStr
= NULL
, *pTmpStr
= NULL
;
3629 LCID systemDefaultLCID
;
3630 BOOL bNegative
= FALSE
;
3639 strncpy(sNumber
, lpvalue
, 128);
3640 sNumber
[127] = '\0';
3642 /* Make sure we have a valid input string, get the number
3643 * of digits before and after the decimal symbol, and check
3644 * if this is a negative number.
3646 if ( OLE_GetNumberComponents(sNumber
, sDigitsBeforeDecimal
, sDigitsAfterDecimal
, &bNegative
) != -1)
3648 nNumberDecimal
= strlen(sDigitsBeforeDecimal
);
3649 nDigits
= strlen(sDigitsAfterDecimal
);
3653 SetLastError(ERROR_INVALID_PARAMETER
);
3657 /* Which source will we use to format the string */
3658 used_operation
= RETURN_ERROR
;
3659 if (lpFormat
!= NULL
)
3662 used_operation
= USE_PARAMETER
;
3666 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3667 used_operation
= USE_LOCALEINFO
;
3669 used_operation
= USE_SYSTEMDEFAULT
;
3672 /* Load the fields we need */
3673 switch(used_operation
)
3675 case USE_LOCALEINFO
:
3676 GetLocaleInfoA(locale
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3677 GetLocaleInfoA(locale
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3678 GetLocaleInfoA(locale
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3679 GetLocaleInfoA(locale
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3680 GetLocaleInfoA(locale
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3681 GetLocaleInfoA(locale
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3684 sprintf(sNumberDigits
, "%d",lpFormat
->NumDigits
);
3685 strcpy(sDecimalSymbol
, lpFormat
->lpDecimalSep
);
3686 sprintf(sDigitsInGroup
, "%d;0",lpFormat
->Grouping
);
3687 strcpy(sDigitGroupSymbol
, lpFormat
->lpThousandSep
);
3688 sprintf(sILZero
, "%d",lpFormat
->LeadingZero
);
3689 sprintf(sNegNumber
, "%d",lpFormat
->NegativeOrder
);
3691 case USE_SYSTEMDEFAULT
:
3692 systemDefaultLCID
= GetSystemDefaultLCID();
3693 GetLocaleInfoA(systemDefaultLCID
, LOCALE_IDIGITS
, sNumberDigits
, sizeof(sNumberDigits
));
3694 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SDECIMAL
, sDecimalSymbol
, sizeof(sDecimalSymbol
));
3695 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SGROUPING
, sDigitsInGroup
, sizeof(sDigitsInGroup
));
3696 GetLocaleInfoA(systemDefaultLCID
, LOCALE_STHOUSAND
, sDigitGroupSymbol
, sizeof(sDigitGroupSymbol
));
3697 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ILZERO
, sILZero
, sizeof(sILZero
));
3698 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGNUMBER
, sNegNumber
, sizeof(sNegNumber
));
3701 SetLastError(ERROR_INVALID_PARAMETER
);
3705 nNumberDigits
= atoi(sNumberDigits
);
3707 /* Remove the ";" */
3710 for (nCounter
=0; nCounter
<strlen(sDigitsInGroup
); nCounter
++)
3712 if ( memcmp(sDigitsInGroup
+ nCounter
, sSemiColumn
, 1) != 0 )
3714 memcpy(sRule
+ j
, sDigitsInGroup
+ nCounter
, 1);
3719 sprintf(sBuffer
, "%d", i
);
3720 memcpy(sRule
, sBuffer
, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3721 memcpy(sRule
+ j
, "\0", 1);
3723 /* First, format the digits before the decimal. */
3724 if ((nNumberDecimal
>0) && (atoi(sDigitsBeforeDecimal
) != 0))
3726 /* Working on an inverted string is easier ! */
3727 OLE_InvertString(sDigitsBeforeDecimal
);
3729 nStep
= nCounter
= i
= j
= 0;
3731 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3733 /* Here, we will loop until we reach the end of the string.
3734 * An internal counter (j) is used in order to know when to
3735 * insert the "digit group symbol".
3737 while (nNumberDecimal
> 0)
3739 i
= nCounter
+ nStep
;
3740 memcpy(sDestination
+ i
, sDigitsBeforeDecimal
+ nCounter
, 1);
3746 if (nRuleIndex
< sRule
[0])
3748 nGrouping
= OLE_GetGrouping(sRule
, nRuleIndex
);
3749 memcpy(sDestination
+ i
+1, sDigitGroupSymbol
, strlen(sDigitGroupSymbol
));
3750 nStep
+= strlen(sDigitGroupSymbol
);
3756 memcpy(sDestination
+ i
+1, "\0", 1);
3757 /* Get the string in the right order ! */
3758 OLE_InvertString(sDestination
);
3762 nLZ
= atoi(sILZero
);
3765 /* Use 0.xxx instead of .xxx */
3766 memcpy(sDestination
, "0", 1);
3767 memcpy(sDestination
+1, "\0", 1);
3770 memcpy(sDestination
, "\0", 1);
3774 /* Second, format the digits after the decimal. */
3776 nCounter
= nNumberDigits
;
3777 if ( (nDigits
>0) && (pStr
= strstr (sNumber
, ".")) )
3779 i
= strlen(sNumber
) - strlen(pStr
) + 1;
3780 strncpy ( sDigitsAfterDecimal
, sNumber
+ i
, nNumberDigits
);
3781 j
= strlen(sDigitsAfterDecimal
);
3782 if (j
< nNumberDigits
)
3783 nCounter
= nNumberDigits
-j
;
3785 for (i
=0;i
<nCounter
;i
++)
3786 memcpy(sDigitsAfterDecimal
+i
+j
, "0", 1);
3787 memcpy(sDigitsAfterDecimal
+ nNumberDigits
, "\0", 1);
3789 i
= strlen(sDestination
);
3790 j
= strlen(sDigitsAfterDecimal
);
3791 /* Finally, construct the resulting formatted string. */
3793 for (nCounter
=0; nCounter
<i
; nCounter
++)
3794 memcpy(sNumber
+ nCounter
, sDestination
+ nCounter
, 1);
3796 memcpy(sNumber
+ nCounter
, sDecimalSymbol
, strlen(sDecimalSymbol
));
3799 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), sDigitsAfterDecimal
+ i
, 1);
3800 memcpy(sNumber
+ nCounter
+i
+strlen(sDecimalSymbol
), "\0", 1);
3802 /* Is it a negative number */
3803 if (bNegative
== TRUE
)
3805 i
= atoi(sNegNumber
);
3806 pStr
= sDestination
;
3812 while (*sNumber
!= '\0')
3813 *pStr
++ = *pTmpStr
++;
3818 while (*pTmpStr
!= '\0')
3819 *pStr
++ = *pTmpStr
++;
3824 while (*pTmpStr
!= '\0')
3825 *pStr
++ = *pTmpStr
++;
3828 while (*pTmpStr
!= '\0')
3829 *pStr
++ = *pTmpStr
++;
3833 while (*pTmpStr
!= '\0')
3834 *pStr
++ = *pTmpStr
++;
3839 while (*pTmpStr
!= '\0')
3840 *pStr
++ = *pTmpStr
++;
3845 strcpy(sDestination
, sNumber
);
3847 /* If cchNumber is zero, then returns the number of bytes or characters
3848 * required to hold the formatted number string
3851 retVal
= strlen(sDestination
) + 1;
3854 strncpy (lpNumberStr
, sDestination
, cchNumber
-1);
3855 *(lpNumberStr
+cchNumber
-1) = '\0'; /* ensure we got a NULL at the end */
3856 retVal
= strlen(lpNumberStr
);
3862 /**************************************************************************
3863 * GetNumberFormatW (KERNEL32.@)
3865 INT WINAPI
GetNumberFormatW(LCID locale
, DWORD dwflags
,
3866 LPCWSTR lpvalue
, const NUMBERFMTW
* lpFormat
,
3867 LPWSTR lpNumberStr
, int cchNumber
)
3869 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue
));
3871 lstrcpynW( lpNumberStr
, lpvalue
, cchNumber
);
3872 return cchNumber
? strlenW( lpNumberStr
) : 0;
3875 /**************************************************************************
3876 * GetCurrencyFormatA (KERNEL32.@)
3878 INT WINAPI
GetCurrencyFormatA(LCID locale
, DWORD dwflags
,
3879 LPCSTR lpvalue
, const CURRENCYFMTA
* lpFormat
,
3880 LPSTR lpCurrencyStr
, int cchCurrency
)
3882 UINT nPosOrder
, nNegOrder
;
3884 char sDestination
[128], sNegOrder
[8], sPosOrder
[8], sCurrencySymbol
[8];
3885 char *pDestination
= sDestination
;
3886 char sNumberFormated
[128];
3887 char *pNumberFormated
= sNumberFormated
;
3888 LCID systemDefaultLCID
;
3889 BOOL bIsPositive
= FALSE
, bValidFormat
= FALSE
;
3898 NUMBERFMTA numberFmt
;
3900 /* Which source will we use to format the string */
3901 used_operation
= RETURN_ERROR
;
3902 if (lpFormat
!= NULL
)
3905 used_operation
= USE_PARAMETER
;
3909 if (dwflags
& LOCALE_NOUSEROVERRIDE
)
3910 used_operation
= USE_LOCALEINFO
;
3912 used_operation
= USE_SYSTEMDEFAULT
;
3915 /* Load the fields we need */
3916 switch(used_operation
)
3918 case USE_LOCALEINFO
:
3919 /* Specific to CURRENCYFMTA*/
3920 GetLocaleInfoA(locale
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3921 GetLocaleInfoA(locale
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3922 GetLocaleInfoA(locale
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3924 nPosOrder
= atoi(sPosOrder
);
3925 nNegOrder
= atoi(sNegOrder
);
3928 /* Specific to CURRENCYFMTA*/
3929 nNegOrder
= lpFormat
->NegativeOrder
;
3930 nPosOrder
= lpFormat
->PositiveOrder
;
3931 strcpy(sCurrencySymbol
, lpFormat
->lpCurrencySymbol
);
3933 case USE_SYSTEMDEFAULT
:
3934 systemDefaultLCID
= GetSystemDefaultLCID();
3935 /* Specific to CURRENCYFMTA*/
3936 GetLocaleInfoA(systemDefaultLCID
, LOCALE_INEGCURR
, sNegOrder
, sizeof(sNegOrder
));
3937 GetLocaleInfoA(systemDefaultLCID
, LOCALE_ICURRENCY
, sPosOrder
, sizeof(sPosOrder
));
3938 GetLocaleInfoA(systemDefaultLCID
, LOCALE_SCURRENCY
, sCurrencySymbol
, sizeof(sCurrencySymbol
));
3940 nPosOrder
= atoi(sPosOrder
);
3941 nNegOrder
= atoi(sNegOrder
);
3944 SetLastError(ERROR_INVALID_PARAMETER
);
3948 /* Construct a temporary number format structure */
3949 if (lpFormat
!= NULL
)
3951 numberFmt
.NumDigits
= lpFormat
->NumDigits
;
3952 numberFmt
.LeadingZero
= lpFormat
->LeadingZero
;
3953 numberFmt
.Grouping
= lpFormat
->Grouping
;
3954 numberFmt
.NegativeOrder
= 0;
3955 numberFmt
.lpDecimalSep
= lpFormat
->lpDecimalSep
;
3956 numberFmt
.lpThousandSep
= lpFormat
->lpThousandSep
;
3957 bValidFormat
= TRUE
;
3960 /* Make a call to GetNumberFormatA() */
3961 if (*lpvalue
== '-')
3963 bIsPositive
= FALSE
;
3964 retVal
= GetNumberFormatA(locale
,0,lpvalue
+1,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3969 retVal
= GetNumberFormatA(locale
,0,lpvalue
,(bValidFormat
)?&numberFmt
:NULL
,pNumberFormated
,128);
3975 /* construct the formatted string */
3980 case 0: /* Prefix, no separation */
3981 strcpy (pDestination
, sCurrencySymbol
);
3982 strcat (pDestination
, pNumberFormated
);
3984 case 1: /* Suffix, no separation */
3985 strcpy (pDestination
, pNumberFormated
);
3986 strcat (pDestination
, sCurrencySymbol
);
3988 case 2: /* Prefix, 1 char separation */
3989 strcpy (pDestination
, sCurrencySymbol
);
3990 strcat (pDestination
, " ");
3991 strcat (pDestination
, pNumberFormated
);
3993 case 3: /* Suffix, 1 char separation */
3994 strcpy (pDestination
, pNumberFormated
);
3995 strcat (pDestination
, " ");
3996 strcat (pDestination
, sCurrencySymbol
);
3999 SetLastError(ERROR_INVALID_PARAMETER
);
4003 else /* negative number */
4007 case 0: /* format: ($1.1) */
4008 strcpy (pDestination
, "(");
4009 strcat (pDestination
, sCurrencySymbol
);
4010 strcat (pDestination
, pNumberFormated
);
4011 strcat (pDestination
, ")");
4013 case 1: /* format: -$1.1 */
4014 strcpy (pDestination
, "-");
4015 strcat (pDestination
, sCurrencySymbol
);
4016 strcat (pDestination
, pNumberFormated
);
4018 case 2: /* format: $-1.1 */
4019 strcpy (pDestination
, sCurrencySymbol
);
4020 strcat (pDestination
, "-");
4021 strcat (pDestination
, pNumberFormated
);
4023 case 3: /* format: $1.1- */
4024 strcpy (pDestination
, sCurrencySymbol
);
4025 strcat (pDestination
, pNumberFormated
);
4026 strcat (pDestination
, "-");
4028 case 4: /* format: (1.1$) */
4029 strcpy (pDestination
, "(");
4030 strcat (pDestination
, pNumberFormated
);
4031 strcat (pDestination
, sCurrencySymbol
);
4032 strcat (pDestination
, ")");
4034 case 5: /* format: -1.1$ */
4035 strcpy (pDestination
, "-");
4036 strcat (pDestination
, pNumberFormated
);
4037 strcat (pDestination
, sCurrencySymbol
);
4039 case 6: /* format: 1.1-$ */
4040 strcpy (pDestination
, pNumberFormated
);
4041 strcat (pDestination
, "-");
4042 strcat (pDestination
, sCurrencySymbol
);
4044 case 7: /* format: 1.1$- */
4045 strcpy (pDestination
, pNumberFormated
);
4046 strcat (pDestination
, sCurrencySymbol
);
4047 strcat (pDestination
, "-");
4049 case 8: /* format: -1.1 $ */
4050 strcpy (pDestination
, "-");
4051 strcat (pDestination
, pNumberFormated
);
4052 strcat (pDestination
, " ");
4053 strcat (pDestination
, sCurrencySymbol
);
4055 case 9: /* format: -$ 1.1 */
4056 strcpy (pDestination
, "-");
4057 strcat (pDestination
, sCurrencySymbol
);
4058 strcat (pDestination
, " ");
4059 strcat (pDestination
, pNumberFormated
);
4061 case 10: /* format: 1.1 $- */
4062 strcpy (pDestination
, pNumberFormated
);
4063 strcat (pDestination
, " ");
4064 strcat (pDestination
, sCurrencySymbol
);
4065 strcat (pDestination
, "-");
4067 case 11: /* format: $ 1.1- */
4068 strcpy (pDestination
, sCurrencySymbol
);
4069 strcat (pDestination
, " ");
4070 strcat (pDestination
, pNumberFormated
);
4071 strcat (pDestination
, "-");
4073 case 12: /* format: $ -1.1 */
4074 strcpy (pDestination
, sCurrencySymbol
);
4075 strcat (pDestination
, " ");
4076 strcat (pDestination
, "-");
4077 strcat (pDestination
, pNumberFormated
);
4079 case 13: /* format: 1.1- $ */
4080 strcpy (pDestination
, pNumberFormated
);
4081 strcat (pDestination
, "-");
4082 strcat (pDestination
, " ");
4083 strcat (pDestination
, sCurrencySymbol
);
4085 case 14: /* format: ($ 1.1) */
4086 strcpy (pDestination
, "(");
4087 strcat (pDestination
, sCurrencySymbol
);
4088 strcat (pDestination
, " ");
4089 strcat (pDestination
, pNumberFormated
);
4090 strcat (pDestination
, ")");
4092 case 15: /* format: (1.1 $) */
4093 strcpy (pDestination
, "(");
4094 strcat (pDestination
, pNumberFormated
);
4095 strcat (pDestination
, " ");
4096 strcat (pDestination
, sCurrencySymbol
);
4097 strcat (pDestination
, ")");
4100 SetLastError(ERROR_INVALID_PARAMETER
);
4105 if (cchCurrency
== 0)
4106 return strlen(pDestination
) + 1;
4110 strncpy (lpCurrencyStr
, pDestination
, cchCurrency
-1);
4111 *(lpCurrencyStr
+cchCurrency
-1) = '\0'; /* ensure we got a NULL at the end */
4112 return strlen(lpCurrencyStr
);
4116 /**************************************************************************
4117 * GetCurrencyFormatW (KERNEL32.@)
4119 INT WINAPI
GetCurrencyFormatW(LCID locale
, DWORD dwflags
,
4120 LPCWSTR lpvalue
, const CURRENCYFMTW
* lpFormat
,
4121 LPWSTR lpCurrencyStr
, int cchCurrency
)
4123 FIXME("This API function is NOT implemented !\n");
4127 /******************************************************************************
4128 * OLE2NLS_CheckLocale [intern]
4130 static LCID
OLE2NLS_CheckLocale (LCID locale
)
4133 { locale
= LOCALE_SYSTEM_DEFAULT
;
4136 if (locale
== LOCALE_SYSTEM_DEFAULT
)
4137 { return GetSystemDefaultLCID();
4139 else if (locale
== LOCALE_USER_DEFAULT
)
4140 { return GetUserDefaultLCID();
4146 /******************************************************************************
4147 * GetTimeFormatA [KERNEL32.@]
4148 * Makes an ASCII string of the time
4150 * Formats date according to format, or locale default if format is
4151 * NULL. The format consists of literal characters and fields as follows:
4153 * h hours with no leading zero (12-hour)
4154 * hh hours with full two digits
4155 * H hours with no leading zero (24-hour)
4156 * HH hours with full two digits
4157 * m minutes with no leading zero
4158 * mm minutes with full two digits
4159 * s seconds with no leading zero
4160 * ss seconds with full two digits
4161 * t time marker (A or P)
4162 * tt time marker (AM, PM)
4166 GetTimeFormatA(LCID locale
, /* [in] */
4167 DWORD flags
, /* [in] */
4168 LPSYSTEMTIME xtime
, /* [in] */
4169 LPCSTR format
, /* [in] */
4170 LPSTR timestr
, /* [out] */
4171 INT timelen
/* [in] */)
4172 { char format_buf
[40];
4175 LPSYSTEMTIME thistime
;
4177 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4180 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,xtime
,format
,timestr
,timelen
);
4182 thislocale
= OLE2NLS_CheckLocale ( locale
);
4185 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4186 { thislocale
= GetSystemDefaultLCID();
4188 GetLocaleInfoA(thislocale
, thisflags
, format_buf
, sizeof(format_buf
));
4189 thisformat
= format_buf
;
4192 { thisformat
= format
;
4195 if (xtime
== NULL
) /* NULL means use the current local time*/
4201 /* Check that hour,min and sec is in range */
4203 ret
= OLE_GetFormatA(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4209 /******************************************************************************
4210 * GetTimeFormatW [KERNEL32.@]
4211 * Makes a Unicode string of the time
4214 GetTimeFormatW(LCID locale
, /* [in] */
4215 DWORD flags
, /* [in] */
4216 LPSYSTEMTIME xtime
, /* [in] */
4217 LPCWSTR format
, /* [in] */
4218 LPWSTR timestr
, /* [out] */
4219 INT timelen
/* [in] */)
4220 { WCHAR format_buf
[40];
4223 LPSYSTEMTIME thistime
;
4225 DWORD thisflags
=LOCALE_STIMEFORMAT
; /* standart timeformat */
4228 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale
,flags
,
4229 xtime
,debugstr_w(format
),timestr
,timelen
);
4231 thislocale
= OLE2NLS_CheckLocale ( locale
);
4234 { if (flags
& LOCALE_NOUSEROVERRIDE
) /*use system default*/
4235 { thislocale
= GetSystemDefaultLCID();
4237 GetLocaleInfoW(thislocale
, thisflags
, format_buf
, 40);
4238 thisformat
= format_buf
;
4241 { thisformat
= format
;
4244 if (xtime
== NULL
) /* NULL means use the current local time*/
4252 ret
= OLE_GetFormatW(thislocale
, thisflags
, flags
, thistime
, thisformat
,
4257 /******************************************************************************
4258 * EnumCalendarInfoA [KERNEL32.@]
4260 BOOL WINAPI
EnumCalendarInfoA(
4261 CALINFO_ENUMPROCA calinfoproc
,LCID locale
,CALID calendar
,CALTYPE caltype
4263 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc
,locale
,calendar
,caltype
);