Fixed some warnings.
[wine.git] / ole / ole2nls.c
blob1205314bcb8db3a66592be97843d8631c463e337
1 /*
2 * National Language Support library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
7 */
9 #include <string.h>
10 #include <stdio.h>
11 #include <ctype.h>
12 #include <stdlib.h>
13 #include <locale.h>
14 #include "windef.h"
15 #include "wingdi.h"
16 #include "winuser.h"
17 #include "wine/unicode.h"
18 #include "heap.h"
19 #include "options.h"
20 #include "winver.h"
21 #include "winnls.h"
22 #include "winreg.h"
23 #include "winerror.h"
24 #include "debugtools.h"
25 #include "main.h"
27 DEFAULT_DEBUG_CHANNEL(string);
29 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
30 * MUST contain all #defines from winnls.h
31 * last entry has NULL name, 0 id.
32 */
33 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
34 static const struct tagLOCALE_NAME2ID {
35 const char *name;
36 LCTYPE id;
37 } locale_name2id[]= {
38 LOCALE_ENTRY(ILANGUAGE),
39 LOCALE_ENTRY(SLANGUAGE),
40 LOCALE_ENTRY(SENGLANGUAGE),
41 LOCALE_ENTRY(SABBREVLANGNAME),
42 LOCALE_ENTRY(SNATIVELANGNAME),
43 LOCALE_ENTRY(ICOUNTRY),
44 LOCALE_ENTRY(SCOUNTRY),
45 LOCALE_ENTRY(SENGCOUNTRY),
46 LOCALE_ENTRY(SABBREVCTRYNAME),
47 LOCALE_ENTRY(SNATIVECTRYNAME),
48 LOCALE_ENTRY(IDEFAULTLANGUAGE),
49 LOCALE_ENTRY(IDEFAULTCOUNTRY),
50 LOCALE_ENTRY(IDEFAULTCODEPAGE),
51 LOCALE_ENTRY(IDEFAULTANSICODEPAGE),
52 LOCALE_ENTRY(IDEFAULTMACCODEPAGE),
53 LOCALE_ENTRY(SLIST),
54 LOCALE_ENTRY(IMEASURE),
55 LOCALE_ENTRY(SDECIMAL),
56 LOCALE_ENTRY(STHOUSAND),
57 LOCALE_ENTRY(SGROUPING),
58 LOCALE_ENTRY(IDIGITS),
59 LOCALE_ENTRY(ILZERO),
60 LOCALE_ENTRY(INEGNUMBER),
61 LOCALE_ENTRY(SNATIVEDIGITS),
62 LOCALE_ENTRY(SCURRENCY),
63 LOCALE_ENTRY(SINTLSYMBOL),
64 LOCALE_ENTRY(SMONDECIMALSEP),
65 LOCALE_ENTRY(SMONTHOUSANDSEP),
66 LOCALE_ENTRY(SMONGROUPING),
67 LOCALE_ENTRY(ICURRDIGITS),
68 LOCALE_ENTRY(IINTLCURRDIGITS),
69 LOCALE_ENTRY(ICURRENCY),
70 LOCALE_ENTRY(INEGCURR),
71 LOCALE_ENTRY(SDATE),
72 LOCALE_ENTRY(STIME),
73 LOCALE_ENTRY(SSHORTDATE),
74 LOCALE_ENTRY(SLONGDATE),
75 LOCALE_ENTRY(STIMEFORMAT),
76 LOCALE_ENTRY(IDATE),
77 LOCALE_ENTRY(ILDATE),
78 LOCALE_ENTRY(ITIME),
79 LOCALE_ENTRY(ITIMEMARKPOSN),
80 LOCALE_ENTRY(ICENTURY),
81 LOCALE_ENTRY(ITLZERO),
82 LOCALE_ENTRY(IDAYLZERO),
83 LOCALE_ENTRY(IMONLZERO),
84 LOCALE_ENTRY(S1159),
85 LOCALE_ENTRY(S2359),
86 LOCALE_ENTRY(ICALENDARTYPE),
87 LOCALE_ENTRY(IOPTIONALCALENDAR),
88 LOCALE_ENTRY(IFIRSTDAYOFWEEK),
89 LOCALE_ENTRY(IFIRSTWEEKOFYEAR),
90 LOCALE_ENTRY(SDAYNAME1),
91 LOCALE_ENTRY(SDAYNAME2),
92 LOCALE_ENTRY(SDAYNAME3),
93 LOCALE_ENTRY(SDAYNAME4),
94 LOCALE_ENTRY(SDAYNAME5),
95 LOCALE_ENTRY(SDAYNAME6),
96 LOCALE_ENTRY(SDAYNAME7),
97 LOCALE_ENTRY(SABBREVDAYNAME1),
98 LOCALE_ENTRY(SABBREVDAYNAME2),
99 LOCALE_ENTRY(SABBREVDAYNAME3),
100 LOCALE_ENTRY(SABBREVDAYNAME4),
101 LOCALE_ENTRY(SABBREVDAYNAME5),
102 LOCALE_ENTRY(SABBREVDAYNAME6),
103 LOCALE_ENTRY(SABBREVDAYNAME7),
104 LOCALE_ENTRY(SMONTHNAME1),
105 LOCALE_ENTRY(SMONTHNAME2),
106 LOCALE_ENTRY(SMONTHNAME3),
107 LOCALE_ENTRY(SMONTHNAME4),
108 LOCALE_ENTRY(SMONTHNAME5),
109 LOCALE_ENTRY(SMONTHNAME6),
110 LOCALE_ENTRY(SMONTHNAME7),
111 LOCALE_ENTRY(SMONTHNAME8),
112 LOCALE_ENTRY(SMONTHNAME9),
113 LOCALE_ENTRY(SMONTHNAME10),
114 LOCALE_ENTRY(SMONTHNAME11),
115 LOCALE_ENTRY(SMONTHNAME12),
116 LOCALE_ENTRY(SMONTHNAME13),
117 LOCALE_ENTRY(SABBREVMONTHNAME1),
118 LOCALE_ENTRY(SABBREVMONTHNAME2),
119 LOCALE_ENTRY(SABBREVMONTHNAME3),
120 LOCALE_ENTRY(SABBREVMONTHNAME4),
121 LOCALE_ENTRY(SABBREVMONTHNAME5),
122 LOCALE_ENTRY(SABBREVMONTHNAME6),
123 LOCALE_ENTRY(SABBREVMONTHNAME7),
124 LOCALE_ENTRY(SABBREVMONTHNAME8),
125 LOCALE_ENTRY(SABBREVMONTHNAME9),
126 LOCALE_ENTRY(SABBREVMONTHNAME10),
127 LOCALE_ENTRY(SABBREVMONTHNAME11),
128 LOCALE_ENTRY(SABBREVMONTHNAME12),
129 LOCALE_ENTRY(SABBREVMONTHNAME13),
130 LOCALE_ENTRY(SPOSITIVESIGN),
131 LOCALE_ENTRY(SNEGATIVESIGN),
132 LOCALE_ENTRY(IPOSSIGNPOSN),
133 LOCALE_ENTRY(INEGSIGNPOSN),
134 LOCALE_ENTRY(IPOSSYMPRECEDES),
135 LOCALE_ENTRY(IPOSSEPBYSPACE),
136 LOCALE_ENTRY(INEGSYMPRECEDES),
137 LOCALE_ENTRY(INEGSEPBYSPACE),
138 LOCALE_ENTRY(FONTSIGNATURE),
139 LOCALE_ENTRY(SISO639LANGNAME),
140 LOCALE_ENTRY(SISO3166CTRYNAME),
141 {NULL,0}
144 static char *GetLocaleSubkeyName( DWORD lctype );
146 /***********************************************************************
147 * GetUserDefaultLCID [KERNEL32.425]
149 LCID WINAPI GetUserDefaultLCID(void)
151 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT );
154 /***********************************************************************
155 * GetSystemDefaultLCID [KERNEL32.400]
157 LCID WINAPI GetSystemDefaultLCID(void)
159 return GetUserDefaultLCID();
162 /***********************************************************************
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;
170 if (userLCID == 0)
172 char buf[256];
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 );
187 lang=buf;
189 do {
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);
197 lang=next;
198 } while (lang && !userLCID);
200 if (!userLCID)
202 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
203 buf );
204 userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
207 return userLCID;
210 /***********************************************************************
211 * GetSystemDefaultLangID [KERNEL32.401]
213 LANGID WINAPI GetSystemDefaultLangID(void)
215 return GetUserDefaultLangID();
218 /******************************************************************************
219 * ConvertDefaultLocale [KERNEL32.147]
221 LCID WINAPI ConvertDefaultLocale (LCID lcid)
222 { switch (lcid)
223 { case LOCALE_SYSTEM_DEFAULT:
224 return GetSystemDefaultLCID();
225 case LOCALE_USER_DEFAULT:
226 return GetUserDefaultLCID();
227 case LOCALE_NEUTRAL:
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)
241 HRSRC hrsrc;
242 HGLOBAL hmem;
243 WCHAR *p;
244 int string_num;
245 int i;
247 hrsrc = FindResourceExW(hModule, RT_STRINGW, (LPCWSTR)((res_id >> 4) + 1), lang_id);
249 if(!hrsrc) return 0;
250 hmem = LoadResource(hModule, hrsrc);
251 if(!hmem) return 0;
253 p = LockResource(hmem);
254 string_num = res_id & 0x000f;
255 for(i = 0; i < string_num; i++)
256 p += *p + 1;
258 TRACE("strlen = %d\n", (int)*p );
260 if (buffer == NULL) return *p;
261 i = min(buflen - 1, *p);
262 if (i > 0) {
263 memcpy(buffer, p + 1, i * sizeof (WCHAR));
264 buffer[i] = (WCHAR) 0;
265 } else {
266 if (buflen > 1)
267 buffer[0] = (WCHAR) 0;
270 FreeResource(hmem);
271 TRACE("\"%s\" loaded!\n", debugstr_w(buffer));
272 return (i + 1);
275 /******************************************************************************
276 * GetLocaleInfoA [KERNEL32.342]
278 * NOTES
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;
288 int found = 0, i;
289 char *pacKey;
290 char acBuffer[128];
291 DWORD dwBufferSize=128;
293 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid,LCType,buf,len);
295 if (len && (! buf) ) {
296 SetLastError(ERROR_INSUFFICIENT_BUFFER);
297 return 0;
300 if (lcid == LOCALE_NEUTRAL || lcid == LANG_SYSTEM_DEFAULT || (LCType & LOCALE_NOUSEROVERRIDE) )
302 lcid = GetSystemDefaultLCID();
304 else if (lcid == LANG_USER_DEFAULT) /*0x800*/
306 lcid = GetUserDefaultLCID();
308 LCType &= ~(LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP);
310 /* First, check if it's in the registry. */
311 /* All user customized values are stored in the registry by SetLocaleInfo */
313 if ( (pacKey = GetLocaleSubkeyName(LCType)) )
315 char acRealKey[128];
316 HKEY hKey;
318 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
320 if ( RegOpenKeyExA( HKEY_CURRENT_USER, acRealKey,
321 0, KEY_READ, &hKey) == ERROR_SUCCESS )
323 if ( RegQueryValueExA( hKey, NULL, NULL, NULL, (LPBYTE)acBuffer,
324 &dwBufferSize ) == ERROR_SUCCESS )
326 retString = acBuffer;
327 found = 1;
329 RegCloseKey(hKey);
333 /* If not in the registry, get it from the NLS entries. */
334 if(!found) {
335 WCHAR wcBuffer[128];
336 int res_size;
338 /* check if language is registered in the kernel32 resources */
339 if((res_size = NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LOWORD(lcid),
340 LCType, wcBuffer, sizeof(wcBuffer)/sizeof(wcBuffer[0])))) {
341 WideCharToMultiByte(CP_ACP, 0, wcBuffer, res_size, acBuffer, dwBufferSize, NULL, NULL);
342 retString = acBuffer;
343 found = 1;
347 /* if not found report a most descriptive error */
348 if(!found) {
349 retString=0;
350 /* If we are through all of this, retLen should not be zero anymore.
351 If it is, the value is not supported */
352 i=0;
353 while (locale_name2id[i].name!=NULL) {
354 if (LCType == locale_name2id[i].id) {
355 retString = locale_name2id[i].name;
356 break;
358 i++;
360 if(!retString)
361 FIXME("Unkown LC type %lX\n", LCType);
362 else
363 ERR("'%s' not supported for your language (%04X)\n",
364 retString, LOWORD(lcid));
365 SetLastError(ERROR_INVALID_PARAMETER);
366 return 0;
369 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
370 if (LCType == LOCALE_FONTSIGNATURE) {
371 if (len) {
372 len = (len < sizeof(FONTSIGNATURE)) ? len : sizeof(FONTSIGNATURE);
373 memcpy(buf, retString, len);
374 return len;
376 return sizeof(FONTSIGNATURE);
378 /* if len=0 return only the length, don't touch the buffer*/
379 if (len) {
380 lstrcpynA(buf,retString,len);
381 return strlen(buf) + 1;
383 return strlen(retString)+1;
386 /******************************************************************************
387 * GetLocaleInfoW [KERNEL32.343]
389 * NOTES
390 * MS documentation states that len "specifies the size, in bytes (ANSI version)
391 * or characters (Unicode version), of" wbuf. Thus the number returned is
392 * the same between GetLocaleInfoW and GetLocaleInfoA.
394 INT WINAPI GetLocaleInfoW(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT len)
395 { WORD wlen;
396 LPSTR abuf;
398 if (len && (! wbuf) )
399 { SetLastError(ERROR_INSUFFICIENT_BUFFER);
400 return 0;
403 abuf = (LPSTR)HeapAlloc(GetProcessHeap(),0,len);
404 wlen = GetLocaleInfoA(lcid, LCType, abuf, len);
406 if (wlen && len) /* if len=0 return only the length*/
407 lstrcpynAtoW(wbuf,abuf,len);
409 HeapFree(GetProcessHeap(),0,abuf);
410 return wlen;
413 /******************************************************************************
415 * GetLocaleSubkeyName [helper function]
417 * - For use with the registry.
418 * - Gets the registry subkey name for a given lctype.
420 static char *GetLocaleSubkeyName( DWORD lctype )
422 char *pacKey=NULL;
424 switch ( lctype )
426 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
427 * the values are stored in the registry, confirmed under Windows,
428 * for the ones that actually assign pacKey. Cases that aren't finished
429 * have not been confirmed, so that must be done before they can be
430 * added.
432 case LOCALE_SDATE : /* The date separator. */
433 pacKey = "sDate";
434 break;
435 case LOCALE_ICURRDIGITS:
436 pacKey = "iCurrDigits";
437 break;
438 case LOCALE_SDECIMAL :
439 pacKey = "sDecimal";
440 break;
441 case LOCALE_ICURRENCY:
442 pacKey = "iCurrency";
443 break;
444 case LOCALE_SGROUPING :
445 pacKey = "sGrouping";
446 break;
447 case LOCALE_IDIGITS:
448 pacKey = "iDigits";
449 break;
450 case LOCALE_SLIST :
451 pacKey = "sList";
452 break;
453 /* case LOCALE_ICALENDARTYPE: */
454 /* case LOCALE_IFIRSTDAYOFWEEK: */
455 /* case LOCALE_IFIRSTWEEKOFYEAR: */
456 /* case LOCALE_SYEARMONTH : */
457 /* case LOCALE_SPOSITIVESIGN : */
458 /* case LOCALE_IPAPERSIZE: */
459 /* break; */
460 case LOCALE_SLONGDATE :
461 pacKey = "sLongDate";
462 break;
463 case LOCALE_SMONDECIMALSEP :
464 pacKey = "sMonDecimalSep";
465 break;
466 case LOCALE_SMONGROUPING:
467 pacKey = "sMonGrouping";
468 break;
469 case LOCALE_IMEASURE:
470 pacKey = "iMeasure";
471 break;
472 case LOCALE_SMONTHOUSANDSEP :
473 pacKey = "sMonThousandSep";
474 break;
475 case LOCALE_INEGCURR:
476 pacKey = "iNegCurr";
477 break;
478 case LOCALE_SNEGATIVESIGN :
479 pacKey = "sNegativeSign";
480 break;
481 case LOCALE_INEGNUMBER:
482 pacKey = "iNegNumber";
483 break;
484 case LOCALE_SSHORTDATE :
485 pacKey = "sShortDate";
486 break;
487 case LOCALE_ILDATE: /* Long Date format ordering specifier. */
488 pacKey = "iLDate";
489 break;
490 case LOCALE_ILZERO:
491 pacKey = "iLZero";
492 break;
493 case LOCALE_ITLZERO:
494 pacKey = "iTLZero";
495 break;
496 case LOCALE_ITIME: /* Time format specifier. */
497 pacKey = "iTime";
498 break;
499 case LOCALE_STHOUSAND :
500 pacKey = "sThousand";
501 break;
502 case LOCALE_S1159: /* AM */
503 pacKey = "s1159";
504 break;
505 case LOCALE_STIME:
506 pacKey = "sTime";
507 break;
508 case LOCALE_S2359: /* PM */
509 pacKey = "s2359";
510 break;
511 case LOCALE_STIMEFORMAT :
512 pacKey = "sTimeFormat";
513 break;
514 case LOCALE_SCURRENCY:
515 pacKey = "sCurrency";
516 break;
518 /* The following are not listed under MSDN as supported,
519 * but seem to be used and also stored in the registry.
522 case LOCALE_IDATE:
523 pacKey = "iDate";
524 break;
525 case LOCALE_SCOUNTRY:
526 pacKey = "sCountry";
527 break;
528 case LOCALE_ICOUNTRY:
529 pacKey = "iCountry";
530 break;
531 case LOCALE_SLANGUAGE:
532 pacKey = "sLanguage";
533 break;
535 default:
536 break;
539 return( pacKey );
542 /******************************************************************************
543 * SetLocaleInfoA [KERNEL32.656]
545 BOOL16 WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
547 HKEY hKey;
548 char *pacKey;
549 char acRealKey[128];
551 if ( (pacKey = GetLocaleSubkeyName(lctype)) )
553 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
554 if ( RegCreateKeyA( HKEY_CURRENT_USER, acRealKey,
555 &hKey ) == ERROR_SUCCESS )
557 if ( RegSetValueExA( hKey, NULL, 0, REG_SZ,
558 data, strlen(data)+1 ) != ERROR_SUCCESS )
560 ERR("SetLocaleInfoA: %s did not work\n", pacKey );
562 RegCloseKey( hKey );
565 else
567 FIXME("(%ld,%ld,%s): stub\n",lcid,lctype,data);
569 return TRUE;
572 /******************************************************************************
573 * IsValidLocale [KERNEL32.489]
575 BOOL WINAPI IsValidLocale(LCID lcid,DWORD flags)
577 /* check if language is registered in the kernel32 resources */
578 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW, (LPCWSTR)LOCALE_ILANGUAGE, LOWORD(lcid)))
579 return FALSE;
580 else
581 return TRUE;
584 static BOOL CALLBACK EnumResourceLanguagesProcW(HMODULE hModule, LPCWSTR type,
585 LPCWSTR name, WORD LangID, LONG lParam)
587 CHAR bufA[20];
588 WCHAR bufW[20];
589 LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
590 sprintf(bufA, "%08X", (UINT)LangID);
591 MultiByteToWideChar(CP_ACP, 0, bufA, -1, bufW, sizeof(bufW)/sizeof(bufW[0]));
592 return lpfnLocaleEnum(bufW);
595 /******************************************************************************
596 * EnumSystemLocalesW [KERNEL32.209]
598 BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum,
599 DWORD flags )
601 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
603 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW,
604 (LPCWSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcW,
605 (LONG)lpfnLocaleEnum);
607 return TRUE;
610 static BOOL CALLBACK EnumResourceLanguagesProcA(HMODULE hModule, LPCSTR type,
611 LPCSTR name, WORD LangID, LONG lParam)
613 CHAR bufA[20];
614 LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
615 sprintf(bufA, "%08X", (UINT)LangID);
616 return lpfnLocaleEnum(bufA);
619 /******************************************************************************
620 * EnumSystemLocalesA [KERNEL32.208]
622 BOOL WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum,
623 DWORD flags)
625 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
627 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
628 (LPCSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcA,
629 (LONG)lpfnLocaleEnum);
631 return TRUE;
634 static const unsigned char CT_CType2_LUT[] = {
635 C2_NOTAPPLICABLE, /* - 0 */
636 C2_NOTAPPLICABLE, /* - 1 */
637 C2_NOTAPPLICABLE, /* - 2 */
638 C2_NOTAPPLICABLE, /* - 3 */
639 C2_NOTAPPLICABLE, /* - 4 */
640 C2_NOTAPPLICABLE, /* - 5 */
641 C2_NOTAPPLICABLE, /* - 6 */
642 C2_NOTAPPLICABLE, /* - 7 */
643 C2_NOTAPPLICABLE, /* - 8 */
644 C2_SEGMENTSEPARATOR, /* - 9 */
645 C2_NOTAPPLICABLE, /* - 10 */
646 C2_NOTAPPLICABLE, /* - 11 */
647 C2_NOTAPPLICABLE, /* - 12 */
648 C2_NOTAPPLICABLE, /* - 13 */
649 C2_NOTAPPLICABLE, /* - 14 */
650 C2_NOTAPPLICABLE, /* - 15 */
651 C2_NOTAPPLICABLE, /* - 16 */
652 C2_NOTAPPLICABLE, /* - 17 */
653 C2_NOTAPPLICABLE, /* - 18 */
654 C2_NOTAPPLICABLE, /* - 19 */
655 C2_NOTAPPLICABLE, /* - 20 */
656 C2_NOTAPPLICABLE, /* - 21 */
657 C2_NOTAPPLICABLE, /* - 22 */
658 C2_NOTAPPLICABLE, /* - 23 */
659 C2_NOTAPPLICABLE, /* - 24 */
660 C2_NOTAPPLICABLE, /* - 25 */
661 C2_NOTAPPLICABLE, /* - 26 */
662 C2_NOTAPPLICABLE, /* - 27 */
663 C2_NOTAPPLICABLE, /* - 28 */
664 C2_NOTAPPLICABLE, /* - 29 */
665 C2_NOTAPPLICABLE, /* - 30 */
666 C2_NOTAPPLICABLE, /* - 31 */
667 C2_WHITESPACE, /* - 32 */
668 C2_OTHERNEUTRAL, /* ! - 33 */
669 C2_OTHERNEUTRAL, /* " - 34 */ /* " */
670 C2_EUROPETERMINATOR, /* # - 35 */
671 C2_EUROPETERMINATOR, /* $ - 36 */
672 C2_EUROPETERMINATOR, /* % - 37 */
673 C2_LEFTTORIGHT, /* & - 38 */
674 C2_OTHERNEUTRAL, /* ' - 39 */
675 C2_OTHERNEUTRAL, /* ( - 40 */
676 C2_OTHERNEUTRAL, /* ) - 41 */
677 C2_OTHERNEUTRAL, /* * - 42 */
678 C2_EUROPETERMINATOR, /* + - 43 */
679 C2_COMMONSEPARATOR, /* , - 44 */
680 C2_EUROPETERMINATOR, /* - - 45 */
681 C2_EUROPESEPARATOR, /* . - 46 */
682 C2_EUROPESEPARATOR, /* / - 47 */
683 C2_EUROPENUMBER, /* 0 - 48 */
684 C2_EUROPENUMBER, /* 1 - 49 */
685 C2_EUROPENUMBER, /* 2 - 50 */
686 C2_EUROPENUMBER, /* 3 - 51 */
687 C2_EUROPENUMBER, /* 4 - 52 */
688 C2_EUROPENUMBER, /* 5 - 53 */
689 C2_EUROPENUMBER, /* 6 - 54 */
690 C2_EUROPENUMBER, /* 7 - 55 */
691 C2_EUROPENUMBER, /* 8 - 56 */
692 C2_EUROPENUMBER, /* 9 - 57 */
693 C2_COMMONSEPARATOR, /* : - 58 */
694 C2_OTHERNEUTRAL, /* ; - 59 */
695 C2_OTHERNEUTRAL, /* < - 60 */
696 C2_OTHERNEUTRAL, /* = - 61 */
697 C2_OTHERNEUTRAL, /* > - 62 */
698 C2_OTHERNEUTRAL, /* ? - 63 */
699 C2_LEFTTORIGHT, /* @ - 64 */
700 C2_LEFTTORIGHT, /* A - 65 */
701 C2_LEFTTORIGHT, /* B - 66 */
702 C2_LEFTTORIGHT, /* C - 67 */
703 C2_LEFTTORIGHT, /* D - 68 */
704 C2_LEFTTORIGHT, /* E - 69 */
705 C2_LEFTTORIGHT, /* F - 70 */
706 C2_LEFTTORIGHT, /* G - 71 */
707 C2_LEFTTORIGHT, /* H - 72 */
708 C2_LEFTTORIGHT, /* I - 73 */
709 C2_LEFTTORIGHT, /* J - 74 */
710 C2_LEFTTORIGHT, /* K - 75 */
711 C2_LEFTTORIGHT, /* L - 76 */
712 C2_LEFTTORIGHT, /* M - 77 */
713 C2_LEFTTORIGHT, /* N - 78 */
714 C2_LEFTTORIGHT, /* O - 79 */
715 C2_LEFTTORIGHT, /* P - 80 */
716 C2_LEFTTORIGHT, /* Q - 81 */
717 C2_LEFTTORIGHT, /* R - 82 */
718 C2_LEFTTORIGHT, /* S - 83 */
719 C2_LEFTTORIGHT, /* T - 84 */
720 C2_LEFTTORIGHT, /* U - 85 */
721 C2_LEFTTORIGHT, /* V - 86 */
722 C2_LEFTTORIGHT, /* W - 87 */
723 C2_LEFTTORIGHT, /* X - 88 */
724 C2_LEFTTORIGHT, /* Y - 89 */
725 C2_LEFTTORIGHT, /* Z - 90 */
726 C2_OTHERNEUTRAL, /* [ - 91 */
727 C2_OTHERNEUTRAL, /* \ - 92 */
728 C2_OTHERNEUTRAL, /* ] - 93 */
729 C2_OTHERNEUTRAL, /* ^ - 94 */
730 C2_OTHERNEUTRAL, /* _ - 95 */
731 C2_OTHERNEUTRAL, /* ` - 96 */
732 C2_LEFTTORIGHT, /* a - 97 */
733 C2_LEFTTORIGHT, /* b - 98 */
734 C2_LEFTTORIGHT, /* c - 99 */
735 C2_LEFTTORIGHT, /* d - 100 */
736 C2_LEFTTORIGHT, /* e - 101 */
737 C2_LEFTTORIGHT, /* f - 102 */
738 C2_LEFTTORIGHT, /* g - 103 */
739 C2_LEFTTORIGHT, /* h - 104 */
740 C2_LEFTTORIGHT, /* i - 105 */
741 C2_LEFTTORIGHT, /* j - 106 */
742 C2_LEFTTORIGHT, /* k - 107 */
743 C2_LEFTTORIGHT, /* l - 108 */
744 C2_LEFTTORIGHT, /* m - 109 */
745 C2_LEFTTORIGHT, /* n - 110 */
746 C2_LEFTTORIGHT, /* o - 111 */
747 C2_LEFTTORIGHT, /* p - 112 */
748 C2_LEFTTORIGHT, /* q - 113 */
749 C2_LEFTTORIGHT, /* r - 114 */
750 C2_LEFTTORIGHT, /* s - 115 */
751 C2_LEFTTORIGHT, /* t - 116 */
752 C2_LEFTTORIGHT, /* u - 117 */
753 C2_LEFTTORIGHT, /* v - 118 */
754 C2_LEFTTORIGHT, /* w - 119 */
755 C2_LEFTTORIGHT, /* x - 120 */
756 C2_LEFTTORIGHT, /* y - 121 */
757 C2_LEFTTORIGHT, /* z - 122 */
758 C2_OTHERNEUTRAL, /* { - 123 */
759 C2_OTHERNEUTRAL, /* | - 124 */
760 C2_OTHERNEUTRAL, /* } - 125 */
761 C2_OTHERNEUTRAL, /* ~ - 126 */
762 C2_NOTAPPLICABLE, /* \x7f - 127 */
763 C2_NOTAPPLICABLE, /* € - 128 */
764 C2_NOTAPPLICABLE, /* � - 129 */
765 C2_OTHERNEUTRAL, /* ‚ - 130 */
766 C2_LEFTTORIGHT, /* ƒ - 131 */
767 C2_OTHERNEUTRAL, /* „ - 132 */
768 C2_OTHERNEUTRAL, /* … - 133 */
769 C2_OTHERNEUTRAL, /* † - 134 */
770 C2_OTHERNEUTRAL, /* ‡ - 135 */
771 C2_LEFTTORIGHT, /* ˆ - 136 */
772 C2_EUROPETERMINATOR, /* ‰ - 137 */
773 C2_LEFTTORIGHT, /* Š - 138 */
774 C2_OTHERNEUTRAL, /* ‹ - 139 */
775 C2_LEFTTORIGHT, /* Π- 140 */
776 C2_NOTAPPLICABLE, /* � - 141 */
777 C2_NOTAPPLICABLE, /* Ž - 142 */
778 C2_NOTAPPLICABLE, /* � - 143 */
779 C2_NOTAPPLICABLE, /* � - 144 */
780 C2_OTHERNEUTRAL, /* ‘ - 145 */
781 C2_OTHERNEUTRAL, /* ’ - 146 */
782 C2_OTHERNEUTRAL, /* “ - 147 */
783 C2_OTHERNEUTRAL, /* ” - 148 */
784 C2_OTHERNEUTRAL, /* • - 149 */
785 C2_OTHERNEUTRAL, /* – - 150 */
786 C2_OTHERNEUTRAL, /* — - 151 */
787 C2_LEFTTORIGHT, /* ˜ - 152 */
788 C2_OTHERNEUTRAL, /* ™ - 153 */
789 C2_LEFTTORIGHT, /* š - 154 */
790 C2_OTHERNEUTRAL, /* › - 155 */
791 C2_LEFTTORIGHT, /* œ - 156 */
792 C2_NOTAPPLICABLE, /* � - 157 */
793 C2_NOTAPPLICABLE, /* ž - 158 */
794 C2_LEFTTORIGHT, /* Ÿ - 159 */
795 C2_WHITESPACE, /*   - 160 */
796 C2_OTHERNEUTRAL, /* ¡ - 161 */
797 C2_EUROPETERMINATOR, /* ¢ - 162 */
798 C2_EUROPETERMINATOR, /* £ - 163 */
799 C2_EUROPETERMINATOR, /* ¤ - 164 */
800 C2_EUROPETERMINATOR, /* ¥ - 165 */
801 C2_OTHERNEUTRAL, /* ¦ - 166 */
802 C2_OTHERNEUTRAL, /* § - 167 */
803 C2_OTHERNEUTRAL, /* ¨ - 168 */
804 C2_OTHERNEUTRAL, /* © - 169 */
805 C2_OTHERNEUTRAL, /* ª - 170 */
806 C2_OTHERNEUTRAL, /* « - 171 */
807 C2_OTHERNEUTRAL, /* ¬ - 172 */
808 C2_OTHERNEUTRAL, /* ­ - 173 */
809 C2_OTHERNEUTRAL, /* ® - 174 */
810 C2_OTHERNEUTRAL, /* ¯ - 175 */
811 C2_EUROPETERMINATOR, /* ° - 176 */
812 C2_EUROPETERMINATOR, /* ± - 177 */
813 C2_EUROPENUMBER, /* ² - 178 */
814 C2_EUROPENUMBER, /* ³ - 179 */
815 C2_OTHERNEUTRAL, /* ´ - 180 */
816 C2_OTHERNEUTRAL, /* µ - 181 */
817 C2_OTHERNEUTRAL, /* ¶ - 182 */
818 C2_OTHERNEUTRAL, /* · - 183 */
819 C2_OTHERNEUTRAL, /* ¸ - 184 */
820 C2_EUROPENUMBER, /* ¹ - 185 */
821 C2_OTHERNEUTRAL, /* º - 186 */
822 C2_OTHERNEUTRAL, /* » - 187 */
823 C2_OTHERNEUTRAL, /* ¼ - 188 */
824 C2_OTHERNEUTRAL, /* ½ - 189 */
825 C2_OTHERNEUTRAL, /* ¾ - 190 */
826 C2_OTHERNEUTRAL, /* ¿ - 191 */
827 C2_LEFTTORIGHT, /* À - 192 */
828 C2_LEFTTORIGHT, /* Á - 193 */
829 C2_LEFTTORIGHT, /* Â - 194 */
830 C2_LEFTTORIGHT, /* Ã - 195 */
831 C2_LEFTTORIGHT, /* Ä - 196 */
832 C2_LEFTTORIGHT, /* Å - 197 */
833 C2_LEFTTORIGHT, /* Æ - 198 */
834 C2_LEFTTORIGHT, /* Ç - 199 */
835 C2_LEFTTORIGHT, /* È - 200 */
836 C2_LEFTTORIGHT, /* É - 201 */
837 C2_LEFTTORIGHT, /* Ê - 202 */
838 C2_LEFTTORIGHT, /* Ë - 203 */
839 C2_LEFTTORIGHT, /* Ì - 204 */
840 C2_LEFTTORIGHT, /* Í - 205 */
841 C2_LEFTTORIGHT, /* Î - 206 */
842 C2_LEFTTORIGHT, /* Ï - 207 */
843 C2_LEFTTORIGHT, /* Ð - 208 */
844 C2_LEFTTORIGHT, /* Ñ - 209 */
845 C2_LEFTTORIGHT, /* Ò - 210 */
846 C2_LEFTTORIGHT, /* Ó - 211 */
847 C2_LEFTTORIGHT, /* Ô - 212 */
848 C2_LEFTTORIGHT, /* Õ - 213 */
849 C2_LEFTTORIGHT, /* Ö - 214 */
850 C2_OTHERNEUTRAL, /* × - 215 */
851 C2_LEFTTORIGHT, /* Ø - 216 */
852 C2_LEFTTORIGHT, /* Ù - 217 */
853 C2_LEFTTORIGHT, /* Ú - 218 */
854 C2_LEFTTORIGHT, /* Û - 219 */
855 C2_LEFTTORIGHT, /* Ü - 220 */
856 C2_LEFTTORIGHT, /* Ý - 221 */
857 C2_LEFTTORIGHT, /* Þ - 222 */
858 C2_LEFTTORIGHT, /* ß - 223 */
859 C2_LEFTTORIGHT, /* à - 224 */
860 C2_LEFTTORIGHT, /* á - 225 */
861 C2_LEFTTORIGHT, /* â - 226 */
862 C2_LEFTTORIGHT, /* ã - 227 */
863 C2_LEFTTORIGHT, /* ä - 228 */
864 C2_LEFTTORIGHT, /* å - 229 */
865 C2_LEFTTORIGHT, /* æ - 230 */
866 C2_LEFTTORIGHT, /* ç - 231 */
867 C2_LEFTTORIGHT, /* è - 232 */
868 C2_LEFTTORIGHT, /* é - 233 */
869 C2_LEFTTORIGHT, /* ê - 234 */
870 C2_LEFTTORIGHT, /* ë - 235 */
871 C2_LEFTTORIGHT, /* ì - 236 */
872 C2_LEFTTORIGHT, /* í - 237 */
873 C2_LEFTTORIGHT, /* î - 238 */
874 C2_LEFTTORIGHT, /* ï - 239 */
875 C2_LEFTTORIGHT, /* ð - 240 */
876 C2_LEFTTORIGHT, /* ñ - 241 */
877 C2_LEFTTORIGHT, /* ò - 242 */
878 C2_LEFTTORIGHT, /* ó - 243 */
879 C2_LEFTTORIGHT, /* ô - 244 */
880 C2_LEFTTORIGHT, /* õ - 245 */
881 C2_LEFTTORIGHT, /* ö - 246 */
882 C2_OTHERNEUTRAL, /* ÷ - 247 */
883 C2_LEFTTORIGHT, /* ø - 248 */
884 C2_LEFTTORIGHT, /* ù - 249 */
885 C2_LEFTTORIGHT, /* ú - 250 */
886 C2_LEFTTORIGHT, /* û - 251 */
887 C2_LEFTTORIGHT, /* ü - 252 */
888 C2_LEFTTORIGHT, /* ý - 253 */
889 C2_LEFTTORIGHT, /* þ - 254 */
890 C2_LEFTTORIGHT /* ÿ - 255 */
893 const WORD OLE2NLS_CT_CType3_LUT[] = {
894 0x0000, /* - 0 */
895 0x0000, /* - 1 */
896 0x0000, /* - 2 */
897 0x0000, /* - 3 */
898 0x0000, /* - 4 */
899 0x0000, /* - 5 */
900 0x0000, /* - 6 */
901 0x0000, /* - 7 */
902 0x0000, /* - 8 */
903 0x0008, /* - 9 */
904 0x0008, /* - 10 */
905 0x0008, /* - 11 */
906 0x0008, /* - 12 */
907 0x0008, /* - 13 */
908 0x0000, /* - 14 */
909 0x0000, /* - 15 */
910 0x0000, /* - 16 */
911 0x0000, /* - 17 */
912 0x0000, /* - 18 */
913 0x0000, /* - 19 */
914 0x0000, /* - 20 */
915 0x0000, /* - 21 */
916 0x0000, /* - 22 */
917 0x0000, /* - 23 */
918 0x0000, /* - 24 */
919 0x0000, /* - 25 */
920 0x0000, /* - 26 */
921 0x0000, /* - 27 */
922 0x0000, /* - 28 */
923 0x0000, /* - 29 */
924 0x0000, /* - 30 */
925 0x0000, /* - 31 */
926 0x0048, /* - 32 */
927 0x0048, /* ! - 33 */
928 0x0448, /* " - 34 */ /* " */
929 0x0048, /* # - 35 */
930 0x0448, /* $ - 36 */
931 0x0048, /* % - 37 */
932 0x0048, /* & - 38 */
933 0x0440, /* ' - 39 */
934 0x0048, /* ( - 40 */
935 0x0048, /* ) - 41 */
936 0x0048, /* * - 42 */
937 0x0048, /* + - 43 */
938 0x0048, /* , - 44 */
939 0x0440, /* - - 45 */
940 0x0048, /* . - 46 */
941 0x0448, /* / - 47 */
942 0x0040, /* 0 - 48 */
943 0x0040, /* 1 - 49 */
944 0x0040, /* 2 - 50 */
945 0x0040, /* 3 - 51 */
946 0x0040, /* 4 - 52 */
947 0x0040, /* 5 - 53 */
948 0x0040, /* 6 - 54 */
949 0x0040, /* 7 - 55 */
950 0x0040, /* 8 - 56 */
951 0x0040, /* 9 - 57 */
952 0x0048, /* : - 58 */
953 0x0048, /* ; - 59 */
954 0x0048, /* < - 60 */
955 0x0448, /* = - 61 */
956 0x0048, /* > - 62 */
957 0x0048, /* ? - 63 */
958 0x0448, /* @ - 64 */
959 0x8040, /* A - 65 */
960 0x8040, /* B - 66 */
961 0x8040, /* C - 67 */
962 0x8040, /* D - 68 */
963 0x8040, /* E - 69 */
964 0x8040, /* F - 70 */
965 0x8040, /* G - 71 */
966 0x8040, /* H - 72 */
967 0x8040, /* I - 73 */
968 0x8040, /* J - 74 */
969 0x8040, /* K - 75 */
970 0x8040, /* L - 76 */
971 0x8040, /* M - 77 */
972 0x8040, /* N - 78 */
973 0x8040, /* O - 79 */
974 0x8040, /* P - 80 */
975 0x8040, /* Q - 81 */
976 0x8040, /* R - 82 */
977 0x8040, /* S - 83 */
978 0x8040, /* T - 84 */
979 0x8040, /* U - 85 */
980 0x8040, /* V - 86 */
981 0x8040, /* W - 87 */
982 0x8040, /* X - 88 */
983 0x8040, /* Y - 89 */
984 0x8040, /* Z - 90 */
985 0x0048, /* [ - 91 */
986 0x0448, /* \ - 92 */
987 0x0048, /* ] - 93 */
988 0x0448, /* ^ - 94 */
989 0x0448, /* _ - 95 */
990 0x0448, /* ` - 96 */
991 0x8040, /* a - 97 */
992 0x8040, /* b - 98 */
993 0x8040, /* c - 99 */
994 0x8040, /* d - 100 */
995 0x8040, /* e - 101 */
996 0x8040, /* f - 102 */
997 0x8040, /* g - 103 */
998 0x8040, /* h - 104 */
999 0x8040, /* i - 105 */
1000 0x8040, /* j - 106 */
1001 0x8040, /* k - 107 */
1002 0x8040, /* l - 108 */
1003 0x8040, /* m - 109 */
1004 0x8040, /* n - 110 */
1005 0x8040, /* o - 111 */
1006 0x8040, /* p - 112 */
1007 0x8040, /* q - 113 */
1008 0x8040, /* r - 114 */
1009 0x8040, /* s - 115 */
1010 0x8040, /* t - 116 */
1011 0x8040, /* u - 117 */
1012 0x8040, /* v - 118 */
1013 0x8040, /* w - 119 */
1014 0x8040, /* x - 120 */
1015 0x8040, /* y - 121 */
1016 0x8040, /* z - 122 */
1017 0x0048, /* { - 123 */
1018 0x0048, /* | - 124 */
1019 0x0048, /* } - 125 */
1020 0x0448, /* ~ - 126 */
1021 0x0000, /* \x7f - 127 */
1022 0x0000, /* € - 128 */
1023 0x0000, /* � - 129 */
1024 0x0008, /* ‚ - 130 */
1025 0x8000, /* ƒ - 131 */
1026 0x0008, /* „ - 132 */
1027 0x0008, /* … - 133 */
1028 0x0008, /* † - 134 */
1029 0x0008, /* ‡ - 135 */
1030 0x0001, /* ˆ - 136 */
1031 0x0008, /* ‰ - 137 */
1032 0x8003, /* Š - 138 */
1033 0x0008, /* ‹ - 139 */
1034 0x8000, /* Π- 140 */
1035 0x0000, /* � - 141 */
1036 0x0000, /* Ž - 142 */
1037 0x0000, /* � - 143 */
1038 0x0000, /* � - 144 */
1039 0x0088, /* ‘ - 145 */
1040 0x0088, /* ’ - 146 */
1041 0x0088, /* “ - 147 */
1042 0x0088, /* ” - 148 */
1043 0x0008, /* • - 149 */
1044 0x0400, /* – - 150 */
1045 0x0400, /* — - 151 */
1046 0x0408, /* ˜ - 152 */
1047 0x0000, /* ™ - 153 */
1048 0x8003, /* š - 154 */
1049 0x0008, /* › - 155 */
1050 0x8000, /* œ - 156 */
1051 0x0000, /* � - 157 */
1052 0x0000, /* ž - 158 */
1053 0x8003, /* Ÿ - 159 */
1054 0x0008, /*   - 160 */
1055 0x0008, /* ¡ - 161 */
1056 0x0048, /* ¢ - 162 */
1057 0x0048, /* £ - 163 */
1058 0x0008, /* ¤ - 164 */
1059 0x0048, /* ¥ - 165 */
1060 0x0048, /* ¦ - 166 */
1061 0x0008, /* § - 167 */
1062 0x0408, /* ¨ - 168 */
1063 0x0008, /* © - 169 */
1064 0x0400, /* ª - 170 */
1065 0x0008, /* « - 171 */
1066 0x0048, /* ¬ - 172 */
1067 0x0408, /* ­ - 173 */
1068 0x0008, /* ® - 174 */
1069 0x0448, /* ¯ - 175 */
1070 0x0008, /* ° - 176 */
1071 0x0008, /* ± - 177 */
1072 0x0000, /* ² - 178 */
1073 0x0000, /* ³ - 179 */
1074 0x0408, /* ´ - 180 */
1075 0x0008, /* µ - 181 */
1076 0x0008, /* ¶ - 182 */
1077 0x0008, /* · - 183 */
1078 0x0408, /* ¸ - 184 */
1079 0x0000, /* ¹ - 185 */
1080 0x0400, /* º - 186 */
1081 0x0008, /* » - 187 */
1082 0x0000, /* ¼ - 188 */
1083 0x0000, /* ½ - 189 */
1084 0x0000, /* ¾ - 190 */
1085 0x0008, /* ¿ - 191 */
1086 0x8003, /* À - 192 */
1087 0x8003, /* Á - 193 */
1088 0x8003, /* Â - 194 */
1089 0x8003, /* Ã - 195 */
1090 0x8003, /* Ä - 196 */
1091 0x8003, /* Å - 197 */
1092 0x8000, /* Æ - 198 */
1093 0x8003, /* Ç - 199 */
1094 0x8003, /* È - 200 */
1095 0x8003, /* É - 201 */
1096 0x8003, /* Ê - 202 */
1097 0x8003, /* Ë - 203 */
1098 0x8003, /* Ì - 204 */
1099 0x8003, /* Í - 205 */
1100 0x8003, /* Î - 206 */
1101 0x8003, /* Ï - 207 */
1102 0x8000, /* Ð - 208 */
1103 0x8003, /* Ñ - 209 */
1104 0x8003, /* Ò - 210 */
1105 0x8003, /* Ó - 211 */
1106 0x8003, /* Ô - 212 */
1107 0x8003, /* Õ - 213 */
1108 0x8003, /* Ö - 214 */
1109 0x0008, /* × - 215 */
1110 0x8003, /* Ø - 216 */
1111 0x8003, /* Ù - 217 */
1112 0x8003, /* Ú - 218 */
1113 0x8003, /* Û - 219 */
1114 0x8003, /* Ü - 220 */
1115 0x8003, /* Ý - 221 */
1116 0x8000, /* Þ - 222 */
1117 0x8000, /* ß - 223 */
1118 0x8003, /* à - 224 */
1119 0x8003, /* á - 225 */
1120 0x8003, /* â - 226 */
1121 0x8003, /* ã - 227 */
1122 0x8003, /* ä - 228 */
1123 0x8003, /* å - 229 */
1124 0x8000, /* æ - 230 */
1125 0x8003, /* ç - 231 */
1126 0x8003, /* è - 232 */
1127 0x8003, /* é - 233 */
1128 0x8003, /* ê - 234 */
1129 0x8003, /* ë - 235 */
1130 0x8003, /* ì - 236 */
1131 0x8003, /* í - 237 */
1132 0x8003, /* î - 238 */
1133 0x8003, /* ï - 239 */
1134 0x8000, /* ð - 240 */
1135 0x8003, /* ñ - 241 */
1136 0x8003, /* ò - 242 */
1137 0x8003, /* ó - 243 */
1138 0x8003, /* ô - 244 */
1139 0x8003, /* õ - 245 */
1140 0x8003, /* ö - 246 */
1141 0x0008, /* ÷ - 247 */
1142 0x8003, /* ø - 248 */
1143 0x8003, /* ù - 249 */
1144 0x8003, /* ú - 250 */
1145 0x8003, /* û - 251 */
1146 0x8003, /* ü - 252 */
1147 0x8003, /* ý - 253 */
1148 0x8000, /* þ - 254 */
1149 0x8003 /* ÿ - 255 */
1152 /******************************************************************************
1153 * GetStringTypeA [KERNEL32.396]
1155 BOOL WINAPI GetStringTypeA(LCID locale,DWORD dwInfoType,LPCSTR src,
1156 INT cchSrc,LPWORD chartype)
1158 return GetStringTypeExA(locale,dwInfoType,src,cchSrc,chartype);
1161 /******************************************************************************
1162 * GetStringTypeExA [KERNEL32.397]
1164 * FIXME: Ignores the locale.
1166 BOOL WINAPI GetStringTypeExA(LCID locale,DWORD dwInfoType,LPCSTR src,
1167 INT cchSrc,LPWORD chartype)
1169 int i;
1171 if ((src==NULL) || (chartype==NULL) || (src==(LPSTR)chartype))
1173 SetLastError(ERROR_INVALID_PARAMETER);
1174 return FALSE;
1177 if (cchSrc==-1)
1178 cchSrc=lstrlenA(src)+1;
1180 switch (dwInfoType) {
1181 case CT_CTYPE1:
1182 for (i=0;i<cchSrc;i++)
1184 chartype[i] = 0;
1185 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1186 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1187 if (islower(src[i])) chartype[i]|=C1_LOWER;
1188 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1189 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1190 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1191 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1192 /* FIXME: isblank() is a GNU extension */
1193 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1194 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1195 /* C1_XDIGIT */
1197 return TRUE;
1199 case CT_CTYPE2:
1200 for (i=0;i<cchSrc;i++)
1202 chartype[i]=(WORD)CT_CType2_LUT[i];
1204 return TRUE;
1206 case CT_CTYPE3:
1207 for (i=0;i<cchSrc;i++)
1209 chartype[i]=OLE2NLS_CT_CType3_LUT[i];
1211 return TRUE;
1213 default:
1214 ERR("Unknown dwInfoType:%ld\n",dwInfoType);
1215 return FALSE;
1219 /******************************************************************************
1220 * GetStringTypeW [KERNEL32.399]
1222 * NOTES
1223 * Yes, this is missing LCID locale. MS fault.
1225 BOOL WINAPI GetStringTypeW(DWORD dwInfoType,LPCWSTR src,INT cchSrc,
1226 LPWORD chartype)
1228 return GetStringTypeExW(0/*defaultlocale*/,dwInfoType,src,cchSrc,chartype);
1231 /******************************************************************************
1232 * GetStringTypeExW [KERNEL32.398]
1234 * FIXME: unicode chars are assumed chars
1236 BOOL WINAPI GetStringTypeExW(LCID locale,DWORD dwInfoType,LPCWSTR src,
1237 INT cchSrc,LPWORD chartype)
1239 int i;
1242 if (cchSrc==-1)
1243 cchSrc=lstrlenW(src)+1;
1245 switch (dwInfoType) {
1246 case CT_CTYPE2:
1247 FIXME("CT_CTYPE2 not supported.\n");
1248 return FALSE;
1249 case CT_CTYPE3:
1250 FIXME("CT_CTYPE3 not supported.\n");
1251 return FALSE;
1252 default:break;
1254 for (i=0;i<cchSrc;i++) {
1255 chartype[i] = 0;
1256 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1257 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1258 if (islower(src[i])) chartype[i]|=C1_LOWER;
1259 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1260 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1261 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1262 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1263 /* FIXME: isblank() is a GNU extension */
1264 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1265 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1266 /* C1_XDIGIT */
1268 return TRUE;
1271 /***********************************************************************
1272 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1274 DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
1276 if(!szLang)
1277 return 0;
1279 return GetLocaleInfoA(MAKELCID(wLang, SORT_DEFAULT) , LOCALE_SENGLANGUAGE, szLang, nSize);
1282 /***********************************************************************
1283 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1285 DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
1287 if(!szLang)
1288 return 0;
1290 return GetLocaleInfoW(MAKELCID(wLang, SORT_DEFAULT) , LOCALE_SENGLANGUAGE, szLang, nSize);
1294 static const unsigned char LCM_Unicode_LUT[] = {
1295 6 , 3, /* - 1 */
1296 6 , 4, /* - 2 */
1297 6 , 5, /* - 3 */
1298 6 , 6, /* - 4 */
1299 6 , 7, /* - 5 */
1300 6 , 8, /* - 6 */
1301 6 , 9, /* - 7 */
1302 6 , 10, /* - 8 */
1303 7 , 5, /* - 9 */
1304 7 , 6, /* - 10 */
1305 7 , 7, /* - 11 */
1306 7 , 8, /* - 12 */
1307 7 , 9, /* - 13 */
1308 6 , 11, /* - 14 */
1309 6 , 12, /* - 15 */
1310 6 , 13, /* - 16 */
1311 6 , 14, /* - 17 */
1312 6 , 15, /* - 18 */
1313 6 , 16, /* - 19 */
1314 6 , 17, /* - 20 */
1315 6 , 18, /* - 21 */
1316 6 , 19, /* - 22 */
1317 6 , 20, /* - 23 */
1318 6 , 21, /* - 24 */
1319 6 , 22, /* - 25 */
1320 6 , 23, /* - 26 */
1321 6 , 24, /* - 27 */
1322 6 , 25, /* - 28 */
1323 6 , 26, /* - 29 */
1324 6 , 27, /* - 30 */
1325 6 , 28, /* - 31 */
1326 7 , 2, /* - 32 */
1327 7 , 28, /* ! - 33 */
1328 7 , 29, /* " - 34 */ /* " */
1329 7 , 31, /* # - 35 */
1330 7 , 33, /* $ - 36 */
1331 7 , 35, /* % - 37 */
1332 7 , 37, /* & - 38 */
1333 6 , 128, /* ' - 39 */
1334 7 , 39, /* ( - 40 */
1335 7 , 42, /* ) - 41 */
1336 7 , 45, /* * - 42 */
1337 8 , 3, /* + - 43 */
1338 7 , 47, /* , - 44 */
1339 6 , 130, /* - - 45 */
1340 7 , 51, /* . - 46 */
1341 7 , 53, /* / - 47 */
1342 12 , 3, /* 0 - 48 */
1343 12 , 33, /* 1 - 49 */
1344 12 , 51, /* 2 - 50 */
1345 12 , 70, /* 3 - 51 */
1346 12 , 88, /* 4 - 52 */
1347 12 , 106, /* 5 - 53 */
1348 12 , 125, /* 6 - 54 */
1349 12 , 144, /* 7 - 55 */
1350 12 , 162, /* 8 - 56 */
1351 12 , 180, /* 9 - 57 */
1352 7 , 55, /* : - 58 */
1353 7 , 58, /* ; - 59 */
1354 8 , 14, /* < - 60 */
1355 8 , 18, /* = - 61 */
1356 8 , 20, /* > - 62 */
1357 7 , 60, /* ? - 63 */
1358 7 , 62, /* @ - 64 */
1359 14 , 2, /* A - 65 */
1360 14 , 9, /* B - 66 */
1361 14 , 10, /* C - 67 */
1362 14 , 26, /* D - 68 */
1363 14 , 33, /* E - 69 */
1364 14 , 35, /* F - 70 */
1365 14 , 37, /* G - 71 */
1366 14 , 44, /* H - 72 */
1367 14 , 50, /* I - 73 */
1368 14 , 53, /* J - 74 */
1369 14 , 54, /* K - 75 */
1370 14 , 72, /* L - 76 */
1371 14 , 81, /* M - 77 */
1372 14 , 112, /* N - 78 */
1373 14 , 124, /* O - 79 */
1374 14 , 126, /* P - 80 */
1375 14 , 137, /* Q - 81 */
1376 14 , 138, /* R - 82 */
1377 14 , 145, /* S - 83 */
1378 14 , 153, /* T - 84 */
1379 14 , 159, /* U - 85 */
1380 14 , 162, /* V - 86 */
1381 14 , 164, /* W - 87 */
1382 14 , 166, /* X - 88 */
1383 14 , 167, /* Y - 89 */
1384 14 , 169, /* Z - 90 */
1385 7 , 63, /* [ - 91 */
1386 7 , 65, /* \ - 92 */
1387 7 , 66, /* ] - 93 */
1388 7 , 67, /* ^ - 94 */
1389 7 , 68, /* _ - 95 */
1390 7 , 72, /* ` - 96 */
1391 14 , 2, /* a - 97 */
1392 14 , 9, /* b - 98 */
1393 14 , 10, /* c - 99 */
1394 14 , 26, /* d - 100 */
1395 14 , 33, /* e - 101 */
1396 14 , 35, /* f - 102 */
1397 14 , 37, /* g - 103 */
1398 14 , 44, /* h - 104 */
1399 14 , 50, /* i - 105 */
1400 14 , 53, /* j - 106 */
1401 14 , 54, /* k - 107 */
1402 14 , 72, /* l - 108 */
1403 14 , 81, /* m - 109 */
1404 14 , 112, /* n - 110 */
1405 14 , 124, /* o - 111 */
1406 14 , 126, /* p - 112 */
1407 14 , 137, /* q - 113 */
1408 14 , 138, /* r - 114 */
1409 14 , 145, /* s - 115 */
1410 14 , 153, /* t - 116 */
1411 14 , 159, /* u - 117 */
1412 14 , 162, /* v - 118 */
1413 14 , 164, /* w - 119 */
1414 14 , 166, /* x - 120 */
1415 14 , 167, /* y - 121 */
1416 14 , 169, /* z - 122 */
1417 7 , 74, /* { - 123 */
1418 7 , 76, /* | - 124 */
1419 7 , 78, /* } - 125 */
1420 7 , 80, /* ~ - 126 */
1421 6 , 29, /* \x7f - 127 */
1422 6 , 30, /* € - 128 */
1423 6 , 31, /* � - 129 */
1424 7 , 123, /* ‚ - 130 */
1425 14 , 35, /* ƒ - 131 */
1426 7 , 127, /* „ - 132 */
1427 10 , 21, /* … - 133 */
1428 10 , 15, /* † - 134 */
1429 10 , 16, /* ‡ - 135 */
1430 7 , 67, /* ˆ - 136 */
1431 10 , 22, /* ‰ - 137 */
1432 14 , 145, /* Š - 138 */
1433 7 , 136, /* ‹ - 139 */
1434 14 + 16 , 124, /* Π- 140 */
1435 6 , 43, /* � - 141 */
1436 6 , 44, /* Ž - 142 */
1437 6 , 45, /* � - 143 */
1438 6 , 46, /* � - 144 */
1439 7 , 121, /* ‘ - 145 */
1440 7 , 122, /* ’ - 146 */
1441 7 , 125, /* “ - 147 */
1442 7 , 126, /* ” - 148 */
1443 10 , 17, /* • - 149 */
1444 6 , 137, /* – - 150 */
1445 6 , 139, /* — - 151 */
1446 7 , 93, /* ˜ - 152 */
1447 14 , 156, /* ™ - 153 */
1448 14 , 145, /* š - 154 */
1449 7 , 137, /* › - 155 */
1450 14 + 16 , 124, /* œ - 156 */
1451 6 , 59, /* � - 157 */
1452 6 , 60, /* ž - 158 */
1453 14 , 167, /* Ÿ - 159 */
1454 7 , 4, /*   - 160 */
1455 7 , 81, /* ¡ - 161 */
1456 10 , 2, /* ¢ - 162 */
1457 10 , 3, /* £ - 163 */
1458 10 , 4, /* ¤ - 164 */
1459 10 , 5, /* ¥ - 165 */
1460 7 , 82, /* ¦ - 166 */
1461 10 , 6, /* § - 167 */
1462 7 , 83, /* ¨ - 168 */
1463 10 , 7, /* © - 169 */
1464 14 , 2, /* ª - 170 */
1465 8 , 24, /* « - 171 */
1466 10 , 8, /* ¬ - 172 */
1467 6 , 131, /* ­ - 173 */
1468 10 , 9, /* ® - 174 */
1469 7 , 84, /* ¯ - 175 */
1470 10 , 10, /* ° - 176 */
1471 8 , 23, /* ± - 177 */
1472 12 , 51, /* ² - 178 */
1473 12 , 70, /* ³ - 179 */
1474 7 , 85, /* ´ - 180 */
1475 10 , 11, /* µ - 181 */
1476 10 , 12, /* ¶ - 182 */
1477 10 , 13, /* · - 183 */
1478 7 , 86, /* ¸ - 184 */
1479 12 , 33, /* ¹ - 185 */
1480 14 , 124, /* º - 186 */
1481 8 , 26, /* » - 187 */
1482 12 , 21, /* ¼ - 188 */
1483 12 , 25, /* ½ - 189 */
1484 12 , 29, /* ¾ - 190 */
1485 7 , 87, /* ¿ - 191 */
1486 14 , 2, /* À - 192 */
1487 14 , 2, /* Á - 193 */
1488 14 , 2, /* Â - 194 */
1489 14 , 2, /* Ã - 195 */
1490 14 , 2, /* Ä - 196 */
1491 14 , 2, /* Å - 197 */
1492 14 + 16 , 2, /* Æ - 198 */
1493 14 , 10, /* Ç - 199 */
1494 14 , 33, /* È - 200 */
1495 14 , 33, /* É - 201 */
1496 14 , 33, /* Ê - 202 */
1497 14 , 33, /* Ë - 203 */
1498 14 , 50, /* Ì - 204 */
1499 14 , 50, /* Í - 205 */
1500 14 , 50, /* Î - 206 */
1501 14 , 50, /* Ï - 207 */
1502 14 , 26, /* Ð - 208 */
1503 14 , 112, /* Ñ - 209 */
1504 14 , 124, /* Ò - 210 */
1505 14 , 124, /* Ó - 211 */
1506 14 , 124, /* Ô - 212 */
1507 14 , 124, /* Õ - 213 */
1508 14 , 124, /* Ö - 214 */
1509 8 , 28, /* × - 215 */
1510 14 , 124, /* Ø - 216 */
1511 14 , 159, /* Ù - 217 */
1512 14 , 159, /* Ú - 218 */
1513 14 , 159, /* Û - 219 */
1514 14 , 159, /* Ü - 220 */
1515 14 , 167, /* Ý - 221 */
1516 14 + 32 , 153, /* Þ - 222 */
1517 14 + 48 , 145, /* ß - 223 */
1518 14 , 2, /* à - 224 */
1519 14 , 2, /* á - 225 */
1520 14 , 2, /* â - 226 */
1521 14 , 2, /* ã - 227 */
1522 14 , 2, /* ä - 228 */
1523 14 , 2, /* å - 229 */
1524 14 + 16 , 2, /* æ - 230 */
1525 14 , 10, /* ç - 231 */
1526 14 , 33, /* è - 232 */
1527 14 , 33, /* é - 233 */
1528 14 , 33, /* ê - 234 */
1529 14 , 33, /* ë - 235 */
1530 14 , 50, /* ì - 236 */
1531 14 , 50, /* í - 237 */
1532 14 , 50, /* î - 238 */
1533 14 , 50, /* ï - 239 */
1534 14 , 26, /* ð - 240 */
1535 14 , 112, /* ñ - 241 */
1536 14 , 124, /* ò - 242 */
1537 14 , 124, /* ó - 243 */
1538 14 , 124, /* ô - 244 */
1539 14 , 124, /* õ - 245 */
1540 14 , 124, /* ö - 246 */
1541 8 , 29, /* ÷ - 247 */
1542 14 , 124, /* ø - 248 */
1543 14 , 159, /* ù - 249 */
1544 14 , 159, /* ú - 250 */
1545 14 , 159, /* û - 251 */
1546 14 , 159, /* ü - 252 */
1547 14 , 167, /* ý - 253 */
1548 14 + 32 , 153, /* þ - 254 */
1549 14 , 167 /* ÿ - 255 */ };
1551 static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
1553 #define LCM_Diacritic_Start 131
1555 static const unsigned char LCM_Diacritic_LUT[] = {
1556 123, /* ƒ - 131 */
1557 2, /* „ - 132 */
1558 2, /* … - 133 */
1559 2, /* † - 134 */
1560 2, /* ‡ - 135 */
1561 3, /* ˆ - 136 */
1562 2, /* ‰ - 137 */
1563 20, /* Š - 138 */
1564 2, /* ‹ - 139 */
1565 2, /* Π- 140 */
1566 2, /* � - 141 */
1567 2, /* Ž - 142 */
1568 2, /* � - 143 */
1569 2, /* � - 144 */
1570 2, /* ‘ - 145 */
1571 2, /* ’ - 146 */
1572 2, /* “ - 147 */
1573 2, /* ” - 148 */
1574 2, /* • - 149 */
1575 2, /* – - 150 */
1576 2, /* — - 151 */
1577 2, /* ˜ - 152 */
1578 2, /* ™ - 153 */
1579 20, /* š - 154 */
1580 2, /* › - 155 */
1581 2, /* œ - 156 */
1582 2, /* � - 157 */
1583 2, /* ž - 158 */
1584 19, /* Ÿ - 159 */
1585 2, /*   - 160 */
1586 2, /* ¡ - 161 */
1587 2, /* ¢ - 162 */
1588 2, /* £ - 163 */
1589 2, /* ¤ - 164 */
1590 2, /* ¥ - 165 */
1591 2, /* ¦ - 166 */
1592 2, /* § - 167 */
1593 2, /* ¨ - 168 */
1594 2, /* © - 169 */
1595 3, /* ª - 170 */
1596 2, /* « - 171 */
1597 2, /* ¬ - 172 */
1598 2, /* ­ - 173 */
1599 2, /* ® - 174 */
1600 2, /* ¯ - 175 */
1601 2, /* ° - 176 */
1602 2, /* ± - 177 */
1603 2, /* ² - 178 */
1604 2, /* ³ - 179 */
1605 2, /* ´ - 180 */
1606 2, /* µ - 181 */
1607 2, /* ¶ - 182 */
1608 2, /* · - 183 */
1609 2, /* ¸ - 184 */
1610 2, /* ¹ - 185 */
1611 3, /* º - 186 */
1612 2, /* » - 187 */
1613 2, /* ¼ - 188 */
1614 2, /* ½ - 189 */
1615 2, /* ¾ - 190 */
1616 2, /* ¿ - 191 */
1617 15, /* À - 192 */
1618 14, /* Á - 193 */
1619 18, /* Â - 194 */
1620 25, /* Ã - 195 */
1621 19, /* Ä - 196 */
1622 26, /* Å - 197 */
1623 2, /* Æ - 198 */
1624 28, /* Ç - 199 */
1625 15, /* È - 200 */
1626 14, /* É - 201 */
1627 18, /* Ê - 202 */
1628 19, /* Ë - 203 */
1629 15, /* Ì - 204 */
1630 14, /* Í - 205 */
1631 18, /* Î - 206 */
1632 19, /* Ï - 207 */
1633 104, /* Ð - 208 */
1634 25, /* Ñ - 209 */
1635 15, /* Ò - 210 */
1636 14, /* Ó - 211 */
1637 18, /* Ô - 212 */
1638 25, /* Õ - 213 */
1639 19, /* Ö - 214 */
1640 2, /* × - 215 */
1641 33, /* Ø - 216 */
1642 15, /* Ù - 217 */
1643 14, /* Ú - 218 */
1644 18, /* Û - 219 */
1645 19, /* Ü - 220 */
1646 14, /* Ý - 221 */
1647 2, /* Þ - 222 */
1648 2, /* ß - 223 */
1649 15, /* à - 224 */
1650 14, /* á - 225 */
1651 18, /* â - 226 */
1652 25, /* ã - 227 */
1653 19, /* ä - 228 */
1654 26, /* å - 229 */
1655 2, /* æ - 230 */
1656 28, /* ç - 231 */
1657 15, /* è - 232 */
1658 14, /* é - 233 */
1659 18, /* ê - 234 */
1660 19, /* ë - 235 */
1661 15, /* ì - 236 */
1662 14, /* í - 237 */
1663 18, /* î - 238 */
1664 19, /* ï - 239 */
1665 104, /* ð - 240 */
1666 25, /* ñ - 241 */
1667 15, /* ò - 242 */
1668 14, /* ó - 243 */
1669 18, /* ô - 244 */
1670 25, /* õ - 245 */
1671 19, /* ö - 246 */
1672 2, /* ÷ - 247 */
1673 33, /* ø - 248 */
1674 15, /* ù - 249 */
1675 14, /* ú - 250 */
1676 18, /* û - 251 */
1677 19, /* ü - 252 */
1678 14, /* ý - 253 */
1679 2, /* þ - 254 */
1680 19, /* ÿ - 255 */
1683 /******************************************************************************
1684 * OLE2NLS_isPunctuation [INTERNAL]
1686 static int OLE2NLS_isPunctuation(unsigned char c)
1688 /* "punctuation character" in this context is a character which is
1689 considered "less important" during word sort comparison.
1690 See LCMapString implementation for the precise definition
1691 of "less important". */
1693 return (LCM_Unicode_LUT[-2+2*c]==6);
1696 /******************************************************************************
1697 * OLE2NLS_isNonSpacing [INTERNAL]
1699 static int OLE2NLS_isNonSpacing(unsigned char c)
1701 /* This function is used by LCMapStringA. Characters
1702 for which it returns true are ignored when mapping a
1703 string with NORM_IGNORENONSPACE */
1704 return ((c==136) || (c==170) || (c==186));
1707 /******************************************************************************
1708 * OLE2NLS_isSymbol [INTERNAL]
1710 static int OLE2NLS_isSymbol(unsigned char c)
1712 /* This function is used by LCMapStringA. Characters
1713 for which it returns true are ignored when mapping a
1714 string with NORM_IGNORESYMBOLS */
1715 return ( (c!=0) && !IsCharAlphaNumericA(c) );
1718 /******************************************************************************
1719 * identity [Internal]
1721 static int identity(int c)
1723 return c;
1726 /*************************************************************************
1727 * LCMapStringA [KERNEL32.492]
1729 * Convert a string, or generate a sort key from it.
1731 * If (mapflags & LCMAP_SORTKEY), the function will generate
1732 * a sort key for the source string. Else, it will convert it
1733 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1735 * RETURNS
1736 * Error : 0.
1737 * Success : length of the result string.
1739 * NOTES
1740 * If called with scrlen = -1, the function will compute the length
1741 * of the 0-terminated string strsrc by itself.
1743 * If called with dstlen = 0, returns the buffer length that
1744 * would be required.
1746 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1747 * as if they are equal.
1748 * In the only code page implemented so far, there may not be
1749 * wide characters in strings passed to LCMapStringA,
1750 * so there is nothing to be done for this flag.
1752 INT WINAPI LCMapStringA(
1753 LCID lcid /* locale identifier created with MAKELCID;
1754 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1755 predefined values. */,
1756 DWORD mapflags /* flags */,
1757 LPCSTR srcstr /* source buffer */,
1758 INT srclen /* source length */,
1759 LPSTR dststr /* destination buffer */,
1760 INT dstlen /* destination buffer length */)
1762 int i;
1764 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1765 lcid,mapflags,srcstr,srclen,dststr,dstlen);
1767 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1769 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
1770 SetLastError(ERROR_INVALID_PARAMETER);
1771 return 0;
1773 if (srclen == -1)
1774 srclen = lstrlenA(srcstr) + 1 ; /* (include final '\0') */
1776 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1777 LCMAP_LOWERCASE | \
1778 LCMAP_SORTKEY | \
1779 NORM_IGNORECASE | \
1780 NORM_IGNORENONSPACE | \
1781 SORT_STRINGSORT | \
1782 NORM_IGNOREWIDTH | \
1783 NORM_IGNOREKANATYPE)
1784 /* FIXME: as long as we don't support Kanakana nor Hirigana
1785 * characters, we can support NORM_IGNOREKANATYPE
1787 if (mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS)
1789 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1790 "unimplemented flags: 0x%08lx\n",
1791 lcid,
1792 mapflags,
1793 srcstr,
1794 srclen,
1795 dststr,
1796 dstlen,
1797 mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS
1801 if ( !(mapflags & LCMAP_SORTKEY) )
1803 int i,j;
1804 int (*f)(int) = identity;
1805 int flag_ignorenonspace = mapflags & NORM_IGNORENONSPACE;
1806 int flag_ignoresymbols = mapflags & NORM_IGNORESYMBOLS;
1808 if (flag_ignorenonspace || flag_ignoresymbols)
1810 /* For some values of mapflags, the length of the resulting
1811 string is not known at this point. Windows does map the string
1812 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1813 these cases. */
1814 if (dstlen==0)
1816 /* Compute required length */
1817 for (i=j=0; i < srclen; i++)
1819 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1820 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1821 j++;
1823 return j;
1826 else
1828 if (dstlen==0)
1829 return srclen;
1830 if (dstlen<srclen)
1832 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1833 return 0;
1836 if (mapflags & LCMAP_UPPERCASE)
1837 f = toupper;
1838 else if (mapflags & LCMAP_LOWERCASE)
1839 f = tolower;
1840 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1841 for (i=j=0; (i<srclen) && (j<dstlen) ; i++)
1843 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1844 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1846 dststr[j] = (CHAR) f(srcstr[i]);
1847 j++;
1850 return j;
1853 /* FIXME: This function completely ignores the "lcid" parameter. */
1854 /* else ... (mapflags & LCMAP_SORTKEY) */
1856 int unicode_len=0;
1857 int case_len=0;
1858 int diacritic_len=0;
1859 int delayed_punctuation_len=0;
1860 char *case_component;
1861 char *diacritic_component;
1862 char *delayed_punctuation_component;
1863 int room,count;
1864 int flag_stringsort = mapflags & SORT_STRINGSORT;
1866 /* compute how much room we will need */
1867 for (i=0;i<srclen;i++)
1869 int ofs;
1870 unsigned char source_char = srcstr[i];
1871 if (source_char!='\0')
1873 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
1875 unicode_len++;
1876 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
1877 unicode_len++; /* double letter */
1879 else
1881 delayed_punctuation_len++;
1885 if (isupper(source_char))
1886 case_len=unicode_len;
1888 ofs = source_char - LCM_Diacritic_Start;
1889 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
1890 diacritic_len=unicode_len;
1893 if (mapflags & NORM_IGNORECASE)
1894 case_len=0;
1895 if (mapflags & NORM_IGNORENONSPACE)
1896 diacritic_len=0;
1898 room = 2 * unicode_len /* "unicode" component */
1899 + diacritic_len /* "diacritic" component */
1900 + case_len /* "case" component */
1901 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
1902 + 4 /* four '\1' separators */
1903 + 1 ; /* terminal '\0' */
1904 if (dstlen==0)
1905 return room;
1906 else if (dstlen<room)
1908 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1909 return 0;
1911 #if 0
1912 /*FIXME the Pointercheck should not be nessesary */
1913 if (IsBadWritePtr (dststr,room))
1914 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
1915 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1916 return 0;
1918 #endif
1919 /* locate each component, write separators */
1920 diacritic_component = dststr + 2*unicode_len ;
1921 *diacritic_component++ = '\1';
1922 case_component = diacritic_component + diacritic_len ;
1923 *case_component++ = '\1';
1924 delayed_punctuation_component = case_component + case_len ;
1925 *delayed_punctuation_component++ = '\1';
1926 *delayed_punctuation_component++ = '\1';
1928 /* read source string char by char, write
1929 corresponding weight in each component. */
1930 for (i=0,count=0;i<srclen;i++)
1932 unsigned char source_char=srcstr[i];
1933 if (source_char!='\0')
1935 int type,longcode;
1936 type = LCM_Unicode_LUT[-2+2*source_char];
1937 longcode = type >> 4;
1938 type &= 15;
1939 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
1941 UINT16 encrypted_location = (1<<15) + 7 + 4*count;
1942 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
1943 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
1944 /* big-endian is used here because it lets string comparison be
1945 compatible with numerical comparison */
1947 *delayed_punctuation_component++ = type;
1948 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
1949 /* assumption : a punctuation character is never a
1950 double or accented letter */
1952 else
1954 dststr[2*count] = type;
1955 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
1956 if (longcode)
1958 if (count<case_len)
1959 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1960 if (count<diacritic_len)
1961 diacritic_component[count] = 2; /* assumption: a double letter
1962 is never accented */
1963 count++;
1965 dststr[2*count] = type;
1966 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
1967 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1968 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1969 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1972 if (count<case_len)
1973 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1974 if (count<diacritic_len)
1976 int ofs = source_char - LCM_Diacritic_Start;
1977 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
1979 count++;
1983 dststr[room-1] = '\0';
1984 return room;
1988 /*************************************************************************
1989 * LCMapStringW [KERNEL32.493]
1991 * Convert a string, or generate a sort key from it.
1993 * NOTE
1995 * See LCMapStringA for documentation
1997 INT WINAPI LCMapStringW(
1998 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT srclen,LPWSTR dststr,
1999 INT dstlen)
2001 int i;
2003 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2004 lcid, mapflags, srcstr, srclen, dststr, dstlen);
2006 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2008 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
2009 SetLastError(ERROR_INVALID_PARAMETER);
2010 return 0;
2012 if (srclen==-1)
2013 srclen = lstrlenW(srcstr)+1;
2015 /* FIXME: Both this function and it's companion LCMapStringA()
2016 * completely ignore the "lcid" parameter. In place of the "lcid"
2017 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2018 * environment variable prior to invoking this function. */
2019 if (mapflags & LCMAP_SORTKEY)
2021 /* Possible values of LC_COLLATE. */
2022 char *lc_collate_default = 0; /* value prior to this function */
2023 char *lc_collate_env = 0; /* value retrieved from the environment */
2025 /* General purpose index into strings of any type. */
2026 int str_idx = 0;
2028 /* Lengths of various strings where the length is measured in
2029 * wide characters for wide character strings and in bytes for
2030 * native strings. The lengths include the NULL terminator. */
2031 size_t returned_len = 0;
2032 size_t src_native_len = 0;
2033 size_t dst_native_len = 0;
2034 size_t dststr_libc_len = 0;
2036 /* Native (character set determined by locale) versions of the
2037 * strings source and destination strings. */
2038 LPSTR src_native = 0;
2039 LPSTR dst_native = 0;
2041 /* Version of the source and destination strings using the
2042 * "wchar_t" Unicode data type needed by various libc functions. */
2043 wchar_t *srcstr_libc = 0;
2044 wchar_t *dststr_libc = 0;
2046 if(!(srcstr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2047 srclen * sizeof(wchar_t))))
2049 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2050 srclen * sizeof(wchar_t));
2051 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2052 return 0;
2055 /* Convert source string to a libc Unicode string. */
2056 for(str_idx = 0; str_idx < srclen; str_idx++)
2058 srcstr_libc[str_idx] = srcstr[str_idx];
2061 /* src_native should contain at most 3 bytes for each
2062 * multibyte characters in the original srcstr string. */
2063 src_native_len = 3 * srclen;
2064 if(!(src_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0,
2065 src_native_len)))
2067 ERR("Unable to allocate %d bytes for src_native\n", src_native_len);
2068 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2069 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2070 return 0;
2073 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2074 * current value is backed up so it can be restored after the
2075 * last LC_COLLATE sensitive function returns.
2077 * Even though the locale is adjusted for a minimum amount of
2078 * time a race condition exists where other threads may be
2079 * affected if they invoke LC_COLLATE sensitive functions. One
2080 * possible solution is to wrap all LC_COLLATE sensitive Wine
2081 * functions, like LCMapStringW(), in a mutex.
2083 * Another enhancement to the following would be to set the
2084 * LC_COLLATE locale category as a function of the "lcid"
2085 * parameter instead of the "LC_COLLATE" environment variable. */
2086 if(!(lc_collate_default = setlocale(LC_COLLATE, NULL)))
2088 ERR("Unable to query the LC_COLLATE catagory\n");
2089 SetLastError(ERROR_INVALID_PARAMETER);
2090 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2091 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2092 return 0;
2095 if(!(lc_collate_env = setlocale(LC_COLLATE, "")))
2097 ERR("Unable to inherit the LC_COLLATE locale category from the "
2098 "environment. The \"LC_COLLATE\" environment variable is "
2099 "\"%s\".\n", getenv("LC_COLLATE") ?
2100 getenv("LC_COLLATE") : "<unset>");
2101 SetLastError(ERROR_INVALID_PARAMETER);
2102 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2103 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2104 return 0;
2107 TRACE("lc_collate_default = %s\n", lc_collate_default);
2108 TRACE("lc_collate_env = %s\n", lc_collate_env);
2110 /* Convert the libc Unicode string to a native multibyte character
2111 * string. */
2112 returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1;
2113 if(returned_len == 0)
2115 LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(),
2116 0, srcstr);
2117 ERR("wcstombs failed. The string specified (%s) may contains an "
2118 "invalid character.\n", srcstr_ascii);
2119 SetLastError(ERROR_INVALID_PARAMETER);
2120 if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii);
2121 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2122 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2123 setlocale(LC_COLLATE, lc_collate_default);
2124 return 0;
2126 else if(returned_len > src_native_len)
2128 src_native[src_native_len - 1] = 0;
2129 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2130 "than expected (%d bytes).\n", src_native, returned_len,
2131 dst_native_len);
2133 /* Since this is an internal error I'm not sure what the correct
2134 * error code is. */
2135 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2137 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2138 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2139 setlocale(LC_COLLATE, lc_collate_default);
2140 return 0;
2142 src_native_len = returned_len;
2144 TRACE("src_native = %s src_native_len = %d\n",
2145 src_native, src_native_len);
2147 /* dst_native seems to contain at most 4 bytes for each byte in
2148 * the original src_native string. Change if need be since this
2149 * isn't documented by the strxfrm() man page. */
2150 dst_native_len = 4 * src_native_len;
2151 if(!(dst_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0, dst_native_len)))
2153 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len);
2154 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2155 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2156 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2157 setlocale(LC_COLLATE, lc_collate_default);
2158 return 0;
2161 /* The actual translation is done by the following call to
2162 * strxfrm(). The surrounding code could have been simplified
2163 * by calling wcsxfrm() instead except that wcsxfrm() is not
2164 * available on older Linux systems (RedHat 4.1 with
2165 * libc-5.3.12-17).
2167 * Also, it is possible that the translation could be done by
2168 * various tables as it is done in LCMapStringA(). However, I'm
2169 * not sure what those tables are. */
2170 returned_len = strxfrm(dst_native, src_native, dst_native_len) + 1;
2172 if(returned_len > dst_native_len)
2174 dst_native[dst_native_len - 1] = 0;
2175 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2176 "than expected (%d bytes).\n", dst_native, returned_len,
2177 dst_native_len);
2179 /* Since this is an internal error I'm not sure what the correct
2180 * error code is. */
2181 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2183 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2184 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2185 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2186 setlocale(LC_COLLATE, lc_collate_default);
2187 return 0;
2189 dst_native_len = returned_len;
2191 TRACE("dst_native = %s dst_native_len = %d\n",
2192 dst_native, dst_native_len);
2194 dststr_libc_len = dst_native_len;
2195 if(!(dststr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2196 dststr_libc_len * sizeof(wchar_t))))
2198 ERR("Unable to allocate %d bytes for dststr_libc\n",
2199 dststr_libc_len * sizeof(wchar_t));
2200 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2201 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2202 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2203 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2204 setlocale(LC_COLLATE, lc_collate_default);
2205 return 0;
2208 /* Convert the native multibyte string to a libc Unicode string. */
2209 returned_len = mbstowcs(dststr_libc, dst_native, dst_native_len) + 1;
2211 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2212 * function has returned. */
2213 setlocale(LC_COLLATE, lc_collate_default);
2215 if(returned_len == 0)
2217 ERR("mbstowcs failed. The native version of the translated string "
2218 "(%s) may contain an invalid character.\n", dst_native);
2219 SetLastError(ERROR_INVALID_PARAMETER);
2220 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2221 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2222 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2223 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2224 return 0;
2226 if(dstlen)
2228 if(returned_len > dstlen)
2230 ERR("mbstowcs returned a string that was longer (%d chars) "
2231 "than the buffer provided (%d chars).\n", returned_len,
2232 dstlen);
2233 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2234 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2235 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2236 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2237 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2238 return 0;
2240 dstlen = returned_len;
2242 /* Convert a libc Unicode string to the destination string. */
2243 for(str_idx = 0; str_idx < dstlen; str_idx++)
2245 dststr[str_idx] = dststr_libc[str_idx];
2247 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2248 *(((int *)dststr) + 0),
2249 *(((int *)dststr) + 1),
2250 *(((int *)dststr) + 2),
2251 *(((int *)dststr) + 3));
2253 else
2255 dstlen = returned_len;
2257 TRACE("dstlen (return) = %d\n", dstlen);
2258 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2259 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2260 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2261 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2262 return dstlen;
2264 else
2266 int (*f)(int)=identity;
2268 if (dstlen==0)
2269 return srclen;
2270 if (dstlen<srclen)
2272 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2273 return 0;
2276 if (mapflags & LCMAP_UPPERCASE)
2277 f = toupper;
2278 else if (mapflags & LCMAP_LOWERCASE)
2279 f = tolower;
2280 for (i=0; i < srclen; i++)
2281 dststr[i] = (WCHAR) f(srcstr[i]);
2282 return srclen;
2287 /***********************************************************************
2288 * OLE2NLS_EstimateMappingLength
2290 * Estimates the number of characters required to hold the string
2291 * computed by LCMapStringA.
2293 * The size is always over-estimated, with a fixed limit on the
2294 * amount of estimation error.
2296 * Note that len == -1 is not permitted.
2298 static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
2299 LPCSTR str, DWORD len)
2301 /* Estimate only for small strings to keep the estimation error from
2302 * becoming too large. */
2303 if (len < 128) return len * 8 + 5;
2304 else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
2307 /******************************************************************************
2308 * CompareStringA [KERNEL32.143]
2309 * Compares two strings using locale
2311 * RETURNS
2313 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2314 * failure: 0
2316 * NOTES
2318 * Defaults to a word sort, but uses a string sort if
2319 * SORT_STRINGSORT is set.
2320 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2322 * BUGS
2324 * This implementation ignores the locale
2326 * FIXME
2328 * Quite inefficient.
2330 UINT WINAPI CompareStringA(
2331 DWORD lcid, /* locale ID */
2332 DWORD fdwStyle, /* comparison-style options */
2333 LPCSTR s1, /* first string */
2334 DWORD l1, /* length of first string */
2335 LPCSTR s2, /* second string */
2336 DWORD l2) /* length of second string */
2338 int mapstring_flags;
2339 int len1,len2;
2340 int result;
2341 LPSTR sk1,sk2;
2342 TRACE("%s and %s\n",
2343 debugstr_a (s1), debugstr_a (s2));
2345 if ( (s1==NULL) || (s2==NULL) )
2347 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
2348 SetLastError(ERROR_INVALID_PARAMETER);
2349 return 0;
2352 if(fdwStyle & NORM_IGNORESYMBOLS)
2353 FIXME("IGNORESYMBOLS not supported\n");
2355 if (l1 == -1) l1 = lstrlenA(s1);
2356 if (l2 == -1) l2 = lstrlenA(s2);
2358 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2359 len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
2360 len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
2362 if ((len1==0)||(len2==0))
2363 return 0; /* something wrong happened */
2365 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
2366 sk2 = sk1 + len1;
2367 if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
2368 || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2370 ERR("Bug in LCmapStringA.\n");
2371 result = 0;
2373 else
2375 /* strcmp doesn't necessarily return -1, 0, or 1 */
2376 result = strcmp(sk1,sk2);
2378 HeapFree(GetProcessHeap(),0,sk1);
2380 if (result < 0)
2381 return 1;
2382 if (result == 0)
2383 return 2;
2385 /* must be greater, if we reach this point */
2386 return 3;
2389 /******************************************************************************
2390 * CompareStringW [KERNEL32.144]
2391 * This implementation ignores the locale
2392 * FIXME : Does only string sort. Should
2393 * be reimplemented the same way as CompareStringA.
2395 UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
2396 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2398 int len,ret;
2399 if(fdwStyle & NORM_IGNORENONSPACE)
2400 FIXME("IGNORENONSPACE not supprted\n");
2401 if(fdwStyle & NORM_IGNORESYMBOLS)
2402 FIXME("IGNORESYMBOLS not supported\n");
2404 /* Is strcmp defaulting to string sort or to word sort?? */
2405 /* FIXME: Handle NORM_STRINGSORT */
2406 l1 = (l1==-1)?lstrlenW(s1):l1;
2407 l2 = (l2==-1)?lstrlenW(s2):l2;
2408 len = l1<l2 ? l1:l2;
2409 ret = (fdwStyle & NORM_IGNORECASE) ? strncmpiW(s1,s2,len) : strncmpW(s1,s2,len);
2410 /* not equal, return 1 or 3 */
2411 if(ret!=0) return ret+2;
2412 /* same len, return 2 */
2413 if(l1==l2) return 2;
2414 /* the longer one is lexically greater */
2415 return (l1<l2)? 1 : 3;
2418 /******************************************************************************
2419 * OLE_GetFormatA [Internal]
2421 * FIXME
2422 * If datelen == 0, it should return the reguired string length.
2424 This function implements stuff for GetDateFormat() and
2425 GetTimeFormat().
2427 d single-digit (no leading zero) day (of month)
2428 dd two-digit day (of month)
2429 ddd short day-of-week name
2430 dddd long day-of-week name
2431 M single-digit month
2432 MM two-digit month
2433 MMM short month name
2434 MMMM full month name
2435 y two-digit year, no leading 0
2436 yy two-digit year
2437 yyyy four-digit year
2438 gg era string
2439 h hours with no leading zero (12-hour)
2440 hh hours with full two digits
2441 H hours with no leading zero (24-hour)
2442 HH hours with full two digits
2443 m minutes with no leading zero
2444 mm minutes with full two digits
2445 s seconds with no leading zero
2446 ss seconds with full two digits
2447 t time marker (A or P)
2448 tt time marker (AM, PM)
2449 '' used to quote literal characters
2450 '' (within a quoted string) indicates a literal '
2452 These functions REQUIRE valid locale, date, and format.
2454 static INT OLE_GetFormatA(LCID locale,
2455 DWORD flags,
2456 DWORD tflags,
2457 LPSYSTEMTIME xtime,
2458 LPCSTR _format, /*in*/
2459 LPSTR date, /*out*/
2460 INT datelen)
2462 INT inpos, outpos;
2463 int count, type, inquote, Overflow;
2464 char buf[40];
2465 char format[40];
2466 char * pos;
2467 int buflen;
2469 const char * _dgfmt[] = { "%d", "%02d" };
2470 const char ** dgfmt = _dgfmt - 1;
2472 /* report, for debugging */
2473 TRACE("(0x%lx,0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
2474 locale, flags, tflags,
2475 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2476 _format, _format, date, datelen);
2478 if(datelen == 0) {
2479 FIXME("datelen = 0, returning 255\n");
2480 return 255;
2483 /* initalize state variables and output buffer */
2484 inpos = outpos = 0;
2485 count = 0; inquote = 0; Overflow = 0;
2486 type = '\0';
2487 date[0] = buf[0] = '\0';
2489 strcpy(format,_format);
2491 /* alter the formatstring, while it works for all languages now in wine
2492 its possible that it fails when the time looks like ss:mm:hh as example*/
2493 if (tflags & (TIME_NOMINUTESORSECONDS))
2494 { if ((pos = strstr ( format, ":mm")))
2495 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2498 if (tflags & (TIME_NOSECONDS))
2499 { if ((pos = strstr ( format, ":ss")))
2500 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2504 for (inpos = 0;; inpos++) {
2505 /* 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]); */
2506 if (inquote) {
2507 if (format[inpos] == '\'') {
2508 if (format[inpos+1] == '\'') {
2509 inpos += 1;
2510 date[outpos++] = '\'';
2511 } else {
2512 inquote = 0;
2513 continue; /* we did nothing to the output */
2515 } else if (format[inpos] == '\0') {
2516 date[outpos++] = '\0';
2517 if (outpos > datelen) Overflow = 1;
2518 break;
2519 } else {
2520 date[outpos++] = format[inpos];
2521 if (outpos > datelen) {
2522 Overflow = 1;
2523 date[outpos-1] = '\0'; /* this is the last place where
2524 it's safe to write */
2525 break;
2528 } else if ( (count && (format[inpos] != type))
2529 || count == 4
2530 || (count == 2 && strchr("ghHmst", type)) )
2532 if (type == 'd') {
2533 if (count == 4) {
2534 GetLocaleInfoA(locale,
2535 LOCALE_SDAYNAME1
2536 + xtime->wDayOfWeek - 1,
2537 buf, sizeof(buf));
2538 } else if (count == 3) {
2539 GetLocaleInfoA(locale,
2540 LOCALE_SABBREVDAYNAME1
2541 + xtime->wDayOfWeek - 1,
2542 buf, sizeof(buf));
2543 } else {
2544 sprintf(buf, dgfmt[count], xtime->wDay);
2546 } else if (type == 'M') {
2547 if (count == 3) {
2548 GetLocaleInfoA(locale,
2549 LOCALE_SABBREVMONTHNAME1
2550 + xtime->wMonth - 1,
2551 buf, sizeof(buf));
2552 } else if (count == 4) {
2553 GetLocaleInfoA(locale,
2554 LOCALE_SMONTHNAME1
2555 + xtime->wMonth - 1,
2556 buf, sizeof(buf));
2557 } else {
2558 sprintf(buf, dgfmt[count], xtime->wMonth);
2560 } else if (type == 'y') {
2561 if (count == 4) {
2562 sprintf(buf, "%d", xtime->wYear);
2563 } else if (count == 3) {
2564 strcpy(buf, "yyy");
2565 WARN("unknown format, c=%c, n=%d\n", type, count);
2566 } else {
2567 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2569 } else if (type == 'g') {
2570 if (count == 2) {
2571 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2572 strcpy(buf, "AD");
2573 } else {
2574 strcpy(buf, "g");
2575 WARN("unknown format, c=%c, n=%d\n", type, count);
2577 } else if (type == 'h') {
2578 /* gives us hours 1:00 -- 12:00 */
2579 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2580 } else if (type == 'H') {
2581 /* 24-hour time */
2582 sprintf(buf, dgfmt[count], xtime->wHour);
2583 } else if ( type == 'm') {
2584 sprintf(buf, dgfmt[count], xtime->wMinute);
2585 } else if ( type == 's') {
2586 sprintf(buf, dgfmt[count], xtime->wSecond);
2587 } else if (type == 't') {
2588 if (count == 1) {
2589 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2590 } else if (count == 2) {
2591 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2592 GetLocaleInfoA(locale,
2593 (xtime->wHour<12)
2594 ? LOCALE_S1159 : LOCALE_S2359,
2595 buf, sizeof(buf));
2599 /* we need to check the next char in the format string
2600 again, no matter what happened */
2601 inpos--;
2603 /* add the contents of buf to the output */
2604 buflen = strlen(buf);
2605 if (outpos + buflen < datelen) {
2606 date[outpos] = '\0'; /* for strcat to hook onto */
2607 strcat(date, buf);
2608 outpos += buflen;
2609 } else {
2610 date[outpos] = '\0';
2611 strncat(date, buf, datelen - outpos);
2612 date[datelen - 1] = '\0';
2613 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2614 WARN("insufficient buffer\n");
2615 return 0;
2618 /* reset the variables we used to keep track of this item */
2619 count = 0;
2620 type = '\0';
2621 } else if (format[inpos] == '\0') {
2622 /* we can't check for this at the loop-head, because
2623 that breaks the printing of the last format-item */
2624 date[outpos] = '\0';
2625 break;
2626 } else if (count) {
2627 /* continuing a code for an item */
2628 count +=1;
2629 continue;
2630 } else if (strchr("hHmstyMdg", format[inpos])) {
2631 type = format[inpos];
2632 count = 1;
2633 continue;
2634 } else if (format[inpos] == '\'') {
2635 inquote = 1;
2636 continue;
2637 } else {
2638 date[outpos++] = format[inpos];
2640 /* now deal with a possible buffer overflow */
2641 if (outpos >= datelen) {
2642 date[datelen - 1] = '\0';
2643 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2644 return 0;
2648 if (Overflow) {
2649 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2652 /* finish it off with a string terminator */
2653 outpos++;
2654 /* sanity check */
2655 if (outpos > datelen-1) outpos = datelen-1;
2656 date[outpos] = '\0';
2658 TRACE("OLE_GetFormatA returns string '%s', len %d\n",
2659 date, outpos);
2660 return outpos;
2663 /******************************************************************************
2664 * OLE_GetFormatW [INTERNAL]
2666 static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
2667 LPSYSTEMTIME xtime,
2668 LPCWSTR format,
2669 LPWSTR output, INT outlen)
2671 INT inpos, outpos;
2672 int count, type=0, inquote;
2673 int Overflow; /* loop check */
2674 WCHAR buf[40];
2675 int buflen=0;
2676 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2677 WCHAR arg2[] = {'%','0','2','d',0};
2678 WCHAR *argarr[3];
2679 int datevars=0, timevars=0;
2681 argarr[0] = arg0;
2682 argarr[1] = arg1;
2683 argarr[2] = arg2;
2685 /* make a debug report */
2686 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2687 "%p with max len %d\n",
2688 locale, flags, tflags,
2689 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2690 debugstr_w(format), format, output, outlen);
2692 if(outlen == 0) {
2693 FIXME("outlen = 0, returning 255\n");
2694 return 255;
2697 /* initialize state variables */
2698 inpos = outpos = 0;
2699 count = 0;
2700 inquote = Overflow = 0;
2701 /* this is really just a sanity check */
2702 output[0] = buf[0] = 0;
2704 /* this loop is the core of the function */
2705 for (inpos = 0; /* we have several break points */ ; inpos++) {
2706 if (inquote) {
2707 if (format[inpos] == (WCHAR) '\'') {
2708 if (format[inpos+1] == '\'') {
2709 inpos++;
2710 output[outpos++] = '\'';
2711 } else {
2712 inquote = 0;
2713 continue;
2715 } else if (format[inpos] == 0) {
2716 output[outpos++] = 0;
2717 if (outpos > outlen) Overflow = 1;
2718 break; /* normal exit (within a quote) */
2719 } else {
2720 output[outpos++] = format[inpos]; /* copy input */
2721 if (outpos > outlen) {
2722 Overflow = 1;
2723 output[outpos-1] = 0;
2724 break;
2727 } else if ( (count && (format[inpos] != type))
2728 || ( (count==4 && type =='y') ||
2729 (count==4 && type =='M') ||
2730 (count==4 && type =='d') ||
2731 (count==2 && type =='g') ||
2732 (count==2 && type =='h') ||
2733 (count==2 && type =='H') ||
2734 (count==2 && type =='m') ||
2735 (count==2 && type =='s') ||
2736 (count==2 && type =='t') ) ) {
2737 if (type == 'd') {
2738 if (count == 3) {
2739 GetLocaleInfoW(locale,
2740 LOCALE_SDAYNAME1 + xtime->wDayOfWeek -1,
2741 buf, sizeof(buf)/sizeof(WCHAR) );
2742 } else if (count == 3) {
2743 GetLocaleInfoW(locale,
2744 LOCALE_SABBREVDAYNAME1 +
2745 xtime->wDayOfWeek -1,
2746 buf, sizeof(buf)/sizeof(WCHAR) );
2747 } else {
2748 wsnprintfW(buf, 5, argarr[count], xtime->wDay );
2750 } else if (type == 'M') {
2751 if (count == 4) {
2752 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
2753 xtime->wMonth -1, buf,
2754 sizeof(buf)/sizeof(WCHAR) );
2755 } else if (count == 3) {
2756 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
2757 xtime->wMonth -1, buf,
2758 sizeof(buf)/sizeof(WCHAR) );
2759 } else {
2760 wsnprintfW(buf, 5, argarr[count], xtime->wMonth);
2762 } else if (type == 'y') {
2763 if (count == 4) {
2764 wsnprintfW(buf, 6, argarr[1] /* "%d" */,
2765 xtime->wYear);
2766 } else if (count == 3) {
2767 lstrcpynAtoW(buf, "yyy", 5);
2768 } else {
2769 wsnprintfW(buf, 6, argarr[count],
2770 xtime->wYear % 100);
2772 } else if (type == 'g') {
2773 if (count == 2) {
2774 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2775 lstrcpynAtoW(buf, "AD", 5);
2776 } else {
2777 /* Win API sez we copy it verbatim */
2778 lstrcpynAtoW(buf, "g", 5);
2780 } else if (type == 'h') {
2781 /* hours 1:00-12:00 --- is this right? */
2782 wsnprintfW(buf, 5, argarr[count],
2783 (xtime->wHour-1)%12 +1);
2784 } else if (type == 'H') {
2785 wsnprintfW(buf, 5, argarr[count],
2786 xtime->wHour);
2787 } else if (type == 'm' ) {
2788 wsnprintfW(buf, 5, argarr[count],
2789 xtime->wMinute);
2790 } else if (type == 's' ) {
2791 wsnprintfW(buf, 5, argarr[count],
2792 xtime->wSecond);
2793 } else if (type == 't') {
2794 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
2795 LOCALE_S1159 : LOCALE_S2359,
2796 buf, sizeof(buf) );
2797 if (count == 1) {
2798 buf[1] = 0;
2802 /* no matter what happened, we need to check this next
2803 character the next time we loop through */
2804 inpos--;
2806 /* cat buf onto the output */
2807 outlen = lstrlenW(buf);
2808 if (outpos + buflen < outlen) {
2809 lstrcpyW( output + outpos, buf );
2810 outpos += buflen;
2811 } else {
2812 lstrcpynW( output + outpos, buf, outlen - outpos );
2813 Overflow = 1;
2814 break; /* Abnormal exit */
2817 /* reset the variables we used this time */
2818 count = 0;
2819 type = '\0';
2820 } else if (format[inpos] == 0) {
2821 /* we can't check for this at the beginning, because that
2822 would keep us from printing a format spec that ended the
2823 string */
2824 output[outpos] = 0;
2825 break; /* NORMAL EXIT */
2826 } else if (count) {
2827 /* how we keep track of the middle of a format spec */
2828 count++;
2829 continue;
2830 } else if ( (datevars && (format[inpos]=='d' ||
2831 format[inpos]=='M' ||
2832 format[inpos]=='y' ||
2833 format[inpos]=='g') ) ||
2834 (timevars && (format[inpos]=='H' ||
2835 format[inpos]=='h' ||
2836 format[inpos]=='m' ||
2837 format[inpos]=='s' ||
2838 format[inpos]=='t') ) ) {
2839 type = format[inpos];
2840 count = 1;
2841 continue;
2842 } else if (format[inpos] == '\'') {
2843 inquote = 1;
2844 continue;
2845 } else {
2846 /* unquoted literals */
2847 output[outpos++] = format[inpos];
2851 if (Overflow) {
2852 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2853 WARN(" buffer overflow\n");
2856 /* final string terminator and sanity check */
2857 outpos++;
2858 if (outpos > outlen-1) outpos = outlen-1;
2859 output[outpos] = '0';
2861 TRACE(" returning %s\n", debugstr_w(output));
2863 return (!Overflow) ? outlen : 0;
2868 /******************************************************************************
2869 * GetDateFormatA [KERNEL32.310]
2870 * Makes an ASCII string of the date
2872 * This function uses format to format the date, or, if format
2873 * is NULL, uses the default for the locale. format is a string
2874 * of literal fields and characters as follows:
2876 * - d single-digit (no leading zero) day (of month)
2877 * - dd two-digit day (of month)
2878 * - ddd short day-of-week name
2879 * - dddd long day-of-week name
2880 * - M single-digit month
2881 * - MM two-digit month
2882 * - MMM short month name
2883 * - MMMM full month name
2884 * - y two-digit year, no leading 0
2885 * - yy two-digit year
2886 * - yyyy four-digit year
2887 * - gg era string
2890 INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
2891 LPSYSTEMTIME xtime,
2892 LPCSTR format, LPSTR date,INT datelen)
2895 char format_buf[40];
2896 LPCSTR thisformat;
2897 SYSTEMTIME t;
2898 LPSYSTEMTIME thistime;
2899 LCID thislocale;
2900 INT ret;
2902 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2903 locale,flags,xtime,format,date,datelen);
2905 if (!locale) {
2906 locale = LOCALE_SYSTEM_DEFAULT;
2909 if (locale == LOCALE_SYSTEM_DEFAULT) {
2910 thislocale = GetSystemDefaultLCID();
2911 } else if (locale == LOCALE_USER_DEFAULT) {
2912 thislocale = GetUserDefaultLCID();
2913 } else {
2914 thislocale = locale;
2917 if (xtime == NULL) {
2918 GetSystemTime(&t);
2919 thistime = &t;
2920 } else {
2921 thistime = xtime;
2924 if (format == NULL) {
2925 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
2926 ? LOCALE_SLONGDATE
2927 : LOCALE_SSHORTDATE),
2928 format_buf, sizeof(format_buf));
2929 thisformat = format_buf;
2930 } else {
2931 thisformat = format;
2935 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
2936 date, datelen);
2939 TRACE(
2940 "GetDateFormatA() returning %d, with data=%s\n",
2941 ret, date);
2942 return ret;
2945 /******************************************************************************
2946 * GetDateFormatW [KERNEL32.311]
2947 * Makes a Unicode string of the date
2949 * Acts the same as GetDateFormatA(), except that it's Unicode.
2950 * Accepts & returns sizes as counts of Unicode characters.
2953 INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
2954 LPSYSTEMTIME xtime,
2955 LPCWSTR format,
2956 LPWSTR date, INT datelen)
2958 unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
2960 FIXME("STUB (should call OLE_GetFormatW)\n");
2961 lstrcpynW(date, datearr, datelen);
2962 return ( datelen < 9) ? datelen : 9;
2967 /**************************************************************************
2968 * EnumDateFormatsA (KERNEL32.198)
2970 BOOL WINAPI EnumDateFormatsA(
2971 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2973 LCID Loc = GetUserDefaultLCID();
2974 if(!lpDateFmtEnumProc)
2976 SetLastError(ERROR_INVALID_PARAMETER);
2977 return FALSE;
2980 switch( Loc )
2983 case 0x00000407: /* (Loc,"de_DE") */
2985 switch(dwFlags)
2987 case DATE_SHORTDATE:
2988 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
2989 if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
2990 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
2991 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
2992 return TRUE;
2993 case DATE_LONGDATE:
2994 if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
2995 if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
2996 if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
2997 return TRUE;
2998 default:
2999 FIXME("Unknown date format (%ld)\n", dwFlags);
3000 SetLastError(ERROR_INVALID_PARAMETER);
3001 return FALSE;
3005 case 0x0000040c: /* (Loc,"fr_FR") */
3007 switch(dwFlags)
3009 case DATE_SHORTDATE:
3010 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3011 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3012 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3013 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3014 return TRUE;
3015 case DATE_LONGDATE:
3016 if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
3017 if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
3018 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3019 return TRUE;
3020 default:
3021 FIXME("Unknown date format (%ld)\n", dwFlags);
3022 SetLastError(ERROR_INVALID_PARAMETER);
3023 return FALSE;
3027 case 0x00000c0c: /* (Loc,"fr_CA") */
3029 switch(dwFlags)
3031 case DATE_SHORTDATE:
3032 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3033 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3034 if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
3035 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3036 return TRUE;
3037 case DATE_LONGDATE:
3038 if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
3039 if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
3040 return TRUE;
3041 default:
3042 FIXME("Unknown date format (%ld)\n", dwFlags);
3043 SetLastError(ERROR_INVALID_PARAMETER);
3044 return FALSE;
3048 case 0x00000809: /* (Loc,"en_UK") */
3050 switch(dwFlags)
3052 case DATE_SHORTDATE:
3053 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3054 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3055 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3056 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3057 return TRUE;
3058 case DATE_LONGDATE:
3059 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3060 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3061 return TRUE;
3062 default:
3063 FIXME("Unknown date format (%ld)\n", dwFlags);
3064 SetLastError(ERROR_INVALID_PARAMETER);
3065 return FALSE;
3069 case 0x00000c09: /* (Loc,"en_AU") */
3071 switch(dwFlags)
3073 case DATE_SHORTDATE:
3074 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3075 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3076 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3077 return TRUE;
3078 case DATE_LONGDATE:
3079 if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
3080 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3081 return TRUE;
3082 default:
3083 FIXME("Unknown date format (%ld)\n", dwFlags);
3084 SetLastError(ERROR_INVALID_PARAMETER);
3085 return FALSE;
3089 case 0x00001009: /* (Loc,"en_CA") */
3091 switch(dwFlags)
3093 case DATE_SHORTDATE:
3094 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3095 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3096 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3097 if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
3098 return TRUE;
3099 case DATE_LONGDATE:
3100 if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
3101 if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
3102 return TRUE;
3103 default:
3104 FIXME("Unknown date format (%ld)\n", dwFlags);
3105 SetLastError(ERROR_INVALID_PARAMETER);
3106 return FALSE;
3110 case 0x00001409: /* (Loc,"en_NZ") */
3112 switch(dwFlags)
3114 case DATE_SHORTDATE:
3115 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3116 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3117 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3118 return TRUE;
3119 case DATE_LONGDATE:
3120 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3121 if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
3122 return TRUE;
3123 default:
3124 FIXME("Unknown date format (%ld)\n", dwFlags);
3125 SetLastError(ERROR_INVALID_PARAMETER);
3126 return FALSE;
3130 case 0x00001809: /* (Loc,"en_IE") */
3132 switch(dwFlags)
3134 case DATE_SHORTDATE:
3135 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3136 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3137 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3138 return TRUE;
3139 case DATE_LONGDATE:
3140 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3141 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3142 return TRUE;
3143 default:
3144 FIXME("Unknown date format (%ld)\n", dwFlags);
3145 SetLastError(ERROR_INVALID_PARAMETER);
3146 return FALSE;
3150 case 0x00001c09: /* (Loc,"en_ZA") */
3152 switch(dwFlags)
3154 case DATE_SHORTDATE:
3155 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3156 return TRUE;
3157 case DATE_LONGDATE:
3158 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3159 return TRUE;
3160 default:
3161 FIXME("Unknown date format (%ld)\n", dwFlags);
3162 SetLastError(ERROR_INVALID_PARAMETER);
3163 return FALSE;
3167 case 0x00002009: /* (Loc,"en_JM") */
3169 switch(dwFlags)
3171 case DATE_SHORTDATE:
3172 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3173 return TRUE;
3174 case DATE_LONGDATE:
3175 if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
3176 if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
3177 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
3178 if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
3179 return TRUE;
3180 default:
3181 FIXME("Unknown date format (%ld)\n", dwFlags);
3182 SetLastError(ERROR_INVALID_PARAMETER);
3183 return FALSE;
3187 case 0x00002809: /* (Loc,"en_BZ") */
3188 case 0x00002c09: /* (Loc,"en_TT") */
3190 switch(dwFlags)
3192 case DATE_SHORTDATE:
3193 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3194 return TRUE;
3195 case DATE_LONGDATE:
3196 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
3197 return TRUE;
3198 default:
3199 FIXME("Unknown date format (%ld)\n", dwFlags);
3200 SetLastError(ERROR_INVALID_PARAMETER);
3201 return FALSE;
3205 default: /* default to US English "en_US" */
3207 switch(dwFlags)
3209 case DATE_SHORTDATE:
3210 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
3211 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
3212 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
3213 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
3214 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3215 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
3216 return TRUE;
3217 case DATE_LONGDATE:
3218 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
3219 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
3220 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
3221 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
3222 return TRUE;
3223 default:
3224 FIXME("Unknown date format (%ld)\n", dwFlags);
3225 SetLastError(ERROR_INVALID_PARAMETER);
3226 return FALSE;
3232 /**************************************************************************
3233 * EnumDateFormatsW (KERNEL32.199)
3235 BOOL WINAPI EnumDateFormatsW(
3236 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3238 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
3239 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3240 return FALSE;
3243 /**************************************************************************
3244 * EnumTimeFormatsA (KERNEL32.210)
3246 BOOL WINAPI EnumTimeFormatsA(
3247 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3249 LCID Loc = GetUserDefaultLCID();
3250 if(!lpTimeFmtEnumProc)
3252 SetLastError(ERROR_INVALID_PARAMETER);
3253 return FALSE;
3255 if(dwFlags)
3257 FIXME("Unknown time format (%ld)\n", dwFlags);
3260 switch( Loc )
3262 case 0x00000407: /* (Loc,"de_DE") */
3264 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3265 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3266 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3267 if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
3268 if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
3269 return TRUE;
3272 case 0x0000040c: /* (Loc,"fr_FR") */
3273 case 0x00000c0c: /* (Loc,"fr_CA") */
3275 if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
3276 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3277 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3278 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3279 if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
3280 return TRUE;
3283 case 0x00000809: /* (Loc,"en_UK") */
3284 case 0x00000c09: /* (Loc,"en_AU") */
3285 case 0x00001409: /* (Loc,"en_NZ") */
3286 case 0x00001809: /* (Loc,"en_IE") */
3288 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3289 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3290 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3291 return TRUE;
3294 case 0x00001c09: /* (Loc,"en_ZA") */
3295 case 0x00002809: /* (Loc,"en_BZ") */
3296 case 0x00002c09: /* (Loc,"en_TT") */
3298 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3299 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3300 return TRUE;
3303 default: /* default to US style "en_US" */
3305 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3306 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3307 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3308 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3309 return TRUE;
3314 /**************************************************************************
3315 * EnumTimeFormatsW (KERNEL32.211)
3317 BOOL WINAPI EnumTimeFormatsW(
3318 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3320 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
3321 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3322 return FALSE;
3325 /**************************************************************************
3326 * This function is used just locally !
3327 * Description: Inverts a string.
3329 static void OLE_InvertString(char* string)
3331 char sTmpArray[128];
3332 INT counter, i = 0;
3334 for (counter = strlen(string); counter > 0; counter--)
3336 memcpy(sTmpArray + i, string + counter-1, 1);
3337 i++;
3339 memcpy(sTmpArray + i, "\0", 1);
3340 strcpy(string, sTmpArray);
3343 /***************************************************************************************
3344 * This function is used just locally !
3345 * Description: Test if the given string (psNumber) is valid or not.
3346 * The valid characters are the following:
3347 * - Characters '0' through '9'.
3348 * - One decimal point (dot) if the number is a floating-point value.
3349 * - A minus sign in the first character position if the number is
3350 * a negative value.
3351 * If the function succeeds, psBefore/psAfter will point to the string
3352 * on the right/left of the decimal symbol. pbNegative indicates if the
3353 * number is negative.
3355 static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
3357 char sNumberSet[] = "0123456789";
3358 BOOL bInDecimal = FALSE;
3360 /* Test if we do have a minus sign */
3361 if ( *pInput == '-' )
3363 *pbNegative = TRUE;
3364 pInput++; /* Jump to the next character. */
3367 while(*pInput != '\0')
3369 /* Do we have a valid numeric character */
3370 if ( strchr(sNumberSet, *pInput) != NULL )
3372 if (bInDecimal == TRUE)
3373 *psAfter++ = *pInput;
3374 else
3375 *psBefore++ = *pInput;
3377 else
3379 /* Is this a decimal point (dot) */
3380 if ( *pInput == '.' )
3382 /* Is it the first time we find it */
3383 if ((bInDecimal == FALSE))
3384 bInDecimal = TRUE;
3385 else
3386 return -1; /* ERROR: Invalid parameter */
3388 else
3390 /* It's neither a numeric character, nor a decimal point.
3391 * Thus, return an error.
3393 return -1;
3396 pInput++;
3399 /* Add an End of Line character to the output buffers */
3400 *psBefore = '\0';
3401 *psAfter = '\0';
3403 return 0;
3406 /**************************************************************************
3407 * This function is used just locally !
3408 * Description: A number could be formatted using different numbers
3409 * of "digits in group" (example: 4;3;2;0).
3410 * The first parameter of this function is an array
3411 * containing the rule to be used. It's format is the following:
3412 * |NDG|DG1|DG2|...|0|
3413 * where NDG is the number of used "digits in group" and DG1, DG2,
3414 * are the corresponding "digits in group".
3415 * Thus, this function returns the grouping value in the array
3416 * pointed by the second parameter.
3418 static INT OLE_GetGrouping(char* sRule, INT index)
3420 char sData[2], sRuleSize[2];
3421 INT nData, nRuleSize;
3423 memcpy(sRuleSize, sRule, 1);
3424 memcpy(sRuleSize+1, "\0", 1);
3425 nRuleSize = atoi(sRuleSize);
3427 if (index > 0 && index < nRuleSize)
3429 memcpy(sData, sRule+index, 1);
3430 memcpy(sData+1, "\0", 1);
3431 nData = atoi(sData);
3434 else
3436 memcpy(sData, sRule+nRuleSize-1, 1);
3437 memcpy(sData+1, "\0", 1);
3438 nData = atoi(sData);
3441 return nData;
3444 /**************************************************************************
3445 * GetNumberFormatA (KERNEL32.355)
3447 INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
3448 LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
3449 LPSTR lpNumberStr, int cchNumber)
3451 char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
3452 INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
3453 char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
3454 char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
3455 char *pStr = NULL, *pTmpStr = NULL;
3456 LCID systemDefaultLCID;
3457 BOOL bNegative = FALSE;
3458 enum Operations
3460 USE_PARAMETER,
3461 USE_LOCALEINFO,
3462 USE_SYSTEMDEFAULT,
3463 RETURN_ERROR
3464 } used_operation;
3466 strncpy(sNumber, lpvalue, 128);
3467 sNumber[127] = '\0';
3469 /* Make sure we have a valid input string, get the number
3470 * of digits before and after the decimal symbol, and check
3471 * if this is a negative number.
3473 if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
3475 nNumberDecimal = strlen(sDigitsBeforeDecimal);
3476 nDigits = strlen(sDigitsAfterDecimal);
3478 else
3480 SetLastError(ERROR_INVALID_PARAMETER);
3481 return 0;
3484 /* Which source will we use to format the string */
3485 used_operation = RETURN_ERROR;
3486 if (lpFormat != NULL)
3488 if (dwflags == 0)
3489 used_operation = USE_PARAMETER;
3491 else
3493 if (dwflags & LOCALE_NOUSEROVERRIDE)
3494 used_operation = USE_LOCALEINFO;
3495 else
3496 used_operation = USE_SYSTEMDEFAULT;
3499 /* Load the fields we need */
3500 switch(used_operation)
3502 case USE_LOCALEINFO:
3503 GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3504 GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3505 GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3506 GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3507 GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3508 GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3509 break;
3510 case USE_PARAMETER:
3511 sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
3512 strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
3513 sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
3514 strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
3515 sprintf(sILZero, "%d",lpFormat->LeadingZero);
3516 sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
3517 break;
3518 case USE_SYSTEMDEFAULT:
3519 systemDefaultLCID = GetSystemDefaultLCID();
3520 GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3521 GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3522 GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3523 GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3524 GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3525 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3526 break;
3527 default:
3528 SetLastError(ERROR_INVALID_PARAMETER);
3529 return 0;
3532 nNumberDigits = atoi(sNumberDigits);
3534 /* Remove the ";" */
3535 i=0;
3536 j = 1;
3537 for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
3539 if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
3541 memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
3542 i++;
3543 j++;
3546 sprintf(sBuffer, "%d", i);
3547 memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3548 memcpy(sRule + j, "\0", 1);
3550 /* First, format the digits before the decimal. */
3551 if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
3553 /* Working on an inverted string is easier ! */
3554 OLE_InvertString(sDigitsBeforeDecimal);
3556 nStep = nCounter = i = j = 0;
3557 nRuleIndex = 1;
3558 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3560 /* Here, we will loop until we reach the end of the string.
3561 * An internal counter (j) is used in order to know when to
3562 * insert the "digit group symbol".
3564 while (nNumberDecimal > 0)
3566 i = nCounter + nStep;
3567 memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
3568 nCounter++;
3569 j++;
3570 if (j >= nGrouping)
3572 j = 0;
3573 if (nRuleIndex < sRule[0])
3574 nRuleIndex++;
3575 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3576 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
3577 nStep+= strlen(sDigitGroupSymbol);
3580 nNumberDecimal--;
3583 memcpy(sDestination + i+1, "\0", 1);
3584 /* Get the string in the right order ! */
3585 OLE_InvertString(sDestination);
3587 else
3589 nLZ = atoi(sILZero);
3590 if (nLZ != 0)
3592 /* Use 0.xxx instead of .xxx */
3593 memcpy(sDestination, "0", 1);
3594 memcpy(sDestination+1, "\0", 1);
3596 else
3597 memcpy(sDestination, "\0", 1);
3601 /* Second, format the digits after the decimal. */
3602 j = 0;
3603 nCounter = nNumberDigits;
3604 if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
3606 i = strlen(sNumber) - strlen(pStr) + 1;
3607 strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
3608 j = strlen(sDigitsAfterDecimal);
3609 if (j < nNumberDigits)
3610 nCounter = nNumberDigits-j;
3612 for (i=0;i<nCounter;i++)
3613 memcpy(sDigitsAfterDecimal+i+j, "0", 1);
3614 memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
3616 i = strlen(sDestination);
3617 j = strlen(sDigitsAfterDecimal);
3618 /* Finally, construct the resulting formatted string. */
3620 for (nCounter=0; nCounter<i; nCounter++)
3621 memcpy(sNumber + nCounter, sDestination + nCounter, 1);
3623 memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
3625 for (i=0; i<j; i++)
3626 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
3627 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
3629 /* Is it a negative number */
3630 if (bNegative == TRUE)
3632 i = atoi(sNegNumber);
3633 pStr = sDestination;
3634 pTmpStr = sNumber;
3635 switch (i)
3637 case 0:
3638 *pStr++ = '(';
3639 while (*sNumber != '\0')
3640 *pStr++ = *pTmpStr++;
3641 *pStr++ = ')';
3642 break;
3643 case 1:
3644 *pStr++ = '-';
3645 while (*pTmpStr != '\0')
3646 *pStr++ = *pTmpStr++;
3647 break;
3648 case 2:
3649 *pStr++ = '-';
3650 *pStr++ = ' ';
3651 while (*pTmpStr != '\0')
3652 *pStr++ = *pTmpStr++;
3653 break;
3654 case 3:
3655 while (*pTmpStr != '\0')
3656 *pStr++ = *pTmpStr++;
3657 *pStr++ = '-';
3658 break;
3659 case 4:
3660 while (*pTmpStr != '\0')
3661 *pStr++ = *pTmpStr++;
3662 *pStr++ = ' ';
3663 *pStr++ = '-';
3664 break;
3665 default:
3666 while (*pTmpStr != '\0')
3667 *pStr++ = *pTmpStr++;
3668 break;
3671 else
3672 strcpy(sDestination, sNumber);
3674 /* If cchNumber is zero, then returns the number of bytes or characters
3675 * required to hold the formatted number string
3677 if (cchNumber==0)
3678 retVal = strlen(sDestination) + 1;
3679 else
3681 strncpy (lpNumberStr, sDestination, cchNumber-1);
3682 *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
3683 retVal = strlen(lpNumberStr);
3686 return retVal;
3689 /**************************************************************************
3690 * GetNumberFormatW (KERNEL32.xxx)
3692 INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
3693 LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
3694 LPWSTR lpNumberStr, int cchNumber)
3696 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue));
3698 lstrcpynW( lpNumberStr, lpvalue, cchNumber );
3699 return cchNumber? lstrlenW( lpNumberStr ) : 0;
3702 /**************************************************************************
3703 * GetCurrencyFormatA (KERNEL32.302)
3705 INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
3706 LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
3707 LPSTR lpCurrencyStr, int cchCurrency)
3709 UINT nPosOrder, nNegOrder;
3710 INT retVal;
3711 char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
3712 char *pDestination = sDestination;
3713 char sNumberFormated[128];
3714 char *pNumberFormated = sNumberFormated;
3715 LCID systemDefaultLCID;
3716 BOOL bIsPositive = FALSE, bValidFormat = FALSE;
3717 enum Operations
3719 USE_PARAMETER,
3720 USE_LOCALEINFO,
3721 USE_SYSTEMDEFAULT,
3722 RETURN_ERROR
3723 } used_operation;
3725 NUMBERFMTA numberFmt;
3727 /* Which source will we use to format the string */
3728 used_operation = RETURN_ERROR;
3729 if (lpFormat != NULL)
3731 if (dwflags == 0)
3732 used_operation = USE_PARAMETER;
3734 else
3736 if (dwflags & LOCALE_NOUSEROVERRIDE)
3737 used_operation = USE_LOCALEINFO;
3738 else
3739 used_operation = USE_SYSTEMDEFAULT;
3742 /* Load the fields we need */
3743 switch(used_operation)
3745 case USE_LOCALEINFO:
3746 /* Specific to CURRENCYFMTA*/
3747 GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3748 GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3749 GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3751 nPosOrder = atoi(sPosOrder);
3752 nNegOrder = atoi(sNegOrder);
3753 break;
3754 case USE_PARAMETER:
3755 /* Specific to CURRENCYFMTA*/
3756 nNegOrder = lpFormat->NegativeOrder;
3757 nPosOrder = lpFormat->PositiveOrder;
3758 strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
3759 break;
3760 case USE_SYSTEMDEFAULT:
3761 systemDefaultLCID = GetSystemDefaultLCID();
3762 /* Specific to CURRENCYFMTA*/
3763 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3764 GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3765 GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3767 nPosOrder = atoi(sPosOrder);
3768 nNegOrder = atoi(sNegOrder);
3769 break;
3770 default:
3771 SetLastError(ERROR_INVALID_PARAMETER);
3772 return 0;
3775 /* Construct a temporary number format structure */
3776 if (lpFormat != NULL)
3778 numberFmt.NumDigits = lpFormat->NumDigits;
3779 numberFmt.LeadingZero = lpFormat->LeadingZero;
3780 numberFmt.Grouping = lpFormat->Grouping;
3781 numberFmt.NegativeOrder = 0;
3782 numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
3783 numberFmt.lpThousandSep = lpFormat->lpThousandSep;
3784 bValidFormat = TRUE;
3787 /* Make a call to GetNumberFormatA() */
3788 if (*lpvalue == '-')
3790 bIsPositive = FALSE;
3791 retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3793 else
3795 bIsPositive = TRUE;
3796 retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3799 if (retVal == 0)
3800 return 0;
3802 /* construct the formatted string */
3803 if (bIsPositive)
3805 switch (nPosOrder)
3807 case 0: /* Prefix, no separation */
3808 strcpy (pDestination, sCurrencySymbol);
3809 strcat (pDestination, pNumberFormated);
3810 break;
3811 case 1: /* Suffix, no separation */
3812 strcpy (pDestination, pNumberFormated);
3813 strcat (pDestination, sCurrencySymbol);
3814 break;
3815 case 2: /* Prefix, 1 char separation */
3816 strcpy (pDestination, sCurrencySymbol);
3817 strcat (pDestination, " ");
3818 strcat (pDestination, pNumberFormated);
3819 break;
3820 case 3: /* Suffix, 1 char separation */
3821 strcpy (pDestination, pNumberFormated);
3822 strcat (pDestination, " ");
3823 strcat (pDestination, sCurrencySymbol);
3824 break;
3825 default:
3826 SetLastError(ERROR_INVALID_PARAMETER);
3827 return 0;
3830 else /* negative number */
3832 switch (nNegOrder)
3834 case 0: /* format: ($1.1) */
3835 strcpy (pDestination, "(");
3836 strcat (pDestination, sCurrencySymbol);
3837 strcat (pDestination, pNumberFormated);
3838 strcat (pDestination, ")");
3839 break;
3840 case 1: /* format: -$1.1 */
3841 strcpy (pDestination, "-");
3842 strcat (pDestination, sCurrencySymbol);
3843 strcat (pDestination, pNumberFormated);
3844 break;
3845 case 2: /* format: $-1.1 */
3846 strcpy (pDestination, sCurrencySymbol);
3847 strcat (pDestination, "-");
3848 strcat (pDestination, pNumberFormated);
3849 break;
3850 case 3: /* format: $1.1- */
3851 strcpy (pDestination, sCurrencySymbol);
3852 strcat (pDestination, pNumberFormated);
3853 strcat (pDestination, "-");
3854 break;
3855 case 4: /* format: (1.1$) */
3856 strcpy (pDestination, "(");
3857 strcat (pDestination, pNumberFormated);
3858 strcat (pDestination, sCurrencySymbol);
3859 strcat (pDestination, ")");
3860 break;
3861 case 5: /* format: -1.1$ */
3862 strcpy (pDestination, "-");
3863 strcat (pDestination, pNumberFormated);
3864 strcat (pDestination, sCurrencySymbol);
3865 break;
3866 case 6: /* format: 1.1-$ */
3867 strcpy (pDestination, pNumberFormated);
3868 strcat (pDestination, "-");
3869 strcat (pDestination, sCurrencySymbol);
3870 break;
3871 case 7: /* format: 1.1$- */
3872 strcpy (pDestination, pNumberFormated);
3873 strcat (pDestination, sCurrencySymbol);
3874 strcat (pDestination, "-");
3875 break;
3876 case 8: /* format: -1.1 $ */
3877 strcpy (pDestination, "-");
3878 strcat (pDestination, pNumberFormated);
3879 strcat (pDestination, " ");
3880 strcat (pDestination, sCurrencySymbol);
3881 break;
3882 case 9: /* format: -$ 1.1 */
3883 strcpy (pDestination, "-");
3884 strcat (pDestination, sCurrencySymbol);
3885 strcat (pDestination, " ");
3886 strcat (pDestination, pNumberFormated);
3887 break;
3888 case 10: /* format: 1.1 $- */
3889 strcpy (pDestination, pNumberFormated);
3890 strcat (pDestination, " ");
3891 strcat (pDestination, sCurrencySymbol);
3892 strcat (pDestination, "-");
3893 break;
3894 case 11: /* format: $ 1.1- */
3895 strcpy (pDestination, sCurrencySymbol);
3896 strcat (pDestination, " ");
3897 strcat (pDestination, pNumberFormated);
3898 strcat (pDestination, "-");
3899 break;
3900 case 12: /* format: $ -1.1 */
3901 strcpy (pDestination, sCurrencySymbol);
3902 strcat (pDestination, " ");
3903 strcat (pDestination, "-");
3904 strcat (pDestination, pNumberFormated);
3905 break;
3906 case 13: /* format: 1.1- $ */
3907 strcpy (pDestination, pNumberFormated);
3908 strcat (pDestination, "-");
3909 strcat (pDestination, " ");
3910 strcat (pDestination, sCurrencySymbol);
3911 break;
3912 case 14: /* format: ($ 1.1) */
3913 strcpy (pDestination, "(");
3914 strcat (pDestination, sCurrencySymbol);
3915 strcat (pDestination, " ");
3916 strcat (pDestination, pNumberFormated);
3917 strcat (pDestination, ")");
3918 break;
3919 case 15: /* format: (1.1 $) */
3920 strcpy (pDestination, "(");
3921 strcat (pDestination, pNumberFormated);
3922 strcat (pDestination, " ");
3923 strcat (pDestination, sCurrencySymbol);
3924 strcat (pDestination, ")");
3925 break;
3926 default:
3927 SetLastError(ERROR_INVALID_PARAMETER);
3928 return 0;
3932 if (cchCurrency == 0)
3933 return strlen(pDestination) + 1;
3935 else
3937 strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
3938 *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
3939 return strlen(lpCurrencyStr);
3943 /**************************************************************************
3944 * GetCurrencyFormatW (KERNEL32.303)
3946 INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
3947 LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
3948 LPWSTR lpCurrencyStr, int cchCurrency)
3950 FIXME("This API function is NOT implemented !\n");
3951 return 0;
3954 /******************************************************************************
3955 * OLE2NLS_CheckLocale [intern]
3957 static LCID OLE2NLS_CheckLocale (LCID locale)
3959 if (!locale)
3960 { locale = LOCALE_SYSTEM_DEFAULT;
3963 if (locale == LOCALE_SYSTEM_DEFAULT)
3964 { return GetSystemDefaultLCID();
3966 else if (locale == LOCALE_USER_DEFAULT)
3967 { return GetUserDefaultLCID();
3969 else
3970 { return locale;
3973 /******************************************************************************
3974 * GetTimeFormatA [KERNEL32.422]
3975 * Makes an ASCII string of the time
3977 * Formats date according to format, or locale default if format is
3978 * NULL. The format consists of literal characters and fields as follows:
3980 * h hours with no leading zero (12-hour)
3981 * hh hours with full two digits
3982 * H hours with no leading zero (24-hour)
3983 * HH hours with full two digits
3984 * m minutes with no leading zero
3985 * mm minutes with full two digits
3986 * s seconds with no leading zero
3987 * ss seconds with full two digits
3988 * t time marker (A or P)
3989 * tt time marker (AM, PM)
3992 INT WINAPI
3993 GetTimeFormatA(LCID locale, /* in */
3994 DWORD flags, /* in */
3995 LPSYSTEMTIME xtime, /* in */
3996 LPCSTR format, /* in */
3997 LPSTR timestr, /* out */
3998 INT timelen /* in */)
3999 { char format_buf[40];
4000 LPCSTR thisformat;
4001 SYSTEMTIME t;
4002 LPSYSTEMTIME thistime;
4003 LCID thislocale=0;
4004 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4005 INT ret;
4007 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
4009 thislocale = OLE2NLS_CheckLocale ( locale );
4011 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
4012 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4015 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
4017 if (format == NULL)
4018 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4019 { thislocale = GetSystemDefaultLCID();
4021 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
4022 thisformat = format_buf;
4024 else
4025 { thisformat = format;
4028 if (xtime == NULL) /* NULL means use the current local time*/
4029 { GetLocalTime(&t);
4030 thistime = &t;
4032 else
4033 { thistime = xtime;
4035 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
4036 timestr, timelen);
4037 return ret;
4041 /******************************************************************************
4042 * GetTimeFormatW [KERNEL32.423]
4043 * Makes a Unicode string of the time
4045 INT WINAPI
4046 GetTimeFormatW(LCID locale, /* in */
4047 DWORD flags, /* in */
4048 LPSYSTEMTIME xtime, /* in */
4049 LPCWSTR format, /* in */
4050 LPWSTR timestr, /* out */
4051 INT timelen /* in */)
4052 { WCHAR format_buf[40];
4053 LPCWSTR thisformat;
4054 SYSTEMTIME t;
4055 LPSYSTEMTIME thistime;
4056 LCID thislocale=0;
4057 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4058 INT ret;
4060 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
4061 xtime,debugstr_w(format),timestr,timelen);
4063 thislocale = OLE2NLS_CheckLocale ( locale );
4065 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
4066 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4069 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
4071 if (format == NULL)
4072 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4073 { thislocale = GetSystemDefaultLCID();
4075 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
4076 thisformat = format_buf;
4078 else
4079 { thisformat = format;
4082 if (xtime == NULL) /* NULL means use the current local time*/
4083 { GetSystemTime(&t);
4084 thistime = &t;
4086 else
4087 { thistime = xtime;
4090 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
4091 timestr, timelen);
4092 return ret;
4095 /******************************************************************************
4096 * EnumCalendarInfoA [KERNEL32.196]
4098 BOOL WINAPI EnumCalendarInfoA(
4099 CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
4101 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);
4102 return FALSE;