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