Must include 'stdlib.h'.
[wine/dcerpc.git] / ole / ole2nls.c
blob0c5bc893aefb5a789dde8f79ba25151907cb805f
1 /*
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
7 */
9 #include <string.h>
10 #include <stdio.h>
11 #include <ctype.h>
12 #include <stdlib.h>
13 #include <locale.h>
14 #include "windef.h"
15 #include "wingdi.h"
16 #include "winuser.h"
17 #include "wine/unicode.h"
18 #include "heap.h"
19 #include "options.h"
20 #include "winver.h"
21 #include "winnls.h"
22 #include "winreg.h"
23 #include "winerror.h"
24 #include "debugtools.h"
25 #include "main.h"
27 DEFAULT_DEBUG_CHANNEL(string);
29 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
30 * MUST contain all #defines from winnls.h
31 * last entry has NULL name, 0 id.
32 */
33 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
34 static const struct tagLOCALE_NAME2ID {
35 const char *name;
36 LCTYPE id;
37 } locale_name2id[]= {
38 LOCALE_ENTRY(ILANGUAGE),
39 LOCALE_ENTRY(SLANGUAGE),
40 LOCALE_ENTRY(SENGLANGUAGE),
41 LOCALE_ENTRY(SABBREVLANGNAME),
42 LOCALE_ENTRY(SNATIVELANGNAME),
43 LOCALE_ENTRY(ICOUNTRY),
44 LOCALE_ENTRY(SCOUNTRY),
45 LOCALE_ENTRY(SENGCOUNTRY),
46 LOCALE_ENTRY(SABBREVCTRYNAME),
47 LOCALE_ENTRY(SNATIVECTRYNAME),
48 LOCALE_ENTRY(IDEFAULTLANGUAGE),
49 LOCALE_ENTRY(IDEFAULTCOUNTRY),
50 LOCALE_ENTRY(IDEFAULTCODEPAGE),
51 LOCALE_ENTRY(IDEFAULTANSICODEPAGE),
52 LOCALE_ENTRY(IDEFAULTMACCODEPAGE),
53 LOCALE_ENTRY(SLIST),
54 LOCALE_ENTRY(IMEASURE),
55 LOCALE_ENTRY(SDECIMAL),
56 LOCALE_ENTRY(STHOUSAND),
57 LOCALE_ENTRY(SGROUPING),
58 LOCALE_ENTRY(IDIGITS),
59 LOCALE_ENTRY(ILZERO),
60 LOCALE_ENTRY(INEGNUMBER),
61 LOCALE_ENTRY(SNATIVEDIGITS),
62 LOCALE_ENTRY(SCURRENCY),
63 LOCALE_ENTRY(SINTLSYMBOL),
64 LOCALE_ENTRY(SMONDECIMALSEP),
65 LOCALE_ENTRY(SMONTHOUSANDSEP),
66 LOCALE_ENTRY(SMONGROUPING),
67 LOCALE_ENTRY(ICURRDIGITS),
68 LOCALE_ENTRY(IINTLCURRDIGITS),
69 LOCALE_ENTRY(ICURRENCY),
70 LOCALE_ENTRY(INEGCURR),
71 LOCALE_ENTRY(SDATE),
72 LOCALE_ENTRY(STIME),
73 LOCALE_ENTRY(SSHORTDATE),
74 LOCALE_ENTRY(SLONGDATE),
75 LOCALE_ENTRY(STIMEFORMAT),
76 LOCALE_ENTRY(IDATE),
77 LOCALE_ENTRY(ILDATE),
78 LOCALE_ENTRY(ITIME),
79 LOCALE_ENTRY(ITIMEMARKPOSN),
80 LOCALE_ENTRY(ICENTURY),
81 LOCALE_ENTRY(ITLZERO),
82 LOCALE_ENTRY(IDAYLZERO),
83 LOCALE_ENTRY(IMONLZERO),
84 LOCALE_ENTRY(S1159),
85 LOCALE_ENTRY(S2359),
86 LOCALE_ENTRY(ICALENDARTYPE),
87 LOCALE_ENTRY(IOPTIONALCALENDAR),
88 LOCALE_ENTRY(IFIRSTDAYOFWEEK),
89 LOCALE_ENTRY(IFIRSTWEEKOFYEAR),
90 LOCALE_ENTRY(SDAYNAME1),
91 LOCALE_ENTRY(SDAYNAME2),
92 LOCALE_ENTRY(SDAYNAME3),
93 LOCALE_ENTRY(SDAYNAME4),
94 LOCALE_ENTRY(SDAYNAME5),
95 LOCALE_ENTRY(SDAYNAME6),
96 LOCALE_ENTRY(SDAYNAME7),
97 LOCALE_ENTRY(SABBREVDAYNAME1),
98 LOCALE_ENTRY(SABBREVDAYNAME2),
99 LOCALE_ENTRY(SABBREVDAYNAME3),
100 LOCALE_ENTRY(SABBREVDAYNAME4),
101 LOCALE_ENTRY(SABBREVDAYNAME5),
102 LOCALE_ENTRY(SABBREVDAYNAME6),
103 LOCALE_ENTRY(SABBREVDAYNAME7),
104 LOCALE_ENTRY(SMONTHNAME1),
105 LOCALE_ENTRY(SMONTHNAME2),
106 LOCALE_ENTRY(SMONTHNAME3),
107 LOCALE_ENTRY(SMONTHNAME4),
108 LOCALE_ENTRY(SMONTHNAME5),
109 LOCALE_ENTRY(SMONTHNAME6),
110 LOCALE_ENTRY(SMONTHNAME7),
111 LOCALE_ENTRY(SMONTHNAME8),
112 LOCALE_ENTRY(SMONTHNAME9),
113 LOCALE_ENTRY(SMONTHNAME10),
114 LOCALE_ENTRY(SMONTHNAME11),
115 LOCALE_ENTRY(SMONTHNAME12),
116 LOCALE_ENTRY(SMONTHNAME13),
117 LOCALE_ENTRY(SABBREVMONTHNAME1),
118 LOCALE_ENTRY(SABBREVMONTHNAME2),
119 LOCALE_ENTRY(SABBREVMONTHNAME3),
120 LOCALE_ENTRY(SABBREVMONTHNAME4),
121 LOCALE_ENTRY(SABBREVMONTHNAME5),
122 LOCALE_ENTRY(SABBREVMONTHNAME6),
123 LOCALE_ENTRY(SABBREVMONTHNAME7),
124 LOCALE_ENTRY(SABBREVMONTHNAME8),
125 LOCALE_ENTRY(SABBREVMONTHNAME9),
126 LOCALE_ENTRY(SABBREVMONTHNAME10),
127 LOCALE_ENTRY(SABBREVMONTHNAME11),
128 LOCALE_ENTRY(SABBREVMONTHNAME12),
129 LOCALE_ENTRY(SABBREVMONTHNAME13),
130 LOCALE_ENTRY(SPOSITIVESIGN),
131 LOCALE_ENTRY(SNEGATIVESIGN),
132 LOCALE_ENTRY(IPOSSIGNPOSN),
133 LOCALE_ENTRY(INEGSIGNPOSN),
134 LOCALE_ENTRY(IPOSSYMPRECEDES),
135 LOCALE_ENTRY(IPOSSEPBYSPACE),
136 LOCALE_ENTRY(INEGSYMPRECEDES),
137 LOCALE_ENTRY(INEGSEPBYSPACE),
138 LOCALE_ENTRY(FONTSIGNATURE),
139 LOCALE_ENTRY(SISO639LANGNAME),
140 LOCALE_ENTRY(SISO3166CTRYNAME),
141 {NULL,0}
144 static char *GetLocaleSubkeyName( DWORD lctype );
146 /***********************************************************************
147 * GetUserDefaultLCID [KERNEL32.425]
149 LCID WINAPI GetUserDefaultLCID(void)
151 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT );
154 /***********************************************************************
155 * GetSystemDefaultLCID [KERNEL32.400]
157 LCID WINAPI GetSystemDefaultLCID(void)
159 return GetUserDefaultLCID();
162 #define NLS_MAX_LANGUAGES 20
163 typedef struct {
164 char lang[128];
165 char country[128];
166 LANGID found_lang_id[NLS_MAX_LANGUAGES];
167 char found_language[NLS_MAX_LANGUAGES][3];
168 char found_country[NLS_MAX_LANGUAGES][3];
169 int n_found;
170 } LANG_FIND_DATA;
172 static BOOL CALLBACK NLS_FindLanguageID_ProcA(HMODULE hModule, LPCSTR type,
173 LPCSTR name, WORD LangID, LONG lParam)
175 LANG_FIND_DATA *l_data = (LANG_FIND_DATA *)lParam;
176 LCID lcid = MAKELCID(LangID, SORT_DEFAULT);
177 char buf_language[128];
178 char buf_country[128];
179 char buf_en_language[128];
181 TRACE("%04X\n", (UINT)LangID);
182 if(PRIMARYLANGID(LangID) == LANG_NEUTRAL)
183 return TRUE; /* continue search */
185 buf_language[0] = 0;
186 buf_country[0] = 0;
188 GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME|LOCALE_NOUSEROVERRIDE,
189 buf_language, sizeof(buf_language));
190 TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language);
192 GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME|LOCALE_NOUSEROVERRIDE,
193 buf_country, sizeof(buf_country));
194 TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country);
196 if(l_data->lang && strlen(l_data->lang) > 0 && !strcasecmp(l_data->lang, buf_language))
198 if(l_data->country && strlen(l_data->country) > 0)
200 if(!strcasecmp(l_data->country, buf_country))
202 l_data->found_lang_id[0] = LangID;
203 l_data->n_found = 1;
204 TRACE("Found lang_id %04X for %s_%s\n", LangID, l_data->lang, l_data->country);
205 return FALSE; /* stop enumeration */
208 else /* l_data->country not specified */
210 if(l_data->n_found < NLS_MAX_LANGUAGES)
212 l_data->found_lang_id[l_data->n_found] = LangID;
213 strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
214 strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
215 l_data->n_found++;
216 TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
217 return TRUE; /* continue search */
222 /* Just in case, check LOCALE_SENGLANGUAGE too,
223 * in hope that possible alias name might have that value.
225 buf_en_language[0] = 0;
226 GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE|LOCALE_NOUSEROVERRIDE,
227 buf_en_language, sizeof(buf_en_language));
228 TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language);
230 if(l_data->lang && strlen(l_data->lang) > 0 && !strcasecmp(l_data->lang, buf_en_language))
232 l_data->found_lang_id[l_data->n_found] = LangID;
233 strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
234 strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
235 l_data->n_found++;
236 TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
239 return TRUE; /* continue search */
242 /***********************************************************************
243 * NLS_GetLanguageID
245 * INPUT:
246 * Lang: a string whose two first chars are the iso name of a language.
247 * Country: a string whose two first chars are the iso name of country
248 * Charset: a string defining the chossen charset encoding
249 * Dialect: a string defining a variation of the locale
251 * all those values are from the standardized format of locale
252 * name in unix which is: Lang[_Country][.Charset][@Dialect]
254 * RETURNS:
255 * the numeric code of the language used by Windows
257 * FIXME: Charset and Dialect are not handled
259 static LANGID NLS_GetLanguageID(LPCSTR Lang, LPCSTR Country, LPCSTR Charset, LPCSTR Dialect)
261 LANG_FIND_DATA l_data;
262 char lang_string[256];
264 if(!Lang)
266 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
267 goto END;
270 memset(&l_data, 0, sizeof(LANG_FIND_DATA));
271 strncpy(l_data.lang, Lang, sizeof(l_data.lang));
273 if(Country && strlen(Country) > 0)
274 strncpy(l_data.country, Country, sizeof(l_data.country));
276 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
277 (LPCSTR)LOCALE_ILANGUAGE, NLS_FindLanguageID_ProcA, (LONG)&l_data);
279 strcpy(lang_string, l_data.lang);
280 if(l_data.country && strlen(l_data.country) > 0)
282 strcat(lang_string, "_");
283 strcat(lang_string, l_data.country);
286 if(!l_data.n_found)
288 if(l_data.country && strlen(l_data.country) > 0)
290 MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string);
291 l_data.country[0] = 0;
292 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
293 (LPCSTR)LOCALE_ILANGUAGE, NLS_FindLanguageID_ProcA, (LONG)&l_data);
297 /* Re-evaluate lang_string */
298 strcpy(lang_string, l_data.lang);
299 if(l_data.country && strlen(l_data.country) > 0)
301 strcat(lang_string, "_");
302 strcat(lang_string, l_data.country);
305 if(!l_data.n_found)
307 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string);
308 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
310 else
312 if(l_data.n_found == 1)
313 TRACE("For language '%s' lang_id %04X was found\n", lang_string, l_data.found_lang_id[0]);
314 else /* l_data->n_found > 1 */
316 int i;
317 MESSAGE("For language '%s' several language ids were found:\n", lang_string);
318 for(i = 0; i < l_data.n_found; i++)
319 MESSAGE("%s_%s - %04X; ", l_data.found_language[i], l_data.found_country[i], l_data.found_lang_id[i]);
321 MESSAGE("\nInstead of using first in the list, suggest to define\n"
322 "your LANG environment variable like this: LANG=%s_%s\n",
323 l_data.found_language[0], l_data.found_country[0]);
326 END:
327 TRACE("Returning %04X\n", l_data.found_lang_id[0]);
328 return l_data.found_lang_id[0];
331 /***********************************************************************
332 * GetUserDefaultLangID [KERNEL32.426]
334 LANGID WINAPI GetUserDefaultLangID(void)
336 /* caching result, if defined from environment, which should (?) not change during a WINE session */
337 static LANGID userLCID = 0;
339 if (userLCID == 0)
341 char buf[256];
342 char *lang,*country,*charset,*dialect,*next;
344 if (GetEnvironmentVariableA( "LANGUAGE", buf, sizeof(buf) )) goto ok;
345 if (GetEnvironmentVariableA( "LANG", buf, sizeof(buf) )) goto ok;
346 if (GetEnvironmentVariableA( "LC_ALL", buf, sizeof(buf) )) goto ok;
347 if (GetEnvironmentVariableA( "LC_MESSAGES", buf, sizeof(buf) )) goto ok;
348 if (GetEnvironmentVariableA( "LC_CTYPE", buf, sizeof(buf) )) goto ok;
350 return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
353 if (!strcmp(buf,"POSIX") || !strcmp(buf,"C"))
354 return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
356 lang=buf;
358 do {
359 next=strchr(lang,':'); if (next) *next++='\0';
360 dialect=strchr(lang,'@'); if (dialect) *dialect++='\0';
361 charset=strchr(lang,'.'); if (charset) *charset++='\0';
362 country=strchr(lang,'_'); if (country) *country++='\0';
364 userLCID = NLS_GetLanguageID(lang, country, charset, dialect);
366 lang=next;
367 } while (lang && !userLCID);
369 if (!userLCID)
371 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
372 buf );
373 userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
376 return userLCID;
379 /***********************************************************************
380 * GetSystemDefaultLangID [KERNEL32.401]
382 LANGID WINAPI GetSystemDefaultLangID(void)
384 return GetUserDefaultLangID();
387 /******************************************************************************
388 * ConvertDefaultLocale [KERNEL32.147]
390 LCID WINAPI ConvertDefaultLocale (LCID lcid)
391 { switch (lcid)
392 { case LOCALE_SYSTEM_DEFAULT:
393 return GetSystemDefaultLCID();
394 case LOCALE_USER_DEFAULT:
395 return GetUserDefaultLCID();
396 case LOCALE_NEUTRAL:
397 return MAKELCID (LANG_NEUTRAL, SUBLANG_NEUTRAL);
399 return MAKELANGID( PRIMARYLANGID(lcid), SUBLANG_NEUTRAL);
402 /* Enhanced version of LoadStringW.
403 * It takes LanguageId to find and load language dependant resources.
404 * Resource is copied as is: "binary" strings are not truncated.
405 * Return: length of resource + 1 to distinguish absent resources
406 * from the resources with zero length.
408 static INT NLS_LoadStringExW(HMODULE hModule, LANGID lang_id, UINT res_id, LPWSTR buffer, INT buflen)
410 HRSRC hrsrc;
411 HGLOBAL hmem;
412 WCHAR *p;
413 int string_num;
414 int i;
416 hrsrc = FindResourceExW(hModule, RT_STRINGW, (LPCWSTR)((res_id >> 4) + 1), lang_id);
418 if(!hrsrc) return 0;
419 hmem = LoadResource(hModule, hrsrc);
420 if(!hmem) return 0;
422 p = LockResource(hmem);
423 string_num = res_id & 0x000f;
424 for(i = 0; i < string_num; i++)
425 p += *p + 1;
427 TRACE("strlen = %d\n", (int)*p );
429 if (buffer == NULL) return *p;
430 i = min(buflen - 1, *p);
431 if (i > 0) {
432 memcpy(buffer, p + 1, i * sizeof (WCHAR));
433 buffer[i] = (WCHAR) 0;
434 } else {
435 if (buflen > 1)
436 buffer[0] = (WCHAR) 0;
439 FreeResource(hmem);
440 TRACE("\"%s\" loaded!\n", debugstr_w(buffer));
441 return (i + 1);
444 /******************************************************************************
445 * GetLocaleInfoA [KERNEL32.342]
447 * NOTES
448 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
450 * MS online documentation states that the string returned is NULL terminated
451 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
452 * terminated string".
454 INT WINAPI GetLocaleInfoA(LCID lcid,LCTYPE LCType,LPSTR buf,INT len)
456 LPCSTR retString = NULL;
457 int found = 0, i;
458 char *pacKey;
459 char acBuffer[128];
460 DWORD dwBufferSize=128;
461 BOOL NoUserOverride;
463 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid,LCType,buf,len);
465 if (len && (! buf) ) {
466 SetLastError(ERROR_INSUFFICIENT_BUFFER);
467 return 0;
470 if (lcid == LOCALE_NEUTRAL || lcid == LANG_SYSTEM_DEFAULT)
472 lcid = GetSystemDefaultLCID();
474 else if (lcid == LANG_USER_DEFAULT) /*0x800*/
476 lcid = GetUserDefaultLCID();
479 /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
480 from the registry. Instead, use system default values. */
481 NoUserOverride = (LCType & LOCALE_NOUSEROVERRIDE) != 0;
483 LCType &= ~(LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP);
485 /* First, check if it's in the registry. */
486 /* All user customized values are stored in the registry by SetLocaleInfo */
487 if ( !NoUserOverride && (pacKey = GetLocaleSubkeyName(LCType)) )
489 char acRealKey[128];
490 HKEY hKey;
492 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
494 if ( RegOpenKeyExA( HKEY_CURRENT_USER, acRealKey,
495 0, KEY_READ, &hKey) == ERROR_SUCCESS )
497 if ( RegQueryValueExA( hKey, NULL, NULL, NULL, (LPBYTE)acBuffer,
498 &dwBufferSize ) == ERROR_SUCCESS )
500 retString = acBuffer;
501 found = 1;
503 RegCloseKey(hKey);
507 /* If not in the registry, get it from the NLS entries. */
508 if(!found) {
509 WCHAR wcBuffer[128];
510 int res_size;
512 /* check if language is registered in the kernel32 resources */
513 if((res_size = NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid),
514 LCType, wcBuffer, sizeof(wcBuffer)/sizeof(wcBuffer[0])))) {
515 WideCharToMultiByte(CP_ACP, 0, wcBuffer, res_size, acBuffer, dwBufferSize, NULL, NULL);
516 retString = acBuffer;
517 found = 1;
521 /* if not found report a most descriptive error */
522 if(!found) {
523 retString=0;
524 /* If we are through all of this, retLen should not be zero anymore.
525 If it is, the value is not supported */
526 i=0;
527 while (locale_name2id[i].name!=NULL) {
528 if (LCType == locale_name2id[i].id) {
529 retString = locale_name2id[i].name;
530 break;
532 i++;
534 if(!retString)
535 FIXME("Unkown LC type %lX\n", LCType);
536 else
537 FIXME("'%s' is not defined for your language (%04X).\n"
538 "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
539 "and submit patch for inclusion into the next Wine release.\n",
540 retString, LOWORD(lcid));
541 SetLastError(ERROR_INVALID_PARAMETER);
542 return 0;
545 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
546 if (LCType == LOCALE_FONTSIGNATURE) {
547 if (len) {
548 len = (len < sizeof(FONTSIGNATURE)) ? len : sizeof(FONTSIGNATURE);
549 memcpy(buf, retString, len);
550 return len;
552 return sizeof(FONTSIGNATURE);
554 /* if len=0 return only the length, don't touch the buffer*/
555 if (len) {
556 lstrcpynA(buf,retString,len);
557 return strlen(buf) + 1;
559 return strlen(retString)+1;
562 /******************************************************************************
563 * GetLocaleInfoW [KERNEL32.343]
565 * NOTES
566 * MS documentation states that len "specifies the size, in bytes (ANSI version)
567 * or characters (Unicode version), of" wbuf. Thus the number returned is
568 * the same between GetLocaleInfoW and GetLocaleInfoA.
570 INT WINAPI GetLocaleInfoW(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT len)
571 { WORD wlen;
572 LPSTR abuf;
574 if (len && (! wbuf) )
575 { SetLastError(ERROR_INSUFFICIENT_BUFFER);
576 return 0;
579 abuf = (LPSTR)HeapAlloc(GetProcessHeap(),0,len);
580 wlen = GetLocaleInfoA(lcid, LCType, abuf, len);
582 if (wlen && len) /* if len=0 return only the length*/
583 lstrcpynAtoW(wbuf,abuf,len);
585 HeapFree(GetProcessHeap(),0,abuf);
586 return wlen;
589 /******************************************************************************
591 * GetLocaleSubkeyName [helper function]
593 * - For use with the registry.
594 * - Gets the registry subkey name for a given lctype.
596 static char *GetLocaleSubkeyName( DWORD lctype )
598 char *pacKey=NULL;
600 switch ( lctype )
602 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
603 * the values are stored in the registry, confirmed under Windows,
604 * for the ones that actually assign pacKey. Cases that aren't finished
605 * have not been confirmed, so that must be done before they can be
606 * added.
608 case LOCALE_SDATE : /* The date separator. */
609 pacKey = "sDate";
610 break;
611 case LOCALE_ICURRDIGITS:
612 pacKey = "iCurrDigits";
613 break;
614 case LOCALE_SDECIMAL :
615 pacKey = "sDecimal";
616 break;
617 case LOCALE_ICURRENCY:
618 pacKey = "iCurrency";
619 break;
620 case LOCALE_SGROUPING :
621 pacKey = "sGrouping";
622 break;
623 case LOCALE_IDIGITS:
624 pacKey = "iDigits";
625 break;
626 case LOCALE_SLIST :
627 pacKey = "sList";
628 break;
629 /* case LOCALE_ICALENDARTYPE: */
630 /* case LOCALE_IFIRSTDAYOFWEEK: */
631 /* case LOCALE_IFIRSTWEEKOFYEAR: */
632 /* case LOCALE_SYEARMONTH : */
633 /* case LOCALE_SPOSITIVESIGN : */
634 /* case LOCALE_IPAPERSIZE: */
635 /* break; */
636 case LOCALE_SLONGDATE :
637 pacKey = "sLongDate";
638 break;
639 case LOCALE_SMONDECIMALSEP :
640 pacKey = "sMonDecimalSep";
641 break;
642 case LOCALE_SMONGROUPING:
643 pacKey = "sMonGrouping";
644 break;
645 case LOCALE_IMEASURE:
646 pacKey = "iMeasure";
647 break;
648 case LOCALE_SMONTHOUSANDSEP :
649 pacKey = "sMonThousandSep";
650 break;
651 case LOCALE_INEGCURR:
652 pacKey = "iNegCurr";
653 break;
654 case LOCALE_SNEGATIVESIGN :
655 pacKey = "sNegativeSign";
656 break;
657 case LOCALE_INEGNUMBER:
658 pacKey = "iNegNumber";
659 break;
660 case LOCALE_SSHORTDATE :
661 pacKey = "sShortDate";
662 break;
663 case LOCALE_ILDATE: /* Long Date format ordering specifier. */
664 pacKey = "iLDate";
665 break;
666 case LOCALE_ILZERO:
667 pacKey = "iLZero";
668 break;
669 case LOCALE_ITLZERO:
670 pacKey = "iTLZero";
671 break;
672 case LOCALE_ITIME: /* Time format specifier. */
673 pacKey = "iTime";
674 break;
675 case LOCALE_STHOUSAND :
676 pacKey = "sThousand";
677 break;
678 case LOCALE_S1159: /* AM */
679 pacKey = "s1159";
680 break;
681 case LOCALE_STIME:
682 pacKey = "sTime";
683 break;
684 case LOCALE_S2359: /* PM */
685 pacKey = "s2359";
686 break;
687 case LOCALE_STIMEFORMAT :
688 pacKey = "sTimeFormat";
689 break;
690 case LOCALE_SCURRENCY:
691 pacKey = "sCurrency";
692 break;
694 /* The following are not listed under MSDN as supported,
695 * but seem to be used and also stored in the registry.
698 case LOCALE_IDATE:
699 pacKey = "iDate";
700 break;
701 case LOCALE_SCOUNTRY:
702 pacKey = "sCountry";
703 break;
704 case LOCALE_ICOUNTRY:
705 pacKey = "iCountry";
706 break;
707 case LOCALE_SLANGUAGE:
708 pacKey = "sLanguage";
709 break;
711 default:
712 break;
715 return( pacKey );
718 /******************************************************************************
719 * SetLocaleInfoA [KERNEL32.656]
721 BOOL16 WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
723 HKEY hKey;
724 char *pacKey;
725 char acRealKey[128];
727 if ( (pacKey = GetLocaleSubkeyName(lctype)) )
729 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
730 if ( RegCreateKeyA( HKEY_CURRENT_USER, acRealKey,
731 &hKey ) == ERROR_SUCCESS )
733 if ( RegSetValueExA( hKey, NULL, 0, REG_SZ,
734 data, strlen(data)+1 ) != ERROR_SUCCESS )
736 ERR("SetLocaleInfoA: %s did not work\n", pacKey );
738 RegCloseKey( hKey );
741 else
743 FIXME("(%ld,%ld,%s): stub\n",lcid,lctype,data);
745 return TRUE;
748 /******************************************************************************
749 * IsValidLocale [KERNEL32.489]
751 BOOL WINAPI IsValidLocale(LCID lcid,DWORD flags)
753 /* check if language is registered in the kernel32 resources */
754 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW, (LPCWSTR)LOCALE_ILANGUAGE, LOWORD(lcid)))
755 return FALSE;
756 else
757 return TRUE;
760 static BOOL CALLBACK EnumResourceLanguagesProcW(HMODULE hModule, LPCWSTR type,
761 LPCWSTR name, WORD LangID, LONG lParam)
763 CHAR bufA[20];
764 WCHAR bufW[20];
765 LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
766 sprintf(bufA, "%08X", (UINT)LangID);
767 MultiByteToWideChar(CP_ACP, 0, bufA, -1, bufW, sizeof(bufW)/sizeof(bufW[0]));
768 return lpfnLocaleEnum(bufW);
771 /******************************************************************************
772 * EnumSystemLocalesW [KERNEL32.209]
774 BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum,
775 DWORD flags )
777 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
779 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW,
780 (LPCWSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcW,
781 (LONG)lpfnLocaleEnum);
783 return TRUE;
786 static BOOL CALLBACK EnumResourceLanguagesProcA(HMODULE hModule, LPCSTR type,
787 LPCSTR name, WORD LangID, LONG lParam)
789 CHAR bufA[20];
790 LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
791 sprintf(bufA, "%08X", (UINT)LangID);
792 return lpfnLocaleEnum(bufA);
795 /******************************************************************************
796 * EnumSystemLocalesA [KERNEL32.208]
798 BOOL WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum,
799 DWORD flags)
801 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
803 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
804 (LPCSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcA,
805 (LONG)lpfnLocaleEnum);
807 return TRUE;
810 static const unsigned char CT_CType2_LUT[] = {
811 C2_NOTAPPLICABLE, /* - 0 */
812 C2_NOTAPPLICABLE, /* - 1 */
813 C2_NOTAPPLICABLE, /* - 2 */
814 C2_NOTAPPLICABLE, /* - 3 */
815 C2_NOTAPPLICABLE, /* - 4 */
816 C2_NOTAPPLICABLE, /* - 5 */
817 C2_NOTAPPLICABLE, /* - 6 */
818 C2_NOTAPPLICABLE, /* - 7 */
819 C2_NOTAPPLICABLE, /* - 8 */
820 C2_SEGMENTSEPARATOR, /* - 9 */
821 C2_NOTAPPLICABLE, /* - 10 */
822 C2_NOTAPPLICABLE, /* - 11 */
823 C2_NOTAPPLICABLE, /* - 12 */
824 C2_NOTAPPLICABLE, /* - 13 */
825 C2_NOTAPPLICABLE, /* - 14 */
826 C2_NOTAPPLICABLE, /* - 15 */
827 C2_NOTAPPLICABLE, /* - 16 */
828 C2_NOTAPPLICABLE, /* - 17 */
829 C2_NOTAPPLICABLE, /* - 18 */
830 C2_NOTAPPLICABLE, /* - 19 */
831 C2_NOTAPPLICABLE, /* - 20 */
832 C2_NOTAPPLICABLE, /* - 21 */
833 C2_NOTAPPLICABLE, /* - 22 */
834 C2_NOTAPPLICABLE, /* - 23 */
835 C2_NOTAPPLICABLE, /* - 24 */
836 C2_NOTAPPLICABLE, /* - 25 */
837 C2_NOTAPPLICABLE, /* - 26 */
838 C2_NOTAPPLICABLE, /* - 27 */
839 C2_NOTAPPLICABLE, /* - 28 */
840 C2_NOTAPPLICABLE, /* - 29 */
841 C2_NOTAPPLICABLE, /* - 30 */
842 C2_NOTAPPLICABLE, /* - 31 */
843 C2_WHITESPACE, /* - 32 */
844 C2_OTHERNEUTRAL, /* ! - 33 */
845 C2_OTHERNEUTRAL, /* " - 34 */ /* " */
846 C2_EUROPETERMINATOR, /* # - 35 */
847 C2_EUROPETERMINATOR, /* $ - 36 */
848 C2_EUROPETERMINATOR, /* % - 37 */
849 C2_LEFTTORIGHT, /* & - 38 */
850 C2_OTHERNEUTRAL, /* ' - 39 */
851 C2_OTHERNEUTRAL, /* ( - 40 */
852 C2_OTHERNEUTRAL, /* ) - 41 */
853 C2_OTHERNEUTRAL, /* * - 42 */
854 C2_EUROPETERMINATOR, /* + - 43 */
855 C2_COMMONSEPARATOR, /* , - 44 */
856 C2_EUROPETERMINATOR, /* - - 45 */
857 C2_EUROPESEPARATOR, /* . - 46 */
858 C2_EUROPESEPARATOR, /* / - 47 */
859 C2_EUROPENUMBER, /* 0 - 48 */
860 C2_EUROPENUMBER, /* 1 - 49 */
861 C2_EUROPENUMBER, /* 2 - 50 */
862 C2_EUROPENUMBER, /* 3 - 51 */
863 C2_EUROPENUMBER, /* 4 - 52 */
864 C2_EUROPENUMBER, /* 5 - 53 */
865 C2_EUROPENUMBER, /* 6 - 54 */
866 C2_EUROPENUMBER, /* 7 - 55 */
867 C2_EUROPENUMBER, /* 8 - 56 */
868 C2_EUROPENUMBER, /* 9 - 57 */
869 C2_COMMONSEPARATOR, /* : - 58 */
870 C2_OTHERNEUTRAL, /* ; - 59 */
871 C2_OTHERNEUTRAL, /* < - 60 */
872 C2_OTHERNEUTRAL, /* = - 61 */
873 C2_OTHERNEUTRAL, /* > - 62 */
874 C2_OTHERNEUTRAL, /* ? - 63 */
875 C2_LEFTTORIGHT, /* @ - 64 */
876 C2_LEFTTORIGHT, /* A - 65 */
877 C2_LEFTTORIGHT, /* B - 66 */
878 C2_LEFTTORIGHT, /* C - 67 */
879 C2_LEFTTORIGHT, /* D - 68 */
880 C2_LEFTTORIGHT, /* E - 69 */
881 C2_LEFTTORIGHT, /* F - 70 */
882 C2_LEFTTORIGHT, /* G - 71 */
883 C2_LEFTTORIGHT, /* H - 72 */
884 C2_LEFTTORIGHT, /* I - 73 */
885 C2_LEFTTORIGHT, /* J - 74 */
886 C2_LEFTTORIGHT, /* K - 75 */
887 C2_LEFTTORIGHT, /* L - 76 */
888 C2_LEFTTORIGHT, /* M - 77 */
889 C2_LEFTTORIGHT, /* N - 78 */
890 C2_LEFTTORIGHT, /* O - 79 */
891 C2_LEFTTORIGHT, /* P - 80 */
892 C2_LEFTTORIGHT, /* Q - 81 */
893 C2_LEFTTORIGHT, /* R - 82 */
894 C2_LEFTTORIGHT, /* S - 83 */
895 C2_LEFTTORIGHT, /* T - 84 */
896 C2_LEFTTORIGHT, /* U - 85 */
897 C2_LEFTTORIGHT, /* V - 86 */
898 C2_LEFTTORIGHT, /* W - 87 */
899 C2_LEFTTORIGHT, /* X - 88 */
900 C2_LEFTTORIGHT, /* Y - 89 */
901 C2_LEFTTORIGHT, /* Z - 90 */
902 C2_OTHERNEUTRAL, /* [ - 91 */
903 C2_OTHERNEUTRAL, /* \ - 92 */
904 C2_OTHERNEUTRAL, /* ] - 93 */
905 C2_OTHERNEUTRAL, /* ^ - 94 */
906 C2_OTHERNEUTRAL, /* _ - 95 */
907 C2_OTHERNEUTRAL, /* ` - 96 */
908 C2_LEFTTORIGHT, /* a - 97 */
909 C2_LEFTTORIGHT, /* b - 98 */
910 C2_LEFTTORIGHT, /* c - 99 */
911 C2_LEFTTORIGHT, /* d - 100 */
912 C2_LEFTTORIGHT, /* e - 101 */
913 C2_LEFTTORIGHT, /* f - 102 */
914 C2_LEFTTORIGHT, /* g - 103 */
915 C2_LEFTTORIGHT, /* h - 104 */
916 C2_LEFTTORIGHT, /* i - 105 */
917 C2_LEFTTORIGHT, /* j - 106 */
918 C2_LEFTTORIGHT, /* k - 107 */
919 C2_LEFTTORIGHT, /* l - 108 */
920 C2_LEFTTORIGHT, /* m - 109 */
921 C2_LEFTTORIGHT, /* n - 110 */
922 C2_LEFTTORIGHT, /* o - 111 */
923 C2_LEFTTORIGHT, /* p - 112 */
924 C2_LEFTTORIGHT, /* q - 113 */
925 C2_LEFTTORIGHT, /* r - 114 */
926 C2_LEFTTORIGHT, /* s - 115 */
927 C2_LEFTTORIGHT, /* t - 116 */
928 C2_LEFTTORIGHT, /* u - 117 */
929 C2_LEFTTORIGHT, /* v - 118 */
930 C2_LEFTTORIGHT, /* w - 119 */
931 C2_LEFTTORIGHT, /* x - 120 */
932 C2_LEFTTORIGHT, /* y - 121 */
933 C2_LEFTTORIGHT, /* z - 122 */
934 C2_OTHERNEUTRAL, /* { - 123 */
935 C2_OTHERNEUTRAL, /* | - 124 */
936 C2_OTHERNEUTRAL, /* } - 125 */
937 C2_OTHERNEUTRAL, /* ~ - 126 */
938 C2_NOTAPPLICABLE, /* \x7f - 127 */
939 C2_NOTAPPLICABLE, /* € - 128 */
940 C2_NOTAPPLICABLE, /* � - 129 */
941 C2_OTHERNEUTRAL, /* ‚ - 130 */
942 C2_LEFTTORIGHT, /* ƒ - 131 */
943 C2_OTHERNEUTRAL, /* „ - 132 */
944 C2_OTHERNEUTRAL, /* … - 133 */
945 C2_OTHERNEUTRAL, /* † - 134 */
946 C2_OTHERNEUTRAL, /* ‡ - 135 */
947 C2_LEFTTORIGHT, /* ˆ - 136 */
948 C2_EUROPETERMINATOR, /* ‰ - 137 */
949 C2_LEFTTORIGHT, /* Š - 138 */
950 C2_OTHERNEUTRAL, /* ‹ - 139 */
951 C2_LEFTTORIGHT, /* Π- 140 */
952 C2_NOTAPPLICABLE, /* � - 141 */
953 C2_NOTAPPLICABLE, /* Ž - 142 */
954 C2_NOTAPPLICABLE, /* � - 143 */
955 C2_NOTAPPLICABLE, /* � - 144 */
956 C2_OTHERNEUTRAL, /* ‘ - 145 */
957 C2_OTHERNEUTRAL, /* ’ - 146 */
958 C2_OTHERNEUTRAL, /* “ - 147 */
959 C2_OTHERNEUTRAL, /* ” - 148 */
960 C2_OTHERNEUTRAL, /* • - 149 */
961 C2_OTHERNEUTRAL, /* – - 150 */
962 C2_OTHERNEUTRAL, /* — - 151 */
963 C2_LEFTTORIGHT, /* ˜ - 152 */
964 C2_OTHERNEUTRAL, /* ™ - 153 */
965 C2_LEFTTORIGHT, /* š - 154 */
966 C2_OTHERNEUTRAL, /* › - 155 */
967 C2_LEFTTORIGHT, /* œ - 156 */
968 C2_NOTAPPLICABLE, /* � - 157 */
969 C2_NOTAPPLICABLE, /* ž - 158 */
970 C2_LEFTTORIGHT, /* Ÿ - 159 */
971 C2_WHITESPACE, /*   - 160 */
972 C2_OTHERNEUTRAL, /* ¡ - 161 */
973 C2_EUROPETERMINATOR, /* ¢ - 162 */
974 C2_EUROPETERMINATOR, /* £ - 163 */
975 C2_EUROPETERMINATOR, /* ¤ - 164 */
976 C2_EUROPETERMINATOR, /* ¥ - 165 */
977 C2_OTHERNEUTRAL, /* ¦ - 166 */
978 C2_OTHERNEUTRAL, /* § - 167 */
979 C2_OTHERNEUTRAL, /* ¨ - 168 */
980 C2_OTHERNEUTRAL, /* © - 169 */
981 C2_OTHERNEUTRAL, /* ª - 170 */
982 C2_OTHERNEUTRAL, /* « - 171 */
983 C2_OTHERNEUTRAL, /* ¬ - 172 */
984 C2_OTHERNEUTRAL, /* ­ - 173 */
985 C2_OTHERNEUTRAL, /* ® - 174 */
986 C2_OTHERNEUTRAL, /* ¯ - 175 */
987 C2_EUROPETERMINATOR, /* ° - 176 */
988 C2_EUROPETERMINATOR, /* ± - 177 */
989 C2_EUROPENUMBER, /* ² - 178 */
990 C2_EUROPENUMBER, /* ³ - 179 */
991 C2_OTHERNEUTRAL, /* ´ - 180 */
992 C2_OTHERNEUTRAL, /* µ - 181 */
993 C2_OTHERNEUTRAL, /* ¶ - 182 */
994 C2_OTHERNEUTRAL, /* · - 183 */
995 C2_OTHERNEUTRAL, /* ¸ - 184 */
996 C2_EUROPENUMBER, /* ¹ - 185 */
997 C2_OTHERNEUTRAL, /* º - 186 */
998 C2_OTHERNEUTRAL, /* » - 187 */
999 C2_OTHERNEUTRAL, /* ¼ - 188 */
1000 C2_OTHERNEUTRAL, /* ½ - 189 */
1001 C2_OTHERNEUTRAL, /* ¾ - 190 */
1002 C2_OTHERNEUTRAL, /* ¿ - 191 */
1003 C2_LEFTTORIGHT, /* À - 192 */
1004 C2_LEFTTORIGHT, /* Á - 193 */
1005 C2_LEFTTORIGHT, /* Â - 194 */
1006 C2_LEFTTORIGHT, /* Ã - 195 */
1007 C2_LEFTTORIGHT, /* Ä - 196 */
1008 C2_LEFTTORIGHT, /* Å - 197 */
1009 C2_LEFTTORIGHT, /* Æ - 198 */
1010 C2_LEFTTORIGHT, /* Ç - 199 */
1011 C2_LEFTTORIGHT, /* È - 200 */
1012 C2_LEFTTORIGHT, /* É - 201 */
1013 C2_LEFTTORIGHT, /* Ê - 202 */
1014 C2_LEFTTORIGHT, /* Ë - 203 */
1015 C2_LEFTTORIGHT, /* Ì - 204 */
1016 C2_LEFTTORIGHT, /* Í - 205 */
1017 C2_LEFTTORIGHT, /* Î - 206 */
1018 C2_LEFTTORIGHT, /* Ï - 207 */
1019 C2_LEFTTORIGHT, /* Ð - 208 */
1020 C2_LEFTTORIGHT, /* Ñ - 209 */
1021 C2_LEFTTORIGHT, /* Ò - 210 */
1022 C2_LEFTTORIGHT, /* Ó - 211 */
1023 C2_LEFTTORIGHT, /* Ô - 212 */
1024 C2_LEFTTORIGHT, /* Õ - 213 */
1025 C2_LEFTTORIGHT, /* Ö - 214 */
1026 C2_OTHERNEUTRAL, /* × - 215 */
1027 C2_LEFTTORIGHT, /* Ø - 216 */
1028 C2_LEFTTORIGHT, /* Ù - 217 */
1029 C2_LEFTTORIGHT, /* Ú - 218 */
1030 C2_LEFTTORIGHT, /* Û - 219 */
1031 C2_LEFTTORIGHT, /* Ü - 220 */
1032 C2_LEFTTORIGHT, /* Ý - 221 */
1033 C2_LEFTTORIGHT, /* Þ - 222 */
1034 C2_LEFTTORIGHT, /* ß - 223 */
1035 C2_LEFTTORIGHT, /* à - 224 */
1036 C2_LEFTTORIGHT, /* á - 225 */
1037 C2_LEFTTORIGHT, /* â - 226 */
1038 C2_LEFTTORIGHT, /* ã - 227 */
1039 C2_LEFTTORIGHT, /* ä - 228 */
1040 C2_LEFTTORIGHT, /* å - 229 */
1041 C2_LEFTTORIGHT, /* æ - 230 */
1042 C2_LEFTTORIGHT, /* ç - 231 */
1043 C2_LEFTTORIGHT, /* è - 232 */
1044 C2_LEFTTORIGHT, /* é - 233 */
1045 C2_LEFTTORIGHT, /* ê - 234 */
1046 C2_LEFTTORIGHT, /* ë - 235 */
1047 C2_LEFTTORIGHT, /* ì - 236 */
1048 C2_LEFTTORIGHT, /* í - 237 */
1049 C2_LEFTTORIGHT, /* î - 238 */
1050 C2_LEFTTORIGHT, /* ï - 239 */
1051 C2_LEFTTORIGHT, /* ð - 240 */
1052 C2_LEFTTORIGHT, /* ñ - 241 */
1053 C2_LEFTTORIGHT, /* ò - 242 */
1054 C2_LEFTTORIGHT, /* ó - 243 */
1055 C2_LEFTTORIGHT, /* ô - 244 */
1056 C2_LEFTTORIGHT, /* õ - 245 */
1057 C2_LEFTTORIGHT, /* ö - 246 */
1058 C2_OTHERNEUTRAL, /* ÷ - 247 */
1059 C2_LEFTTORIGHT, /* ø - 248 */
1060 C2_LEFTTORIGHT, /* ù - 249 */
1061 C2_LEFTTORIGHT, /* ú - 250 */
1062 C2_LEFTTORIGHT, /* û - 251 */
1063 C2_LEFTTORIGHT, /* ü - 252 */
1064 C2_LEFTTORIGHT, /* ý - 253 */
1065 C2_LEFTTORIGHT, /* þ - 254 */
1066 C2_LEFTTORIGHT /* ÿ - 255 */
1069 const WORD OLE2NLS_CT_CType3_LUT[] = {
1070 0x0000, /* - 0 */
1071 0x0000, /* - 1 */
1072 0x0000, /* - 2 */
1073 0x0000, /* - 3 */
1074 0x0000, /* - 4 */
1075 0x0000, /* - 5 */
1076 0x0000, /* - 6 */
1077 0x0000, /* - 7 */
1078 0x0000, /* - 8 */
1079 0x0008, /* - 9 */
1080 0x0008, /* - 10 */
1081 0x0008, /* - 11 */
1082 0x0008, /* - 12 */
1083 0x0008, /* - 13 */
1084 0x0000, /* - 14 */
1085 0x0000, /* - 15 */
1086 0x0000, /* - 16 */
1087 0x0000, /* - 17 */
1088 0x0000, /* - 18 */
1089 0x0000, /* - 19 */
1090 0x0000, /* - 20 */
1091 0x0000, /* - 21 */
1092 0x0000, /* - 22 */
1093 0x0000, /* - 23 */
1094 0x0000, /* - 24 */
1095 0x0000, /* - 25 */
1096 0x0000, /* - 26 */
1097 0x0000, /* - 27 */
1098 0x0000, /* - 28 */
1099 0x0000, /* - 29 */
1100 0x0000, /* - 30 */
1101 0x0000, /* - 31 */
1102 0x0048, /* - 32 */
1103 0x0048, /* ! - 33 */
1104 0x0448, /* " - 34 */ /* " */
1105 0x0048, /* # - 35 */
1106 0x0448, /* $ - 36 */
1107 0x0048, /* % - 37 */
1108 0x0048, /* & - 38 */
1109 0x0440, /* ' - 39 */
1110 0x0048, /* ( - 40 */
1111 0x0048, /* ) - 41 */
1112 0x0048, /* * - 42 */
1113 0x0048, /* + - 43 */
1114 0x0048, /* , - 44 */
1115 0x0440, /* - - 45 */
1116 0x0048, /* . - 46 */
1117 0x0448, /* / - 47 */
1118 0x0040, /* 0 - 48 */
1119 0x0040, /* 1 - 49 */
1120 0x0040, /* 2 - 50 */
1121 0x0040, /* 3 - 51 */
1122 0x0040, /* 4 - 52 */
1123 0x0040, /* 5 - 53 */
1124 0x0040, /* 6 - 54 */
1125 0x0040, /* 7 - 55 */
1126 0x0040, /* 8 - 56 */
1127 0x0040, /* 9 - 57 */
1128 0x0048, /* : - 58 */
1129 0x0048, /* ; - 59 */
1130 0x0048, /* < - 60 */
1131 0x0448, /* = - 61 */
1132 0x0048, /* > - 62 */
1133 0x0048, /* ? - 63 */
1134 0x0448, /* @ - 64 */
1135 0x8040, /* A - 65 */
1136 0x8040, /* B - 66 */
1137 0x8040, /* C - 67 */
1138 0x8040, /* D - 68 */
1139 0x8040, /* E - 69 */
1140 0x8040, /* F - 70 */
1141 0x8040, /* G - 71 */
1142 0x8040, /* H - 72 */
1143 0x8040, /* I - 73 */
1144 0x8040, /* J - 74 */
1145 0x8040, /* K - 75 */
1146 0x8040, /* L - 76 */
1147 0x8040, /* M - 77 */
1148 0x8040, /* N - 78 */
1149 0x8040, /* O - 79 */
1150 0x8040, /* P - 80 */
1151 0x8040, /* Q - 81 */
1152 0x8040, /* R - 82 */
1153 0x8040, /* S - 83 */
1154 0x8040, /* T - 84 */
1155 0x8040, /* U - 85 */
1156 0x8040, /* V - 86 */
1157 0x8040, /* W - 87 */
1158 0x8040, /* X - 88 */
1159 0x8040, /* Y - 89 */
1160 0x8040, /* Z - 90 */
1161 0x0048, /* [ - 91 */
1162 0x0448, /* \ - 92 */
1163 0x0048, /* ] - 93 */
1164 0x0448, /* ^ - 94 */
1165 0x0448, /* _ - 95 */
1166 0x0448, /* ` - 96 */
1167 0x8040, /* a - 97 */
1168 0x8040, /* b - 98 */
1169 0x8040, /* c - 99 */
1170 0x8040, /* d - 100 */
1171 0x8040, /* e - 101 */
1172 0x8040, /* f - 102 */
1173 0x8040, /* g - 103 */
1174 0x8040, /* h - 104 */
1175 0x8040, /* i - 105 */
1176 0x8040, /* j - 106 */
1177 0x8040, /* k - 107 */
1178 0x8040, /* l - 108 */
1179 0x8040, /* m - 109 */
1180 0x8040, /* n - 110 */
1181 0x8040, /* o - 111 */
1182 0x8040, /* p - 112 */
1183 0x8040, /* q - 113 */
1184 0x8040, /* r - 114 */
1185 0x8040, /* s - 115 */
1186 0x8040, /* t - 116 */
1187 0x8040, /* u - 117 */
1188 0x8040, /* v - 118 */
1189 0x8040, /* w - 119 */
1190 0x8040, /* x - 120 */
1191 0x8040, /* y - 121 */
1192 0x8040, /* z - 122 */
1193 0x0048, /* { - 123 */
1194 0x0048, /* | - 124 */
1195 0x0048, /* } - 125 */
1196 0x0448, /* ~ - 126 */
1197 0x0000, /* \x7f - 127 */
1198 0x0000, /* € - 128 */
1199 0x0000, /* � - 129 */
1200 0x0008, /* ‚ - 130 */
1201 0x8000, /* ƒ - 131 */
1202 0x0008, /* „ - 132 */
1203 0x0008, /* … - 133 */
1204 0x0008, /* † - 134 */
1205 0x0008, /* ‡ - 135 */
1206 0x0001, /* ˆ - 136 */
1207 0x0008, /* ‰ - 137 */
1208 0x8003, /* Š - 138 */
1209 0x0008, /* ‹ - 139 */
1210 0x8000, /* Π- 140 */
1211 0x0000, /* � - 141 */
1212 0x0000, /* Ž - 142 */
1213 0x0000, /* � - 143 */
1214 0x0000, /* � - 144 */
1215 0x0088, /* ‘ - 145 */
1216 0x0088, /* ’ - 146 */
1217 0x0088, /* “ - 147 */
1218 0x0088, /* ” - 148 */
1219 0x0008, /* • - 149 */
1220 0x0400, /* – - 150 */
1221 0x0400, /* — - 151 */
1222 0x0408, /* ˜ - 152 */
1223 0x0000, /* ™ - 153 */
1224 0x8003, /* š - 154 */
1225 0x0008, /* › - 155 */
1226 0x8000, /* œ - 156 */
1227 0x0000, /* � - 157 */
1228 0x0000, /* ž - 158 */
1229 0x8003, /* Ÿ - 159 */
1230 0x0008, /*   - 160 */
1231 0x0008, /* ¡ - 161 */
1232 0x0048, /* ¢ - 162 */
1233 0x0048, /* £ - 163 */
1234 0x0008, /* ¤ - 164 */
1235 0x0048, /* ¥ - 165 */
1236 0x0048, /* ¦ - 166 */
1237 0x0008, /* § - 167 */
1238 0x0408, /* ¨ - 168 */
1239 0x0008, /* © - 169 */
1240 0x0400, /* ª - 170 */
1241 0x0008, /* « - 171 */
1242 0x0048, /* ¬ - 172 */
1243 0x0408, /* ­ - 173 */
1244 0x0008, /* ® - 174 */
1245 0x0448, /* ¯ - 175 */
1246 0x0008, /* ° - 176 */
1247 0x0008, /* ± - 177 */
1248 0x0000, /* ² - 178 */
1249 0x0000, /* ³ - 179 */
1250 0x0408, /* ´ - 180 */
1251 0x0008, /* µ - 181 */
1252 0x0008, /* ¶ - 182 */
1253 0x0008, /* · - 183 */
1254 0x0408, /* ¸ - 184 */
1255 0x0000, /* ¹ - 185 */
1256 0x0400, /* º - 186 */
1257 0x0008, /* » - 187 */
1258 0x0000, /* ¼ - 188 */
1259 0x0000, /* ½ - 189 */
1260 0x0000, /* ¾ - 190 */
1261 0x0008, /* ¿ - 191 */
1262 0x8003, /* À - 192 */
1263 0x8003, /* Á - 193 */
1264 0x8003, /* Â - 194 */
1265 0x8003, /* Ã - 195 */
1266 0x8003, /* Ä - 196 */
1267 0x8003, /* Å - 197 */
1268 0x8000, /* Æ - 198 */
1269 0x8003, /* Ç - 199 */
1270 0x8003, /* È - 200 */
1271 0x8003, /* É - 201 */
1272 0x8003, /* Ê - 202 */
1273 0x8003, /* Ë - 203 */
1274 0x8003, /* Ì - 204 */
1275 0x8003, /* Í - 205 */
1276 0x8003, /* Î - 206 */
1277 0x8003, /* Ï - 207 */
1278 0x8000, /* Ð - 208 */
1279 0x8003, /* Ñ - 209 */
1280 0x8003, /* Ò - 210 */
1281 0x8003, /* Ó - 211 */
1282 0x8003, /* Ô - 212 */
1283 0x8003, /* Õ - 213 */
1284 0x8003, /* Ö - 214 */
1285 0x0008, /* × - 215 */
1286 0x8003, /* Ø - 216 */
1287 0x8003, /* Ù - 217 */
1288 0x8003, /* Ú - 218 */
1289 0x8003, /* Û - 219 */
1290 0x8003, /* Ü - 220 */
1291 0x8003, /* Ý - 221 */
1292 0x8000, /* Þ - 222 */
1293 0x8000, /* ß - 223 */
1294 0x8003, /* à - 224 */
1295 0x8003, /* á - 225 */
1296 0x8003, /* â - 226 */
1297 0x8003, /* ã - 227 */
1298 0x8003, /* ä - 228 */
1299 0x8003, /* å - 229 */
1300 0x8000, /* æ - 230 */
1301 0x8003, /* ç - 231 */
1302 0x8003, /* è - 232 */
1303 0x8003, /* é - 233 */
1304 0x8003, /* ê - 234 */
1305 0x8003, /* ë - 235 */
1306 0x8003, /* ì - 236 */
1307 0x8003, /* í - 237 */
1308 0x8003, /* î - 238 */
1309 0x8003, /* ï - 239 */
1310 0x8000, /* ð - 240 */
1311 0x8003, /* ñ - 241 */
1312 0x8003, /* ò - 242 */
1313 0x8003, /* ó - 243 */
1314 0x8003, /* ô - 244 */
1315 0x8003, /* õ - 245 */
1316 0x8003, /* ö - 246 */
1317 0x0008, /* ÷ - 247 */
1318 0x8003, /* ø - 248 */
1319 0x8003, /* ù - 249 */
1320 0x8003, /* ú - 250 */
1321 0x8003, /* û - 251 */
1322 0x8003, /* ü - 252 */
1323 0x8003, /* ý - 253 */
1324 0x8000, /* þ - 254 */
1325 0x8003 /* ÿ - 255 */
1328 /******************************************************************************
1329 * GetStringTypeA [KERNEL32.396]
1331 BOOL WINAPI GetStringTypeA(LCID locale,DWORD dwInfoType,LPCSTR src,
1332 INT cchSrc,LPWORD chartype)
1334 return GetStringTypeExA(locale,dwInfoType,src,cchSrc,chartype);
1337 /******************************************************************************
1338 * GetStringTypeExA [KERNEL32.397]
1340 * FIXME: Ignores the locale.
1342 BOOL WINAPI GetStringTypeExA(LCID locale,DWORD dwInfoType,LPCSTR src,
1343 INT cchSrc,LPWORD chartype)
1345 int i;
1347 if ((src==NULL) || (chartype==NULL) || (src==(LPSTR)chartype))
1349 SetLastError(ERROR_INVALID_PARAMETER);
1350 return FALSE;
1353 if (cchSrc==-1)
1354 cchSrc=strlen(src)+1;
1356 switch (dwInfoType) {
1357 case CT_CTYPE1:
1358 for (i=0;i<cchSrc;i++)
1360 chartype[i] = 0;
1361 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1362 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1363 if (islower(src[i])) chartype[i]|=C1_LOWER;
1364 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1365 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1366 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1367 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1368 /* FIXME: isblank() is a GNU extension */
1369 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1370 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1371 /* C1_XDIGIT */
1373 return TRUE;
1375 case CT_CTYPE2:
1376 for (i=0;i<cchSrc;i++)
1378 chartype[i]=(WORD)CT_CType2_LUT[i];
1380 return TRUE;
1382 case CT_CTYPE3:
1383 for (i=0;i<cchSrc;i++)
1385 chartype[i]=OLE2NLS_CT_CType3_LUT[i];
1387 return TRUE;
1389 default:
1390 ERR("Unknown dwInfoType:%ld\n",dwInfoType);
1391 return FALSE;
1395 /***********************************************************************
1396 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1398 DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
1400 if(!szLang)
1401 return 0;
1403 return GetLocaleInfoA(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
1406 /***********************************************************************
1407 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1409 DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
1411 if(!szLang)
1412 return 0;
1414 return GetLocaleInfoW(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
1418 static const unsigned char LCM_Unicode_LUT[] = {
1419 6 , 3, /* - 1 */
1420 6 , 4, /* - 2 */
1421 6 , 5, /* - 3 */
1422 6 , 6, /* - 4 */
1423 6 , 7, /* - 5 */
1424 6 , 8, /* - 6 */
1425 6 , 9, /* - 7 */
1426 6 , 10, /* - 8 */
1427 7 , 5, /* - 9 */
1428 7 , 6, /* - 10 */
1429 7 , 7, /* - 11 */
1430 7 , 8, /* - 12 */
1431 7 , 9, /* - 13 */
1432 6 , 11, /* - 14 */
1433 6 , 12, /* - 15 */
1434 6 , 13, /* - 16 */
1435 6 , 14, /* - 17 */
1436 6 , 15, /* - 18 */
1437 6 , 16, /* - 19 */
1438 6 , 17, /* - 20 */
1439 6 , 18, /* - 21 */
1440 6 , 19, /* - 22 */
1441 6 , 20, /* - 23 */
1442 6 , 21, /* - 24 */
1443 6 , 22, /* - 25 */
1444 6 , 23, /* - 26 */
1445 6 , 24, /* - 27 */
1446 6 , 25, /* - 28 */
1447 6 , 26, /* - 29 */
1448 6 , 27, /* - 30 */
1449 6 , 28, /* - 31 */
1450 7 , 2, /* - 32 */
1451 7 , 28, /* ! - 33 */
1452 7 , 29, /* " - 34 */ /* " */
1453 7 , 31, /* # - 35 */
1454 7 , 33, /* $ - 36 */
1455 7 , 35, /* % - 37 */
1456 7 , 37, /* & - 38 */
1457 6 , 128, /* ' - 39 */
1458 7 , 39, /* ( - 40 */
1459 7 , 42, /* ) - 41 */
1460 7 , 45, /* * - 42 */
1461 8 , 3, /* + - 43 */
1462 7 , 47, /* , - 44 */
1463 6 , 130, /* - - 45 */
1464 7 , 51, /* . - 46 */
1465 7 , 53, /* / - 47 */
1466 12 , 3, /* 0 - 48 */
1467 12 , 33, /* 1 - 49 */
1468 12 , 51, /* 2 - 50 */
1469 12 , 70, /* 3 - 51 */
1470 12 , 88, /* 4 - 52 */
1471 12 , 106, /* 5 - 53 */
1472 12 , 125, /* 6 - 54 */
1473 12 , 144, /* 7 - 55 */
1474 12 , 162, /* 8 - 56 */
1475 12 , 180, /* 9 - 57 */
1476 7 , 55, /* : - 58 */
1477 7 , 58, /* ; - 59 */
1478 8 , 14, /* < - 60 */
1479 8 , 18, /* = - 61 */
1480 8 , 20, /* > - 62 */
1481 7 , 60, /* ? - 63 */
1482 7 , 62, /* @ - 64 */
1483 14 , 2, /* A - 65 */
1484 14 , 9, /* B - 66 */
1485 14 , 10, /* C - 67 */
1486 14 , 26, /* D - 68 */
1487 14 , 33, /* E - 69 */
1488 14 , 35, /* F - 70 */
1489 14 , 37, /* G - 71 */
1490 14 , 44, /* H - 72 */
1491 14 , 50, /* I - 73 */
1492 14 , 53, /* J - 74 */
1493 14 , 54, /* K - 75 */
1494 14 , 72, /* L - 76 */
1495 14 , 81, /* M - 77 */
1496 14 , 112, /* N - 78 */
1497 14 , 124, /* O - 79 */
1498 14 , 126, /* P - 80 */
1499 14 , 137, /* Q - 81 */
1500 14 , 138, /* R - 82 */
1501 14 , 145, /* S - 83 */
1502 14 , 153, /* T - 84 */
1503 14 , 159, /* U - 85 */
1504 14 , 162, /* V - 86 */
1505 14 , 164, /* W - 87 */
1506 14 , 166, /* X - 88 */
1507 14 , 167, /* Y - 89 */
1508 14 , 169, /* Z - 90 */
1509 7 , 63, /* [ - 91 */
1510 7 , 65, /* \ - 92 */
1511 7 , 66, /* ] - 93 */
1512 7 , 67, /* ^ - 94 */
1513 7 , 68, /* _ - 95 */
1514 7 , 72, /* ` - 96 */
1515 14 , 2, /* a - 97 */
1516 14 , 9, /* b - 98 */
1517 14 , 10, /* c - 99 */
1518 14 , 26, /* d - 100 */
1519 14 , 33, /* e - 101 */
1520 14 , 35, /* f - 102 */
1521 14 , 37, /* g - 103 */
1522 14 , 44, /* h - 104 */
1523 14 , 50, /* i - 105 */
1524 14 , 53, /* j - 106 */
1525 14 , 54, /* k - 107 */
1526 14 , 72, /* l - 108 */
1527 14 , 81, /* m - 109 */
1528 14 , 112, /* n - 110 */
1529 14 , 124, /* o - 111 */
1530 14 , 126, /* p - 112 */
1531 14 , 137, /* q - 113 */
1532 14 , 138, /* r - 114 */
1533 14 , 145, /* s - 115 */
1534 14 , 153, /* t - 116 */
1535 14 , 159, /* u - 117 */
1536 14 , 162, /* v - 118 */
1537 14 , 164, /* w - 119 */
1538 14 , 166, /* x - 120 */
1539 14 , 167, /* y - 121 */
1540 14 , 169, /* z - 122 */
1541 7 , 74, /* { - 123 */
1542 7 , 76, /* | - 124 */
1543 7 , 78, /* } - 125 */
1544 7 , 80, /* ~ - 126 */
1545 6 , 29, /* \x7f - 127 */
1546 6 , 30, /* € - 128 */
1547 6 , 31, /* � - 129 */
1548 7 , 123, /* ‚ - 130 */
1549 14 , 35, /* ƒ - 131 */
1550 7 , 127, /* „ - 132 */
1551 10 , 21, /* … - 133 */
1552 10 , 15, /* † - 134 */
1553 10 , 16, /* ‡ - 135 */
1554 7 , 67, /* ˆ - 136 */
1555 10 , 22, /* ‰ - 137 */
1556 14 , 145, /* Š - 138 */
1557 7 , 136, /* ‹ - 139 */
1558 14 + 16 , 124, /* Π- 140 */
1559 6 , 43, /* � - 141 */
1560 6 , 44, /* Ž - 142 */
1561 6 , 45, /* � - 143 */
1562 6 , 46, /* � - 144 */
1563 7 , 121, /* ‘ - 145 */
1564 7 , 122, /* ’ - 146 */
1565 7 , 125, /* “ - 147 */
1566 7 , 126, /* ” - 148 */
1567 10 , 17, /* • - 149 */
1568 6 , 137, /* – - 150 */
1569 6 , 139, /* — - 151 */
1570 7 , 93, /* ˜ - 152 */
1571 14 , 156, /* ™ - 153 */
1572 14 , 145, /* š - 154 */
1573 7 , 137, /* › - 155 */
1574 14 + 16 , 124, /* œ - 156 */
1575 6 , 59, /* � - 157 */
1576 6 , 60, /* ž - 158 */
1577 14 , 167, /* Ÿ - 159 */
1578 7 , 4, /*   - 160 */
1579 7 , 81, /* ¡ - 161 */
1580 10 , 2, /* ¢ - 162 */
1581 10 , 3, /* £ - 163 */
1582 10 , 4, /* ¤ - 164 */
1583 10 , 5, /* ¥ - 165 */
1584 7 , 82, /* ¦ - 166 */
1585 10 , 6, /* § - 167 */
1586 7 , 83, /* ¨ - 168 */
1587 10 , 7, /* © - 169 */
1588 14 , 2, /* ª - 170 */
1589 8 , 24, /* « - 171 */
1590 10 , 8, /* ¬ - 172 */
1591 6 , 131, /* ­ - 173 */
1592 10 , 9, /* ® - 174 */
1593 7 , 84, /* ¯ - 175 */
1594 10 , 10, /* ° - 176 */
1595 8 , 23, /* ± - 177 */
1596 12 , 51, /* ² - 178 */
1597 12 , 70, /* ³ - 179 */
1598 7 , 85, /* ´ - 180 */
1599 10 , 11, /* µ - 181 */
1600 10 , 12, /* ¶ - 182 */
1601 10 , 13, /* · - 183 */
1602 7 , 86, /* ¸ - 184 */
1603 12 , 33, /* ¹ - 185 */
1604 14 , 124, /* º - 186 */
1605 8 , 26, /* » - 187 */
1606 12 , 21, /* ¼ - 188 */
1607 12 , 25, /* ½ - 189 */
1608 12 , 29, /* ¾ - 190 */
1609 7 , 87, /* ¿ - 191 */
1610 14 , 2, /* À - 192 */
1611 14 , 2, /* Á - 193 */
1612 14 , 2, /* Â - 194 */
1613 14 , 2, /* Ã - 195 */
1614 14 , 2, /* Ä - 196 */
1615 14 , 2, /* Å - 197 */
1616 14 + 16 , 2, /* Æ - 198 */
1617 14 , 10, /* Ç - 199 */
1618 14 , 33, /* È - 200 */
1619 14 , 33, /* É - 201 */
1620 14 , 33, /* Ê - 202 */
1621 14 , 33, /* Ë - 203 */
1622 14 , 50, /* Ì - 204 */
1623 14 , 50, /* Í - 205 */
1624 14 , 50, /* Î - 206 */
1625 14 , 50, /* Ï - 207 */
1626 14 , 26, /* Ð - 208 */
1627 14 , 112, /* Ñ - 209 */
1628 14 , 124, /* Ò - 210 */
1629 14 , 124, /* Ó - 211 */
1630 14 , 124, /* Ô - 212 */
1631 14 , 124, /* Õ - 213 */
1632 14 , 124, /* Ö - 214 */
1633 8 , 28, /* × - 215 */
1634 14 , 124, /* Ø - 216 */
1635 14 , 159, /* Ù - 217 */
1636 14 , 159, /* Ú - 218 */
1637 14 , 159, /* Û - 219 */
1638 14 , 159, /* Ü - 220 */
1639 14 , 167, /* Ý - 221 */
1640 14 + 32 , 153, /* Þ - 222 */
1641 14 + 48 , 145, /* ß - 223 */
1642 14 , 2, /* à - 224 */
1643 14 , 2, /* á - 225 */
1644 14 , 2, /* â - 226 */
1645 14 , 2, /* ã - 227 */
1646 14 , 2, /* ä - 228 */
1647 14 , 2, /* å - 229 */
1648 14 + 16 , 2, /* æ - 230 */
1649 14 , 10, /* ç - 231 */
1650 14 , 33, /* è - 232 */
1651 14 , 33, /* é - 233 */
1652 14 , 33, /* ê - 234 */
1653 14 , 33, /* ë - 235 */
1654 14 , 50, /* ì - 236 */
1655 14 , 50, /* í - 237 */
1656 14 , 50, /* î - 238 */
1657 14 , 50, /* ï - 239 */
1658 14 , 26, /* ð - 240 */
1659 14 , 112, /* ñ - 241 */
1660 14 , 124, /* ò - 242 */
1661 14 , 124, /* ó - 243 */
1662 14 , 124, /* ô - 244 */
1663 14 , 124, /* õ - 245 */
1664 14 , 124, /* ö - 246 */
1665 8 , 29, /* ÷ - 247 */
1666 14 , 124, /* ø - 248 */
1667 14 , 159, /* ù - 249 */
1668 14 , 159, /* ú - 250 */
1669 14 , 159, /* û - 251 */
1670 14 , 159, /* ü - 252 */
1671 14 , 167, /* ý - 253 */
1672 14 + 32 , 153, /* þ - 254 */
1673 14 , 167 /* ÿ - 255 */ };
1675 static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
1677 #define LCM_Diacritic_Start 131
1679 static const unsigned char LCM_Diacritic_LUT[] = {
1680 123, /* ƒ - 131 */
1681 2, /* „ - 132 */
1682 2, /* … - 133 */
1683 2, /* † - 134 */
1684 2, /* ‡ - 135 */
1685 3, /* ˆ - 136 */
1686 2, /* ‰ - 137 */
1687 20, /* Š - 138 */
1688 2, /* ‹ - 139 */
1689 2, /* Π- 140 */
1690 2, /* � - 141 */
1691 2, /* Ž - 142 */
1692 2, /* � - 143 */
1693 2, /* � - 144 */
1694 2, /* ‘ - 145 */
1695 2, /* ’ - 146 */
1696 2, /* “ - 147 */
1697 2, /* ” - 148 */
1698 2, /* • - 149 */
1699 2, /* – - 150 */
1700 2, /* — - 151 */
1701 2, /* ˜ - 152 */
1702 2, /* ™ - 153 */
1703 20, /* š - 154 */
1704 2, /* › - 155 */
1705 2, /* œ - 156 */
1706 2, /* � - 157 */
1707 2, /* ž - 158 */
1708 19, /* Ÿ - 159 */
1709 2, /*   - 160 */
1710 2, /* ¡ - 161 */
1711 2, /* ¢ - 162 */
1712 2, /* £ - 163 */
1713 2, /* ¤ - 164 */
1714 2, /* ¥ - 165 */
1715 2, /* ¦ - 166 */
1716 2, /* § - 167 */
1717 2, /* ¨ - 168 */
1718 2, /* © - 169 */
1719 3, /* ª - 170 */
1720 2, /* « - 171 */
1721 2, /* ¬ - 172 */
1722 2, /* ­ - 173 */
1723 2, /* ® - 174 */
1724 2, /* ¯ - 175 */
1725 2, /* ° - 176 */
1726 2, /* ± - 177 */
1727 2, /* ² - 178 */
1728 2, /* ³ - 179 */
1729 2, /* ´ - 180 */
1730 2, /* µ - 181 */
1731 2, /* ¶ - 182 */
1732 2, /* · - 183 */
1733 2, /* ¸ - 184 */
1734 2, /* ¹ - 185 */
1735 3, /* º - 186 */
1736 2, /* » - 187 */
1737 2, /* ¼ - 188 */
1738 2, /* ½ - 189 */
1739 2, /* ¾ - 190 */
1740 2, /* ¿ - 191 */
1741 15, /* À - 192 */
1742 14, /* Á - 193 */
1743 18, /* Â - 194 */
1744 25, /* Ã - 195 */
1745 19, /* Ä - 196 */
1746 26, /* Å - 197 */
1747 2, /* Æ - 198 */
1748 28, /* Ç - 199 */
1749 15, /* È - 200 */
1750 14, /* É - 201 */
1751 18, /* Ê - 202 */
1752 19, /* Ë - 203 */
1753 15, /* Ì - 204 */
1754 14, /* Í - 205 */
1755 18, /* Î - 206 */
1756 19, /* Ï - 207 */
1757 104, /* Ð - 208 */
1758 25, /* Ñ - 209 */
1759 15, /* Ò - 210 */
1760 14, /* Ó - 211 */
1761 18, /* Ô - 212 */
1762 25, /* Õ - 213 */
1763 19, /* Ö - 214 */
1764 2, /* × - 215 */
1765 33, /* Ø - 216 */
1766 15, /* Ù - 217 */
1767 14, /* Ú - 218 */
1768 18, /* Û - 219 */
1769 19, /* Ü - 220 */
1770 14, /* Ý - 221 */
1771 2, /* Þ - 222 */
1772 2, /* ß - 223 */
1773 15, /* à - 224 */
1774 14, /* á - 225 */
1775 18, /* â - 226 */
1776 25, /* ã - 227 */
1777 19, /* ä - 228 */
1778 26, /* å - 229 */
1779 2, /* æ - 230 */
1780 28, /* ç - 231 */
1781 15, /* è - 232 */
1782 14, /* é - 233 */
1783 18, /* ê - 234 */
1784 19, /* ë - 235 */
1785 15, /* ì - 236 */
1786 14, /* í - 237 */
1787 18, /* î - 238 */
1788 19, /* ï - 239 */
1789 104, /* ð - 240 */
1790 25, /* ñ - 241 */
1791 15, /* ò - 242 */
1792 14, /* ó - 243 */
1793 18, /* ô - 244 */
1794 25, /* õ - 245 */
1795 19, /* ö - 246 */
1796 2, /* ÷ - 247 */
1797 33, /* ø - 248 */
1798 15, /* ù - 249 */
1799 14, /* ú - 250 */
1800 18, /* û - 251 */
1801 19, /* ü - 252 */
1802 14, /* ý - 253 */
1803 2, /* þ - 254 */
1804 19, /* ÿ - 255 */
1807 /******************************************************************************
1808 * OLE2NLS_isPunctuation [INTERNAL]
1810 static int OLE2NLS_isPunctuation(unsigned char c)
1812 /* "punctuation character" in this context is a character which is
1813 considered "less important" during word sort comparison.
1814 See LCMapString implementation for the precise definition
1815 of "less important". */
1817 return (LCM_Unicode_LUT[-2+2*c]==6);
1820 /******************************************************************************
1821 * OLE2NLS_isNonSpacing [INTERNAL]
1823 static int OLE2NLS_isNonSpacing(unsigned char c)
1825 /* This function is used by LCMapStringA. Characters
1826 for which it returns true are ignored when mapping a
1827 string with NORM_IGNORENONSPACE */
1828 return ((c==136) || (c==170) || (c==186));
1831 /******************************************************************************
1832 * OLE2NLS_isSymbol [INTERNAL]
1834 static int OLE2NLS_isSymbol(unsigned char c)
1836 /* This function is used by LCMapStringA. Characters
1837 for which it returns true are ignored when mapping a
1838 string with NORM_IGNORESYMBOLS */
1839 return ( (c!=0) && !IsCharAlphaNumericA(c) );
1842 /******************************************************************************
1843 * identity [Internal]
1845 static int identity(int c)
1847 return c;
1850 /*************************************************************************
1851 * LCMapStringA [KERNEL32.492]
1853 * Convert a string, or generate a sort key from it.
1855 * If (mapflags & LCMAP_SORTKEY), the function will generate
1856 * a sort key for the source string. Else, it will convert it
1857 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1859 * RETURNS
1860 * Error : 0.
1861 * Success : length of the result string.
1863 * NOTES
1864 * If called with scrlen = -1, the function will compute the length
1865 * of the 0-terminated string strsrc by itself.
1867 * If called with dstlen = 0, returns the buffer length that
1868 * would be required.
1870 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1871 * as if they are equal.
1872 * In the only code page implemented so far, there may not be
1873 * wide characters in strings passed to LCMapStringA,
1874 * so there is nothing to be done for this flag.
1876 INT WINAPI LCMapStringA(
1877 LCID lcid /* locale identifier created with MAKELCID;
1878 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1879 predefined values. */,
1880 DWORD mapflags /* flags */,
1881 LPCSTR srcstr /* source buffer */,
1882 INT srclen /* source length */,
1883 LPSTR dststr /* destination buffer */,
1884 INT dstlen /* destination buffer length */)
1886 int i;
1888 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1889 lcid,mapflags,srcstr,srclen,dststr,dstlen);
1891 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1893 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
1894 SetLastError(ERROR_INVALID_PARAMETER);
1895 return 0;
1897 if (srclen == -1)
1898 srclen = strlen(srcstr) + 1 ; /* (include final '\0') */
1900 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1901 LCMAP_LOWERCASE | \
1902 LCMAP_SORTKEY | \
1903 NORM_IGNORECASE | \
1904 NORM_IGNORENONSPACE | \
1905 SORT_STRINGSORT | \
1906 NORM_IGNOREWIDTH | \
1907 NORM_IGNOREKANATYPE)
1908 /* FIXME: as long as we don't support Kanakana nor Hirigana
1909 * characters, we can support NORM_IGNOREKANATYPE
1911 if (mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS)
1913 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1914 "unimplemented flags: 0x%08lx\n",
1915 lcid,
1916 mapflags,
1917 srcstr,
1918 srclen,
1919 dststr,
1920 dstlen,
1921 mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS
1925 if ( !(mapflags & LCMAP_SORTKEY) )
1927 int i,j;
1928 int (*f)(int) = identity;
1929 int flag_ignorenonspace = mapflags & NORM_IGNORENONSPACE;
1930 int flag_ignoresymbols = mapflags & NORM_IGNORESYMBOLS;
1932 if (flag_ignorenonspace || flag_ignoresymbols)
1934 /* For some values of mapflags, the length of the resulting
1935 string is not known at this point. Windows does map the string
1936 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1937 these cases. */
1938 if (dstlen==0)
1940 /* Compute required length */
1941 for (i=j=0; i < srclen; i++)
1943 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1944 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1945 j++;
1947 return j;
1950 else
1952 if (dstlen==0)
1953 return srclen;
1954 if (dstlen<srclen)
1956 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1957 return 0;
1960 if (mapflags & LCMAP_UPPERCASE)
1961 f = toupper;
1962 else if (mapflags & LCMAP_LOWERCASE)
1963 f = tolower;
1964 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1965 for (i=j=0; (i<srclen) && (j<dstlen) ; i++)
1967 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1968 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1970 dststr[j] = (CHAR) f(srcstr[i]);
1971 j++;
1974 return j;
1977 /* FIXME: This function completely ignores the "lcid" parameter. */
1978 /* else ... (mapflags & LCMAP_SORTKEY) */
1980 int unicode_len=0;
1981 int case_len=0;
1982 int diacritic_len=0;
1983 int delayed_punctuation_len=0;
1984 char *case_component;
1985 char *diacritic_component;
1986 char *delayed_punctuation_component;
1987 int room,count;
1988 int flag_stringsort = mapflags & SORT_STRINGSORT;
1990 /* compute how much room we will need */
1991 for (i=0;i<srclen;i++)
1993 int ofs;
1994 unsigned char source_char = srcstr[i];
1995 if (source_char!='\0')
1997 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
1999 unicode_len++;
2000 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
2001 unicode_len++; /* double letter */
2003 else
2005 delayed_punctuation_len++;
2009 if (isupper(source_char))
2010 case_len=unicode_len;
2012 ofs = source_char - LCM_Diacritic_Start;
2013 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
2014 diacritic_len=unicode_len;
2017 if (mapflags & NORM_IGNORECASE)
2018 case_len=0;
2019 if (mapflags & NORM_IGNORENONSPACE)
2020 diacritic_len=0;
2022 room = 2 * unicode_len /* "unicode" component */
2023 + diacritic_len /* "diacritic" component */
2024 + case_len /* "case" component */
2025 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
2026 + 4 /* four '\1' separators */
2027 + 1 ; /* terminal '\0' */
2028 if (dstlen==0)
2029 return room;
2030 else if (dstlen<room)
2032 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2033 return 0;
2035 #if 0
2036 /*FIXME the Pointercheck should not be nessesary */
2037 if (IsBadWritePtr (dststr,room))
2038 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
2039 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2040 return 0;
2042 #endif
2043 /* locate each component, write separators */
2044 diacritic_component = dststr + 2*unicode_len ;
2045 *diacritic_component++ = '\1';
2046 case_component = diacritic_component + diacritic_len ;
2047 *case_component++ = '\1';
2048 delayed_punctuation_component = case_component + case_len ;
2049 *delayed_punctuation_component++ = '\1';
2050 *delayed_punctuation_component++ = '\1';
2052 /* read source string char by char, write
2053 corresponding weight in each component. */
2054 for (i=0,count=0;i<srclen;i++)
2056 unsigned char source_char=srcstr[i];
2057 if (source_char!='\0')
2059 int type,longcode;
2060 type = LCM_Unicode_LUT[-2+2*source_char];
2061 longcode = type >> 4;
2062 type &= 15;
2063 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
2065 UINT16 encrypted_location = (1<<15) + 7 + 4*count;
2066 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
2067 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
2068 /* big-endian is used here because it lets string comparison be
2069 compatible with numerical comparison */
2071 *delayed_punctuation_component++ = type;
2072 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
2073 /* assumption : a punctuation character is never a
2074 double or accented letter */
2076 else
2078 dststr[2*count] = type;
2079 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
2080 if (longcode)
2082 if (count<case_len)
2083 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2084 if (count<diacritic_len)
2085 diacritic_component[count] = 2; /* assumption: a double letter
2086 is never accented */
2087 count++;
2089 dststr[2*count] = type;
2090 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
2091 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
2092 32 in the first column of LCM_Unicode_LUT --> longcode = 2
2093 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
2096 if (count<case_len)
2097 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2098 if (count<diacritic_len)
2100 int ofs = source_char - LCM_Diacritic_Start;
2101 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
2103 count++;
2107 dststr[room-1] = '\0';
2108 return room;
2112 /*************************************************************************
2113 * LCMapStringW [KERNEL32.493]
2115 * Convert a string, or generate a sort key from it.
2117 * NOTE
2119 * See LCMapStringA for documentation
2121 INT WINAPI LCMapStringW(
2122 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT srclen,LPWSTR dststr,
2123 INT dstlen)
2125 int i;
2127 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2128 lcid, mapflags, srcstr, srclen, dststr, dstlen);
2130 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2132 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
2133 SetLastError(ERROR_INVALID_PARAMETER);
2134 return 0;
2136 if (srclen==-1)
2137 srclen = strlenW(srcstr)+1;
2139 /* FIXME: Both this function and it's companion LCMapStringA()
2140 * completely ignore the "lcid" parameter. In place of the "lcid"
2141 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2142 * environment variable prior to invoking this function. */
2143 if (mapflags & LCMAP_SORTKEY)
2145 /* Possible values of LC_COLLATE. */
2146 char *lc_collate_default = 0; /* value prior to this function */
2147 char *lc_collate_env = 0; /* value retrieved from the environment */
2149 /* General purpose index into strings of any type. */
2150 int str_idx = 0;
2152 /* Lengths of various strings where the length is measured in
2153 * wide characters for wide character strings and in bytes for
2154 * native strings. The lengths include the NULL terminator. */
2155 size_t returned_len = 0;
2156 size_t src_native_len = 0;
2157 size_t dst_native_len = 0;
2158 size_t dststr_libc_len = 0;
2160 /* Native (character set determined by locale) versions of the
2161 * strings source and destination strings. */
2162 LPSTR src_native = 0;
2163 LPSTR dst_native = 0;
2165 /* Version of the source and destination strings using the
2166 * "wchar_t" Unicode data type needed by various libc functions. */
2167 wchar_t *srcstr_libc = 0;
2168 wchar_t *dststr_libc = 0;
2170 if(!(srcstr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2171 srclen * sizeof(wchar_t))))
2173 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2174 srclen * sizeof(wchar_t));
2175 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2176 return 0;
2179 /* Convert source string to a libc Unicode string. */
2180 for(str_idx = 0; str_idx < srclen; str_idx++)
2182 srcstr_libc[str_idx] = srcstr[str_idx];
2185 /* src_native should contain at most 3 bytes for each
2186 * multibyte characters in the original srcstr string. */
2187 src_native_len = 3 * srclen;
2188 if(!(src_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0,
2189 src_native_len)))
2191 ERR("Unable to allocate %d bytes for src_native\n", src_native_len);
2192 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2193 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2194 return 0;
2197 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2198 * current value is backed up so it can be restored after the
2199 * last LC_COLLATE sensitive function returns.
2201 * Even though the locale is adjusted for a minimum amount of
2202 * time a race condition exists where other threads may be
2203 * affected if they invoke LC_COLLATE sensitive functions. One
2204 * possible solution is to wrap all LC_COLLATE sensitive Wine
2205 * functions, like LCMapStringW(), in a mutex.
2207 * Another enhancement to the following would be to set the
2208 * LC_COLLATE locale category as a function of the "lcid"
2209 * parameter instead of the "LC_COLLATE" environment variable. */
2210 if(!(lc_collate_default = setlocale(LC_COLLATE, NULL)))
2212 ERR("Unable to query the LC_COLLATE catagory\n");
2213 SetLastError(ERROR_INVALID_PARAMETER);
2214 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2215 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2216 return 0;
2219 if(!(lc_collate_env = setlocale(LC_COLLATE, "")))
2221 ERR("Unable to inherit the LC_COLLATE locale category from the "
2222 "environment. The \"LC_COLLATE\" environment variable is "
2223 "\"%s\".\n", getenv("LC_COLLATE") ?
2224 getenv("LC_COLLATE") : "<unset>");
2225 SetLastError(ERROR_INVALID_PARAMETER);
2226 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2227 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2228 return 0;
2231 TRACE("lc_collate_default = %s\n", lc_collate_default);
2232 TRACE("lc_collate_env = %s\n", lc_collate_env);
2234 /* Convert the libc Unicode string to a native multibyte character
2235 * string. */
2236 returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1;
2237 if(returned_len == 0)
2239 LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(),
2240 0, srcstr);
2241 ERR("wcstombs failed. The string specified (%s) may contains an "
2242 "invalid character.\n", srcstr_ascii);
2243 SetLastError(ERROR_INVALID_PARAMETER);
2244 if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii);
2245 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2246 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2247 setlocale(LC_COLLATE, lc_collate_default);
2248 return 0;
2250 else if(returned_len > src_native_len)
2252 src_native[src_native_len - 1] = 0;
2253 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2254 "than expected (%d bytes).\n", src_native, returned_len,
2255 dst_native_len);
2257 /* Since this is an internal error I'm not sure what the correct
2258 * error code is. */
2259 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2261 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2262 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2263 setlocale(LC_COLLATE, lc_collate_default);
2264 return 0;
2266 src_native_len = returned_len;
2268 TRACE("src_native = %s src_native_len = %d\n",
2269 src_native, src_native_len);
2271 /* dst_native seems to contain at most 4 bytes for each byte in
2272 * the original src_native string. Change if need be since this
2273 * isn't documented by the strxfrm() man page. */
2274 dst_native_len = 4 * src_native_len;
2275 if(!(dst_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0, dst_native_len)))
2277 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len);
2278 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2279 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2280 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2281 setlocale(LC_COLLATE, lc_collate_default);
2282 return 0;
2285 /* The actual translation is done by the following call to
2286 * strxfrm(). The surrounding code could have been simplified
2287 * by calling wcsxfrm() instead except that wcsxfrm() is not
2288 * available on older Linux systems (RedHat 4.1 with
2289 * libc-5.3.12-17).
2291 * Also, it is possible that the translation could be done by
2292 * various tables as it is done in LCMapStringA(). However, I'm
2293 * not sure what those tables are. */
2294 returned_len = strxfrm(dst_native, src_native, dst_native_len) + 1;
2296 if(returned_len > dst_native_len)
2298 dst_native[dst_native_len - 1] = 0;
2299 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2300 "than expected (%d bytes).\n", dst_native, returned_len,
2301 dst_native_len);
2303 /* Since this is an internal error I'm not sure what the correct
2304 * error code is. */
2305 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2307 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2308 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2309 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2310 setlocale(LC_COLLATE, lc_collate_default);
2311 return 0;
2313 dst_native_len = returned_len;
2315 TRACE("dst_native = %s dst_native_len = %d\n",
2316 dst_native, dst_native_len);
2318 dststr_libc_len = dst_native_len;
2319 if(!(dststr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2320 dststr_libc_len * sizeof(wchar_t))))
2322 ERR("Unable to allocate %d bytes for dststr_libc\n",
2323 dststr_libc_len * sizeof(wchar_t));
2324 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2325 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2326 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2327 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2328 setlocale(LC_COLLATE, lc_collate_default);
2329 return 0;
2332 /* Convert the native multibyte string to a libc Unicode string. */
2333 returned_len = mbstowcs(dststr_libc, dst_native, dst_native_len) + 1;
2335 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2336 * function has returned. */
2337 setlocale(LC_COLLATE, lc_collate_default);
2339 if(returned_len == 0)
2341 ERR("mbstowcs failed. The native version of the translated string "
2342 "(%s) may contain an invalid character.\n", dst_native);
2343 SetLastError(ERROR_INVALID_PARAMETER);
2344 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2345 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2346 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2347 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2348 return 0;
2350 if(dstlen)
2352 if(returned_len > dstlen)
2354 ERR("mbstowcs returned a string that was longer (%d chars) "
2355 "than the buffer provided (%d chars).\n", returned_len,
2356 dstlen);
2357 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2358 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2359 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2360 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2361 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2362 return 0;
2364 dstlen = returned_len;
2366 /* Convert a libc Unicode string to the destination string. */
2367 for(str_idx = 0; str_idx < dstlen; str_idx++)
2369 dststr[str_idx] = dststr_libc[str_idx];
2371 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2372 *(((int *)dststr) + 0),
2373 *(((int *)dststr) + 1),
2374 *(((int *)dststr) + 2),
2375 *(((int *)dststr) + 3));
2377 else
2379 dstlen = returned_len;
2381 TRACE("dstlen (return) = %d\n", dstlen);
2382 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2383 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2384 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2385 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2386 return dstlen;
2388 else
2390 int (*f)(int)=identity;
2392 if (dstlen==0)
2393 return srclen;
2394 if (dstlen<srclen)
2396 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2397 return 0;
2400 if (mapflags & LCMAP_UPPERCASE)
2401 f = toupper;
2402 else if (mapflags & LCMAP_LOWERCASE)
2403 f = tolower;
2404 for (i=0; i < srclen; i++)
2405 dststr[i] = (WCHAR) f(srcstr[i]);
2406 return srclen;
2411 /***********************************************************************
2412 * OLE2NLS_EstimateMappingLength
2414 * Estimates the number of characters required to hold the string
2415 * computed by LCMapStringA.
2417 * The size is always over-estimated, with a fixed limit on the
2418 * amount of estimation error.
2420 * Note that len == -1 is not permitted.
2422 static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
2423 LPCSTR str, DWORD len)
2425 /* Estimate only for small strings to keep the estimation error from
2426 * becoming too large. */
2427 if (len < 128) return len * 8 + 5;
2428 else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
2431 /******************************************************************************
2432 * CompareStringA [KERNEL32.143]
2433 * Compares two strings using locale
2435 * RETURNS
2437 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2438 * failure: 0
2440 * NOTES
2442 * Defaults to a word sort, but uses a string sort if
2443 * SORT_STRINGSORT is set.
2444 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2446 * BUGS
2448 * This implementation ignores the locale
2450 * FIXME
2452 * Quite inefficient.
2454 UINT WINAPI CompareStringA(
2455 DWORD lcid, /* locale ID */
2456 DWORD fdwStyle, /* comparison-style options */
2457 LPCSTR s1, /* first string */
2458 DWORD l1, /* length of first string */
2459 LPCSTR s2, /* second string */
2460 DWORD l2) /* length of second string */
2462 int mapstring_flags;
2463 int len1,len2;
2464 int result;
2465 LPSTR sk1,sk2;
2466 TRACE("%s and %s\n",
2467 debugstr_a (s1), debugstr_a (s2));
2469 if ( (s1==NULL) || (s2==NULL) )
2471 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
2472 SetLastError(ERROR_INVALID_PARAMETER);
2473 return 0;
2476 if(fdwStyle & NORM_IGNORESYMBOLS)
2477 FIXME("IGNORESYMBOLS not supported\n");
2479 if (l1 == -1) l1 = strlen(s1);
2480 if (l2 == -1) l2 = strlen(s2);
2482 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2483 len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
2484 len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
2486 if ((len1==0)||(len2==0))
2487 return 0; /* something wrong happened */
2489 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
2490 sk2 = sk1 + len1;
2491 if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
2492 || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2494 ERR("Bug in LCmapStringA.\n");
2495 result = 0;
2497 else
2499 /* strcmp doesn't necessarily return -1, 0, or 1 */
2500 result = strcmp(sk1,sk2);
2502 HeapFree(GetProcessHeap(),0,sk1);
2504 if (result < 0)
2505 return 1;
2506 if (result == 0)
2507 return 2;
2509 /* must be greater, if we reach this point */
2510 return 3;
2513 /******************************************************************************
2514 * CompareStringW [KERNEL32.144]
2515 * This implementation ignores the locale
2516 * FIXME : Does only string sort. Should
2517 * be reimplemented the same way as CompareStringA.
2519 UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
2520 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2522 int len,ret;
2523 if(fdwStyle & NORM_IGNORENONSPACE)
2524 FIXME("IGNORENONSPACE not supprted\n");
2525 if(fdwStyle & NORM_IGNORESYMBOLS)
2526 FIXME("IGNORESYMBOLS not supported\n");
2528 /* Is strcmp defaulting to string sort or to word sort?? */
2529 /* FIXME: Handle NORM_STRINGSORT */
2530 l1 = (l1==-1)?strlenW(s1):l1;
2531 l2 = (l2==-1)?strlenW(s2):l2;
2532 len = l1<l2 ? l1:l2;
2533 ret = (fdwStyle & NORM_IGNORECASE) ? strncmpiW(s1,s2,len) : strncmpW(s1,s2,len);
2534 /* not equal, return 1 or 3 */
2535 if(ret!=0) return ret+2;
2536 /* same len, return 2 */
2537 if(l1==l2) return 2;
2538 /* the longer one is lexically greater */
2539 return (l1<l2)? 1 : 3;
2542 /******************************************************************************
2543 * OLE_GetFormatA [Internal]
2545 * FIXME
2546 * If datelen == 0, it should return the reguired string length.
2548 This function implements stuff for GetDateFormat() and
2549 GetTimeFormat().
2551 d single-digit (no leading zero) day (of month)
2552 dd two-digit day (of month)
2553 ddd short day-of-week name
2554 dddd long day-of-week name
2555 M single-digit month
2556 MM two-digit month
2557 MMM short month name
2558 MMMM full month name
2559 y two-digit year, no leading 0
2560 yy two-digit year
2561 yyyy four-digit year
2562 gg era string
2563 h hours with no leading zero (12-hour)
2564 hh hours with full two digits
2565 H hours with no leading zero (24-hour)
2566 HH hours with full two digits
2567 m minutes with no leading zero
2568 mm minutes with full two digits
2569 s seconds with no leading zero
2570 ss seconds with full two digits
2571 t time marker (A or P)
2572 tt time marker (AM, PM)
2573 '' used to quote literal characters
2574 '' (within a quoted string) indicates a literal '
2576 These functions REQUIRE valid locale, date, and format.
2578 static INT OLE_GetFormatA(LCID locale,
2579 DWORD flags,
2580 DWORD tflags,
2581 LPSYSTEMTIME xtime,
2582 LPCSTR _format, /*in*/
2583 LPSTR date, /*out*/
2584 INT datelen)
2586 INT inpos, outpos;
2587 int count, type, inquote, Overflow;
2588 char buf[40];
2589 char format[40];
2590 char * pos;
2591 int buflen;
2593 const char * _dgfmt[] = { "%d", "%02d" };
2594 const char ** dgfmt = _dgfmt - 1;
2596 /* report, for debugging */
2597 TRACE("(0x%lx,0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
2598 locale, flags, tflags,
2599 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2600 _format, _format, date, datelen);
2602 if(datelen == 0) {
2603 FIXME("datelen = 0, returning 255\n");
2604 return 255;
2607 /* initalize state variables and output buffer */
2608 inpos = outpos = 0;
2609 count = 0; inquote = 0; Overflow = 0;
2610 type = '\0';
2611 date[0] = buf[0] = '\0';
2613 strcpy(format,_format);
2615 /* alter the formatstring, while it works for all languages now in wine
2616 its possible that it fails when the time looks like ss:mm:hh as example*/
2617 if (tflags & (TIME_NOMINUTESORSECONDS))
2618 { if ((pos = strstr ( format, ":mm")))
2619 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2622 if (tflags & (TIME_NOSECONDS))
2623 { if ((pos = strstr ( format, ":ss")))
2624 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2628 for (inpos = 0;; inpos++) {
2629 /* 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]); */
2630 if (inquote) {
2631 if (format[inpos] == '\'') {
2632 if (format[inpos+1] == '\'') {
2633 inpos += 1;
2634 date[outpos++] = '\'';
2635 } else {
2636 inquote = 0;
2637 continue; /* we did nothing to the output */
2639 } else if (format[inpos] == '\0') {
2640 date[outpos++] = '\0';
2641 if (outpos > datelen) Overflow = 1;
2642 break;
2643 } else {
2644 date[outpos++] = format[inpos];
2645 if (outpos > datelen) {
2646 Overflow = 1;
2647 date[outpos-1] = '\0'; /* this is the last place where
2648 it's safe to write */
2649 break;
2652 } else if ( (count && (format[inpos] != type))
2653 || count == 4
2654 || (count == 2 && strchr("ghHmst", type)) )
2656 if (type == 'd') {
2657 if (count == 4) {
2658 GetLocaleInfoA(locale,
2659 LOCALE_SDAYNAME1
2660 + xtime->wDayOfWeek - 1,
2661 buf, sizeof(buf));
2662 } else if (count == 3) {
2663 GetLocaleInfoA(locale,
2664 LOCALE_SABBREVDAYNAME1
2665 + xtime->wDayOfWeek - 1,
2666 buf, sizeof(buf));
2667 } else {
2668 sprintf(buf, dgfmt[count], xtime->wDay);
2670 } else if (type == 'M') {
2671 if (count == 3) {
2672 GetLocaleInfoA(locale,
2673 LOCALE_SABBREVMONTHNAME1
2674 + xtime->wMonth - 1,
2675 buf, sizeof(buf));
2676 } else if (count == 4) {
2677 GetLocaleInfoA(locale,
2678 LOCALE_SMONTHNAME1
2679 + xtime->wMonth - 1,
2680 buf, sizeof(buf));
2681 } else {
2682 sprintf(buf, dgfmt[count], xtime->wMonth);
2684 } else if (type == 'y') {
2685 if (count == 4) {
2686 sprintf(buf, "%d", xtime->wYear);
2687 } else if (count == 3) {
2688 strcpy(buf, "yyy");
2689 WARN("unknown format, c=%c, n=%d\n", type, count);
2690 } else {
2691 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2693 } else if (type == 'g') {
2694 if (count == 2) {
2695 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2696 strcpy(buf, "AD");
2697 } else {
2698 strcpy(buf, "g");
2699 WARN("unknown format, c=%c, n=%d\n", type, count);
2701 } else if (type == 'h') {
2702 /* gives us hours 1:00 -- 12:00 */
2703 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2704 } else if (type == 'H') {
2705 /* 24-hour time */
2706 sprintf(buf, dgfmt[count], xtime->wHour);
2707 } else if ( type == 'm') {
2708 sprintf(buf, dgfmt[count], xtime->wMinute);
2709 } else if ( type == 's') {
2710 sprintf(buf, dgfmt[count], xtime->wSecond);
2711 } else if (type == 't') {
2712 if (count == 1) {
2713 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2714 } else if (count == 2) {
2715 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2716 GetLocaleInfoA(locale,
2717 (xtime->wHour<12)
2718 ? LOCALE_S1159 : LOCALE_S2359,
2719 buf, sizeof(buf));
2723 /* we need to check the next char in the format string
2724 again, no matter what happened */
2725 inpos--;
2727 /* add the contents of buf to the output */
2728 buflen = strlen(buf);
2729 if (outpos + buflen < datelen) {
2730 date[outpos] = '\0'; /* for strcat to hook onto */
2731 strcat(date, buf);
2732 outpos += buflen;
2733 } else {
2734 date[outpos] = '\0';
2735 strncat(date, buf, datelen - outpos);
2736 date[datelen - 1] = '\0';
2737 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2738 WARN("insufficient buffer\n");
2739 return 0;
2742 /* reset the variables we used to keep track of this item */
2743 count = 0;
2744 type = '\0';
2745 } else if (format[inpos] == '\0') {
2746 /* we can't check for this at the loop-head, because
2747 that breaks the printing of the last format-item */
2748 date[outpos] = '\0';
2749 break;
2750 } else if (count) {
2751 /* continuing a code for an item */
2752 count +=1;
2753 continue;
2754 } else if (strchr("hHmstyMdg", format[inpos])) {
2755 type = format[inpos];
2756 count = 1;
2757 continue;
2758 } else if (format[inpos] == '\'') {
2759 inquote = 1;
2760 continue;
2761 } else {
2762 date[outpos++] = format[inpos];
2764 /* now deal with a possible buffer overflow */
2765 if (outpos >= datelen) {
2766 date[datelen - 1] = '\0';
2767 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2768 return 0;
2772 if (Overflow) {
2773 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2776 /* finish it off with a string terminator */
2777 outpos++;
2778 /* sanity check */
2779 if (outpos > datelen-1) outpos = datelen-1;
2780 date[outpos] = '\0';
2782 TRACE("OLE_GetFormatA returns string '%s', len %d\n",
2783 date, outpos);
2784 return outpos;
2787 /******************************************************************************
2788 * OLE_GetFormatW [INTERNAL]
2790 static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
2791 LPSYSTEMTIME xtime,
2792 LPCWSTR format,
2793 LPWSTR output, INT outlen)
2795 INT inpos, outpos;
2796 int count, type=0, inquote;
2797 int Overflow; /* loop check */
2798 WCHAR buf[40];
2799 int buflen=0;
2800 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2801 WCHAR arg2[] = {'%','0','2','d',0};
2802 WCHAR *argarr[3];
2803 int datevars=0, timevars=0;
2805 argarr[0] = arg0;
2806 argarr[1] = arg1;
2807 argarr[2] = arg2;
2809 /* make a debug report */
2810 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2811 "%p with max len %d\n",
2812 locale, flags, tflags,
2813 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2814 debugstr_w(format), format, output, outlen);
2816 if(outlen == 0) {
2817 FIXME("outlen = 0, returning 255\n");
2818 return 255;
2821 /* initialize state variables */
2822 inpos = outpos = 0;
2823 count = 0;
2824 inquote = Overflow = 0;
2825 /* this is really just a sanity check */
2826 output[0] = buf[0] = 0;
2828 /* this loop is the core of the function */
2829 for (inpos = 0; /* we have several break points */ ; inpos++) {
2830 if (inquote) {
2831 if (format[inpos] == (WCHAR) '\'') {
2832 if (format[inpos+1] == '\'') {
2833 inpos++;
2834 output[outpos++] = '\'';
2835 } else {
2836 inquote = 0;
2837 continue;
2839 } else if (format[inpos] == 0) {
2840 output[outpos++] = 0;
2841 if (outpos > outlen) Overflow = 1;
2842 break; /* normal exit (within a quote) */
2843 } else {
2844 output[outpos++] = format[inpos]; /* copy input */
2845 if (outpos > outlen) {
2846 Overflow = 1;
2847 output[outpos-1] = 0;
2848 break;
2851 } else if ( (count && (format[inpos] != type))
2852 || ( (count==4 && type =='y') ||
2853 (count==4 && type =='M') ||
2854 (count==4 && type =='d') ||
2855 (count==2 && type =='g') ||
2856 (count==2 && type =='h') ||
2857 (count==2 && type =='H') ||
2858 (count==2 && type =='m') ||
2859 (count==2 && type =='s') ||
2860 (count==2 && type =='t') ) ) {
2861 if (type == 'd') {
2862 if (count == 3) {
2863 GetLocaleInfoW(locale,
2864 LOCALE_SDAYNAME1 + xtime->wDayOfWeek -1,
2865 buf, sizeof(buf)/sizeof(WCHAR) );
2866 } else if (count == 3) {
2867 GetLocaleInfoW(locale,
2868 LOCALE_SABBREVDAYNAME1 +
2869 xtime->wDayOfWeek -1,
2870 buf, sizeof(buf)/sizeof(WCHAR) );
2871 } else {
2872 wsnprintfW(buf, 5, argarr[count], xtime->wDay );
2874 } else if (type == 'M') {
2875 if (count == 4) {
2876 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
2877 xtime->wMonth -1, buf,
2878 sizeof(buf)/sizeof(WCHAR) );
2879 } else if (count == 3) {
2880 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
2881 xtime->wMonth -1, buf,
2882 sizeof(buf)/sizeof(WCHAR) );
2883 } else {
2884 wsnprintfW(buf, 5, argarr[count], xtime->wMonth);
2886 } else if (type == 'y') {
2887 if (count == 4) {
2888 wsnprintfW(buf, 6, argarr[1] /* "%d" */,
2889 xtime->wYear);
2890 } else if (count == 3) {
2891 lstrcpynAtoW(buf, "yyy", 5);
2892 } else {
2893 wsnprintfW(buf, 6, argarr[count],
2894 xtime->wYear % 100);
2896 } else if (type == 'g') {
2897 if (count == 2) {
2898 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2899 lstrcpynAtoW(buf, "AD", 5);
2900 } else {
2901 /* Win API sez we copy it verbatim */
2902 lstrcpynAtoW(buf, "g", 5);
2904 } else if (type == 'h') {
2905 /* hours 1:00-12:00 --- is this right? */
2906 wsnprintfW(buf, 5, argarr[count],
2907 (xtime->wHour-1)%12 +1);
2908 } else if (type == 'H') {
2909 wsnprintfW(buf, 5, argarr[count],
2910 xtime->wHour);
2911 } else if (type == 'm' ) {
2912 wsnprintfW(buf, 5, argarr[count],
2913 xtime->wMinute);
2914 } else if (type == 's' ) {
2915 wsnprintfW(buf, 5, argarr[count],
2916 xtime->wSecond);
2917 } else if (type == 't') {
2918 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
2919 LOCALE_S1159 : LOCALE_S2359,
2920 buf, sizeof(buf) );
2921 if (count == 1) {
2922 buf[1] = 0;
2926 /* no matter what happened, we need to check this next
2927 character the next time we loop through */
2928 inpos--;
2930 /* cat buf onto the output */
2931 outlen = strlenW(buf);
2932 if (outpos + buflen < outlen) {
2933 strcpyW( output + outpos, buf );
2934 outpos += buflen;
2935 } else {
2936 lstrcpynW( output + outpos, buf, outlen - outpos );
2937 Overflow = 1;
2938 break; /* Abnormal exit */
2941 /* reset the variables we used this time */
2942 count = 0;
2943 type = '\0';
2944 } else if (format[inpos] == 0) {
2945 /* we can't check for this at the beginning, because that
2946 would keep us from printing a format spec that ended the
2947 string */
2948 output[outpos] = 0;
2949 break; /* NORMAL EXIT */
2950 } else if (count) {
2951 /* how we keep track of the middle of a format spec */
2952 count++;
2953 continue;
2954 } else if ( (datevars && (format[inpos]=='d' ||
2955 format[inpos]=='M' ||
2956 format[inpos]=='y' ||
2957 format[inpos]=='g') ) ||
2958 (timevars && (format[inpos]=='H' ||
2959 format[inpos]=='h' ||
2960 format[inpos]=='m' ||
2961 format[inpos]=='s' ||
2962 format[inpos]=='t') ) ) {
2963 type = format[inpos];
2964 count = 1;
2965 continue;
2966 } else if (format[inpos] == '\'') {
2967 inquote = 1;
2968 continue;
2969 } else {
2970 /* unquoted literals */
2971 output[outpos++] = format[inpos];
2975 if (Overflow) {
2976 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2977 WARN(" buffer overflow\n");
2980 /* final string terminator and sanity check */
2981 outpos++;
2982 if (outpos > outlen-1) outpos = outlen-1;
2983 output[outpos] = '0';
2985 TRACE(" returning %s\n", debugstr_w(output));
2987 return (!Overflow) ? outlen : 0;
2992 /******************************************************************************
2993 * GetDateFormatA [KERNEL32.310]
2994 * Makes an ASCII string of the date
2996 * This function uses format to format the date, or, if format
2997 * is NULL, uses the default for the locale. format is a string
2998 * of literal fields and characters as follows:
3000 * - d single-digit (no leading zero) day (of month)
3001 * - dd two-digit day (of month)
3002 * - ddd short day-of-week name
3003 * - dddd long day-of-week name
3004 * - M single-digit month
3005 * - MM two-digit month
3006 * - MMM short month name
3007 * - MMMM full month name
3008 * - y two-digit year, no leading 0
3009 * - yy two-digit year
3010 * - yyyy four-digit year
3011 * - gg era string
3014 INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
3015 LPSYSTEMTIME xtime,
3016 LPCSTR format, LPSTR date,INT datelen)
3019 char format_buf[40];
3020 LPCSTR thisformat;
3021 SYSTEMTIME t;
3022 LPSYSTEMTIME thistime;
3023 LCID thislocale;
3024 INT ret;
3026 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
3027 locale,flags,xtime,format,date,datelen);
3029 if (!locale) {
3030 locale = LOCALE_SYSTEM_DEFAULT;
3033 if (locale == LOCALE_SYSTEM_DEFAULT) {
3034 thislocale = GetSystemDefaultLCID();
3035 } else if (locale == LOCALE_USER_DEFAULT) {
3036 thislocale = GetUserDefaultLCID();
3037 } else {
3038 thislocale = locale;
3041 if (xtime == NULL) {
3042 GetSystemTime(&t);
3043 thistime = &t;
3044 } else {
3045 thistime = xtime;
3048 if (format == NULL) {
3049 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
3050 ? LOCALE_SLONGDATE
3051 : LOCALE_SSHORTDATE),
3052 format_buf, sizeof(format_buf));
3053 thisformat = format_buf;
3054 } else {
3055 thisformat = format;
3059 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
3060 date, datelen);
3063 TRACE(
3064 "GetDateFormatA() returning %d, with data=%s\n",
3065 ret, date);
3066 return ret;
3069 /******************************************************************************
3070 * GetDateFormatW [KERNEL32.311]
3071 * Makes a Unicode string of the date
3073 * Acts the same as GetDateFormatA(), except that it's Unicode.
3074 * Accepts & returns sizes as counts of Unicode characters.
3077 INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
3078 LPSYSTEMTIME xtime,
3079 LPCWSTR format,
3080 LPWSTR date, INT datelen)
3082 unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
3084 FIXME("STUB (should call OLE_GetFormatW)\n");
3085 lstrcpynW(date, datearr, datelen);
3086 return ( datelen < 9) ? datelen : 9;
3091 /**************************************************************************
3092 * EnumDateFormatsA (KERNEL32.198)
3094 BOOL WINAPI EnumDateFormatsA(
3095 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3097 LCID Loc = GetUserDefaultLCID();
3098 if(!lpDateFmtEnumProc)
3100 SetLastError(ERROR_INVALID_PARAMETER);
3101 return FALSE;
3104 switch( Loc )
3107 case 0x00000407: /* (Loc,"de_DE") */
3109 switch(dwFlags)
3111 case DATE_SHORTDATE:
3112 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3113 if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
3114 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3115 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3116 return TRUE;
3117 case DATE_LONGDATE:
3118 if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
3119 if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
3120 if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
3121 return TRUE;
3122 default:
3123 FIXME("Unknown date format (%ld)\n", dwFlags);
3124 SetLastError(ERROR_INVALID_PARAMETER);
3125 return FALSE;
3129 case 0x0000040c: /* (Loc,"fr_FR") */
3131 switch(dwFlags)
3133 case DATE_SHORTDATE:
3134 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3135 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3136 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3137 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3138 return TRUE;
3139 case DATE_LONGDATE:
3140 if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
3141 if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
3142 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3143 return TRUE;
3144 default:
3145 FIXME("Unknown date format (%ld)\n", dwFlags);
3146 SetLastError(ERROR_INVALID_PARAMETER);
3147 return FALSE;
3151 case 0x00000c0c: /* (Loc,"fr_CA") */
3153 switch(dwFlags)
3155 case DATE_SHORTDATE:
3156 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3157 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3158 if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
3159 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3160 return TRUE;
3161 case DATE_LONGDATE:
3162 if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
3163 if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
3164 return TRUE;
3165 default:
3166 FIXME("Unknown date format (%ld)\n", dwFlags);
3167 SetLastError(ERROR_INVALID_PARAMETER);
3168 return FALSE;
3172 case 0x00000809: /* (Loc,"en_UK") */
3174 switch(dwFlags)
3176 case DATE_SHORTDATE:
3177 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3178 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3179 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3180 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3181 return TRUE;
3182 case DATE_LONGDATE:
3183 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3184 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3185 return TRUE;
3186 default:
3187 FIXME("Unknown date format (%ld)\n", dwFlags);
3188 SetLastError(ERROR_INVALID_PARAMETER);
3189 return FALSE;
3193 case 0x00000c09: /* (Loc,"en_AU") */
3195 switch(dwFlags)
3197 case DATE_SHORTDATE:
3198 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3199 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3200 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3201 return TRUE;
3202 case DATE_LONGDATE:
3203 if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
3204 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3205 return TRUE;
3206 default:
3207 FIXME("Unknown date format (%ld)\n", dwFlags);
3208 SetLastError(ERROR_INVALID_PARAMETER);
3209 return FALSE;
3213 case 0x00001009: /* (Loc,"en_CA") */
3215 switch(dwFlags)
3217 case DATE_SHORTDATE:
3218 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3219 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3220 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3221 if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
3222 return TRUE;
3223 case DATE_LONGDATE:
3224 if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
3225 if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
3226 return TRUE;
3227 default:
3228 FIXME("Unknown date format (%ld)\n", dwFlags);
3229 SetLastError(ERROR_INVALID_PARAMETER);
3230 return FALSE;
3234 case 0x00001409: /* (Loc,"en_NZ") */
3236 switch(dwFlags)
3238 case DATE_SHORTDATE:
3239 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3240 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3241 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3242 return TRUE;
3243 case DATE_LONGDATE:
3244 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3245 if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
3246 return TRUE;
3247 default:
3248 FIXME("Unknown date format (%ld)\n", dwFlags);
3249 SetLastError(ERROR_INVALID_PARAMETER);
3250 return FALSE;
3254 case 0x00001809: /* (Loc,"en_IE") */
3256 switch(dwFlags)
3258 case DATE_SHORTDATE:
3259 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3260 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3261 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3262 return TRUE;
3263 case DATE_LONGDATE:
3264 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3265 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3266 return TRUE;
3267 default:
3268 FIXME("Unknown date format (%ld)\n", dwFlags);
3269 SetLastError(ERROR_INVALID_PARAMETER);
3270 return FALSE;
3274 case 0x00001c09: /* (Loc,"en_ZA") */
3276 switch(dwFlags)
3278 case DATE_SHORTDATE:
3279 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3280 return TRUE;
3281 case DATE_LONGDATE:
3282 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3283 return TRUE;
3284 default:
3285 FIXME("Unknown date format (%ld)\n", dwFlags);
3286 SetLastError(ERROR_INVALID_PARAMETER);
3287 return FALSE;
3291 case 0x00002009: /* (Loc,"en_JM") */
3293 switch(dwFlags)
3295 case DATE_SHORTDATE:
3296 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3297 return TRUE;
3298 case DATE_LONGDATE:
3299 if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
3300 if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
3301 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
3302 if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
3303 return TRUE;
3304 default:
3305 FIXME("Unknown date format (%ld)\n", dwFlags);
3306 SetLastError(ERROR_INVALID_PARAMETER);
3307 return FALSE;
3311 case 0x00002809: /* (Loc,"en_BZ") */
3312 case 0x00002c09: /* (Loc,"en_TT") */
3314 switch(dwFlags)
3316 case DATE_SHORTDATE:
3317 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3318 return TRUE;
3319 case DATE_LONGDATE:
3320 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
3321 return TRUE;
3322 default:
3323 FIXME("Unknown date format (%ld)\n", dwFlags);
3324 SetLastError(ERROR_INVALID_PARAMETER);
3325 return FALSE;
3329 default: /* default to US English "en_US" */
3331 switch(dwFlags)
3333 case DATE_SHORTDATE:
3334 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
3335 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
3336 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
3337 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
3338 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3339 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
3340 return TRUE;
3341 case DATE_LONGDATE:
3342 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
3343 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
3344 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
3345 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
3346 return TRUE;
3347 default:
3348 FIXME("Unknown date format (%ld)\n", dwFlags);
3349 SetLastError(ERROR_INVALID_PARAMETER);
3350 return FALSE;
3356 /**************************************************************************
3357 * EnumDateFormatsW (KERNEL32.199)
3359 BOOL WINAPI EnumDateFormatsW(
3360 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3362 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
3363 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3364 return FALSE;
3367 /**************************************************************************
3368 * EnumTimeFormatsA (KERNEL32.210)
3370 BOOL WINAPI EnumTimeFormatsA(
3371 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3373 LCID Loc = GetUserDefaultLCID();
3374 if(!lpTimeFmtEnumProc)
3376 SetLastError(ERROR_INVALID_PARAMETER);
3377 return FALSE;
3379 if(dwFlags)
3381 FIXME("Unknown time format (%ld)\n", dwFlags);
3384 switch( Loc )
3386 case 0x00000407: /* (Loc,"de_DE") */
3388 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3389 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3390 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3391 if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
3392 if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
3393 return TRUE;
3396 case 0x0000040c: /* (Loc,"fr_FR") */
3397 case 0x00000c0c: /* (Loc,"fr_CA") */
3399 if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
3400 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3401 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3402 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3403 if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
3404 return TRUE;
3407 case 0x00000809: /* (Loc,"en_UK") */
3408 case 0x00000c09: /* (Loc,"en_AU") */
3409 case 0x00001409: /* (Loc,"en_NZ") */
3410 case 0x00001809: /* (Loc,"en_IE") */
3412 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3413 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3414 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3415 return TRUE;
3418 case 0x00001c09: /* (Loc,"en_ZA") */
3419 case 0x00002809: /* (Loc,"en_BZ") */
3420 case 0x00002c09: /* (Loc,"en_TT") */
3422 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3423 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3424 return TRUE;
3427 default: /* default to US style "en_US" */
3429 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3430 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3431 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3432 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3433 return TRUE;
3438 /**************************************************************************
3439 * EnumTimeFormatsW (KERNEL32.211)
3441 BOOL WINAPI EnumTimeFormatsW(
3442 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3444 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
3445 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3446 return FALSE;
3449 /**************************************************************************
3450 * This function is used just locally !
3451 * Description: Inverts a string.
3453 static void OLE_InvertString(char* string)
3455 char sTmpArray[128];
3456 INT counter, i = 0;
3458 for (counter = strlen(string); counter > 0; counter--)
3460 memcpy(sTmpArray + i, string + counter-1, 1);
3461 i++;
3463 memcpy(sTmpArray + i, "\0", 1);
3464 strcpy(string, sTmpArray);
3467 /***************************************************************************************
3468 * This function is used just locally !
3469 * Description: Test if the given string (psNumber) is valid or not.
3470 * The valid characters are the following:
3471 * - Characters '0' through '9'.
3472 * - One decimal point (dot) if the number is a floating-point value.
3473 * - A minus sign in the first character position if the number is
3474 * a negative value.
3475 * If the function succeeds, psBefore/psAfter will point to the string
3476 * on the right/left of the decimal symbol. pbNegative indicates if the
3477 * number is negative.
3479 static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
3481 char sNumberSet[] = "0123456789";
3482 BOOL bInDecimal = FALSE;
3484 /* Test if we do have a minus sign */
3485 if ( *pInput == '-' )
3487 *pbNegative = TRUE;
3488 pInput++; /* Jump to the next character. */
3491 while(*pInput != '\0')
3493 /* Do we have a valid numeric character */
3494 if ( strchr(sNumberSet, *pInput) != NULL )
3496 if (bInDecimal == TRUE)
3497 *psAfter++ = *pInput;
3498 else
3499 *psBefore++ = *pInput;
3501 else
3503 /* Is this a decimal point (dot) */
3504 if ( *pInput == '.' )
3506 /* Is it the first time we find it */
3507 if ((bInDecimal == FALSE))
3508 bInDecimal = TRUE;
3509 else
3510 return -1; /* ERROR: Invalid parameter */
3512 else
3514 /* It's neither a numeric character, nor a decimal point.
3515 * Thus, return an error.
3517 return -1;
3520 pInput++;
3523 /* Add an End of Line character to the output buffers */
3524 *psBefore = '\0';
3525 *psAfter = '\0';
3527 return 0;
3530 /**************************************************************************
3531 * This function is used just locally !
3532 * Description: A number could be formatted using different numbers
3533 * of "digits in group" (example: 4;3;2;0).
3534 * The first parameter of this function is an array
3535 * containing the rule to be used. It's format is the following:
3536 * |NDG|DG1|DG2|...|0|
3537 * where NDG is the number of used "digits in group" and DG1, DG2,
3538 * are the corresponding "digits in group".
3539 * Thus, this function returns the grouping value in the array
3540 * pointed by the second parameter.
3542 static INT OLE_GetGrouping(char* sRule, INT index)
3544 char sData[2], sRuleSize[2];
3545 INT nData, nRuleSize;
3547 memcpy(sRuleSize, sRule, 1);
3548 memcpy(sRuleSize+1, "\0", 1);
3549 nRuleSize = atoi(sRuleSize);
3551 if (index > 0 && index < nRuleSize)
3553 memcpy(sData, sRule+index, 1);
3554 memcpy(sData+1, "\0", 1);
3555 nData = atoi(sData);
3558 else
3560 memcpy(sData, sRule+nRuleSize-1, 1);
3561 memcpy(sData+1, "\0", 1);
3562 nData = atoi(sData);
3565 return nData;
3568 /**************************************************************************
3569 * GetNumberFormatA (KERNEL32.355)
3571 INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
3572 LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
3573 LPSTR lpNumberStr, int cchNumber)
3575 char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
3576 INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
3577 char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
3578 char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
3579 char *pStr = NULL, *pTmpStr = NULL;
3580 LCID systemDefaultLCID;
3581 BOOL bNegative = FALSE;
3582 enum Operations
3584 USE_PARAMETER,
3585 USE_LOCALEINFO,
3586 USE_SYSTEMDEFAULT,
3587 RETURN_ERROR
3588 } used_operation;
3590 strncpy(sNumber, lpvalue, 128);
3591 sNumber[127] = '\0';
3593 /* Make sure we have a valid input string, get the number
3594 * of digits before and after the decimal symbol, and check
3595 * if this is a negative number.
3597 if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
3599 nNumberDecimal = strlen(sDigitsBeforeDecimal);
3600 nDigits = strlen(sDigitsAfterDecimal);
3602 else
3604 SetLastError(ERROR_INVALID_PARAMETER);
3605 return 0;
3608 /* Which source will we use to format the string */
3609 used_operation = RETURN_ERROR;
3610 if (lpFormat != NULL)
3612 if (dwflags == 0)
3613 used_operation = USE_PARAMETER;
3615 else
3617 if (dwflags & LOCALE_NOUSEROVERRIDE)
3618 used_operation = USE_LOCALEINFO;
3619 else
3620 used_operation = USE_SYSTEMDEFAULT;
3623 /* Load the fields we need */
3624 switch(used_operation)
3626 case USE_LOCALEINFO:
3627 GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3628 GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3629 GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3630 GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3631 GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3632 GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3633 break;
3634 case USE_PARAMETER:
3635 sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
3636 strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
3637 sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
3638 strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
3639 sprintf(sILZero, "%d",lpFormat->LeadingZero);
3640 sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
3641 break;
3642 case USE_SYSTEMDEFAULT:
3643 systemDefaultLCID = GetSystemDefaultLCID();
3644 GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3645 GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3646 GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3647 GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3648 GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3649 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3650 break;
3651 default:
3652 SetLastError(ERROR_INVALID_PARAMETER);
3653 return 0;
3656 nNumberDigits = atoi(sNumberDigits);
3658 /* Remove the ";" */
3659 i=0;
3660 j = 1;
3661 for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
3663 if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
3665 memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
3666 i++;
3667 j++;
3670 sprintf(sBuffer, "%d", i);
3671 memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3672 memcpy(sRule + j, "\0", 1);
3674 /* First, format the digits before the decimal. */
3675 if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
3677 /* Working on an inverted string is easier ! */
3678 OLE_InvertString(sDigitsBeforeDecimal);
3680 nStep = nCounter = i = j = 0;
3681 nRuleIndex = 1;
3682 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3684 /* Here, we will loop until we reach the end of the string.
3685 * An internal counter (j) is used in order to know when to
3686 * insert the "digit group symbol".
3688 while (nNumberDecimal > 0)
3690 i = nCounter + nStep;
3691 memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
3692 nCounter++;
3693 j++;
3694 if (j >= nGrouping)
3696 j = 0;
3697 if (nRuleIndex < sRule[0])
3698 nRuleIndex++;
3699 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3700 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
3701 nStep+= strlen(sDigitGroupSymbol);
3704 nNumberDecimal--;
3707 memcpy(sDestination + i+1, "\0", 1);
3708 /* Get the string in the right order ! */
3709 OLE_InvertString(sDestination);
3711 else
3713 nLZ = atoi(sILZero);
3714 if (nLZ != 0)
3716 /* Use 0.xxx instead of .xxx */
3717 memcpy(sDestination, "0", 1);
3718 memcpy(sDestination+1, "\0", 1);
3720 else
3721 memcpy(sDestination, "\0", 1);
3725 /* Second, format the digits after the decimal. */
3726 j = 0;
3727 nCounter = nNumberDigits;
3728 if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
3730 i = strlen(sNumber) - strlen(pStr) + 1;
3731 strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
3732 j = strlen(sDigitsAfterDecimal);
3733 if (j < nNumberDigits)
3734 nCounter = nNumberDigits-j;
3736 for (i=0;i<nCounter;i++)
3737 memcpy(sDigitsAfterDecimal+i+j, "0", 1);
3738 memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
3740 i = strlen(sDestination);
3741 j = strlen(sDigitsAfterDecimal);
3742 /* Finally, construct the resulting formatted string. */
3744 for (nCounter=0; nCounter<i; nCounter++)
3745 memcpy(sNumber + nCounter, sDestination + nCounter, 1);
3747 memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
3749 for (i=0; i<j; i++)
3750 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
3751 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
3753 /* Is it a negative number */
3754 if (bNegative == TRUE)
3756 i = atoi(sNegNumber);
3757 pStr = sDestination;
3758 pTmpStr = sNumber;
3759 switch (i)
3761 case 0:
3762 *pStr++ = '(';
3763 while (*sNumber != '\0')
3764 *pStr++ = *pTmpStr++;
3765 *pStr++ = ')';
3766 break;
3767 case 1:
3768 *pStr++ = '-';
3769 while (*pTmpStr != '\0')
3770 *pStr++ = *pTmpStr++;
3771 break;
3772 case 2:
3773 *pStr++ = '-';
3774 *pStr++ = ' ';
3775 while (*pTmpStr != '\0')
3776 *pStr++ = *pTmpStr++;
3777 break;
3778 case 3:
3779 while (*pTmpStr != '\0')
3780 *pStr++ = *pTmpStr++;
3781 *pStr++ = '-';
3782 break;
3783 case 4:
3784 while (*pTmpStr != '\0')
3785 *pStr++ = *pTmpStr++;
3786 *pStr++ = ' ';
3787 *pStr++ = '-';
3788 break;
3789 default:
3790 while (*pTmpStr != '\0')
3791 *pStr++ = *pTmpStr++;
3792 break;
3795 else
3796 strcpy(sDestination, sNumber);
3798 /* If cchNumber is zero, then returns the number of bytes or characters
3799 * required to hold the formatted number string
3801 if (cchNumber==0)
3802 retVal = strlen(sDestination) + 1;
3803 else
3805 strncpy (lpNumberStr, sDestination, cchNumber-1);
3806 *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
3807 retVal = strlen(lpNumberStr);
3810 return retVal;
3813 /**************************************************************************
3814 * GetNumberFormatW (KERNEL32.xxx)
3816 INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
3817 LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
3818 LPWSTR lpNumberStr, int cchNumber)
3820 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue));
3822 lstrcpynW( lpNumberStr, lpvalue, cchNumber );
3823 return cchNumber? strlenW( lpNumberStr ) : 0;
3826 /**************************************************************************
3827 * GetCurrencyFormatA (KERNEL32.302)
3829 INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
3830 LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
3831 LPSTR lpCurrencyStr, int cchCurrency)
3833 UINT nPosOrder, nNegOrder;
3834 INT retVal;
3835 char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
3836 char *pDestination = sDestination;
3837 char sNumberFormated[128];
3838 char *pNumberFormated = sNumberFormated;
3839 LCID systemDefaultLCID;
3840 BOOL bIsPositive = FALSE, bValidFormat = FALSE;
3841 enum Operations
3843 USE_PARAMETER,
3844 USE_LOCALEINFO,
3845 USE_SYSTEMDEFAULT,
3846 RETURN_ERROR
3847 } used_operation;
3849 NUMBERFMTA numberFmt;
3851 /* Which source will we use to format the string */
3852 used_operation = RETURN_ERROR;
3853 if (lpFormat != NULL)
3855 if (dwflags == 0)
3856 used_operation = USE_PARAMETER;
3858 else
3860 if (dwflags & LOCALE_NOUSEROVERRIDE)
3861 used_operation = USE_LOCALEINFO;
3862 else
3863 used_operation = USE_SYSTEMDEFAULT;
3866 /* Load the fields we need */
3867 switch(used_operation)
3869 case USE_LOCALEINFO:
3870 /* Specific to CURRENCYFMTA*/
3871 GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3872 GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3873 GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3875 nPosOrder = atoi(sPosOrder);
3876 nNegOrder = atoi(sNegOrder);
3877 break;
3878 case USE_PARAMETER:
3879 /* Specific to CURRENCYFMTA*/
3880 nNegOrder = lpFormat->NegativeOrder;
3881 nPosOrder = lpFormat->PositiveOrder;
3882 strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
3883 break;
3884 case USE_SYSTEMDEFAULT:
3885 systemDefaultLCID = GetSystemDefaultLCID();
3886 /* Specific to CURRENCYFMTA*/
3887 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3888 GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3889 GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3891 nPosOrder = atoi(sPosOrder);
3892 nNegOrder = atoi(sNegOrder);
3893 break;
3894 default:
3895 SetLastError(ERROR_INVALID_PARAMETER);
3896 return 0;
3899 /* Construct a temporary number format structure */
3900 if (lpFormat != NULL)
3902 numberFmt.NumDigits = lpFormat->NumDigits;
3903 numberFmt.LeadingZero = lpFormat->LeadingZero;
3904 numberFmt.Grouping = lpFormat->Grouping;
3905 numberFmt.NegativeOrder = 0;
3906 numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
3907 numberFmt.lpThousandSep = lpFormat->lpThousandSep;
3908 bValidFormat = TRUE;
3911 /* Make a call to GetNumberFormatA() */
3912 if (*lpvalue == '-')
3914 bIsPositive = FALSE;
3915 retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3917 else
3919 bIsPositive = TRUE;
3920 retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3923 if (retVal == 0)
3924 return 0;
3926 /* construct the formatted string */
3927 if (bIsPositive)
3929 switch (nPosOrder)
3931 case 0: /* Prefix, no separation */
3932 strcpy (pDestination, sCurrencySymbol);
3933 strcat (pDestination, pNumberFormated);
3934 break;
3935 case 1: /* Suffix, no separation */
3936 strcpy (pDestination, pNumberFormated);
3937 strcat (pDestination, sCurrencySymbol);
3938 break;
3939 case 2: /* Prefix, 1 char separation */
3940 strcpy (pDestination, sCurrencySymbol);
3941 strcat (pDestination, " ");
3942 strcat (pDestination, pNumberFormated);
3943 break;
3944 case 3: /* Suffix, 1 char separation */
3945 strcpy (pDestination, pNumberFormated);
3946 strcat (pDestination, " ");
3947 strcat (pDestination, sCurrencySymbol);
3948 break;
3949 default:
3950 SetLastError(ERROR_INVALID_PARAMETER);
3951 return 0;
3954 else /* negative number */
3956 switch (nNegOrder)
3958 case 0: /* format: ($1.1) */
3959 strcpy (pDestination, "(");
3960 strcat (pDestination, sCurrencySymbol);
3961 strcat (pDestination, pNumberFormated);
3962 strcat (pDestination, ")");
3963 break;
3964 case 1: /* format: -$1.1 */
3965 strcpy (pDestination, "-");
3966 strcat (pDestination, sCurrencySymbol);
3967 strcat (pDestination, pNumberFormated);
3968 break;
3969 case 2: /* format: $-1.1 */
3970 strcpy (pDestination, sCurrencySymbol);
3971 strcat (pDestination, "-");
3972 strcat (pDestination, pNumberFormated);
3973 break;
3974 case 3: /* format: $1.1- */
3975 strcpy (pDestination, sCurrencySymbol);
3976 strcat (pDestination, pNumberFormated);
3977 strcat (pDestination, "-");
3978 break;
3979 case 4: /* format: (1.1$) */
3980 strcpy (pDestination, "(");
3981 strcat (pDestination, pNumberFormated);
3982 strcat (pDestination, sCurrencySymbol);
3983 strcat (pDestination, ")");
3984 break;
3985 case 5: /* format: -1.1$ */
3986 strcpy (pDestination, "-");
3987 strcat (pDestination, pNumberFormated);
3988 strcat (pDestination, sCurrencySymbol);
3989 break;
3990 case 6: /* format: 1.1-$ */
3991 strcpy (pDestination, pNumberFormated);
3992 strcat (pDestination, "-");
3993 strcat (pDestination, sCurrencySymbol);
3994 break;
3995 case 7: /* format: 1.1$- */
3996 strcpy (pDestination, pNumberFormated);
3997 strcat (pDestination, sCurrencySymbol);
3998 strcat (pDestination, "-");
3999 break;
4000 case 8: /* format: -1.1 $ */
4001 strcpy (pDestination, "-");
4002 strcat (pDestination, pNumberFormated);
4003 strcat (pDestination, " ");
4004 strcat (pDestination, sCurrencySymbol);
4005 break;
4006 case 9: /* format: -$ 1.1 */
4007 strcpy (pDestination, "-");
4008 strcat (pDestination, sCurrencySymbol);
4009 strcat (pDestination, " ");
4010 strcat (pDestination, pNumberFormated);
4011 break;
4012 case 10: /* format: 1.1 $- */
4013 strcpy (pDestination, pNumberFormated);
4014 strcat (pDestination, " ");
4015 strcat (pDestination, sCurrencySymbol);
4016 strcat (pDestination, "-");
4017 break;
4018 case 11: /* format: $ 1.1- */
4019 strcpy (pDestination, sCurrencySymbol);
4020 strcat (pDestination, " ");
4021 strcat (pDestination, pNumberFormated);
4022 strcat (pDestination, "-");
4023 break;
4024 case 12: /* format: $ -1.1 */
4025 strcpy (pDestination, sCurrencySymbol);
4026 strcat (pDestination, " ");
4027 strcat (pDestination, "-");
4028 strcat (pDestination, pNumberFormated);
4029 break;
4030 case 13: /* format: 1.1- $ */
4031 strcpy (pDestination, pNumberFormated);
4032 strcat (pDestination, "-");
4033 strcat (pDestination, " ");
4034 strcat (pDestination, sCurrencySymbol);
4035 break;
4036 case 14: /* format: ($ 1.1) */
4037 strcpy (pDestination, "(");
4038 strcat (pDestination, sCurrencySymbol);
4039 strcat (pDestination, " ");
4040 strcat (pDestination, pNumberFormated);
4041 strcat (pDestination, ")");
4042 break;
4043 case 15: /* format: (1.1 $) */
4044 strcpy (pDestination, "(");
4045 strcat (pDestination, pNumberFormated);
4046 strcat (pDestination, " ");
4047 strcat (pDestination, sCurrencySymbol);
4048 strcat (pDestination, ")");
4049 break;
4050 default:
4051 SetLastError(ERROR_INVALID_PARAMETER);
4052 return 0;
4056 if (cchCurrency == 0)
4057 return strlen(pDestination) + 1;
4059 else
4061 strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
4062 *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
4063 return strlen(lpCurrencyStr);
4067 /**************************************************************************
4068 * GetCurrencyFormatW (KERNEL32.303)
4070 INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
4071 LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
4072 LPWSTR lpCurrencyStr, int cchCurrency)
4074 FIXME("This API function is NOT implemented !\n");
4075 return 0;
4078 /******************************************************************************
4079 * OLE2NLS_CheckLocale [intern]
4081 static LCID OLE2NLS_CheckLocale (LCID locale)
4083 if (!locale)
4084 { locale = LOCALE_SYSTEM_DEFAULT;
4087 if (locale == LOCALE_SYSTEM_DEFAULT)
4088 { return GetSystemDefaultLCID();
4090 else if (locale == LOCALE_USER_DEFAULT)
4091 { return GetUserDefaultLCID();
4093 else
4094 { return locale;
4097 /******************************************************************************
4098 * GetTimeFormatA [KERNEL32.422]
4099 * Makes an ASCII string of the time
4101 * Formats date according to format, or locale default if format is
4102 * NULL. The format consists of literal characters and fields as follows:
4104 * h hours with no leading zero (12-hour)
4105 * hh hours with full two digits
4106 * H hours with no leading zero (24-hour)
4107 * HH hours with full two digits
4108 * m minutes with no leading zero
4109 * mm minutes with full two digits
4110 * s seconds with no leading zero
4111 * ss seconds with full two digits
4112 * t time marker (A or P)
4113 * tt time marker (AM, PM)
4116 INT WINAPI
4117 GetTimeFormatA(LCID locale, /* in */
4118 DWORD flags, /* in */
4119 LPSYSTEMTIME xtime, /* in */
4120 LPCSTR format, /* in */
4121 LPSTR timestr, /* out */
4122 INT timelen /* in */)
4123 { char format_buf[40];
4124 LPCSTR thisformat;
4125 SYSTEMTIME t;
4126 LPSYSTEMTIME thistime;
4127 LCID thislocale=0;
4128 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4129 INT ret;
4131 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
4133 thislocale = OLE2NLS_CheckLocale ( locale );
4135 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
4136 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4139 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
4141 if (format == NULL)
4142 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4143 { thislocale = GetSystemDefaultLCID();
4145 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
4146 thisformat = format_buf;
4148 else
4149 { thisformat = format;
4152 if (xtime == NULL) /* NULL means use the current local time*/
4153 { GetLocalTime(&t);
4154 thistime = &t;
4156 else
4157 { thistime = xtime;
4159 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
4160 timestr, timelen);
4161 return ret;
4165 /******************************************************************************
4166 * GetTimeFormatW [KERNEL32.423]
4167 * Makes a Unicode string of the time
4169 INT WINAPI
4170 GetTimeFormatW(LCID locale, /* in */
4171 DWORD flags, /* in */
4172 LPSYSTEMTIME xtime, /* in */
4173 LPCWSTR format, /* in */
4174 LPWSTR timestr, /* out */
4175 INT timelen /* in */)
4176 { WCHAR format_buf[40];
4177 LPCWSTR thisformat;
4178 SYSTEMTIME t;
4179 LPSYSTEMTIME thistime;
4180 LCID thislocale=0;
4181 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4182 INT ret;
4184 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
4185 xtime,debugstr_w(format),timestr,timelen);
4187 thislocale = OLE2NLS_CheckLocale ( locale );
4189 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
4190 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4193 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
4195 if (format == NULL)
4196 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4197 { thislocale = GetSystemDefaultLCID();
4199 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
4200 thisformat = format_buf;
4202 else
4203 { thisformat = format;
4206 if (xtime == NULL) /* NULL means use the current local time*/
4207 { GetLocalTime(&t);
4208 thistime = &t;
4210 else
4211 { thistime = xtime;
4214 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
4215 timestr, timelen);
4216 return ret;
4219 /******************************************************************************
4220 * EnumCalendarInfoA [KERNEL32.196]
4222 BOOL WINAPI EnumCalendarInfoA(
4223 CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
4225 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);
4226 return FALSE;