Abey George (of Macadamian/Corel)
[wine.git] / ole / ole2nls.c
blob2aef270786688375276a13302b883170a378843d
1 /*
2 * OLE2NLS library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
7 */
9 #include <string.h>
10 #include <stdio.h>
11 #include <ctype.h>
12 #include <stdlib.h>
13 #include <locale.h>
14 #include "windef.h"
15 #include "wingdi.h"
16 #include "winuser.h"
17 #include "heap.h"
18 #include "options.h"
19 #include "winver.h"
20 #include "winnls.h"
21 #include "winreg.h"
22 #include "winerror.h"
23 #include "debugtools.h"
24 #include "crtdll.h"
25 #include "main.h"
27 DEFAULT_DEBUG_CHANNEL(ole);
28 DECLARE_DEBUG_CHANNEL(string);
29 DECLARE_DEBUG_CHANNEL(win32);
31 struct NLS_langlocale {
32 const int lang;
33 struct NLS_localevar {
34 const int type;
35 const char *val;
36 } locvars[120];
39 #define LANG_BEGIN(l,s) { MAKELANGID(l,s), {
41 #define LOCVAL(type,value) {type,value},
43 #define LANG_END }},
45 static const struct NLS_langlocale langlocales[] = {
46 /* add languages in numerical order of main language (last two digits)
47 * it is much easier to find the missing holes that way */
49 LANG_BEGIN (LANG_CATALAN, SUBLANG_DEFAULT) /*0x0403*/
50 #include "nls/cat.nls"
51 LANG_END
53 LANG_BEGIN (LANG_CZECH, SUBLANG_DEFAULT) /*0x0405*/
54 #include "nls/cze.nls"
55 LANG_END
57 LANG_BEGIN (LANG_DANISH, SUBLANG_DEFAULT) /*0x0406*/
58 #include "nls/dan.nls"
59 LANG_END
61 LANG_BEGIN (LANG_GERMAN, SUBLANG_GERMAN) /*0x0407*/
62 #include "nls/deu.nls"
63 LANG_END
64 LANG_BEGIN (LANG_GERMAN, SUBLANG_GERMAN_SWISS) /*0x0807*/
65 #include "nls/des.nls"
66 LANG_END
67 LANG_BEGIN (LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN) /*0x0C07*/
68 #include "nls/dea.nls"
69 LANG_END
70 LANG_BEGIN (LANG_GERMAN, SUBLANG_GERMAN_LUXEMBOURG) /*0x1007*/
71 #include "nls/del.nls"
72 LANG_END
73 LANG_BEGIN (LANG_GERMAN, SUBLANG_GERMAN_LIECHTENSTEIN) /*0x1407*/
74 #include "nls/dec.nls"
75 LANG_END
77 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_US) /*0x0409*/
78 #include "nls/enu.nls"
79 LANG_END
80 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_UK) /*0x0809*/
81 #include "nls/eng.nls"
82 LANG_END
83 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_AUS) /*0x0C09*/
84 #include "nls/ena.nls"
85 LANG_END
86 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_CAN) /*0x1009*/
87 #include "nls/enc.nls"
88 LANG_END
89 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_NZ) /*0x1409*/
90 #include "nls/enz.nls"
91 LANG_END
92 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_EIRE) /*0x1809*/
93 #include "nls/eni.nls"
94 LANG_END
95 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_SAFRICA) /*0x1C09*/
96 #include "nls/ens.nls"
97 LANG_END
98 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_JAMAICA) /*0x2009*/
99 #include "nls/enj.nls"
100 LANG_END
101 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_CARRIBEAN) /*0x2409*/
102 #include "nls/enb.nls"
103 LANG_END
104 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_BELIZE) /*0x2809*/
105 #include "nls/enl.nls"
106 LANG_END
107 LANG_BEGIN (LANG_ENGLISH, SUBLANG_ENGLISH_TRINIDAD) /*0x2C09*/
108 #include "nls/ent.nls"
109 LANG_END
111 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH) /*0x040a*/
112 #include "nls/esp.nls"
113 LANG_END
114 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_MEXICAN) /*0x080a*/
115 #include "nls/esm.nls"
116 LANG_END
117 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_MODERN) /*0x0C0a*/
118 #include "nls/esn.nls"
119 LANG_END
120 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_GUATEMALA) /*0x100a*/
121 #include "nls/esg.nls"
122 LANG_END
123 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_COSTARICA) /*0x140a*/
124 #include "nls/esc.nls"
125 LANG_END
126 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_PANAMA) /*0x180a*/
127 #include "nls/esa.nls"
128 LANG_END
129 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_DOMINICAN) /*0x1C0A*/
130 #include "nls/esd.nls"
131 LANG_END
132 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_VENEZUELA) /*0x200a*/
133 #include "nls/esv.nls"
134 LANG_END
135 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_COLOMBIA) /*0x240a*/
136 #include "nls/eso.nls"
137 LANG_END
138 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_PERU) /*0x280a*/
139 #include "nls/esr.nls"
140 LANG_END
141 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_ARGENTINA) /*0x2c0a*/
142 #include "nls/ess.nls"
143 LANG_END
144 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_ECUADOR) /*0x300a*/
145 #include "nls/esf.nls"
146 LANG_END
147 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_CHILE) /*0x340a*/
148 #include "nls/esl.nls"
149 LANG_END
150 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_URUGUAY) /*0x380a*/
151 #include "nls/esy.nls"
152 LANG_END
153 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_PARAGUAY) /*0x3c0a*/
154 #include "nls/esz.nls"
155 LANG_END
156 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_BOLIVIA) /*0x400a*/
157 #include "nls/esb.nls"
158 LANG_END
159 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_EL_SALVADOR) /*0x440a*/
160 #include "nls/ese.nls"
161 LANG_END
162 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_HONDURAS) /*0x480a*/
163 #include "nls/esh.nls"
164 LANG_END
165 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_NICARAGUA) /*0x4c0a*/
166 #include "nls/esi.nls"
167 LANG_END
168 LANG_BEGIN (LANG_SPANISH, SUBLANG_SPANISH_PUERTO_RICO) /*0x500a*/
169 #include "nls/esu.nls"
170 LANG_END
172 LANG_BEGIN (LANG_FINNISH, SUBLANG_DEFAULT) /*0x040B*/
173 #include "nls/fin.nls"
174 LANG_END
176 LANG_BEGIN (LANG_FRENCH, SUBLANG_FRENCH) /*0x040C*/
177 #include "nls/fra.nls"
178 LANG_END
179 LANG_BEGIN (LANG_FRENCH, SUBLANG_FRENCH_BELGIAN) /*0x080C*/
180 #include "nls/frb.nls"
181 LANG_END
182 LANG_BEGIN (LANG_FRENCH, SUBLANG_FRENCH_CANADIAN) /*0x0C0C*/
183 #include "nls/frc.nls"
184 LANG_END
185 LANG_BEGIN (LANG_FRENCH, SUBLANG_FRENCH_SWISS) /*0x100C*/
186 #include "nls/frs.nls"
187 LANG_END
188 LANG_BEGIN (LANG_FRENCH, SUBLANG_FRENCH_LUXEMBOURG) /*0x140C*/
189 #include "nls/frl.nls"
190 LANG_END
192 LANG_BEGIN (LANG_HUNGARIAN, SUBLANG_DEFAULT) /*0x040e*/
193 #include "nls/hun.nls"
194 LANG_END
196 LANG_BEGIN (LANG_ITALIAN, SUBLANG_ITALIAN) /*0x0410*/
197 #include "nls/ita.nls"
198 LANG_END
199 LANG_BEGIN (LANG_ITALIAN, SUBLANG_ITALIAN_SWISS) /*0x0810*/
200 #include "nls/its.nls"
201 LANG_END
203 LANG_BEGIN (LANG_JAPANESE, SUBLANG_DEFAULT) /*0x0411*/
204 #include "nls/jpn.nls"
205 LANG_END
207 LANG_BEGIN (LANG_KOREAN, SUBLANG_KOREAN) /*0x0412*/
208 #include "nls/kor.nls"
209 LANG_END
211 LANG_BEGIN (LANG_DUTCH, SUBLANG_DUTCH) /*0x0413*/
212 #include "nls/nld.nls"
213 LANG_END
214 LANG_BEGIN (LANG_DUTCH, SUBLANG_DUTCH_BELGIAN) /*0x0813*/
215 #include "nls/nlb.nls"
216 LANG_END
217 LANG_BEGIN (LANG_DUTCH, SUBLANG_DUTCH_SURINAM) /*0x0C13*/
218 #include "nls/nls.nls"
219 LANG_END
221 LANG_BEGIN (LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL) /*0x0414*/
222 #include "nls/nor.nls"
223 LANG_END
224 LANG_BEGIN (LANG_NORWEGIAN, SUBLANG_NORWEGIAN_NYNORSK) /*0x0814*/
225 #include "nls/non.nls"
226 LANG_END
228 LANG_BEGIN (LANG_POLISH, SUBLANG_DEFAULT) /*0x0415*/
229 #include "nls/plk.nls"
230 LANG_END
232 LANG_BEGIN (LANG_PORTUGUESE ,SUBLANG_PORTUGUESE_BRAZILIAN) /*0x0416*/
233 #include "nls/ptb.nls"
234 LANG_END
235 LANG_BEGIN (LANG_PORTUGUESE ,SUBLANG_PORTUGUESE) /*0x0816*/
236 #include "nls/ptg.nls"
237 LANG_END
239 LANG_BEGIN (LANG_RUSSIAN, SUBLANG_DEFAULT) /*0x419*/
240 #include "nls/rus.nls"
241 LANG_END
243 LANG_BEGIN (LANG_SLOVAK, SUBLANG_DEFAULT) /*0x041b*/
244 #include "nls/sky.nls"
245 LANG_END
247 LANG_BEGIN (LANG_SWEDISH, SUBLANG_SWEDISH) /*0x041d*/
248 #include "nls/sve.nls"
249 LANG_END
250 LANG_BEGIN (LANG_SWEDISH, SUBLANG_SWEDISH_FINLAND) /*0x081d*/
251 #include "nls/svf.nls"
252 LANG_END
254 LANG_BEGIN (LANG_THAI, SUBLANG_DEFAULT) /*0x41e*/
255 #include "nls/tha.nls"
256 LANG_END
257 LANG_BEGIN (LANG_GAELIC, SUBLANG_DEFAULT) /* 0x043c */
258 #include "nls/gae.nls"
259 LANG_END
261 LANG_BEGIN (LANG_GAELIC, SUBLANG_GAELIC_SCOTTISH)
262 #include "nls/gdh.nls"
263 LANG_END
265 LANG_BEGIN (LANG_GAELIC, SUBLANG_GAELIC_MANX)
266 #include "nls/gdv.nls"
267 LANG_END
269 LANG_BEGIN (LANG_ESPERANTO, SUBLANG_DEFAULT) /*0x048f*/
270 #include "nls/esperanto.nls"
271 LANG_END
273 LANG_BEGIN (LANG_WALON, SUBLANG_DEFAULT) /*0x0490*/
274 #include "nls/wal.nls"
275 LANG_END
277 LANG_BEGIN (LANG_CORNISH, SUBLANG_DEFAULT) /* 0x0491 */
278 #include "nls/cor.nls"
279 LANG_END
281 LANG_BEGIN (LANG_WELSH, SUBLANG_DEFAULT) /* 0x0492 */
282 #include "nls/cym.nls"
283 LANG_END
285 LANG_BEGIN (LANG_BRETON, SUBLANG_DEFAULT) /* 0x0x93 */
286 #include "nls/brf.nls"
287 LANG_END
292 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
293 * MUST contain all #defines from winnls.h
294 * last entry has NULL name, 0 id.
296 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
297 static const struct tagLOCALE_NAME2ID {
298 const char *name;
299 DWORD id;
300 } locale_name2id[]= {
301 LOCALE_ENTRY(ILANGUAGE),
302 LOCALE_ENTRY(SLANGUAGE),
303 LOCALE_ENTRY(SENGLANGUAGE),
304 LOCALE_ENTRY(SABBREVLANGNAME),
305 LOCALE_ENTRY(SNATIVELANGNAME),
306 LOCALE_ENTRY(ICOUNTRY),
307 LOCALE_ENTRY(SCOUNTRY),
308 LOCALE_ENTRY(SENGCOUNTRY),
309 LOCALE_ENTRY(SABBREVCTRYNAME),
310 LOCALE_ENTRY(SNATIVECTRYNAME),
311 LOCALE_ENTRY(IDEFAULTLANGUAGE),
312 LOCALE_ENTRY(IDEFAULTCOUNTRY),
313 LOCALE_ENTRY(IDEFAULTCODEPAGE),
314 LOCALE_ENTRY(IDEFAULTANSICODEPAGE),
315 LOCALE_ENTRY(IDEFAULTMACCODEPAGE),
316 LOCALE_ENTRY(SLIST),
317 LOCALE_ENTRY(IMEASURE),
318 LOCALE_ENTRY(SDECIMAL),
319 LOCALE_ENTRY(STHOUSAND),
320 LOCALE_ENTRY(SGROUPING),
321 LOCALE_ENTRY(IDIGITS),
322 LOCALE_ENTRY(ILZERO),
323 LOCALE_ENTRY(INEGNUMBER),
324 LOCALE_ENTRY(SNATIVEDIGITS),
325 LOCALE_ENTRY(SCURRENCY),
326 LOCALE_ENTRY(SINTLSYMBOL),
327 LOCALE_ENTRY(SMONDECIMALSEP),
328 LOCALE_ENTRY(SMONTHOUSANDSEP),
329 LOCALE_ENTRY(SMONGROUPING),
330 LOCALE_ENTRY(ICURRDIGITS),
331 LOCALE_ENTRY(IINTLCURRDIGITS),
332 LOCALE_ENTRY(ICURRENCY),
333 LOCALE_ENTRY(INEGCURR),
334 LOCALE_ENTRY(SDATE),
335 LOCALE_ENTRY(STIME),
336 LOCALE_ENTRY(SSHORTDATE),
337 LOCALE_ENTRY(SLONGDATE),
338 LOCALE_ENTRY(STIMEFORMAT),
339 LOCALE_ENTRY(IDATE),
340 LOCALE_ENTRY(ILDATE),
341 LOCALE_ENTRY(ITIME),
342 LOCALE_ENTRY(ITIMEMARKPOSN),
343 LOCALE_ENTRY(ICENTURY),
344 LOCALE_ENTRY(ITLZERO),
345 LOCALE_ENTRY(IDAYLZERO),
346 LOCALE_ENTRY(IMONLZERO),
347 LOCALE_ENTRY(S1159),
348 LOCALE_ENTRY(S2359),
349 LOCALE_ENTRY(ICALENDARTYPE),
350 LOCALE_ENTRY(IOPTIONALCALENDAR),
351 LOCALE_ENTRY(IFIRSTDAYOFWEEK),
352 LOCALE_ENTRY(IFIRSTWEEKOFYEAR),
353 LOCALE_ENTRY(SDAYNAME1),
354 LOCALE_ENTRY(SDAYNAME2),
355 LOCALE_ENTRY(SDAYNAME3),
356 LOCALE_ENTRY(SDAYNAME4),
357 LOCALE_ENTRY(SDAYNAME5),
358 LOCALE_ENTRY(SDAYNAME6),
359 LOCALE_ENTRY(SDAYNAME7),
360 LOCALE_ENTRY(SABBREVDAYNAME1),
361 LOCALE_ENTRY(SABBREVDAYNAME2),
362 LOCALE_ENTRY(SABBREVDAYNAME3),
363 LOCALE_ENTRY(SABBREVDAYNAME4),
364 LOCALE_ENTRY(SABBREVDAYNAME5),
365 LOCALE_ENTRY(SABBREVDAYNAME6),
366 LOCALE_ENTRY(SABBREVDAYNAME7),
367 LOCALE_ENTRY(SMONTHNAME1),
368 LOCALE_ENTRY(SMONTHNAME2),
369 LOCALE_ENTRY(SMONTHNAME3),
370 LOCALE_ENTRY(SMONTHNAME4),
371 LOCALE_ENTRY(SMONTHNAME5),
372 LOCALE_ENTRY(SMONTHNAME6),
373 LOCALE_ENTRY(SMONTHNAME7),
374 LOCALE_ENTRY(SMONTHNAME8),
375 LOCALE_ENTRY(SMONTHNAME9),
376 LOCALE_ENTRY(SMONTHNAME10),
377 LOCALE_ENTRY(SMONTHNAME11),
378 LOCALE_ENTRY(SMONTHNAME12),
379 LOCALE_ENTRY(SMONTHNAME13),
380 LOCALE_ENTRY(SABBREVMONTHNAME1),
381 LOCALE_ENTRY(SABBREVMONTHNAME2),
382 LOCALE_ENTRY(SABBREVMONTHNAME3),
383 LOCALE_ENTRY(SABBREVMONTHNAME4),
384 LOCALE_ENTRY(SABBREVMONTHNAME5),
385 LOCALE_ENTRY(SABBREVMONTHNAME6),
386 LOCALE_ENTRY(SABBREVMONTHNAME7),
387 LOCALE_ENTRY(SABBREVMONTHNAME8),
388 LOCALE_ENTRY(SABBREVMONTHNAME9),
389 LOCALE_ENTRY(SABBREVMONTHNAME10),
390 LOCALE_ENTRY(SABBREVMONTHNAME11),
391 LOCALE_ENTRY(SABBREVMONTHNAME12),
392 LOCALE_ENTRY(SABBREVMONTHNAME13),
393 LOCALE_ENTRY(SPOSITIVESIGN),
394 LOCALE_ENTRY(SNEGATIVESIGN),
395 LOCALE_ENTRY(IPOSSIGNPOSN),
396 LOCALE_ENTRY(INEGSIGNPOSN),
397 LOCALE_ENTRY(IPOSSYMPRECEDES),
398 LOCALE_ENTRY(IPOSSEPBYSPACE),
399 LOCALE_ENTRY(INEGSYMPRECEDES),
400 LOCALE_ENTRY(INEGSEPBYSPACE),
401 LOCALE_ENTRY(FONTSIGNATURE),
402 LOCALE_ENTRY(SISO639LANGNAME),
403 LOCALE_ENTRY(SISO3166CTRYNAME),
404 {NULL,0},
407 const struct map_lcid2str {
408 LCID langid;
409 const char *langname;
410 } languages[]={
411 {0x0401,"Arabic (Saudi Arabia)"},
412 {0x0801,"Arabic (Iraq)"},
413 {0x0c01,"Arabic (Egypt)"},
414 {0x1001,"Arabic (Libya)"},
415 {0x1401,"Arabic (Algeria)"},
416 {0x1801,"Arabic (Morocco)"},
417 {0x1c01,"Arabic (Tunisia)"},
418 {0x2001,"Arabic (Oman)"},
419 {0x2401,"Arabic (Yemen)"},
420 {0x2801,"Arabic (Syria)"},
421 {0x2c01,"Arabic (Jordan)"},
422 {0x3001,"Arabic (Lebanon)"},
423 {0x3401,"Arabic (Kuwait)"},
424 {0x3801,"Arabic (United Arab Emirates)"},
425 {0x3c01,"Arabic (Bahrain)"},
426 {0x4001,"Arabic (Qatar)"},
427 {0x0402,"Bulgarian"},
428 {0x0403,"Catalan"},
429 {0x0404,"Chinese (Taiwan)"},
430 {0x0804,"Chinese (People's Republic of China)"},
431 {0x0c04,"Chinese (Hong Kong)"},
432 {0x1004,"Chinese (Singapore)"},
433 {0x1404,"Chinese (Macau)"},
434 {0x0405,"Czech"},
435 {0x0406,"Danish"},
436 {0x0407,"German (Germany)"},
437 {0x0807,"German (Switzerland)"},
438 {0x0c07,"German (Austria)"},
439 {0x1007,"German (Luxembourg)"},
440 {0x1407,"German (Liechtenstein)"},
441 {0x0408,"Greek"},
442 {0x0409,"English (United States)"},
443 {0x0809,"English (United Kingdom)"},
444 {0x0c09,"English (Australian)"},
445 {0x1009,"English (Canadian)"},
446 {0x1409,"English (New Zealand)"},
447 {0x1809,"English (Ireland)"},
448 {0x1c09,"English (South Africa)"},
449 {0x2009,"English (Jamaica)"},
450 {0x2409,"English (Caribbean)"},
451 {0x2809,"English (Belize)"},
452 {0x2c09,"English (Trinidad & Tobago)"},
453 {0x3009,"English (Zimbabwe)"},
454 {0x3409,"English (Philippines)"},
455 {0x040a,"Spanish (Spain, traditional sorting)"},
456 {0x080a,"Spanish (Mexico)"},
457 {0x0c0a,"Spanish (Spain, international sorting)"},
458 {0x100a,"Spanish (Guatemala)"},
459 {0x140a,"Spanish (Costa Rica)"},
460 {0x180a,"Spanish (Panama)"},
461 {0x1c0a,"Spanish (Dominican Republic)"},
462 {0x200a,"Spanish (Venezuela)"},
463 {0x240a,"Spanish (Colombia)"},
464 {0x280a,"Spanish (Peru)"},
465 {0x2c0a,"Spanish (Argentina)"},
466 {0x300a,"Spanish (Ecuador)"},
467 {0x340a,"Spanish (Chile)"},
468 {0x380a,"Spanish (Uruguay)"},
469 {0x3c0a,"Spanish (Paraguay)"},
470 {0x400a,"Spanish (Bolivia)"},
471 {0x440a,"Spanish (El Salvador)"},
472 {0x480a,"Spanish (Honduras)"},
473 {0x4c0a,"Spanish (Nicaragua)"},
474 {0x500a,"Spanish (Puerto Rico)"},
475 {0x040b,"Finnish"},
476 {0x040c,"French (France)"},
477 {0x080c,"French (Belgium)"},
478 {0x0c0c,"French (Canada)"},
479 {0x100c,"French (Switzerland)"},
480 {0x140c,"French (Luxembourg)"},
481 {0x180c,"French (Monaco)"},
482 {0x040d,"Hebrew"},
483 {0x040e,"Hungarian"},
484 {0x040f,"Icelandic"},
485 {0x0410,"Italian (Italy)"},
486 {0x0810,"Italian (Switzerland)"},
487 {0x0411,"Japanese"},
488 {0x0412,"Korean (Wansung)"},
489 {0x0812,"Korean (Johab)"},
490 {0x0413,"Dutch (Netherlands)"},
491 {0x0813,"Dutch (Belgium)"},
492 {0x0414,"Norwegian (Bokmal)"},
493 {0x0814,"Norwegian (Nynorsk)"},
494 {0x0415,"Polish"},
495 {0x0416,"Portuguese (Brazil)"},
496 {0x0816,"Portuguese (Portugal)"},
497 {0x0417,"Rhaeto Romanic"},
498 {0x0418,"Romanian"},
499 {0x0818,"Moldavian"},
500 {0x0419,"Russian (Russia)"},
501 {0x0819,"Russian (Moldavia)"},
502 {0x041a,"Croatian"},
503 {0x081a,"Serbian (latin)"},
504 {0x0c1a,"Serbian (cyrillic)"},
505 {0x041b,"Slovak"},
506 {0x041c,"Albanian"},
507 {0x041d,"Swedish (Sweden)"},
508 {0x081d,"Swedish (Finland)"},
509 {0x041e,"Thai"},
510 {0x041f,"Turkish"},
511 {0x0420,"Urdu"},
512 {0x0421,"Indonesian"},
513 {0x0422,"Ukrainian"},
514 {0x0423,"Belarusian"},
515 {0x0424,"Slovene"},
516 {0x0425,"Estonian"},
517 {0x0426,"Latvian"},
518 {0x0427,"Lithuanian (modern)"},
519 {0x0827,"Lithuanian (classic)"},
520 {0x0428,"Maori"},
521 {0x0429,"Farsi"},
522 {0x042a,"Vietnamese"},
523 {0x042b,"Armenian"},
524 {0x042c,"Azeri (latin)"},
525 {0x082c,"Azeri (cyrillic)"},
526 {0x042d,"Basque"},
527 {0x042e,"Sorbian"},
528 {0x042f,"Macedonian"},
529 {0x0430,"Sutu"},
530 {0x0431,"Tsonga"},
531 {0x0432,"Tswana"},
532 {0x0433,"Venda"},
533 {0x0434,"Xhosa"},
534 {0x0435,"Zulu"},
535 {0x0436,"Afrikaans"},
536 {0x0437,"Georgian"},
537 {0x0438,"Faeroese"},
538 {0x0439,"Hindi"},
539 {0x043a,"Maltese"},
540 {0x043b,"Saami"},
541 {0x043c,"Irish gaelic"},
542 {0x083c,"Scottish gaelic"},
543 {0x0c3c,"Manx Gaelic"},
544 {0x043e,"Malay (Malaysia)"},
545 {0x083e,"Malay (Brunei Darussalam)"},
546 {0x043f,"Kazak"},
547 {0x0441,"Swahili"},
548 {0x0443,"Uzbek (latin)"},
549 {0x0843,"Uzbek (cyrillic)"},
550 {0x0444,"Tatar"},
551 {0x0445,"Bengali"},
552 {0x0446,"Punjabi"},
553 {0x0447,"Gujarati"},
554 {0x0448,"Oriya"},
555 {0x0449,"Tamil"},
556 {0x044a,"Telugu"},
557 {0x044b,"Kannada"},
558 {0x044c,"Malayalam"},
559 {0x044d,"Assamese"},
560 {0x044e,"Marathi"},
561 {0x044f,"Sanskrit"},
562 {0x0457,"Konkani"},
563 {0x048f,"Esperanto"}, /* Non official */
564 {0x0490,"Walon"}, /* Non official */
565 {0x0491,"Cornish"}, /* Not official */
566 {0x0492,"Welsh"}, /* Not official */
567 {0x0493,"Breton"}, /* Not official */
568 {0x0000,"Unknown"}
569 }, languages_de[]={
570 {0x0401,"Arabic"},
571 {0x0402,"Bulgarisch"},
572 {0x0403,"Katalanisch"},
573 {0x0404,"Traditionales Chinesisch"},
574 {0x0405,"Tschecisch"},
575 {0x0406,"Dänisch"},
576 {0x0407,"Deutsch"},
577 {0x0408,"Griechisch"},
578 {0x0409,"Amerikanisches Englisch"},
579 {0x040A,"Kastilisches Spanisch"},
580 {0x040B,"Finnisch"},
581 {0x040C,"Franzvsisch"},
582 {0x040D,"Hebrdisch"},
583 {0x040E,"Ungarisch"},
584 {0x040F,"Isldndisch"},
585 {0x0410,"Italienisch"},
586 {0x0411,"Japanisch"},
587 {0x0412,"Koreanisch"},
588 {0x0413,"Niederldndisch"},
589 {0x0414,"Norwegisch-Bokmal"},
590 {0x0415,"Polnisch"},
591 {0x0416,"Brasilianisches Portugiesisch"},
592 {0x0417,"Rdtoromanisch"},
593 {0x0418,"Rumdnisch"},
594 {0x0419,"Russisch"},
595 {0x041A,"Kroatoserbisch (lateinisch)"},
596 {0x041B,"Slowenisch"},
597 {0x041C,"Albanisch"},
598 {0x041D,"Schwedisch"},
599 {0x041E,"Thai"},
600 {0x041F,"Türkisch"},
601 {0x0420,"Urdu"},
602 {0x0421,"Bahasa"},
603 {0x0804,"Vereinfachtes Chinesisch"},
604 {0x0807,"Schweizerdeutsch"},
605 {0x0809,"Britisches Englisch"},
606 {0x080A,"Mexikanisches Spanisch"},
607 {0x080C,"Belgisches Franzvsisch"},
608 {0x0810,"Schweizerisches Italienisch"},
609 {0x0813,"Belgisches Niederldndisch"},
610 {0x0814,"Norgwegisch-Nynorsk"},
611 {0x0816,"Portugiesisch"},
612 {0x081A,"Serbokratisch (kyrillisch)"},
613 {0x0C1C,"Kanadisches Franzvsisch"},
614 {0x100C,"Schweizerisches Franzvsisch"},
615 {0x0000,"Unbekannt"},
618 static char *GetLocaleSubkeyName( DWORD lctype );
620 /***********************************************************************
621 * GetUserDefaultLCID [KERNEL32.425] [OLE2NLS.1]
623 LCID WINAPI GetUserDefaultLCID()
625 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT );
628 /***********************************************************************
629 * GetSystemDefaultLCID [KERNEL32.400] [OLE2NLS.2]
631 LCID WINAPI GetSystemDefaultLCID()
633 return GetUserDefaultLCID();
636 /***********************************************************************
637 * GetUserDefaultLangID [KERNEL32.426] [OLE2NLS.3]
639 LANGID WINAPI GetUserDefaultLangID()
641 /* caching result, if defined from environment, which should (?) not change during a WINE session */
642 static LANGID userLCID = 0;
643 if (Options.language) {
644 return Languages[Options.language].langid;
647 if (userLCID == 0) {
648 char *buf=NULL;
649 char *lang,*country,*charset,*dialect,*next;
650 int ret=0;
652 buf=getenv("LANGUAGE");
653 if (!buf) buf=getenv("LANG");
654 if (!buf) buf=getenv("LC_ALL");
655 if (!buf) buf=getenv("LC_MESSAGES");
656 if (!buf) buf=getenv("LC_CTYPE");
657 if (!buf) return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
659 if (!strcmp(buf,"POSIX") || !strcmp(buf,"C")) {
660 return MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
663 lang=buf;
665 do {
666 next=strchr(lang,':'); if (next) *next++='\0';
667 dialect=strchr(lang,'@'); if (dialect) *dialect++='\0';
668 charset=strchr(lang,'.'); if (charset) *charset++='\0';
669 country=strchr(lang,'_'); if (country) *country++='\0';
671 ret=MAIN_GetLanguageID(lang, country, charset, dialect);
673 lang=next;
675 } while (lang && !ret);
677 /* FIXME : are strings returned by getenv() to be free()'ed ? */
678 userLCID = (LANGID)ret;
680 return userLCID;
683 /***********************************************************************
684 * GetSystemDefaultLangID [KERNEL32.401] [OLE2NLS.4]
686 LANGID WINAPI GetSystemDefaultLangID()
688 return GetUserDefaultLangID();
691 /******************************************************************************
692 * ConvertDefaultLocale32 [KERNEL32.147]
694 LCID WINAPI ConvertDefaultLocale32 (LCID lcid)
695 { switch (lcid)
696 { case LOCALE_SYSTEM_DEFAULT:
697 return GetSystemDefaultLCID();
698 case LOCALE_USER_DEFAULT:
699 return GetUserDefaultLCID();
700 case 0:
701 return MAKELCID (LANG_NEUTRAL, SUBLANG_NEUTRAL);
703 return MAKELANGID( PRIMARYLANGID(lcid), SUBLANG_NEUTRAL);
705 /******************************************************************************
706 * GetLocaleInfoA [KERNEL32.342]
708 * NOTES
709 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
711 * MS online documentation states that the string returned is NULL terminated
712 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
713 * terminated string".
715 INT WINAPI GetLocaleInfoA(LCID lcid,LCTYPE LCType,LPSTR buf,INT len)
717 LPCSTR retString;
718 int found,i;
719 int lang=0;
720 char *pacKey;
721 char acBuffer[128];
722 DWORD dwBufferSize=128;
724 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid,LCType,buf,len);
726 if (len && (! buf) ) {
727 SetLastError(ERROR_INSUFFICIENT_BUFFER);
728 return 0;
731 if (lcid ==0 || lcid == LANG_SYSTEM_DEFAULT || (LCType & LOCALE_NOUSEROVERRIDE) ) /* 0x00, 0x400 */
733 lcid = GetSystemDefaultLCID();
735 else if (lcid == LANG_USER_DEFAULT) /*0x800*/
737 lcid = GetUserDefaultLCID();
739 LCType &= ~(LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP);
741 /* As an option, we could obtain the value from win.ini.
742 This would not match the Wine compile-time option.
743 Also, not all identifiers are available from win.ini */
744 retString=0;
745 /* If we are through all of this, retLen should not be zero anymore.
746 If it is, the value is not supported */
747 i=0;
748 while (locale_name2id[i].name!=NULL) {
749 if (LCType == locale_name2id[i].id) {
750 retString = locale_name2id[i].name;
751 break;
753 i++;
755 if (!retString) {
756 FIXME("Unkown LC type %lX\n",LCType);
757 return 0;
760 found=0;
762 /* First, check if it's in the registry. */
764 if ( (pacKey = GetLocaleSubkeyName(LCType)) )
766 char acRealKey[128];
767 HKEY hKey;
769 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
771 if ( RegOpenKeyExA( HKEY_CURRENT_USER, acRealKey,
772 0, KEY_READ, &hKey) == ERROR_SUCCESS )
774 if ( RegQueryValueExA( hKey, NULL, NULL, NULL, (LPBYTE)acBuffer,
775 &dwBufferSize ) == ERROR_SUCCESS )
777 retString = acBuffer;
778 found = 1;
780 RegCloseKey(hKey);
784 /* If not in the registry, get it from the NLS entries. */
786 lang=lcid;
787 for (i=0;(i<3 && !found);i++) {
788 int j;
790 for (j=0;j<sizeof(langlocales)/sizeof(langlocales[0]);j++) {
791 if (langlocales[j].lang == lang) {
792 int k;
794 for (k=0;k<sizeof(langlocales[j].locvars)/sizeof(langlocales[j].locvars[0]) && (langlocales[j].locvars[k].type);k++) {
795 if (langlocales[j].locvars[k].type == LCType) {
796 found = 1;
797 retString = langlocales[j].locvars[k].val;
798 break;
801 if (found)
802 break;
805 /* language not found, try without a sublanguage*/
806 if (i==1) lang=MAKELANGID( PRIMARYLANGID(lang), SUBLANG_DEFAULT);
807 /* mask the LC Value */
808 if (i==2) LCType &= 0xfff;
811 if(!found) {
812 ERR("'%s' not supported for your language (%04X).\n",
813 retString,(WORD)lcid);
814 SetLastError(ERROR_INVALID_PARAMETER);
815 return 0;
817 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
818 if (LCType == LOCALE_FONTSIGNATURE) {
819 if (len)
820 memcpy(buf, retString, (len<=sizeof(FONTSIGNATURE))?len:sizeof(FONTSIGNATURE));
821 return sizeof(FONTSIGNATURE);
823 /* if len=0 return only the length, don't touch the buffer*/
824 if (len) lstrcpynA(buf,retString,len);
825 return strlen(retString)+1;
828 /******************************************************************************
829 * GetLocaleInfoW [KERNEL32.343]
831 * NOTES
832 * MS documentation states that len "specifies the size, in bytes (ANSI version)
833 * or characters (Unicode version), of" wbuf. Thus the number returned is
834 * the same between GetLocaleInfoW and GetLocaleInfoA.
836 INT WINAPI GetLocaleInfoW(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT len)
837 { WORD wlen;
838 LPSTR abuf;
840 if (len && (! wbuf) )
841 { SetLastError(ERROR_INSUFFICIENT_BUFFER);
842 return 0;
845 abuf = (LPSTR)HeapAlloc(GetProcessHeap(),0,len);
846 wlen = GetLocaleInfoA(lcid, LCType, abuf, len);
848 if (wlen && len) /* if len=0 return only the length*/
849 lstrcpynAtoW(wbuf,abuf,len);
851 HeapFree(GetProcessHeap(),0,abuf);
852 return wlen;
855 /******************************************************************************
857 * GetLocaleSubkeyName [helper function]
859 * - For use with the registry.
860 * - Gets the registry subkey name for a given lctype.
862 static char *GetLocaleSubkeyName( DWORD lctype )
864 char *pacKey=NULL;
866 switch ( lctype )
868 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
869 * the values are stored in the registry, confirmed under Windows,
870 * for the ones that actually assign pacKey. Cases that aren't finished
871 * have not been confirmed, so that must be done before they can be
872 * added.
874 case LOCALE_SDATE : /* The date separator. */
875 pacKey = "sDate";
876 break;
877 case LOCALE_ICURRDIGITS:
878 pacKey = "iCurrDigits";
879 break;
880 case LOCALE_SDECIMAL :
881 pacKey = "sDecimal";
882 break;
883 case LOCALE_ICURRENCY:
884 pacKey = "iCurrency";
885 break;
886 case LOCALE_SGROUPING :
887 pacKey = "sGrouping";
888 break;
889 case LOCALE_IDIGITS:
890 pacKey = "iDigits";
891 break;
892 case LOCALE_SLIST :
893 pacKey = "sList";
894 break;
895 /* case LOCALE_ICALENDARTYPE: */
896 /* case LOCALE_IFIRSTDAYOFWEEK: */
897 /* case LOCALE_IFIRSTWEEKOFYEAR: */
898 /* case LOCALE_SYEARMONTH : */
899 /* case LOCALE_SPOSITIVESIGN : */
900 /* case LOCALE_IPAPERSIZE: */
901 /* break; */
902 case LOCALE_SLONGDATE :
903 pacKey = "sLongDate";
904 break;
905 case LOCALE_SMONDECIMALSEP :
906 pacKey = "sMonDecimalSep";
907 break;
908 case LOCALE_SMONGROUPING:
909 pacKey = "sMonGrouping";
910 break;
911 case LOCALE_IMEASURE:
912 pacKey = "iMeasure";
913 break;
914 case LOCALE_SMONTHOUSANDSEP :
915 pacKey = "sMonThousandSep";
916 break;
917 case LOCALE_INEGCURR:
918 pacKey = "iNegCurr";
919 break;
920 case LOCALE_SNEGATIVESIGN :
921 pacKey = "sNegativeSign";
922 break;
923 case LOCALE_INEGNUMBER:
924 pacKey = "iNegNumber";
925 break;
926 case LOCALE_SSHORTDATE :
927 pacKey = "sShortDate";
928 break;
929 case LOCALE_ILDATE: /* Long Date format ordering specifier. */
930 pacKey = "iLDate";
931 break;
932 case LOCALE_ILZERO:
933 pacKey = "iLZero";
934 break;
935 case LOCALE_ITLZERO:
936 pacKey = "iTLZero";
937 break;
938 case LOCALE_ITIME: /* Time format specifier. */
939 pacKey = "iTime";
940 break;
941 case LOCALE_STHOUSAND :
942 pacKey = "sThousand";
943 break;
944 case LOCALE_S1159: /* AM */
945 pacKey = "s1159";
946 break;
947 case LOCALE_STIME:
948 pacKey = "sTime";
949 break;
950 case LOCALE_S2359: /* PM */
951 pacKey = "s2359";
952 break;
953 case LOCALE_STIMEFORMAT :
954 pacKey = "sTimeFormat";
955 break;
956 case LOCALE_SCURRENCY:
957 pacKey = "sCurrency";
958 break;
960 /* The following are not listed under MSDN as supported,
961 * but seem to be used and also stored in the registry.
964 case LOCALE_IDATE:
965 pacKey = "iDate";
966 break;
967 case LOCALE_SCOUNTRY:
968 pacKey = "sCountry";
969 break;
970 case LOCALE_ICOUNTRY:
971 pacKey = "iCountry";
972 break;
973 case LOCALE_SLANGUAGE:
974 pacKey = "sLanguage";
975 break;
977 default:
978 break;
981 return( pacKey );
984 /******************************************************************************
985 * SetLocaleInfoA [KERNEL32.656]
987 BOOL16 WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
989 HKEY hKey;
990 char *pacKey;
991 char acRealKey[128];
993 if ( (pacKey = GetLocaleSubkeyName(lctype)) )
995 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
996 if ( RegCreateKeyA( HKEY_CURRENT_USER, acRealKey,
997 &hKey ) == ERROR_SUCCESS )
999 if ( RegSetValueExA( hKey, NULL, 0, REG_SZ,
1000 data, strlen(data)+1 ) != ERROR_SUCCESS )
1002 ERR("SetLocaleInfoA: %s did not work\n", pacKey );
1004 RegCloseKey( hKey );
1007 else
1009 FIXME("(%ld,%ld,%s): stub\n",lcid,lctype,data);
1011 return TRUE;
1014 /******************************************************************************
1015 * IsValidLocale [KERNEL32.489]
1017 BOOL WINAPI IsValidLocale(LCID lcid,DWORD flags)
1019 /* we support ANY language. Well, at least say that...*/
1020 return TRUE;
1023 /******************************************************************************
1024 * EnumSystemLocalesW [KERNEL32.209]
1026 BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum,
1027 DWORD flags )
1029 int i;
1030 BOOL ret;
1031 WCHAR buffer[200];
1032 HKEY xhkey;
1034 TRACE_(win32)("(%p,%08lx)\n",lpfnLocaleEnum,flags );
1035 /* see if we can reuse the Win95 registry entries.... */
1036 if (ERROR_SUCCESS==RegOpenKeyA(HKEY_LOCAL_MACHINE,"System\\CurrentControlSet\\control\\Nls\\Locale\\",&xhkey)) {
1037 i=0;
1038 while (1) {
1039 if (ERROR_SUCCESS!=RegEnumKeyW(xhkey,i,buffer,sizeof(buffer)))
1040 break;
1041 if (!lpfnLocaleEnum(buffer))
1042 break;
1043 i++;
1045 RegCloseKey(xhkey);
1046 return TRUE;
1049 i=0;
1050 while (languages[i].langid!=0)
1052 LPWSTR cp;
1053 char xbuffer[10];
1055 sprintf(xbuffer,"%08lx",(DWORD)languages[i].langid);
1057 cp = HEAP_strdupAtoW( GetProcessHeap(), 0, xbuffer );
1058 ret = lpfnLocaleEnum(cp);
1059 HeapFree( GetProcessHeap(), 0, cp );
1060 if (!ret) break;
1061 i++;
1063 return TRUE;
1066 /******************************************************************************
1067 * EnumSystemLocalesA [KERNEL32.208]
1069 BOOL WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum,
1070 DWORD flags)
1072 int i;
1073 CHAR buffer[200];
1074 HKEY xhkey;
1076 TRACE_(win32)("(%p,%08lx)\n",
1077 lpfnLocaleEnum,flags
1080 if ( ERROR_SUCCESS==RegOpenKeyA(HKEY_LOCAL_MACHINE,
1081 "System\\CurrentControlSet\\Control\\Nls\\Locale\\",
1082 &xhkey)) {
1083 i=0;
1084 while (1) {
1085 DWORD size=sizeof(buffer);
1086 if (ERROR_SUCCESS!=RegEnumValueA(xhkey,i,buffer,&size,NULL,
1087 NULL, NULL,NULL))
1088 break;
1089 if (size && !lpfnLocaleEnum(buffer))
1090 break;
1091 i++;
1093 RegCloseKey(xhkey);
1094 return TRUE;
1096 i=0;
1097 while (languages[i].langid!=0) {
1098 sprintf(buffer,"%08lx",(DWORD)languages[i].langid);
1099 if (!lpfnLocaleEnum(buffer))
1100 break;
1101 i++;
1103 return TRUE;
1106 static const unsigned char CT_CType2_LUT[] = {
1107 C2_NOTAPPLICABLE, /* - 0 */
1108 C2_NOTAPPLICABLE, /* - 1 */
1109 C2_NOTAPPLICABLE, /* - 2 */
1110 C2_NOTAPPLICABLE, /* - 3 */
1111 C2_NOTAPPLICABLE, /* - 4 */
1112 C2_NOTAPPLICABLE, /* - 5 */
1113 C2_NOTAPPLICABLE, /* - 6 */
1114 C2_NOTAPPLICABLE, /* - 7 */
1115 C2_NOTAPPLICABLE, /* - 8 */
1116 C2_SEGMENTSEPARATOR, /* - 9 */
1117 C2_NOTAPPLICABLE, /* - 10 */
1118 C2_NOTAPPLICABLE, /* - 11 */
1119 C2_NOTAPPLICABLE, /* - 12 */
1120 C2_NOTAPPLICABLE, /* - 13 */
1121 C2_NOTAPPLICABLE, /* - 14 */
1122 C2_NOTAPPLICABLE, /* - 15 */
1123 C2_NOTAPPLICABLE, /* - 16 */
1124 C2_NOTAPPLICABLE, /* - 17 */
1125 C2_NOTAPPLICABLE, /* - 18 */
1126 C2_NOTAPPLICABLE, /* - 19 */
1127 C2_NOTAPPLICABLE, /* - 20 */
1128 C2_NOTAPPLICABLE, /* - 21 */
1129 C2_NOTAPPLICABLE, /* - 22 */
1130 C2_NOTAPPLICABLE, /* - 23 */
1131 C2_NOTAPPLICABLE, /* - 24 */
1132 C2_NOTAPPLICABLE, /* - 25 */
1133 C2_NOTAPPLICABLE, /* - 26 */
1134 C2_NOTAPPLICABLE, /* - 27 */
1135 C2_NOTAPPLICABLE, /* - 28 */
1136 C2_NOTAPPLICABLE, /* - 29 */
1137 C2_NOTAPPLICABLE, /* - 30 */
1138 C2_NOTAPPLICABLE, /* - 31 */
1139 C2_WHITESPACE, /* - 32 */
1140 C2_OTHERNEUTRAL, /* ! - 33 */
1141 C2_OTHERNEUTRAL, /* " - 34 */ /* " */
1142 C2_EUROPETERMINATOR, /* # - 35 */
1143 C2_EUROPETERMINATOR, /* $ - 36 */
1144 C2_EUROPETERMINATOR, /* % - 37 */
1145 C2_LEFTTORIGHT, /* & - 38 */
1146 C2_OTHERNEUTRAL, /* ' - 39 */
1147 C2_OTHERNEUTRAL, /* ( - 40 */
1148 C2_OTHERNEUTRAL, /* ) - 41 */
1149 C2_OTHERNEUTRAL, /* * - 42 */
1150 C2_EUROPETERMINATOR, /* + - 43 */
1151 C2_COMMONSEPARATOR, /* , - 44 */
1152 C2_EUROPETERMINATOR, /* - - 45 */
1153 C2_EUROPESEPARATOR, /* . - 46 */
1154 C2_EUROPESEPARATOR, /* / - 47 */
1155 C2_EUROPENUMBER, /* 0 - 48 */
1156 C2_EUROPENUMBER, /* 1 - 49 */
1157 C2_EUROPENUMBER, /* 2 - 50 */
1158 C2_EUROPENUMBER, /* 3 - 51 */
1159 C2_EUROPENUMBER, /* 4 - 52 */
1160 C2_EUROPENUMBER, /* 5 - 53 */
1161 C2_EUROPENUMBER, /* 6 - 54 */
1162 C2_EUROPENUMBER, /* 7 - 55 */
1163 C2_EUROPENUMBER, /* 8 - 56 */
1164 C2_EUROPENUMBER, /* 9 - 57 */
1165 C2_COMMONSEPARATOR, /* : - 58 */
1166 C2_OTHERNEUTRAL, /* ; - 59 */
1167 C2_OTHERNEUTRAL, /* < - 60 */
1168 C2_OTHERNEUTRAL, /* = - 61 */
1169 C2_OTHERNEUTRAL, /* > - 62 */
1170 C2_OTHERNEUTRAL, /* ? - 63 */
1171 C2_LEFTTORIGHT, /* @ - 64 */
1172 C2_LEFTTORIGHT, /* A - 65 */
1173 C2_LEFTTORIGHT, /* B - 66 */
1174 C2_LEFTTORIGHT, /* C - 67 */
1175 C2_LEFTTORIGHT, /* D - 68 */
1176 C2_LEFTTORIGHT, /* E - 69 */
1177 C2_LEFTTORIGHT, /* F - 70 */
1178 C2_LEFTTORIGHT, /* G - 71 */
1179 C2_LEFTTORIGHT, /* H - 72 */
1180 C2_LEFTTORIGHT, /* I - 73 */
1181 C2_LEFTTORIGHT, /* J - 74 */
1182 C2_LEFTTORIGHT, /* K - 75 */
1183 C2_LEFTTORIGHT, /* L - 76 */
1184 C2_LEFTTORIGHT, /* M - 77 */
1185 C2_LEFTTORIGHT, /* N - 78 */
1186 C2_LEFTTORIGHT, /* O - 79 */
1187 C2_LEFTTORIGHT, /* P - 80 */
1188 C2_LEFTTORIGHT, /* Q - 81 */
1189 C2_LEFTTORIGHT, /* R - 82 */
1190 C2_LEFTTORIGHT, /* S - 83 */
1191 C2_LEFTTORIGHT, /* T - 84 */
1192 C2_LEFTTORIGHT, /* U - 85 */
1193 C2_LEFTTORIGHT, /* V - 86 */
1194 C2_LEFTTORIGHT, /* W - 87 */
1195 C2_LEFTTORIGHT, /* X - 88 */
1196 C2_LEFTTORIGHT, /* Y - 89 */
1197 C2_LEFTTORIGHT, /* Z - 90 */
1198 C2_OTHERNEUTRAL, /* [ - 91 */
1199 C2_OTHERNEUTRAL, /* \ - 92 */
1200 C2_OTHERNEUTRAL, /* ] - 93 */
1201 C2_OTHERNEUTRAL, /* ^ - 94 */
1202 C2_OTHERNEUTRAL, /* _ - 95 */
1203 C2_OTHERNEUTRAL, /* ` - 96 */
1204 C2_LEFTTORIGHT, /* a - 97 */
1205 C2_LEFTTORIGHT, /* b - 98 */
1206 C2_LEFTTORIGHT, /* c - 99 */
1207 C2_LEFTTORIGHT, /* d - 100 */
1208 C2_LEFTTORIGHT, /* e - 101 */
1209 C2_LEFTTORIGHT, /* f - 102 */
1210 C2_LEFTTORIGHT, /* g - 103 */
1211 C2_LEFTTORIGHT, /* h - 104 */
1212 C2_LEFTTORIGHT, /* i - 105 */
1213 C2_LEFTTORIGHT, /* j - 106 */
1214 C2_LEFTTORIGHT, /* k - 107 */
1215 C2_LEFTTORIGHT, /* l - 108 */
1216 C2_LEFTTORIGHT, /* m - 109 */
1217 C2_LEFTTORIGHT, /* n - 110 */
1218 C2_LEFTTORIGHT, /* o - 111 */
1219 C2_LEFTTORIGHT, /* p - 112 */
1220 C2_LEFTTORIGHT, /* q - 113 */
1221 C2_LEFTTORIGHT, /* r - 114 */
1222 C2_LEFTTORIGHT, /* s - 115 */
1223 C2_LEFTTORIGHT, /* t - 116 */
1224 C2_LEFTTORIGHT, /* u - 117 */
1225 C2_LEFTTORIGHT, /* v - 118 */
1226 C2_LEFTTORIGHT, /* w - 119 */
1227 C2_LEFTTORIGHT, /* x - 120 */
1228 C2_LEFTTORIGHT, /* y - 121 */
1229 C2_LEFTTORIGHT, /* z - 122 */
1230 C2_OTHERNEUTRAL, /* { - 123 */
1231 C2_OTHERNEUTRAL, /* | - 124 */
1232 C2_OTHERNEUTRAL, /* } - 125 */
1233 C2_OTHERNEUTRAL, /* ~ - 126 */
1234 C2_NOTAPPLICABLE, /* \x7f - 127 */
1235 C2_NOTAPPLICABLE, /* € - 128 */
1236 C2_NOTAPPLICABLE, /* � - 129 */
1237 C2_OTHERNEUTRAL, /* ‚ - 130 */
1238 C2_LEFTTORIGHT, /* ƒ - 131 */
1239 C2_OTHERNEUTRAL, /* „ - 132 */
1240 C2_OTHERNEUTRAL, /* … - 133 */
1241 C2_OTHERNEUTRAL, /* † - 134 */
1242 C2_OTHERNEUTRAL, /* ‡ - 135 */
1243 C2_LEFTTORIGHT, /* ˆ - 136 */
1244 C2_EUROPETERMINATOR, /* ‰ - 137 */
1245 C2_LEFTTORIGHT, /* Š - 138 */
1246 C2_OTHERNEUTRAL, /* ‹ - 139 */
1247 C2_LEFTTORIGHT, /* Π- 140 */
1248 C2_NOTAPPLICABLE, /* � - 141 */
1249 C2_NOTAPPLICABLE, /* Ž - 142 */
1250 C2_NOTAPPLICABLE, /* � - 143 */
1251 C2_NOTAPPLICABLE, /* � - 144 */
1252 C2_OTHERNEUTRAL, /* ‘ - 145 */
1253 C2_OTHERNEUTRAL, /* ’ - 146 */
1254 C2_OTHERNEUTRAL, /* “ - 147 */
1255 C2_OTHERNEUTRAL, /* ” - 148 */
1256 C2_OTHERNEUTRAL, /* • - 149 */
1257 C2_OTHERNEUTRAL, /* – - 150 */
1258 C2_OTHERNEUTRAL, /* — - 151 */
1259 C2_LEFTTORIGHT, /* ˜ - 152 */
1260 C2_OTHERNEUTRAL, /* ™ - 153 */
1261 C2_LEFTTORIGHT, /* š - 154 */
1262 C2_OTHERNEUTRAL, /* › - 155 */
1263 C2_LEFTTORIGHT, /* œ - 156 */
1264 C2_NOTAPPLICABLE, /* � - 157 */
1265 C2_NOTAPPLICABLE, /* ž - 158 */
1266 C2_LEFTTORIGHT, /* Ÿ - 159 */
1267 C2_WHITESPACE, /*   - 160 */
1268 C2_OTHERNEUTRAL, /* ¡ - 161 */
1269 C2_EUROPETERMINATOR, /* ¢ - 162 */
1270 C2_EUROPETERMINATOR, /* £ - 163 */
1271 C2_EUROPETERMINATOR, /* ¤ - 164 */
1272 C2_EUROPETERMINATOR, /* ¥ - 165 */
1273 C2_OTHERNEUTRAL, /* ¦ - 166 */
1274 C2_OTHERNEUTRAL, /* § - 167 */
1275 C2_OTHERNEUTRAL, /* ¨ - 168 */
1276 C2_OTHERNEUTRAL, /* © - 169 */
1277 C2_OTHERNEUTRAL, /* ª - 170 */
1278 C2_OTHERNEUTRAL, /* « - 171 */
1279 C2_OTHERNEUTRAL, /* ¬ - 172 */
1280 C2_OTHERNEUTRAL, /* ­ - 173 */
1281 C2_OTHERNEUTRAL, /* ® - 174 */
1282 C2_OTHERNEUTRAL, /* ¯ - 175 */
1283 C2_EUROPETERMINATOR, /* ° - 176 */
1284 C2_EUROPETERMINATOR, /* ± - 177 */
1285 C2_EUROPENUMBER, /* ² - 178 */
1286 C2_EUROPENUMBER, /* ³ - 179 */
1287 C2_OTHERNEUTRAL, /* ´ - 180 */
1288 C2_OTHERNEUTRAL, /* µ - 181 */
1289 C2_OTHERNEUTRAL, /* ¶ - 182 */
1290 C2_OTHERNEUTRAL, /* · - 183 */
1291 C2_OTHERNEUTRAL, /* ¸ - 184 */
1292 C2_EUROPENUMBER, /* ¹ - 185 */
1293 C2_OTHERNEUTRAL, /* º - 186 */
1294 C2_OTHERNEUTRAL, /* » - 187 */
1295 C2_OTHERNEUTRAL, /* ¼ - 188 */
1296 C2_OTHERNEUTRAL, /* ½ - 189 */
1297 C2_OTHERNEUTRAL, /* ¾ - 190 */
1298 C2_OTHERNEUTRAL, /* ¿ - 191 */
1299 C2_LEFTTORIGHT, /* À - 192 */
1300 C2_LEFTTORIGHT, /* Á - 193 */
1301 C2_LEFTTORIGHT, /* Â - 194 */
1302 C2_LEFTTORIGHT, /* Ã - 195 */
1303 C2_LEFTTORIGHT, /* Ä - 196 */
1304 C2_LEFTTORIGHT, /* Å - 197 */
1305 C2_LEFTTORIGHT, /* Æ - 198 */
1306 C2_LEFTTORIGHT, /* Ç - 199 */
1307 C2_LEFTTORIGHT, /* È - 200 */
1308 C2_LEFTTORIGHT, /* É - 201 */
1309 C2_LEFTTORIGHT, /* Ê - 202 */
1310 C2_LEFTTORIGHT, /* Ë - 203 */
1311 C2_LEFTTORIGHT, /* Ì - 204 */
1312 C2_LEFTTORIGHT, /* Í - 205 */
1313 C2_LEFTTORIGHT, /* Î - 206 */
1314 C2_LEFTTORIGHT, /* Ï - 207 */
1315 C2_LEFTTORIGHT, /* Ð - 208 */
1316 C2_LEFTTORIGHT, /* Ñ - 209 */
1317 C2_LEFTTORIGHT, /* Ò - 210 */
1318 C2_LEFTTORIGHT, /* Ó - 211 */
1319 C2_LEFTTORIGHT, /* Ô - 212 */
1320 C2_LEFTTORIGHT, /* Õ - 213 */
1321 C2_LEFTTORIGHT, /* Ö - 214 */
1322 C2_OTHERNEUTRAL, /* × - 215 */
1323 C2_LEFTTORIGHT, /* Ø - 216 */
1324 C2_LEFTTORIGHT, /* Ù - 217 */
1325 C2_LEFTTORIGHT, /* Ú - 218 */
1326 C2_LEFTTORIGHT, /* Û - 219 */
1327 C2_LEFTTORIGHT, /* Ü - 220 */
1328 C2_LEFTTORIGHT, /* Ý - 221 */
1329 C2_LEFTTORIGHT, /* Þ - 222 */
1330 C2_LEFTTORIGHT, /* ß - 223 */
1331 C2_LEFTTORIGHT, /* à - 224 */
1332 C2_LEFTTORIGHT, /* á - 225 */
1333 C2_LEFTTORIGHT, /* â - 226 */
1334 C2_LEFTTORIGHT, /* ã - 227 */
1335 C2_LEFTTORIGHT, /* ä - 228 */
1336 C2_LEFTTORIGHT, /* å - 229 */
1337 C2_LEFTTORIGHT, /* æ - 230 */
1338 C2_LEFTTORIGHT, /* ç - 231 */
1339 C2_LEFTTORIGHT, /* è - 232 */
1340 C2_LEFTTORIGHT, /* é - 233 */
1341 C2_LEFTTORIGHT, /* ê - 234 */
1342 C2_LEFTTORIGHT, /* ë - 235 */
1343 C2_LEFTTORIGHT, /* ì - 236 */
1344 C2_LEFTTORIGHT, /* í - 237 */
1345 C2_LEFTTORIGHT, /* î - 238 */
1346 C2_LEFTTORIGHT, /* ï - 239 */
1347 C2_LEFTTORIGHT, /* ð - 240 */
1348 C2_LEFTTORIGHT, /* ñ - 241 */
1349 C2_LEFTTORIGHT, /* ò - 242 */
1350 C2_LEFTTORIGHT, /* ó - 243 */
1351 C2_LEFTTORIGHT, /* ô - 244 */
1352 C2_LEFTTORIGHT, /* õ - 245 */
1353 C2_LEFTTORIGHT, /* ö - 246 */
1354 C2_OTHERNEUTRAL, /* ÷ - 247 */
1355 C2_LEFTTORIGHT, /* ø - 248 */
1356 C2_LEFTTORIGHT, /* ù - 249 */
1357 C2_LEFTTORIGHT, /* ú - 250 */
1358 C2_LEFTTORIGHT, /* û - 251 */
1359 C2_LEFTTORIGHT, /* ü - 252 */
1360 C2_LEFTTORIGHT, /* ý - 253 */
1361 C2_LEFTTORIGHT, /* þ - 254 */
1362 C2_LEFTTORIGHT /* ÿ - 255 */
1365 const WORD OLE2NLS_CT_CType3_LUT[] = {
1366 0x0000, /* - 0 */
1367 0x0000, /* - 1 */
1368 0x0000, /* - 2 */
1369 0x0000, /* - 3 */
1370 0x0000, /* - 4 */
1371 0x0000, /* - 5 */
1372 0x0000, /* - 6 */
1373 0x0000, /* - 7 */
1374 0x0000, /* - 8 */
1375 0x0008, /* - 9 */
1376 0x0008, /* - 10 */
1377 0x0008, /* - 11 */
1378 0x0008, /* - 12 */
1379 0x0008, /* - 13 */
1380 0x0000, /* - 14 */
1381 0x0000, /* - 15 */
1382 0x0000, /* - 16 */
1383 0x0000, /* - 17 */
1384 0x0000, /* - 18 */
1385 0x0000, /* - 19 */
1386 0x0000, /* - 20 */
1387 0x0000, /* - 21 */
1388 0x0000, /* - 22 */
1389 0x0000, /* - 23 */
1390 0x0000, /* - 24 */
1391 0x0000, /* - 25 */
1392 0x0000, /* - 26 */
1393 0x0000, /* - 27 */
1394 0x0000, /* - 28 */
1395 0x0000, /* - 29 */
1396 0x0000, /* - 30 */
1397 0x0000, /* - 31 */
1398 0x0048, /* - 32 */
1399 0x0048, /* ! - 33 */
1400 0x0448, /* " - 34 */ /* " */
1401 0x0048, /* # - 35 */
1402 0x0448, /* $ - 36 */
1403 0x0048, /* % - 37 */
1404 0x0048, /* & - 38 */
1405 0x0440, /* ' - 39 */
1406 0x0048, /* ( - 40 */
1407 0x0048, /* ) - 41 */
1408 0x0048, /* * - 42 */
1409 0x0048, /* + - 43 */
1410 0x0048, /* , - 44 */
1411 0x0440, /* - - 45 */
1412 0x0048, /* . - 46 */
1413 0x0448, /* / - 47 */
1414 0x0040, /* 0 - 48 */
1415 0x0040, /* 1 - 49 */
1416 0x0040, /* 2 - 50 */
1417 0x0040, /* 3 - 51 */
1418 0x0040, /* 4 - 52 */
1419 0x0040, /* 5 - 53 */
1420 0x0040, /* 6 - 54 */
1421 0x0040, /* 7 - 55 */
1422 0x0040, /* 8 - 56 */
1423 0x0040, /* 9 - 57 */
1424 0x0048, /* : - 58 */
1425 0x0048, /* ; - 59 */
1426 0x0048, /* < - 60 */
1427 0x0448, /* = - 61 */
1428 0x0048, /* > - 62 */
1429 0x0048, /* ? - 63 */
1430 0x0448, /* @ - 64 */
1431 0x8040, /* A - 65 */
1432 0x8040, /* B - 66 */
1433 0x8040, /* C - 67 */
1434 0x8040, /* D - 68 */
1435 0x8040, /* E - 69 */
1436 0x8040, /* F - 70 */
1437 0x8040, /* G - 71 */
1438 0x8040, /* H - 72 */
1439 0x8040, /* I - 73 */
1440 0x8040, /* J - 74 */
1441 0x8040, /* K - 75 */
1442 0x8040, /* L - 76 */
1443 0x8040, /* M - 77 */
1444 0x8040, /* N - 78 */
1445 0x8040, /* O - 79 */
1446 0x8040, /* P - 80 */
1447 0x8040, /* Q - 81 */
1448 0x8040, /* R - 82 */
1449 0x8040, /* S - 83 */
1450 0x8040, /* T - 84 */
1451 0x8040, /* U - 85 */
1452 0x8040, /* V - 86 */
1453 0x8040, /* W - 87 */
1454 0x8040, /* X - 88 */
1455 0x8040, /* Y - 89 */
1456 0x8040, /* Z - 90 */
1457 0x0048, /* [ - 91 */
1458 0x0448, /* \ - 92 */
1459 0x0048, /* ] - 93 */
1460 0x0448, /* ^ - 94 */
1461 0x0448, /* _ - 95 */
1462 0x0448, /* ` - 96 */
1463 0x8040, /* a - 97 */
1464 0x8040, /* b - 98 */
1465 0x8040, /* c - 99 */
1466 0x8040, /* d - 100 */
1467 0x8040, /* e - 101 */
1468 0x8040, /* f - 102 */
1469 0x8040, /* g - 103 */
1470 0x8040, /* h - 104 */
1471 0x8040, /* i - 105 */
1472 0x8040, /* j - 106 */
1473 0x8040, /* k - 107 */
1474 0x8040, /* l - 108 */
1475 0x8040, /* m - 109 */
1476 0x8040, /* n - 110 */
1477 0x8040, /* o - 111 */
1478 0x8040, /* p - 112 */
1479 0x8040, /* q - 113 */
1480 0x8040, /* r - 114 */
1481 0x8040, /* s - 115 */
1482 0x8040, /* t - 116 */
1483 0x8040, /* u - 117 */
1484 0x8040, /* v - 118 */
1485 0x8040, /* w - 119 */
1486 0x8040, /* x - 120 */
1487 0x8040, /* y - 121 */
1488 0x8040, /* z - 122 */
1489 0x0048, /* { - 123 */
1490 0x0048, /* | - 124 */
1491 0x0048, /* } - 125 */
1492 0x0448, /* ~ - 126 */
1493 0x0000, /* \x7f - 127 */
1494 0x0000, /* € - 128 */
1495 0x0000, /* � - 129 */
1496 0x0008, /* ‚ - 130 */
1497 0x8000, /* ƒ - 131 */
1498 0x0008, /* „ - 132 */
1499 0x0008, /* … - 133 */
1500 0x0008, /* † - 134 */
1501 0x0008, /* ‡ - 135 */
1502 0x0001, /* ˆ - 136 */
1503 0x0008, /* ‰ - 137 */
1504 0x8003, /* Š - 138 */
1505 0x0008, /* ‹ - 139 */
1506 0x8000, /* Π- 140 */
1507 0x0000, /* � - 141 */
1508 0x0000, /* Ž - 142 */
1509 0x0000, /* � - 143 */
1510 0x0000, /* � - 144 */
1511 0x0088, /* ‘ - 145 */
1512 0x0088, /* ’ - 146 */
1513 0x0088, /* “ - 147 */
1514 0x0088, /* ” - 148 */
1515 0x0008, /* • - 149 */
1516 0x0400, /* – - 150 */
1517 0x0400, /* — - 151 */
1518 0x0408, /* ˜ - 152 */
1519 0x0000, /* ™ - 153 */
1520 0x8003, /* š - 154 */
1521 0x0008, /* › - 155 */
1522 0x8000, /* œ - 156 */
1523 0x0000, /* � - 157 */
1524 0x0000, /* ž - 158 */
1525 0x8003, /* Ÿ - 159 */
1526 0x0008, /*   - 160 */
1527 0x0008, /* ¡ - 161 */
1528 0x0048, /* ¢ - 162 */
1529 0x0048, /* £ - 163 */
1530 0x0008, /* ¤ - 164 */
1531 0x0048, /* ¥ - 165 */
1532 0x0048, /* ¦ - 166 */
1533 0x0008, /* § - 167 */
1534 0x0408, /* ¨ - 168 */
1535 0x0008, /* © - 169 */
1536 0x0400, /* ª - 170 */
1537 0x0008, /* « - 171 */
1538 0x0048, /* ¬ - 172 */
1539 0x0408, /* ­ - 173 */
1540 0x0008, /* ® - 174 */
1541 0x0448, /* ¯ - 175 */
1542 0x0008, /* ° - 176 */
1543 0x0008, /* ± - 177 */
1544 0x0000, /* ² - 178 */
1545 0x0000, /* ³ - 179 */
1546 0x0408, /* ´ - 180 */
1547 0x0008, /* µ - 181 */
1548 0x0008, /* ¶ - 182 */
1549 0x0008, /* · - 183 */
1550 0x0408, /* ¸ - 184 */
1551 0x0000, /* ¹ - 185 */
1552 0x0400, /* º - 186 */
1553 0x0008, /* » - 187 */
1554 0x0000, /* ¼ - 188 */
1555 0x0000, /* ½ - 189 */
1556 0x0000, /* ¾ - 190 */
1557 0x0008, /* ¿ - 191 */
1558 0x8003, /* À - 192 */
1559 0x8003, /* Á - 193 */
1560 0x8003, /* Â - 194 */
1561 0x8003, /* Ã - 195 */
1562 0x8003, /* Ä - 196 */
1563 0x8003, /* Å - 197 */
1564 0x8000, /* Æ - 198 */
1565 0x8003, /* Ç - 199 */
1566 0x8003, /* È - 200 */
1567 0x8003, /* É - 201 */
1568 0x8003, /* Ê - 202 */
1569 0x8003, /* Ë - 203 */
1570 0x8003, /* Ì - 204 */
1571 0x8003, /* Í - 205 */
1572 0x8003, /* Î - 206 */
1573 0x8003, /* Ï - 207 */
1574 0x8000, /* Ð - 208 */
1575 0x8003, /* Ñ - 209 */
1576 0x8003, /* Ò - 210 */
1577 0x8003, /* Ó - 211 */
1578 0x8003, /* Ô - 212 */
1579 0x8003, /* Õ - 213 */
1580 0x8003, /* Ö - 214 */
1581 0x0008, /* × - 215 */
1582 0x8003, /* Ø - 216 */
1583 0x8003, /* Ù - 217 */
1584 0x8003, /* Ú - 218 */
1585 0x8003, /* Û - 219 */
1586 0x8003, /* Ü - 220 */
1587 0x8003, /* Ý - 221 */
1588 0x8000, /* Þ - 222 */
1589 0x8000, /* ß - 223 */
1590 0x8003, /* à - 224 */
1591 0x8003, /* á - 225 */
1592 0x8003, /* â - 226 */
1593 0x8003, /* ã - 227 */
1594 0x8003, /* ä - 228 */
1595 0x8003, /* å - 229 */
1596 0x8000, /* æ - 230 */
1597 0x8003, /* ç - 231 */
1598 0x8003, /* è - 232 */
1599 0x8003, /* é - 233 */
1600 0x8003, /* ê - 234 */
1601 0x8003, /* ë - 235 */
1602 0x8003, /* ì - 236 */
1603 0x8003, /* í - 237 */
1604 0x8003, /* î - 238 */
1605 0x8003, /* ï - 239 */
1606 0x8000, /* ð - 240 */
1607 0x8003, /* ñ - 241 */
1608 0x8003, /* ò - 242 */
1609 0x8003, /* ó - 243 */
1610 0x8003, /* ô - 244 */
1611 0x8003, /* õ - 245 */
1612 0x8003, /* ö - 246 */
1613 0x0008, /* ÷ - 247 */
1614 0x8003, /* ø - 248 */
1615 0x8003, /* ù - 249 */
1616 0x8003, /* ú - 250 */
1617 0x8003, /* û - 251 */
1618 0x8003, /* ü - 252 */
1619 0x8003, /* ý - 253 */
1620 0x8000, /* þ - 254 */
1621 0x8003 /* ÿ - 255 */
1624 /******************************************************************************
1625 * GetStringTypeA [KERNEL32.396]
1627 BOOL WINAPI GetStringTypeA(LCID locale,DWORD dwInfoType,LPCSTR src,
1628 INT cchSrc,LPWORD chartype)
1630 return GetStringTypeExA(locale,dwInfoType,src,cchSrc,chartype);
1633 /******************************************************************************
1634 * GetStringTypeExA [KERNEL32.397]
1636 * FIXME: Ignores the locale.
1638 BOOL WINAPI GetStringTypeExA(LCID locale,DWORD dwInfoType,LPCSTR src,
1639 INT cchSrc,LPWORD chartype)
1641 int i;
1643 if ((src==NULL) || (chartype==NULL) || (src==(LPSTR)chartype))
1645 SetLastError(ERROR_INVALID_PARAMETER);
1646 return FALSE;
1649 if (cchSrc==-1)
1650 cchSrc=lstrlenA(src)+1;
1652 switch (dwInfoType) {
1653 case CT_CTYPE1:
1654 for (i=0;i<cchSrc;i++)
1656 chartype[i] = 0;
1657 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1658 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1659 if (islower(src[i])) chartype[i]|=C1_LOWER;
1660 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1661 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1662 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1663 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1664 /* FIXME: isblank() is a GNU extension */
1665 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1666 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1667 /* C1_XDIGIT */
1669 return TRUE;
1671 case CT_CTYPE2:
1672 for (i=0;i<cchSrc;i++)
1674 chartype[i]=(WORD)CT_CType2_LUT[i];
1676 return TRUE;
1678 case CT_CTYPE3:
1679 for (i=0;i<cchSrc;i++)
1681 chartype[i]=OLE2NLS_CT_CType3_LUT[i];
1683 return TRUE;
1685 default:
1686 ERR("Unknown dwInfoType:%ld\n",dwInfoType);
1687 return FALSE;
1691 /******************************************************************************
1692 * GetStringTypeW [KERNEL32.399]
1694 * NOTES
1695 * Yes, this is missing LCID locale. MS fault.
1697 BOOL WINAPI GetStringTypeW(DWORD dwInfoType,LPCWSTR src,INT cchSrc,
1698 LPWORD chartype)
1700 return GetStringTypeExW(0/*defaultlocale*/,dwInfoType,src,cchSrc,chartype);
1703 /******************************************************************************
1704 * GetStringTypeExW [KERNEL32.398]
1706 * FIXME: unicode chars are assumed chars
1708 BOOL WINAPI GetStringTypeExW(LCID locale,DWORD dwInfoType,LPCWSTR src,
1709 INT cchSrc,LPWORD chartype)
1711 int i;
1714 if (cchSrc==-1)
1715 cchSrc=lstrlenW(src)+1;
1717 switch (dwInfoType) {
1718 case CT_CTYPE2:
1719 FIXME("CT_CTYPE2 not supported.\n");
1720 return FALSE;
1721 case CT_CTYPE3:
1722 FIXME("CT_CTYPE3 not supported.\n");
1723 return FALSE;
1724 default:break;
1726 for (i=0;i<cchSrc;i++) {
1727 chartype[i] = 0;
1728 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1729 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1730 if (islower(src[i])) chartype[i]|=C1_LOWER;
1731 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1732 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1733 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1734 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1735 /* FIXME: isblank() is a GNU extension */
1736 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1737 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1738 /* C1_XDIGIT */
1740 return TRUE;
1743 /*****************************************************************
1744 * WINE_GetLanguageName [internal]
1746 static LPCSTR WINE_GetLanguageName( UINT langid )
1748 int i;
1749 for ( i = 0; languages[i].langid != 0; i++ )
1750 if ( langid == languages[i].langid )
1751 break;
1753 return languages[i].langname;
1756 /***********************************************************************
1757 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1759 DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
1761 char buffer[80];
1762 LPCSTR name;
1763 DWORD result;
1766 * First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
1767 * from the registry.
1770 sprintf( buffer,
1771 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
1772 wLang );
1774 result = RegQueryValueA( HKEY_LOCAL_MACHINE, buffer, szLang, (LPDWORD)&nSize );
1775 if ( result == ERROR_SUCCESS || result == ERROR_MORE_DATA )
1776 return nSize;
1779 * If that fails, use the internal table
1782 name = WINE_GetLanguageName( wLang );
1783 lstrcpynA( szLang, name, nSize );
1784 return lstrlenA( name );
1787 /***********************************************************************
1788 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1790 DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
1792 char buffer[80];
1793 LPWSTR keyname;
1794 LPCSTR name;
1795 DWORD result;
1798 * First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
1799 * from the registry.
1802 sprintf( buffer,
1803 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
1804 wLang );
1806 keyname = HEAP_strdupAtoW( GetProcessHeap(), 0, buffer );
1807 result = RegQueryValueW( HKEY_LOCAL_MACHINE, keyname, szLang, (LPDWORD)&nSize );
1808 HeapFree( GetProcessHeap(), 0, keyname );
1810 if ( result == ERROR_SUCCESS || result == ERROR_MORE_DATA )
1811 return nSize;
1814 * If that fails, use the internal table
1817 name = WINE_GetLanguageName( wLang );
1818 lstrcpynAtoW( szLang, name, nSize );
1819 return lstrlenA( name );
1823 static const unsigned char LCM_Unicode_LUT[] = {
1824 6 , 3, /* - 1 */
1825 6 , 4, /* - 2 */
1826 6 , 5, /* - 3 */
1827 6 , 6, /* - 4 */
1828 6 , 7, /* - 5 */
1829 6 , 8, /* - 6 */
1830 6 , 9, /* - 7 */
1831 6 , 10, /* - 8 */
1832 7 , 5, /* - 9 */
1833 7 , 6, /* - 10 */
1834 7 , 7, /* - 11 */
1835 7 , 8, /* - 12 */
1836 7 , 9, /* - 13 */
1837 6 , 11, /* - 14 */
1838 6 , 12, /* - 15 */
1839 6 , 13, /* - 16 */
1840 6 , 14, /* - 17 */
1841 6 , 15, /* - 18 */
1842 6 , 16, /* - 19 */
1843 6 , 17, /* - 20 */
1844 6 , 18, /* - 21 */
1845 6 , 19, /* - 22 */
1846 6 , 20, /* - 23 */
1847 6 , 21, /* - 24 */
1848 6 , 22, /* - 25 */
1849 6 , 23, /* - 26 */
1850 6 , 24, /* - 27 */
1851 6 , 25, /* - 28 */
1852 6 , 26, /* - 29 */
1853 6 , 27, /* - 30 */
1854 6 , 28, /* - 31 */
1855 7 , 2, /* - 32 */
1856 7 , 28, /* ! - 33 */
1857 7 , 29, /* " - 34 */ /* " */
1858 7 , 31, /* # - 35 */
1859 7 , 33, /* $ - 36 */
1860 7 , 35, /* % - 37 */
1861 7 , 37, /* & - 38 */
1862 6 , 128, /* ' - 39 */
1863 7 , 39, /* ( - 40 */
1864 7 , 42, /* ) - 41 */
1865 7 , 45, /* * - 42 */
1866 8 , 3, /* + - 43 */
1867 7 , 47, /* , - 44 */
1868 6 , 130, /* - - 45 */
1869 7 , 51, /* . - 46 */
1870 7 , 53, /* / - 47 */
1871 12 , 3, /* 0 - 48 */
1872 12 , 33, /* 1 - 49 */
1873 12 , 51, /* 2 - 50 */
1874 12 , 70, /* 3 - 51 */
1875 12 , 88, /* 4 - 52 */
1876 12 , 106, /* 5 - 53 */
1877 12 , 125, /* 6 - 54 */
1878 12 , 144, /* 7 - 55 */
1879 12 , 162, /* 8 - 56 */
1880 12 , 180, /* 9 - 57 */
1881 7 , 55, /* : - 58 */
1882 7 , 58, /* ; - 59 */
1883 8 , 14, /* < - 60 */
1884 8 , 18, /* = - 61 */
1885 8 , 20, /* > - 62 */
1886 7 , 60, /* ? - 63 */
1887 7 , 62, /* @ - 64 */
1888 14 , 2, /* A - 65 */
1889 14 , 9, /* B - 66 */
1890 14 , 10, /* C - 67 */
1891 14 , 26, /* D - 68 */
1892 14 , 33, /* E - 69 */
1893 14 , 35, /* F - 70 */
1894 14 , 37, /* G - 71 */
1895 14 , 44, /* H - 72 */
1896 14 , 50, /* I - 73 */
1897 14 , 53, /* J - 74 */
1898 14 , 54, /* K - 75 */
1899 14 , 72, /* L - 76 */
1900 14 , 81, /* M - 77 */
1901 14 , 112, /* N - 78 */
1902 14 , 124, /* O - 79 */
1903 14 , 126, /* P - 80 */
1904 14 , 137, /* Q - 81 */
1905 14 , 138, /* R - 82 */
1906 14 , 145, /* S - 83 */
1907 14 , 153, /* T - 84 */
1908 14 , 159, /* U - 85 */
1909 14 , 162, /* V - 86 */
1910 14 , 164, /* W - 87 */
1911 14 , 166, /* X - 88 */
1912 14 , 167, /* Y - 89 */
1913 14 , 169, /* Z - 90 */
1914 7 , 63, /* [ - 91 */
1915 7 , 65, /* \ - 92 */
1916 7 , 66, /* ] - 93 */
1917 7 , 67, /* ^ - 94 */
1918 7 , 68, /* _ - 95 */
1919 7 , 72, /* ` - 96 */
1920 14 , 2, /* a - 97 */
1921 14 , 9, /* b - 98 */
1922 14 , 10, /* c - 99 */
1923 14 , 26, /* d - 100 */
1924 14 , 33, /* e - 101 */
1925 14 , 35, /* f - 102 */
1926 14 , 37, /* g - 103 */
1927 14 , 44, /* h - 104 */
1928 14 , 50, /* i - 105 */
1929 14 , 53, /* j - 106 */
1930 14 , 54, /* k - 107 */
1931 14 , 72, /* l - 108 */
1932 14 , 81, /* m - 109 */
1933 14 , 112, /* n - 110 */
1934 14 , 124, /* o - 111 */
1935 14 , 126, /* p - 112 */
1936 14 , 137, /* q - 113 */
1937 14 , 138, /* r - 114 */
1938 14 , 145, /* s - 115 */
1939 14 , 153, /* t - 116 */
1940 14 , 159, /* u - 117 */
1941 14 , 162, /* v - 118 */
1942 14 , 164, /* w - 119 */
1943 14 , 166, /* x - 120 */
1944 14 , 167, /* y - 121 */
1945 14 , 169, /* z - 122 */
1946 7 , 74, /* { - 123 */
1947 7 , 76, /* | - 124 */
1948 7 , 78, /* } - 125 */
1949 7 , 80, /* ~ - 126 */
1950 6 , 29, /* \x7f - 127 */
1951 6 , 30, /* € - 128 */
1952 6 , 31, /* � - 129 */
1953 7 , 123, /* ‚ - 130 */
1954 14 , 35, /* ƒ - 131 */
1955 7 , 127, /* „ - 132 */
1956 10 , 21, /* … - 133 */
1957 10 , 15, /* † - 134 */
1958 10 , 16, /* ‡ - 135 */
1959 7 , 67, /* ˆ - 136 */
1960 10 , 22, /* ‰ - 137 */
1961 14 , 145, /* Š - 138 */
1962 7 , 136, /* ‹ - 139 */
1963 14 + 16 , 124, /* Π- 140 */
1964 6 , 43, /* � - 141 */
1965 6 , 44, /* Ž - 142 */
1966 6 , 45, /* � - 143 */
1967 6 , 46, /* � - 144 */
1968 7 , 121, /* ‘ - 145 */
1969 7 , 122, /* ’ - 146 */
1970 7 , 125, /* “ - 147 */
1971 7 , 126, /* ” - 148 */
1972 10 , 17, /* • - 149 */
1973 6 , 137, /* – - 150 */
1974 6 , 139, /* — - 151 */
1975 7 , 93, /* ˜ - 152 */
1976 14 , 156, /* ™ - 153 */
1977 14 , 145, /* š - 154 */
1978 7 , 137, /* › - 155 */
1979 14 + 16 , 124, /* œ - 156 */
1980 6 , 59, /* � - 157 */
1981 6 , 60, /* ž - 158 */
1982 14 , 167, /* Ÿ - 159 */
1983 7 , 4, /*   - 160 */
1984 7 , 81, /* ¡ - 161 */
1985 10 , 2, /* ¢ - 162 */
1986 10 , 3, /* £ - 163 */
1987 10 , 4, /* ¤ - 164 */
1988 10 , 5, /* ¥ - 165 */
1989 7 , 82, /* ¦ - 166 */
1990 10 , 6, /* § - 167 */
1991 7 , 83, /* ¨ - 168 */
1992 10 , 7, /* © - 169 */
1993 14 , 2, /* ª - 170 */
1994 8 , 24, /* « - 171 */
1995 10 , 8, /* ¬ - 172 */
1996 6 , 131, /* ­ - 173 */
1997 10 , 9, /* ® - 174 */
1998 7 , 84, /* ¯ - 175 */
1999 10 , 10, /* ° - 176 */
2000 8 , 23, /* ± - 177 */
2001 12 , 51, /* ² - 178 */
2002 12 , 70, /* ³ - 179 */
2003 7 , 85, /* ´ - 180 */
2004 10 , 11, /* µ - 181 */
2005 10 , 12, /* ¶ - 182 */
2006 10 , 13, /* · - 183 */
2007 7 , 86, /* ¸ - 184 */
2008 12 , 33, /* ¹ - 185 */
2009 14 , 124, /* º - 186 */
2010 8 , 26, /* » - 187 */
2011 12 , 21, /* ¼ - 188 */
2012 12 , 25, /* ½ - 189 */
2013 12 , 29, /* ¾ - 190 */
2014 7 , 87, /* ¿ - 191 */
2015 14 , 2, /* À - 192 */
2016 14 , 2, /* Á - 193 */
2017 14 , 2, /* Â - 194 */
2018 14 , 2, /* Ã - 195 */
2019 14 , 2, /* Ä - 196 */
2020 14 , 2, /* Å - 197 */
2021 14 + 16 , 2, /* Æ - 198 */
2022 14 , 10, /* Ç - 199 */
2023 14 , 33, /* È - 200 */
2024 14 , 33, /* É - 201 */
2025 14 , 33, /* Ê - 202 */
2026 14 , 33, /* Ë - 203 */
2027 14 , 50, /* Ì - 204 */
2028 14 , 50, /* Í - 205 */
2029 14 , 50, /* Î - 206 */
2030 14 , 50, /* Ï - 207 */
2031 14 , 26, /* Ð - 208 */
2032 14 , 112, /* Ñ - 209 */
2033 14 , 124, /* Ò - 210 */
2034 14 , 124, /* Ó - 211 */
2035 14 , 124, /* Ô - 212 */
2036 14 , 124, /* Õ - 213 */
2037 14 , 124, /* Ö - 214 */
2038 8 , 28, /* × - 215 */
2039 14 , 124, /* Ø - 216 */
2040 14 , 159, /* Ù - 217 */
2041 14 , 159, /* Ú - 218 */
2042 14 , 159, /* Û - 219 */
2043 14 , 159, /* Ü - 220 */
2044 14 , 167, /* Ý - 221 */
2045 14 + 32 , 153, /* Þ - 222 */
2046 14 + 48 , 145, /* ß - 223 */
2047 14 , 2, /* à - 224 */
2048 14 , 2, /* á - 225 */
2049 14 , 2, /* â - 226 */
2050 14 , 2, /* ã - 227 */
2051 14 , 2, /* ä - 228 */
2052 14 , 2, /* å - 229 */
2053 14 + 16 , 2, /* æ - 230 */
2054 14 , 10, /* ç - 231 */
2055 14 , 33, /* è - 232 */
2056 14 , 33, /* é - 233 */
2057 14 , 33, /* ê - 234 */
2058 14 , 33, /* ë - 235 */
2059 14 , 50, /* ì - 236 */
2060 14 , 50, /* í - 237 */
2061 14 , 50, /* î - 238 */
2062 14 , 50, /* ï - 239 */
2063 14 , 26, /* ð - 240 */
2064 14 , 112, /* ñ - 241 */
2065 14 , 124, /* ò - 242 */
2066 14 , 124, /* ó - 243 */
2067 14 , 124, /* ô - 244 */
2068 14 , 124, /* õ - 245 */
2069 14 , 124, /* ö - 246 */
2070 8 , 29, /* ÷ - 247 */
2071 14 , 124, /* ø - 248 */
2072 14 , 159, /* ù - 249 */
2073 14 , 159, /* ú - 250 */
2074 14 , 159, /* û - 251 */
2075 14 , 159, /* ü - 252 */
2076 14 , 167, /* ý - 253 */
2077 14 + 32 , 153, /* þ - 254 */
2078 14 , 167 /* ÿ - 255 */ };
2080 static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
2082 #define LCM_Diacritic_Start 131
2084 static const unsigned char LCM_Diacritic_LUT[] = {
2085 123, /* ƒ - 131 */
2086 2, /* „ - 132 */
2087 2, /* … - 133 */
2088 2, /* † - 134 */
2089 2, /* ‡ - 135 */
2090 3, /* ˆ - 136 */
2091 2, /* ‰ - 137 */
2092 20, /* Š - 138 */
2093 2, /* ‹ - 139 */
2094 2, /* Π- 140 */
2095 2, /* � - 141 */
2096 2, /* Ž - 142 */
2097 2, /* � - 143 */
2098 2, /* � - 144 */
2099 2, /* ‘ - 145 */
2100 2, /* ’ - 146 */
2101 2, /* “ - 147 */
2102 2, /* ” - 148 */
2103 2, /* • - 149 */
2104 2, /* – - 150 */
2105 2, /* — - 151 */
2106 2, /* ˜ - 152 */
2107 2, /* ™ - 153 */
2108 20, /* š - 154 */
2109 2, /* › - 155 */
2110 2, /* œ - 156 */
2111 2, /* � - 157 */
2112 2, /* ž - 158 */
2113 19, /* Ÿ - 159 */
2114 2, /*   - 160 */
2115 2, /* ¡ - 161 */
2116 2, /* ¢ - 162 */
2117 2, /* £ - 163 */
2118 2, /* ¤ - 164 */
2119 2, /* ¥ - 165 */
2120 2, /* ¦ - 166 */
2121 2, /* § - 167 */
2122 2, /* ¨ - 168 */
2123 2, /* © - 169 */
2124 3, /* ª - 170 */
2125 2, /* « - 171 */
2126 2, /* ¬ - 172 */
2127 2, /* ­ - 173 */
2128 2, /* ® - 174 */
2129 2, /* ¯ - 175 */
2130 2, /* ° - 176 */
2131 2, /* ± - 177 */
2132 2, /* ² - 178 */
2133 2, /* ³ - 179 */
2134 2, /* ´ - 180 */
2135 2, /* µ - 181 */
2136 2, /* ¶ - 182 */
2137 2, /* · - 183 */
2138 2, /* ¸ - 184 */
2139 2, /* ¹ - 185 */
2140 3, /* º - 186 */
2141 2, /* » - 187 */
2142 2, /* ¼ - 188 */
2143 2, /* ½ - 189 */
2144 2, /* ¾ - 190 */
2145 2, /* ¿ - 191 */
2146 15, /* À - 192 */
2147 14, /* Á - 193 */
2148 18, /* Â - 194 */
2149 25, /* Ã - 195 */
2150 19, /* Ä - 196 */
2151 26, /* Å - 197 */
2152 2, /* Æ - 198 */
2153 28, /* Ç - 199 */
2154 15, /* È - 200 */
2155 14, /* É - 201 */
2156 18, /* Ê - 202 */
2157 19, /* Ë - 203 */
2158 15, /* Ì - 204 */
2159 14, /* Í - 205 */
2160 18, /* Î - 206 */
2161 19, /* Ï - 207 */
2162 104, /* Ð - 208 */
2163 25, /* Ñ - 209 */
2164 15, /* Ò - 210 */
2165 14, /* Ó - 211 */
2166 18, /* Ô - 212 */
2167 25, /* Õ - 213 */
2168 19, /* Ö - 214 */
2169 2, /* × - 215 */
2170 33, /* Ø - 216 */
2171 15, /* Ù - 217 */
2172 14, /* Ú - 218 */
2173 18, /* Û - 219 */
2174 19, /* Ü - 220 */
2175 14, /* Ý - 221 */
2176 2, /* Þ - 222 */
2177 2, /* ß - 223 */
2178 15, /* à - 224 */
2179 14, /* á - 225 */
2180 18, /* â - 226 */
2181 25, /* ã - 227 */
2182 19, /* ä - 228 */
2183 26, /* å - 229 */
2184 2, /* æ - 230 */
2185 28, /* ç - 231 */
2186 15, /* è - 232 */
2187 14, /* é - 233 */
2188 18, /* ê - 234 */
2189 19, /* ë - 235 */
2190 15, /* ì - 236 */
2191 14, /* í - 237 */
2192 18, /* î - 238 */
2193 19, /* ï - 239 */
2194 104, /* ð - 240 */
2195 25, /* ñ - 241 */
2196 15, /* ò - 242 */
2197 14, /* ó - 243 */
2198 18, /* ô - 244 */
2199 25, /* õ - 245 */
2200 19, /* ö - 246 */
2201 2, /* ÷ - 247 */
2202 33, /* ø - 248 */
2203 15, /* ù - 249 */
2204 14, /* ú - 250 */
2205 18, /* û - 251 */
2206 19, /* ü - 252 */
2207 14, /* ý - 253 */
2208 2, /* þ - 254 */
2209 19, /* ÿ - 255 */
2212 /******************************************************************************
2213 * OLE2NLS_isPunctuation [INTERNAL]
2215 static int OLE2NLS_isPunctuation(unsigned char c)
2217 /* "punctuation character" in this context is a character which is
2218 considered "less important" during word sort comparison.
2219 See LCMapString implementation for the precise definition
2220 of "less important". */
2222 return (LCM_Unicode_LUT[-2+2*c]==6);
2225 /******************************************************************************
2226 * OLE2NLS_isNonSpacing [INTERNAL]
2228 static int OLE2NLS_isNonSpacing(unsigned char c)
2230 /* This function is used by LCMapStringA. Characters
2231 for which it returns true are ignored when mapping a
2232 string with NORM_IGNORENONSPACE */
2233 return ((c==136) || (c==170) || (c==186));
2236 /******************************************************************************
2237 * OLE2NLS_isSymbol [INTERNAL]
2239 static int OLE2NLS_isSymbol(unsigned char c)
2241 /* This function is used by LCMapStringA. Characters
2242 for which it returns true are ignored when mapping a
2243 string with NORM_IGNORESYMBOLS */
2244 return ( (c!=0) && !IsCharAlphaNumericA(c) );
2247 /******************************************************************************
2248 * identity [Internal]
2250 static int identity(int c)
2252 return c;
2255 /*************************************************************************
2256 * LCMapStringA [KERNEL32.492]
2258 * Convert a string, or generate a sort key from it.
2260 * If (mapflags & LCMAP_SORTKEY), the function will generate
2261 * a sort key for the source string. Else, it will convert it
2262 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
2264 * RETURNS
2265 * Error : 0.
2266 * Success : length of the result string.
2268 * NOTES
2269 * If called with scrlen = -1, the function will compute the length
2270 * of the 0-terminated string strsrc by itself.
2272 * If called with dstlen = 0, returns the buffer length that
2273 * would be required.
2275 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
2276 * as if they are equal.
2277 * In the only code page implemented so far, there may not be
2278 * wide characters in strings passed to LCMapStringA,
2279 * so there is nothing to be done for this flag.
2281 INT WINAPI LCMapStringA(
2282 LCID lcid /* locale identifier created with MAKELCID;
2283 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
2284 predefined values. */,
2285 DWORD mapflags /* flags */,
2286 LPCSTR srcstr /* source buffer */,
2287 INT srclen /* source length */,
2288 LPSTR dststr /* destination buffer */,
2289 INT dstlen /* destination buffer length */)
2291 int i;
2293 TRACE_(string)("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
2294 lcid,mapflags,srcstr,srclen,dststr,dstlen);
2296 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2298 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
2299 SetLastError(ERROR_INVALID_PARAMETER);
2300 return 0;
2302 if (srclen == -1)
2303 srclen = lstrlenA(srcstr) + 1 ; /* (include final '\0') */
2305 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
2306 LCMAP_LOWERCASE | \
2307 LCMAP_SORTKEY | \
2308 NORM_IGNORECASE | \
2309 NORM_IGNORENONSPACE | \
2310 SORT_STRINGSORT | \
2311 NORM_IGNOREWIDTH | \
2312 NORM_IGNOREKANATYPE)
2313 /* FIXME: as long as we don't support Kanakana nor Hirigana
2314 * characters, we can support NORM_IGNOREKANATYPE
2316 if (mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS)
2318 FIXME_(string)("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
2319 "unimplemented flags: 0x%08lx\n",
2320 lcid,
2321 mapflags,
2322 srcstr,
2323 srclen,
2324 dststr,
2325 dstlen,
2326 mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS
2330 if ( !(mapflags & LCMAP_SORTKEY) )
2332 int i,j;
2333 int (*f)(int) = identity;
2334 int flag_ignorenonspace = mapflags & NORM_IGNORENONSPACE;
2335 int flag_ignoresymbols = mapflags & NORM_IGNORESYMBOLS;
2337 if (flag_ignorenonspace || flag_ignoresymbols)
2339 /* For some values of mapflags, the length of the resulting
2340 string is not known at this point. Windows does map the string
2341 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
2342 these cases. */
2343 if (dstlen==0)
2345 /* Compute required length */
2346 for (i=j=0; i < srclen; i++)
2348 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
2349 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
2350 j++;
2352 return j;
2355 else
2357 if (dstlen==0)
2358 return srclen;
2359 if (dstlen<srclen)
2361 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2362 return 0;
2365 if (mapflags & LCMAP_UPPERCASE)
2366 f = toupper;
2367 else if (mapflags & LCMAP_LOWERCASE)
2368 f = tolower;
2369 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
2370 for (i=j=0; (i<srclen) && (j<dstlen) ; i++)
2372 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
2373 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
2375 dststr[j] = (CHAR) f(srcstr[i]);
2376 j++;
2379 return j;
2382 /* FIXME: This function completely ignores the "lcid" parameter. */
2383 /* else ... (mapflags & LCMAP_SORTKEY) */
2385 int unicode_len=0;
2386 int case_len=0;
2387 int diacritic_len=0;
2388 int delayed_punctuation_len=0;
2389 char *case_component;
2390 char *diacritic_component;
2391 char *delayed_punctuation_component;
2392 int room,count;
2393 int flag_stringsort = mapflags & SORT_STRINGSORT;
2395 /* compute how much room we will need */
2396 for (i=0;i<srclen;i++)
2398 int ofs;
2399 unsigned char source_char = srcstr[i];
2400 if (source_char!='\0')
2402 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
2404 unicode_len++;
2405 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
2406 unicode_len++; /* double letter */
2408 else
2410 delayed_punctuation_len++;
2414 if (isupper(source_char))
2415 case_len=unicode_len;
2417 ofs = source_char - LCM_Diacritic_Start;
2418 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
2419 diacritic_len=unicode_len;
2422 if (mapflags & NORM_IGNORECASE)
2423 case_len=0;
2424 if (mapflags & NORM_IGNORENONSPACE)
2425 diacritic_len=0;
2427 room = 2 * unicode_len /* "unicode" component */
2428 + diacritic_len /* "diacritic" component */
2429 + case_len /* "case" component */
2430 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
2431 + 4 /* four '\1' separators */
2432 + 1 ; /* terminal '\0' */
2433 if (dstlen==0)
2434 return room;
2435 else if (dstlen<room)
2437 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2438 return 0;
2441 /*FIXME the Pointercheck should not be nessesary */
2442 if (IsBadWritePtr (dststr,room))
2443 { ERR_(string)("bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
2444 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2445 return 0;
2448 /* locate each component, write separators */
2449 diacritic_component = dststr + 2*unicode_len ;
2450 *diacritic_component++ = '\1';
2451 case_component = diacritic_component + diacritic_len ;
2452 *case_component++ = '\1';
2453 delayed_punctuation_component = case_component + case_len ;
2454 *delayed_punctuation_component++ = '\1';
2455 *delayed_punctuation_component++ = '\1';
2457 /* read source string char by char, write
2458 corresponding weight in each component. */
2459 for (i=0,count=0;i<srclen;i++)
2461 unsigned char source_char=srcstr[i];
2462 if (source_char!='\0')
2464 int type,longcode;
2465 type = LCM_Unicode_LUT[-2+2*source_char];
2466 longcode = type >> 4;
2467 type &= 15;
2468 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
2470 UINT16 encrypted_location = (1<<15) + 7 + 4*count;
2471 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
2472 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
2473 /* big-endian is used here because it lets string comparison be
2474 compatible with numerical comparison */
2476 *delayed_punctuation_component++ = type;
2477 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
2478 /* assumption : a punctuation character is never a
2479 double or accented letter */
2481 else
2483 dststr[2*count] = type;
2484 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
2485 if (longcode)
2487 if (count<case_len)
2488 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2489 if (count<diacritic_len)
2490 diacritic_component[count] = 2; /* assumption: a double letter
2491 is never accented */
2492 count++;
2494 dststr[2*count] = type;
2495 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
2496 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
2497 32 in the first column of LCM_Unicode_LUT --> longcode = 2
2498 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
2501 if (count<case_len)
2502 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2503 if (count<diacritic_len)
2505 int ofs = source_char - LCM_Diacritic_Start;
2506 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
2508 count++;
2512 dststr[room-1] = '\0';
2513 return room;
2517 /*************************************************************************
2518 * LCMapStringW [KERNEL32.493]
2520 * Convert a string, or generate a sort key from it.
2522 * NOTE
2524 * See LCMapStringA for documentation
2526 INT WINAPI LCMapStringW(
2527 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT srclen,LPWSTR dststr,
2528 INT dstlen)
2530 int i;
2532 TRACE_(string)("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2533 lcid, mapflags, srcstr, srclen, dststr, dstlen);
2535 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2537 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
2538 SetLastError(ERROR_INVALID_PARAMETER);
2539 return 0;
2541 if (srclen==-1)
2542 srclen = lstrlenW(srcstr)+1;
2544 /* FIXME: Both this function and it's companion LCMapStringA()
2545 * completely ignore the "lcid" parameter. In place of the "lcid"
2546 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2547 * environment variable prior to invoking this function. */
2548 if (mapflags & LCMAP_SORTKEY)
2550 /* Possible values of LC_COLLATE. */
2551 char *lc_collate_default = 0; /* value prior to this function */
2552 char *lc_collate_env = 0; /* value retrieved from the environment */
2554 /* General purpose index into strings of any type. */
2555 int str_idx = 0;
2557 /* Lengths of various strings where the length is measured in
2558 * wide characters for wide character strings and in bytes for
2559 * native strings. The lengths include the NULL terminator. */
2560 size_t returned_len = 0;
2561 size_t src_native_len = 0;
2562 size_t dst_native_len = 0;
2563 size_t dststr_libc_len = 0;
2565 /* Native (character set determined by locale) versions of the
2566 * strings source and destination strings. */
2567 LPSTR src_native = 0;
2568 LPSTR dst_native = 0;
2570 /* Version of the source and destination strings using the
2571 * "wchar_t" Unicode data type needed by various libc functions. */
2572 wchar_t *srcstr_libc = 0;
2573 wchar_t *dststr_libc = 0;
2575 if(!(srcstr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2576 srclen * sizeof(wchar_t))))
2578 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2579 srclen * sizeof(wchar_t));
2580 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2581 return 0;
2584 /* Convert source string to a libc Unicode string. */
2585 for(str_idx = 0; str_idx < srclen; str_idx++)
2587 srcstr_libc[str_idx] = srcstr[str_idx];
2590 /* src_native should contain at most 3 bytes for each
2591 * multibyte characters in the original srcstr string. */
2592 src_native_len = 3 * srclen;
2593 if(!(src_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0,
2594 src_native_len)))
2596 ERR("Unable to allocate %d bytes for src_native\n", src_native_len);
2597 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2598 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2599 return 0;
2602 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2603 * current value is backed up so it can be restored after the
2604 * last LC_COLLATE sensitive function returns.
2606 * Even though the locale is adjusted for a minimum amount of
2607 * time a race condition exists where other threads may be
2608 * affected if they invoke LC_COLLATE sensitive functions. One
2609 * possible solution is to wrap all LC_COLLATE sensitive Wine
2610 * functions, like LCMapStringW(), in a mutex.
2612 * Another enhancement to the following would be to set the
2613 * LC_COLLATE locale category as a function of the "lcid"
2614 * parameter instead of the "LC_COLLATE" environment variable. */
2615 if(!(lc_collate_default = setlocale(LC_COLLATE, NULL)))
2617 ERR("Unable to query the LC_COLLATE catagory\n");
2618 SetLastError(ERROR_INVALID_PARAMETER);
2619 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2620 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2621 return 0;
2624 if(!(lc_collate_env = setlocale(LC_COLLATE, "")))
2626 ERR("Unable to inherit the LC_COLLATE locale category from the "
2627 "environment. The \"LC_COLLATE\" environment variable is "
2628 "\"%s\".\n", getenv("LC_COLLATE") ?
2629 getenv("LC_COLLATE") : "<unset>");
2630 SetLastError(ERROR_INVALID_PARAMETER);
2631 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2632 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2633 return 0;
2636 TRACE_(string)("lc_collate_default = %s\n", lc_collate_default);
2637 TRACE_(string)("lc_collate_env = %s\n", lc_collate_env);
2639 /* Convert the libc Unicode string to a native multibyte character
2640 * string. */
2641 returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1;
2642 if(returned_len == 0)
2644 LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(),
2645 0, srcstr);
2646 ERR("wcstombs failed. The string specified (%s) may contains an "
2647 "invalid character.\n", srcstr_ascii);
2648 SetLastError(ERROR_INVALID_PARAMETER);
2649 if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii);
2650 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2651 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2652 setlocale(LC_COLLATE, lc_collate_default);
2653 return 0;
2655 else if(returned_len > src_native_len)
2657 src_native[src_native_len - 1] = 0;
2658 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2659 "than expected (%d bytes).\n", src_native, returned_len,
2660 dst_native_len);
2662 /* Since this is an internal error I'm not sure what the correct
2663 * error code is. */
2664 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2666 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2667 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2668 setlocale(LC_COLLATE, lc_collate_default);
2669 return 0;
2671 src_native_len = returned_len;
2673 TRACE_(string)("src_native = %s src_native_len = %d\n",
2674 src_native, src_native_len);
2676 /* dst_native seems to contain at most 4 bytes for each byte in
2677 * the original src_native string. Change if need be since this
2678 * isn't documented by the strxfrm() man page. */
2679 dst_native_len = 4 * src_native_len;
2680 if(!(dst_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0, dst_native_len)))
2682 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len);
2683 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2684 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2685 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2686 setlocale(LC_COLLATE, lc_collate_default);
2687 return 0;
2690 /* The actual translation is done by the following call to
2691 * strxfrm(). The surrounding code could have been simplified
2692 * by calling wcsxfrm() instead except that wcsxfrm() is not
2693 * available on older Linux systems (RedHat 4.1 with
2694 * libc-5.3.12-17).
2696 * Also, it is possible that the translation could be done by
2697 * various tables as it is done in LCMapStringA(). However, I'm
2698 * not sure what those tables are. */
2699 returned_len = strxfrm(dst_native, src_native, dst_native_len) + 1;
2701 if(returned_len > dst_native_len)
2703 dst_native[dst_native_len - 1] = 0;
2704 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2705 "than expected (%d bytes).\n", dst_native, returned_len,
2706 dst_native_len);
2708 /* Since this is an internal error I'm not sure what the correct
2709 * error code is. */
2710 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2712 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2713 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2714 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2715 setlocale(LC_COLLATE, lc_collate_default);
2716 return 0;
2718 dst_native_len = returned_len;
2720 TRACE_(string)("dst_native = %s dst_native_len = %d\n",
2721 dst_native, dst_native_len);
2723 dststr_libc_len = dst_native_len;
2724 if(!(dststr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2725 dststr_libc_len * sizeof(wchar_t))))
2727 ERR("Unable to allocate %d bytes for dststr_libc\n",
2728 dststr_libc_len * sizeof(wchar_t));
2729 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2730 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2731 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2732 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2733 setlocale(LC_COLLATE, lc_collate_default);
2734 return 0;
2737 /* Convert the native multibyte string to a libc Unicode string. */
2738 returned_len = mbstowcs(dststr_libc, dst_native, dst_native_len) + 1;
2740 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2741 * function has returned. */
2742 setlocale(LC_COLLATE, lc_collate_default);
2744 if(returned_len == 0)
2746 ERR("mbstowcs failed. The native version of the translated string "
2747 "(%s) may contain an invalid character.\n", dst_native);
2748 SetLastError(ERROR_INVALID_PARAMETER);
2749 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2750 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2751 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2752 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2753 return 0;
2755 if(dstlen)
2757 if(returned_len > dstlen)
2759 ERR("mbstowcs returned a string that was longer (%d chars) "
2760 "than the buffer provided (%d chars).\n", returned_len,
2761 dstlen);
2762 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2763 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2764 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2765 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2766 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2767 return 0;
2769 dstlen = returned_len;
2771 /* Convert a libc Unicode string to the destination string. */
2772 for(str_idx = 0; str_idx < dstlen; str_idx++)
2774 dststr[str_idx] = dststr_libc[str_idx];
2776 TRACE_(string)("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2777 *(((int *)dststr) + 0),
2778 *(((int *)dststr) + 1),
2779 *(((int *)dststr) + 2),
2780 *(((int *)dststr) + 3));
2782 else
2784 dstlen = returned_len;
2786 TRACE_(string)("dstlen (return) = %d\n", dstlen);
2787 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2788 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2789 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2790 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2791 return dstlen;
2793 else
2795 int (*f)(int)=identity;
2797 if (dstlen==0)
2798 return srclen;
2799 if (dstlen<srclen)
2801 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2802 return 0;
2805 if (mapflags & LCMAP_UPPERCASE)
2806 f = toupper;
2807 else if (mapflags & LCMAP_LOWERCASE)
2808 f = tolower;
2809 for (i=0; i < srclen; i++)
2810 dststr[i] = (WCHAR) f(srcstr[i]);
2811 return srclen;
2816 /***********************************************************************
2817 * OLE2NLS_EstimateMappingLength
2819 * Estimates the number of characters required to hold the string
2820 * computed by LCMapStringA.
2822 * The size is always over-estimated, with a fixed limit on the
2823 * amount of estimation error.
2825 * Note that len == -1 is not permitted.
2827 static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
2828 LPCSTR str, DWORD len)
2830 /* Estimate only for small strings to keep the estimation error from
2831 * becoming too large. */
2832 if (len < 128) return len * 8 + 5;
2833 else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
2836 /******************************************************************************
2837 * CompareStringA [KERNEL32.143]
2838 * Compares two strings using locale
2840 * RETURNS
2842 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2843 * failure: 0
2845 * NOTES
2847 * Defaults to a word sort, but uses a string sort if
2848 * SORT_STRINGSORT is set.
2849 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2851 * BUGS
2853 * This implementation ignores the locale
2855 * FIXME
2857 * Quite inefficient.
2859 UINT WINAPI CompareStringA(
2860 DWORD lcid, /* locale ID */
2861 DWORD fdwStyle, /* comparison-style options */
2862 LPCSTR s1, /* first string */
2863 DWORD l1, /* length of first string */
2864 LPCSTR s2, /* second string */
2865 DWORD l2) /* length of second string */
2867 int mapstring_flags;
2868 int len1,len2;
2869 int result;
2870 LPSTR sk1,sk2;
2871 TRACE("%s and %s\n",
2872 debugstr_a (s1), debugstr_a (s2));
2874 if ( (s1==NULL) || (s2==NULL) )
2876 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
2877 SetLastError(ERROR_INVALID_PARAMETER);
2878 return 0;
2881 if(fdwStyle & NORM_IGNORESYMBOLS)
2882 FIXME("IGNORESYMBOLS not supported\n");
2884 if (l1 == -1) l1 = lstrlenA(s1);
2885 if (l2 == -1) l2 = lstrlenA(s2);
2887 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2888 len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
2889 len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
2891 if ((len1==0)||(len2==0))
2892 return 0; /* something wrong happened */
2894 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
2895 sk2 = sk1 + len1;
2896 if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
2897 || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2899 ERR("Bug in LCmapStringA.\n");
2900 result = 0;
2902 else
2904 /* strcmp doesn't necessarily return -1, 0, or 1 */
2905 result = strcmp(sk1,sk2);
2907 HeapFree(GetProcessHeap(),0,sk1);
2909 if (result < 0)
2910 return 1;
2911 if (result == 0)
2912 return 2;
2914 /* must be greater, if we reach this point */
2915 return 3;
2918 /******************************************************************************
2919 * CompareStringW [KERNEL32.144]
2920 * This implementation ignores the locale
2921 * FIXME : Does only string sort. Should
2922 * be reimplemented the same way as CompareStringA.
2924 UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
2925 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2927 int len,ret;
2928 if(fdwStyle & NORM_IGNORENONSPACE)
2929 FIXME("IGNORENONSPACE not supprted\n");
2930 if(fdwStyle & NORM_IGNORESYMBOLS)
2931 FIXME("IGNORESYMBOLS not supported\n");
2933 /* Is strcmp defaulting to string sort or to word sort?? */
2934 /* FIXME: Handle NORM_STRINGSORT */
2935 l1 = (l1==-1)?lstrlenW(s1):l1;
2936 l2 = (l2==-1)?lstrlenW(s2):l2;
2937 len = l1<l2 ? l1:l2;
2938 ret = (fdwStyle & NORM_IGNORECASE) ?
2939 CRTDLL__wcsnicmp(s1,s2,len) : CRTDLL_wcsncmp(s1,s2,len);
2940 /* not equal, return 1 or 3 */
2941 if(ret!=0) return ret+2;
2942 /* same len, return 2 */
2943 if(l1==l2) return 2;
2944 /* the longer one is lexically greater */
2945 return (l1<l2)? 1 : 3;
2948 /******************************************************************************
2949 * OLE_GetFormatA [Internal]
2951 * FIXME
2952 * If datelen == 0, it should return the reguired string length.
2954 This function implements stuff for GetDateFormat() and
2955 GetTimeFormat().
2957 d single-digit (no leading zero) day (of month)
2958 dd two-digit day (of month)
2959 ddd short day-of-week name
2960 dddd long day-of-week name
2961 M single-digit month
2962 MM two-digit month
2963 MMM short month name
2964 MMMM full month name
2965 y two-digit year, no leading 0
2966 yy two-digit year
2967 yyyy four-digit year
2968 gg era string
2969 h hours with no leading zero (12-hour)
2970 hh hours with full two digits
2971 H hours with no leading zero (24-hour)
2972 HH hours with full two digits
2973 m minutes with no leading zero
2974 mm minutes with full two digits
2975 s seconds with no leading zero
2976 ss seconds with full two digits
2977 t time marker (A or P)
2978 tt time marker (AM, PM)
2979 '' used to quote literal characters
2980 '' (within a quoted string) indicates a literal '
2982 These functions REQUIRE valid locale, date, and format.
2984 static INT OLE_GetFormatA(LCID locale,
2985 DWORD flags,
2986 DWORD tflags,
2987 LPSYSTEMTIME xtime,
2988 LPCSTR _format, /*in*/
2989 LPSTR date, /*out*/
2990 INT datelen)
2992 INT inpos, outpos;
2993 int count, type, inquote, Overflow;
2994 char buf[40];
2995 char format[40];
2996 char * pos;
2997 int buflen;
2999 const char * _dgfmt[] = { "%d", "%02d" };
3000 const char ** dgfmt = _dgfmt - 1;
3002 /* report, for debugging */
3003 TRACE("(0x%lx,0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
3004 locale, flags, tflags,
3005 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
3006 _format, _format, date, datelen);
3008 if(datelen == 0) {
3009 FIXME("datelen = 0, returning 255\n");
3010 return 255;
3013 /* initalize state variables and output buffer */
3014 inpos = outpos = 0;
3015 count = 0; inquote = 0; Overflow = 0;
3016 type = '\0';
3017 date[0] = buf[0] = '\0';
3019 strcpy(format,_format);
3021 /* alter the formatstring, while it works for all languages now in wine
3022 its possible that it fails when the time looks like ss:mm:hh as example*/
3023 if (tflags & (TIME_NOMINUTESORSECONDS))
3024 { if ((pos = strstr ( format, ":mm")))
3025 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
3028 if (tflags & (TIME_NOSECONDS))
3029 { if ((pos = strstr ( format, ":ss")))
3030 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
3034 for (inpos = 0;; inpos++) {
3035 /* 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]); */
3036 if (inquote) {
3037 if (format[inpos] == '\'') {
3038 if (format[inpos+1] == '\'') {
3039 inpos += 1;
3040 date[outpos++] = '\'';
3041 } else {
3042 inquote = 0;
3043 continue; /* we did nothing to the output */
3045 } else if (format[inpos] == '\0') {
3046 date[outpos++] = '\0';
3047 if (outpos > datelen) Overflow = 1;
3048 break;
3049 } else {
3050 date[outpos++] = format[inpos];
3051 if (outpos > datelen) {
3052 Overflow = 1;
3053 date[outpos-1] = '\0'; /* this is the last place where
3054 it's safe to write */
3055 break;
3058 } else if ( (count && (format[inpos] != type))
3059 || count == 4
3060 || (count == 2 && strchr("ghHmst", type)) )
3062 if (type == 'd') {
3063 if (count == 4) {
3064 GetLocaleInfoA(locale,
3065 LOCALE_SDAYNAME1
3066 + xtime->wDayOfWeek - 1,
3067 buf, sizeof(buf));
3068 } else if (count == 3) {
3069 GetLocaleInfoA(locale,
3070 LOCALE_SABBREVDAYNAME1
3071 + xtime->wDayOfWeek - 1,
3072 buf, sizeof(buf));
3073 } else {
3074 sprintf(buf, dgfmt[count], xtime->wDay);
3076 } else if (type == 'M') {
3077 if (count == 3) {
3078 GetLocaleInfoA(locale,
3079 LOCALE_SABBREVMONTHNAME1
3080 + xtime->wMonth - 1,
3081 buf, sizeof(buf));
3082 } else if (count == 4) {
3083 GetLocaleInfoA(locale,
3084 LOCALE_SMONTHNAME1
3085 + xtime->wMonth - 1,
3086 buf, sizeof(buf));
3087 } else {
3088 sprintf(buf, dgfmt[count], xtime->wMonth);
3090 } else if (type == 'y') {
3091 if (count == 4) {
3092 sprintf(buf, "%d", xtime->wYear);
3093 } else if (count == 3) {
3094 strcpy(buf, "yyy");
3095 WARN("unknown format, c=%c, n=%d\n", type, count);
3096 } else {
3097 sprintf(buf, dgfmt[count], xtime->wYear % 100);
3099 } else if (type == 'g') {
3100 if (count == 2) {
3101 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
3102 strcpy(buf, "AD");
3103 } else {
3104 strcpy(buf, "g");
3105 WARN("unknown format, c=%c, n=%d\n", type, count);
3107 } else if (type == 'h') {
3108 /* gives us hours 1:00 -- 12:00 */
3109 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
3110 } else if (type == 'H') {
3111 /* 24-hour time */
3112 sprintf(buf, dgfmt[count], xtime->wHour);
3113 } else if ( type == 'm') {
3114 sprintf(buf, dgfmt[count], xtime->wMinute);
3115 } else if ( type == 's') {
3116 sprintf(buf, dgfmt[count], xtime->wSecond);
3117 } else if (type == 't') {
3118 if (count == 1) {
3119 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
3120 } else if (count == 2) {
3121 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
3122 GetLocaleInfoA(locale,
3123 (xtime->wHour<12)
3124 ? LOCALE_S1159 : LOCALE_S2359,
3125 buf, sizeof(buf));
3129 /* we need to check the next char in the format string
3130 again, no matter what happened */
3131 inpos--;
3133 /* add the contents of buf to the output */
3134 buflen = strlen(buf);
3135 if (outpos + buflen < datelen) {
3136 date[outpos] = '\0'; /* for strcat to hook onto */
3137 strcat(date, buf);
3138 outpos += buflen;
3139 } else {
3140 date[outpos] = '\0';
3141 strncat(date, buf, datelen - outpos);
3142 date[datelen - 1] = '\0';
3143 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3144 WARN("insufficient buffer\n");
3145 return 0;
3148 /* reset the variables we used to keep track of this item */
3149 count = 0;
3150 type = '\0';
3151 } else if (format[inpos] == '\0') {
3152 /* we can't check for this at the loop-head, because
3153 that breaks the printing of the last format-item */
3154 date[outpos] = '\0';
3155 break;
3156 } else if (count) {
3157 /* continuing a code for an item */
3158 count +=1;
3159 continue;
3160 } else if (strchr("hHmstyMdg", format[inpos])) {
3161 type = format[inpos];
3162 count = 1;
3163 continue;
3164 } else if (format[inpos] == '\'') {
3165 inquote = 1;
3166 continue;
3167 } else {
3168 date[outpos++] = format[inpos];
3170 /* now deal with a possible buffer overflow */
3171 if (outpos >= datelen) {
3172 date[datelen - 1] = '\0';
3173 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3174 return 0;
3178 if (Overflow) {
3179 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3182 /* finish it off with a string terminator */
3183 outpos++;
3184 /* sanity check */
3185 if (outpos > datelen-1) outpos = datelen-1;
3186 date[outpos] = '\0';
3188 TRACE("OLE_GetFormatA returns string '%s', len %d\n",
3189 date, outpos);
3190 return outpos;
3193 /******************************************************************************
3194 * OLE_GetFormatW [INTERNAL]
3196 static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
3197 LPSYSTEMTIME xtime,
3198 LPCWSTR format,
3199 LPWSTR output, INT outlen)
3201 INT inpos, outpos;
3202 int count, type=0, inquote;
3203 int Overflow; /* loop check */
3204 WCHAR buf[40];
3205 int buflen=0;
3206 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
3207 WCHAR arg2[] = {'%','0','2','d',0};
3208 WCHAR *argarr[3];
3209 int datevars=0, timevars=0;
3211 argarr[0] = arg0;
3212 argarr[1] = arg1;
3213 argarr[2] = arg2;
3215 /* make a debug report */
3216 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
3217 "%p with max len %d\n",
3218 locale, flags, tflags,
3219 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
3220 debugstr_w(format), format, output, outlen);
3222 if(outlen == 0) {
3223 FIXME("outlen = 0, returning 255\n");
3224 return 255;
3227 /* initialize state variables */
3228 inpos = outpos = 0;
3229 count = 0;
3230 inquote = Overflow = 0;
3231 /* this is really just a sanity check */
3232 output[0] = buf[0] = 0;
3234 /* this loop is the core of the function */
3235 for (inpos = 0; /* we have several break points */ ; inpos++) {
3236 if (inquote) {
3237 if (format[inpos] == (WCHAR) '\'') {
3238 if (format[inpos+1] == '\'') {
3239 inpos++;
3240 output[outpos++] = '\'';
3241 } else {
3242 inquote = 0;
3243 continue;
3245 } else if (format[inpos] == 0) {
3246 output[outpos++] = 0;
3247 if (outpos > outlen) Overflow = 1;
3248 break; /* normal exit (within a quote) */
3249 } else {
3250 output[outpos++] = format[inpos]; /* copy input */
3251 if (outpos > outlen) {
3252 Overflow = 1;
3253 output[outpos-1] = 0;
3254 break;
3257 } else if ( (count && (format[inpos] != type))
3258 || ( (count==4 && type =='y') ||
3259 (count==4 && type =='M') ||
3260 (count==4 && type =='d') ||
3261 (count==2 && type =='g') ||
3262 (count==2 && type =='h') ||
3263 (count==2 && type =='H') ||
3264 (count==2 && type =='m') ||
3265 (count==2 && type =='s') ||
3266 (count==2 && type =='t') ) ) {
3267 if (type == 'd') {
3268 if (count == 3) {
3269 GetLocaleInfoW(locale,
3270 LOCALE_SDAYNAME1 + xtime->wDayOfWeek -1,
3271 buf, sizeof(buf)/sizeof(WCHAR) );
3272 } else if (count == 3) {
3273 GetLocaleInfoW(locale,
3274 LOCALE_SABBREVDAYNAME1 +
3275 xtime->wDayOfWeek -1,
3276 buf, sizeof(buf)/sizeof(WCHAR) );
3277 } else {
3278 wsnprintfW(buf, 5, argarr[count], xtime->wDay );
3280 } else if (type == 'M') {
3281 if (count == 4) {
3282 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
3283 xtime->wMonth -1, buf,
3284 sizeof(buf)/sizeof(WCHAR) );
3285 } else if (count == 3) {
3286 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
3287 xtime->wMonth -1, buf,
3288 sizeof(buf)/sizeof(WCHAR) );
3289 } else {
3290 wsnprintfW(buf, 5, argarr[count], xtime->wMonth);
3292 } else if (type == 'y') {
3293 if (count == 4) {
3294 wsnprintfW(buf, 6, argarr[1] /* "%d" */,
3295 xtime->wYear);
3296 } else if (count == 3) {
3297 lstrcpynAtoW(buf, "yyy", 5);
3298 } else {
3299 wsnprintfW(buf, 6, argarr[count],
3300 xtime->wYear % 100);
3302 } else if (type == 'g') {
3303 if (count == 2) {
3304 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
3305 lstrcpynAtoW(buf, "AD", 5);
3306 } else {
3307 /* Win API sez we copy it verbatim */
3308 lstrcpynAtoW(buf, "g", 5);
3310 } else if (type == 'h') {
3311 /* hours 1:00-12:00 --- is this right? */
3312 wsnprintfW(buf, 5, argarr[count],
3313 (xtime->wHour-1)%12 +1);
3314 } else if (type == 'H') {
3315 wsnprintfW(buf, 5, argarr[count],
3316 xtime->wHour);
3317 } else if (type == 'm' ) {
3318 wsnprintfW(buf, 5, argarr[count],
3319 xtime->wMinute);
3320 } else if (type == 's' ) {
3321 wsnprintfW(buf, 5, argarr[count],
3322 xtime->wSecond);
3323 } else if (type == 't') {
3324 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
3325 LOCALE_S1159 : LOCALE_S2359,
3326 buf, sizeof(buf) );
3327 if (count == 1) {
3328 buf[1] = 0;
3332 /* no matter what happened, we need to check this next
3333 character the next time we loop through */
3334 inpos--;
3336 /* cat buf onto the output */
3337 outlen = lstrlenW(buf);
3338 if (outpos + buflen < outlen) {
3339 lstrcpyW( output + outpos, buf );
3340 outpos += buflen;
3341 } else {
3342 lstrcpynW( output + outpos, buf, outlen - outpos );
3343 Overflow = 1;
3344 break; /* Abnormal exit */
3347 /* reset the variables we used this time */
3348 count = 0;
3349 type = '\0';
3350 } else if (format[inpos] == 0) {
3351 /* we can't check for this at the beginning, because that
3352 would keep us from printing a format spec that ended the
3353 string */
3354 output[outpos] = 0;
3355 break; /* NORMAL EXIT */
3356 } else if (count) {
3357 /* how we keep track of the middle of a format spec */
3358 count++;
3359 continue;
3360 } else if ( (datevars && (format[inpos]=='d' ||
3361 format[inpos]=='M' ||
3362 format[inpos]=='y' ||
3363 format[inpos]=='g') ) ||
3364 (timevars && (format[inpos]=='H' ||
3365 format[inpos]=='h' ||
3366 format[inpos]=='m' ||
3367 format[inpos]=='s' ||
3368 format[inpos]=='t') ) ) {
3369 type = format[inpos];
3370 count = 1;
3371 continue;
3372 } else if (format[inpos] == '\'') {
3373 inquote = 1;
3374 continue;
3375 } else {
3376 /* unquoted literals */
3377 output[outpos++] = format[inpos];
3381 if (Overflow) {
3382 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3383 WARN(" buffer overflow\n");
3386 /* final string terminator and sanity check */
3387 outpos++;
3388 if (outpos > outlen-1) outpos = outlen-1;
3389 output[outpos] = '0';
3391 TRACE(" returning %s\n", debugstr_w(output));
3393 return (!Overflow) ? outlen : 0;
3398 /******************************************************************************
3399 * GetDateFormatA [KERNEL32.310]
3400 * Makes an ASCII string of the date
3402 * This function uses format to format the date, or, if format
3403 * is NULL, uses the default for the locale. format is a string
3404 * of literal fields and characters as follows:
3406 * - d single-digit (no leading zero) day (of month)
3407 * - dd two-digit day (of month)
3408 * - ddd short day-of-week name
3409 * - dddd long day-of-week name
3410 * - M single-digit month
3411 * - MM two-digit month
3412 * - MMM short month name
3413 * - MMMM full month name
3414 * - y two-digit year, no leading 0
3415 * - yy two-digit year
3416 * - yyyy four-digit year
3417 * - gg era string
3420 INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
3421 LPSYSTEMTIME xtime,
3422 LPCSTR format, LPSTR date,INT datelen)
3425 char format_buf[40];
3426 LPCSTR thisformat;
3427 SYSTEMTIME t;
3428 LPSYSTEMTIME thistime;
3429 LCID thislocale;
3430 INT ret;
3432 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
3433 locale,flags,xtime,format,date,datelen);
3435 if (!locale) {
3436 locale = LOCALE_SYSTEM_DEFAULT;
3439 if (locale == LOCALE_SYSTEM_DEFAULT) {
3440 thislocale = GetSystemDefaultLCID();
3441 } else if (locale == LOCALE_USER_DEFAULT) {
3442 thislocale = GetUserDefaultLCID();
3443 } else {
3444 thislocale = locale;
3447 if (xtime == NULL) {
3448 GetSystemTime(&t);
3449 thistime = &t;
3450 } else {
3451 thistime = xtime;
3454 if (format == NULL) {
3455 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
3456 ? LOCALE_SLONGDATE
3457 : LOCALE_SSHORTDATE),
3458 format_buf, sizeof(format_buf));
3459 thisformat = format_buf;
3460 } else {
3461 thisformat = format;
3465 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
3466 date, datelen);
3469 TRACE(
3470 "GetDateFormatA() returning %d, with data=%s\n",
3471 ret, date);
3472 return ret;
3475 /******************************************************************************
3476 * GetDateFormatW [KERNEL32.311]
3477 * Makes a Unicode string of the date
3479 * Acts the same as GetDateFormatA(), except that it's Unicode.
3480 * Accepts & returns sizes as counts of Unicode characters.
3483 INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
3484 LPSYSTEMTIME xtime,
3485 LPCWSTR format,
3486 LPWSTR date, INT datelen)
3488 unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
3490 FIXME("STUB (should call OLE_GetFormatW)\n");
3491 lstrcpynW(date, datearr, datelen);
3492 return ( datelen < 9) ? datelen : 9;
3497 /**************************************************************************
3498 * EnumDateFormatsA (KERNEL32.198)
3500 BOOL WINAPI EnumDateFormatsA(
3501 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3503 LCID Loc = GetUserDefaultLCID();
3504 if(!lpDateFmtEnumProc)
3506 SetLastError(ERROR_INVALID_PARAMETER);
3507 return FALSE;
3510 switch( Loc )
3513 case 0x00000407: /* (Loc,"de_DE") */
3515 switch(dwFlags)
3517 case DATE_SHORTDATE:
3518 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3519 if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
3520 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3521 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3522 return TRUE;
3523 case DATE_LONGDATE:
3524 if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
3525 if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
3526 if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
3527 return TRUE;
3528 default:
3529 FIXME("Unknown date format (%ld)\n", dwFlags);
3530 SetLastError(ERROR_INVALID_PARAMETER);
3531 return FALSE;
3535 case 0x0000040c: /* (Loc,"fr_FR") */
3537 switch(dwFlags)
3539 case DATE_SHORTDATE:
3540 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3541 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3542 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3543 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3544 return TRUE;
3545 case DATE_LONGDATE:
3546 if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
3547 if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
3548 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3549 return TRUE;
3550 default:
3551 FIXME("Unknown date format (%ld)\n", dwFlags);
3552 SetLastError(ERROR_INVALID_PARAMETER);
3553 return FALSE;
3557 case 0x00000c0c: /* (Loc,"fr_CA") */
3559 switch(dwFlags)
3561 case DATE_SHORTDATE:
3562 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3563 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3564 if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
3565 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3566 return TRUE;
3567 case DATE_LONGDATE:
3568 if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
3569 if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
3570 return TRUE;
3571 default:
3572 FIXME("Unknown date format (%ld)\n", dwFlags);
3573 SetLastError(ERROR_INVALID_PARAMETER);
3574 return FALSE;
3578 case 0x00000809: /* (Loc,"en_UK") */
3580 switch(dwFlags)
3582 case DATE_SHORTDATE:
3583 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3584 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3585 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3586 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3587 return TRUE;
3588 case DATE_LONGDATE:
3589 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3590 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3591 return TRUE;
3592 default:
3593 FIXME("Unknown date format (%ld)\n", dwFlags);
3594 SetLastError(ERROR_INVALID_PARAMETER);
3595 return FALSE;
3599 case 0x00000c09: /* (Loc,"en_AU") */
3601 switch(dwFlags)
3603 case DATE_SHORTDATE:
3604 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3605 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3606 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3607 return TRUE;
3608 case DATE_LONGDATE:
3609 if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
3610 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3611 return TRUE;
3612 default:
3613 FIXME("Unknown date format (%ld)\n", dwFlags);
3614 SetLastError(ERROR_INVALID_PARAMETER);
3615 return FALSE;
3619 case 0x00001009: /* (Loc,"en_CA") */
3621 switch(dwFlags)
3623 case DATE_SHORTDATE:
3624 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3625 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3626 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3627 if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
3628 return TRUE;
3629 case DATE_LONGDATE:
3630 if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
3631 if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
3632 return TRUE;
3633 default:
3634 FIXME("Unknown date format (%ld)\n", dwFlags);
3635 SetLastError(ERROR_INVALID_PARAMETER);
3636 return FALSE;
3640 case 0x00001409: /* (Loc,"en_NZ") */
3642 switch(dwFlags)
3644 case DATE_SHORTDATE:
3645 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3646 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3647 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3648 return TRUE;
3649 case DATE_LONGDATE:
3650 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3651 if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
3652 return TRUE;
3653 default:
3654 FIXME("Unknown date format (%ld)\n", dwFlags);
3655 SetLastError(ERROR_INVALID_PARAMETER);
3656 return FALSE;
3660 case 0x00001809: /* (Loc,"en_IE") */
3662 switch(dwFlags)
3664 case DATE_SHORTDATE:
3665 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3666 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3667 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3668 return TRUE;
3669 case DATE_LONGDATE:
3670 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3671 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3672 return TRUE;
3673 default:
3674 FIXME("Unknown date format (%ld)\n", dwFlags);
3675 SetLastError(ERROR_INVALID_PARAMETER);
3676 return FALSE;
3680 case 0x00001c09: /* (Loc,"en_ZA") */
3682 switch(dwFlags)
3684 case DATE_SHORTDATE:
3685 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3686 return TRUE;
3687 case DATE_LONGDATE:
3688 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3689 return TRUE;
3690 default:
3691 FIXME("Unknown date format (%ld)\n", dwFlags);
3692 SetLastError(ERROR_INVALID_PARAMETER);
3693 return FALSE;
3697 case 0x00002009: /* (Loc,"en_JM") */
3699 switch(dwFlags)
3701 case DATE_SHORTDATE:
3702 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3703 return TRUE;
3704 case DATE_LONGDATE:
3705 if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
3706 if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
3707 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
3708 if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
3709 return TRUE;
3710 default:
3711 FIXME("Unknown date format (%ld)\n", dwFlags);
3712 SetLastError(ERROR_INVALID_PARAMETER);
3713 return FALSE;
3717 case 0x00002809: /* (Loc,"en_BZ") */
3718 case 0x00002c09: /* (Loc,"en_TT") */
3720 switch(dwFlags)
3722 case DATE_SHORTDATE:
3723 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3724 return TRUE;
3725 case DATE_LONGDATE:
3726 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
3727 return TRUE;
3728 default:
3729 FIXME("Unknown date format (%ld)\n", dwFlags);
3730 SetLastError(ERROR_INVALID_PARAMETER);
3731 return FALSE;
3735 default: /* default to US English "en_US" */
3737 switch(dwFlags)
3739 case DATE_SHORTDATE:
3740 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
3741 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
3742 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
3743 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
3744 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3745 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
3746 return TRUE;
3747 case DATE_LONGDATE:
3748 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
3749 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
3750 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
3751 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
3752 return TRUE;
3753 default:
3754 FIXME("Unknown date format (%ld)\n", dwFlags);
3755 SetLastError(ERROR_INVALID_PARAMETER);
3756 return FALSE;
3762 /**************************************************************************
3763 * EnumDateFormatsW (KERNEL32.199)
3765 BOOL WINAPI EnumDateFormatsW(
3766 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3768 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
3769 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3770 return FALSE;
3773 /**************************************************************************
3774 * EnumTimeFormatsA (KERNEL32.210)
3776 BOOL WINAPI EnumTimeFormatsA(
3777 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3779 LCID Loc = GetUserDefaultLCID();
3780 if(!lpTimeFmtEnumProc)
3782 SetLastError(ERROR_INVALID_PARAMETER);
3783 return FALSE;
3785 if(dwFlags)
3787 FIXME("Unknown time format (%ld)\n", dwFlags);
3790 switch( Loc )
3792 case 0x00000407: /* (Loc,"de_DE") */
3794 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3795 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3796 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3797 if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
3798 if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
3799 return TRUE;
3802 case 0x0000040c: /* (Loc,"fr_FR") */
3803 case 0x00000c0c: /* (Loc,"fr_CA") */
3805 if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
3806 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3807 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3808 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3809 if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
3810 return TRUE;
3813 case 0x00000809: /* (Loc,"en_UK") */
3814 case 0x00000c09: /* (Loc,"en_AU") */
3815 case 0x00001409: /* (Loc,"en_NZ") */
3816 case 0x00001809: /* (Loc,"en_IE") */
3818 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3819 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3820 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3821 return TRUE;
3824 case 0x00001c09: /* (Loc,"en_ZA") */
3825 case 0x00002809: /* (Loc,"en_BZ") */
3826 case 0x00002c09: /* (Loc,"en_TT") */
3828 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3829 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3830 return TRUE;
3833 default: /* default to US style "en_US" */
3835 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3836 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3837 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3838 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3839 return TRUE;
3844 /**************************************************************************
3845 * EnumTimeFormatsW (KERNEL32.211)
3847 BOOL WINAPI EnumTimeFormatsW(
3848 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3850 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
3851 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3852 return FALSE;
3855 /**************************************************************************
3856 * This function is used just locally !
3857 * Description: Inverts a string.
3859 static void OLE_InvertString(char* string)
3861 char sTmpArray[128];
3862 INT counter, i = 0;
3864 for (counter = strlen(string); counter > 0; counter--)
3866 memcpy(sTmpArray + i, string + counter-1, 1);
3867 i++;
3869 memcpy(sTmpArray + i, "\0", 1);
3870 strcpy(string, sTmpArray);
3873 /***************************************************************************************
3874 * This function is used just locally !
3875 * Description: Test if the given string (psNumber) is valid or not.
3876 * The valid characters are the following:
3877 * - Characters '0' through '9'.
3878 * - One decimal point (dot) if the number is a floating-point value.
3879 * - A minus sign in the first character position if the number is
3880 * a negative value.
3881 * If the function succeeds, psBefore/psAfter will point to the string
3882 * on the right/left of the decimal symbol. pbNegative indicates if the
3883 * number is negative.
3885 static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
3887 char sNumberSet[] = "0123456789";
3888 BOOL bInDecimal = FALSE;
3890 /* Test if we do have a minus sign */
3891 if ( *pInput == '-' )
3893 *pbNegative = TRUE;
3894 pInput++; /* Jump to the next character. */
3897 while(*pInput != '\0')
3899 /* Do we have a valid numeric character */
3900 if ( strchr(sNumberSet, *pInput) != NULL )
3902 if (bInDecimal == TRUE)
3903 *psAfter++ = *pInput;
3904 else
3905 *psBefore++ = *pInput;
3907 else
3909 /* Is this a decimal point (dot) */
3910 if ( *pInput == '.' )
3912 /* Is it the first time we find it */
3913 if ((bInDecimal == FALSE))
3914 bInDecimal = TRUE;
3915 else
3916 return -1; /* ERROR: Invalid parameter */
3918 else
3920 /* It's neither a numeric character, nor a decimal point.
3921 * Thus, return an error.
3923 return -1;
3926 pInput++;
3929 /* Add an End of Line character to the output buffers */
3930 *psBefore = '\0';
3931 *psAfter = '\0';
3933 return 0;
3936 /**************************************************************************
3937 * This function is used just locally !
3938 * Description: A number could be formatted using different numbers
3939 * of "digits in group" (example: 4;3;2;0).
3940 * The first parameter of this function is an array
3941 * containing the rule to be used. It's format is the following:
3942 * |NDG|DG1|DG2|...|0|
3943 * where NDG is the number of used "digits in group" and DG1, DG2,
3944 * are the corresponding "digits in group".
3945 * Thus, this function returns the grouping value in the array
3946 * pointed by the second parameter.
3948 static INT OLE_GetGrouping(char* sRule, INT index)
3950 char sData[2], sRuleSize[2];
3951 INT nData, nRuleSize;
3953 memcpy(sRuleSize, sRule, 1);
3954 memcpy(sRuleSize+1, "\0", 1);
3955 nRuleSize = atoi(sRuleSize);
3957 if (index > 0 && index < nRuleSize)
3959 memcpy(sData, sRule+index, 1);
3960 memcpy(sData+1, "\0", 1);
3961 nData = atoi(sData);
3964 else
3966 memcpy(sData, sRule+nRuleSize-1, 1);
3967 memcpy(sData+1, "\0", 1);
3968 nData = atoi(sData);
3971 return nData;
3974 /**************************************************************************
3975 * GetNumberFormatA (KERNEL32.355)
3977 INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
3978 LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
3979 LPSTR lpNumberStr, int cchNumber)
3981 char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
3982 INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
3983 char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
3984 char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
3985 char *pStr = NULL, *pTmpStr = NULL;
3986 LCID systemDefaultLCID;
3987 BOOL bNegative = FALSE;
3988 enum Operations
3990 USE_PARAMETER,
3991 USE_LOCALEINFO,
3992 USE_SYSTEMDEFAULT,
3993 RETURN_ERROR
3994 } used_operation;
3996 strncpy(sNumber, lpvalue, 128);
3997 sNumber[127] = '\0';
3999 /* Make sure we have a valid input string, get the number
4000 * of digits before and after the decimal symbol, and check
4001 * if this is a negative number.
4003 if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
4005 nNumberDecimal = strlen(sDigitsBeforeDecimal);
4006 nDigits = strlen(sDigitsAfterDecimal);
4008 else
4010 SetLastError(ERROR_INVALID_PARAMETER);
4011 return 0;
4014 /* Which source will we use to format the string */
4015 used_operation = RETURN_ERROR;
4016 if (lpFormat != NULL)
4018 if (dwflags == 0)
4019 used_operation = USE_PARAMETER;
4021 else
4023 if (dwflags & LOCALE_NOUSEROVERRIDE)
4024 used_operation = USE_LOCALEINFO;
4025 else
4026 used_operation = USE_SYSTEMDEFAULT;
4029 /* Load the fields we need */
4030 switch(used_operation)
4032 case USE_LOCALEINFO:
4033 GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
4034 GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
4035 GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
4036 GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
4037 GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
4038 GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
4039 break;
4040 case USE_PARAMETER:
4041 sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
4042 strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
4043 sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
4044 strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
4045 sprintf(sILZero, "%d",lpFormat->LeadingZero);
4046 sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
4047 break;
4048 case USE_SYSTEMDEFAULT:
4049 systemDefaultLCID = GetSystemDefaultLCID();
4050 GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
4051 GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
4052 GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
4053 GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
4054 GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
4055 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
4056 break;
4057 default:
4058 SetLastError(ERROR_INVALID_PARAMETER);
4059 return 0;
4062 nNumberDigits = atoi(sNumberDigits);
4064 /* Remove the ";" */
4065 i=0;
4066 j = 1;
4067 for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
4069 if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
4071 memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
4072 i++;
4073 j++;
4076 sprintf(sBuffer, "%d", i);
4077 memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
4078 memcpy(sRule + j, "\0", 1);
4080 /* First, format the digits before the decimal. */
4081 if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
4083 /* Working on an inverted string is easier ! */
4084 OLE_InvertString(sDigitsBeforeDecimal);
4086 nStep = nCounter = i = j = 0;
4087 nRuleIndex = 1;
4088 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
4090 /* Here, we will loop until we reach the end of the string.
4091 * An internal counter (j) is used in order to know when to
4092 * insert the "digit group symbol".
4094 while (nNumberDecimal > 0)
4096 i = nCounter + nStep;
4097 memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
4098 nCounter++;
4099 j++;
4100 if (j >= nGrouping)
4102 j = 0;
4103 if (nRuleIndex < sRule[0])
4104 nRuleIndex++;
4105 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
4106 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
4107 nStep+= strlen(sDigitGroupSymbol);
4110 nNumberDecimal--;
4113 memcpy(sDestination + i+1, "\0", 1);
4114 /* Get the string in the right order ! */
4115 OLE_InvertString(sDestination);
4117 else
4119 nLZ = atoi(sILZero);
4120 if (nLZ != 0)
4122 /* Use 0.xxx instead of .xxx */
4123 memcpy(sDestination, "0", 1);
4124 memcpy(sDestination+1, "\0", 1);
4126 else
4127 memcpy(sDestination, "\0", 1);
4131 /* Second, format the digits after the decimal. */
4132 j = 0;
4133 nCounter = nNumberDigits;
4134 if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
4136 i = strlen(sNumber) - strlen(pStr) + 1;
4137 strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
4138 j = strlen(sDigitsAfterDecimal);
4139 if (j < nNumberDigits)
4140 nCounter = nNumberDigits-j;
4142 for (i=0;i<nCounter;i++)
4143 memcpy(sDigitsAfterDecimal+i+j, "0", 1);
4144 memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
4146 i = strlen(sDestination);
4147 j = strlen(sDigitsAfterDecimal);
4148 /* Finally, construct the resulting formatted string. */
4150 for (nCounter=0; nCounter<i; nCounter++)
4151 memcpy(sNumber + nCounter, sDestination + nCounter, 1);
4153 memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
4155 for (i=0; i<j; i++)
4156 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
4157 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
4159 /* Is it a negative number */
4160 if (bNegative == TRUE)
4162 i = atoi(sNegNumber);
4163 pStr = sDestination;
4164 pTmpStr = sNumber;
4165 switch (i)
4167 case 0:
4168 *pStr++ = '(';
4169 while (*sNumber != '\0')
4170 *pStr++ = *pTmpStr++;
4171 *pStr++ = ')';
4172 break;
4173 case 1:
4174 *pStr++ = '-';
4175 while (*pTmpStr != '\0')
4176 *pStr++ = *pTmpStr++;
4177 break;
4178 case 2:
4179 *pStr++ = '-';
4180 *pStr++ = ' ';
4181 while (*pTmpStr != '\0')
4182 *pStr++ = *pTmpStr++;
4183 break;
4184 case 3:
4185 while (*pTmpStr != '\0')
4186 *pStr++ = *pTmpStr++;
4187 *pStr++ = '-';
4188 break;
4189 case 4:
4190 while (*pTmpStr != '\0')
4191 *pStr++ = *pTmpStr++;
4192 *pStr++ = ' ';
4193 *pStr++ = '-';
4194 break;
4195 default:
4196 while (*pTmpStr != '\0')
4197 *pStr++ = *pTmpStr++;
4198 break;
4201 else
4202 strcpy(sDestination, sNumber);
4204 /* If cchNumber is zero, then returns the number of bytes or characters
4205 * required to hold the formatted number string
4207 if (cchNumber==0)
4208 retVal = strlen(sDestination) + 1;
4209 else
4211 strncpy (lpNumberStr, sDestination, cchNumber-1);
4212 *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
4213 retVal = strlen(lpNumberStr);
4216 return retVal;
4219 /**************************************************************************
4220 * GetNumberFormatW (KERNEL32.xxx)
4222 INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
4223 LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
4224 LPWSTR lpNumberStr, int cchNumber)
4226 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue));
4228 lstrcpynW( lpNumberStr, lpvalue, cchNumber );
4229 return cchNumber? lstrlenW( lpNumberStr ) : 0;
4232 /**************************************************************************
4233 * GetCurrencyFormatA (KERNEL32.302)
4235 INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
4236 LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
4237 LPSTR lpCurrencyStr, int cchCurrency)
4239 UINT nPosOrder, nNegOrder;
4240 INT retVal;
4241 char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
4242 char *pDestination = sDestination;
4243 char sNumberFormated[128];
4244 char *pNumberFormated = sNumberFormated;
4245 LCID systemDefaultLCID;
4246 BOOL bIsPositive = FALSE, bValidFormat = FALSE;
4247 enum Operations
4249 USE_PARAMETER,
4250 USE_LOCALEINFO,
4251 USE_SYSTEMDEFAULT,
4252 RETURN_ERROR
4253 } used_operation;
4255 NUMBERFMTA numberFmt;
4257 /* Which source will we use to format the string */
4258 used_operation = RETURN_ERROR;
4259 if (lpFormat != NULL)
4261 if (dwflags == 0)
4262 used_operation = USE_PARAMETER;
4264 else
4266 if (dwflags & LOCALE_NOUSEROVERRIDE)
4267 used_operation = USE_LOCALEINFO;
4268 else
4269 used_operation = USE_SYSTEMDEFAULT;
4272 /* Load the fields we need */
4273 switch(used_operation)
4275 case USE_LOCALEINFO:
4276 /* Specific to CURRENCYFMTA*/
4277 GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
4278 GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
4279 GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
4281 nPosOrder = atoi(sPosOrder);
4282 nNegOrder = atoi(sNegOrder);
4283 break;
4284 case USE_PARAMETER:
4285 /* Specific to CURRENCYFMTA*/
4286 nNegOrder = lpFormat->NegativeOrder;
4287 nPosOrder = lpFormat->PositiveOrder;
4288 strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
4289 break;
4290 case USE_SYSTEMDEFAULT:
4291 systemDefaultLCID = GetSystemDefaultLCID();
4292 /* Specific to CURRENCYFMTA*/
4293 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
4294 GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
4295 GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
4297 nPosOrder = atoi(sPosOrder);
4298 nNegOrder = atoi(sNegOrder);
4299 break;
4300 default:
4301 SetLastError(ERROR_INVALID_PARAMETER);
4302 return 0;
4305 /* Construct a temporary number format structure */
4306 if (lpFormat != NULL)
4308 numberFmt.NumDigits = lpFormat->NumDigits;
4309 numberFmt.LeadingZero = lpFormat->LeadingZero;
4310 numberFmt.Grouping = lpFormat->Grouping;
4311 numberFmt.NegativeOrder = 0;
4312 numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
4313 numberFmt.lpThousandSep = lpFormat->lpThousandSep;
4314 bValidFormat = TRUE;
4317 /* Make a call to GetNumberFormatA() */
4318 if (*lpvalue == '-')
4320 bIsPositive = FALSE;
4321 retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
4323 else
4325 bIsPositive = TRUE;
4326 retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
4329 if (retVal == 0)
4330 return 0;
4332 /* construct the formatted string */
4333 if (bIsPositive)
4335 switch (nPosOrder)
4337 case 0: /* Prefix, no separation */
4338 strcpy (pDestination, sCurrencySymbol);
4339 strcat (pDestination, pNumberFormated);
4340 break;
4341 case 1: /* Suffix, no separation */
4342 strcpy (pDestination, pNumberFormated);
4343 strcat (pDestination, sCurrencySymbol);
4344 break;
4345 case 2: /* Prefix, 1 char separation */
4346 strcpy (pDestination, sCurrencySymbol);
4347 strcat (pDestination, " ");
4348 strcat (pDestination, pNumberFormated);
4349 break;
4350 case 3: /* Suffix, 1 char separation */
4351 strcpy (pDestination, pNumberFormated);
4352 strcat (pDestination, " ");
4353 strcat (pDestination, sCurrencySymbol);
4354 break;
4355 default:
4356 SetLastError(ERROR_INVALID_PARAMETER);
4357 return 0;
4360 else /* negative number */
4362 switch (nNegOrder)
4364 case 0: /* format: ($1.1) */
4365 strcpy (pDestination, "(");
4366 strcat (pDestination, sCurrencySymbol);
4367 strcat (pDestination, pNumberFormated);
4368 strcat (pDestination, ")");
4369 break;
4370 case 1: /* format: -$1.1 */
4371 strcpy (pDestination, "-");
4372 strcat (pDestination, sCurrencySymbol);
4373 strcat (pDestination, pNumberFormated);
4374 break;
4375 case 2: /* format: $-1.1 */
4376 strcpy (pDestination, sCurrencySymbol);
4377 strcat (pDestination, "-");
4378 strcat (pDestination, pNumberFormated);
4379 break;
4380 case 3: /* format: $1.1- */
4381 strcpy (pDestination, sCurrencySymbol);
4382 strcat (pDestination, pNumberFormated);
4383 strcat (pDestination, "-");
4384 break;
4385 case 4: /* format: (1.1$) */
4386 strcpy (pDestination, "(");
4387 strcat (pDestination, pNumberFormated);
4388 strcat (pDestination, sCurrencySymbol);
4389 strcat (pDestination, ")");
4390 break;
4391 case 5: /* format: -1.1$ */
4392 strcpy (pDestination, "-");
4393 strcat (pDestination, pNumberFormated);
4394 strcat (pDestination, sCurrencySymbol);
4395 break;
4396 case 6: /* format: 1.1-$ */
4397 strcpy (pDestination, pNumberFormated);
4398 strcat (pDestination, "-");
4399 strcat (pDestination, sCurrencySymbol);
4400 break;
4401 case 7: /* format: 1.1$- */
4402 strcpy (pDestination, pNumberFormated);
4403 strcat (pDestination, sCurrencySymbol);
4404 strcat (pDestination, "-");
4405 break;
4406 case 8: /* format: -1.1 $ */
4407 strcpy (pDestination, "-");
4408 strcat (pDestination, pNumberFormated);
4409 strcat (pDestination, " ");
4410 strcat (pDestination, sCurrencySymbol);
4411 break;
4412 case 9: /* format: -$ 1.1 */
4413 strcpy (pDestination, "-");
4414 strcat (pDestination, sCurrencySymbol);
4415 strcat (pDestination, " ");
4416 strcat (pDestination, pNumberFormated);
4417 break;
4418 case 10: /* format: 1.1 $- */
4419 strcpy (pDestination, pNumberFormated);
4420 strcat (pDestination, " ");
4421 strcat (pDestination, sCurrencySymbol);
4422 strcat (pDestination, "-");
4423 break;
4424 case 11: /* format: $ 1.1- */
4425 strcpy (pDestination, sCurrencySymbol);
4426 strcat (pDestination, " ");
4427 strcat (pDestination, pNumberFormated);
4428 strcat (pDestination, "-");
4429 break;
4430 case 12: /* format: $ -1.1 */
4431 strcpy (pDestination, sCurrencySymbol);
4432 strcat (pDestination, " ");
4433 strcat (pDestination, "-");
4434 strcat (pDestination, pNumberFormated);
4435 break;
4436 case 13: /* format: 1.1- $ */
4437 strcpy (pDestination, pNumberFormated);
4438 strcat (pDestination, "-");
4439 strcat (pDestination, " ");
4440 strcat (pDestination, sCurrencySymbol);
4441 break;
4442 case 14: /* format: ($ 1.1) */
4443 strcpy (pDestination, "(");
4444 strcat (pDestination, sCurrencySymbol);
4445 strcat (pDestination, " ");
4446 strcat (pDestination, pNumberFormated);
4447 strcat (pDestination, ")");
4448 break;
4449 case 15: /* format: (1.1 $) */
4450 strcpy (pDestination, "(");
4451 strcat (pDestination, pNumberFormated);
4452 strcat (pDestination, " ");
4453 strcat (pDestination, sCurrencySymbol);
4454 strcat (pDestination, ")");
4455 break;
4456 default:
4457 SetLastError(ERROR_INVALID_PARAMETER);
4458 return 0;
4462 if (cchCurrency == 0)
4463 return strlen(pDestination) + 1;
4465 else
4467 strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
4468 *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
4469 return strlen(lpCurrencyStr);
4473 /**************************************************************************
4474 * GetCurrencyFormatW (KERNEL32.303)
4476 INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
4477 LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
4478 LPWSTR lpCurrencyStr, int cchCurrency)
4480 FIXME("This API function is NOT implemented !\n");
4481 return 0;
4484 /******************************************************************************
4485 * OLE2NLS_CheckLocale [intern]
4487 static LCID OLE2NLS_CheckLocale (LCID locale)
4489 if (!locale)
4490 { locale = LOCALE_SYSTEM_DEFAULT;
4493 if (locale == LOCALE_SYSTEM_DEFAULT)
4494 { return GetSystemDefaultLCID();
4496 else if (locale == LOCALE_USER_DEFAULT)
4497 { return GetUserDefaultLCID();
4499 else
4500 { return locale;
4503 /******************************************************************************
4504 * GetTimeFormatA [KERNEL32.422]
4505 * Makes an ASCII string of the time
4507 * Formats date according to format, or locale default if format is
4508 * NULL. The format consists of literal characters and fields as follows:
4510 * h hours with no leading zero (12-hour)
4511 * hh hours with full two digits
4512 * H hours with no leading zero (24-hour)
4513 * HH hours with full two digits
4514 * m minutes with no leading zero
4515 * mm minutes with full two digits
4516 * s seconds with no leading zero
4517 * ss seconds with full two digits
4518 * t time marker (A or P)
4519 * tt time marker (AM, PM)
4522 INT WINAPI
4523 GetTimeFormatA(LCID locale, /* in */
4524 DWORD flags, /* in */
4525 LPSYSTEMTIME xtime, /* in */
4526 LPCSTR format, /* in */
4527 LPSTR timestr, /* out */
4528 INT timelen /* in */)
4529 { char format_buf[40];
4530 LPCSTR thisformat;
4531 SYSTEMTIME t;
4532 LPSYSTEMTIME thistime;
4533 LCID thislocale=0;
4534 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4535 INT ret;
4537 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
4539 thislocale = OLE2NLS_CheckLocale ( locale );
4541 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
4542 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4545 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
4547 if (format == NULL)
4548 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4549 { thislocale = GetSystemDefaultLCID();
4551 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
4552 thisformat = format_buf;
4554 else
4555 { thisformat = format;
4558 if (xtime == NULL) /* NULL means use the current local time*/
4559 { GetLocalTime(&t);
4560 thistime = &t;
4562 else
4563 { thistime = xtime;
4565 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
4566 timestr, timelen);
4567 return ret;
4571 /******************************************************************************
4572 * GetTimeFormatW [KERNEL32.423]
4573 * Makes a Unicode string of the time
4575 INT WINAPI
4576 GetTimeFormatW(LCID locale, /* in */
4577 DWORD flags, /* in */
4578 LPSYSTEMTIME xtime, /* in */
4579 LPCWSTR format, /* in */
4580 LPWSTR timestr, /* out */
4581 INT timelen /* in */)
4582 { WCHAR format_buf[40];
4583 LPCWSTR thisformat;
4584 SYSTEMTIME t;
4585 LPSYSTEMTIME thistime;
4586 LCID thislocale=0;
4587 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4588 INT ret;
4590 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
4591 xtime,debugstr_w(format),timestr,timelen);
4593 thislocale = OLE2NLS_CheckLocale ( locale );
4595 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
4596 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4599 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
4601 if (format == NULL)
4602 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4603 { thislocale = GetSystemDefaultLCID();
4605 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
4606 thisformat = format_buf;
4608 else
4609 { thisformat = format;
4612 if (xtime == NULL) /* NULL means use the current local time*/
4613 { GetSystemTime(&t);
4614 thistime = &t;
4616 else
4617 { thistime = xtime;
4620 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
4621 timestr, timelen);
4622 return ret;
4625 /******************************************************************************
4626 * EnumCalendarInfoA [KERNEL32.196]
4628 BOOL WINAPI EnumCalendarInfoA(
4629 CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
4631 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);
4632 return FALSE;