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 * GetStringTypeW [KERNEL32.399]
1230 * Yes, this is missing LCID locale. MS fault.
1232 BOOL WINAPI GetStringTypeW(DWORD dwInfoType,LPCWSTR src,INT cchSrc,
1235 return GetStringTypeExW(0/*defaultlocale*/,dwInfoType,src,cchSrc,chartype);
1238 /******************************************************************************
1239 * GetStringTypeExW [KERNEL32.398]
1241 * FIXME: unicode chars are assumed chars
1243 BOOL WINAPI GetStringTypeExW(LCID locale,DWORD dwInfoType,LPCWSTR src,
1244 INT cchSrc,LPWORD chartype)
1250 cchSrc=lstrlenW(src)+1;
1252 switch (dwInfoType) {
1254 FIXME("CT_CTYPE2 not supported.\n");
1257 FIXME("CT_CTYPE3 not supported.\n");
1261 for (i=0;i<cchSrc;i++) {
1264 if ( ch >= (UINT)0x100 ) continue;
1265 if (isdigit(ch)) chartype[i]|=C1_DIGIT;
1266 if (isalpha(ch)) chartype[i]|=C1_ALPHA;
1267 if (islower(ch)) chartype[i]|=C1_LOWER;
1268 if (isupper(ch)) chartype[i]|=C1_UPPER;
1269 if (isspace(ch)) chartype[i]|=C1_SPACE;
1270 if (ispunct(ch)) chartype[i]|=C1_PUNCT;
1271 if (iscntrl(ch)) chartype[i]|=C1_CNTRL;
1272 /* FIXME: isblank() is a GNU extension */
1273 /* if (isblank(ch)) chartype[i]|=C1_BLANK; */
1274 if ((ch == ' ') || (ch == '\t')) chartype[i]|=C1_BLANK;
1280 /***********************************************************************
1281 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1283 DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
1288 return GetLocaleInfoA(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
1291 /***********************************************************************
1292 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1294 DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
1299 return GetLocaleInfoW(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
1303 static const unsigned char LCM_Unicode_LUT[] = {
1336 7 , 28, /* ! - 33 */
1337 7 , 29, /* " - 34 */ /* " */
1338 7 , 31, /* # - 35 */
1339 7 , 33, /* $ - 36 */
1340 7 , 35, /* % - 37 */
1341 7 , 37, /* & - 38 */
1342 6 , 128, /* ' - 39 */
1343 7 , 39, /* ( - 40 */
1344 7 , 42, /* ) - 41 */
1345 7 , 45, /* * - 42 */
1347 7 , 47, /* , - 44 */
1348 6 , 130, /* - - 45 */
1349 7 , 51, /* . - 46 */
1350 7 , 53, /* / - 47 */
1351 12 , 3, /* 0 - 48 */
1352 12 , 33, /* 1 - 49 */
1353 12 , 51, /* 2 - 50 */
1354 12 , 70, /* 3 - 51 */
1355 12 , 88, /* 4 - 52 */
1356 12 , 106, /* 5 - 53 */
1357 12 , 125, /* 6 - 54 */
1358 12 , 144, /* 7 - 55 */
1359 12 , 162, /* 8 - 56 */
1360 12 , 180, /* 9 - 57 */
1361 7 , 55, /* : - 58 */
1362 7 , 58, /* ; - 59 */
1363 8 , 14, /* < - 60 */
1364 8 , 18, /* = - 61 */
1365 8 , 20, /* > - 62 */
1366 7 , 60, /* ? - 63 */
1367 7 , 62, /* @ - 64 */
1368 14 , 2, /* A - 65 */
1369 14 , 9, /* B - 66 */
1370 14 , 10, /* C - 67 */
1371 14 , 26, /* D - 68 */
1372 14 , 33, /* E - 69 */
1373 14 , 35, /* F - 70 */
1374 14 , 37, /* G - 71 */
1375 14 , 44, /* H - 72 */
1376 14 , 50, /* I - 73 */
1377 14 , 53, /* J - 74 */
1378 14 , 54, /* K - 75 */
1379 14 , 72, /* L - 76 */
1380 14 , 81, /* M - 77 */
1381 14 , 112, /* N - 78 */
1382 14 , 124, /* O - 79 */
1383 14 , 126, /* P - 80 */
1384 14 , 137, /* Q - 81 */
1385 14 , 138, /* R - 82 */
1386 14 , 145, /* S - 83 */
1387 14 , 153, /* T - 84 */
1388 14 , 159, /* U - 85 */
1389 14 , 162, /* V - 86 */
1390 14 , 164, /* W - 87 */
1391 14 , 166, /* X - 88 */
1392 14 , 167, /* Y - 89 */
1393 14 , 169, /* Z - 90 */
1394 7 , 63, /* [ - 91 */
1395 7 , 65, /* \ - 92 */
1396 7 , 66, /* ] - 93 */
1397 7 , 67, /* ^ - 94 */
1398 7 , 68, /* _ - 95 */
1399 7 , 72, /* ` - 96 */
1400 14 , 2, /* a - 97 */
1401 14 , 9, /* b - 98 */
1402 14 , 10, /* c - 99 */
1403 14 , 26, /* d - 100 */
1404 14 , 33, /* e - 101 */
1405 14 , 35, /* f - 102 */
1406 14 , 37, /* g - 103 */
1407 14 , 44, /* h - 104 */
1408 14 , 50, /* i - 105 */
1409 14 , 53, /* j - 106 */
1410 14 , 54, /* k - 107 */
1411 14 , 72, /* l - 108 */
1412 14 , 81, /* m - 109 */
1413 14 , 112, /* n - 110 */
1414 14 , 124, /* o - 111 */
1415 14 , 126, /* p - 112 */
1416 14 , 137, /* q - 113 */
1417 14 , 138, /* r - 114 */
1418 14 , 145, /* s - 115 */
1419 14 , 153, /* t - 116 */
1420 14 , 159, /* u - 117 */
1421 14 , 162, /* v - 118 */
1422 14 , 164, /* w - 119 */
1423 14 , 166, /* x - 120 */
1424 14 , 167, /* y - 121 */
1425 14 , 169, /* z - 122 */
1426 7 , 74, /* { - 123 */
1427 7 , 76, /* | - 124 */
1428 7 , 78, /* } - 125 */
1429 7 , 80, /* ~ - 126 */
1430 6 , 29, /*
\7f - 127 */
1431 6 , 30, /*
\80 - 128 */
1432 6 , 31, /*
\81 - 129 */
1433 7 , 123, /*
\82 - 130 */
1434 14 , 35, /*
\83 - 131 */
1435 7 , 127, /*
\84 - 132 */
1436 10 , 21, /*
\85 - 133 */
1437 10 , 15, /*
\86 - 134 */
1438 10 , 16, /*
\87 - 135 */
1439 7 , 67, /*
\88 - 136 */
1440 10 , 22, /*
\89 - 137 */
1441 14 , 145, /*
\8a - 138 */
1442 7 , 136, /*
\8b - 139 */
1443 14 + 16 , 124, /*
\8c - 140 */
1444 6 , 43, /*
\8d - 141 */
1445 6 , 44, /*
\8e - 142 */
1446 6 , 45, /*
\8f - 143 */
1447 6 , 46, /*
\90 - 144 */
1448 7 , 121, /*
\91 - 145 */
1449 7 , 122, /*
\92 - 146 */
1450 7 , 125, /*
\93 - 147 */
1451 7 , 126, /*
\94 - 148 */
1452 10 , 17, /*
\95 - 149 */
1453 6 , 137, /*
\96 - 150 */
1454 6 , 139, /*
\97 - 151 */
1455 7 , 93, /*
\98 - 152 */
1456 14 , 156, /*
\99 - 153 */
1457 14 , 145, /*
\9a - 154 */
1458 7 , 137, /*
\9b - 155 */
1459 14 + 16 , 124, /*
\9c - 156 */
1460 6 , 59, /*
\9d - 157 */
1461 6 , 60, /*
\9e - 158 */
1462 14 , 167, /*
\9f - 159 */
1464 7 , 81, /* ¡ - 161 */
1465 10 , 2, /* ¢ - 162 */
1466 10 , 3, /* £ - 163 */
1467 10 , 4, /* ¤ - 164 */
1468 10 , 5, /* ¥ - 165 */
1469 7 , 82, /* ¦ - 166 */
1470 10 , 6, /* § - 167 */
1471 7 , 83, /* ¨ - 168 */
1472 10 , 7, /* © - 169 */
1473 14 , 2, /* ª - 170 */
1474 8 , 24, /* « - 171 */
1475 10 , 8, /* ¬ - 172 */
1476 6 , 131, /* - 173 */
1477 10 , 9, /* ® - 174 */
1478 7 , 84, /* ¯ - 175 */
1479 10 , 10, /* ° - 176 */
1480 8 , 23, /* ± - 177 */
1481 12 , 51, /* ² - 178 */
1482 12 , 70, /* ³ - 179 */
1483 7 , 85, /* ´ - 180 */
1484 10 , 11, /* µ - 181 */
1485 10 , 12, /* ¶ - 182 */
1486 10 , 13, /* · - 183 */
1487 7 , 86, /* ¸ - 184 */
1488 12 , 33, /* ¹ - 185 */
1489 14 , 124, /* º - 186 */
1490 8 , 26, /* » - 187 */
1491 12 , 21, /* ¼ - 188 */
1492 12 , 25, /* ½ - 189 */
1493 12 , 29, /* ¾ - 190 */
1494 7 , 87, /* ¿ - 191 */
1495 14 , 2, /* À - 192 */
1496 14 , 2, /* Á - 193 */
1497 14 , 2, /* Â - 194 */
1498 14 , 2, /* Ã - 195 */
1499 14 , 2, /* Ä - 196 */
1500 14 , 2, /* Å - 197 */
1501 14 + 16 , 2, /* Æ - 198 */
1502 14 , 10, /* Ç - 199 */
1503 14 , 33, /* È - 200 */
1504 14 , 33, /* É - 201 */
1505 14 , 33, /* Ê - 202 */
1506 14 , 33, /* Ë - 203 */
1507 14 , 50, /* Ì - 204 */
1508 14 , 50, /* Í - 205 */
1509 14 , 50, /* Î - 206 */
1510 14 , 50, /* Ï - 207 */
1511 14 , 26, /* Ð - 208 */
1512 14 , 112, /* Ñ - 209 */
1513 14 , 124, /* Ò - 210 */
1514 14 , 124, /* Ó - 211 */
1515 14 , 124, /* Ô - 212 */
1516 14 , 124, /* Õ - 213 */
1517 14 , 124, /* Ö - 214 */
1518 8 , 28, /* × - 215 */
1519 14 , 124, /* Ø - 216 */
1520 14 , 159, /* Ù - 217 */
1521 14 , 159, /* Ú - 218 */
1522 14 , 159, /* Û - 219 */
1523 14 , 159, /* Ü - 220 */
1524 14 , 167, /* Ý - 221 */
1525 14 + 32 , 153, /* Þ - 222 */
1526 14 + 48 , 145, /* ß - 223 */
1527 14 , 2, /* à - 224 */
1528 14 , 2, /* á - 225 */
1529 14 , 2, /* â - 226 */
1530 14 , 2, /* ã - 227 */
1531 14 , 2, /* ä - 228 */
1532 14 , 2, /* å - 229 */
1533 14 + 16 , 2, /* æ - 230 */
1534 14 , 10, /* ç - 231 */
1535 14 , 33, /* è - 232 */
1536 14 , 33, /* é - 233 */
1537 14 , 33, /* ê - 234 */
1538 14 , 33, /* ë - 235 */
1539 14 , 50, /* ì - 236 */
1540 14 , 50, /* í - 237 */
1541 14 , 50, /* î - 238 */
1542 14 , 50, /* ï - 239 */
1543 14 , 26, /* ð - 240 */
1544 14 , 112, /* ñ - 241 */
1545 14 , 124, /* ò - 242 */
1546 14 , 124, /* ó - 243 */
1547 14 , 124, /* ô - 244 */
1548 14 , 124, /* õ - 245 */
1549 14 , 124, /* ö - 246 */
1550 8 , 29, /* ÷ - 247 */
1551 14 , 124, /* ø - 248 */
1552 14 , 159, /* ù - 249 */
1553 14 , 159, /* ú - 250 */
1554 14 , 159, /* û - 251 */
1555 14 , 159, /* ü - 252 */
1556 14 , 167, /* ý - 253 */
1557 14 + 32 , 153, /* þ - 254 */
1558 14 , 167 /* ÿ - 255 */ };
1560 static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
1562 #define LCM_Diacritic_Start 131
1564 static const unsigned char LCM_Diacritic_LUT[] = {
1565 123, /*
\83 - 131 */
1692 /******************************************************************************
1693 * OLE2NLS_isPunctuation [INTERNAL]
1695 static int OLE2NLS_isPunctuation(unsigned char c)
1697 /* "punctuation character" in this context is a character which is
1698 considered "less important" during word sort comparison.
1699 See LCMapString implementation for the precise definition
1700 of "less important". */
1702 return (LCM_Unicode_LUT[-2+2*c]==6);
1705 /******************************************************************************
1706 * OLE2NLS_isNonSpacing [INTERNAL]
1708 static int OLE2NLS_isNonSpacing(unsigned char c)
1710 /* This function is used by LCMapStringA. Characters
1711 for which it returns true are ignored when mapping a
1712 string with NORM_IGNORENONSPACE */
1713 return ((c==136) || (c==170) || (c==186));
1716 /******************************************************************************
1717 * OLE2NLS_isSymbol [INTERNAL]
1719 static int OLE2NLS_isSymbol(unsigned char c)
1721 /* This function is used by LCMapStringA. Characters
1722 for which it returns true are ignored when mapping a
1723 string with NORM_IGNORESYMBOLS */
1724 return ( (c!=0) && !IsCharAlphaNumericA(c) );
1727 /******************************************************************************
1728 * identity [Internal]
1730 static int identity(int c)
1735 /*************************************************************************
1736 * LCMapStringA [KERNEL32.492]
1738 * Convert a string, or generate a sort key from it.
1740 * If (mapflags & LCMAP_SORTKEY), the function will generate
1741 * a sort key for the source string. Else, it will convert it
1742 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1746 * Success : length of the result string.
1749 * If called with scrlen = -1, the function will compute the length
1750 * of the 0-terminated string strsrc by itself.
1752 * If called with dstlen = 0, returns the buffer length that
1753 * would be required.
1755 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1756 * as if they are equal.
1757 * In the only code page implemented so far, there may not be
1758 * wide characters in strings passed to LCMapStringA,
1759 * so there is nothing to be done for this flag.
1761 INT WINAPI LCMapStringA(
1762 LCID lcid /* locale identifier created with MAKELCID;
1763 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1764 predefined values. */,
1765 DWORD mapflags /* flags */,
1766 LPCSTR srcstr /* source buffer */,
1767 INT srclen /* source length */,
1768 LPSTR dststr /* destination buffer */,
1769 INT dstlen /* destination buffer length */)
1773 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1774 lcid,mapflags,srcstr,srclen,dststr,dstlen);
1776 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1778 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
1779 SetLastError(ERROR_INVALID_PARAMETER);
1783 srclen = strlen(srcstr) + 1 ; /* (include final '\0') */
1785 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1789 NORM_IGNORENONSPACE | \
1791 NORM_IGNOREWIDTH | \
1792 NORM_IGNOREKANATYPE)
1793 /* FIXME: as long as we don't support Kanakana nor Hirigana
1794 * characters, we can support NORM_IGNOREKANATYPE
1796 if (mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS)
1798 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1799 "unimplemented flags: 0x%08lx\n",
1806 mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS
1810 if ( !(mapflags & LCMAP_SORTKEY) )
1813 int (*f)(int) = identity;
1814 int flag_ignorenonspace = mapflags & NORM_IGNORENONSPACE;
1815 int flag_ignoresymbols = mapflags & NORM_IGNORESYMBOLS;
1817 if (flag_ignorenonspace || flag_ignoresymbols)
1819 /* For some values of mapflags, the length of the resulting
1820 string is not known at this point. Windows does map the string
1821 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1825 /* Compute required length */
1826 for (i=j=0; i < srclen; i++)
1828 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1829 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1841 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1845 if (mapflags & LCMAP_UPPERCASE)
1847 else if (mapflags & LCMAP_LOWERCASE)
1849 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1850 for (i=j=0; (i<srclen) && (j<dstlen) ; i++)
1852 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1853 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1855 dststr[j] = (CHAR) f(srcstr[i]);
1862 /* FIXME: This function completely ignores the "lcid" parameter. */
1863 /* else ... (mapflags & LCMAP_SORTKEY) */
1867 int diacritic_len=0;
1868 int delayed_punctuation_len=0;
1869 char *case_component;
1870 char *diacritic_component;
1871 char *delayed_punctuation_component;
1873 int flag_stringsort = mapflags & SORT_STRINGSORT;
1875 /* compute how much room we will need */
1876 for (i=0;i<srclen;i++)
1879 unsigned char source_char = srcstr[i];
1880 if (source_char!='\0')
1882 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
1885 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
1886 unicode_len++; /* double letter */
1890 delayed_punctuation_len++;
1894 if (isupper(source_char))
1895 case_len=unicode_len;
1897 ofs = source_char - LCM_Diacritic_Start;
1898 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
1899 diacritic_len=unicode_len;
1902 if (mapflags & NORM_IGNORECASE)
1904 if (mapflags & NORM_IGNORENONSPACE)
1907 room = 2 * unicode_len /* "unicode" component */
1908 + diacritic_len /* "diacritic" component */
1909 + case_len /* "case" component */
1910 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
1911 + 4 /* four '\1' separators */
1912 + 1 ; /* terminal '\0' */
1915 else if (dstlen<room)
1917 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1921 /*FIXME the Pointercheck should not be nessesary */
1922 if (IsBadWritePtr (dststr,room))
1923 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
1924 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1928 /* locate each component, write separators */
1929 diacritic_component = dststr + 2*unicode_len ;
1930 *diacritic_component++ = '\1';
1931 case_component = diacritic_component + diacritic_len ;
1932 *case_component++ = '\1';
1933 delayed_punctuation_component = case_component + case_len ;
1934 *delayed_punctuation_component++ = '\1';
1935 *delayed_punctuation_component++ = '\1';
1937 /* read source string char by char, write
1938 corresponding weight in each component. */
1939 for (i=0,count=0;i<srclen;i++)
1941 unsigned char source_char=srcstr[i];
1942 if (source_char!='\0')
1945 type = LCM_Unicode_LUT[-2+2*source_char];
1946 longcode = type >> 4;
1948 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
1950 UINT16 encrypted_location = (1<<15) + 7 + 4*count;
1951 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
1952 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
1953 /* big-endian is used here because it lets string comparison be
1954 compatible with numerical comparison */
1956 *delayed_punctuation_component++ = type;
1957 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
1958 /* assumption : a punctuation character is never a
1959 double or accented letter */
1963 dststr[2*count] = type;
1964 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
1968 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1969 if (count<diacritic_len)
1970 diacritic_component[count] = 2; /* assumption: a double letter
1971 is never accented */
1974 dststr[2*count] = type;
1975 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
1976 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1977 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1978 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1982 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1983 if (count<diacritic_len)
1985 int ofs = source_char - LCM_Diacritic_Start;
1986 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
1992 dststr[room-1] = '\0';
1997 /*************************************************************************
1998 * LCMapStringW [KERNEL32.493]
2000 * Convert a string, or generate a sort key from it.
2004 * See LCMapStringA for documentation
2006 INT WINAPI LCMapStringW(
2007 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT srclen,LPWSTR dststr,
2012 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2013 lcid, mapflags, srcstr, srclen, dststr, dstlen);
2015 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2017 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
2018 SetLastError(ERROR_INVALID_PARAMETER);
2022 srclen = lstrlenW(srcstr)+1;
2024 /* FIXME: Both this function and it's companion LCMapStringA()
2025 * completely ignore the "lcid" parameter. In place of the "lcid"
2026 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2027 * environment variable prior to invoking this function. */
2028 if (mapflags & LCMAP_SORTKEY)
2030 /* Possible values of LC_COLLATE. */
2031 char *lc_collate_default = 0; /* value prior to this function */
2032 char *lc_collate_env = 0; /* value retrieved from the environment */
2034 /* General purpose index into strings of any type. */
2037 /* Lengths of various strings where the length is measured in
2038 * wide characters for wide character strings and in bytes for
2039 * native strings. The lengths include the NULL terminator. */
2040 size_t returned_len = 0;
2041 size_t src_native_len = 0;
2042 size_t dst_native_len = 0;
2043 size_t dststr_libc_len = 0;
2045 /* Native (character set determined by locale) versions of the
2046 * strings source and destination strings. */
2047 LPSTR src_native = 0;
2048 LPSTR dst_native = 0;
2050 /* Version of the source and destination strings using the
2051 * "wchar_t" Unicode data type needed by various libc functions. */
2052 wchar_t *srcstr_libc = 0;
2053 wchar_t *dststr_libc = 0;
2055 if(!(srcstr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2056 srclen * sizeof(wchar_t))))
2058 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2059 srclen * sizeof(wchar_t));
2060 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2064 /* Convert source string to a libc Unicode string. */
2065 for(str_idx = 0; str_idx < srclen; str_idx++)
2067 srcstr_libc[str_idx] = srcstr[str_idx];
2070 /* src_native should contain at most 3 bytes for each
2071 * multibyte characters in the original srcstr string. */
2072 src_native_len = 3 * srclen;
2073 if(!(src_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0,
2076 ERR("Unable to allocate %d bytes for src_native\n", src_native_len);
2077 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2078 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2082 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2083 * current value is backed up so it can be restored after the
2084 * last LC_COLLATE sensitive function returns.
2086 * Even though the locale is adjusted for a minimum amount of
2087 * time a race condition exists where other threads may be
2088 * affected if they invoke LC_COLLATE sensitive functions. One
2089 * possible solution is to wrap all LC_COLLATE sensitive Wine
2090 * functions, like LCMapStringW(), in a mutex.
2092 * Another enhancement to the following would be to set the
2093 * LC_COLLATE locale category as a function of the "lcid"
2094 * parameter instead of the "LC_COLLATE" environment variable. */
2095 if(!(lc_collate_default = setlocale(LC_COLLATE, NULL)))
2097 ERR("Unable to query the LC_COLLATE catagory\n");
2098 SetLastError(ERROR_INVALID_PARAMETER);
2099 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2100 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2104 if(!(lc_collate_env = setlocale(LC_COLLATE, "")))
2106 ERR("Unable to inherit the LC_COLLATE locale category from the "
2107 "environment. The \"LC_COLLATE\" environment variable is "
2108 "\"%s\".\n", getenv("LC_COLLATE") ?
2109 getenv("LC_COLLATE") : "<unset>");
2110 SetLastError(ERROR_INVALID_PARAMETER);
2111 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2112 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2116 TRACE("lc_collate_default = %s\n", lc_collate_default);
2117 TRACE("lc_collate_env = %s\n", lc_collate_env);
2119 /* Convert the libc Unicode string to a native multibyte character
2121 returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1;
2122 if(returned_len == 0)
2124 LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(),
2126 ERR("wcstombs failed. The string specified (%s) may contains an "
2127 "invalid character.\n", srcstr_ascii);
2128 SetLastError(ERROR_INVALID_PARAMETER);
2129 if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii);
2130 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2131 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2132 setlocale(LC_COLLATE, lc_collate_default);
2135 else if(returned_len > src_native_len)
2137 src_native[src_native_len - 1] = 0;
2138 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2139 "than expected (%d bytes).\n", src_native, returned_len,
2142 /* Since this is an internal error I'm not sure what the correct
2144 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2146 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2147 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2148 setlocale(LC_COLLATE, lc_collate_default);
2151 src_native_len = returned_len;
2153 TRACE("src_native = %s src_native_len = %d\n",
2154 src_native, src_native_len);
2156 /* dst_native seems to contain at most 4 bytes for each byte in
2157 * the original src_native string. Change if need be since this
2158 * isn't documented by the strxfrm() man page. */
2159 dst_native_len = 4 * src_native_len;
2160 if(!(dst_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0, dst_native_len)))
2162 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len);
2163 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2164 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2165 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2166 setlocale(LC_COLLATE, lc_collate_default);
2170 /* The actual translation is done by the following call to
2171 * strxfrm(). The surrounding code could have been simplified
2172 * by calling wcsxfrm() instead except that wcsxfrm() is not
2173 * available on older Linux systems (RedHat 4.1 with
2176 * Also, it is possible that the translation could be done by
2177 * various tables as it is done in LCMapStringA(). However, I'm
2178 * not sure what those tables are. */
2179 returned_len = strxfrm(dst_native, src_native, dst_native_len) + 1;
2181 if(returned_len > dst_native_len)
2183 dst_native[dst_native_len - 1] = 0;
2184 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2185 "than expected (%d bytes).\n", dst_native, returned_len,
2188 /* Since this is an internal error I'm not sure what the correct
2190 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2192 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2193 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2194 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2195 setlocale(LC_COLLATE, lc_collate_default);
2198 dst_native_len = returned_len;
2200 TRACE("dst_native = %s dst_native_len = %d\n",
2201 dst_native, dst_native_len);
2203 dststr_libc_len = dst_native_len;
2204 if(!(dststr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2205 dststr_libc_len * sizeof(wchar_t))))
2207 ERR("Unable to allocate %d bytes for dststr_libc\n",
2208 dststr_libc_len * sizeof(wchar_t));
2209 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2210 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2211 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2212 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2213 setlocale(LC_COLLATE, lc_collate_default);
2217 /* Convert the native multibyte string to a libc Unicode string. */
2218 returned_len = mbstowcs(dststr_libc, dst_native, dst_native_len) + 1;
2220 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2221 * function has returned. */
2222 setlocale(LC_COLLATE, lc_collate_default);
2224 if(returned_len == 0)
2226 ERR("mbstowcs failed. The native version of the translated string "
2227 "(%s) may contain an invalid character.\n", dst_native);
2228 SetLastError(ERROR_INVALID_PARAMETER);
2229 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2230 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2231 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2232 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2237 if(returned_len > dstlen)
2239 ERR("mbstowcs returned a string that was longer (%d chars) "
2240 "than the buffer provided (%d chars).\n", returned_len,
2242 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2243 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2244 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2245 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2246 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2249 dstlen = returned_len;
2251 /* Convert a libc Unicode string to the destination string. */
2252 for(str_idx = 0; str_idx < dstlen; str_idx++)
2254 dststr[str_idx] = dststr_libc[str_idx];
2256 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2257 *(((int *)dststr) + 0),
2258 *(((int *)dststr) + 1),
2259 *(((int *)dststr) + 2),
2260 *(((int *)dststr) + 3));
2264 dstlen = returned_len;
2266 TRACE("dstlen (return) = %d\n", dstlen);
2267 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2268 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2269 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2270 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2275 int (*f)(int)=identity;
2281 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2285 if (mapflags & LCMAP_UPPERCASE)
2287 else if (mapflags & LCMAP_LOWERCASE)
2289 for (i=0; i < srclen; i++)
2290 dststr[i] = (WCHAR) f(srcstr[i]);
2296 /***********************************************************************
2297 * OLE2NLS_EstimateMappingLength
2299 * Estimates the number of characters required to hold the string
2300 * computed by LCMapStringA.
2302 * The size is always over-estimated, with a fixed limit on the
2303 * amount of estimation error.
2305 * Note that len == -1 is not permitted.
2307 static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
2308 LPCSTR str, DWORD len)
2310 /* Estimate only for small strings to keep the estimation error from
2311 * becoming too large. */
2312 if (len < 128) return len * 8 + 5;
2313 else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
2316 /******************************************************************************
2317 * CompareStringA [KERNEL32.143]
2318 * Compares two strings using locale
2322 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2327 * Defaults to a word sort, but uses a string sort if
2328 * SORT_STRINGSORT is set.
2329 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2333 * This implementation ignores the locale
2337 * Quite inefficient.
2339 UINT WINAPI CompareStringA(
2340 DWORD lcid, /* locale ID */
2341 DWORD fdwStyle, /* comparison-style options */
2342 LPCSTR s1, /* first string */
2343 DWORD l1, /* length of first string */
2344 LPCSTR s2, /* second string */
2345 DWORD l2) /* length of second string */
2347 int mapstring_flags;
2351 TRACE("%s and %s\n",
2352 debugstr_a (s1), debugstr_a (s2));
2354 if ( (s1==NULL) || (s2==NULL) )
2356 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
2357 SetLastError(ERROR_INVALID_PARAMETER);
2361 if(fdwStyle & NORM_IGNORESYMBOLS)
2362 FIXME("IGNORESYMBOLS not supported\n");
2364 if (l1 == -1) l1 = strlen(s1);
2365 if (l2 == -1) l2 = strlen(s2);
2367 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2368 len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
2369 len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
2371 if ((len1==0)||(len2==0))
2372 return 0; /* something wrong happened */
2374 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
2376 if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
2377 || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2379 ERR("Bug in LCmapStringA.\n");
2384 /* strcmp doesn't necessarily return -1, 0, or 1 */
2385 result = strcmp(sk1,sk2);
2387 HeapFree(GetProcessHeap(),0,sk1);
2394 /* must be greater, if we reach this point */
2398 /******************************************************************************
2399 * CompareStringW [KERNEL32.144]
2400 * This implementation ignores the locale
2401 * FIXME : Does only string sort. Should
2402 * be reimplemented the same way as CompareStringA.
2404 UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
2405 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2408 if(fdwStyle & NORM_IGNORENONSPACE)
2409 FIXME("IGNORENONSPACE not supprted\n");
2410 if(fdwStyle & NORM_IGNORESYMBOLS)
2411 FIXME("IGNORESYMBOLS not supported\n");
2413 /* Is strcmp defaulting to string sort or to word sort?? */
2414 /* FIXME: Handle NORM_STRINGSORT */
2415 l1 = (l1==-1)?lstrlenW(s1):l1;
2416 l2 = (l2==-1)?lstrlenW(s2):l2;
2417 len = l1<l2 ? l1:l2;
2418 ret = (fdwStyle & NORM_IGNORECASE) ? strncmpiW(s1,s2,len) : strncmpW(s1,s2,len);
2419 /* not equal, return 1 or 3 */
2420 if(ret!=0) return ret+2;
2421 /* same len, return 2 */
2422 if(l1==l2) return 2;
2423 /* the longer one is lexically greater */
2424 return (l1<l2)? 1 : 3;
2427 /******************************************************************************
2428 * OLE_GetFormatA [Internal]
2431 * If datelen == 0, it should return the reguired string length.
2433 This function implements stuff for GetDateFormat() and
2436 d single-digit (no leading zero) day (of month)
2437 dd two-digit day (of month)
2438 ddd short day-of-week name
2439 dddd long day-of-week name
2440 M single-digit month
2442 MMM short month name
2443 MMMM full month name
2444 y two-digit year, no leading 0
2446 yyyy four-digit year
2448 h hours with no leading zero (12-hour)
2449 hh hours with full two digits
2450 H hours with no leading zero (24-hour)
2451 HH hours with full two digits
2452 m minutes with no leading zero
2453 mm minutes with full two digits
2454 s seconds with no leading zero
2455 ss seconds with full two digits
2456 t time marker (A or P)
2457 tt time marker (AM, PM)
2458 '' used to quote literal characters
2459 '' (within a quoted string) indicates a literal '
2461 These functions REQUIRE valid locale, date, and format.
2463 static INT OLE_GetFormatA(LCID locale,
2467 LPCSTR _format, /*in*/
2472 int count, type, inquote, Overflow;
2478 const char * _dgfmt[] = { "%d", "%02d" };
2479 const char ** dgfmt = _dgfmt - 1;
2481 /* report, for debugging */
2482 TRACE("(0x%lx,0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
2483 locale, flags, tflags,
2484 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2485 _format, _format, date, datelen);
2488 FIXME("datelen = 0, returning 255\n");
2492 /* initalize state variables and output buffer */
2494 count = 0; inquote = 0; Overflow = 0;
2496 date[0] = buf[0] = '\0';
2498 strcpy(format,_format);
2500 /* alter the formatstring, while it works for all languages now in wine
2501 its possible that it fails when the time looks like ss:mm:hh as example*/
2502 if (tflags & (TIME_NOMINUTESORSECONDS))
2503 { if ((pos = strstr ( format, ":mm")))
2504 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2507 if (tflags & (TIME_NOSECONDS))
2508 { if ((pos = strstr ( format, ":ss")))
2509 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2513 for (inpos = 0;; inpos++) {
2514 /* 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]); */
2516 if (format[inpos] == '\'') {
2517 if (format[inpos+1] == '\'') {
2519 date[outpos++] = '\'';
2522 continue; /* we did nothing to the output */
2524 } else if (format[inpos] == '\0') {
2525 date[outpos++] = '\0';
2526 if (outpos > datelen) Overflow = 1;
2529 date[outpos++] = format[inpos];
2530 if (outpos > datelen) {
2532 date[outpos-1] = '\0'; /* this is the last place where
2533 it's safe to write */
2537 } else if ( (count && (format[inpos] != type))
2539 || (count == 2 && strchr("ghHmst", type)) )
2543 GetLocaleInfoA(locale,
2545 + xtime->wDayOfWeek - 1,
2547 } else if (count == 3) {
2548 GetLocaleInfoA(locale,
2549 LOCALE_SABBREVDAYNAME1
2550 + xtime->wDayOfWeek - 1,
2553 sprintf(buf, dgfmt[count], xtime->wDay);
2555 } else if (type == 'M') {
2557 GetLocaleInfoA(locale,
2558 LOCALE_SABBREVMONTHNAME1
2559 + xtime->wMonth - 1,
2561 } else if (count == 4) {
2562 GetLocaleInfoA(locale,
2564 + xtime->wMonth - 1,
2567 sprintf(buf, dgfmt[count], xtime->wMonth);
2569 } else if (type == 'y') {
2571 sprintf(buf, "%d", xtime->wYear);
2572 } else if (count == 3) {
2574 WARN("unknown format, c=%c, n=%d\n", type, count);
2576 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2578 } else if (type == 'g') {
2580 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2584 WARN("unknown format, c=%c, n=%d\n", type, count);
2586 } else if (type == 'h') {
2587 /* gives us hours 1:00 -- 12:00 */
2588 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2589 } else if (type == 'H') {
2591 sprintf(buf, dgfmt[count], xtime->wHour);
2592 } else if ( type == 'm') {
2593 sprintf(buf, dgfmt[count], xtime->wMinute);
2594 } else if ( type == 's') {
2595 sprintf(buf, dgfmt[count], xtime->wSecond);
2596 } else if (type == 't') {
2598 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2599 } else if (count == 2) {
2600 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2601 GetLocaleInfoA(locale,
2603 ? LOCALE_S1159 : LOCALE_S2359,
2608 /* we need to check the next char in the format string
2609 again, no matter what happened */
2612 /* add the contents of buf to the output */
2613 buflen = strlen(buf);
2614 if (outpos + buflen < datelen) {
2615 date[outpos] = '\0'; /* for strcat to hook onto */
2619 date[outpos] = '\0';
2620 strncat(date, buf, datelen - outpos);
2621 date[datelen - 1] = '\0';
2622 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2623 WARN("insufficient buffer\n");
2627 /* reset the variables we used to keep track of this item */
2630 } else if (format[inpos] == '\0') {
2631 /* we can't check for this at the loop-head, because
2632 that breaks the printing of the last format-item */
2633 date[outpos] = '\0';
2636 /* continuing a code for an item */
2639 } else if (strchr("hHmstyMdg", format[inpos])) {
2640 type = format[inpos];
2643 } else if (format[inpos] == '\'') {
2647 date[outpos++] = format[inpos];
2649 /* now deal with a possible buffer overflow */
2650 if (outpos >= datelen) {
2651 date[datelen - 1] = '\0';
2652 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2658 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2661 /* finish it off with a string terminator */
2664 if (outpos > datelen-1) outpos = datelen-1;
2665 date[outpos] = '\0';
2667 TRACE("OLE_GetFormatA returns string '%s', len %d\n",
2672 /******************************************************************************
2673 * OLE_GetFormatW [INTERNAL]
2675 static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
2678 LPWSTR output, INT outlen)
2681 int count, type=0, inquote;
2682 int Overflow; /* loop check */
2685 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2686 WCHAR arg2[] = {'%','0','2','d',0};
2688 int datevars=0, timevars=0;
2694 /* make a debug report */
2695 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2696 "%p with max len %d\n",
2697 locale, flags, tflags,
2698 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2699 debugstr_w(format), format, output, outlen);
2702 FIXME("outlen = 0, returning 255\n");
2706 /* initialize state variables */
2709 inquote = Overflow = 0;
2710 /* this is really just a sanity check */
2711 output[0] = buf[0] = 0;
2713 /* this loop is the core of the function */
2714 for (inpos = 0; /* we have several break points */ ; inpos++) {
2716 if (format[inpos] == (WCHAR) '\'') {
2717 if (format[inpos+1] == '\'') {
2719 output[outpos++] = '\'';
2724 } else if (format[inpos] == 0) {
2725 output[outpos++] = 0;
2726 if (outpos > outlen) Overflow = 1;
2727 break; /* normal exit (within a quote) */
2729 output[outpos++] = format[inpos]; /* copy input */
2730 if (outpos > outlen) {
2732 output[outpos-1] = 0;
2736 } else if ( (count && (format[inpos] != type))
2737 || ( (count==4 && type =='y') ||
2738 (count==4 && type =='M') ||
2739 (count==4 && type =='d') ||
2740 (count==2 && type =='g') ||
2741 (count==2 && type =='h') ||
2742 (count==2 && type =='H') ||
2743 (count==2 && type =='m') ||
2744 (count==2 && type =='s') ||
2745 (count==2 && type =='t') ) ) {
2748 GetLocaleInfoW(locale,
2749 LOCALE_SDAYNAME1 + xtime->wDayOfWeek -1,
2750 buf, sizeof(buf)/sizeof(WCHAR) );
2751 } else if (count == 3) {
2752 GetLocaleInfoW(locale,
2753 LOCALE_SABBREVDAYNAME1 +
2754 xtime->wDayOfWeek -1,
2755 buf, sizeof(buf)/sizeof(WCHAR) );
2757 wsnprintfW(buf, 5, argarr[count], xtime->wDay );
2759 } else if (type == 'M') {
2761 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
2762 xtime->wMonth -1, buf,
2763 sizeof(buf)/sizeof(WCHAR) );
2764 } else if (count == 3) {
2765 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
2766 xtime->wMonth -1, buf,
2767 sizeof(buf)/sizeof(WCHAR) );
2769 wsnprintfW(buf, 5, argarr[count], xtime->wMonth);
2771 } else if (type == 'y') {
2773 wsnprintfW(buf, 6, argarr[1] /* "%d" */,
2775 } else if (count == 3) {
2776 lstrcpynAtoW(buf, "yyy", 5);
2778 wsnprintfW(buf, 6, argarr[count],
2779 xtime->wYear % 100);
2781 } else if (type == 'g') {
2783 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2784 lstrcpynAtoW(buf, "AD", 5);
2786 /* Win API sez we copy it verbatim */
2787 lstrcpynAtoW(buf, "g", 5);
2789 } else if (type == 'h') {
2790 /* hours 1:00-12:00 --- is this right? */
2791 wsnprintfW(buf, 5, argarr[count],
2792 (xtime->wHour-1)%12 +1);
2793 } else if (type == 'H') {
2794 wsnprintfW(buf, 5, argarr[count],
2796 } else if (type == 'm' ) {
2797 wsnprintfW(buf, 5, argarr[count],
2799 } else if (type == 's' ) {
2800 wsnprintfW(buf, 5, argarr[count],
2802 } else if (type == 't') {
2803 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
2804 LOCALE_S1159 : LOCALE_S2359,
2811 /* no matter what happened, we need to check this next
2812 character the next time we loop through */
2815 /* cat buf onto the output */
2816 outlen = lstrlenW(buf);
2817 if (outpos + buflen < outlen) {
2818 lstrcpyW( output + outpos, buf );
2821 lstrcpynW( output + outpos, buf, outlen - outpos );
2823 break; /* Abnormal exit */
2826 /* reset the variables we used this time */
2829 } else if (format[inpos] == 0) {
2830 /* we can't check for this at the beginning, because that
2831 would keep us from printing a format spec that ended the
2834 break; /* NORMAL EXIT */
2836 /* how we keep track of the middle of a format spec */
2839 } else if ( (datevars && (format[inpos]=='d' ||
2840 format[inpos]=='M' ||
2841 format[inpos]=='y' ||
2842 format[inpos]=='g') ) ||
2843 (timevars && (format[inpos]=='H' ||
2844 format[inpos]=='h' ||
2845 format[inpos]=='m' ||
2846 format[inpos]=='s' ||
2847 format[inpos]=='t') ) ) {
2848 type = format[inpos];
2851 } else if (format[inpos] == '\'') {
2855 /* unquoted literals */
2856 output[outpos++] = format[inpos];
2861 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2862 WARN(" buffer overflow\n");
2865 /* final string terminator and sanity check */
2867 if (outpos > outlen-1) outpos = outlen-1;
2868 output[outpos] = '0';
2870 TRACE(" returning %s\n", debugstr_w(output));
2872 return (!Overflow) ? outlen : 0;
2877 /******************************************************************************
2878 * GetDateFormatA [KERNEL32.310]
2879 * Makes an ASCII string of the date
2881 * This function uses format to format the date, or, if format
2882 * is NULL, uses the default for the locale. format is a string
2883 * of literal fields and characters as follows:
2885 * - d single-digit (no leading zero) day (of month)
2886 * - dd two-digit day (of month)
2887 * - ddd short day-of-week name
2888 * - dddd long day-of-week name
2889 * - M single-digit month
2890 * - MM two-digit month
2891 * - MMM short month name
2892 * - MMMM full month name
2893 * - y two-digit year, no leading 0
2894 * - yy two-digit year
2895 * - yyyy four-digit year
2899 INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
2901 LPCSTR format, LPSTR date,INT datelen)
2904 char format_buf[40];
2907 LPSYSTEMTIME thistime;
2911 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2912 locale,flags,xtime,format,date,datelen);
2915 locale = LOCALE_SYSTEM_DEFAULT;
2918 if (locale == LOCALE_SYSTEM_DEFAULT) {
2919 thislocale = GetSystemDefaultLCID();
2920 } else if (locale == LOCALE_USER_DEFAULT) {
2921 thislocale = GetUserDefaultLCID();
2923 thislocale = locale;
2926 if (xtime == NULL) {
2933 if (format == NULL) {
2934 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
2936 : LOCALE_SSHORTDATE),
2937 format_buf, sizeof(format_buf));
2938 thisformat = format_buf;
2940 thisformat = format;
2944 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
2949 "GetDateFormatA() returning %d, with data=%s\n",
2954 /******************************************************************************
2955 * GetDateFormatW [KERNEL32.311]
2956 * Makes a Unicode string of the date
2958 * Acts the same as GetDateFormatA(), except that it's Unicode.
2959 * Accepts & returns sizes as counts of Unicode characters.
2962 INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
2965 LPWSTR date, INT datelen)
2967 unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
2969 FIXME("STUB (should call OLE_GetFormatW)\n");
2970 lstrcpynW(date, datearr, datelen);
2971 return ( datelen < 9) ? datelen : 9;
2976 /**************************************************************************
2977 * EnumDateFormatsA (KERNEL32.198)
2979 BOOL WINAPI EnumDateFormatsA(
2980 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2982 LCID Loc = GetUserDefaultLCID();
2983 if(!lpDateFmtEnumProc)
2985 SetLastError(ERROR_INVALID_PARAMETER);
2992 case 0x00000407: /* (Loc,"de_DE") */
2996 case DATE_SHORTDATE:
2997 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
2998 if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
2999 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3000 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3003 if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
3004 if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
3005 if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
3008 FIXME("Unknown date format (%ld)\n", dwFlags);
3009 SetLastError(ERROR_INVALID_PARAMETER);
3014 case 0x0000040c: /* (Loc,"fr_FR") */
3018 case DATE_SHORTDATE:
3019 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3020 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3021 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3022 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3025 if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
3026 if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
3027 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3030 FIXME("Unknown date format (%ld)\n", dwFlags);
3031 SetLastError(ERROR_INVALID_PARAMETER);
3036 case 0x00000c0c: /* (Loc,"fr_CA") */
3040 case DATE_SHORTDATE:
3041 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3042 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3043 if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
3044 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3047 if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
3048 if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
3051 FIXME("Unknown date format (%ld)\n", dwFlags);
3052 SetLastError(ERROR_INVALID_PARAMETER);
3057 case 0x00000809: /* (Loc,"en_UK") */
3061 case DATE_SHORTDATE:
3062 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3063 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3064 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3065 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3068 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3069 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3072 FIXME("Unknown date format (%ld)\n", dwFlags);
3073 SetLastError(ERROR_INVALID_PARAMETER);
3078 case 0x00000c09: /* (Loc,"en_AU") */
3082 case DATE_SHORTDATE:
3083 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3084 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3085 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3088 if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
3089 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3092 FIXME("Unknown date format (%ld)\n", dwFlags);
3093 SetLastError(ERROR_INVALID_PARAMETER);
3098 case 0x00001009: /* (Loc,"en_CA") */
3102 case DATE_SHORTDATE:
3103 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3104 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3105 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3106 if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
3109 if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
3110 if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
3113 FIXME("Unknown date format (%ld)\n", dwFlags);
3114 SetLastError(ERROR_INVALID_PARAMETER);
3119 case 0x00001409: /* (Loc,"en_NZ") */
3123 case DATE_SHORTDATE:
3124 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3125 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3126 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3129 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3130 if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
3133 FIXME("Unknown date format (%ld)\n", dwFlags);
3134 SetLastError(ERROR_INVALID_PARAMETER);
3139 case 0x00001809: /* (Loc,"en_IE") */
3143 case DATE_SHORTDATE:
3144 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3145 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3146 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3149 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3150 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3153 FIXME("Unknown date format (%ld)\n", dwFlags);
3154 SetLastError(ERROR_INVALID_PARAMETER);
3159 case 0x00001c09: /* (Loc,"en_ZA") */
3163 case DATE_SHORTDATE:
3164 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3167 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3170 FIXME("Unknown date format (%ld)\n", dwFlags);
3171 SetLastError(ERROR_INVALID_PARAMETER);
3176 case 0x00002009: /* (Loc,"en_JM") */
3180 case DATE_SHORTDATE:
3181 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3184 if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
3185 if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
3186 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
3187 if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
3190 FIXME("Unknown date format (%ld)\n", dwFlags);
3191 SetLastError(ERROR_INVALID_PARAMETER);
3196 case 0x00002809: /* (Loc,"en_BZ") */
3197 case 0x00002c09: /* (Loc,"en_TT") */
3201 case DATE_SHORTDATE:
3202 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3205 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
3208 FIXME("Unknown date format (%ld)\n", dwFlags);
3209 SetLastError(ERROR_INVALID_PARAMETER);
3214 default: /* default to US English "en_US" */
3218 case DATE_SHORTDATE:
3219 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
3220 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
3221 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
3222 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
3223 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3224 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
3227 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
3228 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
3229 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
3230 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
3233 FIXME("Unknown date format (%ld)\n", dwFlags);
3234 SetLastError(ERROR_INVALID_PARAMETER);
3241 /**************************************************************************
3242 * EnumDateFormatsW (KERNEL32.199)
3244 BOOL WINAPI EnumDateFormatsW(
3245 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3247 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
3248 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3252 /**************************************************************************
3253 * EnumTimeFormatsA (KERNEL32.210)
3255 BOOL WINAPI EnumTimeFormatsA(
3256 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3258 LCID Loc = GetUserDefaultLCID();
3259 if(!lpTimeFmtEnumProc)
3261 SetLastError(ERROR_INVALID_PARAMETER);
3266 FIXME("Unknown time format (%ld)\n", dwFlags);
3271 case 0x00000407: /* (Loc,"de_DE") */
3273 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3274 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3275 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3276 if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
3277 if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
3281 case 0x0000040c: /* (Loc,"fr_FR") */
3282 case 0x00000c0c: /* (Loc,"fr_CA") */
3284 if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
3285 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3286 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3287 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3288 if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
3292 case 0x00000809: /* (Loc,"en_UK") */
3293 case 0x00000c09: /* (Loc,"en_AU") */
3294 case 0x00001409: /* (Loc,"en_NZ") */
3295 case 0x00001809: /* (Loc,"en_IE") */
3297 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3298 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3299 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3303 case 0x00001c09: /* (Loc,"en_ZA") */
3304 case 0x00002809: /* (Loc,"en_BZ") */
3305 case 0x00002c09: /* (Loc,"en_TT") */
3307 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3308 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3312 default: /* default to US style "en_US" */
3314 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3315 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3316 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3317 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3323 /**************************************************************************
3324 * EnumTimeFormatsW (KERNEL32.211)
3326 BOOL WINAPI EnumTimeFormatsW(
3327 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3329 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
3330 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3334 /**************************************************************************
3335 * This function is used just locally !
3336 * Description: Inverts a string.
3338 static void OLE_InvertString(char* string)
3340 char sTmpArray[128];
3343 for (counter = strlen(string); counter > 0; counter--)
3345 memcpy(sTmpArray + i, string + counter-1, 1);
3348 memcpy(sTmpArray + i, "\0", 1);
3349 strcpy(string, sTmpArray);
3352 /***************************************************************************************
3353 * This function is used just locally !
3354 * Description: Test if the given string (psNumber) is valid or not.
3355 * The valid characters are the following:
3356 * - Characters '0' through '9'.
3357 * - One decimal point (dot) if the number is a floating-point value.
3358 * - A minus sign in the first character position if the number is
3360 * If the function succeeds, psBefore/psAfter will point to the string
3361 * on the right/left of the decimal symbol. pbNegative indicates if the
3362 * number is negative.
3364 static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
3366 char sNumberSet[] = "0123456789";
3367 BOOL bInDecimal = FALSE;
3369 /* Test if we do have a minus sign */
3370 if ( *pInput == '-' )
3373 pInput++; /* Jump to the next character. */
3376 while(*pInput != '\0')
3378 /* Do we have a valid numeric character */
3379 if ( strchr(sNumberSet, *pInput) != NULL )
3381 if (bInDecimal == TRUE)
3382 *psAfter++ = *pInput;
3384 *psBefore++ = *pInput;
3388 /* Is this a decimal point (dot) */
3389 if ( *pInput == '.' )
3391 /* Is it the first time we find it */
3392 if ((bInDecimal == FALSE))
3395 return -1; /* ERROR: Invalid parameter */
3399 /* It's neither a numeric character, nor a decimal point.
3400 * Thus, return an error.
3408 /* Add an End of Line character to the output buffers */
3415 /**************************************************************************
3416 * This function is used just locally !
3417 * Description: A number could be formatted using different numbers
3418 * of "digits in group" (example: 4;3;2;0).
3419 * The first parameter of this function is an array
3420 * containing the rule to be used. It's format is the following:
3421 * |NDG|DG1|DG2|...|0|
3422 * where NDG is the number of used "digits in group" and DG1, DG2,
3423 * are the corresponding "digits in group".
3424 * Thus, this function returns the grouping value in the array
3425 * pointed by the second parameter.
3427 static INT OLE_GetGrouping(char* sRule, INT index)
3429 char sData[2], sRuleSize[2];
3430 INT nData, nRuleSize;
3432 memcpy(sRuleSize, sRule, 1);
3433 memcpy(sRuleSize+1, "\0", 1);
3434 nRuleSize = atoi(sRuleSize);
3436 if (index > 0 && index < nRuleSize)
3438 memcpy(sData, sRule+index, 1);
3439 memcpy(sData+1, "\0", 1);
3440 nData = atoi(sData);
3445 memcpy(sData, sRule+nRuleSize-1, 1);
3446 memcpy(sData+1, "\0", 1);
3447 nData = atoi(sData);
3453 /**************************************************************************
3454 * GetNumberFormatA (KERNEL32.355)
3456 INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
3457 LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
3458 LPSTR lpNumberStr, int cchNumber)
3460 char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
3461 INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
3462 char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
3463 char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
3464 char *pStr = NULL, *pTmpStr = NULL;
3465 LCID systemDefaultLCID;
3466 BOOL bNegative = FALSE;
3475 strncpy(sNumber, lpvalue, 128);
3476 sNumber[127] = '\0';
3478 /* Make sure we have a valid input string, get the number
3479 * of digits before and after the decimal symbol, and check
3480 * if this is a negative number.
3482 if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
3484 nNumberDecimal = strlen(sDigitsBeforeDecimal);
3485 nDigits = strlen(sDigitsAfterDecimal);
3489 SetLastError(ERROR_INVALID_PARAMETER);
3493 /* Which source will we use to format the string */
3494 used_operation = RETURN_ERROR;
3495 if (lpFormat != NULL)
3498 used_operation = USE_PARAMETER;
3502 if (dwflags & LOCALE_NOUSEROVERRIDE)
3503 used_operation = USE_LOCALEINFO;
3505 used_operation = USE_SYSTEMDEFAULT;
3508 /* Load the fields we need */
3509 switch(used_operation)
3511 case USE_LOCALEINFO:
3512 GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3513 GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3514 GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3515 GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3516 GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3517 GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3520 sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
3521 strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
3522 sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
3523 strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
3524 sprintf(sILZero, "%d",lpFormat->LeadingZero);
3525 sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
3527 case USE_SYSTEMDEFAULT:
3528 systemDefaultLCID = GetSystemDefaultLCID();
3529 GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3530 GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3531 GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3532 GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3533 GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3534 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3537 SetLastError(ERROR_INVALID_PARAMETER);
3541 nNumberDigits = atoi(sNumberDigits);
3543 /* Remove the ";" */
3546 for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
3548 if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
3550 memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
3555 sprintf(sBuffer, "%d", i);
3556 memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3557 memcpy(sRule + j, "\0", 1);
3559 /* First, format the digits before the decimal. */
3560 if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
3562 /* Working on an inverted string is easier ! */
3563 OLE_InvertString(sDigitsBeforeDecimal);
3565 nStep = nCounter = i = j = 0;
3567 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3569 /* Here, we will loop until we reach the end of the string.
3570 * An internal counter (j) is used in order to know when to
3571 * insert the "digit group symbol".
3573 while (nNumberDecimal > 0)
3575 i = nCounter + nStep;
3576 memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
3582 if (nRuleIndex < sRule[0])
3584 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3585 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
3586 nStep+= strlen(sDigitGroupSymbol);
3592 memcpy(sDestination + i+1, "\0", 1);
3593 /* Get the string in the right order ! */
3594 OLE_InvertString(sDestination);
3598 nLZ = atoi(sILZero);
3601 /* Use 0.xxx instead of .xxx */
3602 memcpy(sDestination, "0", 1);
3603 memcpy(sDestination+1, "\0", 1);
3606 memcpy(sDestination, "\0", 1);
3610 /* Second, format the digits after the decimal. */
3612 nCounter = nNumberDigits;
3613 if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
3615 i = strlen(sNumber) - strlen(pStr) + 1;
3616 strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
3617 j = strlen(sDigitsAfterDecimal);
3618 if (j < nNumberDigits)
3619 nCounter = nNumberDigits-j;
3621 for (i=0;i<nCounter;i++)
3622 memcpy(sDigitsAfterDecimal+i+j, "0", 1);
3623 memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
3625 i = strlen(sDestination);
3626 j = strlen(sDigitsAfterDecimal);
3627 /* Finally, construct the resulting formatted string. */
3629 for (nCounter=0; nCounter<i; nCounter++)
3630 memcpy(sNumber + nCounter, sDestination + nCounter, 1);
3632 memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
3635 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
3636 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
3638 /* Is it a negative number */
3639 if (bNegative == TRUE)
3641 i = atoi(sNegNumber);
3642 pStr = sDestination;
3648 while (*sNumber != '\0')
3649 *pStr++ = *pTmpStr++;
3654 while (*pTmpStr != '\0')
3655 *pStr++ = *pTmpStr++;
3660 while (*pTmpStr != '\0')
3661 *pStr++ = *pTmpStr++;
3664 while (*pTmpStr != '\0')
3665 *pStr++ = *pTmpStr++;
3669 while (*pTmpStr != '\0')
3670 *pStr++ = *pTmpStr++;
3675 while (*pTmpStr != '\0')
3676 *pStr++ = *pTmpStr++;
3681 strcpy(sDestination, sNumber);
3683 /* If cchNumber is zero, then returns the number of bytes or characters
3684 * required to hold the formatted number string
3687 retVal = strlen(sDestination) + 1;
3690 strncpy (lpNumberStr, sDestination, cchNumber-1);
3691 *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
3692 retVal = strlen(lpNumberStr);
3698 /**************************************************************************
3699 * GetNumberFormatW (KERNEL32.xxx)
3701 INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
3702 LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
3703 LPWSTR lpNumberStr, int cchNumber)
3705 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue));
3707 lstrcpynW( lpNumberStr, lpvalue, cchNumber );
3708 return cchNumber? lstrlenW( lpNumberStr ) : 0;
3711 /**************************************************************************
3712 * GetCurrencyFormatA (KERNEL32.302)
3714 INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
3715 LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
3716 LPSTR lpCurrencyStr, int cchCurrency)
3718 UINT nPosOrder, nNegOrder;
3720 char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
3721 char *pDestination = sDestination;
3722 char sNumberFormated[128];
3723 char *pNumberFormated = sNumberFormated;
3724 LCID systemDefaultLCID;
3725 BOOL bIsPositive = FALSE, bValidFormat = FALSE;
3734 NUMBERFMTA numberFmt;
3736 /* Which source will we use to format the string */
3737 used_operation = RETURN_ERROR;
3738 if (lpFormat != NULL)
3741 used_operation = USE_PARAMETER;
3745 if (dwflags & LOCALE_NOUSEROVERRIDE)
3746 used_operation = USE_LOCALEINFO;
3748 used_operation = USE_SYSTEMDEFAULT;
3751 /* Load the fields we need */
3752 switch(used_operation)
3754 case USE_LOCALEINFO:
3755 /* Specific to CURRENCYFMTA*/
3756 GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3757 GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3758 GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3760 nPosOrder = atoi(sPosOrder);
3761 nNegOrder = atoi(sNegOrder);
3764 /* Specific to CURRENCYFMTA*/
3765 nNegOrder = lpFormat->NegativeOrder;
3766 nPosOrder = lpFormat->PositiveOrder;
3767 strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
3769 case USE_SYSTEMDEFAULT:
3770 systemDefaultLCID = GetSystemDefaultLCID();
3771 /* Specific to CURRENCYFMTA*/
3772 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3773 GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3774 GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3776 nPosOrder = atoi(sPosOrder);
3777 nNegOrder = atoi(sNegOrder);
3780 SetLastError(ERROR_INVALID_PARAMETER);
3784 /* Construct a temporary number format structure */
3785 if (lpFormat != NULL)
3787 numberFmt.NumDigits = lpFormat->NumDigits;
3788 numberFmt.LeadingZero = lpFormat->LeadingZero;
3789 numberFmt.Grouping = lpFormat->Grouping;
3790 numberFmt.NegativeOrder = 0;
3791 numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
3792 numberFmt.lpThousandSep = lpFormat->lpThousandSep;
3793 bValidFormat = TRUE;
3796 /* Make a call to GetNumberFormatA() */
3797 if (*lpvalue == '-')
3799 bIsPositive = FALSE;
3800 retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3805 retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3811 /* construct the formatted string */
3816 case 0: /* Prefix, no separation */
3817 strcpy (pDestination, sCurrencySymbol);
3818 strcat (pDestination, pNumberFormated);
3820 case 1: /* Suffix, no separation */
3821 strcpy (pDestination, pNumberFormated);
3822 strcat (pDestination, sCurrencySymbol);
3824 case 2: /* Prefix, 1 char separation */
3825 strcpy (pDestination, sCurrencySymbol);
3826 strcat (pDestination, " ");
3827 strcat (pDestination, pNumberFormated);
3829 case 3: /* Suffix, 1 char separation */
3830 strcpy (pDestination, pNumberFormated);
3831 strcat (pDestination, " ");
3832 strcat (pDestination, sCurrencySymbol);
3835 SetLastError(ERROR_INVALID_PARAMETER);
3839 else /* negative number */
3843 case 0: /* format: ($1.1) */
3844 strcpy (pDestination, "(");
3845 strcat (pDestination, sCurrencySymbol);
3846 strcat (pDestination, pNumberFormated);
3847 strcat (pDestination, ")");
3849 case 1: /* format: -$1.1 */
3850 strcpy (pDestination, "-");
3851 strcat (pDestination, sCurrencySymbol);
3852 strcat (pDestination, pNumberFormated);
3854 case 2: /* format: $-1.1 */
3855 strcpy (pDestination, sCurrencySymbol);
3856 strcat (pDestination, "-");
3857 strcat (pDestination, pNumberFormated);
3859 case 3: /* format: $1.1- */
3860 strcpy (pDestination, sCurrencySymbol);
3861 strcat (pDestination, pNumberFormated);
3862 strcat (pDestination, "-");
3864 case 4: /* format: (1.1$) */
3865 strcpy (pDestination, "(");
3866 strcat (pDestination, pNumberFormated);
3867 strcat (pDestination, sCurrencySymbol);
3868 strcat (pDestination, ")");
3870 case 5: /* format: -1.1$ */
3871 strcpy (pDestination, "-");
3872 strcat (pDestination, pNumberFormated);
3873 strcat (pDestination, sCurrencySymbol);
3875 case 6: /* format: 1.1-$ */
3876 strcpy (pDestination, pNumberFormated);
3877 strcat (pDestination, "-");
3878 strcat (pDestination, sCurrencySymbol);
3880 case 7: /* format: 1.1$- */
3881 strcpy (pDestination, pNumberFormated);
3882 strcat (pDestination, sCurrencySymbol);
3883 strcat (pDestination, "-");
3885 case 8: /* format: -1.1 $ */
3886 strcpy (pDestination, "-");
3887 strcat (pDestination, pNumberFormated);
3888 strcat (pDestination, " ");
3889 strcat (pDestination, sCurrencySymbol);
3891 case 9: /* format: -$ 1.1 */
3892 strcpy (pDestination, "-");
3893 strcat (pDestination, sCurrencySymbol);
3894 strcat (pDestination, " ");
3895 strcat (pDestination, pNumberFormated);
3897 case 10: /* format: 1.1 $- */
3898 strcpy (pDestination, pNumberFormated);
3899 strcat (pDestination, " ");
3900 strcat (pDestination, sCurrencySymbol);
3901 strcat (pDestination, "-");
3903 case 11: /* format: $ 1.1- */
3904 strcpy (pDestination, sCurrencySymbol);
3905 strcat (pDestination, " ");
3906 strcat (pDestination, pNumberFormated);
3907 strcat (pDestination, "-");
3909 case 12: /* format: $ -1.1 */
3910 strcpy (pDestination, sCurrencySymbol);
3911 strcat (pDestination, " ");
3912 strcat (pDestination, "-");
3913 strcat (pDestination, pNumberFormated);
3915 case 13: /* format: 1.1- $ */
3916 strcpy (pDestination, pNumberFormated);
3917 strcat (pDestination, "-");
3918 strcat (pDestination, " ");
3919 strcat (pDestination, sCurrencySymbol);
3921 case 14: /* format: ($ 1.1) */
3922 strcpy (pDestination, "(");
3923 strcat (pDestination, sCurrencySymbol);
3924 strcat (pDestination, " ");
3925 strcat (pDestination, pNumberFormated);
3926 strcat (pDestination, ")");
3928 case 15: /* format: (1.1 $) */
3929 strcpy (pDestination, "(");
3930 strcat (pDestination, pNumberFormated);
3931 strcat (pDestination, " ");
3932 strcat (pDestination, sCurrencySymbol);
3933 strcat (pDestination, ")");
3936 SetLastError(ERROR_INVALID_PARAMETER);
3941 if (cchCurrency == 0)
3942 return strlen(pDestination) + 1;
3946 strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
3947 *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
3948 return strlen(lpCurrencyStr);
3952 /**************************************************************************
3953 * GetCurrencyFormatW (KERNEL32.303)
3955 INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
3956 LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
3957 LPWSTR lpCurrencyStr, int cchCurrency)
3959 FIXME("This API function is NOT implemented !\n");
3963 /******************************************************************************
3964 * OLE2NLS_CheckLocale [intern]
3966 static LCID OLE2NLS_CheckLocale (LCID locale)
3969 { locale = LOCALE_SYSTEM_DEFAULT;
3972 if (locale == LOCALE_SYSTEM_DEFAULT)
3973 { return GetSystemDefaultLCID();
3975 else if (locale == LOCALE_USER_DEFAULT)
3976 { return GetUserDefaultLCID();
3982 /******************************************************************************
3983 * GetTimeFormatA [KERNEL32.422]
3984 * Makes an ASCII string of the time
3986 * Formats date according to format, or locale default if format is
3987 * NULL. The format consists of literal characters and fields as follows:
3989 * h hours with no leading zero (12-hour)
3990 * hh hours with full two digits
3991 * H hours with no leading zero (24-hour)
3992 * HH hours with full two digits
3993 * m minutes with no leading zero
3994 * mm minutes with full two digits
3995 * s seconds with no leading zero
3996 * ss seconds with full two digits
3997 * t time marker (A or P)
3998 * tt time marker (AM, PM)
4002 GetTimeFormatA(LCID locale, /* in */
4003 DWORD flags, /* in */
4004 LPSYSTEMTIME xtime, /* in */
4005 LPCSTR format, /* in */
4006 LPSTR timestr, /* out */
4007 INT timelen /* in */)
4008 { char format_buf[40];
4011 LPSYSTEMTIME thistime;
4013 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4016 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,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 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
4031 thisformat = format_buf;
4034 { thisformat = format;
4037 if (xtime == NULL) /* NULL means use the current local time*/
4044 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
4050 /******************************************************************************
4051 * GetTimeFormatW [KERNEL32.423]
4052 * Makes a Unicode string of the time
4055 GetTimeFormatW(LCID locale, /* in */
4056 DWORD flags, /* in */
4057 LPSYSTEMTIME xtime, /* in */
4058 LPCWSTR format, /* in */
4059 LPWSTR timestr, /* out */
4060 INT timelen /* in */)
4061 { WCHAR format_buf[40];
4064 LPSYSTEMTIME thistime;
4066 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4069 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
4070 xtime,debugstr_w(format),timestr,timelen);
4072 thislocale = OLE2NLS_CheckLocale ( locale );
4074 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
4075 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4078 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
4081 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4082 { thislocale = GetSystemDefaultLCID();
4084 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
4085 thisformat = format_buf;
4088 { thisformat = format;
4091 if (xtime == NULL) /* NULL means use the current local time*/
4092 { GetSystemTime(&t);
4099 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
4104 /******************************************************************************
4105 * EnumCalendarInfoA [KERNEL32.196]
4107 BOOL WINAPI EnumCalendarInfoA(
4108 CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
4110 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);