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