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