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