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