Fixes for LANG_NEUTRAL.
[wine/multimedia.git] / ole / ole2nls.c
blob1ebc2d435377ab4dacac48df8d59c0ee4be210e8
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 & 0xff) == 0x00) /*LANG_NEUTRAL ==> US English*/
477 lang = 0x409;
478 WARN(ole,"no language set, assume LANG_ENGLISH_US \n");
483 { switch(lang)
486 LANG_BEGIN (LANG_GERMAN, SUBLANG_GERMAN) /*0x407*/
487 #include "nls/deu.nls"
488 LANG_END
490 LANG_BEGIN (LANG_DANISH, SUBLANG_DEFAULT) /*0x406*/
491 #include "nls/dan.nls"
492 LANG_END
494 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_US) /*0x409*/
495 #include "nls/enu.nls"
496 LANG_END
498 LANG_BEGIN (LANG_ESPERANTO, SUBLANG_DEFAULT) /*0x48f*/
499 #include "nls/esperanto.nls"
500 LANG_END
502 LANG_BEGIN (LANG_FINNISH, SUBLANG_DEFAULT) /*0x040B*/
503 #include "nls/fin.nls"
504 LANG_END
506 LANG_BEGIN (LANG_FRENCH, SUBLANG_DEFAULT) /*0x040C*/
507 #include "nls/fra.nls"
508 LANG_END
510 LANG_BEGIN (LANG_ITALIAN, SUBLANG_ITALIAN) /*0x410*/
511 #include "nls/ita.nls"
512 LANG_END
514 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_UK) /*0x809*/
515 #include "nls/eng.nls"
516 LANG_END
518 LANG_BEGIN (LANG_KOREAN, SUBLANG_KOREAN) /*0x412*/
519 #include "nls/kor.nls"
520 LANG_END
522 LANG_BEGIN (LANG_HUNGARIAN, SUBLANG_DEFAULT) /*0x40e*/
523 #include "nls/hun.nls"
524 LANG_END
526 LANG_BEGIN (LANG_POLISH, SUBLANG_DEFAULT) /*0x415*/
527 #include "nls/plk.nls"
528 LANG_END
530 LANG_BEGIN (LANG_PORTUGUESE ,SUBLANG_PORTUGUESE_BRAZILIAN) /*0x416*/
531 #include "nls/ptb.nls"
532 LANG_END
534 LANG_BEGIN (LANG_SWEDISH, SUBLANG_DEFAULT) /*0x41d*/
535 #include "nls/sve.nls"
536 LANG_END
538 /*Insert other languages here*/
540 default:
541 found=0;
542 break;
543 } /* switch */
546 /* language not found, try without a sublanguage*/
547 if (i==1) lang=MAKELANGID( PRIMARYLANGID(lang), SUBLANG_DEFAULT);
549 /* mask the LC Value */
550 if (i==2) LCType &= 0xfff;
552 i++;
553 } while (!found && i<3);
555 if(!found)
556 { ERR(ole,"'%s' not supported for your language.\n", retString);
557 SetLastError(ERROR_INVALID_PARAMETER);
558 return 0;
560 /* if len=0 return only the length, don't touch the buffer*/
561 if (len)
562 lstrcpyn32A(buf,retString,len);
564 return strlen(retString)+1;
567 /******************************************************************************
568 * GetLocaleInfo32W [KERNEL32.343]
571 INT32 WINAPI GetLocaleInfo32W(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT32 len)
572 { WORD wlen;
573 LPSTR abuf;
575 if (len && (! wbuf) )
576 { SetLastError(ERROR_INSUFFICIENT_BUFFER);
577 return 0;
580 abuf = (LPSTR)HeapAlloc(GetProcessHeap(),0,len);
581 wlen = 2 * GetLocaleInfo32A(lcid, LCType, abuf, len);
583 if (wlen && len) /* if len=0 return only the length*/
584 lstrcpynAtoW(wbuf,abuf,len/2);
586 HeapFree(GetProcessHeap(),0,abuf);
587 return wlen;
590 /******************************************************************************
591 * SetLocaleInfoA [KERNEL32.656]
593 BOOL16 WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
595 FIXME(ole,"(%ld,%ld,%s): stub\n",lcid,lctype,data);
596 return TRUE;
599 /******************************************************************************
600 * IsValidLocale [KERNEL32.489]
602 BOOL32 WINAPI IsValidLocale(LCID lcid,DWORD flags)
604 /* we support ANY language. Well, at least say that...*/
605 return TRUE;
608 /******************************************************************************
609 * EnumSystemLocales32W [KERNEL32.209]
611 BOOL32 WINAPI EnumSystemLocales32W( LOCALE_ENUMPROC32W lpfnLocaleEnum,
612 DWORD flags )
614 int i;
615 BOOL32 ret;
616 WCHAR buffer[200];
617 HKEY xhkey;
619 TRACE(win32,"(%p,%08lx)\n",lpfnLocaleEnum,flags );
620 /* see if we can reuse the Win95 registry entries.... */
621 if (ERROR_SUCCESS==RegOpenKey32A(HKEY_LOCAL_MACHINE,"\\System\\CurrentControlSet\\control\\Nls\\Locale\\",&xhkey)) {
622 i=0;
623 while (1) {
624 if (ERROR_SUCCESS!=RegEnumKey32W(xhkey,i,buffer,sizeof(buffer)))
625 break;
626 if (!lpfnLocaleEnum(buffer))
627 break;
628 i++;
630 RegCloseKey(xhkey);
631 return TRUE;
634 i=0;
635 while (languages[i].langname!=NULL)
637 LPWSTR cp;
638 char xbuffer[10];
640 sprintf(xbuffer,"%08lx",(DWORD)languages[i].langid);
642 cp = HEAP_strdupAtoW( GetProcessHeap(), 0, xbuffer );
643 ret = lpfnLocaleEnum(cp);
644 HeapFree( GetProcessHeap(), 0, cp );
645 if (!ret) break;
646 i++;
648 return TRUE;
651 /******************************************************************************
652 * EnumSystemLocales32A [KERNEL32.208]
654 BOOL32 WINAPI EnumSystemLocales32A(LOCALE_ENUMPROC32A lpfnLocaleEnum,
655 DWORD flags)
657 int i;
658 CHAR buffer[200];
659 HKEY xhkey;
661 TRACE(win32,"(%p,%08lx)\n",
662 lpfnLocaleEnum,flags
664 if (ERROR_SUCCESS==RegOpenKey32A(HKEY_LOCAL_MACHINE,"\\System\\CurrentControlSet\\control\\Nls\\Locale\\",&xhkey)) {
665 i=0;
666 while (1) {
667 if (ERROR_SUCCESS!=RegEnumKey32A(xhkey,i,buffer,sizeof(buffer)))
668 break;
669 if (!lpfnLocaleEnum(buffer))
670 break;
671 i++;
673 RegCloseKey(xhkey);
674 return TRUE;
676 i=0;
677 while (languages[i].langname!=NULL) {
678 sprintf(buffer,"%08lx",(DWORD)languages[i].langid);
679 if (!lpfnLocaleEnum(buffer))
680 break;
681 i++;
683 return TRUE;
686 static const unsigned char CT_CType2_LUT[] = {
687 C2_NOTAPPLICABLE, /* - 0 */
688 C2_NOTAPPLICABLE, /* - 1 */
689 C2_NOTAPPLICABLE, /* - 2 */
690 C2_NOTAPPLICABLE, /* - 3 */
691 C2_NOTAPPLICABLE, /* - 4 */
692 C2_NOTAPPLICABLE, /* - 5 */
693 C2_NOTAPPLICABLE, /* - 6 */
694 C2_NOTAPPLICABLE, /* - 7 */
695 C2_NOTAPPLICABLE, /* - 8 */
696 C2_SEGMENTSEPARATOR, /* - 9 */
697 C2_NOTAPPLICABLE, /* - 10 */
698 C2_NOTAPPLICABLE, /* - 11 */
699 C2_NOTAPPLICABLE, /* - 12 */
700 C2_NOTAPPLICABLE, /* - 13 */
701 C2_NOTAPPLICABLE, /* - 14 */
702 C2_NOTAPPLICABLE, /* - 15 */
703 C2_NOTAPPLICABLE, /* - 16 */
704 C2_NOTAPPLICABLE, /* - 17 */
705 C2_NOTAPPLICABLE, /* - 18 */
706 C2_NOTAPPLICABLE, /* - 19 */
707 C2_NOTAPPLICABLE, /* - 20 */
708 C2_NOTAPPLICABLE, /* - 21 */
709 C2_NOTAPPLICABLE, /* - 22 */
710 C2_NOTAPPLICABLE, /* - 23 */
711 C2_NOTAPPLICABLE, /* - 24 */
712 C2_NOTAPPLICABLE, /* - 25 */
713 C2_NOTAPPLICABLE, /* - 26 */
714 C2_NOTAPPLICABLE, /* - 27 */
715 C2_NOTAPPLICABLE, /* - 28 */
716 C2_NOTAPPLICABLE, /* - 29 */
717 C2_NOTAPPLICABLE, /* - 30 */
718 C2_NOTAPPLICABLE, /* - 31 */
719 C2_WHITESPACE, /* - 32 */
720 C2_OTHERNEUTRAL, /* ! - 33 */
721 C2_OTHERNEUTRAL, /* " - 34 */ /* " */
722 C2_EUROPETERMINATOR, /* # - 35 */
723 C2_EUROPETERMINATOR, /* $ - 36 */
724 C2_EUROPETERMINATOR, /* % - 37 */
725 C2_LEFTTORIGHT, /* & - 38 */
726 C2_OTHERNEUTRAL, /* ' - 39 */
727 C2_OTHERNEUTRAL, /* ( - 40 */
728 C2_OTHERNEUTRAL, /* ) - 41 */
729 C2_OTHERNEUTRAL, /* * - 42 */
730 C2_EUROPETERMINATOR, /* + - 43 */
731 C2_COMMONSEPARATOR, /* , - 44 */
732 C2_EUROPETERMINATOR, /* - - 45 */
733 C2_EUROPESEPARATOR, /* . - 46 */
734 C2_EUROPESEPARATOR, /* / - 47 */
735 C2_EUROPENUMBER, /* 0 - 48 */
736 C2_EUROPENUMBER, /* 1 - 49 */
737 C2_EUROPENUMBER, /* 2 - 50 */
738 C2_EUROPENUMBER, /* 3 - 51 */
739 C2_EUROPENUMBER, /* 4 - 52 */
740 C2_EUROPENUMBER, /* 5 - 53 */
741 C2_EUROPENUMBER, /* 6 - 54 */
742 C2_EUROPENUMBER, /* 7 - 55 */
743 C2_EUROPENUMBER, /* 8 - 56 */
744 C2_EUROPENUMBER, /* 9 - 57 */
745 C2_COMMONSEPARATOR, /* : - 58 */
746 C2_OTHERNEUTRAL, /* ; - 59 */
747 C2_OTHERNEUTRAL, /* < - 60 */
748 C2_OTHERNEUTRAL, /* = - 61 */
749 C2_OTHERNEUTRAL, /* > - 62 */
750 C2_OTHERNEUTRAL, /* ? - 63 */
751 C2_LEFTTORIGHT, /* @ - 64 */
752 C2_LEFTTORIGHT, /* A - 65 */
753 C2_LEFTTORIGHT, /* B - 66 */
754 C2_LEFTTORIGHT, /* C - 67 */
755 C2_LEFTTORIGHT, /* D - 68 */
756 C2_LEFTTORIGHT, /* E - 69 */
757 C2_LEFTTORIGHT, /* F - 70 */
758 C2_LEFTTORIGHT, /* G - 71 */
759 C2_LEFTTORIGHT, /* H - 72 */
760 C2_LEFTTORIGHT, /* I - 73 */
761 C2_LEFTTORIGHT, /* J - 74 */
762 C2_LEFTTORIGHT, /* K - 75 */
763 C2_LEFTTORIGHT, /* L - 76 */
764 C2_LEFTTORIGHT, /* M - 77 */
765 C2_LEFTTORIGHT, /* N - 78 */
766 C2_LEFTTORIGHT, /* O - 79 */
767 C2_LEFTTORIGHT, /* P - 80 */
768 C2_LEFTTORIGHT, /* Q - 81 */
769 C2_LEFTTORIGHT, /* R - 82 */
770 C2_LEFTTORIGHT, /* S - 83 */
771 C2_LEFTTORIGHT, /* T - 84 */
772 C2_LEFTTORIGHT, /* U - 85 */
773 C2_LEFTTORIGHT, /* V - 86 */
774 C2_LEFTTORIGHT, /* W - 87 */
775 C2_LEFTTORIGHT, /* X - 88 */
776 C2_LEFTTORIGHT, /* Y - 89 */
777 C2_LEFTTORIGHT, /* Z - 90 */
778 C2_OTHERNEUTRAL, /* [ - 91 */
779 C2_OTHERNEUTRAL, /* \ - 92 */
780 C2_OTHERNEUTRAL, /* ] - 93 */
781 C2_OTHERNEUTRAL, /* ^ - 94 */
782 C2_OTHERNEUTRAL, /* _ - 95 */
783 C2_OTHERNEUTRAL, /* ` - 96 */
784 C2_LEFTTORIGHT, /* a - 97 */
785 C2_LEFTTORIGHT, /* b - 98 */
786 C2_LEFTTORIGHT, /* c - 99 */
787 C2_LEFTTORIGHT, /* d - 100 */
788 C2_LEFTTORIGHT, /* e - 101 */
789 C2_LEFTTORIGHT, /* f - 102 */
790 C2_LEFTTORIGHT, /* g - 103 */
791 C2_LEFTTORIGHT, /* h - 104 */
792 C2_LEFTTORIGHT, /* i - 105 */
793 C2_LEFTTORIGHT, /* j - 106 */
794 C2_LEFTTORIGHT, /* k - 107 */
795 C2_LEFTTORIGHT, /* l - 108 */
796 C2_LEFTTORIGHT, /* m - 109 */
797 C2_LEFTTORIGHT, /* n - 110 */
798 C2_LEFTTORIGHT, /* o - 111 */
799 C2_LEFTTORIGHT, /* p - 112 */
800 C2_LEFTTORIGHT, /* q - 113 */
801 C2_LEFTTORIGHT, /* r - 114 */
802 C2_LEFTTORIGHT, /* s - 115 */
803 C2_LEFTTORIGHT, /* t - 116 */
804 C2_LEFTTORIGHT, /* u - 117 */
805 C2_LEFTTORIGHT, /* v - 118 */
806 C2_LEFTTORIGHT, /* w - 119 */
807 C2_LEFTTORIGHT, /* x - 120 */
808 C2_LEFTTORIGHT, /* y - 121 */
809 C2_LEFTTORIGHT, /* z - 122 */
810 C2_OTHERNEUTRAL, /* { - 123 */
811 C2_OTHERNEUTRAL, /* | - 124 */
812 C2_OTHERNEUTRAL, /* } - 125 */
813 C2_OTHERNEUTRAL, /* ~ - 126 */
814 C2_NOTAPPLICABLE, /* \x7f - 127 */
815 C2_NOTAPPLICABLE, /* € - 128 */
816 C2_NOTAPPLICABLE, /* � - 129 */
817 C2_OTHERNEUTRAL, /* ‚ - 130 */
818 C2_LEFTTORIGHT, /* ƒ - 131 */
819 C2_OTHERNEUTRAL, /* „ - 132 */
820 C2_OTHERNEUTRAL, /* … - 133 */
821 C2_OTHERNEUTRAL, /* † - 134 */
822 C2_OTHERNEUTRAL, /* ‡ - 135 */
823 C2_LEFTTORIGHT, /* ˆ - 136 */
824 C2_EUROPETERMINATOR, /* ‰ - 137 */
825 C2_LEFTTORIGHT, /* Š - 138 */
826 C2_OTHERNEUTRAL, /* ‹ - 139 */
827 C2_LEFTTORIGHT, /* Π- 140 */
828 C2_NOTAPPLICABLE, /* � - 141 */
829 C2_NOTAPPLICABLE, /* Ž - 142 */
830 C2_NOTAPPLICABLE, /* � - 143 */
831 C2_NOTAPPLICABLE, /* � - 144 */
832 C2_OTHERNEUTRAL, /* ‘ - 145 */
833 C2_OTHERNEUTRAL, /* ’ - 146 */
834 C2_OTHERNEUTRAL, /* “ - 147 */
835 C2_OTHERNEUTRAL, /* ” - 148 */
836 C2_OTHERNEUTRAL, /* • - 149 */
837 C2_OTHERNEUTRAL, /* – - 150 */
838 C2_OTHERNEUTRAL, /* — - 151 */
839 C2_LEFTTORIGHT, /* ˜ - 152 */
840 C2_OTHERNEUTRAL, /* ™ - 153 */
841 C2_LEFTTORIGHT, /* š - 154 */
842 C2_OTHERNEUTRAL, /* › - 155 */
843 C2_LEFTTORIGHT, /* œ - 156 */
844 C2_NOTAPPLICABLE, /* � - 157 */
845 C2_NOTAPPLICABLE, /* ž - 158 */
846 C2_LEFTTORIGHT, /* Ÿ - 159 */
847 C2_WHITESPACE, /*   - 160 */
848 C2_OTHERNEUTRAL, /* ¡ - 161 */
849 C2_EUROPETERMINATOR, /* ¢ - 162 */
850 C2_EUROPETERMINATOR, /* £ - 163 */
851 C2_EUROPETERMINATOR, /* ¤ - 164 */
852 C2_EUROPETERMINATOR, /* ¥ - 165 */
853 C2_OTHERNEUTRAL, /* ¦ - 166 */
854 C2_OTHERNEUTRAL, /* § - 167 */
855 C2_OTHERNEUTRAL, /* ¨ - 168 */
856 C2_OTHERNEUTRAL, /* © - 169 */
857 C2_OTHERNEUTRAL, /* ª - 170 */
858 C2_OTHERNEUTRAL, /* « - 171 */
859 C2_OTHERNEUTRAL, /* ¬ - 172 */
860 C2_OTHERNEUTRAL, /* ­ - 173 */
861 C2_OTHERNEUTRAL, /* ® - 174 */
862 C2_OTHERNEUTRAL, /* ¯ - 175 */
863 C2_EUROPETERMINATOR, /* ° - 176 */
864 C2_EUROPETERMINATOR, /* ± - 177 */
865 C2_EUROPENUMBER, /* ² - 178 */
866 C2_EUROPENUMBER, /* ³ - 179 */
867 C2_OTHERNEUTRAL, /* ´ - 180 */
868 C2_OTHERNEUTRAL, /* µ - 181 */
869 C2_OTHERNEUTRAL, /* ¶ - 182 */
870 C2_OTHERNEUTRAL, /* · - 183 */
871 C2_OTHERNEUTRAL, /* ¸ - 184 */
872 C2_EUROPENUMBER, /* ¹ - 185 */
873 C2_OTHERNEUTRAL, /* º - 186 */
874 C2_OTHERNEUTRAL, /* » - 187 */
875 C2_OTHERNEUTRAL, /* ¼ - 188 */
876 C2_OTHERNEUTRAL, /* ½ - 189 */
877 C2_OTHERNEUTRAL, /* ¾ - 190 */
878 C2_OTHERNEUTRAL, /* ¿ - 191 */
879 C2_LEFTTORIGHT, /* À - 192 */
880 C2_LEFTTORIGHT, /* Á - 193 */
881 C2_LEFTTORIGHT, /* Â - 194 */
882 C2_LEFTTORIGHT, /* Ã - 195 */
883 C2_LEFTTORIGHT, /* Ä - 196 */
884 C2_LEFTTORIGHT, /* Å - 197 */
885 C2_LEFTTORIGHT, /* Æ - 198 */
886 C2_LEFTTORIGHT, /* Ç - 199 */
887 C2_LEFTTORIGHT, /* È - 200 */
888 C2_LEFTTORIGHT, /* É - 201 */
889 C2_LEFTTORIGHT, /* Ê - 202 */
890 C2_LEFTTORIGHT, /* Ë - 203 */
891 C2_LEFTTORIGHT, /* Ì - 204 */
892 C2_LEFTTORIGHT, /* Í - 205 */
893 C2_LEFTTORIGHT, /* Î - 206 */
894 C2_LEFTTORIGHT, /* Ï - 207 */
895 C2_LEFTTORIGHT, /* Ð - 208 */
896 C2_LEFTTORIGHT, /* Ñ - 209 */
897 C2_LEFTTORIGHT, /* Ò - 210 */
898 C2_LEFTTORIGHT, /* Ó - 211 */
899 C2_LEFTTORIGHT, /* Ô - 212 */
900 C2_LEFTTORIGHT, /* Õ - 213 */
901 C2_LEFTTORIGHT, /* Ö - 214 */
902 C2_OTHERNEUTRAL, /* × - 215 */
903 C2_LEFTTORIGHT, /* Ø - 216 */
904 C2_LEFTTORIGHT, /* Ù - 217 */
905 C2_LEFTTORIGHT, /* Ú - 218 */
906 C2_LEFTTORIGHT, /* Û - 219 */
907 C2_LEFTTORIGHT, /* Ü - 220 */
908 C2_LEFTTORIGHT, /* Ý - 221 */
909 C2_LEFTTORIGHT, /* Þ - 222 */
910 C2_LEFTTORIGHT, /* ß - 223 */
911 C2_LEFTTORIGHT, /* à - 224 */
912 C2_LEFTTORIGHT, /* á - 225 */
913 C2_LEFTTORIGHT, /* â - 226 */
914 C2_LEFTTORIGHT, /* ã - 227 */
915 C2_LEFTTORIGHT, /* ä - 228 */
916 C2_LEFTTORIGHT, /* å - 229 */
917 C2_LEFTTORIGHT, /* æ - 230 */
918 C2_LEFTTORIGHT, /* ç - 231 */
919 C2_LEFTTORIGHT, /* è - 232 */
920 C2_LEFTTORIGHT, /* é - 233 */
921 C2_LEFTTORIGHT, /* ê - 234 */
922 C2_LEFTTORIGHT, /* ë - 235 */
923 C2_LEFTTORIGHT, /* ì - 236 */
924 C2_LEFTTORIGHT, /* í - 237 */
925 C2_LEFTTORIGHT, /* î - 238 */
926 C2_LEFTTORIGHT, /* ï - 239 */
927 C2_LEFTTORIGHT, /* ð - 240 */
928 C2_LEFTTORIGHT, /* ñ - 241 */
929 C2_LEFTTORIGHT, /* ò - 242 */
930 C2_LEFTTORIGHT, /* ó - 243 */
931 C2_LEFTTORIGHT, /* ô - 244 */
932 C2_LEFTTORIGHT, /* õ - 245 */
933 C2_LEFTTORIGHT, /* ö - 246 */
934 C2_OTHERNEUTRAL, /* ÷ - 247 */
935 C2_LEFTTORIGHT, /* ø - 248 */
936 C2_LEFTTORIGHT, /* ù - 249 */
937 C2_LEFTTORIGHT, /* ú - 250 */
938 C2_LEFTTORIGHT, /* û - 251 */
939 C2_LEFTTORIGHT, /* ü - 252 */
940 C2_LEFTTORIGHT, /* ý - 253 */
941 C2_LEFTTORIGHT, /* þ - 254 */
942 C2_LEFTTORIGHT /* ÿ - 255 */
945 static const WORD CT_CType3_LUT[] = {
946 0x0000, /* - 0 */
947 0x0000, /* - 1 */
948 0x0000, /* - 2 */
949 0x0000, /* - 3 */
950 0x0000, /* - 4 */
951 0x0000, /* - 5 */
952 0x0000, /* - 6 */
953 0x0000, /* - 7 */
954 0x0000, /* - 8 */
955 0x0008, /* - 9 */
956 0x0008, /* - 10 */
957 0x0008, /* - 11 */
958 0x0008, /* - 12 */
959 0x0008, /* - 13 */
960 0x0000, /* - 14 */
961 0x0000, /* - 15 */
962 0x0000, /* - 16 */
963 0x0000, /* - 17 */
964 0x0000, /* - 18 */
965 0x0000, /* - 19 */
966 0x0000, /* - 20 */
967 0x0000, /* - 21 */
968 0x0000, /* - 22 */
969 0x0000, /* - 23 */
970 0x0000, /* - 24 */
971 0x0000, /* - 25 */
972 0x0000, /* - 26 */
973 0x0000, /* - 27 */
974 0x0000, /* - 28 */
975 0x0000, /* - 29 */
976 0x0000, /* - 30 */
977 0x0000, /* - 31 */
978 0x0048, /* - 32 */
979 0x0048, /* ! - 33 */
980 0x0448, /* " - 34 */ /* " */
981 0x0048, /* # - 35 */
982 0x0448, /* $ - 36 */
983 0x0048, /* % - 37 */
984 0x0048, /* & - 38 */
985 0x0440, /* ' - 39 */
986 0x0048, /* ( - 40 */
987 0x0048, /* ) - 41 */
988 0x0048, /* * - 42 */
989 0x0048, /* + - 43 */
990 0x0048, /* , - 44 */
991 0x0440, /* - - 45 */
992 0x0048, /* . - 46 */
993 0x0448, /* / - 47 */
994 0x0040, /* 0 - 48 */
995 0x0040, /* 1 - 49 */
996 0x0040, /* 2 - 50 */
997 0x0040, /* 3 - 51 */
998 0x0040, /* 4 - 52 */
999 0x0040, /* 5 - 53 */
1000 0x0040, /* 6 - 54 */
1001 0x0040, /* 7 - 55 */
1002 0x0040, /* 8 - 56 */
1003 0x0040, /* 9 - 57 */
1004 0x0048, /* : - 58 */
1005 0x0048, /* ; - 59 */
1006 0x0048, /* < - 60 */
1007 0x0448, /* = - 61 */
1008 0x0048, /* > - 62 */
1009 0x0048, /* ? - 63 */
1010 0x0448, /* @ - 64 */
1011 0x8040, /* A - 65 */
1012 0x8040, /* B - 66 */
1013 0x8040, /* C - 67 */
1014 0x8040, /* D - 68 */
1015 0x8040, /* E - 69 */
1016 0x8040, /* F - 70 */
1017 0x8040, /* G - 71 */
1018 0x8040, /* H - 72 */
1019 0x8040, /* I - 73 */
1020 0x8040, /* J - 74 */
1021 0x8040, /* K - 75 */
1022 0x8040, /* L - 76 */
1023 0x8040, /* M - 77 */
1024 0x8040, /* N - 78 */
1025 0x8040, /* O - 79 */
1026 0x8040, /* P - 80 */
1027 0x8040, /* Q - 81 */
1028 0x8040, /* R - 82 */
1029 0x8040, /* S - 83 */
1030 0x8040, /* T - 84 */
1031 0x8040, /* U - 85 */
1032 0x8040, /* V - 86 */
1033 0x8040, /* W - 87 */
1034 0x8040, /* X - 88 */
1035 0x8040, /* Y - 89 */
1036 0x8040, /* Z - 90 */
1037 0x0048, /* [ - 91 */
1038 0x0448, /* \ - 92 */
1039 0x0048, /* ] - 93 */
1040 0x0448, /* ^ - 94 */
1041 0x0448, /* _ - 95 */
1042 0x0448, /* ` - 96 */
1043 0x8040, /* a - 97 */
1044 0x8040, /* b - 98 */
1045 0x8040, /* c - 99 */
1046 0x8040, /* d - 100 */
1047 0x8040, /* e - 101 */
1048 0x8040, /* f - 102 */
1049 0x8040, /* g - 103 */
1050 0x8040, /* h - 104 */
1051 0x8040, /* i - 105 */
1052 0x8040, /* j - 106 */
1053 0x8040, /* k - 107 */
1054 0x8040, /* l - 108 */
1055 0x8040, /* m - 109 */
1056 0x8040, /* n - 110 */
1057 0x8040, /* o - 111 */
1058 0x8040, /* p - 112 */
1059 0x8040, /* q - 113 */
1060 0x8040, /* r - 114 */
1061 0x8040, /* s - 115 */
1062 0x8040, /* t - 116 */
1063 0x8040, /* u - 117 */
1064 0x8040, /* v - 118 */
1065 0x8040, /* w - 119 */
1066 0x8040, /* x - 120 */
1067 0x8040, /* y - 121 */
1068 0x8040, /* z - 122 */
1069 0x0048, /* { - 123 */
1070 0x0048, /* | - 124 */
1071 0x0048, /* } - 125 */
1072 0x0448, /* ~ - 126 */
1073 0x0000, /* \x7f - 127 */
1074 0x0000, /* € - 128 */
1075 0x0000, /* � - 129 */
1076 0x0008, /* ‚ - 130 */
1077 0x8000, /* ƒ - 131 */
1078 0x0008, /* „ - 132 */
1079 0x0008, /* … - 133 */
1080 0x0008, /* † - 134 */
1081 0x0008, /* ‡ - 135 */
1082 0x0001, /* ˆ - 136 */
1083 0x0008, /* ‰ - 137 */
1084 0x8003, /* Š - 138 */
1085 0x0008, /* ‹ - 139 */
1086 0x8000, /* Π- 140 */
1087 0x0000, /* � - 141 */
1088 0x0000, /* Ž - 142 */
1089 0x0000, /* � - 143 */
1090 0x0000, /* � - 144 */
1091 0x0088, /* ‘ - 145 */
1092 0x0088, /* ’ - 146 */
1093 0x0088, /* “ - 147 */
1094 0x0088, /* ” - 148 */
1095 0x0008, /* • - 149 */
1096 0x0400, /* – - 150 */
1097 0x0400, /* — - 151 */
1098 0x0408, /* ˜ - 152 */
1099 0x0000, /* ™ - 153 */
1100 0x8003, /* š - 154 */
1101 0x0008, /* › - 155 */
1102 0x8000, /* œ - 156 */
1103 0x0000, /* � - 157 */
1104 0x0000, /* ž - 158 */
1105 0x8003, /* Ÿ - 159 */
1106 0x0008, /*   - 160 */
1107 0x0008, /* ¡ - 161 */
1108 0x0048, /* ¢ - 162 */
1109 0x0048, /* £ - 163 */
1110 0x0008, /* ¤ - 164 */
1111 0x0048, /* ¥ - 165 */
1112 0x0048, /* ¦ - 166 */
1113 0x0008, /* § - 167 */
1114 0x0408, /* ¨ - 168 */
1115 0x0008, /* © - 169 */
1116 0x0400, /* ª - 170 */
1117 0x0008, /* « - 171 */
1118 0x0048, /* ¬ - 172 */
1119 0x0408, /* ­ - 173 */
1120 0x0008, /* ® - 174 */
1121 0x0448, /* ¯ - 175 */
1122 0x0008, /* ° - 176 */
1123 0x0008, /* ± - 177 */
1124 0x0000, /* ² - 178 */
1125 0x0000, /* ³ - 179 */
1126 0x0408, /* ´ - 180 */
1127 0x0008, /* µ - 181 */
1128 0x0008, /* ¶ - 182 */
1129 0x0008, /* · - 183 */
1130 0x0408, /* ¸ - 184 */
1131 0x0000, /* ¹ - 185 */
1132 0x0400, /* º - 186 */
1133 0x0008, /* » - 187 */
1134 0x0000, /* ¼ - 188 */
1135 0x0000, /* ½ - 189 */
1136 0x0000, /* ¾ - 190 */
1137 0x0008, /* ¿ - 191 */
1138 0x8003, /* À - 192 */
1139 0x8003, /* Á - 193 */
1140 0x8003, /* Â - 194 */
1141 0x8003, /* Ã - 195 */
1142 0x8003, /* Ä - 196 */
1143 0x8003, /* Å - 197 */
1144 0x8000, /* Æ - 198 */
1145 0x8003, /* Ç - 199 */
1146 0x8003, /* È - 200 */
1147 0x8003, /* É - 201 */
1148 0x8003, /* Ê - 202 */
1149 0x8003, /* Ë - 203 */
1150 0x8003, /* Ì - 204 */
1151 0x8003, /* Í - 205 */
1152 0x8003, /* Î - 206 */
1153 0x8003, /* Ï - 207 */
1154 0x8000, /* Ð - 208 */
1155 0x8003, /* Ñ - 209 */
1156 0x8003, /* Ò - 210 */
1157 0x8003, /* Ó - 211 */
1158 0x8003, /* Ô - 212 */
1159 0x8003, /* Õ - 213 */
1160 0x8003, /* Ö - 214 */
1161 0x0008, /* × - 215 */
1162 0x8003, /* Ø - 216 */
1163 0x8003, /* Ù - 217 */
1164 0x8003, /* Ú - 218 */
1165 0x8003, /* Û - 219 */
1166 0x8003, /* Ü - 220 */
1167 0x8003, /* Ý - 221 */
1168 0x8000, /* Þ - 222 */
1169 0x8000, /* ß - 223 */
1170 0x8003, /* à - 224 */
1171 0x8003, /* á - 225 */
1172 0x8003, /* â - 226 */
1173 0x8003, /* ã - 227 */
1174 0x8003, /* ä - 228 */
1175 0x8003, /* å - 229 */
1176 0x8000, /* æ - 230 */
1177 0x8003, /* ç - 231 */
1178 0x8003, /* è - 232 */
1179 0x8003, /* é - 233 */
1180 0x8003, /* ê - 234 */
1181 0x8003, /* ë - 235 */
1182 0x8003, /* ì - 236 */
1183 0x8003, /* í - 237 */
1184 0x8003, /* î - 238 */
1185 0x8003, /* ï - 239 */
1186 0x8000, /* ð - 240 */
1187 0x8003, /* ñ - 241 */
1188 0x8003, /* ò - 242 */
1189 0x8003, /* ó - 243 */
1190 0x8003, /* ô - 244 */
1191 0x8003, /* õ - 245 */
1192 0x8003, /* ö - 246 */
1193 0x0008, /* ÷ - 247 */
1194 0x8003, /* ø - 248 */
1195 0x8003, /* ù - 249 */
1196 0x8003, /* ú - 250 */
1197 0x8003, /* û - 251 */
1198 0x8003, /* ü - 252 */
1199 0x8003, /* ý - 253 */
1200 0x8000, /* þ - 254 */
1201 0x8003 /* ÿ - 255 */
1204 /******************************************************************************
1205 * GetStringType16 [OLE2NLS.7]
1207 BOOL16 WINAPI GetStringType16(LCID locale,DWORD dwInfoType,LPCSTR src,
1208 INT16 cchSrc,LPWORD chartype)
1210 return GetStringTypeEx32A(locale,dwInfoType,src,cchSrc,chartype);
1212 /******************************************************************************
1213 * GetStringType32A [KERNEL32.396]
1215 BOOL32 WINAPI GetStringType32A(LCID locale,DWORD dwInfoType,LPCSTR src,
1216 INT32 cchSrc,LPWORD chartype)
1218 return GetStringTypeEx32A(locale,dwInfoType,src,cchSrc,chartype);
1221 /******************************************************************************
1222 * GetStringTypeEx32A [KERNEL32.397]
1224 * FIXME: Ignores the locale.
1226 BOOL32 WINAPI GetStringTypeEx32A(LCID locale,DWORD dwInfoType,LPCSTR src,
1227 INT32 cchSrc,LPWORD chartype)
1229 int i;
1231 if ((src==NULL) || (chartype==NULL) || (src==(LPSTR)chartype))
1233 SetLastError(ERROR_INVALID_PARAMETER);
1234 return FALSE;
1237 if (cchSrc==-1)
1238 cchSrc=lstrlen32A(src)+1;
1240 switch (dwInfoType) {
1241 case CT_CTYPE1:
1242 for (i=0;i<cchSrc;i++)
1244 chartype[i] = 0;
1245 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1246 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1247 if (islower(src[i])) chartype[i]|=C1_LOWER;
1248 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1249 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1250 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1251 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1252 /* FIXME: isblank() is a GNU extension */
1253 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1254 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1255 /* C1_XDIGIT */
1257 return TRUE;
1259 case CT_CTYPE2:
1260 for (i=0;i<cchSrc;i++)
1262 chartype[i]=(WORD)CT_CType2_LUT[i];
1264 return TRUE;
1266 case CT_CTYPE3:
1267 for (i=0;i<cchSrc;i++)
1269 chartype[i]=CT_CType3_LUT[i];
1271 return TRUE;
1273 default:
1274 ERR(ole,"Unknown dwInfoType:%ld\n",dwInfoType);
1275 return FALSE;
1279 /******************************************************************************
1280 * GetStringType32W [KERNEL32.399]
1282 * NOTES
1283 * Yes, this is missing LCID locale. MS fault.
1285 BOOL32 WINAPI GetStringType32W(DWORD dwInfoType,LPCWSTR src,INT32 cchSrc,
1286 LPWORD chartype)
1288 return GetStringTypeEx32W(0/*defaultlocale*/,dwInfoType,src,cchSrc,chartype);
1291 /******************************************************************************
1292 * GetStringTypeEx32W [KERNEL32.398]
1294 * FIXME: unicode chars are assumed chars
1296 BOOL32 WINAPI GetStringTypeEx32W(LCID locale,DWORD dwInfoType,LPCWSTR src,
1297 INT32 cchSrc,LPWORD chartype)
1299 int i;
1302 if (cchSrc==-1)
1303 cchSrc=lstrlen32W(src)+1;
1305 switch (dwInfoType) {
1306 case CT_CTYPE2:
1307 FIXME(ole,"CT_CTYPE2 not supported.\n");
1308 return FALSE;
1309 case CT_CTYPE3:
1310 FIXME(ole,"CT_CTYPE3 not supported.\n");
1311 return FALSE;
1312 default:break;
1314 for (i=0;i<cchSrc;i++) {
1315 chartype[i] = 0;
1316 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1317 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1318 if (islower(src[i])) chartype[i]|=C1_LOWER;
1319 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1320 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1321 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1322 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1323 /* FIXME: isblank() is a GNU extension */
1324 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1325 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1326 /* C1_XDIGIT */
1328 return TRUE;
1331 /*****************************************************************
1332 * VerLanguageName16 [VER.10]
1334 DWORD WINAPI VerLanguageName16(UINT16 langid,LPSTR langname,UINT16 langnamelen)
1336 int i;
1337 DWORD result;
1338 char buffer[80];
1340 TRACE(ver,"(%d,%p,%d)\n",langid,langname,langnamelen);
1341 /* First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
1342 * from the registry.
1344 sprintf(buffer,
1345 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
1346 langid);
1347 result = RegQueryValue16(HKEY_LOCAL_MACHINE, buffer, langname,
1348 (LPDWORD)&langnamelen);
1349 if (result == ERROR_SUCCESS) {
1350 langname[langnamelen-1]='\0';
1351 return langnamelen;
1353 /* if that fails, use the internal table */
1354 for (i=0;languages[i].langid!=0;i++)
1355 if (langid==languages[i].langid)
1356 break;
1357 strncpy(langname,languages[i].langname,langnamelen);
1358 langname[langnamelen-1]='\0';
1359 return strlen(languages[i].langname);
1362 /*****************************************************************
1363 * VerLanguageName32A [VERSION.9]
1365 DWORD WINAPI VerLanguageName32A(UINT32 langid,LPSTR langname,
1366 UINT32 langnamelen)
1368 return VerLanguageName16(langid,langname,langnamelen);
1371 /*****************************************************************
1372 * VerLanguageName32W [VERSION.10]
1374 DWORD WINAPI VerLanguageName32W(UINT32 langid,LPWSTR langname,
1375 UINT32 langnamelen)
1377 int i;
1378 LPWSTR keyname;
1379 DWORD result;
1380 char buffer[80];
1382 /* First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
1383 * from the registry.
1385 sprintf(buffer,
1386 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
1387 langid);
1388 keyname = HEAP_strdupAtoW( GetProcessHeap(), 0, buffer );
1389 result = RegQueryValue32W(HKEY_LOCAL_MACHINE, keyname, langname,
1390 (LPDWORD)&langnamelen);
1391 HeapFree( GetProcessHeap(), 0, keyname );
1392 if (result != ERROR_SUCCESS) {
1393 /* if that fails, use the internal table */
1394 for (i=0;languages[i].langid!=0;i++)
1395 if (langid==languages[i].langid)
1396 break;
1397 lstrcpyAtoW( langname, languages[i].langname );
1398 langnamelen = strlen(languages[i].langname);
1399 /* same as strlenW(langname); */
1401 return langnamelen;
1404 static const unsigned char LCM_Unicode_LUT[] = {
1405 6 , 3, /* - 1 */
1406 6 , 4, /* - 2 */
1407 6 , 5, /* - 3 */
1408 6 , 6, /* - 4 */
1409 6 , 7, /* - 5 */
1410 6 , 8, /* - 6 */
1411 6 , 9, /* - 7 */
1412 6 , 10, /* - 8 */
1413 7 , 5, /* - 9 */
1414 7 , 6, /* - 10 */
1415 7 , 7, /* - 11 */
1416 7 , 8, /* - 12 */
1417 7 , 9, /* - 13 */
1418 6 , 11, /* - 14 */
1419 6 , 12, /* - 15 */
1420 6 , 13, /* - 16 */
1421 6 , 14, /* - 17 */
1422 6 , 15, /* - 18 */
1423 6 , 16, /* - 19 */
1424 6 , 17, /* - 20 */
1425 6 , 18, /* - 21 */
1426 6 , 19, /* - 22 */
1427 6 , 20, /* - 23 */
1428 6 , 21, /* - 24 */
1429 6 , 22, /* - 25 */
1430 6 , 23, /* - 26 */
1431 6 , 24, /* - 27 */
1432 6 , 25, /* - 28 */
1433 6 , 26, /* - 29 */
1434 6 , 27, /* - 30 */
1435 6 , 28, /* - 31 */
1436 7 , 2, /* - 32 */
1437 7 , 28, /* ! - 33 */
1438 7 , 29, /* " - 34 */ /* " */
1439 7 , 31, /* # - 35 */
1440 7 , 33, /* $ - 36 */
1441 7 , 35, /* % - 37 */
1442 7 , 37, /* & - 38 */
1443 6 , 128, /* ' - 39 */
1444 7 , 39, /* ( - 40 */
1445 7 , 42, /* ) - 41 */
1446 7 , 45, /* * - 42 */
1447 8 , 3, /* + - 43 */
1448 7 , 47, /* , - 44 */
1449 6 , 130, /* - - 45 */
1450 7 , 51, /* . - 46 */
1451 7 , 53, /* / - 47 */
1452 12 , 3, /* 0 - 48 */
1453 12 , 33, /* 1 - 49 */
1454 12 , 51, /* 2 - 50 */
1455 12 , 70, /* 3 - 51 */
1456 12 , 88, /* 4 - 52 */
1457 12 , 106, /* 5 - 53 */
1458 12 , 125, /* 6 - 54 */
1459 12 , 144, /* 7 - 55 */
1460 12 , 162, /* 8 - 56 */
1461 12 , 180, /* 9 - 57 */
1462 7 , 55, /* : - 58 */
1463 7 , 58, /* ; - 59 */
1464 8 , 14, /* < - 60 */
1465 8 , 18, /* = - 61 */
1466 8 , 20, /* > - 62 */
1467 7 , 60, /* ? - 63 */
1468 7 , 62, /* @ - 64 */
1469 14 , 2, /* A - 65 */
1470 14 , 9, /* B - 66 */
1471 14 , 10, /* C - 67 */
1472 14 , 26, /* D - 68 */
1473 14 , 33, /* E - 69 */
1474 14 , 35, /* F - 70 */
1475 14 , 37, /* G - 71 */
1476 14 , 44, /* H - 72 */
1477 14 , 50, /* I - 73 */
1478 14 , 53, /* J - 74 */
1479 14 , 54, /* K - 75 */
1480 14 , 72, /* L - 76 */
1481 14 , 81, /* M - 77 */
1482 14 , 112, /* N - 78 */
1483 14 , 124, /* O - 79 */
1484 14 , 126, /* P - 80 */
1485 14 , 137, /* Q - 81 */
1486 14 , 138, /* R - 82 */
1487 14 , 145, /* S - 83 */
1488 14 , 153, /* T - 84 */
1489 14 , 159, /* U - 85 */
1490 14 , 162, /* V - 86 */
1491 14 , 164, /* W - 87 */
1492 14 , 166, /* X - 88 */
1493 14 , 167, /* Y - 89 */
1494 14 , 169, /* Z - 90 */
1495 7 , 63, /* [ - 91 */
1496 7 , 65, /* \ - 92 */
1497 7 , 66, /* ] - 93 */
1498 7 , 67, /* ^ - 94 */
1499 7 , 68, /* _ - 95 */
1500 7 , 72, /* ` - 96 */
1501 14 , 2, /* a - 97 */
1502 14 , 9, /* b - 98 */
1503 14 , 10, /* c - 99 */
1504 14 , 26, /* d - 100 */
1505 14 , 33, /* e - 101 */
1506 14 , 35, /* f - 102 */
1507 14 , 37, /* g - 103 */
1508 14 , 44, /* h - 104 */
1509 14 , 50, /* i - 105 */
1510 14 , 53, /* j - 106 */
1511 14 , 54, /* k - 107 */
1512 14 , 72, /* l - 108 */
1513 14 , 81, /* m - 109 */
1514 14 , 112, /* n - 110 */
1515 14 , 124, /* o - 111 */
1516 14 , 126, /* p - 112 */
1517 14 , 137, /* q - 113 */
1518 14 , 138, /* r - 114 */
1519 14 , 145, /* s - 115 */
1520 14 , 153, /* t - 116 */
1521 14 , 159, /* u - 117 */
1522 14 , 162, /* v - 118 */
1523 14 , 164, /* w - 119 */
1524 14 , 166, /* x - 120 */
1525 14 , 167, /* y - 121 */
1526 14 , 169, /* z - 122 */
1527 7 , 74, /* { - 123 */
1528 7 , 76, /* | - 124 */
1529 7 , 78, /* } - 125 */
1530 7 , 80, /* ~ - 126 */
1531 6 , 29, /* \x7f - 127 */
1532 6 , 30, /* € - 128 */
1533 6 , 31, /* � - 129 */
1534 7 , 123, /* ‚ - 130 */
1535 14 , 35, /* ƒ - 131 */
1536 7 , 127, /* „ - 132 */
1537 10 , 21, /* … - 133 */
1538 10 , 15, /* † - 134 */
1539 10 , 16, /* ‡ - 135 */
1540 7 , 67, /* ˆ - 136 */
1541 10 , 22, /* ‰ - 137 */
1542 14 , 145, /* Š - 138 */
1543 7 , 136, /* ‹ - 139 */
1544 14 + 16 , 124, /* Π- 140 */
1545 6 , 43, /* � - 141 */
1546 6 , 44, /* Ž - 142 */
1547 6 , 45, /* � - 143 */
1548 6 , 46, /* � - 144 */
1549 7 , 121, /* ‘ - 145 */
1550 7 , 122, /* ’ - 146 */
1551 7 , 125, /* “ - 147 */
1552 7 , 126, /* ” - 148 */
1553 10 , 17, /* • - 149 */
1554 6 , 137, /* – - 150 */
1555 6 , 139, /* — - 151 */
1556 7 , 93, /* ˜ - 152 */
1557 14 , 156, /* ™ - 153 */
1558 14 , 145, /* š - 154 */
1559 7 , 137, /* › - 155 */
1560 14 + 16 , 124, /* œ - 156 */
1561 6 , 59, /* � - 157 */
1562 6 , 60, /* ž - 158 */
1563 14 , 167, /* Ÿ - 159 */
1564 7 , 4, /*   - 160 */
1565 7 , 81, /* ¡ - 161 */
1566 10 , 2, /* ¢ - 162 */
1567 10 , 3, /* £ - 163 */
1568 10 , 4, /* ¤ - 164 */
1569 10 , 5, /* ¥ - 165 */
1570 7 , 82, /* ¦ - 166 */
1571 10 , 6, /* § - 167 */
1572 7 , 83, /* ¨ - 168 */
1573 10 , 7, /* © - 169 */
1574 14 , 2, /* ª - 170 */
1575 8 , 24, /* « - 171 */
1576 10 , 8, /* ¬ - 172 */
1577 6 , 131, /* ­ - 173 */
1578 10 , 9, /* ® - 174 */
1579 7 , 84, /* ¯ - 175 */
1580 10 , 10, /* ° - 176 */
1581 8 , 23, /* ± - 177 */
1582 12 , 51, /* ² - 178 */
1583 12 , 70, /* ³ - 179 */
1584 7 , 85, /* ´ - 180 */
1585 10 , 11, /* µ - 181 */
1586 10 , 12, /* ¶ - 182 */
1587 10 , 13, /* · - 183 */
1588 7 , 86, /* ¸ - 184 */
1589 12 , 33, /* ¹ - 185 */
1590 14 , 124, /* º - 186 */
1591 8 , 26, /* » - 187 */
1592 12 , 21, /* ¼ - 188 */
1593 12 , 25, /* ½ - 189 */
1594 12 , 29, /* ¾ - 190 */
1595 7 , 87, /* ¿ - 191 */
1596 14 , 2, /* À - 192 */
1597 14 , 2, /* Á - 193 */
1598 14 , 2, /* Â - 194 */
1599 14 , 2, /* Ã - 195 */
1600 14 , 2, /* Ä - 196 */
1601 14 , 2, /* Å - 197 */
1602 14 + 16 , 2, /* Æ - 198 */
1603 14 , 10, /* Ç - 199 */
1604 14 , 33, /* È - 200 */
1605 14 , 33, /* É - 201 */
1606 14 , 33, /* Ê - 202 */
1607 14 , 33, /* Ë - 203 */
1608 14 , 50, /* Ì - 204 */
1609 14 , 50, /* Í - 205 */
1610 14 , 50, /* Î - 206 */
1611 14 , 50, /* Ï - 207 */
1612 14 , 26, /* Ð - 208 */
1613 14 , 112, /* Ñ - 209 */
1614 14 , 124, /* Ò - 210 */
1615 14 , 124, /* Ó - 211 */
1616 14 , 124, /* Ô - 212 */
1617 14 , 124, /* Õ - 213 */
1618 14 , 124, /* Ö - 214 */
1619 8 , 28, /* × - 215 */
1620 14 , 124, /* Ø - 216 */
1621 14 , 159, /* Ù - 217 */
1622 14 , 159, /* Ú - 218 */
1623 14 , 159, /* Û - 219 */
1624 14 , 159, /* Ü - 220 */
1625 14 , 167, /* Ý - 221 */
1626 14 + 32 , 153, /* Þ - 222 */
1627 14 + 48 , 145, /* ß - 223 */
1628 14 , 2, /* à - 224 */
1629 14 , 2, /* á - 225 */
1630 14 , 2, /* â - 226 */
1631 14 , 2, /* ã - 227 */
1632 14 , 2, /* ä - 228 */
1633 14 , 2, /* å - 229 */
1634 14 + 16 , 2, /* æ - 230 */
1635 14 , 10, /* ç - 231 */
1636 14 , 33, /* è - 232 */
1637 14 , 33, /* é - 233 */
1638 14 , 33, /* ê - 234 */
1639 14 , 33, /* ë - 235 */
1640 14 , 50, /* ì - 236 */
1641 14 , 50, /* í - 237 */
1642 14 , 50, /* î - 238 */
1643 14 , 50, /* ï - 239 */
1644 14 , 26, /* ð - 240 */
1645 14 , 112, /* ñ - 241 */
1646 14 , 124, /* ò - 242 */
1647 14 , 124, /* ó - 243 */
1648 14 , 124, /* ô - 244 */
1649 14 , 124, /* õ - 245 */
1650 14 , 124, /* ö - 246 */
1651 8 , 29, /* ÷ - 247 */
1652 14 , 124, /* ø - 248 */
1653 14 , 159, /* ù - 249 */
1654 14 , 159, /* ú - 250 */
1655 14 , 159, /* û - 251 */
1656 14 , 159, /* ü - 252 */
1657 14 , 167, /* ý - 253 */
1658 14 + 32 , 153, /* þ - 254 */
1659 14 , 167 /* ÿ - 255 */ };
1661 static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
1663 #define LCM_Diacritic_Start 131
1665 static const unsigned char LCM_Diacritic_LUT[] = {
1666 123, /* ƒ - 131 */
1667 2, /* „ - 132 */
1668 2, /* … - 133 */
1669 2, /* † - 134 */
1670 2, /* ‡ - 135 */
1671 3, /* ˆ - 136 */
1672 2, /* ‰ - 137 */
1673 20, /* Š - 138 */
1674 2, /* ‹ - 139 */
1675 2, /* Π- 140 */
1676 2, /* � - 141 */
1677 2, /* Ž - 142 */
1678 2, /* � - 143 */
1679 2, /* � - 144 */
1680 2, /* ‘ - 145 */
1681 2, /* ’ - 146 */
1682 2, /* “ - 147 */
1683 2, /* ” - 148 */
1684 2, /* • - 149 */
1685 2, /* – - 150 */
1686 2, /* — - 151 */
1687 2, /* ˜ - 152 */
1688 2, /* ™ - 153 */
1689 20, /* š - 154 */
1690 2, /* › - 155 */
1691 2, /* œ - 156 */
1692 2, /* � - 157 */
1693 2, /* ž - 158 */
1694 19, /* Ÿ - 159 */
1695 2, /*   - 160 */
1696 2, /* ¡ - 161 */
1697 2, /* ¢ - 162 */
1698 2, /* £ - 163 */
1699 2, /* ¤ - 164 */
1700 2, /* ¥ - 165 */
1701 2, /* ¦ - 166 */
1702 2, /* § - 167 */
1703 2, /* ¨ - 168 */
1704 2, /* © - 169 */
1705 3, /* ª - 170 */
1706 2, /* « - 171 */
1707 2, /* ¬ - 172 */
1708 2, /* ­ - 173 */
1709 2, /* ® - 174 */
1710 2, /* ¯ - 175 */
1711 2, /* ° - 176 */
1712 2, /* ± - 177 */
1713 2, /* ² - 178 */
1714 2, /* ³ - 179 */
1715 2, /* ´ - 180 */
1716 2, /* µ - 181 */
1717 2, /* ¶ - 182 */
1718 2, /* · - 183 */
1719 2, /* ¸ - 184 */
1720 2, /* ¹ - 185 */
1721 3, /* º - 186 */
1722 2, /* » - 187 */
1723 2, /* ¼ - 188 */
1724 2, /* ½ - 189 */
1725 2, /* ¾ - 190 */
1726 2, /* ¿ - 191 */
1727 15, /* À - 192 */
1728 14, /* Á - 193 */
1729 18, /* Â - 194 */
1730 25, /* Ã - 195 */
1731 19, /* Ä - 196 */
1732 26, /* Å - 197 */
1733 2, /* Æ - 198 */
1734 28, /* Ç - 199 */
1735 15, /* È - 200 */
1736 14, /* É - 201 */
1737 18, /* Ê - 202 */
1738 19, /* Ë - 203 */
1739 15, /* Ì - 204 */
1740 14, /* Í - 205 */
1741 18, /* Î - 206 */
1742 19, /* Ï - 207 */
1743 104, /* Ð - 208 */
1744 25, /* Ñ - 209 */
1745 15, /* Ò - 210 */
1746 14, /* Ó - 211 */
1747 18, /* Ô - 212 */
1748 25, /* Õ - 213 */
1749 19, /* Ö - 214 */
1750 2, /* × - 215 */
1751 33, /* Ø - 216 */
1752 15, /* Ù - 217 */
1753 14, /* Ú - 218 */
1754 18, /* Û - 219 */
1755 19, /* Ü - 220 */
1756 14, /* Ý - 221 */
1757 2, /* Þ - 222 */
1758 2, /* ß - 223 */
1759 15, /* à - 224 */
1760 14, /* á - 225 */
1761 18, /* â - 226 */
1762 25, /* ã - 227 */
1763 19, /* ä - 228 */
1764 26, /* å - 229 */
1765 2, /* æ - 230 */
1766 28, /* ç - 231 */
1767 15, /* è - 232 */
1768 14, /* é - 233 */
1769 18, /* ê - 234 */
1770 19, /* ë - 235 */
1771 15, /* ì - 236 */
1772 14, /* í - 237 */
1773 18, /* î - 238 */
1774 19, /* ï - 239 */
1775 104, /* ð - 240 */
1776 25, /* ñ - 241 */
1777 15, /* ò - 242 */
1778 14, /* ó - 243 */
1779 18, /* ô - 244 */
1780 25, /* õ - 245 */
1781 19, /* ö - 246 */
1782 2, /* ÷ - 247 */
1783 33, /* ø - 248 */
1784 15, /* ù - 249 */
1785 14, /* ú - 250 */
1786 18, /* û - 251 */
1787 19, /* ü - 252 */
1788 14, /* ý - 253 */
1789 2, /* þ - 254 */
1790 19, /* ÿ - 255 */
1793 /******************************************************************************
1794 * OLE2NLS_isPunctuation [INTERNAL]
1796 static int OLE2NLS_isPunctuation(unsigned char c)
1798 /* "punctuation character" in this context is a character which is
1799 considered "less important" during word sort comparison.
1800 See LCMapString implementation for the precise definition
1801 of "less important". */
1803 return (LCM_Unicode_LUT[-2+2*c]==6);
1806 /******************************************************************************
1807 * identity [Internal]
1809 static int identity(int c)
1811 return c;
1814 /*************************************************************************
1815 * LCMapString32A [KERNEL32.492]
1817 * Convert a string, or generate a sort key from it.
1819 * If (mapflags & LCMAP_SORTKEY), the function will generate
1820 * a sort key for the source string. Else, it will convert it
1821 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1823 * RETURNS
1824 * Error : 0.
1825 * Success : length of the result string.
1827 * NOTES
1828 * If called with scrlen = -1, the function will compute the length
1829 * of the 0-terminated string strsrc by itself.
1831 * If called with dstlen = 0, returns the buffer length that
1832 * would be required.
1834 * NORM_IGNOREWIDTH means to compare ASCII and Unicode characters
1835 * as if they are equal. Since Wine separates ASCII and Unicode into
1836 * separate functions, we shouldn't have to do anything for this flag.
1837 * I added it to the list of flags that don't need a fixme message
1838 * to make MS Word 95 not print several thousand fixme messages for
1839 * this function.
1841 INT32 WINAPI LCMapString32A(
1842 LCID lcid /* locale identifier created with MAKELCID;
1843 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1844 predefined values. */,
1845 DWORD mapflags /* flags */,
1846 LPCSTR srcstr /* source buffer */,
1847 INT32 srclen /* source length */,
1848 LPSTR dststr /* destination buffer */,
1849 INT32 dstlen /* destination buffer length */)
1851 int i;
1853 TRACE(string,"(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1854 lcid,mapflags,srcstr,srclen,dststr,dstlen);
1856 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1858 ERR(ole, "(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
1859 SetLastError(ERROR_INVALID_PARAMETER);
1860 return 0;
1862 if (srclen == -1)
1863 srclen = lstrlen32A(srcstr) + 1 ; /* (include final '\0') */
1865 if (mapflags & ~ ( LCMAP_UPPERCASE | LCMAP_LOWERCASE | LCMAP_SORTKEY |
1866 NORM_IGNORECASE | NORM_IGNORENONSPACE | SORT_STRINGSORT |
1867 NORM_IGNOREWIDTH) )
1869 FIXME(string,"(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1870 "unimplemented flags: 0x%08lx\n",
1871 lcid,mapflags,srcstr,srclen,dststr,dstlen,mapflags);
1874 if ( !(mapflags & LCMAP_SORTKEY) )
1876 int (*f)(int)=identity;
1878 if (dstlen==0)
1879 return srclen; /* dstlen=0 means "do nothing but return required length" */
1880 if (dstlen<srclen)
1881 srclen=dstlen; /* No, this case is not an error under Windows 95.
1882 And no '\0' gets written. */
1883 if (mapflags & LCMAP_UPPERCASE)
1884 f = toupper;
1885 else if (mapflags & LCMAP_LOWERCASE)
1886 f = tolower;
1887 for (i=0; i < srclen; i++)
1888 dststr[i] = (CHAR) f(srcstr[i]);
1889 return srclen;
1892 /* else ... (mapflags & LCMAP_SORTKEY) */
1894 int unicode_len=0;
1895 int case_len=0;
1896 int diacritic_len=0;
1897 int delayed_punctuation_len=0;
1898 char *case_component;
1899 char *diacritic_component;
1900 char *delayed_punctuation_component;
1901 int room,count;
1902 int flag_stringsort = mapflags & SORT_STRINGSORT;
1904 /* compute how much room we will need */
1905 for (i=0;i<srclen;i++)
1907 int ofs;
1908 unsigned char source_char = srcstr[i];
1909 if (source_char!='\0')
1911 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
1913 unicode_len++;
1914 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
1915 unicode_len++; /* double letter */
1917 else
1919 delayed_punctuation_len++;
1923 if (isupper(source_char))
1924 case_len=unicode_len;
1926 ofs = source_char - LCM_Diacritic_Start;
1927 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
1928 diacritic_len=unicode_len;
1931 if (mapflags & NORM_IGNORECASE)
1932 case_len=0;
1933 if (mapflags & NORM_IGNORENONSPACE)
1934 diacritic_len=0;
1936 room = 2 * unicode_len /* "unicode" component */
1937 + diacritic_len /* "diacritic" component */
1938 + case_len /* "case" component */
1939 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
1940 + 4 /* four '\1' separators */
1941 + 1 ; /* terminal '\0' */
1942 if (dstlen==0)
1943 return room;
1944 else if (dstlen<room)
1946 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1947 return 0;
1950 /*FIXME the Pointercheck should not be nessesary */
1951 if (IsBadWritePtr32 (dststr,room))
1952 { ERR (string,"bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
1953 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1954 return 0;
1957 /* locate each component, write separators */
1958 diacritic_component = dststr + 2*unicode_len ;
1959 *diacritic_component++ = '\1';
1960 case_component = diacritic_component + diacritic_len ;
1961 *case_component++ = '\1';
1962 delayed_punctuation_component = case_component + case_len ;
1963 *delayed_punctuation_component++ = '\1';
1964 *delayed_punctuation_component++ = '\1';
1966 /* read source string char by char, write
1967 corresponding weight in each component. */
1968 for (i=0,count=0;i<srclen;i++)
1970 unsigned char source_char=srcstr[i];
1971 if (source_char!='\0')
1973 int type,longcode;
1974 type = LCM_Unicode_LUT[-2+2*source_char];
1975 longcode = type >> 4;
1976 type &= 15;
1977 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
1979 UINT16 encrypted_location = (1<<15) + 7 + 4*count;
1980 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
1981 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
1982 /* big-endian is used here because it lets string comparison be
1983 compatible with numerical comparison */
1985 *delayed_punctuation_component++ = type;
1986 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
1987 /* assumption : a punctuation character is never a
1988 double or accented letter */
1990 else
1992 dststr[2*count] = type;
1993 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
1994 if (longcode)
1996 if (count<case_len)
1997 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1998 if (count<diacritic_len)
1999 diacritic_component[count] = 2; /* assumption: a double letter
2000 is never accented */
2001 count++;
2003 dststr[2*count] = type;
2004 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
2005 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
2006 32 in the first column of LCM_Unicode_LUT --> longcode = 2
2007 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
2010 if (count<case_len)
2011 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2012 if (count<diacritic_len)
2014 int ofs = source_char - LCM_Diacritic_Start;
2015 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
2017 count++;
2021 dststr[room-1] = '\0';
2022 return room;
2026 /*************************************************************************
2027 * LCMapString32W [KERNEL32.493]
2029 * Convert a string, or generate a sort key from it.
2031 * NOTE
2033 * See LCMapString32A for documentation
2035 INT32 WINAPI LCMapString32W(
2036 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT32 srclen,LPWSTR dststr,
2037 INT32 dstlen)
2039 int i;
2041 TRACE(string,"(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2042 lcid,mapflags,srcstr,srclen,dststr,dstlen);
2044 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2046 ERR(ole, "(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
2047 SetLastError(ERROR_INVALID_PARAMETER);
2048 return 0;
2050 if (srclen==-1)
2051 srclen = lstrlen32W(srcstr)+1;
2052 if (mapflags & LCMAP_SORTKEY)
2054 FIXME(string,"(0x%04lx,0x%08lx,%p,%d,%p,%d): "
2055 "unimplemented flags: 0x%08lx\n",
2056 lcid,mapflags,srcstr,srclen,dststr,dstlen,mapflags);
2057 return 0;
2059 else
2061 int (*f)(int)=identity;
2063 if (dstlen==0)
2064 return srclen;
2065 if (dstlen<srclen)
2066 return 0;
2067 if (mapflags & LCMAP_UPPERCASE)
2068 f = toupper;
2069 else if (mapflags & LCMAP_LOWERCASE)
2070 f = tolower;
2071 for (i=0; i < srclen; i++)
2072 dststr[i] = (WCHAR) f(srcstr[i]);
2073 return srclen;
2077 /***********************************************************************
2078 * CompareString16 (OLE2NLS.8)
2080 UINT16 WINAPI CompareString16(DWORD lcid,DWORD fdwStyle,
2081 LPCSTR s1,DWORD l1,LPCSTR s2,DWORD l2)
2083 return (UINT16)CompareString32A(lcid,fdwStyle,s1,l1,s2,l2);
2086 /******************************************************************************
2087 * CompareString32A [KERNEL32.143]
2088 * Compares two strings using locale
2090 * RETURNS
2092 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2093 * failure: 0
2095 * NOTES
2097 * Defaults to a word sort, but uses a string sort if
2098 * SORT_STRINGSORT is set.
2099 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2101 * BUGS
2103 * This implementation ignores the locale
2105 * FIXME
2107 * Quite inefficient.
2109 UINT32 WINAPI CompareString32A(
2110 DWORD lcid, /* locale ID */
2111 DWORD fdwStyle, /* comparison-style options */
2112 LPCSTR s1, /* first string */
2113 DWORD l1, /* length of first string */
2114 LPCSTR s2, /* second string */
2115 DWORD l2) /* length of second string */
2117 int mapstring_flags;
2118 int len1,len2;
2119 int result;
2120 LPSTR sk1,sk2;
2121 TRACE(ole,"%s and %s\n",
2122 debugstr_a (s1), debugstr_a (s2));
2124 if ( (s1==NULL) || (s2==NULL) )
2126 ERR(ole, "(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
2127 SetLastError(ERROR_INVALID_PARAMETER);
2128 return 0;
2131 if(fdwStyle & NORM_IGNORESYMBOLS)
2132 FIXME(ole, "IGNORESYMBOLS not supported\n");
2134 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2135 len1 = LCMapString32A(lcid,mapstring_flags,s1,l1,NULL,0);
2136 len2 = LCMapString32A(lcid,mapstring_flags,s2,l2,NULL,0);
2138 if ((len1==0)||(len2==0))
2139 return 0; /* something wrong happened */
2141 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(),0,len1);
2142 sk2 = (LPSTR)HeapAlloc(GetProcessHeap(),0,len2);
2143 if ( (!LCMapString32A(lcid,mapstring_flags,s1,l1,sk1,len1))
2144 || (!LCMapString32A(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2146 ERR(ole,"Bug in LCmapString32A.\n");
2147 result = 0;
2149 else
2151 /* strcmp doesn't necessarily return -1, 0, or 1 */
2152 result = strcmp(sk1,sk2);
2154 HeapFree(GetProcessHeap(),0,sk1);
2155 HeapFree(GetProcessHeap(),0,sk2);
2157 if (result < 0)
2158 return 1;
2159 if (result == 0)
2160 return 2;
2162 /* must be greater, if we reach this point */
2163 return 3;
2166 /******************************************************************************
2167 * CompareString32W [KERNEL32.144]
2168 * This implementation ignores the locale
2169 * FIXME : Does only string sort. Should
2170 * be reimplemented the same way as CompareString32A.
2172 UINT32 WINAPI CompareString32W(DWORD lcid, DWORD fdwStyle,
2173 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2175 int len,ret;
2176 if(fdwStyle & NORM_IGNORENONSPACE)
2177 FIXME(ole,"IGNORENONSPACE not supprted\n");
2178 if(fdwStyle & NORM_IGNORESYMBOLS)
2179 FIXME(ole,"IGNORESYMBOLS not supported\n");
2181 /* Is strcmp defaulting to string sort or to word sort?? */
2182 /* FIXME: Handle NORM_STRINGSORT */
2183 l1 = (l1==-1)?lstrlen32W(s1):l1;
2184 l2 = (l2==-1)?lstrlen32W(s2):l2;
2185 len = l1<l2 ? l1:l2;
2186 ret = (fdwStyle & NORM_IGNORECASE) ?
2187 lstrncmpi32W(s1,s2,len) : lstrncmp32W(s1,s2,len);
2188 /* not equal, return 1 or 3 */
2189 if(ret!=0) return ret+2;
2190 /* same len, return 2 */
2191 if(l1==l2) return 2;
2192 /* the longer one is lexically greater */
2193 return (l1<l2)? 1 : 3;
2196 /******************************************************************************
2197 * OLE_GetFormatA [Internal]
2199 * FIXME
2200 * Why is it WINAPI if internal?
2202 This function implements stuff for GetDateFormat() and
2203 GetTimeFormat().
2205 d single-digit (no leading zero) day (of month)
2206 dd two-digit day (of month)
2207 ddd short day-of-week name
2208 dddd long day-of-week name
2209 M single-digit month
2210 MM two-digit month
2211 MMM short month name
2212 MMMM full month name
2213 y two-digit year, no leading 0
2214 yy two-digit year
2215 yyyy four-digit year
2216 gg era string
2217 h hours with no leading zero (12-hour)
2218 hh hours with full two digits
2219 H hours with no leading zero (24-hour)
2220 HH hours with full two digits
2221 m minutes with no leading zero
2222 mm minutes with full two digits
2223 s seconds with no leading zero
2224 ss seconds with full two digits
2225 t time marker (A or P)
2226 tt time marker (AM, PM)
2227 '' used to quote literal characters
2228 '' (within a quoted string) indicates a literal '
2230 These functions REQUIRE valid locale, date, and format.
2232 INT32 WINAPI OLE_GetFormatA(LCID locale,
2233 DWORD flags,
2234 DWORD tflags,
2235 LPSYSTEMTIME xtime,
2236 LPCSTR _format, /*in*/
2237 LPSTR date, /*out*/
2238 INT32 datelen)
2240 INT32 inpos, outpos;
2241 int count, type, inquote, Overflow;
2242 char buf[40];
2243 char format[40];
2244 char * pos;
2245 int buflen;
2247 const char * _dgfmt[] = { "%d", "%02d" };
2248 const char ** dgfmt = _dgfmt - 1;
2250 /* report, for debugging */
2251 TRACE(ole, "(0x%lx,0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
2252 locale, flags, tflags,
2253 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2254 _format, _format, date, datelen);
2256 /* initalize state variables and output buffer */
2257 inpos = outpos = 0;
2258 count = 0; inquote = 0; Overflow = 0;
2259 type = '\0';
2260 date[0] = buf[0] = '\0';
2262 strcpy(format,_format);
2264 /* alter the formatstring, while it works for all languages now in wine
2265 its possible that it fails when the time looks like ss:mm:hh as example*/
2266 if (tflags & (TIME_NOMINUTESORSECONDS))
2267 { if ((pos = strstr ( format, ":mm")))
2268 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2271 if (tflags & (TIME_NOSECONDS))
2272 { if ((pos = strstr ( format, ":ss")))
2273 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2277 for (inpos = 0;; inpos++) {
2278 /* 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]); */
2279 if (inquote) {
2280 if (format[inpos] == '\'') {
2281 if (format[inpos+1] == '\'') {
2282 inpos += 1;
2283 date[outpos++] = '\'';
2284 } else {
2285 inquote = 0;
2286 continue; /* we did nothing to the output */
2288 } else if (format[inpos] == '\0') {
2289 date[outpos++] = '\0';
2290 if (outpos > datelen) Overflow = 1;
2291 break;
2292 } else {
2293 date[outpos++] = format[inpos];
2294 if (outpos > datelen) {
2295 Overflow = 1;
2296 date[outpos-1] = '\0'; /* this is the last place where
2297 it's safe to write */
2298 break;
2301 } else if ( (count && (format[inpos] != type))
2302 || count == 4
2303 || (count == 2 && strchr("ghHmst", type)) )
2305 if (type == 'd') {
2306 if (count == 4) {
2307 GetLocaleInfo32A(locale,
2308 LOCALE_SDAYNAME1
2309 + xtime->wDayOfWeek - 1,
2310 buf, sizeof(buf));
2311 } else if (count == 3) {
2312 GetLocaleInfo32A(locale,
2313 LOCALE_SABBREVDAYNAME1
2314 + xtime->wDayOfWeek - 1,
2315 buf, sizeof(buf));
2316 } else {
2317 sprintf(buf, dgfmt[count], xtime->wDay);
2319 } else if (type == 'M') {
2320 if (count == 3) {
2321 GetLocaleInfo32A(locale,
2322 LOCALE_SABBREVMONTHNAME1
2323 + xtime->wMonth - 1,
2324 buf, sizeof(buf));
2325 } else if (count == 4) {
2326 GetLocaleInfo32A(locale,
2327 LOCALE_SMONTHNAME1
2328 + xtime->wMonth - 1,
2329 buf, sizeof(buf));
2330 } else {
2331 sprintf(buf, dgfmt[count], xtime->wMonth);
2333 } else if (type == 'y') {
2334 if (count == 4) {
2335 sprintf(buf, "%d", xtime->wYear);
2336 } else if (count == 3) {
2337 strcpy(buf, "yyy");
2338 WARN(ole, "unknown format, c=%c, n=%d\n", type, count);
2339 } else {
2340 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2342 } else if (type == 'g') {
2343 if (count == 2) {
2344 FIXME(ole, "LOCALE_ICALENDARTYPE unimp.\n");
2345 strcpy(buf, "AD");
2346 } else {
2347 strcpy(buf, "g");
2348 WARN(ole, "unknown format, c=%c, n=%d\n", type, count);
2350 } else if (type == 'h') {
2351 /* gives us hours 1:00 -- 12:00 */
2352 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2353 } else if (type == 'H') {
2354 /* 24-hour time */
2355 sprintf(buf, dgfmt[count], xtime->wHour);
2356 } else if ( type == 'm') {
2357 sprintf(buf, dgfmt[count], xtime->wMinute);
2358 } else if ( type == 's') {
2359 sprintf(buf, dgfmt[count], xtime->wSecond);
2360 } else if (type == 't') {
2361 if (count == 1) {
2362 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2363 } else if (count == 2) {
2364 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2365 GetLocaleInfo32A(locale,
2366 (xtime->wHour<12)
2367 ? LOCALE_S1159 : LOCALE_S2359,
2368 buf, sizeof(buf));
2372 /* we need to check the next char in the format string
2373 again, no matter what happened */
2374 inpos--;
2376 /* add the contents of buf to the output */
2377 buflen = strlen(buf);
2378 if (outpos + buflen < datelen) {
2379 date[outpos] = '\0'; /* for strcat to hook onto */
2380 strcat(date, buf);
2381 outpos += buflen;
2382 } else {
2383 date[outpos] = '\0';
2384 strncat(date, buf, datelen - outpos);
2385 date[datelen - 1] = '\0';
2386 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2387 WARN(ole, "insufficient buffer\n");
2388 return 0;
2391 /* reset the variables we used to keep track of this item */
2392 count = 0;
2393 type = '\0';
2394 } else if (format[inpos] == '\0') {
2395 /* we can't check for this at the loop-head, because
2396 that breaks the printing of the last format-item */
2397 date[outpos] = '\0';
2398 break;
2399 } else if (count) {
2400 /* continuing a code for an item */
2401 count +=1;
2402 continue;
2403 } else if (strchr("hHmstyMdg", format[inpos])) {
2404 type = format[inpos];
2405 count = 1;
2406 continue;
2407 } else if (format[inpos] == '\'') {
2408 inquote = 1;
2409 continue;
2410 } else {
2411 date[outpos++] = format[inpos];
2413 /* now deal with a possible buffer overflow */
2414 if (outpos >= datelen) {
2415 date[datelen - 1] = '\0';
2416 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2417 return 0;
2421 if (Overflow) {
2422 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2425 /* finish it off with a string terminator */
2426 outpos++;
2427 /* sanity check */
2428 if (outpos > datelen-1) outpos = datelen-1;
2429 date[outpos] = '\0';
2431 TRACE(ole, "OLE_GetFormatA returns string '%s', len %d\n",
2432 date, outpos);
2433 return outpos;
2436 /******************************************************************************
2437 * OLE_GetFormatW [INTERNAL]
2439 INT32 WINAPI OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
2440 LPSYSTEMTIME xtime,
2441 LPCWSTR format,
2442 LPWSTR output, INT32 outlen)
2444 INT32 inpos, outpos;
2445 int count, type=0, inquote;
2446 int Overflow; /* loop check */
2447 WCHAR buf[40];
2448 int buflen=0;
2449 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2450 WCHAR arg2[] = {'%','0','2','d',0};
2451 WCHAR *argarr[] = {arg0, arg1, arg2};
2452 int datevars=0, timevars=0;
2454 /* make a debug report */
2455 TRACE(ole, "args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p),
2456 %p with max len %d\n",
2457 locale, flags, tflags,
2458 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2459 debugstr_w(format), format, output, outlen);
2462 /* initialize state variables */
2463 inpos = outpos = 0;
2464 count = 0;
2465 inquote = Overflow = 0;
2466 /* this is really just a sanity check */
2467 output[0] = buf[0] = 0;
2469 /* this loop is the core of the function */
2470 for (inpos = 0; /* we have several break points */ ; inpos++) {
2471 if (inquote) {
2472 if (format[inpos] == (WCHAR) '\'') {
2473 if (format[inpos+1] == '\'') {
2474 inpos++;
2475 output[outpos++] = '\'';
2476 } else {
2477 inquote = 0;
2478 continue;
2480 } else if (format[inpos] == 0) {
2481 output[outpos++] = 0;
2482 if (outpos > outlen) Overflow = 1;
2483 break; /* normal exit (within a quote) */
2484 } else {
2485 output[outpos++] = format[inpos]; /* copy input */
2486 if (outpos > outlen) {
2487 Overflow = 1;
2488 output[outpos-1] = 0;
2489 break;
2492 } else if ( (count && (format[inpos] != type))
2493 || ( (count==4 && type =='y') ||
2494 (count==4 && type =='M') ||
2495 (count==4 && type =='d') ||
2496 (count==2 && type =='g') ||
2497 (count==2 && type =='h') ||
2498 (count==2 && type =='H') ||
2499 (count==2 && type =='m') ||
2500 (count==2 && type =='s') ||
2501 (count==2 && type =='t') ) ) {
2502 if (type == 'd') {
2503 if (count == 3) {
2504 GetLocaleInfo32W(locale,
2505 LOCALE_SDAYNAME1 + xtime->wDayOfWeek -1,
2506 buf, sizeof(buf)/sizeof(WCHAR) );
2507 } else if (count == 3) {
2508 GetLocaleInfo32W(locale,
2509 LOCALE_SABBREVDAYNAME1 +
2510 xtime->wDayOfWeek -1,
2511 buf, sizeof(buf)/sizeof(WCHAR) );
2512 } else {
2513 wsnprintf32W(buf, 5, argarr[count], xtime->wDay );
2515 } else if (type == 'M') {
2516 if (count == 4) {
2517 GetLocaleInfo32W(locale, LOCALE_SMONTHNAME1 +
2518 xtime->wMonth -1, buf,
2519 sizeof(buf)/sizeof(WCHAR) );
2520 } else if (count == 3) {
2521 GetLocaleInfo32W(locale, LOCALE_SABBREVMONTHNAME1 +
2522 xtime->wMonth -1, buf,
2523 sizeof(buf)/sizeof(WCHAR) );
2524 } else {
2525 wsnprintf32W(buf, 5, argarr[count], xtime->wMonth);
2527 } else if (type == 'y') {
2528 if (count == 4) {
2529 wsnprintf32W(buf, 6, argarr[1] /* "%d" */,
2530 xtime->wYear);
2531 } else if (count == 3) {
2532 lstrcpynAtoW(buf, "yyy", 5);
2533 } else {
2534 wsnprintf32W(buf, 6, argarr[count],
2535 xtime->wYear % 100);
2537 } else if (type == 'g') {
2538 if (count == 2) {
2539 FIXME(ole, "LOCALE_ICALENDARTYPE unimplemented\n");
2540 lstrcpynAtoW(buf, "AD", 5);
2541 } else {
2542 /* Win API sez we copy it verbatim */
2543 lstrcpynAtoW(buf, "g", 5);
2545 } else if (type == 'h') {
2546 /* hours 1:00-12:00 --- is this right? */
2547 wsnprintf32W(buf, 5, argarr[count],
2548 (xtime->wHour-1)%12 +1);
2549 } else if (type == 'H') {
2550 wsnprintf32W(buf, 5, argarr[count],
2551 xtime->wHour);
2552 } else if (type == 'm' ) {
2553 wsnprintf32W(buf, 5, argarr[count],
2554 xtime->wMinute);
2555 } else if (type == 's' ) {
2556 wsnprintf32W(buf, 5, argarr[count],
2557 xtime->wSecond);
2558 } else if (type == 't') {
2559 GetLocaleInfo32W(locale, (xtime->wHour < 12) ?
2560 LOCALE_S1159 : LOCALE_S2359,
2561 buf, sizeof(buf) );
2562 if (count == 1) {
2563 buf[1] = 0;
2567 /* no matter what happened, we need to check this next
2568 character the next time we loop through */
2569 inpos--;
2571 /* cat buf onto the output */
2572 outlen = lstrlen32W(buf);
2573 if (outpos + buflen < outlen) {
2574 output[outpos] = 0; /* a "hook" for strcat */
2575 lstrcat32W(output, buf);
2576 outpos += buflen;
2577 } else {
2578 output[outpos] = 0;
2579 lstrcatn32W(output, buf, outlen - outpos);
2580 output[outlen - 1] = 0;
2581 Overflow = 1;
2582 break; /* Abnormal exit */
2585 /* reset the variables we used this time */
2586 count = 0;
2587 type = '\0';
2588 } else if (format[inpos] == 0) {
2589 /* we can't check for this at the beginning, because that
2590 would keep us from printing a format spec that ended the
2591 string */
2592 output[outpos] = 0;
2593 break; /* NORMAL EXIT */
2594 } else if (count) {
2595 /* how we keep track of the middle of a format spec */
2596 count++;
2597 continue;
2598 } else if ( (datevars && (format[inpos]=='d' ||
2599 format[inpos]=='M' ||
2600 format[inpos]=='y' ||
2601 format[inpos]=='g') ) ||
2602 (timevars && (format[inpos]=='H' ||
2603 format[inpos]=='h' ||
2604 format[inpos]=='m' ||
2605 format[inpos]=='s' ||
2606 format[inpos]=='t') ) ) {
2607 type = format[inpos];
2608 count = 1;
2609 continue;
2610 } else if (format[inpos] == '\'') {
2611 inquote = 1;
2612 continue;
2613 } else {
2614 /* unquoted literals */
2615 output[outpos++] = format[inpos];
2619 if (Overflow) {
2620 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2621 WARN(ole, " buffer overflow\n");
2624 /* final string terminator and sanity check */
2625 outpos++;
2626 if (outpos > outlen-1) outpos = outlen-1;
2627 output[outpos] = '0';
2629 TRACE(ole, " returning %s\n", debugstr_w(output));
2631 return (!Overflow) ? outlen : 0;
2636 /******************************************************************************
2637 * GetDateFormat32A [KERNEL32.310]
2638 * Makes an ASCII string of the date
2640 * This function uses format to format the date, or, if format
2641 * is NULL, uses the default for the locale. format is a string
2642 * of literal fields and characters as follows:
2644 * - d single-digit (no leading zero) day (of month)
2645 * - dd two-digit day (of month)
2646 * - ddd short day-of-week name
2647 * - dddd long day-of-week name
2648 * - M single-digit month
2649 * - MM two-digit month
2650 * - MMM short month name
2651 * - MMMM full month name
2652 * - y two-digit year, no leading 0
2653 * - yy two-digit year
2654 * - yyyy four-digit year
2655 * - gg era string
2658 INT32 WINAPI GetDateFormat32A(LCID locale,DWORD flags,
2659 LPSYSTEMTIME xtime,
2660 LPCSTR format, LPSTR date,INT32 datelen)
2663 char format_buf[40];
2664 LPCSTR thisformat;
2665 SYSTEMTIME t;
2666 LPSYSTEMTIME thistime;
2667 LCID thislocale;
2668 INT32 ret;
2670 TRACE(ole,"(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2671 locale,flags,xtime,format,date,datelen);
2673 if (!locale) {
2674 locale = LOCALE_SYSTEM_DEFAULT;
2677 if (locale == LOCALE_SYSTEM_DEFAULT) {
2678 thislocale = GetSystemDefaultLCID();
2679 } else if (locale == LOCALE_USER_DEFAULT) {
2680 thislocale = GetUserDefaultLCID();
2681 } else {
2682 thislocale = locale;
2685 if (xtime == NULL) {
2686 GetSystemTime(&t);
2687 thistime = &t;
2688 } else {
2689 thistime = xtime;
2692 if (format == NULL) {
2693 GetLocaleInfo32A(thislocale, ((flags&DATE_LONGDATE)
2694 ? LOCALE_SLONGDATE
2695 : LOCALE_SSHORTDATE),
2696 format_buf, sizeof(format_buf));
2697 thisformat = format_buf;
2698 } else {
2699 thisformat = format;
2703 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
2704 date, datelen);
2707 TRACE(ole,
2708 "GetDateFormat32A() returning %d, with data=%s\n",
2709 ret, date);
2710 return ret;
2713 /******************************************************************************
2714 * GetDateFormat32W [KERNEL32.311]
2715 * Makes a Unicode string of the date
2717 * Acts the same as GetDateFormat32A(), except that it's Unicode.
2718 * Accepts & returns sizes as counts of Unicode characters.
2721 INT32 WINAPI GetDateFormat32W(LCID locale,DWORD flags,
2722 LPSYSTEMTIME xtime,
2723 LPCWSTR format,
2724 LPWSTR date, INT32 datelen)
2726 short datearr[] = {'1','9','9','4','-','1','-','1',0};
2728 FIXME(ole, "STUB (should call OLE_GetFormatW)\n");
2729 lstrcpyn32W(date, datearr, datelen);
2730 return ( datelen < 9) ? datelen : 9;
2735 /**************************************************************************
2736 * EnumDateFormats32A (KERNEL32.198)
2738 BOOL32 WINAPI EnumDateFormats32A(
2739 DATEFMT_ENUMPROC32A lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2741 FIXME(ole, "Only US English supported\n");
2743 if(!lpDateFmtEnumProc)
2745 SetLastError(ERROR_INVALID_PARAMETER);
2746 return FALSE;
2749 switch(dwFlags)
2751 case DATE_SHORTDATE:
2752 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
2753 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
2754 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
2755 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
2756 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
2757 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
2758 return TRUE;
2759 case DATE_LONGDATE:
2760 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
2761 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
2762 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
2763 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
2764 return TRUE;
2765 default:
2766 FIXME(ole, "Unknown date format (%ld)\n", dwFlags);
2767 SetLastError(ERROR_INVALID_PARAMETER);
2768 return FALSE;
2772 /**************************************************************************
2773 * EnumDateFormats32W (KERNEL32.199)
2775 BOOL32 WINAPI EnumDateFormats32W(
2776 DATEFMT_ENUMPROC32W lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2778 FIXME(ole, "(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
2779 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2780 return FALSE;
2783 /**************************************************************************
2784 * EnumTimeFormats32A (KERNEL32.210)
2786 BOOL32 WINAPI EnumTimeFormats32A(
2787 TIMEFMT_ENUMPROC32A lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
2789 FIXME(ole, "Only US English supported\n");
2791 if(!lpTimeFmtEnumProc)
2793 SetLastError(ERROR_INVALID_PARAMETER);
2794 return FALSE;
2797 if(dwFlags)
2799 FIXME(ole, "Unknown time format (%ld)\n", dwFlags);
2802 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
2803 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
2804 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
2805 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
2807 return TRUE;
2810 /**************************************************************************
2811 * EnumTimeFormats32W (KERNEL32.211)
2813 BOOL32 WINAPI EnumTimeFormats32W(
2814 TIMEFMT_ENUMPROC32W lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
2816 FIXME(ole, "(%p,%ld,%ld): stub", lpTimeFmtEnumProc, Locale, dwFlags);
2817 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2818 return FALSE;
2821 /**************************************************************************
2822 * GetNumberFormat32A (KERNEL32.355)
2823 * NOTE: type of lpFormat should be CONST NUMBERFORMAT
2825 INT32 WINAPI GetNumberFormat32A(LCID locale, DWORD dwflags,
2826 LPCSTR lpvalue, char *lpFormat,
2827 LPSTR lpNumberStr, int cchNumber)
2829 int n;
2831 FIXME(file,"%s: stub, no reformating done\n",lpvalue);
2833 n = strlen(lpvalue);
2834 if (cchNumber) {
2835 strncpy(lpNumberStr,lpvalue,cchNumber);
2836 if (cchNumber <= n) {
2837 lpNumberStr[cchNumber-1] = 0;
2838 n = cchNumber-1;
2841 return n;
2843 /******************************************************************************
2844 * OLE2NLS_CheckLocale [intern]
2846 static LCID OLE2NLS_CheckLocale (LCID locale)
2848 if (!locale)
2849 { locale = LOCALE_SYSTEM_DEFAULT;
2852 if (locale == LOCALE_SYSTEM_DEFAULT)
2853 { return GetSystemDefaultLCID();
2855 else if (locale == LOCALE_USER_DEFAULT)
2856 { return GetUserDefaultLCID();
2858 else
2859 { return locale;
2862 /******************************************************************************
2863 * GetTimeFormat32A [KERNEL32.422]
2864 * Makes an ASCII string of the time
2866 * Formats date according to format, or locale default if format is
2867 * NULL. The format consists of literal characters and fields as follows:
2869 * h hours with no leading zero (12-hour)
2870 * hh hours with full two digits
2871 * H hours with no leading zero (24-hour)
2872 * HH hours with full two digits
2873 * m minutes with no leading zero
2874 * mm minutes with full two digits
2875 * s seconds with no leading zero
2876 * ss seconds with full two digits
2877 * t time marker (A or P)
2878 * tt time marker (AM, PM)
2881 INT32 WINAPI
2882 GetTimeFormat32A(LCID locale, /* in */
2883 DWORD flags, /* in */
2884 LPSYSTEMTIME xtime, /* in */
2885 LPCSTR format, /* in */
2886 LPSTR timestr, /* out */
2887 INT32 timelen /* in */)
2888 { char format_buf[40];
2889 LPCSTR thisformat;
2890 SYSTEMTIME t;
2891 LPSYSTEMTIME thistime;
2892 LCID thislocale=0;
2893 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
2894 INT32 ret;
2896 TRACE(ole,"GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
2898 thislocale = OLE2NLS_CheckLocale ( locale );
2900 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
2901 { FIXME(ole,"TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
2904 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
2906 if (format == NULL)
2907 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
2908 { thislocale = GetSystemDefaultLCID();
2910 GetLocaleInfo32A(thislocale, thisflags, format_buf, sizeof(format_buf));
2911 thisformat = format_buf;
2913 else
2914 { thisformat = format;
2917 if (xtime == NULL) /* NULL means use the current local time*/
2918 { GetSystemTime(&t);
2919 thistime = &t;
2921 else
2922 { thistime = xtime;
2924 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
2925 timestr, timelen);
2926 SetLastError(ret);
2927 return ret;
2931 /******************************************************************************
2932 * GetTimeFormat32W [KERNEL32.423]
2933 * Makes a Unicode string of the time
2935 INT32 WINAPI
2936 GetTimeFormat32W(LCID locale, /* in */
2937 DWORD flags, /* in */
2938 LPSYSTEMTIME xtime, /* in */
2939 LPCWSTR format, /* in */
2940 LPWSTR timestr, /* out */
2941 INT32 timelen /* in */)
2942 { WCHAR format_buf[40];
2943 LPCWSTR thisformat;
2944 SYSTEMTIME t;
2945 LPSYSTEMTIME thistime;
2946 LCID thislocale=0;
2947 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
2948 INT32 ret;
2950 TRACE(ole,"GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
2951 xtime,debugstr_w(format),timestr,timelen);
2953 thislocale = OLE2NLS_CheckLocale ( locale );
2955 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
2956 { FIXME(ole,"TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
2959 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
2961 if (format == NULL)
2962 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
2963 { thislocale = GetSystemDefaultLCID();
2965 GetLocaleInfo32W(thislocale, thisflags, format_buf, 40);
2966 thisformat = format_buf;
2968 else
2969 { thisformat = format;
2972 if (xtime == NULL) /* NULL means use the current local time*/
2973 { GetSystemTime(&t);
2974 thistime = &t;
2976 else
2977 { thistime = xtime;
2980 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
2981 timestr, timelen);
2982 SetLastError(ret);
2983 return ret;