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