Fixed bug in SwitchStackTo.
[wine/multimedia.git] / ole / ole2nls.c
blob9b3331b7ab7d649bb569ebd8a0f1a2055d01c574
1 /*
2 * OLE2NLS library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 */
8 #include <string.h>
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include "windows.h"
12 #include "heap.h"
13 #include "ole.h"
14 #include "options.h"
15 #include "winnls.h"
16 #include "winreg.h"
17 #include "winerror.h"
18 #include "debug.h"
19 #include "main.h"
21 /* Locale name to id map. used by EnumSystemLocales, GetLocalInfoA
22 * MUST contain all #defines from winnls.h
23 * last entry has NULL name, 0 id.
24 */
25 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
26 static struct tagLOCALE_NAME2ID {
27 char *name;
28 DWORD id;
29 } locale_name2id[]= {
30 LOCALE_ENTRY(ILANGUAGE),
31 LOCALE_ENTRY(SLANGUAGE),
32 LOCALE_ENTRY(SENGLANGUAGE),
33 LOCALE_ENTRY(SABBREVLANGNAME),
34 LOCALE_ENTRY(SNATIVELANGNAME),
35 LOCALE_ENTRY(ICOUNTRY),
36 LOCALE_ENTRY(SCOUNTRY),
37 LOCALE_ENTRY(SENGCOUNTRY),
38 LOCALE_ENTRY(SABBREVCTRYNAME),
39 LOCALE_ENTRY(SNATIVECTRYNAME),
40 LOCALE_ENTRY(IDEFAULTLANGUAGE),
41 LOCALE_ENTRY(IDEFAULTCOUNTRY),
42 LOCALE_ENTRY(IDEFAULTCODEPAGE),
43 LOCALE_ENTRY(IDEFAULTANSICODEPAGE),
44 LOCALE_ENTRY(IDEFAULTMACCODEPAGE),
45 LOCALE_ENTRY(SLIST),
46 LOCALE_ENTRY(IMEASURE),
47 LOCALE_ENTRY(SDECIMAL),
48 LOCALE_ENTRY(STHOUSAND),
49 LOCALE_ENTRY(SGROUPING),
50 LOCALE_ENTRY(IDIGITS),
51 LOCALE_ENTRY(ILZERO),
52 LOCALE_ENTRY(INEGNUMBER),
53 LOCALE_ENTRY(SNATIVEDIGITS),
54 LOCALE_ENTRY(SCURRENCY),
55 LOCALE_ENTRY(SINTLSYMBOL),
56 LOCALE_ENTRY(SMONDECIMALSEP),
57 LOCALE_ENTRY(SMONTHOUSANDSEP),
58 LOCALE_ENTRY(SMONGROUPING),
59 LOCALE_ENTRY(ICURRDIGITS),
60 LOCALE_ENTRY(IINTLCURRDIGITS),
61 LOCALE_ENTRY(ICURRENCY),
62 LOCALE_ENTRY(INEGCURR),
63 LOCALE_ENTRY(SDATE),
64 LOCALE_ENTRY(STIME),
65 LOCALE_ENTRY(SSHORTDATE),
66 LOCALE_ENTRY(SLONGDATE),
67 LOCALE_ENTRY(STIMEFORMAT),
68 LOCALE_ENTRY(IDATE),
69 LOCALE_ENTRY(ILDATE),
70 LOCALE_ENTRY(ITIME),
71 LOCALE_ENTRY(ITIMEMARKPOSN),
72 LOCALE_ENTRY(ICENTURY),
73 LOCALE_ENTRY(ITLZERO),
74 LOCALE_ENTRY(IDAYLZERO),
75 LOCALE_ENTRY(IMONLZERO),
76 LOCALE_ENTRY(S1159),
77 LOCALE_ENTRY(S2359),
78 LOCALE_ENTRY(ICALENDARTYPE),
79 LOCALE_ENTRY(IOPTIONALCALENDAR),
80 LOCALE_ENTRY(IFIRSTDAYOFWEEK),
81 LOCALE_ENTRY(IFIRSTWEEKOFYEAR),
82 LOCALE_ENTRY(SDAYNAME1),
83 LOCALE_ENTRY(SDAYNAME2),
84 LOCALE_ENTRY(SDAYNAME3),
85 LOCALE_ENTRY(SDAYNAME4),
86 LOCALE_ENTRY(SDAYNAME5),
87 LOCALE_ENTRY(SDAYNAME6),
88 LOCALE_ENTRY(SDAYNAME7),
89 LOCALE_ENTRY(SABBREVDAYNAME1),
90 LOCALE_ENTRY(SABBREVDAYNAME2),
91 LOCALE_ENTRY(SABBREVDAYNAME3),
92 LOCALE_ENTRY(SABBREVDAYNAME4),
93 LOCALE_ENTRY(SABBREVDAYNAME5),
94 LOCALE_ENTRY(SABBREVDAYNAME6),
95 LOCALE_ENTRY(SABBREVDAYNAME7),
96 LOCALE_ENTRY(SMONTHNAME1),
97 LOCALE_ENTRY(SMONTHNAME2),
98 LOCALE_ENTRY(SMONTHNAME3),
99 LOCALE_ENTRY(SMONTHNAME4),
100 LOCALE_ENTRY(SMONTHNAME5),
101 LOCALE_ENTRY(SMONTHNAME6),
102 LOCALE_ENTRY(SMONTHNAME7),
103 LOCALE_ENTRY(SMONTHNAME8),
104 LOCALE_ENTRY(SMONTHNAME9),
105 LOCALE_ENTRY(SMONTHNAME10),
106 LOCALE_ENTRY(SMONTHNAME11),
107 LOCALE_ENTRY(SMONTHNAME12),
108 LOCALE_ENTRY(SMONTHNAME13),
109 LOCALE_ENTRY(SABBREVMONTHNAME1),
110 LOCALE_ENTRY(SABBREVMONTHNAME2),
111 LOCALE_ENTRY(SABBREVMONTHNAME3),
112 LOCALE_ENTRY(SABBREVMONTHNAME4),
113 LOCALE_ENTRY(SABBREVMONTHNAME5),
114 LOCALE_ENTRY(SABBREVMONTHNAME6),
115 LOCALE_ENTRY(SABBREVMONTHNAME7),
116 LOCALE_ENTRY(SABBREVMONTHNAME8),
117 LOCALE_ENTRY(SABBREVMONTHNAME9),
118 LOCALE_ENTRY(SABBREVMONTHNAME10),
119 LOCALE_ENTRY(SABBREVMONTHNAME11),
120 LOCALE_ENTRY(SABBREVMONTHNAME12),
121 LOCALE_ENTRY(SABBREVMONTHNAME13),
122 LOCALE_ENTRY(SPOSITIVESIGN),
123 LOCALE_ENTRY(SNEGATIVESIGN),
124 LOCALE_ENTRY(IPOSSIGNPOSN),
125 LOCALE_ENTRY(INEGSIGNPOSN),
126 LOCALE_ENTRY(IPOSSYMPRECEDES),
127 LOCALE_ENTRY(IPOSSEPBYSPACE),
128 LOCALE_ENTRY(INEGSYMPRECEDES),
129 LOCALE_ENTRY(INEGSEPBYSPACE),
130 LOCALE_ENTRY(FONTSIGNATURE),
131 LOCALE_ENTRY(SISO639LANGNAME),
132 LOCALE_ENTRY(SISO3166CTRYNAME),
133 {NULL,0},
136 const struct map_lcid2str {
137 LCID langid;
138 const char *langname;
139 } languages[]={
140 {0x0401,"Arabic (Saudi Arabia)"},
141 {0x0801,"Arabic (Iraq)"},
142 {0x0c01,"Arabic (Egypt)"},
143 {0x1001,"Arabic (Libya)"},
144 {0x1401,"Arabic (Algeria)"},
145 {0x1801,"Arabic (Morocco)"},
146 {0x1c01,"Arabic (Tunisia)"},
147 {0x2001,"Arabic (Oman)"},
148 {0x2401,"Arabic (Yemen)"},
149 {0x2801,"Arabic (Syria)"},
150 {0x2c01,"Arabic (Jordan)"},
151 {0x3001,"Arabic (Lebanon)"},
152 {0x3401,"Arabic (Kuwait)"},
153 {0x3801,"Arabic (United Arab Emirates)"},
154 {0x3c01,"Arabic (Bahrain)"},
155 {0x4001,"Arabic (Qatar)"},
156 {0x0402,"Bulgarian"},
157 {0x0403,"Catalan"},
158 {0x0404,"Chinese (Taiwan)"},
159 {0x0804,"Chinese (People's Republic of China)"},
160 {0x0c04,"Chinese (Hong Kong)"},
161 {0x1004,"Chinese (Singapore)"},
162 {0x1404,"Chinese (Macau)"},
163 {0x0405,"Czech"},
164 {0x0406,"Danish"},
165 {0x0407,"German (Germany)"},
166 {0x0807,"German (Switzerland)"},
167 {0x0c07,"German (Austria)"},
168 {0x1007,"German (Luxembourg)"},
169 {0x1407,"German (Liechtenstein)"},
170 {0x0408,"Greek"},
171 {0x0409,"English (United States)"},
172 {0x0809,"English (United Kingdom)"},
173 {0x0c09,"English (Australia)"},
174 {0x1009,"English (Canada)"},
175 {0x1409,"English (New Zealand)"},
176 {0x1809,"English (Ireland)"},
177 {0x1c09,"English (South Africa)"},
178 {0x2009,"English (Jamaica)"},
179 {0x2409,"English (Caribbean)"},
180 {0x2809,"English (Belize)"},
181 {0x2c09,"English (Trinidad)"},
182 {0x3009,"English (Zimbabwe)"},
183 {0x3409,"English (Philippines)"},
184 {0x040a,"Spanish (Spain, traditional sorting)"},
185 {0x080a,"Spanish (Mexico)"},
186 {0x0c0a,"Spanish (Spain, international sorting)"},
187 {0x100a,"Spanish (Guatemala)"},
188 {0x140a,"Spanish (Costa Rica)"},
189 {0x180a,"Spanish (Panama)"},
190 {0x1c0a,"Spanish (Dominican Republic)"},
191 {0x200a,"Spanish (Venezuela)"},
192 {0x240a,"Spanish (Colombia)"},
193 {0x280a,"Spanish (Peru)"},
194 {0x2c0a,"Spanish (Argentina)"},
195 {0x300a,"Spanish (Ecuador)"},
196 {0x340a,"Spanish (Chile)"},
197 {0x380a,"Spanish (Uruguay)"},
198 {0x3c0a,"Spanish (Paraguay)"},
199 {0x400a,"Spanish (Bolivia)"},
200 {0x440a,"Spanish (El Salvador)"},
201 {0x480a,"Spanish (Honduras)"},
202 {0x4c0a,"Spanish (Nicaragua)"},
203 {0x500a,"Spanish (Puerto Rico)"},
204 {0x040b,"Finnish"},
205 {0x040c,"French (France)"},
206 {0x080c,"French (Belgium)"},
207 {0x0c0c,"French (Canada)"},
208 {0x100c,"French (Switzerland)"},
209 {0x140c,"French (Luxembourg)"},
210 {0x180c,"French (Monaco)"},
211 {0x040d,"Hebrew"},
212 {0x040e,"Hungarian"},
213 {0x040f,"Icelandic"},
214 {0x0410,"Italian (Italy)"},
215 {0x0810,"Italian (Switzerland)"},
216 {0x0411,"Japanese"},
217 {0x0412,"Korean (Wansung)"},
218 {0x0812,"Korean (Johab)"},
219 {0x0413,"Dutch (Netherlands)"},
220 {0x0813,"Dutch (Belgium)"},
221 {0x0414,"Norwegian (Bokmal)"},
222 {0x0814,"Norwegian (Nynorsk)"},
223 {0x0415,"Polish"},
224 {0x0416,"Portuguese (Brazil)"},
225 {0x0816,"Portuguese (Portugal)"},
226 {0x0417,"Rhaeto Romanic"},
227 {0x0418,"Romanian"},
228 {0x0818,"Moldavian"},
229 {0x0419,"Russian (Russia)"},
230 {0x0819,"Russian (Moldavia)"},
231 {0x041a,"Croatian"},
232 {0x081a,"Serbian (latin)"},
233 {0x0c1a,"Serbian (cyrillic)"},
234 {0x041b,"Slovak"},
235 {0x041c,"Albanian"},
236 {0x041d,"Swedish (Sweden)"},
237 {0x081d,"Swedish (Finland)"},
238 {0x041e,"Thai"},
239 {0x041f,"Turkish"},
240 {0x0420,"Urdu"},
241 {0x0421,"Indonesian"},
242 {0x0422,"Ukrainian"},
243 {0x0423,"Belarusian"},
244 {0x0424,"Slovene"},
245 {0x0425,"Estonian"},
246 {0x0426,"Latvian"},
247 {0x0427,"Lithuanian (modern)"},
248 {0x0827,"Lithuanian (classic)"},
249 {0x0428,"Maori"},
250 {0x0429,"Farsi"},
251 {0x042a,"Vietnamese"},
252 {0x042b,"Armenian"},
253 {0x042c,"Azeri (latin)"},
254 {0x082c,"Azeri (cyrillic)"},
255 {0x042d,"Basque"},
256 {0x042e,"Sorbian"},
257 {0x042f,"Macedonian"},
258 {0x0430,"Sutu"},
259 {0x0431,"Tsonga"},
260 {0x0432,"Tswana"},
261 {0x0433,"Venda"},
262 {0x0434,"Xhosa"},
263 {0x0435,"Zulu"},
264 {0x0436,"Afrikaans"},
265 {0x0437,"Georgian"},
266 {0x0438,"Faeroese"},
267 {0x0439,"Hindi"},
268 {0x043a,"Maltese"},
269 {0x043b,"Saami"},
270 {0x043c,"Irish gaelic"},
271 {0x083c,"Scottish gaelic"},
272 {0x043e,"Malay (Malaysia)"},
273 {0x083e,"Malay (Brunei Darussalam)"},
274 {0x043f,"Kazak"},
275 {0x0441,"Swahili"},
276 {0x0443,"Uzbek (latin)"},
277 {0x0843,"Uzbek (cyrillic)"},
278 {0x0444,"Tatar"},
279 {0x0445,"Bengali"},
280 {0x0446,"Punjabi"},
281 {0x0447,"Gujarati"},
282 {0x0448,"Oriya"},
283 {0x0449,"Tamil"},
284 {0x044a,"Telugu"},
285 {0x044b,"Kannada"},
286 {0x044c,"Malayalam"},
287 {0x044d,"Assamese"},
288 {0x044e,"Marathi"},
289 {0x044f,"Sanskrit"},
290 {0x0457,"Konkani"},
291 {0x048f,"Esperanto"}, /* Non official */
292 {0x0000,"Unknown"}
293 }, languages_de[]={
294 {0x0401,"Arabic"},
295 {0x0402,"Bulgarisch"},
296 {0x0403,"Katalanisch"},
297 {0x0404,"Traditionales Chinesisch"},
298 {0x0405,"Tschecisch"},
299 {0x0406,"Dänisch"},
300 {0x0407,"Deutsch"},
301 {0x0408,"Griechisch"},
302 {0x0409,"Amerikanisches Englisch"},
303 {0x040A,"Kastilisches Spanisch"},
304 {0x040B,"Finnisch"},
305 {0x040C,"Franzvsisch"},
306 {0x040D,"Hebrdisch"},
307 {0x040E,"Ungarisch"},
308 {0x040F,"Isldndisch"},
309 {0x0410,"Italienisch"},
310 {0x0411,"Japanisch"},
311 {0x0412,"Koreanisch"},
312 {0x0413,"Niederldndisch"},
313 {0x0414,"Norwegisch-Bokmal"},
314 {0x0415,"Polnisch"},
315 {0x0416,"Brasilianisches Portugiesisch"},
316 {0x0417,"Rdtoromanisch"},
317 {0x0418,"Rumdnisch"},
318 {0x0419,"Russisch"},
319 {0x041A,"Kroatoserbisch (lateinisch)"},
320 {0x041B,"Slowenisch"},
321 {0x041C,"Albanisch"},
322 {0x041D,"Schwedisch"},
323 {0x041E,"Thai"},
324 {0x041F,"Türkisch"},
325 {0x0420,"Urdu"},
326 {0x0421,"Bahasa"},
327 {0x0804,"Vereinfachtes Chinesisch"},
328 {0x0807,"Schweizerdeutsch"},
329 {0x0809,"Britisches Englisch"},
330 {0x080A,"Mexikanisches Spanisch"},
331 {0x080C,"Belgisches Franzvsisch"},
332 {0x0810,"Schweizerisches Italienisch"},
333 {0x0813,"Belgisches Niederldndisch"},
334 {0x0814,"Norgwegisch-Nynorsk"},
335 {0x0816,"Portugiesisch"},
336 {0x081A,"Serbokratisch (kyrillisch)"},
337 {0x0C1C,"Kanadisches Franzvsisch"},
338 {0x100C,"Schweizerisches Franzvsisch"},
339 {0x0000,"Unbekannt"},
342 /***********************************************************************
343 * GetUserDefaultLCID (OLE2NLS.1)
345 LCID WINAPI GetUserDefaultLCID()
347 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT );
350 /***********************************************************************
351 * GetSystemDefaultLCID (OLE2NLS.2)
353 LCID WINAPI GetSystemDefaultLCID()
355 return GetUserDefaultLCID();
358 /***********************************************************************
359 * GetUserDefaultLangID (OLE2NLS.3)
361 LANGID WINAPI GetUserDefaultLangID()
363 /* caching result, if defined from environment, which should (?) not change during a WINE session */
364 static LANGID userLCID = 0;
365 if (Options.language) {
366 return Languages[Options.language].langid;
369 if (userLCID == 0) {
370 char *buf=NULL;
371 char *lang,*country,*charset,*dialect,*next;
372 int ret=0;
374 buf=getenv("LANGUAGE");
375 if (!buf) buf=getenv("LANG");
376 if (!buf) buf=getenv("LC_ALL");
377 if (!buf) buf=getenv("LC_MESSAGES");
378 if (!buf) return userLCID = MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT );
380 if (!strcmp(buf,"POSIX") || !strcmp(buf,"C")) {
381 return MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT );
384 lang=buf;
386 do {
387 next=strchr(lang,':'); if (next) *next++='\0';
388 dialect=strchr(lang,'@'); if (dialect) *dialect++='\0';
389 charset=strchr(lang,'.'); if (charset) *charset++='\0';
390 country=strchr(lang,'_'); if (country) *country++='\0';
392 ret=MAIN_GetLanguageID(lang, country, charset, dialect);
394 lang=next;
396 } while (lang && !ret);
398 /* FIXME : are strings returned by getenv() to be free()'ed ? */
399 userLCID = (LANGID)ret;
401 return userLCID;
404 /***********************************************************************
405 * GetSystemDefaultLangID (OLE2NLS.4)
407 LANGID WINAPI GetSystemDefaultLangID()
409 return GetUserDefaultLangID();
412 /******************************************************************************
413 * GetLocaleInfo16 [OLE2NLS.5]
414 * Is the last parameter really WORD for Win16?
416 INT16 WINAPI GetLocaleInfo16(LCID lcid,LCTYPE LCType,LPSTR buf,INT16 len)
418 return GetLocaleInfo32A(lcid,LCType,buf,len);
421 /******************************************************************************
422 * GetLocaleInfo32A [KERNEL32.342]
424 INT32 WINAPI GetLocaleInfo32A(LCID lcid,LCTYPE LCType,LPSTR buf,INT32 len)
426 char *retString;
427 int found,i;
428 int lang=0;
430 TRACE(ole,"(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",
431 lcid,LCType,buf,len);
433 if (len && (! buf) )
434 { SetLastError(ERROR_INSUFFICIENT_BUFFER);
435 return 0;
438 if (lcid == LOCALE_SYSTEM_DEFAULT || (LCType & LOCALE_NOUSEROVERRIDE) )
439 { lcid = GetSystemDefaultLCID();
441 else if (lcid == LOCALE_USER_DEFAULT)
442 { lcid = GetUserDefaultLCID();
445 LCType &= ~(LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP);
447 /* As an option, we could obtain the value from win.ini.
448 This would not match the Wine compile-time option.
449 Also, not all identifiers are available from win.ini */
450 retString=0;
451 /* If we are through all of this, retLen should not be zero anymore.
452 If it is, the value is not supported */
453 i=0;
454 while (locale_name2id[i].name!=NULL) {
455 if (LCType == locale_name2id[i].id) {
456 retString = locale_name2id[i].name;
457 break;
459 i++;
461 if (!retString) {
462 WARN(ole,"Unkown LC type %lX\n",LCType);
463 return 0;
466 #define LOCVAL(type,value) case type:retString=value;found=1;break;
467 #define LANG_BEGIN(l,s) case MAKELANGID(l,s): switch (LCType) {
468 #define LANG_END default: found=0; break; } break;
470 /* Now, the language specific definitions. They don't have to be
471 complete */
473 found=0; i=0; lang=lcid;
475 if (lang ==0x400) /*LANG_NEUTRAL ==> US English*/
476 { lang = 0x409;
477 WARN(ole,"no language set, assume LANG_ENGLISH_US \n");
482 { switch(lang)
485 LANG_BEGIN (LANG_GERMAN, SUBLANG_GERMAN) /*0x407*/
486 #include "nls/deu.nls"
487 LANG_END
489 LANG_BEGIN (LANG_DANISH, SUBLANG_DEFAULT) /*0x406*/
490 #include "nls/dan.nls"
491 LANG_END
493 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_US) /*0x409*/
494 #include "nls/enu.nls"
495 LANG_END
497 LANG_BEGIN (LANG_ESPERANTO, SUBLANG_DEFAULT) /*0x48f*/
498 #include "nls/esperanto.nls"
499 LANG_END
501 LANG_BEGIN (LANG_FINNISH, SUBLANG_DEFAULT) /*0x040B*/
502 #include "nls/fin.nls"
503 LANG_END
505 LANG_BEGIN (LANG_FRENCH, SUBLANG_DEFAULT) /*0x040C*/
506 #include "nls/fra.nls"
507 LANG_END
509 LANG_BEGIN (LANG_ITALIAN, SUBLANG_ITALIAN) /*0x410*/
510 #include "nls/ita.nls"
511 LANG_END
513 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_UK) /*0x809*/
514 #include "nls/eng.nls"
515 LANG_END
517 LANG_BEGIN (LANG_KOREAN, SUBLANG_KOREAN) /*0x412*/
518 #include "nls/kor.nls"
519 LANG_END
521 LANG_BEGIN (LANG_HUNGARIAN, SUBLANG_DEFAULT) /*0x40e*/
522 #include "nls/hun.nls"
523 LANG_END
525 LANG_BEGIN (LANG_POLISH, SUBLANG_DEFAULT) /*0x415*/
526 #include "nls/plk.nls"
527 LANG_END
529 LANG_BEGIN (LANG_PORTUGUESE ,SUBLANG_PORTUGUESE_BRAZILIAN) /*0x416*/
530 #include "nls/ptb.nls"
531 LANG_END
533 LANG_BEGIN (LANG_SWEDISH, SUBLANG_DEFAULT) /*0x41d*/
534 #include "nls/sve.nls"
535 LANG_END
537 /*Insert other languages here*/
539 default:
540 found=0;
541 break;
542 } /* switch */
545 /* language not found, try without a sublanguage*/
546 if (i==1) lang=MAKELANGID( PRIMARYLANGID(lang), SUBLANG_DEFAULT);
548 /* mask the LC Value */
549 if (i==2) LCType &= 0xfff;
551 i++;
552 } while (!found && i<3);
554 if(!found)
555 { ERR(ole,"'%s' not supported for your language.\n", retString);
556 SetLastError(ERROR_INVALID_PARAMETER);
557 return 0;
559 /* if len=0 return only the length, don't touch the buffer*/
560 if (len)
561 lstrcpyn32A(buf,retString,len);
563 return strlen(retString)+1;
566 /******************************************************************************
567 * GetLocaleInfo32W [KERNEL32.343]
570 INT32 WINAPI GetLocaleInfo32W(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT32 len)
571 { WORD wlen;
572 LPSTR abuf;
574 if (len && (! wbuf) )
575 { SetLastError(ERROR_INSUFFICIENT_BUFFER);
576 return 0;
579 abuf = (LPSTR)HeapAlloc(GetProcessHeap(),0,len);
580 wlen = 2 * GetLocaleInfo32A(lcid, LCType, abuf, len);
582 if (wlen && len) /* if len=0 return only the length*/
583 lstrcpynAtoW(wbuf,abuf,len/2);
585 HeapFree(GetProcessHeap(),0,abuf);
586 return wlen;
589 /******************************************************************************
590 * SetLocaleInfoA [KERNEL32.656]
592 BOOL16 WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
594 FIXME(ole,"(%ld,%ld,%s): stub\n",lcid,lctype,data);
595 return TRUE;
598 /******************************************************************************
599 * IsValidLocale [KERNEL32.489]
601 BOOL32 WINAPI IsValidLocale(LCID lcid,DWORD flags)
603 /* we support ANY language. Well, at least say that...*/
604 return TRUE;
607 /******************************************************************************
608 * EnumSystemLocales32W [KERNEL32.209]
610 BOOL32 WINAPI EnumSystemLocales32W( LOCALE_ENUMPROC32W lpfnLocaleEnum,
611 DWORD flags )
613 int i;
614 BOOL32 ret;
615 WCHAR buffer[200];
616 HKEY xhkey;
618 TRACE(win32,"(%p,%08lx)\n",lpfnLocaleEnum,flags );
619 /* see if we can reuse the Win95 registry entries.... */
620 if (ERROR_SUCCESS==RegOpenKey32A(HKEY_LOCAL_MACHINE,"\\System\\CurrentControlSet\\control\\Nls\\Locale\\",&xhkey)) {
621 i=0;
622 while (1) {
623 if (ERROR_SUCCESS!=RegEnumKey32W(xhkey,i,buffer,sizeof(buffer)))
624 break;
625 if (!lpfnLocaleEnum(buffer))
626 break;
627 i++;
629 RegCloseKey(xhkey);
630 return TRUE;
633 i=0;
634 while (languages[i].langname!=NULL)
636 LPWSTR cp;
637 char xbuffer[10];
639 sprintf(xbuffer,"%08lx",(DWORD)languages[i].langid);
641 cp = HEAP_strdupAtoW( GetProcessHeap(), 0, xbuffer );
642 ret = lpfnLocaleEnum(cp);
643 HeapFree( GetProcessHeap(), 0, cp );
644 if (!ret) break;
645 i++;
647 return TRUE;
650 /******************************************************************************
651 * EnumSystemLocales32A [KERNEL32.208]
653 BOOL32 WINAPI EnumSystemLocales32A(LOCALE_ENUMPROC32A lpfnLocaleEnum,
654 DWORD flags)
656 int i;
657 CHAR buffer[200];
658 HKEY xhkey;
660 TRACE(win32,"(%p,%08lx)\n",
661 lpfnLocaleEnum,flags
663 if (ERROR_SUCCESS==RegOpenKey32A(HKEY_LOCAL_MACHINE,"\\System\\CurrentControlSet\\control\\Nls\\Locale\\",&xhkey)) {
664 i=0;
665 while (1) {
666 if (ERROR_SUCCESS!=RegEnumKey32A(xhkey,i,buffer,sizeof(buffer)))
667 break;
668 if (!lpfnLocaleEnum(buffer))
669 break;
670 i++;
672 RegCloseKey(xhkey);
673 return TRUE;
675 i=0;
676 while (languages[i].langname!=NULL) {
677 sprintf(buffer,"%08lx",(DWORD)languages[i].langid);
678 if (!lpfnLocaleEnum(buffer))
679 break;
680 i++;
682 return TRUE;
685 static const unsigned char CT_CType2_LUT[] = {
686 C2_NOTAPPLICABLE, /* - 0 */
687 C2_NOTAPPLICABLE, /* - 1 */
688 C2_NOTAPPLICABLE, /* - 2 */
689 C2_NOTAPPLICABLE, /* - 3 */
690 C2_NOTAPPLICABLE, /* - 4 */
691 C2_NOTAPPLICABLE, /* - 5 */
692 C2_NOTAPPLICABLE, /* - 6 */
693 C2_NOTAPPLICABLE, /* - 7 */
694 C2_NOTAPPLICABLE, /* - 8 */
695 C2_SEGMENTSEPARATOR, /* - 9 */
696 C2_NOTAPPLICABLE, /* - 10 */
697 C2_NOTAPPLICABLE, /* - 11 */
698 C2_NOTAPPLICABLE, /* - 12 */
699 C2_NOTAPPLICABLE, /* - 13 */
700 C2_NOTAPPLICABLE, /* - 14 */
701 C2_NOTAPPLICABLE, /* - 15 */
702 C2_NOTAPPLICABLE, /* - 16 */
703 C2_NOTAPPLICABLE, /* - 17 */
704 C2_NOTAPPLICABLE, /* - 18 */
705 C2_NOTAPPLICABLE, /* - 19 */
706 C2_NOTAPPLICABLE, /* - 20 */
707 C2_NOTAPPLICABLE, /* - 21 */
708 C2_NOTAPPLICABLE, /* - 22 */
709 C2_NOTAPPLICABLE, /* - 23 */
710 C2_NOTAPPLICABLE, /* - 24 */
711 C2_NOTAPPLICABLE, /* - 25 */
712 C2_NOTAPPLICABLE, /* - 26 */
713 C2_NOTAPPLICABLE, /* - 27 */
714 C2_NOTAPPLICABLE, /* - 28 */
715 C2_NOTAPPLICABLE, /* - 29 */
716 C2_NOTAPPLICABLE, /* - 30 */
717 C2_NOTAPPLICABLE, /* - 31 */
718 C2_WHITESPACE, /* - 32 */
719 C2_OTHERNEUTRAL, /* ! - 33 */
720 C2_OTHERNEUTRAL, /* " - 34 */ /* " */
721 C2_EUROPETERMINATOR, /* # - 35 */
722 C2_EUROPETERMINATOR, /* $ - 36 */
723 C2_EUROPETERMINATOR, /* % - 37 */
724 C2_LEFTTORIGHT, /* & - 38 */
725 C2_OTHERNEUTRAL, /* ' - 39 */
726 C2_OTHERNEUTRAL, /* ( - 40 */
727 C2_OTHERNEUTRAL, /* ) - 41 */
728 C2_OTHERNEUTRAL, /* * - 42 */
729 C2_EUROPETERMINATOR, /* + - 43 */
730 C2_COMMONSEPARATOR, /* , - 44 */
731 C2_EUROPETERMINATOR, /* - - 45 */
732 C2_EUROPESEPARATOR, /* . - 46 */
733 C2_EUROPESEPARATOR, /* / - 47 */
734 C2_EUROPENUMBER, /* 0 - 48 */
735 C2_EUROPENUMBER, /* 1 - 49 */
736 C2_EUROPENUMBER, /* 2 - 50 */
737 C2_EUROPENUMBER, /* 3 - 51 */
738 C2_EUROPENUMBER, /* 4 - 52 */
739 C2_EUROPENUMBER, /* 5 - 53 */
740 C2_EUROPENUMBER, /* 6 - 54 */
741 C2_EUROPENUMBER, /* 7 - 55 */
742 C2_EUROPENUMBER, /* 8 - 56 */
743 C2_EUROPENUMBER, /* 9 - 57 */
744 C2_COMMONSEPARATOR, /* : - 58 */
745 C2_OTHERNEUTRAL, /* ; - 59 */
746 C2_OTHERNEUTRAL, /* < - 60 */
747 C2_OTHERNEUTRAL, /* = - 61 */
748 C2_OTHERNEUTRAL, /* > - 62 */
749 C2_OTHERNEUTRAL, /* ? - 63 */
750 C2_LEFTTORIGHT, /* @ - 64 */
751 C2_LEFTTORIGHT, /* A - 65 */
752 C2_LEFTTORIGHT, /* B - 66 */
753 C2_LEFTTORIGHT, /* C - 67 */
754 C2_LEFTTORIGHT, /* D - 68 */
755 C2_LEFTTORIGHT, /* E - 69 */
756 C2_LEFTTORIGHT, /* F - 70 */
757 C2_LEFTTORIGHT, /* G - 71 */
758 C2_LEFTTORIGHT, /* H - 72 */
759 C2_LEFTTORIGHT, /* I - 73 */
760 C2_LEFTTORIGHT, /* J - 74 */
761 C2_LEFTTORIGHT, /* K - 75 */
762 C2_LEFTTORIGHT, /* L - 76 */
763 C2_LEFTTORIGHT, /* M - 77 */
764 C2_LEFTTORIGHT, /* N - 78 */
765 C2_LEFTTORIGHT, /* O - 79 */
766 C2_LEFTTORIGHT, /* P - 80 */
767 C2_LEFTTORIGHT, /* Q - 81 */
768 C2_LEFTTORIGHT, /* R - 82 */
769 C2_LEFTTORIGHT, /* S - 83 */
770 C2_LEFTTORIGHT, /* T - 84 */
771 C2_LEFTTORIGHT, /* U - 85 */
772 C2_LEFTTORIGHT, /* V - 86 */
773 C2_LEFTTORIGHT, /* W - 87 */
774 C2_LEFTTORIGHT, /* X - 88 */
775 C2_LEFTTORIGHT, /* Y - 89 */
776 C2_LEFTTORIGHT, /* Z - 90 */
777 C2_OTHERNEUTRAL, /* [ - 91 */
778 C2_OTHERNEUTRAL, /* \ - 92 */
779 C2_OTHERNEUTRAL, /* ] - 93 */
780 C2_OTHERNEUTRAL, /* ^ - 94 */
781 C2_OTHERNEUTRAL, /* _ - 95 */
782 C2_OTHERNEUTRAL, /* ` - 96 */
783 C2_LEFTTORIGHT, /* a - 97 */
784 C2_LEFTTORIGHT, /* b - 98 */
785 C2_LEFTTORIGHT, /* c - 99 */
786 C2_LEFTTORIGHT, /* d - 100 */
787 C2_LEFTTORIGHT, /* e - 101 */
788 C2_LEFTTORIGHT, /* f - 102 */
789 C2_LEFTTORIGHT, /* g - 103 */
790 C2_LEFTTORIGHT, /* h - 104 */
791 C2_LEFTTORIGHT, /* i - 105 */
792 C2_LEFTTORIGHT, /* j - 106 */
793 C2_LEFTTORIGHT, /* k - 107 */
794 C2_LEFTTORIGHT, /* l - 108 */
795 C2_LEFTTORIGHT, /* m - 109 */
796 C2_LEFTTORIGHT, /* n - 110 */
797 C2_LEFTTORIGHT, /* o - 111 */
798 C2_LEFTTORIGHT, /* p - 112 */
799 C2_LEFTTORIGHT, /* q - 113 */
800 C2_LEFTTORIGHT, /* r - 114 */
801 C2_LEFTTORIGHT, /* s - 115 */
802 C2_LEFTTORIGHT, /* t - 116 */
803 C2_LEFTTORIGHT, /* u - 117 */
804 C2_LEFTTORIGHT, /* v - 118 */
805 C2_LEFTTORIGHT, /* w - 119 */
806 C2_LEFTTORIGHT, /* x - 120 */
807 C2_LEFTTORIGHT, /* y - 121 */
808 C2_LEFTTORIGHT, /* z - 122 */
809 C2_OTHERNEUTRAL, /* { - 123 */
810 C2_OTHERNEUTRAL, /* | - 124 */
811 C2_OTHERNEUTRAL, /* } - 125 */
812 C2_OTHERNEUTRAL, /* ~ - 126 */
813 C2_NOTAPPLICABLE, /* \x7f - 127 */
814 C2_NOTAPPLICABLE, /* € - 128 */
815 C2_NOTAPPLICABLE, /* � - 129 */
816 C2_OTHERNEUTRAL, /* ‚ - 130 */
817 C2_LEFTTORIGHT, /* ƒ - 131 */
818 C2_OTHERNEUTRAL, /* „ - 132 */
819 C2_OTHERNEUTRAL, /* … - 133 */
820 C2_OTHERNEUTRAL, /* † - 134 */
821 C2_OTHERNEUTRAL, /* ‡ - 135 */
822 C2_LEFTTORIGHT, /* ˆ - 136 */
823 C2_EUROPETERMINATOR, /* ‰ - 137 */
824 C2_LEFTTORIGHT, /* Š - 138 */
825 C2_OTHERNEUTRAL, /* ‹ - 139 */
826 C2_LEFTTORIGHT, /* Π- 140 */
827 C2_NOTAPPLICABLE, /* � - 141 */
828 C2_NOTAPPLICABLE, /* Ž - 142 */
829 C2_NOTAPPLICABLE, /* � - 143 */
830 C2_NOTAPPLICABLE, /* � - 144 */
831 C2_OTHERNEUTRAL, /* ‘ - 145 */
832 C2_OTHERNEUTRAL, /* ’ - 146 */
833 C2_OTHERNEUTRAL, /* “ - 147 */
834 C2_OTHERNEUTRAL, /* ” - 148 */
835 C2_OTHERNEUTRAL, /* • - 149 */
836 C2_OTHERNEUTRAL, /* – - 150 */
837 C2_OTHERNEUTRAL, /* — - 151 */
838 C2_LEFTTORIGHT, /* ˜ - 152 */
839 C2_OTHERNEUTRAL, /* ™ - 153 */
840 C2_LEFTTORIGHT, /* š - 154 */
841 C2_OTHERNEUTRAL, /* › - 155 */
842 C2_LEFTTORIGHT, /* œ - 156 */
843 C2_NOTAPPLICABLE, /* � - 157 */
844 C2_NOTAPPLICABLE, /* ž - 158 */
845 C2_LEFTTORIGHT, /* Ÿ - 159 */
846 C2_WHITESPACE, /*   - 160 */
847 C2_OTHERNEUTRAL, /* ¡ - 161 */
848 C2_EUROPETERMINATOR, /* ¢ - 162 */
849 C2_EUROPETERMINATOR, /* £ - 163 */
850 C2_EUROPETERMINATOR, /* ¤ - 164 */
851 C2_EUROPETERMINATOR, /* ¥ - 165 */
852 C2_OTHERNEUTRAL, /* ¦ - 166 */
853 C2_OTHERNEUTRAL, /* § - 167 */
854 C2_OTHERNEUTRAL, /* ¨ - 168 */
855 C2_OTHERNEUTRAL, /* © - 169 */
856 C2_OTHERNEUTRAL, /* ª - 170 */
857 C2_OTHERNEUTRAL, /* « - 171 */
858 C2_OTHERNEUTRAL, /* ¬ - 172 */
859 C2_OTHERNEUTRAL, /* ­ - 173 */
860 C2_OTHERNEUTRAL, /* ® - 174 */
861 C2_OTHERNEUTRAL, /* ¯ - 175 */
862 C2_EUROPETERMINATOR, /* ° - 176 */
863 C2_EUROPETERMINATOR, /* ± - 177 */
864 C2_EUROPENUMBER, /* ² - 178 */
865 C2_EUROPENUMBER, /* ³ - 179 */
866 C2_OTHERNEUTRAL, /* ´ - 180 */
867 C2_OTHERNEUTRAL, /* µ - 181 */
868 C2_OTHERNEUTRAL, /* ¶ - 182 */
869 C2_OTHERNEUTRAL, /* · - 183 */
870 C2_OTHERNEUTRAL, /* ¸ - 184 */
871 C2_EUROPENUMBER, /* ¹ - 185 */
872 C2_OTHERNEUTRAL, /* º - 186 */
873 C2_OTHERNEUTRAL, /* » - 187 */
874 C2_OTHERNEUTRAL, /* ¼ - 188 */
875 C2_OTHERNEUTRAL, /* ½ - 189 */
876 C2_OTHERNEUTRAL, /* ¾ - 190 */
877 C2_OTHERNEUTRAL, /* ¿ - 191 */
878 C2_LEFTTORIGHT, /* À - 192 */
879 C2_LEFTTORIGHT, /* Á - 193 */
880 C2_LEFTTORIGHT, /* Â - 194 */
881 C2_LEFTTORIGHT, /* Ã - 195 */
882 C2_LEFTTORIGHT, /* Ä - 196 */
883 C2_LEFTTORIGHT, /* Å - 197 */
884 C2_LEFTTORIGHT, /* Æ - 198 */
885 C2_LEFTTORIGHT, /* Ç - 199 */
886 C2_LEFTTORIGHT, /* È - 200 */
887 C2_LEFTTORIGHT, /* É - 201 */
888 C2_LEFTTORIGHT, /* Ê - 202 */
889 C2_LEFTTORIGHT, /* Ë - 203 */
890 C2_LEFTTORIGHT, /* Ì - 204 */
891 C2_LEFTTORIGHT, /* Í - 205 */
892 C2_LEFTTORIGHT, /* Î - 206 */
893 C2_LEFTTORIGHT, /* Ï - 207 */
894 C2_LEFTTORIGHT, /* Ð - 208 */
895 C2_LEFTTORIGHT, /* Ñ - 209 */
896 C2_LEFTTORIGHT, /* Ò - 210 */
897 C2_LEFTTORIGHT, /* Ó - 211 */
898 C2_LEFTTORIGHT, /* Ô - 212 */
899 C2_LEFTTORIGHT, /* Õ - 213 */
900 C2_LEFTTORIGHT, /* Ö - 214 */
901 C2_OTHERNEUTRAL, /* × - 215 */
902 C2_LEFTTORIGHT, /* Ø - 216 */
903 C2_LEFTTORIGHT, /* Ù - 217 */
904 C2_LEFTTORIGHT, /* Ú - 218 */
905 C2_LEFTTORIGHT, /* Û - 219 */
906 C2_LEFTTORIGHT, /* Ü - 220 */
907 C2_LEFTTORIGHT, /* Ý - 221 */
908 C2_LEFTTORIGHT, /* Þ - 222 */
909 C2_LEFTTORIGHT, /* ß - 223 */
910 C2_LEFTTORIGHT, /* à - 224 */
911 C2_LEFTTORIGHT, /* á - 225 */
912 C2_LEFTTORIGHT, /* â - 226 */
913 C2_LEFTTORIGHT, /* ã - 227 */
914 C2_LEFTTORIGHT, /* ä - 228 */
915 C2_LEFTTORIGHT, /* å - 229 */
916 C2_LEFTTORIGHT, /* æ - 230 */
917 C2_LEFTTORIGHT, /* ç - 231 */
918 C2_LEFTTORIGHT, /* è - 232 */
919 C2_LEFTTORIGHT, /* é - 233 */
920 C2_LEFTTORIGHT, /* ê - 234 */
921 C2_LEFTTORIGHT, /* ë - 235 */
922 C2_LEFTTORIGHT, /* ì - 236 */
923 C2_LEFTTORIGHT, /* í - 237 */
924 C2_LEFTTORIGHT, /* î - 238 */
925 C2_LEFTTORIGHT, /* ï - 239 */
926 C2_LEFTTORIGHT, /* ð - 240 */
927 C2_LEFTTORIGHT, /* ñ - 241 */
928 C2_LEFTTORIGHT, /* ò - 242 */
929 C2_LEFTTORIGHT, /* ó - 243 */
930 C2_LEFTTORIGHT, /* ô - 244 */
931 C2_LEFTTORIGHT, /* õ - 245 */
932 C2_LEFTTORIGHT, /* ö - 246 */
933 C2_OTHERNEUTRAL, /* ÷ - 247 */
934 C2_LEFTTORIGHT, /* ø - 248 */
935 C2_LEFTTORIGHT, /* ù - 249 */
936 C2_LEFTTORIGHT, /* ú - 250 */
937 C2_LEFTTORIGHT, /* û - 251 */
938 C2_LEFTTORIGHT, /* ü - 252 */
939 C2_LEFTTORIGHT, /* ý - 253 */
940 C2_LEFTTORIGHT, /* þ - 254 */
941 C2_LEFTTORIGHT /* ÿ - 255 */
944 static const WORD CT_CType3_LUT[] = {
945 0x0000, /* - 0 */
946 0x0000, /* - 1 */
947 0x0000, /* - 2 */
948 0x0000, /* - 3 */
949 0x0000, /* - 4 */
950 0x0000, /* - 5 */
951 0x0000, /* - 6 */
952 0x0000, /* - 7 */
953 0x0000, /* - 8 */
954 0x0008, /* - 9 */
955 0x0008, /* - 10 */
956 0x0008, /* - 11 */
957 0x0008, /* - 12 */
958 0x0008, /* - 13 */
959 0x0000, /* - 14 */
960 0x0000, /* - 15 */
961 0x0000, /* - 16 */
962 0x0000, /* - 17 */
963 0x0000, /* - 18 */
964 0x0000, /* - 19 */
965 0x0000, /* - 20 */
966 0x0000, /* - 21 */
967 0x0000, /* - 22 */
968 0x0000, /* - 23 */
969 0x0000, /* - 24 */
970 0x0000, /* - 25 */
971 0x0000, /* - 26 */
972 0x0000, /* - 27 */
973 0x0000, /* - 28 */
974 0x0000, /* - 29 */
975 0x0000, /* - 30 */
976 0x0000, /* - 31 */
977 0x0048, /* - 32 */
978 0x0048, /* ! - 33 */
979 0x0448, /* " - 34 */ /* " */
980 0x0048, /* # - 35 */
981 0x0448, /* $ - 36 */
982 0x0048, /* % - 37 */
983 0x0048, /* & - 38 */
984 0x0440, /* ' - 39 */
985 0x0048, /* ( - 40 */
986 0x0048, /* ) - 41 */
987 0x0048, /* * - 42 */
988 0x0048, /* + - 43 */
989 0x0048, /* , - 44 */
990 0x0440, /* - - 45 */
991 0x0048, /* . - 46 */
992 0x0448, /* / - 47 */
993 0x0040, /* 0 - 48 */
994 0x0040, /* 1 - 49 */
995 0x0040, /* 2 - 50 */
996 0x0040, /* 3 - 51 */
997 0x0040, /* 4 - 52 */
998 0x0040, /* 5 - 53 */
999 0x0040, /* 6 - 54 */
1000 0x0040, /* 7 - 55 */
1001 0x0040, /* 8 - 56 */
1002 0x0040, /* 9 - 57 */
1003 0x0048, /* : - 58 */
1004 0x0048, /* ; - 59 */
1005 0x0048, /* < - 60 */
1006 0x0448, /* = - 61 */
1007 0x0048, /* > - 62 */
1008 0x0048, /* ? - 63 */
1009 0x0448, /* @ - 64 */
1010 0x8040, /* A - 65 */
1011 0x8040, /* B - 66 */
1012 0x8040, /* C - 67 */
1013 0x8040, /* D - 68 */
1014 0x8040, /* E - 69 */
1015 0x8040, /* F - 70 */
1016 0x8040, /* G - 71 */
1017 0x8040, /* H - 72 */
1018 0x8040, /* I - 73 */
1019 0x8040, /* J - 74 */
1020 0x8040, /* K - 75 */
1021 0x8040, /* L - 76 */
1022 0x8040, /* M - 77 */
1023 0x8040, /* N - 78 */
1024 0x8040, /* O - 79 */
1025 0x8040, /* P - 80 */
1026 0x8040, /* Q - 81 */
1027 0x8040, /* R - 82 */
1028 0x8040, /* S - 83 */
1029 0x8040, /* T - 84 */
1030 0x8040, /* U - 85 */
1031 0x8040, /* V - 86 */
1032 0x8040, /* W - 87 */
1033 0x8040, /* X - 88 */
1034 0x8040, /* Y - 89 */
1035 0x8040, /* Z - 90 */
1036 0x0048, /* [ - 91 */
1037 0x0448, /* \ - 92 */
1038 0x0048, /* ] - 93 */
1039 0x0448, /* ^ - 94 */
1040 0x0448, /* _ - 95 */
1041 0x0448, /* ` - 96 */
1042 0x8040, /* a - 97 */
1043 0x8040, /* b - 98 */
1044 0x8040, /* c - 99 */
1045 0x8040, /* d - 100 */
1046 0x8040, /* e - 101 */
1047 0x8040, /* f - 102 */
1048 0x8040, /* g - 103 */
1049 0x8040, /* h - 104 */
1050 0x8040, /* i - 105 */
1051 0x8040, /* j - 106 */
1052 0x8040, /* k - 107 */
1053 0x8040, /* l - 108 */
1054 0x8040, /* m - 109 */
1055 0x8040, /* n - 110 */
1056 0x8040, /* o - 111 */
1057 0x8040, /* p - 112 */
1058 0x8040, /* q - 113 */
1059 0x8040, /* r - 114 */
1060 0x8040, /* s - 115 */
1061 0x8040, /* t - 116 */
1062 0x8040, /* u - 117 */
1063 0x8040, /* v - 118 */
1064 0x8040, /* w - 119 */
1065 0x8040, /* x - 120 */
1066 0x8040, /* y - 121 */
1067 0x8040, /* z - 122 */
1068 0x0048, /* { - 123 */
1069 0x0048, /* | - 124 */
1070 0x0048, /* } - 125 */
1071 0x0448, /* ~ - 126 */
1072 0x0000, /* \x7f - 127 */
1073 0x0000, /* € - 128 */
1074 0x0000, /* � - 129 */
1075 0x0008, /* ‚ - 130 */
1076 0x8000, /* ƒ - 131 */
1077 0x0008, /* „ - 132 */
1078 0x0008, /* … - 133 */
1079 0x0008, /* † - 134 */
1080 0x0008, /* ‡ - 135 */
1081 0x0001, /* ˆ - 136 */
1082 0x0008, /* ‰ - 137 */
1083 0x8003, /* Š - 138 */
1084 0x0008, /* ‹ - 139 */
1085 0x8000, /* Π- 140 */
1086 0x0000, /* � - 141 */
1087 0x0000, /* Ž - 142 */
1088 0x0000, /* � - 143 */
1089 0x0000, /* � - 144 */
1090 0x0088, /* ‘ - 145 */
1091 0x0088, /* ’ - 146 */
1092 0x0088, /* “ - 147 */
1093 0x0088, /* ” - 148 */
1094 0x0008, /* • - 149 */
1095 0x0400, /* – - 150 */
1096 0x0400, /* — - 151 */
1097 0x0408, /* ˜ - 152 */
1098 0x0000, /* ™ - 153 */
1099 0x8003, /* š - 154 */
1100 0x0008, /* › - 155 */
1101 0x8000, /* œ - 156 */
1102 0x0000, /* � - 157 */
1103 0x0000, /* ž - 158 */
1104 0x8003, /* Ÿ - 159 */
1105 0x0008, /*   - 160 */
1106 0x0008, /* ¡ - 161 */
1107 0x0048, /* ¢ - 162 */
1108 0x0048, /* £ - 163 */
1109 0x0008, /* ¤ - 164 */
1110 0x0048, /* ¥ - 165 */
1111 0x0048, /* ¦ - 166 */
1112 0x0008, /* § - 167 */
1113 0x0408, /* ¨ - 168 */
1114 0x0008, /* © - 169 */
1115 0x0400, /* ª - 170 */
1116 0x0008, /* « - 171 */
1117 0x0048, /* ¬ - 172 */
1118 0x0408, /* ­ - 173 */
1119 0x0008, /* ® - 174 */
1120 0x0448, /* ¯ - 175 */
1121 0x0008, /* ° - 176 */
1122 0x0008, /* ± - 177 */
1123 0x0000, /* ² - 178 */
1124 0x0000, /* ³ - 179 */
1125 0x0408, /* ´ - 180 */
1126 0x0008, /* µ - 181 */
1127 0x0008, /* ¶ - 182 */
1128 0x0008, /* · - 183 */
1129 0x0408, /* ¸ - 184 */
1130 0x0000, /* ¹ - 185 */
1131 0x0400, /* º - 186 */
1132 0x0008, /* » - 187 */
1133 0x0000, /* ¼ - 188 */
1134 0x0000, /* ½ - 189 */
1135 0x0000, /* ¾ - 190 */
1136 0x0008, /* ¿ - 191 */
1137 0x8003, /* À - 192 */
1138 0x8003, /* Á - 193 */
1139 0x8003, /* Â - 194 */
1140 0x8003, /* Ã - 195 */
1141 0x8003, /* Ä - 196 */
1142 0x8003, /* Å - 197 */
1143 0x8000, /* Æ - 198 */
1144 0x8003, /* Ç - 199 */
1145 0x8003, /* È - 200 */
1146 0x8003, /* É - 201 */
1147 0x8003, /* Ê - 202 */
1148 0x8003, /* Ë - 203 */
1149 0x8003, /* Ì - 204 */
1150 0x8003, /* Í - 205 */
1151 0x8003, /* Î - 206 */
1152 0x8003, /* Ï - 207 */
1153 0x8000, /* Ð - 208 */
1154 0x8003, /* Ñ - 209 */
1155 0x8003, /* Ò - 210 */
1156 0x8003, /* Ó - 211 */
1157 0x8003, /* Ô - 212 */
1158 0x8003, /* Õ - 213 */
1159 0x8003, /* Ö - 214 */
1160 0x0008, /* × - 215 */
1161 0x8003, /* Ø - 216 */
1162 0x8003, /* Ù - 217 */
1163 0x8003, /* Ú - 218 */
1164 0x8003, /* Û - 219 */
1165 0x8003, /* Ü - 220 */
1166 0x8003, /* Ý - 221 */
1167 0x8000, /* Þ - 222 */
1168 0x8000, /* ß - 223 */
1169 0x8003, /* à - 224 */
1170 0x8003, /* á - 225 */
1171 0x8003, /* â - 226 */
1172 0x8003, /* ã - 227 */
1173 0x8003, /* ä - 228 */
1174 0x8003, /* å - 229 */
1175 0x8000, /* æ - 230 */
1176 0x8003, /* ç - 231 */
1177 0x8003, /* è - 232 */
1178 0x8003, /* é - 233 */
1179 0x8003, /* ê - 234 */
1180 0x8003, /* ë - 235 */
1181 0x8003, /* ì - 236 */
1182 0x8003, /* í - 237 */
1183 0x8003, /* î - 238 */
1184 0x8003, /* ï - 239 */
1185 0x8000, /* ð - 240 */
1186 0x8003, /* ñ - 241 */
1187 0x8003, /* ò - 242 */
1188 0x8003, /* ó - 243 */
1189 0x8003, /* ô - 244 */
1190 0x8003, /* õ - 245 */
1191 0x8003, /* ö - 246 */
1192 0x0008, /* ÷ - 247 */
1193 0x8003, /* ø - 248 */
1194 0x8003, /* ù - 249 */
1195 0x8003, /* ú - 250 */
1196 0x8003, /* û - 251 */
1197 0x8003, /* ü - 252 */
1198 0x8003, /* ý - 253 */
1199 0x8000, /* þ - 254 */
1200 0x8003 /* ÿ - 255 */
1203 /******************************************************************************
1204 * GetStringType16 [OLE2NLS.7]
1206 BOOL16 WINAPI GetStringType16(LCID locale,DWORD dwInfoType,LPCSTR src,
1207 INT16 cchSrc,LPWORD chartype)
1209 return GetStringTypeEx32A(locale,dwInfoType,src,cchSrc,chartype);
1211 /******************************************************************************
1212 * GetStringType32A [KERNEL32.396]
1214 BOOL32 WINAPI GetStringType32A(LCID locale,DWORD dwInfoType,LPCSTR src,
1215 INT32 cchSrc,LPWORD chartype)
1217 return GetStringTypeEx32A(locale,dwInfoType,src,cchSrc,chartype);
1220 /******************************************************************************
1221 * GetStringTypeEx32A [KERNEL32.397]
1223 * FIXME: Ignores the locale.
1225 BOOL32 WINAPI GetStringTypeEx32A(LCID locale,DWORD dwInfoType,LPCSTR src,
1226 INT32 cchSrc,LPWORD chartype)
1228 int i;
1230 if ((src==NULL) || (chartype==NULL) || (src==(LPSTR)chartype))
1232 SetLastError(ERROR_INVALID_PARAMETER);
1233 return FALSE;
1236 if (cchSrc==-1)
1237 cchSrc=lstrlen32A(src)+1;
1239 switch (dwInfoType) {
1240 case CT_CTYPE1:
1241 for (i=0;i<cchSrc;i++)
1243 chartype[i] = 0;
1244 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1245 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1246 if (islower(src[i])) chartype[i]|=C1_LOWER;
1247 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1248 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1249 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1250 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1251 /* FIXME: isblank() is a GNU extension */
1252 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1253 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1254 /* C1_XDIGIT */
1256 return TRUE;
1258 case CT_CTYPE2:
1259 for (i=0;i<cchSrc;i++)
1261 chartype[i]=(WORD)CT_CType2_LUT[i];
1263 return TRUE;
1265 case CT_CTYPE3:
1266 for (i=0;i<cchSrc;i++)
1268 chartype[i]=CT_CType3_LUT[i];
1270 return TRUE;
1272 default:
1273 ERR(ole,"Unknown dwInfoType:%ld\n",dwInfoType);
1274 return FALSE;
1278 /******************************************************************************
1279 * GetStringType32W [KERNEL32.399]
1281 * NOTES
1282 * Yes, this is missing LCID locale. MS fault.
1284 BOOL32 WINAPI GetStringType32W(DWORD dwInfoType,LPCWSTR src,INT32 cchSrc,
1285 LPWORD chartype)
1287 return GetStringTypeEx32W(0/*defaultlocale*/,dwInfoType,src,cchSrc,chartype);
1290 /******************************************************************************
1291 * GetStringTypeEx32W [KERNEL32.398]
1293 * FIXME: unicode chars are assumed chars
1295 BOOL32 WINAPI GetStringTypeEx32W(LCID locale,DWORD dwInfoType,LPCWSTR src,
1296 INT32 cchSrc,LPWORD chartype)
1298 int i;
1301 if (cchSrc==-1)
1302 cchSrc=lstrlen32W(src)+1;
1304 switch (dwInfoType) {
1305 case CT_CTYPE2:
1306 FIXME(ole,"CT_CTYPE2 not supported.\n");
1307 return FALSE;
1308 case CT_CTYPE3:
1309 FIXME(ole,"CT_CTYPE3 not supported.\n");
1310 return FALSE;
1311 default:break;
1313 for (i=0;i<cchSrc;i++) {
1314 chartype[i] = 0;
1315 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1316 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1317 if (islower(src[i])) chartype[i]|=C1_LOWER;
1318 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1319 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1320 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1321 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1322 /* FIXME: isblank() is a GNU extension */
1323 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1324 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1325 /* C1_XDIGIT */
1327 return TRUE;
1330 /*****************************************************************
1331 * VerLanguageName16 [VER.10]
1333 DWORD WINAPI VerLanguageName16(UINT16 langid,LPSTR langname,UINT16 langnamelen)
1335 int i;
1336 DWORD result;
1337 char buffer[80];
1339 TRACE(ver,"(%d,%p,%d)\n",langid,langname,langnamelen);
1340 /* First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
1341 * from the registry.
1343 sprintf(buffer,
1344 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
1345 langid);
1346 result = RegQueryValue16(HKEY_LOCAL_MACHINE, buffer, langname,
1347 (LPDWORD)&langnamelen);
1348 if (result == ERROR_SUCCESS) {
1349 langname[langnamelen-1]='\0';
1350 return langnamelen;
1352 /* if that fails, use the internal table */
1353 for (i=0;languages[i].langid!=0;i++)
1354 if (langid==languages[i].langid)
1355 break;
1356 strncpy(langname,languages[i].langname,langnamelen);
1357 langname[langnamelen-1]='\0';
1358 return strlen(languages[i].langname);
1361 /*****************************************************************
1362 * VerLanguageName32A [VERSION.9]
1364 DWORD WINAPI VerLanguageName32A(UINT32 langid,LPSTR langname,
1365 UINT32 langnamelen)
1367 return VerLanguageName16(langid,langname,langnamelen);
1370 /*****************************************************************
1371 * VerLanguageName32W [VERSION.10]
1373 DWORD WINAPI VerLanguageName32W(UINT32 langid,LPWSTR langname,
1374 UINT32 langnamelen)
1376 int i;
1377 LPWSTR keyname;
1378 DWORD result;
1379 char buffer[80];
1381 /* First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
1382 * from the registry.
1384 sprintf(buffer,
1385 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
1386 langid);
1387 keyname = HEAP_strdupAtoW( GetProcessHeap(), 0, buffer );
1388 result = RegQueryValue32W(HKEY_LOCAL_MACHINE, keyname, langname,
1389 (LPDWORD)&langnamelen);
1390 HeapFree( GetProcessHeap(), 0, keyname );
1391 if (result != ERROR_SUCCESS) {
1392 /* if that fails, use the internal table */
1393 for (i=0;languages[i].langid!=0;i++)
1394 if (langid==languages[i].langid)
1395 break;
1396 lstrcpyAtoW( langname, languages[i].langname );
1397 langnamelen = strlen(languages[i].langname);
1398 /* same as strlenW(langname); */
1400 return langnamelen;
1403 static const unsigned char LCM_Unicode_LUT[] = {
1404 6 , 3, /* - 1 */
1405 6 , 4, /* - 2 */
1406 6 , 5, /* - 3 */
1407 6 , 6, /* - 4 */
1408 6 , 7, /* - 5 */
1409 6 , 8, /* - 6 */
1410 6 , 9, /* - 7 */
1411 6 , 10, /* - 8 */
1412 7 , 5, /* - 9 */
1413 7 , 6, /* - 10 */
1414 7 , 7, /* - 11 */
1415 7 , 8, /* - 12 */
1416 7 , 9, /* - 13 */
1417 6 , 11, /* - 14 */
1418 6 , 12, /* - 15 */
1419 6 , 13, /* - 16 */
1420 6 , 14, /* - 17 */
1421 6 , 15, /* - 18 */
1422 6 , 16, /* - 19 */
1423 6 , 17, /* - 20 */
1424 6 , 18, /* - 21 */
1425 6 , 19, /* - 22 */
1426 6 , 20, /* - 23 */
1427 6 , 21, /* - 24 */
1428 6 , 22, /* - 25 */
1429 6 , 23, /* - 26 */
1430 6 , 24, /* - 27 */
1431 6 , 25, /* - 28 */
1432 6 , 26, /* - 29 */
1433 6 , 27, /* - 30 */
1434 6 , 28, /* - 31 */
1435 7 , 2, /* - 32 */
1436 7 , 28, /* ! - 33 */
1437 7 , 29, /* " - 34 */ /* " */
1438 7 , 31, /* # - 35 */
1439 7 , 33, /* $ - 36 */
1440 7 , 35, /* % - 37 */
1441 7 , 37, /* & - 38 */
1442 6 , 128, /* ' - 39 */
1443 7 , 39, /* ( - 40 */
1444 7 , 42, /* ) - 41 */
1445 7 , 45, /* * - 42 */
1446 8 , 3, /* + - 43 */
1447 7 , 47, /* , - 44 */
1448 6 , 130, /* - - 45 */
1449 7 , 51, /* . - 46 */
1450 7 , 53, /* / - 47 */
1451 12 , 3, /* 0 - 48 */
1452 12 , 33, /* 1 - 49 */
1453 12 , 51, /* 2 - 50 */
1454 12 , 70, /* 3 - 51 */
1455 12 , 88, /* 4 - 52 */
1456 12 , 106, /* 5 - 53 */
1457 12 , 125, /* 6 - 54 */
1458 12 , 144, /* 7 - 55 */
1459 12 , 162, /* 8 - 56 */
1460 12 , 180, /* 9 - 57 */
1461 7 , 55, /* : - 58 */
1462 7 , 58, /* ; - 59 */
1463 8 , 14, /* < - 60 */
1464 8 , 18, /* = - 61 */
1465 8 , 20, /* > - 62 */
1466 7 , 60, /* ? - 63 */
1467 7 , 62, /* @ - 64 */
1468 14 , 2, /* A - 65 */
1469 14 , 9, /* B - 66 */
1470 14 , 10, /* C - 67 */
1471 14 , 26, /* D - 68 */
1472 14 , 33, /* E - 69 */
1473 14 , 35, /* F - 70 */
1474 14 , 37, /* G - 71 */
1475 14 , 44, /* H - 72 */
1476 14 , 50, /* I - 73 */
1477 14 , 53, /* J - 74 */
1478 14 , 54, /* K - 75 */
1479 14 , 72, /* L - 76 */
1480 14 , 81, /* M - 77 */
1481 14 , 112, /* N - 78 */
1482 14 , 124, /* O - 79 */
1483 14 , 126, /* P - 80 */
1484 14 , 137, /* Q - 81 */
1485 14 , 138, /* R - 82 */
1486 14 , 145, /* S - 83 */
1487 14 , 153, /* T - 84 */
1488 14 , 159, /* U - 85 */
1489 14 , 162, /* V - 86 */
1490 14 , 164, /* W - 87 */
1491 14 , 166, /* X - 88 */
1492 14 , 167, /* Y - 89 */
1493 14 , 169, /* Z - 90 */
1494 7 , 63, /* [ - 91 */
1495 7 , 65, /* \ - 92 */
1496 7 , 66, /* ] - 93 */
1497 7 , 67, /* ^ - 94 */
1498 7 , 68, /* _ - 95 */
1499 7 , 72, /* ` - 96 */
1500 14 , 2, /* a - 97 */
1501 14 , 9, /* b - 98 */
1502 14 , 10, /* c - 99 */
1503 14 , 26, /* d - 100 */
1504 14 , 33, /* e - 101 */
1505 14 , 35, /* f - 102 */
1506 14 , 37, /* g - 103 */
1507 14 , 44, /* h - 104 */
1508 14 , 50, /* i - 105 */
1509 14 , 53, /* j - 106 */
1510 14 , 54, /* k - 107 */
1511 14 , 72, /* l - 108 */
1512 14 , 81, /* m - 109 */
1513 14 , 112, /* n - 110 */
1514 14 , 124, /* o - 111 */
1515 14 , 126, /* p - 112 */
1516 14 , 137, /* q - 113 */
1517 14 , 138, /* r - 114 */
1518 14 , 145, /* s - 115 */
1519 14 , 153, /* t - 116 */
1520 14 , 159, /* u - 117 */
1521 14 , 162, /* v - 118 */
1522 14 , 164, /* w - 119 */
1523 14 , 166, /* x - 120 */
1524 14 , 167, /* y - 121 */
1525 14 , 169, /* z - 122 */
1526 7 , 74, /* { - 123 */
1527 7 , 76, /* | - 124 */
1528 7 , 78, /* } - 125 */
1529 7 , 80, /* ~ - 126 */
1530 6 , 29, /* \x7f - 127 */
1531 6 , 30, /* € - 128 */
1532 6 , 31, /* � - 129 */
1533 7 , 123, /* ‚ - 130 */
1534 14 , 35, /* ƒ - 131 */
1535 7 , 127, /* „ - 132 */
1536 10 , 21, /* … - 133 */
1537 10 , 15, /* † - 134 */
1538 10 , 16, /* ‡ - 135 */
1539 7 , 67, /* ˆ - 136 */
1540 10 , 22, /* ‰ - 137 */
1541 14 , 145, /* Š - 138 */
1542 7 , 136, /* ‹ - 139 */
1543 14 + 16 , 124, /* Π- 140 */
1544 6 , 43, /* � - 141 */
1545 6 , 44, /* Ž - 142 */
1546 6 , 45, /* � - 143 */
1547 6 , 46, /* � - 144 */
1548 7 , 121, /* ‘ - 145 */
1549 7 , 122, /* ’ - 146 */
1550 7 , 125, /* “ - 147 */
1551 7 , 126, /* ” - 148 */
1552 10 , 17, /* • - 149 */
1553 6 , 137, /* – - 150 */
1554 6 , 139, /* — - 151 */
1555 7 , 93, /* ˜ - 152 */
1556 14 , 156, /* ™ - 153 */
1557 14 , 145, /* š - 154 */
1558 7 , 137, /* › - 155 */
1559 14 + 16 , 124, /* œ - 156 */
1560 6 , 59, /* � - 157 */
1561 6 , 60, /* ž - 158 */
1562 14 , 167, /* Ÿ - 159 */
1563 7 , 4, /*   - 160 */
1564 7 , 81, /* ¡ - 161 */
1565 10 , 2, /* ¢ - 162 */
1566 10 , 3, /* £ - 163 */
1567 10 , 4, /* ¤ - 164 */
1568 10 , 5, /* ¥ - 165 */
1569 7 , 82, /* ¦ - 166 */
1570 10 , 6, /* § - 167 */
1571 7 , 83, /* ¨ - 168 */
1572 10 , 7, /* © - 169 */
1573 14 , 2, /* ª - 170 */
1574 8 , 24, /* « - 171 */
1575 10 , 8, /* ¬ - 172 */
1576 6 , 131, /* ­ - 173 */
1577 10 , 9, /* ® - 174 */
1578 7 , 84, /* ¯ - 175 */
1579 10 , 10, /* ° - 176 */
1580 8 , 23, /* ± - 177 */
1581 12 , 51, /* ² - 178 */
1582 12 , 70, /* ³ - 179 */
1583 7 , 85, /* ´ - 180 */
1584 10 , 11, /* µ - 181 */
1585 10 , 12, /* ¶ - 182 */
1586 10 , 13, /* · - 183 */
1587 7 , 86, /* ¸ - 184 */
1588 12 , 33, /* ¹ - 185 */
1589 14 , 124, /* º - 186 */
1590 8 , 26, /* » - 187 */
1591 12 , 21, /* ¼ - 188 */
1592 12 , 25, /* ½ - 189 */
1593 12 , 29, /* ¾ - 190 */
1594 7 , 87, /* ¿ - 191 */
1595 14 , 2, /* À - 192 */
1596 14 , 2, /* Á - 193 */
1597 14 , 2, /* Â - 194 */
1598 14 , 2, /* Ã - 195 */
1599 14 , 2, /* Ä - 196 */
1600 14 , 2, /* Å - 197 */
1601 14 + 16 , 2, /* Æ - 198 */
1602 14 , 10, /* Ç - 199 */
1603 14 , 33, /* È - 200 */
1604 14 , 33, /* É - 201 */
1605 14 , 33, /* Ê - 202 */
1606 14 , 33, /* Ë - 203 */
1607 14 , 50, /* Ì - 204 */
1608 14 , 50, /* Í - 205 */
1609 14 , 50, /* Î - 206 */
1610 14 , 50, /* Ï - 207 */
1611 14 , 26, /* Ð - 208 */
1612 14 , 112, /* Ñ - 209 */
1613 14 , 124, /* Ò - 210 */
1614 14 , 124, /* Ó - 211 */
1615 14 , 124, /* Ô - 212 */
1616 14 , 124, /* Õ - 213 */
1617 14 , 124, /* Ö - 214 */
1618 8 , 28, /* × - 215 */
1619 14 , 124, /* Ø - 216 */
1620 14 , 159, /* Ù - 217 */
1621 14 , 159, /* Ú - 218 */
1622 14 , 159, /* Û - 219 */
1623 14 , 159, /* Ü - 220 */
1624 14 , 167, /* Ý - 221 */
1625 14 + 32 , 153, /* Þ - 222 */
1626 14 + 48 , 145, /* ß - 223 */
1627 14 , 2, /* à - 224 */
1628 14 , 2, /* á - 225 */
1629 14 , 2, /* â - 226 */
1630 14 , 2, /* ã - 227 */
1631 14 , 2, /* ä - 228 */
1632 14 , 2, /* å - 229 */
1633 14 + 16 , 2, /* æ - 230 */
1634 14 , 10, /* ç - 231 */
1635 14 , 33, /* è - 232 */
1636 14 , 33, /* é - 233 */
1637 14 , 33, /* ê - 234 */
1638 14 , 33, /* ë - 235 */
1639 14 , 50, /* ì - 236 */
1640 14 , 50, /* í - 237 */
1641 14 , 50, /* î - 238 */
1642 14 , 50, /* ï - 239 */
1643 14 , 26, /* ð - 240 */
1644 14 , 112, /* ñ - 241 */
1645 14 , 124, /* ò - 242 */
1646 14 , 124, /* ó - 243 */
1647 14 , 124, /* ô - 244 */
1648 14 , 124, /* õ - 245 */
1649 14 , 124, /* ö - 246 */
1650 8 , 29, /* ÷ - 247 */
1651 14 , 124, /* ø - 248 */
1652 14 , 159, /* ù - 249 */
1653 14 , 159, /* ú - 250 */
1654 14 , 159, /* û - 251 */
1655 14 , 159, /* ü - 252 */
1656 14 , 167, /* ý - 253 */
1657 14 + 32 , 153, /* þ - 254 */
1658 14 , 167 /* ÿ - 255 */ };
1660 static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
1662 #define LCM_Diacritic_Start 131
1664 static const unsigned char LCM_Diacritic_LUT[] = {
1665 123, /* ƒ - 131 */
1666 2, /* „ - 132 */
1667 2, /* … - 133 */
1668 2, /* † - 134 */
1669 2, /* ‡ - 135 */
1670 3, /* ˆ - 136 */
1671 2, /* ‰ - 137 */
1672 20, /* Š - 138 */
1673 2, /* ‹ - 139 */
1674 2, /* Π- 140 */
1675 2, /* � - 141 */
1676 2, /* Ž - 142 */
1677 2, /* � - 143 */
1678 2, /* � - 144 */
1679 2, /* ‘ - 145 */
1680 2, /* ’ - 146 */
1681 2, /* “ - 147 */
1682 2, /* ” - 148 */
1683 2, /* • - 149 */
1684 2, /* – - 150 */
1685 2, /* — - 151 */
1686 2, /* ˜ - 152 */
1687 2, /* ™ - 153 */
1688 20, /* š - 154 */
1689 2, /* › - 155 */
1690 2, /* œ - 156 */
1691 2, /* � - 157 */
1692 2, /* ž - 158 */
1693 19, /* Ÿ - 159 */
1694 2, /*   - 160 */
1695 2, /* ¡ - 161 */
1696 2, /* ¢ - 162 */
1697 2, /* £ - 163 */
1698 2, /* ¤ - 164 */
1699 2, /* ¥ - 165 */
1700 2, /* ¦ - 166 */
1701 2, /* § - 167 */
1702 2, /* ¨ - 168 */
1703 2, /* © - 169 */
1704 3, /* ª - 170 */
1705 2, /* « - 171 */
1706 2, /* ¬ - 172 */
1707 2, /* ­ - 173 */
1708 2, /* ® - 174 */
1709 2, /* ¯ - 175 */
1710 2, /* ° - 176 */
1711 2, /* ± - 177 */
1712 2, /* ² - 178 */
1713 2, /* ³ - 179 */
1714 2, /* ´ - 180 */
1715 2, /* µ - 181 */
1716 2, /* ¶ - 182 */
1717 2, /* · - 183 */
1718 2, /* ¸ - 184 */
1719 2, /* ¹ - 185 */
1720 3, /* º - 186 */
1721 2, /* » - 187 */
1722 2, /* ¼ - 188 */
1723 2, /* ½ - 189 */
1724 2, /* ¾ - 190 */
1725 2, /* ¿ - 191 */
1726 15, /* À - 192 */
1727 14, /* Á - 193 */
1728 18, /* Â - 194 */
1729 25, /* Ã - 195 */
1730 19, /* Ä - 196 */
1731 26, /* Å - 197 */
1732 2, /* Æ - 198 */
1733 28, /* Ç - 199 */
1734 15, /* È - 200 */
1735 14, /* É - 201 */
1736 18, /* Ê - 202 */
1737 19, /* Ë - 203 */
1738 15, /* Ì - 204 */
1739 14, /* Í - 205 */
1740 18, /* Î - 206 */
1741 19, /* Ï - 207 */
1742 104, /* Ð - 208 */
1743 25, /* Ñ - 209 */
1744 15, /* Ò - 210 */
1745 14, /* Ó - 211 */
1746 18, /* Ô - 212 */
1747 25, /* Õ - 213 */
1748 19, /* Ö - 214 */
1749 2, /* × - 215 */
1750 33, /* Ø - 216 */
1751 15, /* Ù - 217 */
1752 14, /* Ú - 218 */
1753 18, /* Û - 219 */
1754 19, /* Ü - 220 */
1755 14, /* Ý - 221 */
1756 2, /* Þ - 222 */
1757 2, /* ß - 223 */
1758 15, /* à - 224 */
1759 14, /* á - 225 */
1760 18, /* â - 226 */
1761 25, /* ã - 227 */
1762 19, /* ä - 228 */
1763 26, /* å - 229 */
1764 2, /* æ - 230 */
1765 28, /* ç - 231 */
1766 15, /* è - 232 */
1767 14, /* é - 233 */
1768 18, /* ê - 234 */
1769 19, /* ë - 235 */
1770 15, /* ì - 236 */
1771 14, /* í - 237 */
1772 18, /* î - 238 */
1773 19, /* ï - 239 */
1774 104, /* ð - 240 */
1775 25, /* ñ - 241 */
1776 15, /* ò - 242 */
1777 14, /* ó - 243 */
1778 18, /* ô - 244 */
1779 25, /* õ - 245 */
1780 19, /* ö - 246 */
1781 2, /* ÷ - 247 */
1782 33, /* ø - 248 */
1783 15, /* ù - 249 */
1784 14, /* ú - 250 */
1785 18, /* û - 251 */
1786 19, /* ü - 252 */
1787 14, /* ý - 253 */
1788 2, /* þ - 254 */
1789 19, /* ÿ - 255 */
1792 /******************************************************************************
1793 * OLE2NLS_isPunctuation [INTERNAL]
1795 static int OLE2NLS_isPunctuation(unsigned char c)
1797 /* "punctuation character" in this context is a character which is
1798 considered "less important" during word sort comparison.
1799 See LCMapString implementation for the precise definition
1800 of "less important". */
1802 return (LCM_Unicode_LUT[-2+2*c]==6);
1805 /******************************************************************************
1806 * identity [Internal]
1808 static int identity(int c)
1810 return c;
1813 /*************************************************************************
1814 * LCMapString32A [KERNEL32.492]
1816 * Convert a string, or generate a sort key from it.
1818 * If (mapflags & LCMAP_SORTKEY), the function will generate
1819 * a sort key for the source string. Else, it will convert it
1820 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1822 * RETURNS
1823 * Error : 0.
1824 * Success : length of the result string.
1826 * NOTES
1827 * If called with scrlen = -1, the function will compute the length
1828 * of the 0-terminated string strsrc by itself.
1830 * If called with dstlen = 0, returns the buffer length that
1831 * would be required.
1833 * NORM_IGNOREWIDTH means to compare ASCII and Unicode characters
1834 * as if they are equal. Since Wine separates ASCII and Unicode into
1835 * separate functions, we shouldn't have to do anything for this flag.
1836 * I added it to the list of flags that don't need a fixme message
1837 * to make MS Word 95 not print several thousand fixme messages for
1838 * this function.
1840 INT32 WINAPI LCMapString32A(
1841 LCID lcid /* locale identifier created with MAKELCID;
1842 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1843 predefined values. */,
1844 DWORD mapflags /* flags */,
1845 LPCSTR srcstr /* source buffer */,
1846 INT32 srclen /* source length */,
1847 LPSTR dststr /* destination buffer */,
1848 INT32 dstlen /* destination buffer length */)
1850 int i;
1852 TRACE(string,"(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1853 lcid,mapflags,srcstr,srclen,dststr,dstlen);
1855 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1857 ERR(ole, "(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
1858 SetLastError(ERROR_INVALID_PARAMETER);
1859 return 0;
1861 if (srclen == -1)
1862 srclen = lstrlen32A(srcstr) + 1 ; /* (include final '\0') */
1864 if (mapflags & ~ ( LCMAP_UPPERCASE | LCMAP_LOWERCASE | LCMAP_SORTKEY |
1865 NORM_IGNORECASE | NORM_IGNORENONSPACE | SORT_STRINGSORT |
1866 NORM_IGNOREWIDTH) )
1868 FIXME(string,"(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1869 "unimplemented flags: 0x%08lx\n",
1870 lcid,mapflags,srcstr,srclen,dststr,dstlen,mapflags);
1873 if ( !(mapflags & LCMAP_SORTKEY) )
1875 int (*f)(int)=identity;
1877 if (dstlen==0)
1878 return srclen; /* dstlen=0 means "do nothing but return required length" */
1879 if (dstlen<srclen)
1880 srclen=dstlen; /* No, this case is not an error under Windows 95.
1881 And no '\0' gets written. */
1882 if (mapflags & LCMAP_UPPERCASE)
1883 f = toupper;
1884 else if (mapflags & LCMAP_LOWERCASE)
1885 f = tolower;
1886 for (i=0; i < srclen; i++)
1887 dststr[i] = (CHAR) f(srcstr[i]);
1888 return srclen;
1891 /* else ... (mapflags & LCMAP_SORTKEY) */
1893 int unicode_len=0;
1894 int case_len=0;
1895 int diacritic_len=0;
1896 int delayed_punctuation_len=0;
1897 char *case_component;
1898 char *diacritic_component;
1899 char *delayed_punctuation_component;
1900 int room,count;
1901 int flag_stringsort = mapflags & SORT_STRINGSORT;
1903 /* compute how much room we will need */
1904 for (i=0;i<srclen;i++)
1906 int ofs;
1907 unsigned char source_char = srcstr[i];
1908 if (source_char!='\0')
1910 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
1912 unicode_len++;
1913 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
1914 unicode_len++; /* double letter */
1916 else
1918 delayed_punctuation_len++;
1922 if (isupper(source_char))
1923 case_len=unicode_len;
1925 ofs = source_char - LCM_Diacritic_Start;
1926 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
1927 diacritic_len=unicode_len;
1930 if (mapflags & NORM_IGNORECASE)
1931 case_len=0;
1932 if (mapflags & NORM_IGNORENONSPACE)
1933 diacritic_len=0;
1935 room = 2 * unicode_len /* "unicode" component */
1936 + diacritic_len /* "diacritic" component */
1937 + case_len /* "case" component */
1938 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
1939 + 4 /* four '\1' separators */
1940 + 1 ; /* terminal '\0' */
1941 if (dstlen==0)
1942 return room;
1943 else if (dstlen<room)
1945 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1946 return 0;
1949 /*FIXME the Pointercheck should not be nessesary */
1950 if (IsBadWritePtr32 (dststr,room))
1951 { ERR (string,"bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
1952 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1953 return 0;
1956 /* locate each component, write separators */
1957 diacritic_component = dststr + 2*unicode_len ;
1958 *diacritic_component++ = '\1';
1959 case_component = diacritic_component + diacritic_len ;
1960 *case_component++ = '\1';
1961 delayed_punctuation_component = case_component + case_len ;
1962 *delayed_punctuation_component++ = '\1';
1963 *delayed_punctuation_component++ = '\1';
1965 /* read source string char by char, write
1966 corresponding weight in each component. */
1967 for (i=0,count=0;i<srclen;i++)
1969 unsigned char source_char=srcstr[i];
1970 if (source_char!='\0')
1972 int type,longcode;
1973 type = LCM_Unicode_LUT[-2+2*source_char];
1974 longcode = type >> 4;
1975 type &= 15;
1976 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
1978 UINT16 encrypted_location = (1<<15) + 7 + 4*count;
1979 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
1980 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
1981 /* big-endian is used here because it lets string comparison be
1982 compatible with numerical comparison */
1984 *delayed_punctuation_component++ = type;
1985 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
1986 /* assumption : a punctuation character is never a
1987 double or accented letter */
1989 else
1991 dststr[2*count] = type;
1992 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
1993 if (longcode)
1995 if (count<case_len)
1996 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1997 if (count<diacritic_len)
1998 diacritic_component[count] = 2; /* assumption: a double letter
1999 is never accented */
2000 count++;
2002 dststr[2*count] = type;
2003 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
2004 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
2005 32 in the first column of LCM_Unicode_LUT --> longcode = 2
2006 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
2009 if (count<case_len)
2010 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2011 if (count<diacritic_len)
2013 int ofs = source_char - LCM_Diacritic_Start;
2014 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
2016 count++;
2020 dststr[room-1] = '\0';
2021 return room;
2025 /*************************************************************************
2026 * LCMapString32W [KERNEL32.493]
2028 * Convert a string, or generate a sort key from it.
2030 * NOTE
2032 * See LCMapString32A for documentation
2034 INT32 WINAPI LCMapString32W(
2035 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT32 srclen,LPWSTR dststr,
2036 INT32 dstlen)
2038 int i;
2040 TRACE(string,"(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2041 lcid,mapflags,srcstr,srclen,dststr,dstlen);
2043 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2045 ERR(ole, "(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
2046 SetLastError(ERROR_INVALID_PARAMETER);
2047 return 0;
2049 if (srclen==-1)
2050 srclen = lstrlen32W(srcstr)+1;
2051 if (mapflags & LCMAP_SORTKEY)
2053 FIXME(string,"(0x%04lx,0x%08lx,%p,%d,%p,%d): "
2054 "unimplemented flags: 0x%08lx\n",
2055 lcid,mapflags,srcstr,srclen,dststr,dstlen,mapflags);
2056 return 0;
2058 else
2060 int (*f)(int)=identity;
2062 if (dstlen==0)
2063 return srclen;
2064 if (dstlen<srclen)
2065 return 0;
2066 if (mapflags & LCMAP_UPPERCASE)
2067 f = toupper;
2068 else if (mapflags & LCMAP_LOWERCASE)
2069 f = tolower;
2070 for (i=0; i < srclen; i++)
2071 dststr[i] = (WCHAR) f(srcstr[i]);
2072 return srclen;
2076 /***********************************************************************
2077 * CompareString16 (OLE2NLS.8)
2079 UINT16 WINAPI CompareString16(DWORD lcid,DWORD fdwStyle,
2080 LPCSTR s1,DWORD l1,LPCSTR s2,DWORD l2)
2082 return (UINT16)CompareString32A(lcid,fdwStyle,s1,l1,s2,l2);
2085 /******************************************************************************
2086 * CompareString32A [KERNEL32.143]
2087 * Compares two strings using locale
2089 * RETURNS
2091 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2092 * failure: 0
2094 * NOTES
2096 * Defaults to a word sort, but uses a string sort if
2097 * SORT_STRINGSORT is set.
2098 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2100 * BUGS
2102 * This implementation ignores the locale
2104 * FIXME
2106 * Quite inefficient.
2108 UINT32 WINAPI CompareString32A(
2109 DWORD lcid, /* locale ID */
2110 DWORD fdwStyle, /* comparison-style options */
2111 LPCSTR s1, /* first string */
2112 DWORD l1, /* length of first string */
2113 LPCSTR s2, /* second string */
2114 DWORD l2) /* length of second string */
2116 int mapstring_flags;
2117 int len1,len2;
2118 int result;
2119 LPSTR sk1,sk2;
2120 TRACE(ole,"%s and %s\n",
2121 debugstr_a (s1), debugstr_a (s2));
2123 if ( (s1==NULL) || (s2==NULL) )
2125 ERR(ole, "(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
2126 SetLastError(ERROR_INVALID_PARAMETER);
2127 return 0;
2130 if(fdwStyle & NORM_IGNORESYMBOLS)
2131 FIXME(ole, "IGNORESYMBOLS not supported\n");
2133 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2134 len1 = LCMapString32A(lcid,mapstring_flags,s1,l1,NULL,0);
2135 len2 = LCMapString32A(lcid,mapstring_flags,s2,l2,NULL,0);
2137 if ((len1==0)||(len2==0))
2138 return 0; /* something wrong happened */
2140 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(),0,len1);
2141 sk2 = (LPSTR)HeapAlloc(GetProcessHeap(),0,len2);
2142 if ( (!LCMapString32A(lcid,mapstring_flags,s1,l1,sk1,len1))
2143 || (!LCMapString32A(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2145 ERR(ole,"Bug in LCmapString32A.\n");
2146 result = 0;
2148 else
2150 /* strcmp doesn't necessarily return -1, 0, or 1 */
2151 result = strcmp(sk1,sk2);
2153 HeapFree(GetProcessHeap(),0,sk1);
2154 HeapFree(GetProcessHeap(),0,sk2);
2156 if (result < 0)
2157 return 1;
2158 if (result == 0)
2159 return 2;
2161 /* must be greater, if we reach this point */
2162 return 3;
2165 /******************************************************************************
2166 * CompareString32W [KERNEL32.144]
2167 * This implementation ignores the locale
2168 * FIXME : Does only string sort. Should
2169 * be reimplemented the same way as CompareString32A.
2171 UINT32 WINAPI CompareString32W(DWORD lcid, DWORD fdwStyle,
2172 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2174 int len,ret;
2175 if(fdwStyle & NORM_IGNORENONSPACE)
2176 FIXME(ole,"IGNORENONSPACE not supprted\n");
2177 if(fdwStyle & NORM_IGNORESYMBOLS)
2178 FIXME(ole,"IGNORESYMBOLS not supported\n");
2180 /* Is strcmp defaulting to string sort or to word sort?? */
2181 /* FIXME: Handle NORM_STRINGSORT */
2182 l1 = (l1==-1)?lstrlen32W(s1):l1;
2183 l2 = (l2==-1)?lstrlen32W(s2):l2;
2184 len = l1<l2 ? l1:l2;
2185 ret = (fdwStyle & NORM_IGNORECASE) ?
2186 lstrncmpi32W(s1,s2,len) : lstrncmp32W(s1,s2,len);
2187 /* not equal, return 1 or 3 */
2188 if(ret!=0) return ret+2;
2189 /* same len, return 2 */
2190 if(l1==l2) return 2;
2191 /* the longer one is lexically greater */
2192 return (l1<l2)? 1 : 3;
2195 /******************************************************************************
2196 * OLE_GetFormatA [Internal]
2198 * FIXME
2199 * Why is it WINAPI if internal?
2201 This function implements stuff for GetDateFormat() and
2202 GetTimeFormat().
2204 d single-digit (no leading zero) day (of month)
2205 dd two-digit day (of month)
2206 ddd short day-of-week name
2207 dddd long day-of-week name
2208 M single-digit month
2209 MM two-digit month
2210 MMM short month name
2211 MMMM full month name
2212 y two-digit year, no leading 0
2213 yy two-digit year
2214 yyyy four-digit year
2215 gg era string
2216 h hours with no leading zero (12-hour)
2217 hh hours with full two digits
2218 H hours with no leading zero (24-hour)
2219 HH hours with full two digits
2220 m minutes with no leading zero
2221 mm minutes with full two digits
2222 s seconds with no leading zero
2223 ss seconds with full two digits
2224 t time marker (A or P)
2225 tt time marker (AM, PM)
2226 '' used to quote literal characters
2227 '' (within a quoted string) indicates a literal '
2229 These functions REQUIRE valid locale, date, and format.
2231 INT32 WINAPI OLE_GetFormatA(LCID locale,
2232 DWORD flags,
2233 DWORD tflags,
2234 LPSYSTEMTIME xtime,
2235 LPCSTR _format, /*in*/
2236 LPSTR date, /*out*/
2237 INT32 datelen)
2239 INT32 inpos, outpos;
2240 int count, type, inquote, Overflow;
2241 char buf[40];
2242 char format[40];
2243 char * pos;
2244 int buflen;
2246 const char * _dgfmt[] = { "%d", "%02d" };
2247 const char ** dgfmt = _dgfmt - 1;
2249 /* report, for debugging */
2250 TRACE(ole, "(0x%lx,0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
2251 locale, flags, tflags,
2252 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2253 _format, _format, date, datelen);
2255 /* initalize state variables and output buffer */
2256 inpos = outpos = 0;
2257 count = 0; inquote = 0; Overflow = 0;
2258 type = '\0';
2259 date[0] = buf[0] = '\0';
2261 strcpy(format,_format);
2263 /* alter the formatstring, while it works for all languages now in wine
2264 its possible that it fails when the time looks like ss:mm:hh as example*/
2265 if (tflags & (TIME_NOMINUTESORSECONDS))
2266 { if ((pos = strstr ( format, ":mm")))
2267 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2270 if (tflags & (TIME_NOSECONDS))
2271 { if ((pos = strstr ( format, ":ss")))
2272 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2276 for (inpos = 0;; inpos++) {
2277 /* TRACE(ole, "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]); */
2278 if (inquote) {
2279 if (format[inpos] == '\'') {
2280 if (format[inpos+1] == '\'') {
2281 inpos += 1;
2282 date[outpos++] = '\'';
2283 } else {
2284 inquote = 0;
2285 continue; /* we did nothing to the output */
2287 } else if (format[inpos] == '\0') {
2288 date[outpos++] = '\0';
2289 if (outpos > datelen) Overflow = 1;
2290 break;
2291 } else {
2292 date[outpos++] = format[inpos];
2293 if (outpos > datelen) {
2294 Overflow = 1;
2295 date[outpos-1] = '\0'; /* this is the last place where
2296 it's safe to write */
2297 break;
2300 } else if ( (count && (format[inpos] != type))
2301 || count == 4
2302 || (count == 2 && strchr("ghHmst", type)) )
2304 if (type == 'd') {
2305 if (count == 4) {
2306 GetLocaleInfo32A(locale,
2307 LOCALE_SDAYNAME1
2308 + xtime->wDayOfWeek - 1,
2309 buf, sizeof(buf));
2310 } else if (count == 3) {
2311 GetLocaleInfo32A(locale,
2312 LOCALE_SABBREVDAYNAME1
2313 + xtime->wDayOfWeek - 1,
2314 buf, sizeof(buf));
2315 } else {
2316 sprintf(buf, dgfmt[count], xtime->wDay);
2318 } else if (type == 'M') {
2319 if (count == 3) {
2320 GetLocaleInfo32A(locale,
2321 LOCALE_SABBREVMONTHNAME1
2322 + xtime->wMonth - 1,
2323 buf, sizeof(buf));
2324 } else if (count == 4) {
2325 GetLocaleInfo32A(locale,
2326 LOCALE_SMONTHNAME1
2327 + xtime->wMonth - 1,
2328 buf, sizeof(buf));
2329 } else {
2330 sprintf(buf, dgfmt[count], xtime->wMonth);
2332 } else if (type == 'y') {
2333 if (count == 4) {
2334 sprintf(buf, "%d", xtime->wYear);
2335 } else if (count == 3) {
2336 strcpy(buf, "yyy");
2337 WARN(ole, "unknown format, c=%c, n=%d\n", type, count);
2338 } else {
2339 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2341 } else if (type == 'g') {
2342 if (count == 2) {
2343 FIXME(ole, "LOCALE_ICALENDARTYPE unimp.\n");
2344 strcpy(buf, "AD");
2345 } else {
2346 strcpy(buf, "g");
2347 WARN(ole, "unknown format, c=%c, n=%d\n", type, count);
2349 } else if (type == 'h') {
2350 /* gives us hours 1:00 -- 12:00 */
2351 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2352 } else if (type == 'H') {
2353 /* 24-hour time */
2354 sprintf(buf, dgfmt[count], xtime->wHour);
2355 } else if ( type == 'm') {
2356 sprintf(buf, dgfmt[count], xtime->wMinute);
2357 } else if ( type == 's') {
2358 sprintf(buf, dgfmt[count], xtime->wSecond);
2359 } else if (type == 't') {
2360 if (count == 1) {
2361 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2362 } else if (count == 2) {
2363 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2364 GetLocaleInfo32A(locale,
2365 (xtime->wHour<12)
2366 ? LOCALE_S1159 : LOCALE_S2359,
2367 buf, sizeof(buf));
2371 /* we need to check the next char in the format string
2372 again, no matter what happened */
2373 inpos--;
2375 /* add the contents of buf to the output */
2376 buflen = strlen(buf);
2377 if (outpos + buflen < datelen) {
2378 date[outpos] = '\0'; /* for strcat to hook onto */
2379 strcat(date, buf);
2380 outpos += buflen;
2381 } else {
2382 date[outpos] = '\0';
2383 strncat(date, buf, datelen - outpos);
2384 date[datelen - 1] = '\0';
2385 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2386 WARN(ole, "insufficient buffer\n");
2387 return 0;
2390 /* reset the variables we used to keep track of this item */
2391 count = 0;
2392 type = '\0';
2393 } else if (format[inpos] == '\0') {
2394 /* we can't check for this at the loop-head, because
2395 that breaks the printing of the last format-item */
2396 date[outpos] = '\0';
2397 break;
2398 } else if (count) {
2399 /* continuing a code for an item */
2400 count +=1;
2401 continue;
2402 } else if (strchr("hHmstyMdg", format[inpos])) {
2403 type = format[inpos];
2404 count = 1;
2405 continue;
2406 } else if (format[inpos] == '\'') {
2407 inquote = 1;
2408 continue;
2409 } else {
2410 date[outpos++] = format[inpos];
2412 /* now deal with a possible buffer overflow */
2413 if (outpos >= datelen) {
2414 date[datelen - 1] = '\0';
2415 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2416 return 0;
2420 if (Overflow) {
2421 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2424 /* finish it off with a string terminator */
2425 outpos++;
2426 /* sanity check */
2427 if (outpos > datelen-1) outpos = datelen-1;
2428 date[outpos] = '\0';
2430 TRACE(ole, "OLE_GetFormatA returns string '%s', len %d\n",
2431 date, outpos);
2432 return outpos;
2435 /******************************************************************************
2436 * OLE_GetFormatW [INTERNAL]
2438 INT32 WINAPI OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
2439 LPSYSTEMTIME xtime,
2440 LPCWSTR format,
2441 LPWSTR output, INT32 outlen)
2443 INT32 inpos, outpos;
2444 int count, type=0, inquote;
2445 int Overflow; /* loop check */
2446 WCHAR buf[40];
2447 int buflen=0;
2448 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2449 WCHAR arg2[] = {'%','0','2','d',0};
2450 WCHAR *argarr[] = {arg0, arg1, arg2};
2451 int datevars=0, timevars=0;
2453 /* make a debug report */
2454 TRACE(ole, "args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p),
2455 %p with max len %d\n",
2456 locale, flags, tflags,
2457 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2458 debugstr_w(format), format, output, outlen);
2461 /* initialize state variables */
2462 inpos = outpos = 0;
2463 count = 0;
2464 inquote = Overflow = 0;
2465 /* this is really just a sanity check */
2466 output[0] = buf[0] = 0;
2468 /* this loop is the core of the function */
2469 for (inpos = 0; /* we have several break points */ ; inpos++) {
2470 if (inquote) {
2471 if (format[inpos] == (WCHAR) '\'') {
2472 if (format[inpos+1] == '\'') {
2473 inpos++;
2474 output[outpos++] = '\'';
2475 } else {
2476 inquote = 0;
2477 continue;
2479 } else if (format[inpos] == 0) {
2480 output[outpos++] = 0;
2481 if (outpos > outlen) Overflow = 1;
2482 break; /* normal exit (within a quote) */
2483 } else {
2484 output[outpos++] = format[inpos]; /* copy input */
2485 if (outpos > outlen) {
2486 Overflow = 1;
2487 output[outpos-1] = 0;
2488 break;
2491 } else if ( (count && (format[inpos] != type))
2492 || ( (count==4 && type =='y') ||
2493 (count==4 && type =='M') ||
2494 (count==4 && type =='d') ||
2495 (count==2 && type =='g') ||
2496 (count==2 && type =='h') ||
2497 (count==2 && type =='H') ||
2498 (count==2 && type =='m') ||
2499 (count==2 && type =='s') ||
2500 (count==2 && type =='t') ) ) {
2501 if (type == 'd') {
2502 if (count == 3) {
2503 GetLocaleInfo32W(locale,
2504 LOCALE_SDAYNAME1 + xtime->wDayOfWeek -1,
2505 buf, sizeof(buf)/sizeof(WCHAR) );
2506 } else if (count == 3) {
2507 GetLocaleInfo32W(locale,
2508 LOCALE_SABBREVDAYNAME1 +
2509 xtime->wDayOfWeek -1,
2510 buf, sizeof(buf)/sizeof(WCHAR) );
2511 } else {
2512 wsnprintf32W(buf, 5, argarr[count], xtime->wDay );
2514 } else if (type == 'M') {
2515 if (count == 4) {
2516 GetLocaleInfo32W(locale, LOCALE_SMONTHNAME1 +
2517 xtime->wMonth -1, buf,
2518 sizeof(buf)/sizeof(WCHAR) );
2519 } else if (count == 3) {
2520 GetLocaleInfo32W(locale, LOCALE_SABBREVMONTHNAME1 +
2521 xtime->wMonth -1, buf,
2522 sizeof(buf)/sizeof(WCHAR) );
2523 } else {
2524 wsnprintf32W(buf, 5, argarr[count], xtime->wMonth);
2526 } else if (type == 'y') {
2527 if (count == 4) {
2528 wsnprintf32W(buf, 6, argarr[1] /* "%d" */,
2529 xtime->wYear);
2530 } else if (count == 3) {
2531 lstrcpynAtoW(buf, "yyy", 5);
2532 } else {
2533 wsnprintf32W(buf, 6, argarr[count],
2534 xtime->wYear % 100);
2536 } else if (type == 'g') {
2537 if (count == 2) {
2538 FIXME(ole, "LOCALE_ICALENDARTYPE unimplemented\n");
2539 lstrcpynAtoW(buf, "AD", 5);
2540 } else {
2541 /* Win API sez we copy it verbatim */
2542 lstrcpynAtoW(buf, "g", 5);
2544 } else if (type == 'h') {
2545 /* hours 1:00-12:00 --- is this right? */
2546 wsnprintf32W(buf, 5, argarr[count],
2547 (xtime->wHour-1)%12 +1);
2548 } else if (type == 'H') {
2549 wsnprintf32W(buf, 5, argarr[count],
2550 xtime->wHour);
2551 } else if (type == 'm' ) {
2552 wsnprintf32W(buf, 5, argarr[count],
2553 xtime->wMinute);
2554 } else if (type == 's' ) {
2555 wsnprintf32W(buf, 5, argarr[count],
2556 xtime->wSecond);
2557 } else if (type == 't') {
2558 GetLocaleInfo32W(locale, (xtime->wHour < 12) ?
2559 LOCALE_S1159 : LOCALE_S2359,
2560 buf, sizeof(buf) );
2561 if (count == 1) {
2562 buf[1] = 0;
2566 /* no matter what happened, we need to check this next
2567 character the next time we loop through */
2568 inpos--;
2570 /* cat buf onto the output */
2571 outlen = lstrlen32W(buf);
2572 if (outpos + buflen < outlen) {
2573 output[outpos] = 0; /* a "hook" for strcat */
2574 lstrcat32W(output, buf);
2575 outpos += buflen;
2576 } else {
2577 output[outpos] = 0;
2578 lstrcatn32W(output, buf, outlen - outpos);
2579 output[outlen - 1] = 0;
2580 Overflow = 1;
2581 break; /* Abnormal exit */
2584 /* reset the variables we used this time */
2585 count = 0;
2586 type = '\0';
2587 } else if (format[inpos] == 0) {
2588 /* we can't check for this at the beginning, because that
2589 would keep us from printing a format spec that ended the
2590 string */
2591 output[outpos] = 0;
2592 break; /* NORMAL EXIT */
2593 } else if (count) {
2594 /* how we keep track of the middle of a format spec */
2595 count++;
2596 continue;
2597 } else if ( (datevars && (format[inpos]=='d' ||
2598 format[inpos]=='M' ||
2599 format[inpos]=='y' ||
2600 format[inpos]=='g') ) ||
2601 (timevars && (format[inpos]=='H' ||
2602 format[inpos]=='h' ||
2603 format[inpos]=='m' ||
2604 format[inpos]=='s' ||
2605 format[inpos]=='t') ) ) {
2606 type = format[inpos];
2607 count = 1;
2608 continue;
2609 } else if (format[inpos] == '\'') {
2610 inquote = 1;
2611 continue;
2612 } else {
2613 /* unquoted literals */
2614 output[outpos++] = format[inpos];
2618 if (Overflow) {
2619 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2620 WARN(ole, " buffer overflow\n");
2623 /* final string terminator and sanity check */
2624 outpos++;
2625 if (outpos > outlen-1) outpos = outlen-1;
2626 output[outpos] = '0';
2628 TRACE(ole, " returning %s\n", debugstr_w(output));
2630 return (!Overflow) ? outlen : 0;
2635 /******************************************************************************
2636 * GetDateFormat32A [KERNEL32.310]
2637 * Makes an ASCII string of the date
2639 * This function uses format to format the date, or, if format
2640 * is NULL, uses the default for the locale. format is a string
2641 * of literal fields and characters as follows:
2643 * - d single-digit (no leading zero) day (of month)
2644 * - dd two-digit day (of month)
2645 * - ddd short day-of-week name
2646 * - dddd long day-of-week name
2647 * - M single-digit month
2648 * - MM two-digit month
2649 * - MMM short month name
2650 * - MMMM full month name
2651 * - y two-digit year, no leading 0
2652 * - yy two-digit year
2653 * - yyyy four-digit year
2654 * - gg era string
2657 INT32 WINAPI GetDateFormat32A(LCID locale,DWORD flags,
2658 LPSYSTEMTIME xtime,
2659 LPCSTR format, LPSTR date,INT32 datelen)
2662 char format_buf[40];
2663 LPCSTR thisformat;
2664 SYSTEMTIME t;
2665 LPSYSTEMTIME thistime;
2666 LCID thislocale;
2667 INT32 ret;
2669 TRACE(ole,"(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2670 locale,flags,xtime,format,date,datelen);
2672 if (!locale) {
2673 locale = LOCALE_SYSTEM_DEFAULT;
2676 if (locale == LOCALE_SYSTEM_DEFAULT) {
2677 thislocale = GetSystemDefaultLCID();
2678 } else if (locale == LOCALE_USER_DEFAULT) {
2679 thislocale = GetUserDefaultLCID();
2680 } else {
2681 thislocale = locale;
2684 if (xtime == NULL) {
2685 GetSystemTime(&t);
2686 thistime = &t;
2687 } else {
2688 thistime = xtime;
2691 if (format == NULL) {
2692 GetLocaleInfo32A(thislocale, ((flags&DATE_LONGDATE)
2693 ? LOCALE_SLONGDATE
2694 : LOCALE_SSHORTDATE),
2695 format_buf, sizeof(format_buf));
2696 thisformat = format_buf;
2697 } else {
2698 thisformat = format;
2702 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
2703 date, datelen);
2706 TRACE(ole,
2707 "GetDateFormat32A() returning %d, with data=%s\n",
2708 ret, date);
2709 return ret;
2712 /******************************************************************************
2713 * GetDateFormat32W [KERNEL32.311]
2714 * Makes a Unicode string of the date
2716 * Acts the same as GetDateFormat32A(), except that it's Unicode.
2717 * Accepts & returns sizes as counts of Unicode characters.
2720 INT32 WINAPI GetDateFormat32W(LCID locale,DWORD flags,
2721 LPSYSTEMTIME xtime,
2722 LPCWSTR format,
2723 LPWSTR date, INT32 datelen)
2725 short datearr[] = {'1','9','9','4','-','1','-','1',0};
2727 FIXME(ole, "STUB (should call OLE_GetFormatW)\n");
2728 lstrcpyn32W(date, datearr, datelen);
2729 return ( datelen < 9) ? datelen : 9;
2734 /**************************************************************************
2735 * EnumDateFormats32A (KERNEL32.198)
2737 BOOL32 WINAPI EnumDateFormats32A(
2738 DATEFMT_ENUMPROC32A lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2740 FIXME(ole, "Only US English supported\n");
2742 if(!lpDateFmtEnumProc)
2744 SetLastError(ERROR_INVALID_PARAMETER);
2745 return FALSE;
2748 switch(dwFlags)
2750 case DATE_SHORTDATE:
2751 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
2752 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
2753 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
2754 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
2755 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
2756 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
2757 return TRUE;
2758 case DATE_LONGDATE:
2759 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
2760 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
2761 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
2762 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
2763 return TRUE;
2764 default:
2765 FIXME(ole, "Unknown date format (%ld)\n", dwFlags);
2766 SetLastError(ERROR_INVALID_PARAMETER);
2767 return FALSE;
2771 /**************************************************************************
2772 * EnumDateFormats32W (KERNEL32.199)
2774 BOOL32 WINAPI EnumDateFormats32W(
2775 DATEFMT_ENUMPROC32W lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2777 FIXME(ole, "(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
2778 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2779 return FALSE;
2782 /**************************************************************************
2783 * EnumTimeFormats32A (KERNEL32.210)
2785 BOOL32 WINAPI EnumTimeFormats32A(
2786 TIMEFMT_ENUMPROC32A lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
2788 FIXME(ole, "Only US English supported\n");
2790 if(!lpTimeFmtEnumProc)
2792 SetLastError(ERROR_INVALID_PARAMETER);
2793 return FALSE;
2796 if(dwFlags)
2798 FIXME(ole, "Unknown time format (%ld)\n", dwFlags);
2801 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
2802 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
2803 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
2804 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
2806 return TRUE;
2809 /**************************************************************************
2810 * EnumTimeFormats32W (KERNEL32.211)
2812 BOOL32 WINAPI EnumTimeFormats32W(
2813 TIMEFMT_ENUMPROC32W lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
2815 FIXME(ole, "(%p,%ld,%ld): stub", lpTimeFmtEnumProc, Locale, dwFlags);
2816 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2817 return FALSE;
2820 /**************************************************************************
2821 * GetNumberFormat32A (KERNEL32.355)
2822 * NOTE: type of lpFormat should be CONST NUMBERFORMAT
2824 INT32 WINAPI GetNumberFormat32A(LCID locale, DWORD dwflags,
2825 LPCSTR lpvalue, char *lpFormat,
2826 LPSTR lpNumberStr, int cchNumber)
2828 int n;
2830 FIXME(file,"%s: stub, no reformating done\n",lpvalue);
2832 n = strlen(lpvalue);
2833 if (cchNumber) {
2834 strncpy(lpNumberStr,lpvalue,cchNumber);
2835 if (cchNumber <= n) {
2836 lpNumberStr[cchNumber-1] = 0;
2837 n = cchNumber-1;
2840 return n;
2842 /******************************************************************************
2843 * OLE2NLS_CheckLocale [intern]
2845 static LCID OLE2NLS_CheckLocale (LCID locale)
2847 if (!locale)
2848 { locale = LOCALE_SYSTEM_DEFAULT;
2851 if (locale == LOCALE_SYSTEM_DEFAULT)
2852 { return GetSystemDefaultLCID();
2854 else if (locale == LOCALE_USER_DEFAULT)
2855 { return GetUserDefaultLCID();
2857 else
2858 { return locale;
2861 /******************************************************************************
2862 * GetTimeFormat32A [KERNEL32.422]
2863 * Makes an ASCII string of the time
2865 * Formats date according to format, or locale default if format is
2866 * NULL. The format consists of literal characters and fields as follows:
2868 * h hours with no leading zero (12-hour)
2869 * hh hours with full two digits
2870 * H hours with no leading zero (24-hour)
2871 * HH hours with full two digits
2872 * m minutes with no leading zero
2873 * mm minutes with full two digits
2874 * s seconds with no leading zero
2875 * ss seconds with full two digits
2876 * t time marker (A or P)
2877 * tt time marker (AM, PM)
2880 INT32 WINAPI
2881 GetTimeFormat32A(LCID locale, /* in */
2882 DWORD flags, /* in */
2883 LPSYSTEMTIME xtime, /* in */
2884 LPCSTR format, /* in */
2885 LPSTR timestr, /* out */
2886 INT32 timelen /* in */)
2887 { char format_buf[40];
2888 LPCSTR thisformat;
2889 SYSTEMTIME t;
2890 LPSYSTEMTIME thistime;
2891 LCID thislocale=0;
2892 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
2893 INT32 ret;
2895 TRACE(ole,"GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
2897 thislocale = OLE2NLS_CheckLocale ( locale );
2899 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
2900 { FIXME(ole,"TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
2903 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
2905 if (format == NULL)
2906 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
2907 { thislocale = GetSystemDefaultLCID();
2909 GetLocaleInfo32A(thislocale, thisflags, format_buf, sizeof(format_buf));
2910 thisformat = format_buf;
2912 else
2913 { thisformat = format;
2916 if (xtime == NULL) /* NULL means use the current local time*/
2917 { GetSystemTime(&t);
2918 thistime = &t;
2920 else
2921 { thistime = xtime;
2923 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
2924 timestr, timelen);
2925 SetLastError(ret);
2926 return ret;
2930 /******************************************************************************
2931 * GetTimeFormat32W [KERNEL32.423]
2932 * Makes a Unicode string of the time
2934 INT32 WINAPI
2935 GetTimeFormat32W(LCID locale, /* in */
2936 DWORD flags, /* in */
2937 LPSYSTEMTIME xtime, /* in */
2938 LPCWSTR format, /* in */
2939 LPWSTR timestr, /* out */
2940 INT32 timelen /* in */)
2941 { WCHAR format_buf[40];
2942 LPCWSTR thisformat;
2943 SYSTEMTIME t;
2944 LPSYSTEMTIME thistime;
2945 LCID thislocale=0;
2946 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
2947 INT32 ret;
2949 TRACE(ole,"GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
2950 xtime,debugstr_w(format),timestr,timelen);
2952 thislocale = OLE2NLS_CheckLocale ( locale );
2954 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
2955 { FIXME(ole,"TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
2958 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
2960 if (format == NULL)
2961 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
2962 { thislocale = GetSystemDefaultLCID();
2964 GetLocaleInfo32W(thislocale, thisflags, format_buf, 40);
2965 thisformat = format_buf;
2967 else
2968 { thisformat = format;
2971 if (xtime == NULL) /* NULL means use the current local time*/
2972 { GetSystemTime(&t);
2973 thistime = &t;
2975 else
2976 { thistime = xtime;
2979 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
2980 timestr, timelen);
2981 SetLastError(ret);
2982 return ret;