2 * National Language Support library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
17 #include "wine/unicode.h"
24 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(string);
29 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
30 * MUST contain all #defines from winnls.h
31 * last entry has NULL name, 0 id.
33 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
34 static const struct tagLOCALE_NAME2ID {
38 LOCALE_ENTRY(ILANGUAGE),
39 LOCALE_ENTRY(SLANGUAGE),
40 LOCALE_ENTRY(SENGLANGUAGE),
41 LOCALE_ENTRY(SABBREVLANGNAME),
42 LOCALE_ENTRY(SNATIVELANGNAME),
43 LOCALE_ENTRY(ICOUNTRY),
44 LOCALE_ENTRY(SCOUNTRY),
45 LOCALE_ENTRY(SENGCOUNTRY),
46 LOCALE_ENTRY(SABBREVCTRYNAME),
47 LOCALE_ENTRY(SNATIVECTRYNAME),
48 LOCALE_ENTRY(IDEFAULTLANGUAGE),
49 LOCALE_ENTRY(IDEFAULTCOUNTRY),
50 LOCALE_ENTRY(IDEFAULTCODEPAGE),
51 LOCALE_ENTRY(IDEFAULTANSICODEPAGE),
52 LOCALE_ENTRY(IDEFAULTMACCODEPAGE),
54 LOCALE_ENTRY(IMEASURE),
55 LOCALE_ENTRY(SDECIMAL),
56 LOCALE_ENTRY(STHOUSAND),
57 LOCALE_ENTRY(SGROUPING),
58 LOCALE_ENTRY(IDIGITS),
60 LOCALE_ENTRY(INEGNUMBER),
61 LOCALE_ENTRY(SNATIVEDIGITS),
62 LOCALE_ENTRY(SCURRENCY),
63 LOCALE_ENTRY(SINTLSYMBOL),
64 LOCALE_ENTRY(SMONDECIMALSEP),
65 LOCALE_ENTRY(SMONTHOUSANDSEP),
66 LOCALE_ENTRY(SMONGROUPING),
67 LOCALE_ENTRY(ICURRDIGITS),
68 LOCALE_ENTRY(IINTLCURRDIGITS),
69 LOCALE_ENTRY(ICURRENCY),
70 LOCALE_ENTRY(INEGCURR),
73 LOCALE_ENTRY(SSHORTDATE),
74 LOCALE_ENTRY(SLONGDATE),
75 LOCALE_ENTRY(STIMEFORMAT),
79 LOCALE_ENTRY(ITIMEMARKPOSN),
80 LOCALE_ENTRY(ICENTURY),
81 LOCALE_ENTRY(ITLZERO),
82 LOCALE_ENTRY(IDAYLZERO),
83 LOCALE_ENTRY(IMONLZERO),
86 LOCALE_ENTRY(ICALENDARTYPE),
87 LOCALE_ENTRY(IOPTIONALCALENDAR),
88 LOCALE_ENTRY(IFIRSTDAYOFWEEK),
89 LOCALE_ENTRY(IFIRSTWEEKOFYEAR),
90 LOCALE_ENTRY(SDAYNAME1),
91 LOCALE_ENTRY(SDAYNAME2),
92 LOCALE_ENTRY(SDAYNAME3),
93 LOCALE_ENTRY(SDAYNAME4),
94 LOCALE_ENTRY(SDAYNAME5),
95 LOCALE_ENTRY(SDAYNAME6),
96 LOCALE_ENTRY(SDAYNAME7),
97 LOCALE_ENTRY(SABBREVDAYNAME1),
98 LOCALE_ENTRY(SABBREVDAYNAME2),
99 LOCALE_ENTRY(SABBREVDAYNAME3),
100 LOCALE_ENTRY(SABBREVDAYNAME4),
101 LOCALE_ENTRY(SABBREVDAYNAME5),
102 LOCALE_ENTRY(SABBREVDAYNAME6),
103 LOCALE_ENTRY(SABBREVDAYNAME7),
104 LOCALE_ENTRY(SMONTHNAME1),
105 LOCALE_ENTRY(SMONTHNAME2),
106 LOCALE_ENTRY(SMONTHNAME3),
107 LOCALE_ENTRY(SMONTHNAME4),
108 LOCALE_ENTRY(SMONTHNAME5),
109 LOCALE_ENTRY(SMONTHNAME6),
110 LOCALE_ENTRY(SMONTHNAME7),
111 LOCALE_ENTRY(SMONTHNAME8),
112 LOCALE_ENTRY(SMONTHNAME9),
113 LOCALE_ENTRY(SMONTHNAME10),
114 LOCALE_ENTRY(SMONTHNAME11),
115 LOCALE_ENTRY(SMONTHNAME12),
116 LOCALE_ENTRY(SMONTHNAME13),
117 LOCALE_ENTRY(SABBREVMONTHNAME1),
118 LOCALE_ENTRY(SABBREVMONTHNAME2),
119 LOCALE_ENTRY(SABBREVMONTHNAME3),
120 LOCALE_ENTRY(SABBREVMONTHNAME4),
121 LOCALE_ENTRY(SABBREVMONTHNAME5),
122 LOCALE_ENTRY(SABBREVMONTHNAME6),
123 LOCALE_ENTRY(SABBREVMONTHNAME7),
124 LOCALE_ENTRY(SABBREVMONTHNAME8),
125 LOCALE_ENTRY(SABBREVMONTHNAME9),
126 LOCALE_ENTRY(SABBREVMONTHNAME10),
127 LOCALE_ENTRY(SABBREVMONTHNAME11),
128 LOCALE_ENTRY(SABBREVMONTHNAME12),
129 LOCALE_ENTRY(SABBREVMONTHNAME13),
130 LOCALE_ENTRY(SPOSITIVESIGN),
131 LOCALE_ENTRY(SNEGATIVESIGN),
132 LOCALE_ENTRY(IPOSSIGNPOSN),
133 LOCALE_ENTRY(INEGSIGNPOSN),
134 LOCALE_ENTRY(IPOSSYMPRECEDES),
135 LOCALE_ENTRY(IPOSSEPBYSPACE),
136 LOCALE_ENTRY(INEGSYMPRECEDES),
137 LOCALE_ENTRY(INEGSEPBYSPACE),
138 LOCALE_ENTRY(FONTSIGNATURE),
139 LOCALE_ENTRY(SISO639LANGNAME),
140 LOCALE_ENTRY(SISO3166CTRYNAME),
144 static char *GetLocaleSubkeyName( DWORD lctype );
146 /***********************************************************************
147 * GetUserDefaultLCID [KERNEL32.425]
149 LCID WINAPI GetUserDefaultLCID(void)
151 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT );
154 /***********************************************************************
155 * GetSystemDefaultLCID [KERNEL32.400]
157 LCID WINAPI GetSystemDefaultLCID(void)
159 return GetUserDefaultLCID();
162 /***********************************************************************
163 * GetUserDefaultLangID [KERNEL32.426]
165 LANGID WINAPI GetUserDefaultLangID(void)
167 /* caching result, if defined from environment, which should (?) not change during a WINE session */
168 static LANGID userLCID = 0;
173 char *lang,*country,*charset,*dialect,*next;
175 if (GetEnvironmentVariableA( "LANGUAGE", buf, sizeof(buf) )) goto ok;
176 if (GetEnvironmentVariableA( "LANG", buf, sizeof(buf) )) goto ok;
177 if (GetEnvironmentVariableA( "LC_ALL", buf, sizeof(buf) )) goto ok;
178 if (GetEnvironmentVariableA( "LC_MESSAGES", buf, sizeof(buf) )) goto ok;
179 if (GetEnvironmentVariableA( "LC_CTYPE", buf, sizeof(buf) )) goto ok;
181 return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
184 if (!strcmp(buf,"POSIX") || !strcmp(buf,"C"))
185 return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
190 next=strchr(lang,':'); if (next) *next++='\0';
191 dialect=strchr(lang,'@'); if (dialect) *dialect++='\0';
192 charset=strchr(lang,'.'); if (charset) *charset++='\0';
193 country=strchr(lang,'_'); if (country) *country++='\0';
195 userLCID = MAIN_GetLanguageID(lang, country, charset, dialect);
198 } while (lang && !userLCID);
202 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
204 userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
210 /***********************************************************************
211 * GetSystemDefaultLangID [KERNEL32.401]
213 LANGID WINAPI GetSystemDefaultLangID(void)
215 return GetUserDefaultLangID();
218 /******************************************************************************
219 * ConvertDefaultLocale [KERNEL32.147]
221 LCID WINAPI ConvertDefaultLocale (LCID lcid)
223 { case LOCALE_SYSTEM_DEFAULT:
224 return GetSystemDefaultLCID();
225 case LOCALE_USER_DEFAULT:
226 return GetUserDefaultLCID();
228 return MAKELCID (LANG_NEUTRAL, SUBLANG_NEUTRAL);
230 return MAKELANGID( PRIMARYLANGID(lcid), SUBLANG_NEUTRAL);
233 /* Enhanced version of LoadStringW.
234 * It takes LanguageId to find and load language dependant resources.
235 * Resource is copied as is: "binary" strings are not truncated.
236 * Return: length of resource + 1 to distinguish absent resources
237 * from the resources with zero length.
239 static INT NLS_LoadStringExW(HMODULE hModule, LANGID lang_id, UINT res_id, LPWSTR buffer, INT buflen)
247 hrsrc = FindResourceExW(hModule, RT_STRINGW, (LPCWSTR)((res_id >> 4) + 1), lang_id);
250 hmem = LoadResource(hModule, hrsrc);
253 p = LockResource(hmem);
254 string_num = res_id & 0x000f;
255 for(i = 0; i < string_num; i++)
258 TRACE("strlen = %d\n", (int)*p );
260 if (buffer == NULL) return *p;
261 i = min(buflen - 1, *p);
263 memcpy(buffer, p + 1, i * sizeof (WCHAR));
264 buffer[i] = (WCHAR) 0;
267 buffer[0] = (WCHAR) 0;
271 TRACE("\"%s\" loaded!\n", debugstr_w(buffer));
275 /******************************************************************************
276 * GetLocaleInfoA [KERNEL32.342]
279 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
281 * MS online documentation states that the string returned is NULL terminated
282 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
283 * terminated string".
285 INT WINAPI GetLocaleInfoA(LCID lcid,LCTYPE LCType,LPSTR buf,INT len)
287 LPCSTR retString = NULL;
291 DWORD dwBufferSize=128;
294 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid,LCType,buf,len);
296 if (len && (! buf) ) {
297 SetLastError(ERROR_INSUFFICIENT_BUFFER);
301 if (lcid == LOCALE_NEUTRAL || lcid == LANG_SYSTEM_DEFAULT)
303 lcid = GetSystemDefaultLCID();
305 else if (lcid == LANG_USER_DEFAULT) /*0x800*/
307 lcid = GetUserDefaultLCID();
310 /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
311 from the registry. Instead, use system default values. */
312 NoUserOverride = (LCType & LOCALE_NOUSEROVERRIDE) != 0;
314 LCType &= ~(LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP);
316 /* First, check if it's in the registry. */
317 /* All user customized values are stored in the registry by SetLocaleInfo */
318 if ( !NoUserOverride && (pacKey = GetLocaleSubkeyName(LCType)) )
323 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
325 if ( RegOpenKeyExA( HKEY_CURRENT_USER, acRealKey,
326 0, KEY_READ, &hKey) == ERROR_SUCCESS )
328 if ( RegQueryValueExA( hKey, NULL, NULL, NULL, (LPBYTE)acBuffer,
329 &dwBufferSize ) == ERROR_SUCCESS )
331 retString = acBuffer;
338 /* If not in the registry, get it from the NLS entries. */
343 /* check if language is registered in the kernel32 resources */
344 if((res_size = NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid),
345 LCType, wcBuffer, sizeof(wcBuffer)/sizeof(wcBuffer[0])))) {
346 WideCharToMultiByte(CP_ACP, 0, wcBuffer, res_size, acBuffer, dwBufferSize, NULL, NULL);
347 retString = acBuffer;
352 /* if not found report a most descriptive error */
355 /* If we are through all of this, retLen should not be zero anymore.
356 If it is, the value is not supported */
358 while (locale_name2id[i].name!=NULL) {
359 if (LCType == locale_name2id[i].id) {
360 retString = locale_name2id[i].name;
366 FIXME("Unkown LC type %lX\n", LCType);
368 FIXME("'%s' is not defined for your language (%04X).\n"
369 "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
370 "and submit patch for inclusion into the next Wine release.\n",
371 retString, LOWORD(lcid));
372 SetLastError(ERROR_INVALID_PARAMETER);
376 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
377 if (LCType == LOCALE_FONTSIGNATURE) {
379 len = (len < sizeof(FONTSIGNATURE)) ? len : sizeof(FONTSIGNATURE);
380 memcpy(buf, retString, len);
383 return sizeof(FONTSIGNATURE);
385 /* if len=0 return only the length, don't touch the buffer*/
387 lstrcpynA(buf,retString,len);
388 return strlen(buf) + 1;
390 return strlen(retString)+1;
393 /******************************************************************************
394 * GetLocaleInfoW [KERNEL32.343]
397 * MS documentation states that len "specifies the size, in bytes (ANSI version)
398 * or characters (Unicode version), of" wbuf. Thus the number returned is
399 * the same between GetLocaleInfoW and GetLocaleInfoA.
401 INT WINAPI GetLocaleInfoW(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT len)
405 if (len && (! wbuf) )
406 { SetLastError(ERROR_INSUFFICIENT_BUFFER);
410 abuf = (LPSTR)HeapAlloc(GetProcessHeap(),0,len);
411 wlen = GetLocaleInfoA(lcid, LCType, abuf, len);
413 if (wlen && len) /* if len=0 return only the length*/
414 lstrcpynAtoW(wbuf,abuf,len);
416 HeapFree(GetProcessHeap(),0,abuf);
420 /******************************************************************************
422 * GetLocaleSubkeyName [helper function]
424 * - For use with the registry.
425 * - Gets the registry subkey name for a given lctype.
427 static char *GetLocaleSubkeyName( DWORD lctype )
433 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
434 * the values are stored in the registry, confirmed under Windows,
435 * for the ones that actually assign pacKey. Cases that aren't finished
436 * have not been confirmed, so that must be done before they can be
439 case LOCALE_SDATE : /* The date separator. */
442 case LOCALE_ICURRDIGITS:
443 pacKey = "iCurrDigits";
445 case LOCALE_SDECIMAL :
448 case LOCALE_ICURRENCY:
449 pacKey = "iCurrency";
451 case LOCALE_SGROUPING :
452 pacKey = "sGrouping";
460 /* case LOCALE_ICALENDARTYPE: */
461 /* case LOCALE_IFIRSTDAYOFWEEK: */
462 /* case LOCALE_IFIRSTWEEKOFYEAR: */
463 /* case LOCALE_SYEARMONTH : */
464 /* case LOCALE_SPOSITIVESIGN : */
465 /* case LOCALE_IPAPERSIZE: */
467 case LOCALE_SLONGDATE :
468 pacKey = "sLongDate";
470 case LOCALE_SMONDECIMALSEP :
471 pacKey = "sMonDecimalSep";
473 case LOCALE_SMONGROUPING:
474 pacKey = "sMonGrouping";
476 case LOCALE_IMEASURE:
479 case LOCALE_SMONTHOUSANDSEP :
480 pacKey = "sMonThousandSep";
482 case LOCALE_INEGCURR:
485 case LOCALE_SNEGATIVESIGN :
486 pacKey = "sNegativeSign";
488 case LOCALE_INEGNUMBER:
489 pacKey = "iNegNumber";
491 case LOCALE_SSHORTDATE :
492 pacKey = "sShortDate";
494 case LOCALE_ILDATE: /* Long Date format ordering specifier. */
503 case LOCALE_ITIME: /* Time format specifier. */
506 case LOCALE_STHOUSAND :
507 pacKey = "sThousand";
509 case LOCALE_S1159: /* AM */
515 case LOCALE_S2359: /* PM */
518 case LOCALE_STIMEFORMAT :
519 pacKey = "sTimeFormat";
521 case LOCALE_SCURRENCY:
522 pacKey = "sCurrency";
525 /* The following are not listed under MSDN as supported,
526 * but seem to be used and also stored in the registry.
532 case LOCALE_SCOUNTRY:
535 case LOCALE_ICOUNTRY:
538 case LOCALE_SLANGUAGE:
539 pacKey = "sLanguage";
549 /******************************************************************************
550 * SetLocaleInfoA [KERNEL32.656]
552 BOOL16 WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
558 if ( (pacKey = GetLocaleSubkeyName(lctype)) )
560 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
561 if ( RegCreateKeyA( HKEY_CURRENT_USER, acRealKey,
562 &hKey ) == ERROR_SUCCESS )
564 if ( RegSetValueExA( hKey, NULL, 0, REG_SZ,
565 data, strlen(data)+1 ) != ERROR_SUCCESS )
567 ERR("SetLocaleInfoA: %s did not work\n", pacKey );
574 FIXME("(%ld,%ld,%s): stub\n",lcid,lctype,data);
579 /******************************************************************************
580 * IsValidLocale [KERNEL32.489]
582 BOOL WINAPI IsValidLocale(LCID lcid,DWORD flags)
584 /* check if language is registered in the kernel32 resources */
585 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW, (LPCWSTR)LOCALE_ILANGUAGE, LOWORD(lcid)))
591 static BOOL CALLBACK EnumResourceLanguagesProcW(HMODULE hModule, LPCWSTR type,
592 LPCWSTR name, WORD LangID, LONG lParam)
596 LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
597 sprintf(bufA, "%08X", (UINT)LangID);
598 MultiByteToWideChar(CP_ACP, 0, bufA, -1, bufW, sizeof(bufW)/sizeof(bufW[0]));
599 return lpfnLocaleEnum(bufW);
602 /******************************************************************************
603 * EnumSystemLocalesW [KERNEL32.209]
605 BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum,
608 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
610 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW,
611 (LPCWSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcW,
612 (LONG)lpfnLocaleEnum);
617 static BOOL CALLBACK EnumResourceLanguagesProcA(HMODULE hModule, LPCSTR type,
618 LPCSTR name, WORD LangID, LONG lParam)
621 LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
622 sprintf(bufA, "%08X", (UINT)LangID);
623 return lpfnLocaleEnum(bufA);
626 /******************************************************************************
627 * EnumSystemLocalesA [KERNEL32.208]
629 BOOL WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum,
632 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
634 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
635 (LPCSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcA,
636 (LONG)lpfnLocaleEnum);
641 static const unsigned char CT_CType2_LUT[] = {
642 C2_NOTAPPLICABLE, /* - 0 */
643 C2_NOTAPPLICABLE, /* - 1 */
644 C2_NOTAPPLICABLE, /* - 2 */
645 C2_NOTAPPLICABLE, /* - 3 */
646 C2_NOTAPPLICABLE, /* - 4 */
647 C2_NOTAPPLICABLE, /* - 5 */
648 C2_NOTAPPLICABLE, /* - 6 */
649 C2_NOTAPPLICABLE, /* - 7 */
650 C2_NOTAPPLICABLE, /* - 8 */
651 C2_SEGMENTSEPARATOR, /* - 9 */
652 C2_NOTAPPLICABLE, /* - 10 */
653 C2_NOTAPPLICABLE, /* - 11 */
654 C2_NOTAPPLICABLE, /* - 12 */
655 C2_NOTAPPLICABLE, /* - 13 */
656 C2_NOTAPPLICABLE, /* - 14 */
657 C2_NOTAPPLICABLE, /* - 15 */
658 C2_NOTAPPLICABLE, /* - 16 */
659 C2_NOTAPPLICABLE, /* - 17 */
660 C2_NOTAPPLICABLE, /* - 18 */
661 C2_NOTAPPLICABLE, /* - 19 */
662 C2_NOTAPPLICABLE, /* - 20 */
663 C2_NOTAPPLICABLE, /* - 21 */
664 C2_NOTAPPLICABLE, /* - 22 */
665 C2_NOTAPPLICABLE, /* - 23 */
666 C2_NOTAPPLICABLE, /* - 24 */
667 C2_NOTAPPLICABLE, /* - 25 */
668 C2_NOTAPPLICABLE, /* - 26 */
669 C2_NOTAPPLICABLE, /* - 27 */
670 C2_NOTAPPLICABLE, /* - 28 */
671 C2_NOTAPPLICABLE, /* - 29 */
672 C2_NOTAPPLICABLE, /* - 30 */
673 C2_NOTAPPLICABLE, /* - 31 */
674 C2_WHITESPACE, /* - 32 */
675 C2_OTHERNEUTRAL, /* ! - 33 */
676 C2_OTHERNEUTRAL, /* " - 34 */ /* " */
677 C2_EUROPETERMINATOR, /* # - 35 */
678 C2_EUROPETERMINATOR, /* $ - 36 */
679 C2_EUROPETERMINATOR, /* % - 37 */
680 C2_LEFTTORIGHT, /* & - 38 */
681 C2_OTHERNEUTRAL, /* ' - 39 */
682 C2_OTHERNEUTRAL, /* ( - 40 */
683 C2_OTHERNEUTRAL, /* ) - 41 */
684 C2_OTHERNEUTRAL, /* * - 42 */
685 C2_EUROPETERMINATOR, /* + - 43 */
686 C2_COMMONSEPARATOR, /* , - 44 */
687 C2_EUROPETERMINATOR, /* - - 45 */
688 C2_EUROPESEPARATOR, /* . - 46 */
689 C2_EUROPESEPARATOR, /* / - 47 */
690 C2_EUROPENUMBER, /* 0 - 48 */
691 C2_EUROPENUMBER, /* 1 - 49 */
692 C2_EUROPENUMBER, /* 2 - 50 */
693 C2_EUROPENUMBER, /* 3 - 51 */
694 C2_EUROPENUMBER, /* 4 - 52 */
695 C2_EUROPENUMBER, /* 5 - 53 */
696 C2_EUROPENUMBER, /* 6 - 54 */
697 C2_EUROPENUMBER, /* 7 - 55 */
698 C2_EUROPENUMBER, /* 8 - 56 */
699 C2_EUROPENUMBER, /* 9 - 57 */
700 C2_COMMONSEPARATOR, /* : - 58 */
701 C2_OTHERNEUTRAL, /* ; - 59 */
702 C2_OTHERNEUTRAL, /* < - 60 */
703 C2_OTHERNEUTRAL, /* = - 61 */
704 C2_OTHERNEUTRAL, /* > - 62 */
705 C2_OTHERNEUTRAL, /* ? - 63 */
706 C2_LEFTTORIGHT, /* @ - 64 */
707 C2_LEFTTORIGHT, /* A - 65 */
708 C2_LEFTTORIGHT, /* B - 66 */
709 C2_LEFTTORIGHT, /* C - 67 */
710 C2_LEFTTORIGHT, /* D - 68 */
711 C2_LEFTTORIGHT, /* E - 69 */
712 C2_LEFTTORIGHT, /* F - 70 */
713 C2_LEFTTORIGHT, /* G - 71 */
714 C2_LEFTTORIGHT, /* H - 72 */
715 C2_LEFTTORIGHT, /* I - 73 */
716 C2_LEFTTORIGHT, /* J - 74 */
717 C2_LEFTTORIGHT, /* K - 75 */
718 C2_LEFTTORIGHT, /* L - 76 */
719 C2_LEFTTORIGHT, /* M - 77 */
720 C2_LEFTTORIGHT, /* N - 78 */
721 C2_LEFTTORIGHT, /* O - 79 */
722 C2_LEFTTORIGHT, /* P - 80 */
723 C2_LEFTTORIGHT, /* Q - 81 */
724 C2_LEFTTORIGHT, /* R - 82 */
725 C2_LEFTTORIGHT, /* S - 83 */
726 C2_LEFTTORIGHT, /* T - 84 */
727 C2_LEFTTORIGHT, /* U - 85 */
728 C2_LEFTTORIGHT, /* V - 86 */
729 C2_LEFTTORIGHT, /* W - 87 */
730 C2_LEFTTORIGHT, /* X - 88 */
731 C2_LEFTTORIGHT, /* Y - 89 */
732 C2_LEFTTORIGHT, /* Z - 90 */
733 C2_OTHERNEUTRAL, /* [ - 91 */
734 C2_OTHERNEUTRAL, /* \ - 92 */
735 C2_OTHERNEUTRAL, /* ] - 93 */
736 C2_OTHERNEUTRAL, /* ^ - 94 */
737 C2_OTHERNEUTRAL, /* _ - 95 */
738 C2_OTHERNEUTRAL, /* ` - 96 */
739 C2_LEFTTORIGHT, /* a - 97 */
740 C2_LEFTTORIGHT, /* b - 98 */
741 C2_LEFTTORIGHT, /* c - 99 */
742 C2_LEFTTORIGHT, /* d - 100 */
743 C2_LEFTTORIGHT, /* e - 101 */
744 C2_LEFTTORIGHT, /* f - 102 */
745 C2_LEFTTORIGHT, /* g - 103 */
746 C2_LEFTTORIGHT, /* h - 104 */
747 C2_LEFTTORIGHT, /* i - 105 */
748 C2_LEFTTORIGHT, /* j - 106 */
749 C2_LEFTTORIGHT, /* k - 107 */
750 C2_LEFTTORIGHT, /* l - 108 */
751 C2_LEFTTORIGHT, /* m - 109 */
752 C2_LEFTTORIGHT, /* n - 110 */
753 C2_LEFTTORIGHT, /* o - 111 */
754 C2_LEFTTORIGHT, /* p - 112 */
755 C2_LEFTTORIGHT, /* q - 113 */
756 C2_LEFTTORIGHT, /* r - 114 */
757 C2_LEFTTORIGHT, /* s - 115 */
758 C2_LEFTTORIGHT, /* t - 116 */
759 C2_LEFTTORIGHT, /* u - 117 */
760 C2_LEFTTORIGHT, /* v - 118 */
761 C2_LEFTTORIGHT, /* w - 119 */
762 C2_LEFTTORIGHT, /* x - 120 */
763 C2_LEFTTORIGHT, /* y - 121 */
764 C2_LEFTTORIGHT, /* z - 122 */
765 C2_OTHERNEUTRAL, /* { - 123 */
766 C2_OTHERNEUTRAL, /* | - 124 */
767 C2_OTHERNEUTRAL, /* } - 125 */
768 C2_OTHERNEUTRAL, /* ~ - 126 */
769 C2_NOTAPPLICABLE, /*
\7f - 127 */
770 C2_NOTAPPLICABLE, /*
\80 - 128 */
771 C2_NOTAPPLICABLE, /*
\81 - 129 */
772 C2_OTHERNEUTRAL, /*
\82 - 130 */
773 C2_LEFTTORIGHT, /*
\83 - 131 */
774 C2_OTHERNEUTRAL, /*
\84 - 132 */
775 C2_OTHERNEUTRAL, /*
\85 - 133 */
776 C2_OTHERNEUTRAL, /*
\86 - 134 */
777 C2_OTHERNEUTRAL, /*
\87 - 135 */
778 C2_LEFTTORIGHT, /*
\88 - 136 */
779 C2_EUROPETERMINATOR, /*
\89 - 137 */
780 C2_LEFTTORIGHT, /*
\8a - 138 */
781 C2_OTHERNEUTRAL, /*
\8b - 139 */
782 C2_LEFTTORIGHT, /*
\8c - 140 */
783 C2_NOTAPPLICABLE, /*
\8d - 141 */
784 C2_NOTAPPLICABLE, /*
\8e - 142 */
785 C2_NOTAPPLICABLE, /*
\8f - 143 */
786 C2_NOTAPPLICABLE, /*
\90 - 144 */
787 C2_OTHERNEUTRAL, /*
\91 - 145 */
788 C2_OTHERNEUTRAL, /*
\92 - 146 */
789 C2_OTHERNEUTRAL, /*
\93 - 147 */
790 C2_OTHERNEUTRAL, /*
\94 - 148 */
791 C2_OTHERNEUTRAL, /*
\95 - 149 */
792 C2_OTHERNEUTRAL, /*
\96 - 150 */
793 C2_OTHERNEUTRAL, /*
\97 - 151 */
794 C2_LEFTTORIGHT, /*
\98 - 152 */
795 C2_OTHERNEUTRAL, /*
\99 - 153 */
796 C2_LEFTTORIGHT, /*
\9a - 154 */
797 C2_OTHERNEUTRAL, /*
\9b - 155 */
798 C2_LEFTTORIGHT, /*
\9c - 156 */
799 C2_NOTAPPLICABLE, /*
\9d - 157 */
800 C2_NOTAPPLICABLE, /*
\9e - 158 */
801 C2_LEFTTORIGHT, /*
\9f - 159 */
802 C2_WHITESPACE, /* - 160 */
803 C2_OTHERNEUTRAL, /* ¡ - 161 */
804 C2_EUROPETERMINATOR, /* ¢ - 162 */
805 C2_EUROPETERMINATOR, /* £ - 163 */
806 C2_EUROPETERMINATOR, /* ¤ - 164 */
807 C2_EUROPETERMINATOR, /* ¥ - 165 */
808 C2_OTHERNEUTRAL, /* ¦ - 166 */
809 C2_OTHERNEUTRAL, /* § - 167 */
810 C2_OTHERNEUTRAL, /* ¨ - 168 */
811 C2_OTHERNEUTRAL, /* © - 169 */
812 C2_OTHERNEUTRAL, /* ª - 170 */
813 C2_OTHERNEUTRAL, /* « - 171 */
814 C2_OTHERNEUTRAL, /* ¬ - 172 */
815 C2_OTHERNEUTRAL, /* - 173 */
816 C2_OTHERNEUTRAL, /* ® - 174 */
817 C2_OTHERNEUTRAL, /* ¯ - 175 */
818 C2_EUROPETERMINATOR, /* ° - 176 */
819 C2_EUROPETERMINATOR, /* ± - 177 */
820 C2_EUROPENUMBER, /* ² - 178 */
821 C2_EUROPENUMBER, /* ³ - 179 */
822 C2_OTHERNEUTRAL, /* ´ - 180 */
823 C2_OTHERNEUTRAL, /* µ - 181 */
824 C2_OTHERNEUTRAL, /* ¶ - 182 */
825 C2_OTHERNEUTRAL, /* · - 183 */
826 C2_OTHERNEUTRAL, /* ¸ - 184 */
827 C2_EUROPENUMBER, /* ¹ - 185 */
828 C2_OTHERNEUTRAL, /* º - 186 */
829 C2_OTHERNEUTRAL, /* » - 187 */
830 C2_OTHERNEUTRAL, /* ¼ - 188 */
831 C2_OTHERNEUTRAL, /* ½ - 189 */
832 C2_OTHERNEUTRAL, /* ¾ - 190 */
833 C2_OTHERNEUTRAL, /* ¿ - 191 */
834 C2_LEFTTORIGHT, /* À - 192 */
835 C2_LEFTTORIGHT, /* Á - 193 */
836 C2_LEFTTORIGHT, /* Â - 194 */
837 C2_LEFTTORIGHT, /* Ã - 195 */
838 C2_LEFTTORIGHT, /* Ä - 196 */
839 C2_LEFTTORIGHT, /* Å - 197 */
840 C2_LEFTTORIGHT, /* Æ - 198 */
841 C2_LEFTTORIGHT, /* Ç - 199 */
842 C2_LEFTTORIGHT, /* È - 200 */
843 C2_LEFTTORIGHT, /* É - 201 */
844 C2_LEFTTORIGHT, /* Ê - 202 */
845 C2_LEFTTORIGHT, /* Ë - 203 */
846 C2_LEFTTORIGHT, /* Ì - 204 */
847 C2_LEFTTORIGHT, /* Í - 205 */
848 C2_LEFTTORIGHT, /* Î - 206 */
849 C2_LEFTTORIGHT, /* Ï - 207 */
850 C2_LEFTTORIGHT, /* Ð - 208 */
851 C2_LEFTTORIGHT, /* Ñ - 209 */
852 C2_LEFTTORIGHT, /* Ò - 210 */
853 C2_LEFTTORIGHT, /* Ó - 211 */
854 C2_LEFTTORIGHT, /* Ô - 212 */
855 C2_LEFTTORIGHT, /* Õ - 213 */
856 C2_LEFTTORIGHT, /* Ö - 214 */
857 C2_OTHERNEUTRAL, /* × - 215 */
858 C2_LEFTTORIGHT, /* Ø - 216 */
859 C2_LEFTTORIGHT, /* Ù - 217 */
860 C2_LEFTTORIGHT, /* Ú - 218 */
861 C2_LEFTTORIGHT, /* Û - 219 */
862 C2_LEFTTORIGHT, /* Ü - 220 */
863 C2_LEFTTORIGHT, /* Ý - 221 */
864 C2_LEFTTORIGHT, /* Þ - 222 */
865 C2_LEFTTORIGHT, /* ß - 223 */
866 C2_LEFTTORIGHT, /* à - 224 */
867 C2_LEFTTORIGHT, /* á - 225 */
868 C2_LEFTTORIGHT, /* â - 226 */
869 C2_LEFTTORIGHT, /* ã - 227 */
870 C2_LEFTTORIGHT, /* ä - 228 */
871 C2_LEFTTORIGHT, /* å - 229 */
872 C2_LEFTTORIGHT, /* æ - 230 */
873 C2_LEFTTORIGHT, /* ç - 231 */
874 C2_LEFTTORIGHT, /* è - 232 */
875 C2_LEFTTORIGHT, /* é - 233 */
876 C2_LEFTTORIGHT, /* ê - 234 */
877 C2_LEFTTORIGHT, /* ë - 235 */
878 C2_LEFTTORIGHT, /* ì - 236 */
879 C2_LEFTTORIGHT, /* í - 237 */
880 C2_LEFTTORIGHT, /* î - 238 */
881 C2_LEFTTORIGHT, /* ï - 239 */
882 C2_LEFTTORIGHT, /* ð - 240 */
883 C2_LEFTTORIGHT, /* ñ - 241 */
884 C2_LEFTTORIGHT, /* ò - 242 */
885 C2_LEFTTORIGHT, /* ó - 243 */
886 C2_LEFTTORIGHT, /* ô - 244 */
887 C2_LEFTTORIGHT, /* õ - 245 */
888 C2_LEFTTORIGHT, /* ö - 246 */
889 C2_OTHERNEUTRAL, /* ÷ - 247 */
890 C2_LEFTTORIGHT, /* ø - 248 */
891 C2_LEFTTORIGHT, /* ù - 249 */
892 C2_LEFTTORIGHT, /* ú - 250 */
893 C2_LEFTTORIGHT, /* û - 251 */
894 C2_LEFTTORIGHT, /* ü - 252 */
895 C2_LEFTTORIGHT, /* ý - 253 */
896 C2_LEFTTORIGHT, /* þ - 254 */
897 C2_LEFTTORIGHT /* ÿ - 255 */
900 const WORD OLE2NLS_CT_CType3_LUT[] = {
935 0x0448, /* " - 34 */ /* " */
1000 0x8040, /* c - 99 */
1001 0x8040, /* d - 100 */
1002 0x8040, /* e - 101 */
1003 0x8040, /* f - 102 */
1004 0x8040, /* g - 103 */
1005 0x8040, /* h - 104 */
1006 0x8040, /* i - 105 */
1007 0x8040, /* j - 106 */
1008 0x8040, /* k - 107 */
1009 0x8040, /* l - 108 */
1010 0x8040, /* m - 109 */
1011 0x8040, /* n - 110 */
1012 0x8040, /* o - 111 */
1013 0x8040, /* p - 112 */
1014 0x8040, /* q - 113 */
1015 0x8040, /* r - 114 */
1016 0x8040, /* s - 115 */
1017 0x8040, /* t - 116 */
1018 0x8040, /* u - 117 */
1019 0x8040, /* v - 118 */
1020 0x8040, /* w - 119 */
1021 0x8040, /* x - 120 */
1022 0x8040, /* y - 121 */
1023 0x8040, /* z - 122 */
1024 0x0048, /* { - 123 */
1025 0x0048, /* | - 124 */
1026 0x0048, /* } - 125 */
1027 0x0448, /* ~ - 126 */
1028 0x0000, /*
\7f - 127 */
1029 0x0000, /*
\80 - 128 */
1030 0x0000, /*
\81 - 129 */
1031 0x0008, /*
\82 - 130 */
1032 0x8000, /*
\83 - 131 */
1033 0x0008, /*
\84 - 132 */
1034 0x0008, /*
\85 - 133 */
1035 0x0008, /*
\86 - 134 */
1036 0x0008, /*
\87 - 135 */
1037 0x0001, /*
\88 - 136 */
1038 0x0008, /*
\89 - 137 */
1039 0x8003, /*
\8a - 138 */
1040 0x0008, /*
\8b - 139 */
1041 0x8000, /*
\8c - 140 */
1042 0x0000, /*
\8d - 141 */
1043 0x0000, /*
\8e - 142 */
1044 0x0000, /*
\8f - 143 */
1045 0x0000, /*
\90 - 144 */
1046 0x0088, /*
\91 - 145 */
1047 0x0088, /*
\92 - 146 */
1048 0x0088, /*
\93 - 147 */
1049 0x0088, /*
\94 - 148 */
1050 0x0008, /*
\95 - 149 */
1051 0x0400, /*
\96 - 150 */
1052 0x0400, /*
\97 - 151 */
1053 0x0408, /*
\98 - 152 */
1054 0x0000, /*
\99 - 153 */
1055 0x8003, /*
\9a - 154 */
1056 0x0008, /*
\9b - 155 */
1057 0x8000, /*
\9c - 156 */
1058 0x0000, /*
\9d - 157 */
1059 0x0000, /*
\9e - 158 */
1060 0x8003, /*
\9f - 159 */
1062 0x0008, /* ¡ - 161 */
1063 0x0048, /* ¢ - 162 */
1064 0x0048, /* £ - 163 */
1065 0x0008, /* ¤ - 164 */
1066 0x0048, /* ¥ - 165 */
1067 0x0048, /* ¦ - 166 */
1068 0x0008, /* § - 167 */
1069 0x0408, /* ¨ - 168 */
1070 0x0008, /* © - 169 */
1071 0x0400, /* ª - 170 */
1072 0x0008, /* « - 171 */
1073 0x0048, /* ¬ - 172 */
1074 0x0408, /* - 173 */
1075 0x0008, /* ® - 174 */
1076 0x0448, /* ¯ - 175 */
1077 0x0008, /* ° - 176 */
1078 0x0008, /* ± - 177 */
1079 0x0000, /* ² - 178 */
1080 0x0000, /* ³ - 179 */
1081 0x0408, /* ´ - 180 */
1082 0x0008, /* µ - 181 */
1083 0x0008, /* ¶ - 182 */
1084 0x0008, /* · - 183 */
1085 0x0408, /* ¸ - 184 */
1086 0x0000, /* ¹ - 185 */
1087 0x0400, /* º - 186 */
1088 0x0008, /* » - 187 */
1089 0x0000, /* ¼ - 188 */
1090 0x0000, /* ½ - 189 */
1091 0x0000, /* ¾ - 190 */
1092 0x0008, /* ¿ - 191 */
1093 0x8003, /* À - 192 */
1094 0x8003, /* Á - 193 */
1095 0x8003, /* Â - 194 */
1096 0x8003, /* Ã - 195 */
1097 0x8003, /* Ä - 196 */
1098 0x8003, /* Å - 197 */
1099 0x8000, /* Æ - 198 */
1100 0x8003, /* Ç - 199 */
1101 0x8003, /* È - 200 */
1102 0x8003, /* É - 201 */
1103 0x8003, /* Ê - 202 */
1104 0x8003, /* Ë - 203 */
1105 0x8003, /* Ì - 204 */
1106 0x8003, /* Í - 205 */
1107 0x8003, /* Î - 206 */
1108 0x8003, /* Ï - 207 */
1109 0x8000, /* Ð - 208 */
1110 0x8003, /* Ñ - 209 */
1111 0x8003, /* Ò - 210 */
1112 0x8003, /* Ó - 211 */
1113 0x8003, /* Ô - 212 */
1114 0x8003, /* Õ - 213 */
1115 0x8003, /* Ö - 214 */
1116 0x0008, /* × - 215 */
1117 0x8003, /* Ø - 216 */
1118 0x8003, /* Ù - 217 */
1119 0x8003, /* Ú - 218 */
1120 0x8003, /* Û - 219 */
1121 0x8003, /* Ü - 220 */
1122 0x8003, /* Ý - 221 */
1123 0x8000, /* Þ - 222 */
1124 0x8000, /* ß - 223 */
1125 0x8003, /* à - 224 */
1126 0x8003, /* á - 225 */
1127 0x8003, /* â - 226 */
1128 0x8003, /* ã - 227 */
1129 0x8003, /* ä - 228 */
1130 0x8003, /* å - 229 */
1131 0x8000, /* æ - 230 */
1132 0x8003, /* ç - 231 */
1133 0x8003, /* è - 232 */
1134 0x8003, /* é - 233 */
1135 0x8003, /* ê - 234 */
1136 0x8003, /* ë - 235 */
1137 0x8003, /* ì - 236 */
1138 0x8003, /* í - 237 */
1139 0x8003, /* î - 238 */
1140 0x8003, /* ï - 239 */
1141 0x8000, /* ð - 240 */
1142 0x8003, /* ñ - 241 */
1143 0x8003, /* ò - 242 */
1144 0x8003, /* ó - 243 */
1145 0x8003, /* ô - 244 */
1146 0x8003, /* õ - 245 */
1147 0x8003, /* ö - 246 */
1148 0x0008, /* ÷ - 247 */
1149 0x8003, /* ø - 248 */
1150 0x8003, /* ù - 249 */
1151 0x8003, /* ú - 250 */
1152 0x8003, /* û - 251 */
1153 0x8003, /* ü - 252 */
1154 0x8003, /* ý - 253 */
1155 0x8000, /* þ - 254 */
1156 0x8003 /* ÿ - 255 */
1159 /******************************************************************************
1160 * GetStringTypeA [KERNEL32.396]
1162 BOOL WINAPI GetStringTypeA(LCID locale,DWORD dwInfoType,LPCSTR src,
1163 INT cchSrc,LPWORD chartype)
1165 return GetStringTypeExA(locale,dwInfoType,src,cchSrc,chartype);
1168 /******************************************************************************
1169 * GetStringTypeExA [KERNEL32.397]
1171 * FIXME: Ignores the locale.
1173 BOOL WINAPI GetStringTypeExA(LCID locale,DWORD dwInfoType,LPCSTR src,
1174 INT cchSrc,LPWORD chartype)
1178 if ((src==NULL) || (chartype==NULL) || (src==(LPSTR)chartype))
1180 SetLastError(ERROR_INVALID_PARAMETER);
1185 cchSrc=strlen(src)+1;
1187 switch (dwInfoType) {
1189 for (i=0;i<cchSrc;i++)
1192 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1193 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1194 if (islower(src[i])) chartype[i]|=C1_LOWER;
1195 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1196 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1197 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1198 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1199 /* FIXME: isblank() is a GNU extension */
1200 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1201 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1207 for (i=0;i<cchSrc;i++)
1209 chartype[i]=(WORD)CT_CType2_LUT[i];
1214 for (i=0;i<cchSrc;i++)
1216 chartype[i]=OLE2NLS_CT_CType3_LUT[i];
1221 ERR("Unknown dwInfoType:%ld\n",dwInfoType);
1226 /***********************************************************************
1227 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1229 DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
1234 return GetLocaleInfoA(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
1237 /***********************************************************************
1238 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1240 DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
1245 return GetLocaleInfoW(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
1249 static const unsigned char LCM_Unicode_LUT[] = {
1282 7 , 28, /* ! - 33 */
1283 7 , 29, /* " - 34 */ /* " */
1284 7 , 31, /* # - 35 */
1285 7 , 33, /* $ - 36 */
1286 7 , 35, /* % - 37 */
1287 7 , 37, /* & - 38 */
1288 6 , 128, /* ' - 39 */
1289 7 , 39, /* ( - 40 */
1290 7 , 42, /* ) - 41 */
1291 7 , 45, /* * - 42 */
1293 7 , 47, /* , - 44 */
1294 6 , 130, /* - - 45 */
1295 7 , 51, /* . - 46 */
1296 7 , 53, /* / - 47 */
1297 12 , 3, /* 0 - 48 */
1298 12 , 33, /* 1 - 49 */
1299 12 , 51, /* 2 - 50 */
1300 12 , 70, /* 3 - 51 */
1301 12 , 88, /* 4 - 52 */
1302 12 , 106, /* 5 - 53 */
1303 12 , 125, /* 6 - 54 */
1304 12 , 144, /* 7 - 55 */
1305 12 , 162, /* 8 - 56 */
1306 12 , 180, /* 9 - 57 */
1307 7 , 55, /* : - 58 */
1308 7 , 58, /* ; - 59 */
1309 8 , 14, /* < - 60 */
1310 8 , 18, /* = - 61 */
1311 8 , 20, /* > - 62 */
1312 7 , 60, /* ? - 63 */
1313 7 , 62, /* @ - 64 */
1314 14 , 2, /* A - 65 */
1315 14 , 9, /* B - 66 */
1316 14 , 10, /* C - 67 */
1317 14 , 26, /* D - 68 */
1318 14 , 33, /* E - 69 */
1319 14 , 35, /* F - 70 */
1320 14 , 37, /* G - 71 */
1321 14 , 44, /* H - 72 */
1322 14 , 50, /* I - 73 */
1323 14 , 53, /* J - 74 */
1324 14 , 54, /* K - 75 */
1325 14 , 72, /* L - 76 */
1326 14 , 81, /* M - 77 */
1327 14 , 112, /* N - 78 */
1328 14 , 124, /* O - 79 */
1329 14 , 126, /* P - 80 */
1330 14 , 137, /* Q - 81 */
1331 14 , 138, /* R - 82 */
1332 14 , 145, /* S - 83 */
1333 14 , 153, /* T - 84 */
1334 14 , 159, /* U - 85 */
1335 14 , 162, /* V - 86 */
1336 14 , 164, /* W - 87 */
1337 14 , 166, /* X - 88 */
1338 14 , 167, /* Y - 89 */
1339 14 , 169, /* Z - 90 */
1340 7 , 63, /* [ - 91 */
1341 7 , 65, /* \ - 92 */
1342 7 , 66, /* ] - 93 */
1343 7 , 67, /* ^ - 94 */
1344 7 , 68, /* _ - 95 */
1345 7 , 72, /* ` - 96 */
1346 14 , 2, /* a - 97 */
1347 14 , 9, /* b - 98 */
1348 14 , 10, /* c - 99 */
1349 14 , 26, /* d - 100 */
1350 14 , 33, /* e - 101 */
1351 14 , 35, /* f - 102 */
1352 14 , 37, /* g - 103 */
1353 14 , 44, /* h - 104 */
1354 14 , 50, /* i - 105 */
1355 14 , 53, /* j - 106 */
1356 14 , 54, /* k - 107 */
1357 14 , 72, /* l - 108 */
1358 14 , 81, /* m - 109 */
1359 14 , 112, /* n - 110 */
1360 14 , 124, /* o - 111 */
1361 14 , 126, /* p - 112 */
1362 14 , 137, /* q - 113 */
1363 14 , 138, /* r - 114 */
1364 14 , 145, /* s - 115 */
1365 14 , 153, /* t - 116 */
1366 14 , 159, /* u - 117 */
1367 14 , 162, /* v - 118 */
1368 14 , 164, /* w - 119 */
1369 14 , 166, /* x - 120 */
1370 14 , 167, /* y - 121 */
1371 14 , 169, /* z - 122 */
1372 7 , 74, /* { - 123 */
1373 7 , 76, /* | - 124 */
1374 7 , 78, /* } - 125 */
1375 7 , 80, /* ~ - 126 */
1376 6 , 29, /*
\7f - 127 */
1377 6 , 30, /*
\80 - 128 */
1378 6 , 31, /*
\81 - 129 */
1379 7 , 123, /*
\82 - 130 */
1380 14 , 35, /*
\83 - 131 */
1381 7 , 127, /*
\84 - 132 */
1382 10 , 21, /*
\85 - 133 */
1383 10 , 15, /*
\86 - 134 */
1384 10 , 16, /*
\87 - 135 */
1385 7 , 67, /*
\88 - 136 */
1386 10 , 22, /*
\89 - 137 */
1387 14 , 145, /*
\8a - 138 */
1388 7 , 136, /*
\8b - 139 */
1389 14 + 16 , 124, /*
\8c - 140 */
1390 6 , 43, /*
\8d - 141 */
1391 6 , 44, /*
\8e - 142 */
1392 6 , 45, /*
\8f - 143 */
1393 6 , 46, /*
\90 - 144 */
1394 7 , 121, /*
\91 - 145 */
1395 7 , 122, /*
\92 - 146 */
1396 7 , 125, /*
\93 - 147 */
1397 7 , 126, /*
\94 - 148 */
1398 10 , 17, /*
\95 - 149 */
1399 6 , 137, /*
\96 - 150 */
1400 6 , 139, /*
\97 - 151 */
1401 7 , 93, /*
\98 - 152 */
1402 14 , 156, /*
\99 - 153 */
1403 14 , 145, /*
\9a - 154 */
1404 7 , 137, /*
\9b - 155 */
1405 14 + 16 , 124, /*
\9c - 156 */
1406 6 , 59, /*
\9d - 157 */
1407 6 , 60, /*
\9e - 158 */
1408 14 , 167, /*
\9f - 159 */
1410 7 , 81, /* ¡ - 161 */
1411 10 , 2, /* ¢ - 162 */
1412 10 , 3, /* £ - 163 */
1413 10 , 4, /* ¤ - 164 */
1414 10 , 5, /* ¥ - 165 */
1415 7 , 82, /* ¦ - 166 */
1416 10 , 6, /* § - 167 */
1417 7 , 83, /* ¨ - 168 */
1418 10 , 7, /* © - 169 */
1419 14 , 2, /* ª - 170 */
1420 8 , 24, /* « - 171 */
1421 10 , 8, /* ¬ - 172 */
1422 6 , 131, /* - 173 */
1423 10 , 9, /* ® - 174 */
1424 7 , 84, /* ¯ - 175 */
1425 10 , 10, /* ° - 176 */
1426 8 , 23, /* ± - 177 */
1427 12 , 51, /* ² - 178 */
1428 12 , 70, /* ³ - 179 */
1429 7 , 85, /* ´ - 180 */
1430 10 , 11, /* µ - 181 */
1431 10 , 12, /* ¶ - 182 */
1432 10 , 13, /* · - 183 */
1433 7 , 86, /* ¸ - 184 */
1434 12 , 33, /* ¹ - 185 */
1435 14 , 124, /* º - 186 */
1436 8 , 26, /* » - 187 */
1437 12 , 21, /* ¼ - 188 */
1438 12 , 25, /* ½ - 189 */
1439 12 , 29, /* ¾ - 190 */
1440 7 , 87, /* ¿ - 191 */
1441 14 , 2, /* À - 192 */
1442 14 , 2, /* Á - 193 */
1443 14 , 2, /* Â - 194 */
1444 14 , 2, /* Ã - 195 */
1445 14 , 2, /* Ä - 196 */
1446 14 , 2, /* Å - 197 */
1447 14 + 16 , 2, /* Æ - 198 */
1448 14 , 10, /* Ç - 199 */
1449 14 , 33, /* È - 200 */
1450 14 , 33, /* É - 201 */
1451 14 , 33, /* Ê - 202 */
1452 14 , 33, /* Ë - 203 */
1453 14 , 50, /* Ì - 204 */
1454 14 , 50, /* Í - 205 */
1455 14 , 50, /* Î - 206 */
1456 14 , 50, /* Ï - 207 */
1457 14 , 26, /* Ð - 208 */
1458 14 , 112, /* Ñ - 209 */
1459 14 , 124, /* Ò - 210 */
1460 14 , 124, /* Ó - 211 */
1461 14 , 124, /* Ô - 212 */
1462 14 , 124, /* Õ - 213 */
1463 14 , 124, /* Ö - 214 */
1464 8 , 28, /* × - 215 */
1465 14 , 124, /* Ø - 216 */
1466 14 , 159, /* Ù - 217 */
1467 14 , 159, /* Ú - 218 */
1468 14 , 159, /* Û - 219 */
1469 14 , 159, /* Ü - 220 */
1470 14 , 167, /* Ý - 221 */
1471 14 + 32 , 153, /* Þ - 222 */
1472 14 + 48 , 145, /* ß - 223 */
1473 14 , 2, /* à - 224 */
1474 14 , 2, /* á - 225 */
1475 14 , 2, /* â - 226 */
1476 14 , 2, /* ã - 227 */
1477 14 , 2, /* ä - 228 */
1478 14 , 2, /* å - 229 */
1479 14 + 16 , 2, /* æ - 230 */
1480 14 , 10, /* ç - 231 */
1481 14 , 33, /* è - 232 */
1482 14 , 33, /* é - 233 */
1483 14 , 33, /* ê - 234 */
1484 14 , 33, /* ë - 235 */
1485 14 , 50, /* ì - 236 */
1486 14 , 50, /* í - 237 */
1487 14 , 50, /* î - 238 */
1488 14 , 50, /* ï - 239 */
1489 14 , 26, /* ð - 240 */
1490 14 , 112, /* ñ - 241 */
1491 14 , 124, /* ò - 242 */
1492 14 , 124, /* ó - 243 */
1493 14 , 124, /* ô - 244 */
1494 14 , 124, /* õ - 245 */
1495 14 , 124, /* ö - 246 */
1496 8 , 29, /* ÷ - 247 */
1497 14 , 124, /* ø - 248 */
1498 14 , 159, /* ù - 249 */
1499 14 , 159, /* ú - 250 */
1500 14 , 159, /* û - 251 */
1501 14 , 159, /* ü - 252 */
1502 14 , 167, /* ý - 253 */
1503 14 + 32 , 153, /* þ - 254 */
1504 14 , 167 /* ÿ - 255 */ };
1506 static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
1508 #define LCM_Diacritic_Start 131
1510 static const unsigned char LCM_Diacritic_LUT[] = {
1511 123, /*
\83 - 131 */
1638 /******************************************************************************
1639 * OLE2NLS_isPunctuation [INTERNAL]
1641 static int OLE2NLS_isPunctuation(unsigned char c)
1643 /* "punctuation character" in this context is a character which is
1644 considered "less important" during word sort comparison.
1645 See LCMapString implementation for the precise definition
1646 of "less important". */
1648 return (LCM_Unicode_LUT[-2+2*c]==6);
1651 /******************************************************************************
1652 * OLE2NLS_isNonSpacing [INTERNAL]
1654 static int OLE2NLS_isNonSpacing(unsigned char c)
1656 /* This function is used by LCMapStringA. Characters
1657 for which it returns true are ignored when mapping a
1658 string with NORM_IGNORENONSPACE */
1659 return ((c==136) || (c==170) || (c==186));
1662 /******************************************************************************
1663 * OLE2NLS_isSymbol [INTERNAL]
1665 static int OLE2NLS_isSymbol(unsigned char c)
1667 /* This function is used by LCMapStringA. Characters
1668 for which it returns true are ignored when mapping a
1669 string with NORM_IGNORESYMBOLS */
1670 return ( (c!=0) && !IsCharAlphaNumericA(c) );
1673 /******************************************************************************
1674 * identity [Internal]
1676 static int identity(int c)
1681 /*************************************************************************
1682 * LCMapStringA [KERNEL32.492]
1684 * Convert a string, or generate a sort key from it.
1686 * If (mapflags & LCMAP_SORTKEY), the function will generate
1687 * a sort key for the source string. Else, it will convert it
1688 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1692 * Success : length of the result string.
1695 * If called with scrlen = -1, the function will compute the length
1696 * of the 0-terminated string strsrc by itself.
1698 * If called with dstlen = 0, returns the buffer length that
1699 * would be required.
1701 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1702 * as if they are equal.
1703 * In the only code page implemented so far, there may not be
1704 * wide characters in strings passed to LCMapStringA,
1705 * so there is nothing to be done for this flag.
1707 INT WINAPI LCMapStringA(
1708 LCID lcid /* locale identifier created with MAKELCID;
1709 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1710 predefined values. */,
1711 DWORD mapflags /* flags */,
1712 LPCSTR srcstr /* source buffer */,
1713 INT srclen /* source length */,
1714 LPSTR dststr /* destination buffer */,
1715 INT dstlen /* destination buffer length */)
1719 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1720 lcid,mapflags,srcstr,srclen,dststr,dstlen);
1722 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1724 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
1725 SetLastError(ERROR_INVALID_PARAMETER);
1729 srclen = strlen(srcstr) + 1 ; /* (include final '\0') */
1731 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1735 NORM_IGNORENONSPACE | \
1737 NORM_IGNOREWIDTH | \
1738 NORM_IGNOREKANATYPE)
1739 /* FIXME: as long as we don't support Kanakana nor Hirigana
1740 * characters, we can support NORM_IGNOREKANATYPE
1742 if (mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS)
1744 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1745 "unimplemented flags: 0x%08lx\n",
1752 mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS
1756 if ( !(mapflags & LCMAP_SORTKEY) )
1759 int (*f)(int) = identity;
1760 int flag_ignorenonspace = mapflags & NORM_IGNORENONSPACE;
1761 int flag_ignoresymbols = mapflags & NORM_IGNORESYMBOLS;
1763 if (flag_ignorenonspace || flag_ignoresymbols)
1765 /* For some values of mapflags, the length of the resulting
1766 string is not known at this point. Windows does map the string
1767 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1771 /* Compute required length */
1772 for (i=j=0; i < srclen; i++)
1774 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1775 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1787 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1791 if (mapflags & LCMAP_UPPERCASE)
1793 else if (mapflags & LCMAP_LOWERCASE)
1795 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1796 for (i=j=0; (i<srclen) && (j<dstlen) ; i++)
1798 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1799 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1801 dststr[j] = (CHAR) f(srcstr[i]);
1808 /* FIXME: This function completely ignores the "lcid" parameter. */
1809 /* else ... (mapflags & LCMAP_SORTKEY) */
1813 int diacritic_len=0;
1814 int delayed_punctuation_len=0;
1815 char *case_component;
1816 char *diacritic_component;
1817 char *delayed_punctuation_component;
1819 int flag_stringsort = mapflags & SORT_STRINGSORT;
1821 /* compute how much room we will need */
1822 for (i=0;i<srclen;i++)
1825 unsigned char source_char = srcstr[i];
1826 if (source_char!='\0')
1828 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
1831 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
1832 unicode_len++; /* double letter */
1836 delayed_punctuation_len++;
1840 if (isupper(source_char))
1841 case_len=unicode_len;
1843 ofs = source_char - LCM_Diacritic_Start;
1844 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
1845 diacritic_len=unicode_len;
1848 if (mapflags & NORM_IGNORECASE)
1850 if (mapflags & NORM_IGNORENONSPACE)
1853 room = 2 * unicode_len /* "unicode" component */
1854 + diacritic_len /* "diacritic" component */
1855 + case_len /* "case" component */
1856 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
1857 + 4 /* four '\1' separators */
1858 + 1 ; /* terminal '\0' */
1861 else if (dstlen<room)
1863 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1867 /*FIXME the Pointercheck should not be nessesary */
1868 if (IsBadWritePtr (dststr,room))
1869 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
1870 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1874 /* locate each component, write separators */
1875 diacritic_component = dststr + 2*unicode_len ;
1876 *diacritic_component++ = '\1';
1877 case_component = diacritic_component + diacritic_len ;
1878 *case_component++ = '\1';
1879 delayed_punctuation_component = case_component + case_len ;
1880 *delayed_punctuation_component++ = '\1';
1881 *delayed_punctuation_component++ = '\1';
1883 /* read source string char by char, write
1884 corresponding weight in each component. */
1885 for (i=0,count=0;i<srclen;i++)
1887 unsigned char source_char=srcstr[i];
1888 if (source_char!='\0')
1891 type = LCM_Unicode_LUT[-2+2*source_char];
1892 longcode = type >> 4;
1894 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
1896 UINT16 encrypted_location = (1<<15) + 7 + 4*count;
1897 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
1898 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
1899 /* big-endian is used here because it lets string comparison be
1900 compatible with numerical comparison */
1902 *delayed_punctuation_component++ = type;
1903 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
1904 /* assumption : a punctuation character is never a
1905 double or accented letter */
1909 dststr[2*count] = type;
1910 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
1914 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1915 if (count<diacritic_len)
1916 diacritic_component[count] = 2; /* assumption: a double letter
1917 is never accented */
1920 dststr[2*count] = type;
1921 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
1922 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1923 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1924 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1928 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1929 if (count<diacritic_len)
1931 int ofs = source_char - LCM_Diacritic_Start;
1932 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
1938 dststr[room-1] = '\0';
1943 /*************************************************************************
1944 * LCMapStringW [KERNEL32.493]
1946 * Convert a string, or generate a sort key from it.
1950 * See LCMapStringA for documentation
1952 INT WINAPI LCMapStringW(
1953 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT srclen,LPWSTR dststr,
1958 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
1959 lcid, mapflags, srcstr, srclen, dststr, dstlen);
1961 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1963 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
1964 SetLastError(ERROR_INVALID_PARAMETER);
1968 srclen = strlenW(srcstr)+1;
1970 /* FIXME: Both this function and it's companion LCMapStringA()
1971 * completely ignore the "lcid" parameter. In place of the "lcid"
1972 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
1973 * environment variable prior to invoking this function. */
1974 if (mapflags & LCMAP_SORTKEY)
1976 /* Possible values of LC_COLLATE. */
1977 char *lc_collate_default = 0; /* value prior to this function */
1978 char *lc_collate_env = 0; /* value retrieved from the environment */
1980 /* General purpose index into strings of any type. */
1983 /* Lengths of various strings where the length is measured in
1984 * wide characters for wide character strings and in bytes for
1985 * native strings. The lengths include the NULL terminator. */
1986 size_t returned_len = 0;
1987 size_t src_native_len = 0;
1988 size_t dst_native_len = 0;
1989 size_t dststr_libc_len = 0;
1991 /* Native (character set determined by locale) versions of the
1992 * strings source and destination strings. */
1993 LPSTR src_native = 0;
1994 LPSTR dst_native = 0;
1996 /* Version of the source and destination strings using the
1997 * "wchar_t" Unicode data type needed by various libc functions. */
1998 wchar_t *srcstr_libc = 0;
1999 wchar_t *dststr_libc = 0;
2001 if(!(srcstr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2002 srclen * sizeof(wchar_t))))
2004 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2005 srclen * sizeof(wchar_t));
2006 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2010 /* Convert source string to a libc Unicode string. */
2011 for(str_idx = 0; str_idx < srclen; str_idx++)
2013 srcstr_libc[str_idx] = srcstr[str_idx];
2016 /* src_native should contain at most 3 bytes for each
2017 * multibyte characters in the original srcstr string. */
2018 src_native_len = 3 * srclen;
2019 if(!(src_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0,
2022 ERR("Unable to allocate %d bytes for src_native\n", src_native_len);
2023 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2024 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2028 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2029 * current value is backed up so it can be restored after the
2030 * last LC_COLLATE sensitive function returns.
2032 * Even though the locale is adjusted for a minimum amount of
2033 * time a race condition exists where other threads may be
2034 * affected if they invoke LC_COLLATE sensitive functions. One
2035 * possible solution is to wrap all LC_COLLATE sensitive Wine
2036 * functions, like LCMapStringW(), in a mutex.
2038 * Another enhancement to the following would be to set the
2039 * LC_COLLATE locale category as a function of the "lcid"
2040 * parameter instead of the "LC_COLLATE" environment variable. */
2041 if(!(lc_collate_default = setlocale(LC_COLLATE, NULL)))
2043 ERR("Unable to query the LC_COLLATE catagory\n");
2044 SetLastError(ERROR_INVALID_PARAMETER);
2045 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2046 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2050 if(!(lc_collate_env = setlocale(LC_COLLATE, "")))
2052 ERR("Unable to inherit the LC_COLLATE locale category from the "
2053 "environment. The \"LC_COLLATE\" environment variable is "
2054 "\"%s\".\n", getenv("LC_COLLATE") ?
2055 getenv("LC_COLLATE") : "<unset>");
2056 SetLastError(ERROR_INVALID_PARAMETER);
2057 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2058 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2062 TRACE("lc_collate_default = %s\n", lc_collate_default);
2063 TRACE("lc_collate_env = %s\n", lc_collate_env);
2065 /* Convert the libc Unicode string to a native multibyte character
2067 returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1;
2068 if(returned_len == 0)
2070 LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(),
2072 ERR("wcstombs failed. The string specified (%s) may contains an "
2073 "invalid character.\n", srcstr_ascii);
2074 SetLastError(ERROR_INVALID_PARAMETER);
2075 if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii);
2076 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2077 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2078 setlocale(LC_COLLATE, lc_collate_default);
2081 else if(returned_len > src_native_len)
2083 src_native[src_native_len - 1] = 0;
2084 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2085 "than expected (%d bytes).\n", src_native, returned_len,
2088 /* Since this is an internal error I'm not sure what the correct
2090 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2092 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2093 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2094 setlocale(LC_COLLATE, lc_collate_default);
2097 src_native_len = returned_len;
2099 TRACE("src_native = %s src_native_len = %d\n",
2100 src_native, src_native_len);
2102 /* dst_native seems to contain at most 4 bytes for each byte in
2103 * the original src_native string. Change if need be since this
2104 * isn't documented by the strxfrm() man page. */
2105 dst_native_len = 4 * src_native_len;
2106 if(!(dst_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0, dst_native_len)))
2108 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len);
2109 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2110 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2111 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2112 setlocale(LC_COLLATE, lc_collate_default);
2116 /* The actual translation is done by the following call to
2117 * strxfrm(). The surrounding code could have been simplified
2118 * by calling wcsxfrm() instead except that wcsxfrm() is not
2119 * available on older Linux systems (RedHat 4.1 with
2122 * Also, it is possible that the translation could be done by
2123 * various tables as it is done in LCMapStringA(). However, I'm
2124 * not sure what those tables are. */
2125 returned_len = strxfrm(dst_native, src_native, dst_native_len) + 1;
2127 if(returned_len > dst_native_len)
2129 dst_native[dst_native_len - 1] = 0;
2130 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2131 "than expected (%d bytes).\n", dst_native, returned_len,
2134 /* Since this is an internal error I'm not sure what the correct
2136 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2138 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2139 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2140 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2141 setlocale(LC_COLLATE, lc_collate_default);
2144 dst_native_len = returned_len;
2146 TRACE("dst_native = %s dst_native_len = %d\n",
2147 dst_native, dst_native_len);
2149 dststr_libc_len = dst_native_len;
2150 if(!(dststr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2151 dststr_libc_len * sizeof(wchar_t))))
2153 ERR("Unable to allocate %d bytes for dststr_libc\n",
2154 dststr_libc_len * sizeof(wchar_t));
2155 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2156 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2157 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2158 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2159 setlocale(LC_COLLATE, lc_collate_default);
2163 /* Convert the native multibyte string to a libc Unicode string. */
2164 returned_len = mbstowcs(dststr_libc, dst_native, dst_native_len) + 1;
2166 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2167 * function has returned. */
2168 setlocale(LC_COLLATE, lc_collate_default);
2170 if(returned_len == 0)
2172 ERR("mbstowcs failed. The native version of the translated string "
2173 "(%s) may contain an invalid character.\n", dst_native);
2174 SetLastError(ERROR_INVALID_PARAMETER);
2175 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2176 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2177 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2178 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2183 if(returned_len > dstlen)
2185 ERR("mbstowcs returned a string that was longer (%d chars) "
2186 "than the buffer provided (%d chars).\n", returned_len,
2188 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2189 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2190 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2191 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2192 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2195 dstlen = returned_len;
2197 /* Convert a libc Unicode string to the destination string. */
2198 for(str_idx = 0; str_idx < dstlen; str_idx++)
2200 dststr[str_idx] = dststr_libc[str_idx];
2202 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2203 *(((int *)dststr) + 0),
2204 *(((int *)dststr) + 1),
2205 *(((int *)dststr) + 2),
2206 *(((int *)dststr) + 3));
2210 dstlen = returned_len;
2212 TRACE("dstlen (return) = %d\n", dstlen);
2213 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2214 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2215 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2216 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2221 int (*f)(int)=identity;
2227 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2231 if (mapflags & LCMAP_UPPERCASE)
2233 else if (mapflags & LCMAP_LOWERCASE)
2235 for (i=0; i < srclen; i++)
2236 dststr[i] = (WCHAR) f(srcstr[i]);
2242 /***********************************************************************
2243 * OLE2NLS_EstimateMappingLength
2245 * Estimates the number of characters required to hold the string
2246 * computed by LCMapStringA.
2248 * The size is always over-estimated, with a fixed limit on the
2249 * amount of estimation error.
2251 * Note that len == -1 is not permitted.
2253 static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
2254 LPCSTR str, DWORD len)
2256 /* Estimate only for small strings to keep the estimation error from
2257 * becoming too large. */
2258 if (len < 128) return len * 8 + 5;
2259 else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
2262 /******************************************************************************
2263 * CompareStringA [KERNEL32.143]
2264 * Compares two strings using locale
2268 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2273 * Defaults to a word sort, but uses a string sort if
2274 * SORT_STRINGSORT is set.
2275 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2279 * This implementation ignores the locale
2283 * Quite inefficient.
2285 UINT WINAPI CompareStringA(
2286 DWORD lcid, /* locale ID */
2287 DWORD fdwStyle, /* comparison-style options */
2288 LPCSTR s1, /* first string */
2289 DWORD l1, /* length of first string */
2290 LPCSTR s2, /* second string */
2291 DWORD l2) /* length of second string */
2293 int mapstring_flags;
2297 TRACE("%s and %s\n",
2298 debugstr_a (s1), debugstr_a (s2));
2300 if ( (s1==NULL) || (s2==NULL) )
2302 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
2303 SetLastError(ERROR_INVALID_PARAMETER);
2307 if(fdwStyle & NORM_IGNORESYMBOLS)
2308 FIXME("IGNORESYMBOLS not supported\n");
2310 if (l1 == -1) l1 = strlen(s1);
2311 if (l2 == -1) l2 = strlen(s2);
2313 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2314 len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
2315 len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
2317 if ((len1==0)||(len2==0))
2318 return 0; /* something wrong happened */
2320 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
2322 if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
2323 || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2325 ERR("Bug in LCmapStringA.\n");
2330 /* strcmp doesn't necessarily return -1, 0, or 1 */
2331 result = strcmp(sk1,sk2);
2333 HeapFree(GetProcessHeap(),0,sk1);
2340 /* must be greater, if we reach this point */
2344 /******************************************************************************
2345 * CompareStringW [KERNEL32.144]
2346 * This implementation ignores the locale
2347 * FIXME : Does only string sort. Should
2348 * be reimplemented the same way as CompareStringA.
2350 UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
2351 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2354 if(fdwStyle & NORM_IGNORENONSPACE)
2355 FIXME("IGNORENONSPACE not supprted\n");
2356 if(fdwStyle & NORM_IGNORESYMBOLS)
2357 FIXME("IGNORESYMBOLS not supported\n");
2359 /* Is strcmp defaulting to string sort or to word sort?? */
2360 /* FIXME: Handle NORM_STRINGSORT */
2361 l1 = (l1==-1)?strlenW(s1):l1;
2362 l2 = (l2==-1)?strlenW(s2):l2;
2363 len = l1<l2 ? l1:l2;
2364 ret = (fdwStyle & NORM_IGNORECASE) ? strncmpiW(s1,s2,len) : strncmpW(s1,s2,len);
2365 /* not equal, return 1 or 3 */
2366 if(ret!=0) return ret+2;
2367 /* same len, return 2 */
2368 if(l1==l2) return 2;
2369 /* the longer one is lexically greater */
2370 return (l1<l2)? 1 : 3;
2373 /******************************************************************************
2374 * OLE_GetFormatA [Internal]
2377 * If datelen == 0, it should return the reguired string length.
2379 This function implements stuff for GetDateFormat() and
2382 d single-digit (no leading zero) day (of month)
2383 dd two-digit day (of month)
2384 ddd short day-of-week name
2385 dddd long day-of-week name
2386 M single-digit month
2388 MMM short month name
2389 MMMM full month name
2390 y two-digit year, no leading 0
2392 yyyy four-digit year
2394 h hours with no leading zero (12-hour)
2395 hh hours with full two digits
2396 H hours with no leading zero (24-hour)
2397 HH hours with full two digits
2398 m minutes with no leading zero
2399 mm minutes with full two digits
2400 s seconds with no leading zero
2401 ss seconds with full two digits
2402 t time marker (A or P)
2403 tt time marker (AM, PM)
2404 '' used to quote literal characters
2405 '' (within a quoted string) indicates a literal '
2407 These functions REQUIRE valid locale, date, and format.
2409 static INT OLE_GetFormatA(LCID locale,
2413 LPCSTR _format, /*in*/
2418 int count, type, inquote, Overflow;
2424 const char * _dgfmt[] = { "%d", "%02d" };
2425 const char ** dgfmt = _dgfmt - 1;
2427 /* report, for debugging */
2428 TRACE("(0x%lx,0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
2429 locale, flags, tflags,
2430 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2431 _format, _format, date, datelen);
2434 FIXME("datelen = 0, returning 255\n");
2438 /* initalize state variables and output buffer */
2440 count = 0; inquote = 0; Overflow = 0;
2442 date[0] = buf[0] = '\0';
2444 strcpy(format,_format);
2446 /* alter the formatstring, while it works for all languages now in wine
2447 its possible that it fails when the time looks like ss:mm:hh as example*/
2448 if (tflags & (TIME_NOMINUTESORSECONDS))
2449 { if ((pos = strstr ( format, ":mm")))
2450 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2453 if (tflags & (TIME_NOSECONDS))
2454 { if ((pos = strstr ( format, ":ss")))
2455 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2459 for (inpos = 0;; inpos++) {
2460 /* 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]); */
2462 if (format[inpos] == '\'') {
2463 if (format[inpos+1] == '\'') {
2465 date[outpos++] = '\'';
2468 continue; /* we did nothing to the output */
2470 } else if (format[inpos] == '\0') {
2471 date[outpos++] = '\0';
2472 if (outpos > datelen) Overflow = 1;
2475 date[outpos++] = format[inpos];
2476 if (outpos > datelen) {
2478 date[outpos-1] = '\0'; /* this is the last place where
2479 it's safe to write */
2483 } else if ( (count && (format[inpos] != type))
2485 || (count == 2 && strchr("ghHmst", type)) )
2489 GetLocaleInfoA(locale,
2491 + xtime->wDayOfWeek - 1,
2493 } else if (count == 3) {
2494 GetLocaleInfoA(locale,
2495 LOCALE_SABBREVDAYNAME1
2496 + xtime->wDayOfWeek - 1,
2499 sprintf(buf, dgfmt[count], xtime->wDay);
2501 } else if (type == 'M') {
2503 GetLocaleInfoA(locale,
2504 LOCALE_SABBREVMONTHNAME1
2505 + xtime->wMonth - 1,
2507 } else if (count == 4) {
2508 GetLocaleInfoA(locale,
2510 + xtime->wMonth - 1,
2513 sprintf(buf, dgfmt[count], xtime->wMonth);
2515 } else if (type == 'y') {
2517 sprintf(buf, "%d", xtime->wYear);
2518 } else if (count == 3) {
2520 WARN("unknown format, c=%c, n=%d\n", type, count);
2522 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2524 } else if (type == 'g') {
2526 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2530 WARN("unknown format, c=%c, n=%d\n", type, count);
2532 } else if (type == 'h') {
2533 /* gives us hours 1:00 -- 12:00 */
2534 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2535 } else if (type == 'H') {
2537 sprintf(buf, dgfmt[count], xtime->wHour);
2538 } else if ( type == 'm') {
2539 sprintf(buf, dgfmt[count], xtime->wMinute);
2540 } else if ( type == 's') {
2541 sprintf(buf, dgfmt[count], xtime->wSecond);
2542 } else if (type == 't') {
2544 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2545 } else if (count == 2) {
2546 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2547 GetLocaleInfoA(locale,
2549 ? LOCALE_S1159 : LOCALE_S2359,
2554 /* we need to check the next char in the format string
2555 again, no matter what happened */
2558 /* add the contents of buf to the output */
2559 buflen = strlen(buf);
2560 if (outpos + buflen < datelen) {
2561 date[outpos] = '\0'; /* for strcat to hook onto */
2565 date[outpos] = '\0';
2566 strncat(date, buf, datelen - outpos);
2567 date[datelen - 1] = '\0';
2568 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2569 WARN("insufficient buffer\n");
2573 /* reset the variables we used to keep track of this item */
2576 } else if (format[inpos] == '\0') {
2577 /* we can't check for this at the loop-head, because
2578 that breaks the printing of the last format-item */
2579 date[outpos] = '\0';
2582 /* continuing a code for an item */
2585 } else if (strchr("hHmstyMdg", format[inpos])) {
2586 type = format[inpos];
2589 } else if (format[inpos] == '\'') {
2593 date[outpos++] = format[inpos];
2595 /* now deal with a possible buffer overflow */
2596 if (outpos >= datelen) {
2597 date[datelen - 1] = '\0';
2598 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2604 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2607 /* finish it off with a string terminator */
2610 if (outpos > datelen-1) outpos = datelen-1;
2611 date[outpos] = '\0';
2613 TRACE("OLE_GetFormatA returns string '%s', len %d\n",
2618 /******************************************************************************
2619 * OLE_GetFormatW [INTERNAL]
2621 static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
2624 LPWSTR output, INT outlen)
2627 int count, type=0, inquote;
2628 int Overflow; /* loop check */
2631 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2632 WCHAR arg2[] = {'%','0','2','d',0};
2634 int datevars=0, timevars=0;
2640 /* make a debug report */
2641 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2642 "%p with max len %d\n",
2643 locale, flags, tflags,
2644 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2645 debugstr_w(format), format, output, outlen);
2648 FIXME("outlen = 0, returning 255\n");
2652 /* initialize state variables */
2655 inquote = Overflow = 0;
2656 /* this is really just a sanity check */
2657 output[0] = buf[0] = 0;
2659 /* this loop is the core of the function */
2660 for (inpos = 0; /* we have several break points */ ; inpos++) {
2662 if (format[inpos] == (WCHAR) '\'') {
2663 if (format[inpos+1] == '\'') {
2665 output[outpos++] = '\'';
2670 } else if (format[inpos] == 0) {
2671 output[outpos++] = 0;
2672 if (outpos > outlen) Overflow = 1;
2673 break; /* normal exit (within a quote) */
2675 output[outpos++] = format[inpos]; /* copy input */
2676 if (outpos > outlen) {
2678 output[outpos-1] = 0;
2682 } else if ( (count && (format[inpos] != type))
2683 || ( (count==4 && type =='y') ||
2684 (count==4 && type =='M') ||
2685 (count==4 && type =='d') ||
2686 (count==2 && type =='g') ||
2687 (count==2 && type =='h') ||
2688 (count==2 && type =='H') ||
2689 (count==2 && type =='m') ||
2690 (count==2 && type =='s') ||
2691 (count==2 && type =='t') ) ) {
2694 GetLocaleInfoW(locale,
2695 LOCALE_SDAYNAME1 + xtime->wDayOfWeek -1,
2696 buf, sizeof(buf)/sizeof(WCHAR) );
2697 } else if (count == 3) {
2698 GetLocaleInfoW(locale,
2699 LOCALE_SABBREVDAYNAME1 +
2700 xtime->wDayOfWeek -1,
2701 buf, sizeof(buf)/sizeof(WCHAR) );
2703 wsnprintfW(buf, 5, argarr[count], xtime->wDay );
2705 } else if (type == 'M') {
2707 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
2708 xtime->wMonth -1, buf,
2709 sizeof(buf)/sizeof(WCHAR) );
2710 } else if (count == 3) {
2711 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
2712 xtime->wMonth -1, buf,
2713 sizeof(buf)/sizeof(WCHAR) );
2715 wsnprintfW(buf, 5, argarr[count], xtime->wMonth);
2717 } else if (type == 'y') {
2719 wsnprintfW(buf, 6, argarr[1] /* "%d" */,
2721 } else if (count == 3) {
2722 lstrcpynAtoW(buf, "yyy", 5);
2724 wsnprintfW(buf, 6, argarr[count],
2725 xtime->wYear % 100);
2727 } else if (type == 'g') {
2729 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2730 lstrcpynAtoW(buf, "AD", 5);
2732 /* Win API sez we copy it verbatim */
2733 lstrcpynAtoW(buf, "g", 5);
2735 } else if (type == 'h') {
2736 /* hours 1:00-12:00 --- is this right? */
2737 wsnprintfW(buf, 5, argarr[count],
2738 (xtime->wHour-1)%12 +1);
2739 } else if (type == 'H') {
2740 wsnprintfW(buf, 5, argarr[count],
2742 } else if (type == 'm' ) {
2743 wsnprintfW(buf, 5, argarr[count],
2745 } else if (type == 's' ) {
2746 wsnprintfW(buf, 5, argarr[count],
2748 } else if (type == 't') {
2749 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
2750 LOCALE_S1159 : LOCALE_S2359,
2757 /* no matter what happened, we need to check this next
2758 character the next time we loop through */
2761 /* cat buf onto the output */
2762 outlen = strlenW(buf);
2763 if (outpos + buflen < outlen) {
2764 strcpyW( output + outpos, buf );
2767 lstrcpynW( output + outpos, buf, outlen - outpos );
2769 break; /* Abnormal exit */
2772 /* reset the variables we used this time */
2775 } else if (format[inpos] == 0) {
2776 /* we can't check for this at the beginning, because that
2777 would keep us from printing a format spec that ended the
2780 break; /* NORMAL EXIT */
2782 /* how we keep track of the middle of a format spec */
2785 } else if ( (datevars && (format[inpos]=='d' ||
2786 format[inpos]=='M' ||
2787 format[inpos]=='y' ||
2788 format[inpos]=='g') ) ||
2789 (timevars && (format[inpos]=='H' ||
2790 format[inpos]=='h' ||
2791 format[inpos]=='m' ||
2792 format[inpos]=='s' ||
2793 format[inpos]=='t') ) ) {
2794 type = format[inpos];
2797 } else if (format[inpos] == '\'') {
2801 /* unquoted literals */
2802 output[outpos++] = format[inpos];
2807 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2808 WARN(" buffer overflow\n");
2811 /* final string terminator and sanity check */
2813 if (outpos > outlen-1) outpos = outlen-1;
2814 output[outpos] = '0';
2816 TRACE(" returning %s\n", debugstr_w(output));
2818 return (!Overflow) ? outlen : 0;
2823 /******************************************************************************
2824 * GetDateFormatA [KERNEL32.310]
2825 * Makes an ASCII string of the date
2827 * This function uses format to format the date, or, if format
2828 * is NULL, uses the default for the locale. format is a string
2829 * of literal fields and characters as follows:
2831 * - d single-digit (no leading zero) day (of month)
2832 * - dd two-digit day (of month)
2833 * - ddd short day-of-week name
2834 * - dddd long day-of-week name
2835 * - M single-digit month
2836 * - MM two-digit month
2837 * - MMM short month name
2838 * - MMMM full month name
2839 * - y two-digit year, no leading 0
2840 * - yy two-digit year
2841 * - yyyy four-digit year
2845 INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
2847 LPCSTR format, LPSTR date,INT datelen)
2850 char format_buf[40];
2853 LPSYSTEMTIME thistime;
2857 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2858 locale,flags,xtime,format,date,datelen);
2861 locale = LOCALE_SYSTEM_DEFAULT;
2864 if (locale == LOCALE_SYSTEM_DEFAULT) {
2865 thislocale = GetSystemDefaultLCID();
2866 } else if (locale == LOCALE_USER_DEFAULT) {
2867 thislocale = GetUserDefaultLCID();
2869 thislocale = locale;
2872 if (xtime == NULL) {
2879 if (format == NULL) {
2880 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
2882 : LOCALE_SSHORTDATE),
2883 format_buf, sizeof(format_buf));
2884 thisformat = format_buf;
2886 thisformat = format;
2890 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
2895 "GetDateFormatA() returning %d, with data=%s\n",
2900 /******************************************************************************
2901 * GetDateFormatW [KERNEL32.311]
2902 * Makes a Unicode string of the date
2904 * Acts the same as GetDateFormatA(), except that it's Unicode.
2905 * Accepts & returns sizes as counts of Unicode characters.
2908 INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
2911 LPWSTR date, INT datelen)
2913 unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
2915 FIXME("STUB (should call OLE_GetFormatW)\n");
2916 lstrcpynW(date, datearr, datelen);
2917 return ( datelen < 9) ? datelen : 9;
2922 /**************************************************************************
2923 * EnumDateFormatsA (KERNEL32.198)
2925 BOOL WINAPI EnumDateFormatsA(
2926 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2928 LCID Loc = GetUserDefaultLCID();
2929 if(!lpDateFmtEnumProc)
2931 SetLastError(ERROR_INVALID_PARAMETER);
2938 case 0x00000407: /* (Loc,"de_DE") */
2942 case DATE_SHORTDATE:
2943 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
2944 if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
2945 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
2946 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
2949 if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
2950 if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
2951 if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
2954 FIXME("Unknown date format (%ld)\n", dwFlags);
2955 SetLastError(ERROR_INVALID_PARAMETER);
2960 case 0x0000040c: /* (Loc,"fr_FR") */
2964 case DATE_SHORTDATE:
2965 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2966 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
2967 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
2968 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2971 if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
2972 if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
2973 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2976 FIXME("Unknown date format (%ld)\n", dwFlags);
2977 SetLastError(ERROR_INVALID_PARAMETER);
2982 case 0x00000c0c: /* (Loc,"fr_CA") */
2986 case DATE_SHORTDATE:
2987 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
2988 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
2989 if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
2990 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2993 if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
2994 if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
2997 FIXME("Unknown date format (%ld)\n", dwFlags);
2998 SetLastError(ERROR_INVALID_PARAMETER);
3003 case 0x00000809: /* (Loc,"en_UK") */
3007 case DATE_SHORTDATE:
3008 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3009 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3010 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3011 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3014 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3015 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3018 FIXME("Unknown date format (%ld)\n", dwFlags);
3019 SetLastError(ERROR_INVALID_PARAMETER);
3024 case 0x00000c09: /* (Loc,"en_AU") */
3028 case DATE_SHORTDATE:
3029 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3030 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3031 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3034 if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
3035 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3038 FIXME("Unknown date format (%ld)\n", dwFlags);
3039 SetLastError(ERROR_INVALID_PARAMETER);
3044 case 0x00001009: /* (Loc,"en_CA") */
3048 case DATE_SHORTDATE:
3049 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3050 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3051 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3052 if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
3055 if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
3056 if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
3059 FIXME("Unknown date format (%ld)\n", dwFlags);
3060 SetLastError(ERROR_INVALID_PARAMETER);
3065 case 0x00001409: /* (Loc,"en_NZ") */
3069 case DATE_SHORTDATE:
3070 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3071 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3072 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3075 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3076 if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
3079 FIXME("Unknown date format (%ld)\n", dwFlags);
3080 SetLastError(ERROR_INVALID_PARAMETER);
3085 case 0x00001809: /* (Loc,"en_IE") */
3089 case DATE_SHORTDATE:
3090 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3091 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3092 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3095 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3096 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3099 FIXME("Unknown date format (%ld)\n", dwFlags);
3100 SetLastError(ERROR_INVALID_PARAMETER);
3105 case 0x00001c09: /* (Loc,"en_ZA") */
3109 case DATE_SHORTDATE:
3110 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3113 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3116 FIXME("Unknown date format (%ld)\n", dwFlags);
3117 SetLastError(ERROR_INVALID_PARAMETER);
3122 case 0x00002009: /* (Loc,"en_JM") */
3126 case DATE_SHORTDATE:
3127 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3130 if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
3131 if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
3132 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
3133 if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
3136 FIXME("Unknown date format (%ld)\n", dwFlags);
3137 SetLastError(ERROR_INVALID_PARAMETER);
3142 case 0x00002809: /* (Loc,"en_BZ") */
3143 case 0x00002c09: /* (Loc,"en_TT") */
3147 case DATE_SHORTDATE:
3148 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3151 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
3154 FIXME("Unknown date format (%ld)\n", dwFlags);
3155 SetLastError(ERROR_INVALID_PARAMETER);
3160 default: /* default to US English "en_US" */
3164 case DATE_SHORTDATE:
3165 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
3166 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
3167 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
3168 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
3169 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3170 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
3173 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
3174 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
3175 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
3176 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
3179 FIXME("Unknown date format (%ld)\n", dwFlags);
3180 SetLastError(ERROR_INVALID_PARAMETER);
3187 /**************************************************************************
3188 * EnumDateFormatsW (KERNEL32.199)
3190 BOOL WINAPI EnumDateFormatsW(
3191 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3193 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
3194 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3198 /**************************************************************************
3199 * EnumTimeFormatsA (KERNEL32.210)
3201 BOOL WINAPI EnumTimeFormatsA(
3202 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3204 LCID Loc = GetUserDefaultLCID();
3205 if(!lpTimeFmtEnumProc)
3207 SetLastError(ERROR_INVALID_PARAMETER);
3212 FIXME("Unknown time format (%ld)\n", dwFlags);
3217 case 0x00000407: /* (Loc,"de_DE") */
3219 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3220 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3221 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3222 if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
3223 if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
3227 case 0x0000040c: /* (Loc,"fr_FR") */
3228 case 0x00000c0c: /* (Loc,"fr_CA") */
3230 if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
3231 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3232 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3233 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3234 if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
3238 case 0x00000809: /* (Loc,"en_UK") */
3239 case 0x00000c09: /* (Loc,"en_AU") */
3240 case 0x00001409: /* (Loc,"en_NZ") */
3241 case 0x00001809: /* (Loc,"en_IE") */
3243 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3244 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3245 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3249 case 0x00001c09: /* (Loc,"en_ZA") */
3250 case 0x00002809: /* (Loc,"en_BZ") */
3251 case 0x00002c09: /* (Loc,"en_TT") */
3253 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3254 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3258 default: /* default to US style "en_US" */
3260 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3261 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3262 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3263 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3269 /**************************************************************************
3270 * EnumTimeFormatsW (KERNEL32.211)
3272 BOOL WINAPI EnumTimeFormatsW(
3273 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3275 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
3276 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3280 /**************************************************************************
3281 * This function is used just locally !
3282 * Description: Inverts a string.
3284 static void OLE_InvertString(char* string)
3286 char sTmpArray[128];
3289 for (counter = strlen(string); counter > 0; counter--)
3291 memcpy(sTmpArray + i, string + counter-1, 1);
3294 memcpy(sTmpArray + i, "\0", 1);
3295 strcpy(string, sTmpArray);
3298 /***************************************************************************************
3299 * This function is used just locally !
3300 * Description: Test if the given string (psNumber) is valid or not.
3301 * The valid characters are the following:
3302 * - Characters '0' through '9'.
3303 * - One decimal point (dot) if the number is a floating-point value.
3304 * - A minus sign in the first character position if the number is
3306 * If the function succeeds, psBefore/psAfter will point to the string
3307 * on the right/left of the decimal symbol. pbNegative indicates if the
3308 * number is negative.
3310 static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
3312 char sNumberSet[] = "0123456789";
3313 BOOL bInDecimal = FALSE;
3315 /* Test if we do have a minus sign */
3316 if ( *pInput == '-' )
3319 pInput++; /* Jump to the next character. */
3322 while(*pInput != '\0')
3324 /* Do we have a valid numeric character */
3325 if ( strchr(sNumberSet, *pInput) != NULL )
3327 if (bInDecimal == TRUE)
3328 *psAfter++ = *pInput;
3330 *psBefore++ = *pInput;
3334 /* Is this a decimal point (dot) */
3335 if ( *pInput == '.' )
3337 /* Is it the first time we find it */
3338 if ((bInDecimal == FALSE))
3341 return -1; /* ERROR: Invalid parameter */
3345 /* It's neither a numeric character, nor a decimal point.
3346 * Thus, return an error.
3354 /* Add an End of Line character to the output buffers */
3361 /**************************************************************************
3362 * This function is used just locally !
3363 * Description: A number could be formatted using different numbers
3364 * of "digits in group" (example: 4;3;2;0).
3365 * The first parameter of this function is an array
3366 * containing the rule to be used. It's format is the following:
3367 * |NDG|DG1|DG2|...|0|
3368 * where NDG is the number of used "digits in group" and DG1, DG2,
3369 * are the corresponding "digits in group".
3370 * Thus, this function returns the grouping value in the array
3371 * pointed by the second parameter.
3373 static INT OLE_GetGrouping(char* sRule, INT index)
3375 char sData[2], sRuleSize[2];
3376 INT nData, nRuleSize;
3378 memcpy(sRuleSize, sRule, 1);
3379 memcpy(sRuleSize+1, "\0", 1);
3380 nRuleSize = atoi(sRuleSize);
3382 if (index > 0 && index < nRuleSize)
3384 memcpy(sData, sRule+index, 1);
3385 memcpy(sData+1, "\0", 1);
3386 nData = atoi(sData);
3391 memcpy(sData, sRule+nRuleSize-1, 1);
3392 memcpy(sData+1, "\0", 1);
3393 nData = atoi(sData);
3399 /**************************************************************************
3400 * GetNumberFormatA (KERNEL32.355)
3402 INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
3403 LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
3404 LPSTR lpNumberStr, int cchNumber)
3406 char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
3407 INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
3408 char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
3409 char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
3410 char *pStr = NULL, *pTmpStr = NULL;
3411 LCID systemDefaultLCID;
3412 BOOL bNegative = FALSE;
3421 strncpy(sNumber, lpvalue, 128);
3422 sNumber[127] = '\0';
3424 /* Make sure we have a valid input string, get the number
3425 * of digits before and after the decimal symbol, and check
3426 * if this is a negative number.
3428 if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
3430 nNumberDecimal = strlen(sDigitsBeforeDecimal);
3431 nDigits = strlen(sDigitsAfterDecimal);
3435 SetLastError(ERROR_INVALID_PARAMETER);
3439 /* Which source will we use to format the string */
3440 used_operation = RETURN_ERROR;
3441 if (lpFormat != NULL)
3444 used_operation = USE_PARAMETER;
3448 if (dwflags & LOCALE_NOUSEROVERRIDE)
3449 used_operation = USE_LOCALEINFO;
3451 used_operation = USE_SYSTEMDEFAULT;
3454 /* Load the fields we need */
3455 switch(used_operation)
3457 case USE_LOCALEINFO:
3458 GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3459 GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3460 GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3461 GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3462 GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3463 GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3466 sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
3467 strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
3468 sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
3469 strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
3470 sprintf(sILZero, "%d",lpFormat->LeadingZero);
3471 sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
3473 case USE_SYSTEMDEFAULT:
3474 systemDefaultLCID = GetSystemDefaultLCID();
3475 GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3476 GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3477 GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3478 GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3479 GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3480 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3483 SetLastError(ERROR_INVALID_PARAMETER);
3487 nNumberDigits = atoi(sNumberDigits);
3489 /* Remove the ";" */
3492 for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
3494 if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
3496 memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
3501 sprintf(sBuffer, "%d", i);
3502 memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3503 memcpy(sRule + j, "\0", 1);
3505 /* First, format the digits before the decimal. */
3506 if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
3508 /* Working on an inverted string is easier ! */
3509 OLE_InvertString(sDigitsBeforeDecimal);
3511 nStep = nCounter = i = j = 0;
3513 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3515 /* Here, we will loop until we reach the end of the string.
3516 * An internal counter (j) is used in order to know when to
3517 * insert the "digit group symbol".
3519 while (nNumberDecimal > 0)
3521 i = nCounter + nStep;
3522 memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
3528 if (nRuleIndex < sRule[0])
3530 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3531 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
3532 nStep+= strlen(sDigitGroupSymbol);
3538 memcpy(sDestination + i+1, "\0", 1);
3539 /* Get the string in the right order ! */
3540 OLE_InvertString(sDestination);
3544 nLZ = atoi(sILZero);
3547 /* Use 0.xxx instead of .xxx */
3548 memcpy(sDestination, "0", 1);
3549 memcpy(sDestination+1, "\0", 1);
3552 memcpy(sDestination, "\0", 1);
3556 /* Second, format the digits after the decimal. */
3558 nCounter = nNumberDigits;
3559 if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
3561 i = strlen(sNumber) - strlen(pStr) + 1;
3562 strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
3563 j = strlen(sDigitsAfterDecimal);
3564 if (j < nNumberDigits)
3565 nCounter = nNumberDigits-j;
3567 for (i=0;i<nCounter;i++)
3568 memcpy(sDigitsAfterDecimal+i+j, "0", 1);
3569 memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
3571 i = strlen(sDestination);
3572 j = strlen(sDigitsAfterDecimal);
3573 /* Finally, construct the resulting formatted string. */
3575 for (nCounter=0; nCounter<i; nCounter++)
3576 memcpy(sNumber + nCounter, sDestination + nCounter, 1);
3578 memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
3581 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
3582 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
3584 /* Is it a negative number */
3585 if (bNegative == TRUE)
3587 i = atoi(sNegNumber);
3588 pStr = sDestination;
3594 while (*sNumber != '\0')
3595 *pStr++ = *pTmpStr++;
3600 while (*pTmpStr != '\0')
3601 *pStr++ = *pTmpStr++;
3606 while (*pTmpStr != '\0')
3607 *pStr++ = *pTmpStr++;
3610 while (*pTmpStr != '\0')
3611 *pStr++ = *pTmpStr++;
3615 while (*pTmpStr != '\0')
3616 *pStr++ = *pTmpStr++;
3621 while (*pTmpStr != '\0')
3622 *pStr++ = *pTmpStr++;
3627 strcpy(sDestination, sNumber);
3629 /* If cchNumber is zero, then returns the number of bytes or characters
3630 * required to hold the formatted number string
3633 retVal = strlen(sDestination) + 1;
3636 strncpy (lpNumberStr, sDestination, cchNumber-1);
3637 *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
3638 retVal = strlen(lpNumberStr);
3644 /**************************************************************************
3645 * GetNumberFormatW (KERNEL32.xxx)
3647 INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
3648 LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
3649 LPWSTR lpNumberStr, int cchNumber)
3651 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue));
3653 lstrcpynW( lpNumberStr, lpvalue, cchNumber );
3654 return cchNumber? strlenW( lpNumberStr ) : 0;
3657 /**************************************************************************
3658 * GetCurrencyFormatA (KERNEL32.302)
3660 INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
3661 LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
3662 LPSTR lpCurrencyStr, int cchCurrency)
3664 UINT nPosOrder, nNegOrder;
3666 char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
3667 char *pDestination = sDestination;
3668 char sNumberFormated[128];
3669 char *pNumberFormated = sNumberFormated;
3670 LCID systemDefaultLCID;
3671 BOOL bIsPositive = FALSE, bValidFormat = FALSE;
3680 NUMBERFMTA numberFmt;
3682 /* Which source will we use to format the string */
3683 used_operation = RETURN_ERROR;
3684 if (lpFormat != NULL)
3687 used_operation = USE_PARAMETER;
3691 if (dwflags & LOCALE_NOUSEROVERRIDE)
3692 used_operation = USE_LOCALEINFO;
3694 used_operation = USE_SYSTEMDEFAULT;
3697 /* Load the fields we need */
3698 switch(used_operation)
3700 case USE_LOCALEINFO:
3701 /* Specific to CURRENCYFMTA*/
3702 GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3703 GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3704 GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3706 nPosOrder = atoi(sPosOrder);
3707 nNegOrder = atoi(sNegOrder);
3710 /* Specific to CURRENCYFMTA*/
3711 nNegOrder = lpFormat->NegativeOrder;
3712 nPosOrder = lpFormat->PositiveOrder;
3713 strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
3715 case USE_SYSTEMDEFAULT:
3716 systemDefaultLCID = GetSystemDefaultLCID();
3717 /* Specific to CURRENCYFMTA*/
3718 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3719 GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3720 GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3722 nPosOrder = atoi(sPosOrder);
3723 nNegOrder = atoi(sNegOrder);
3726 SetLastError(ERROR_INVALID_PARAMETER);
3730 /* Construct a temporary number format structure */
3731 if (lpFormat != NULL)
3733 numberFmt.NumDigits = lpFormat->NumDigits;
3734 numberFmt.LeadingZero = lpFormat->LeadingZero;
3735 numberFmt.Grouping = lpFormat->Grouping;
3736 numberFmt.NegativeOrder = 0;
3737 numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
3738 numberFmt.lpThousandSep = lpFormat->lpThousandSep;
3739 bValidFormat = TRUE;
3742 /* Make a call to GetNumberFormatA() */
3743 if (*lpvalue == '-')
3745 bIsPositive = FALSE;
3746 retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3751 retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3757 /* construct the formatted string */
3762 case 0: /* Prefix, no separation */
3763 strcpy (pDestination, sCurrencySymbol);
3764 strcat (pDestination, pNumberFormated);
3766 case 1: /* Suffix, no separation */
3767 strcpy (pDestination, pNumberFormated);
3768 strcat (pDestination, sCurrencySymbol);
3770 case 2: /* Prefix, 1 char separation */
3771 strcpy (pDestination, sCurrencySymbol);
3772 strcat (pDestination, " ");
3773 strcat (pDestination, pNumberFormated);
3775 case 3: /* Suffix, 1 char separation */
3776 strcpy (pDestination, pNumberFormated);
3777 strcat (pDestination, " ");
3778 strcat (pDestination, sCurrencySymbol);
3781 SetLastError(ERROR_INVALID_PARAMETER);
3785 else /* negative number */
3789 case 0: /* format: ($1.1) */
3790 strcpy (pDestination, "(");
3791 strcat (pDestination, sCurrencySymbol);
3792 strcat (pDestination, pNumberFormated);
3793 strcat (pDestination, ")");
3795 case 1: /* format: -$1.1 */
3796 strcpy (pDestination, "-");
3797 strcat (pDestination, sCurrencySymbol);
3798 strcat (pDestination, pNumberFormated);
3800 case 2: /* format: $-1.1 */
3801 strcpy (pDestination, sCurrencySymbol);
3802 strcat (pDestination, "-");
3803 strcat (pDestination, pNumberFormated);
3805 case 3: /* format: $1.1- */
3806 strcpy (pDestination, sCurrencySymbol);
3807 strcat (pDestination, pNumberFormated);
3808 strcat (pDestination, "-");
3810 case 4: /* format: (1.1$) */
3811 strcpy (pDestination, "(");
3812 strcat (pDestination, pNumberFormated);
3813 strcat (pDestination, sCurrencySymbol);
3814 strcat (pDestination, ")");
3816 case 5: /* format: -1.1$ */
3817 strcpy (pDestination, "-");
3818 strcat (pDestination, pNumberFormated);
3819 strcat (pDestination, sCurrencySymbol);
3821 case 6: /* format: 1.1-$ */
3822 strcpy (pDestination, pNumberFormated);
3823 strcat (pDestination, "-");
3824 strcat (pDestination, sCurrencySymbol);
3826 case 7: /* format: 1.1$- */
3827 strcpy (pDestination, pNumberFormated);
3828 strcat (pDestination, sCurrencySymbol);
3829 strcat (pDestination, "-");
3831 case 8: /* format: -1.1 $ */
3832 strcpy (pDestination, "-");
3833 strcat (pDestination, pNumberFormated);
3834 strcat (pDestination, " ");
3835 strcat (pDestination, sCurrencySymbol);
3837 case 9: /* format: -$ 1.1 */
3838 strcpy (pDestination, "-");
3839 strcat (pDestination, sCurrencySymbol);
3840 strcat (pDestination, " ");
3841 strcat (pDestination, pNumberFormated);
3843 case 10: /* format: 1.1 $- */
3844 strcpy (pDestination, pNumberFormated);
3845 strcat (pDestination, " ");
3846 strcat (pDestination, sCurrencySymbol);
3847 strcat (pDestination, "-");
3849 case 11: /* format: $ 1.1- */
3850 strcpy (pDestination, sCurrencySymbol);
3851 strcat (pDestination, " ");
3852 strcat (pDestination, pNumberFormated);
3853 strcat (pDestination, "-");
3855 case 12: /* format: $ -1.1 */
3856 strcpy (pDestination, sCurrencySymbol);
3857 strcat (pDestination, " ");
3858 strcat (pDestination, "-");
3859 strcat (pDestination, pNumberFormated);
3861 case 13: /* format: 1.1- $ */
3862 strcpy (pDestination, pNumberFormated);
3863 strcat (pDestination, "-");
3864 strcat (pDestination, " ");
3865 strcat (pDestination, sCurrencySymbol);
3867 case 14: /* format: ($ 1.1) */
3868 strcpy (pDestination, "(");
3869 strcat (pDestination, sCurrencySymbol);
3870 strcat (pDestination, " ");
3871 strcat (pDestination, pNumberFormated);
3872 strcat (pDestination, ")");
3874 case 15: /* format: (1.1 $) */
3875 strcpy (pDestination, "(");
3876 strcat (pDestination, pNumberFormated);
3877 strcat (pDestination, " ");
3878 strcat (pDestination, sCurrencySymbol);
3879 strcat (pDestination, ")");
3882 SetLastError(ERROR_INVALID_PARAMETER);
3887 if (cchCurrency == 0)
3888 return strlen(pDestination) + 1;
3892 strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
3893 *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
3894 return strlen(lpCurrencyStr);
3898 /**************************************************************************
3899 * GetCurrencyFormatW (KERNEL32.303)
3901 INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
3902 LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
3903 LPWSTR lpCurrencyStr, int cchCurrency)
3905 FIXME("This API function is NOT implemented !\n");
3909 /******************************************************************************
3910 * OLE2NLS_CheckLocale [intern]
3912 static LCID OLE2NLS_CheckLocale (LCID locale)
3915 { locale = LOCALE_SYSTEM_DEFAULT;
3918 if (locale == LOCALE_SYSTEM_DEFAULT)
3919 { return GetSystemDefaultLCID();
3921 else if (locale == LOCALE_USER_DEFAULT)
3922 { return GetUserDefaultLCID();
3928 /******************************************************************************
3929 * GetTimeFormatA [KERNEL32.422]
3930 * Makes an ASCII string of the time
3932 * Formats date according to format, or locale default if format is
3933 * NULL. The format consists of literal characters and fields as follows:
3935 * h hours with no leading zero (12-hour)
3936 * hh hours with full two digits
3937 * H hours with no leading zero (24-hour)
3938 * HH hours with full two digits
3939 * m minutes with no leading zero
3940 * mm minutes with full two digits
3941 * s seconds with no leading zero
3942 * ss seconds with full two digits
3943 * t time marker (A or P)
3944 * tt time marker (AM, PM)
3948 GetTimeFormatA(LCID locale, /* in */
3949 DWORD flags, /* in */
3950 LPSYSTEMTIME xtime, /* in */
3951 LPCSTR format, /* in */
3952 LPSTR timestr, /* out */
3953 INT timelen /* in */)
3954 { char format_buf[40];
3957 LPSYSTEMTIME thistime;
3959 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
3962 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
3964 thislocale = OLE2NLS_CheckLocale ( locale );
3966 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
3967 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
3970 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
3973 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
3974 { thislocale = GetSystemDefaultLCID();
3976 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
3977 thisformat = format_buf;
3980 { thisformat = format;
3983 if (xtime == NULL) /* NULL means use the current local time*/
3990 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
3996 /******************************************************************************
3997 * GetTimeFormatW [KERNEL32.423]
3998 * Makes a Unicode string of the time
4001 GetTimeFormatW(LCID locale, /* in */
4002 DWORD flags, /* in */
4003 LPSYSTEMTIME xtime, /* in */
4004 LPCWSTR format, /* in */
4005 LPWSTR timestr, /* out */
4006 INT timelen /* in */)
4007 { WCHAR format_buf[40];
4010 LPSYSTEMTIME thistime;
4012 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4015 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
4016 xtime,debugstr_w(format),timestr,timelen);
4018 thislocale = OLE2NLS_CheckLocale ( locale );
4020 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
4021 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4024 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
4027 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4028 { thislocale = GetSystemDefaultLCID();
4030 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
4031 thisformat = format_buf;
4034 { thisformat = format;
4037 if (xtime == NULL) /* NULL means use the current local time*/
4038 { GetSystemTime(&t);
4045 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
4050 /******************************************************************************
4051 * EnumCalendarInfoA [KERNEL32.196]
4053 BOOL WINAPI EnumCalendarInfoA(
4054 CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
4056 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);