Implemented OleCreate.
[wine.git] / ole / ole2nls.c
blobfae0280c862de460af5dda359a21b4f2ae08e84b
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 "wine/unicode.h"
18 #include "heap.h"
19 #include "options.h"
20 #include "winver.h"
21 #include "winnls.h"
22 #include "winreg.h"
23 #include "winerror.h"
24 #include "debugtools.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_CROATIAN, SUBLANG_CROATIAN) /*0x41a*/
244 #include "nls/hrv.nls"
245 LANG_END
247 LANG_BEGIN (LANG_SLOVAK, SUBLANG_DEFAULT) /*0x041b*/
248 #include "nls/sky.nls"
249 LANG_END
251 LANG_BEGIN (LANG_SWEDISH, SUBLANG_SWEDISH) /*0x041d*/
252 #include "nls/sve.nls"
253 LANG_END
254 LANG_BEGIN (LANG_SWEDISH, SUBLANG_SWEDISH_FINLAND) /*0x081d*/
255 #include "nls/svf.nls"
256 LANG_END
258 LANG_BEGIN (LANG_THAI, SUBLANG_DEFAULT) /*0x41e*/
259 #include "nls/tha.nls"
260 LANG_END
261 LANG_BEGIN (LANG_GAELIC, SUBLANG_DEFAULT) /* 0x043c */
262 #include "nls/gae.nls"
263 LANG_END
265 LANG_BEGIN (LANG_GAELIC, SUBLANG_GAELIC_SCOTTISH)
266 #include "nls/gdh.nls"
267 LANG_END
269 LANG_BEGIN (LANG_GAELIC, SUBLANG_GAELIC_MANX)
270 #include "nls/gdv.nls"
271 LANG_END
273 LANG_BEGIN (LANG_ESPERANTO, SUBLANG_DEFAULT) /*0x048f*/
274 #include "nls/esperanto.nls"
275 LANG_END
277 LANG_BEGIN (LANG_WALON, SUBLANG_DEFAULT) /*0x0490*/
278 #include "nls/wal.nls"
279 LANG_END
281 LANG_BEGIN (LANG_CORNISH, SUBLANG_DEFAULT) /* 0x0491 */
282 #include "nls/cor.nls"
283 LANG_END
285 LANG_BEGIN (LANG_WELSH, SUBLANG_DEFAULT) /* 0x0492 */
286 #include "nls/cym.nls"
287 LANG_END
289 LANG_BEGIN (LANG_BRETON, SUBLANG_DEFAULT) /* 0x0x93 */
290 #include "nls/brf.nls"
291 LANG_END
296 /* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
297 * MUST contain all #defines from winnls.h
298 * last entry has NULL name, 0 id.
300 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
301 static const struct tagLOCALE_NAME2ID {
302 const char *name;
303 DWORD id;
304 } locale_name2id[]= {
305 LOCALE_ENTRY(ILANGUAGE),
306 LOCALE_ENTRY(SLANGUAGE),
307 LOCALE_ENTRY(SENGLANGUAGE),
308 LOCALE_ENTRY(SABBREVLANGNAME),
309 LOCALE_ENTRY(SNATIVELANGNAME),
310 LOCALE_ENTRY(ICOUNTRY),
311 LOCALE_ENTRY(SCOUNTRY),
312 LOCALE_ENTRY(SENGCOUNTRY),
313 LOCALE_ENTRY(SABBREVCTRYNAME),
314 LOCALE_ENTRY(SNATIVECTRYNAME),
315 LOCALE_ENTRY(IDEFAULTLANGUAGE),
316 LOCALE_ENTRY(IDEFAULTCOUNTRY),
317 LOCALE_ENTRY(IDEFAULTCODEPAGE),
318 LOCALE_ENTRY(IDEFAULTANSICODEPAGE),
319 LOCALE_ENTRY(IDEFAULTMACCODEPAGE),
320 LOCALE_ENTRY(SLIST),
321 LOCALE_ENTRY(IMEASURE),
322 LOCALE_ENTRY(SDECIMAL),
323 LOCALE_ENTRY(STHOUSAND),
324 LOCALE_ENTRY(SGROUPING),
325 LOCALE_ENTRY(IDIGITS),
326 LOCALE_ENTRY(ILZERO),
327 LOCALE_ENTRY(INEGNUMBER),
328 LOCALE_ENTRY(SNATIVEDIGITS),
329 LOCALE_ENTRY(SCURRENCY),
330 LOCALE_ENTRY(SINTLSYMBOL),
331 LOCALE_ENTRY(SMONDECIMALSEP),
332 LOCALE_ENTRY(SMONTHOUSANDSEP),
333 LOCALE_ENTRY(SMONGROUPING),
334 LOCALE_ENTRY(ICURRDIGITS),
335 LOCALE_ENTRY(IINTLCURRDIGITS),
336 LOCALE_ENTRY(ICURRENCY),
337 LOCALE_ENTRY(INEGCURR),
338 LOCALE_ENTRY(SDATE),
339 LOCALE_ENTRY(STIME),
340 LOCALE_ENTRY(SSHORTDATE),
341 LOCALE_ENTRY(SLONGDATE),
342 LOCALE_ENTRY(STIMEFORMAT),
343 LOCALE_ENTRY(IDATE),
344 LOCALE_ENTRY(ILDATE),
345 LOCALE_ENTRY(ITIME),
346 LOCALE_ENTRY(ITIMEMARKPOSN),
347 LOCALE_ENTRY(ICENTURY),
348 LOCALE_ENTRY(ITLZERO),
349 LOCALE_ENTRY(IDAYLZERO),
350 LOCALE_ENTRY(IMONLZERO),
351 LOCALE_ENTRY(S1159),
352 LOCALE_ENTRY(S2359),
353 LOCALE_ENTRY(ICALENDARTYPE),
354 LOCALE_ENTRY(IOPTIONALCALENDAR),
355 LOCALE_ENTRY(IFIRSTDAYOFWEEK),
356 LOCALE_ENTRY(IFIRSTWEEKOFYEAR),
357 LOCALE_ENTRY(SDAYNAME1),
358 LOCALE_ENTRY(SDAYNAME2),
359 LOCALE_ENTRY(SDAYNAME3),
360 LOCALE_ENTRY(SDAYNAME4),
361 LOCALE_ENTRY(SDAYNAME5),
362 LOCALE_ENTRY(SDAYNAME6),
363 LOCALE_ENTRY(SDAYNAME7),
364 LOCALE_ENTRY(SABBREVDAYNAME1),
365 LOCALE_ENTRY(SABBREVDAYNAME2),
366 LOCALE_ENTRY(SABBREVDAYNAME3),
367 LOCALE_ENTRY(SABBREVDAYNAME4),
368 LOCALE_ENTRY(SABBREVDAYNAME5),
369 LOCALE_ENTRY(SABBREVDAYNAME6),
370 LOCALE_ENTRY(SABBREVDAYNAME7),
371 LOCALE_ENTRY(SMONTHNAME1),
372 LOCALE_ENTRY(SMONTHNAME2),
373 LOCALE_ENTRY(SMONTHNAME3),
374 LOCALE_ENTRY(SMONTHNAME4),
375 LOCALE_ENTRY(SMONTHNAME5),
376 LOCALE_ENTRY(SMONTHNAME6),
377 LOCALE_ENTRY(SMONTHNAME7),
378 LOCALE_ENTRY(SMONTHNAME8),
379 LOCALE_ENTRY(SMONTHNAME9),
380 LOCALE_ENTRY(SMONTHNAME10),
381 LOCALE_ENTRY(SMONTHNAME11),
382 LOCALE_ENTRY(SMONTHNAME12),
383 LOCALE_ENTRY(SMONTHNAME13),
384 LOCALE_ENTRY(SABBREVMONTHNAME1),
385 LOCALE_ENTRY(SABBREVMONTHNAME2),
386 LOCALE_ENTRY(SABBREVMONTHNAME3),
387 LOCALE_ENTRY(SABBREVMONTHNAME4),
388 LOCALE_ENTRY(SABBREVMONTHNAME5),
389 LOCALE_ENTRY(SABBREVMONTHNAME6),
390 LOCALE_ENTRY(SABBREVMONTHNAME7),
391 LOCALE_ENTRY(SABBREVMONTHNAME8),
392 LOCALE_ENTRY(SABBREVMONTHNAME9),
393 LOCALE_ENTRY(SABBREVMONTHNAME10),
394 LOCALE_ENTRY(SABBREVMONTHNAME11),
395 LOCALE_ENTRY(SABBREVMONTHNAME12),
396 LOCALE_ENTRY(SABBREVMONTHNAME13),
397 LOCALE_ENTRY(SPOSITIVESIGN),
398 LOCALE_ENTRY(SNEGATIVESIGN),
399 LOCALE_ENTRY(IPOSSIGNPOSN),
400 LOCALE_ENTRY(INEGSIGNPOSN),
401 LOCALE_ENTRY(IPOSSYMPRECEDES),
402 LOCALE_ENTRY(IPOSSEPBYSPACE),
403 LOCALE_ENTRY(INEGSYMPRECEDES),
404 LOCALE_ENTRY(INEGSEPBYSPACE),
405 LOCALE_ENTRY(FONTSIGNATURE),
406 LOCALE_ENTRY(SISO639LANGNAME),
407 LOCALE_ENTRY(SISO3166CTRYNAME),
408 {NULL,0},
411 const struct map_lcid2str {
412 LCID langid;
413 const char *langname;
414 } languages[]={
415 {0x0401,"Arabic (Saudi Arabia)"},
416 {0x0801,"Arabic (Iraq)"},
417 {0x0c01,"Arabic (Egypt)"},
418 {0x1001,"Arabic (Libya)"},
419 {0x1401,"Arabic (Algeria)"},
420 {0x1801,"Arabic (Morocco)"},
421 {0x1c01,"Arabic (Tunisia)"},
422 {0x2001,"Arabic (Oman)"},
423 {0x2401,"Arabic (Yemen)"},
424 {0x2801,"Arabic (Syria)"},
425 {0x2c01,"Arabic (Jordan)"},
426 {0x3001,"Arabic (Lebanon)"},
427 {0x3401,"Arabic (Kuwait)"},
428 {0x3801,"Arabic (United Arab Emirates)"},
429 {0x3c01,"Arabic (Bahrain)"},
430 {0x4001,"Arabic (Qatar)"},
431 {0x0402,"Bulgarian"},
432 {0x0403,"Catalan"},
433 {0x0404,"Chinese (Taiwan)"},
434 {0x0804,"Chinese (People's Republic of China)"},
435 {0x0c04,"Chinese (Hong Kong)"},
436 {0x1004,"Chinese (Singapore)"},
437 {0x1404,"Chinese (Macau)"},
438 {0x0405,"Czech"},
439 {0x0406,"Danish"},
440 {0x0407,"German (Germany)"},
441 {0x0807,"German (Switzerland)"},
442 {0x0c07,"German (Austria)"},
443 {0x1007,"German (Luxembourg)"},
444 {0x1407,"German (Liechtenstein)"},
445 {0x0408,"Greek"},
446 {0x0409,"English (United States)"},
447 {0x0809,"English (United Kingdom)"},
448 {0x0c09,"English (Australian)"},
449 {0x1009,"English (Canadian)"},
450 {0x1409,"English (New Zealand)"},
451 {0x1809,"English (Ireland)"},
452 {0x1c09,"English (South Africa)"},
453 {0x2009,"English (Jamaica)"},
454 {0x2409,"English (Caribbean)"},
455 {0x2809,"English (Belize)"},
456 {0x2c09,"English (Trinidad & Tobago)"},
457 {0x3009,"English (Zimbabwe)"},
458 {0x3409,"English (Philippines)"},
459 {0x040a,"Spanish (Spain, traditional sorting)"},
460 {0x080a,"Spanish (Mexico)"},
461 {0x0c0a,"Spanish (Spain, international sorting)"},
462 {0x100a,"Spanish (Guatemala)"},
463 {0x140a,"Spanish (Costa Rica)"},
464 {0x180a,"Spanish (Panama)"},
465 {0x1c0a,"Spanish (Dominican Republic)"},
466 {0x200a,"Spanish (Venezuela)"},
467 {0x240a,"Spanish (Colombia)"},
468 {0x280a,"Spanish (Peru)"},
469 {0x2c0a,"Spanish (Argentina)"},
470 {0x300a,"Spanish (Ecuador)"},
471 {0x340a,"Spanish (Chile)"},
472 {0x380a,"Spanish (Uruguay)"},
473 {0x3c0a,"Spanish (Paraguay)"},
474 {0x400a,"Spanish (Bolivia)"},
475 {0x440a,"Spanish (El Salvador)"},
476 {0x480a,"Spanish (Honduras)"},
477 {0x4c0a,"Spanish (Nicaragua)"},
478 {0x500a,"Spanish (Puerto Rico)"},
479 {0x040b,"Finnish"},
480 {0x040c,"French (France)"},
481 {0x080c,"French (Belgium)"},
482 {0x0c0c,"French (Canada)"},
483 {0x100c,"French (Switzerland)"},
484 {0x140c,"French (Luxembourg)"},
485 {0x180c,"French (Monaco)"},
486 {0x040d,"Hebrew"},
487 {0x040e,"Hungarian"},
488 {0x040f,"Icelandic"},
489 {0x0410,"Italian (Italy)"},
490 {0x0810,"Italian (Switzerland)"},
491 {0x0411,"Japanese"},
492 {0x0412,"Korean (Wansung)"},
493 {0x0812,"Korean (Johab)"},
494 {0x0413,"Dutch (Netherlands)"},
495 {0x0813,"Dutch (Belgium)"},
496 {0x0414,"Norwegian (Bokmal)"},
497 {0x0814,"Norwegian (Nynorsk)"},
498 {0x0415,"Polish"},
499 {0x0416,"Portuguese (Brazil)"},
500 {0x0816,"Portuguese (Portugal)"},
501 {0x0417,"Rhaeto Romanic"},
502 {0x0418,"Romanian"},
503 {0x0818,"Moldavian"},
504 {0x0419,"Russian (Russia)"},
505 {0x0819,"Russian (Moldavia)"},
506 {0x041a,"Croatian"},
507 {0x081a,"Serbian (latin)"},
508 {0x0c1a,"Serbian (cyrillic)"},
509 {0x041b,"Slovak"},
510 {0x041c,"Albanian"},
511 {0x041d,"Swedish (Sweden)"},
512 {0x081d,"Swedish (Finland)"},
513 {0x041e,"Thai"},
514 {0x041f,"Turkish"},
515 {0x0420,"Urdu"},
516 {0x0421,"Indonesian"},
517 {0x0422,"Ukrainian"},
518 {0x0423,"Belarusian"},
519 {0x0424,"Slovene"},
520 {0x0425,"Estonian"},
521 {0x0426,"Latvian"},
522 {0x0427,"Lithuanian (modern)"},
523 {0x0827,"Lithuanian (classic)"},
524 {0x0428,"Maori"},
525 {0x0429,"Farsi"},
526 {0x042a,"Vietnamese"},
527 {0x042b,"Armenian"},
528 {0x042c,"Azeri (latin)"},
529 {0x082c,"Azeri (cyrillic)"},
530 {0x042d,"Basque"},
531 {0x042e,"Sorbian"},
532 {0x042f,"Macedonian"},
533 {0x0430,"Sutu"},
534 {0x0431,"Tsonga"},
535 {0x0432,"Tswana"},
536 {0x0433,"Venda"},
537 {0x0434,"Xhosa"},
538 {0x0435,"Zulu"},
539 {0x0436,"Afrikaans"},
540 {0x0437,"Georgian"},
541 {0x0438,"Faeroese"},
542 {0x0439,"Hindi"},
543 {0x043a,"Maltese"},
544 {0x043b,"Saami"},
545 {0x043c,"Irish gaelic"},
546 {0x083c,"Scottish gaelic"},
547 {0x0c3c,"Manx Gaelic"},
548 {0x043e,"Malay (Malaysia)"},
549 {0x083e,"Malay (Brunei Darussalam)"},
550 {0x043f,"Kazak"},
551 {0x0441,"Swahili"},
552 {0x0443,"Uzbek (latin)"},
553 {0x0843,"Uzbek (cyrillic)"},
554 {0x0444,"Tatar"},
555 {0x0445,"Bengali"},
556 {0x0446,"Punjabi"},
557 {0x0447,"Gujarati"},
558 {0x0448,"Oriya"},
559 {0x0449,"Tamil"},
560 {0x044a,"Telugu"},
561 {0x044b,"Kannada"},
562 {0x044c,"Malayalam"},
563 {0x044d,"Assamese"},
564 {0x044e,"Marathi"},
565 {0x044f,"Sanskrit"},
566 {0x0457,"Konkani"},
567 {0x048f,"Esperanto"}, /* Non official */
568 {0x0490,"Walon"}, /* Non official */
569 {0x0491,"Cornish"}, /* Not official */
570 {0x0492,"Welsh"}, /* Not official */
571 {0x0493,"Breton"}, /* Not official */
572 {0x0000,"Unknown"}
573 }, languages_de[]={
574 {0x0401,"Arabic"},
575 {0x0402,"Bulgarisch"},
576 {0x0403,"Katalanisch"},
577 {0x0404,"Traditionales Chinesisch"},
578 {0x0405,"Tschecisch"},
579 {0x0406,"Dänisch"},
580 {0x0407,"Deutsch"},
581 {0x0408,"Griechisch"},
582 {0x0409,"Amerikanisches Englisch"},
583 {0x040A,"Kastilisches Spanisch"},
584 {0x040B,"Finnisch"},
585 {0x040C,"Franzvsisch"},
586 {0x040D,"Hebrdisch"},
587 {0x040E,"Ungarisch"},
588 {0x040F,"Isldndisch"},
589 {0x0410,"Italienisch"},
590 {0x0411,"Japanisch"},
591 {0x0412,"Koreanisch"},
592 {0x0413,"Niederldndisch"},
593 {0x0414,"Norwegisch-Bokmal"},
594 {0x0415,"Polnisch"},
595 {0x0416,"Brasilianisches Portugiesisch"},
596 {0x0417,"Rdtoromanisch"},
597 {0x0418,"Rumdnisch"},
598 {0x0419,"Russisch"},
599 {0x041A,"Kroatoserbisch (lateinisch)"},
600 {0x041B,"Slowenisch"},
601 {0x041C,"Albanisch"},
602 {0x041D,"Schwedisch"},
603 {0x041E,"Thai"},
604 {0x041F,"Türkisch"},
605 {0x0420,"Urdu"},
606 {0x0421,"Bahasa"},
607 {0x0804,"Vereinfachtes Chinesisch"},
608 {0x0807,"Schweizerdeutsch"},
609 {0x0809,"Britisches Englisch"},
610 {0x080A,"Mexikanisches Spanisch"},
611 {0x080C,"Belgisches Franzvsisch"},
612 {0x0810,"Schweizerisches Italienisch"},
613 {0x0813,"Belgisches Niederldndisch"},
614 {0x0814,"Norgwegisch-Nynorsk"},
615 {0x0816,"Portugiesisch"},
616 {0x081A,"Serbokratisch (kyrillisch)"},
617 {0x0C1C,"Kanadisches Franzvsisch"},
618 {0x100C,"Schweizerisches Franzvsisch"},
619 {0x0000,"Unbekannt"},
622 static char *GetLocaleSubkeyName( DWORD lctype );
624 /***********************************************************************
625 * GetUserDefaultLCID [KERNEL32.425] [OLE2NLS.1]
627 LCID WINAPI GetUserDefaultLCID()
629 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT );
632 /***********************************************************************
633 * GetSystemDefaultLCID [KERNEL32.400] [OLE2NLS.2]
635 LCID WINAPI GetSystemDefaultLCID()
637 return GetUserDefaultLCID();
640 /***********************************************************************
641 * GetUserDefaultLangID [KERNEL32.426] [OLE2NLS.3]
643 LANGID WINAPI GetUserDefaultLangID()
645 /* caching result, if defined from environment, which should (?) not change during a WINE session */
646 static LANGID userLCID = 0;
647 if (Options.language) {
648 return Languages[Options.language].langid;
651 if (userLCID == 0) {
652 char *buf=NULL;
653 char *lang,*country,*charset,*dialect,*next;
654 int ret=0;
656 buf=getenv("LANGUAGE");
657 if (!buf) buf=getenv("LANG");
658 if (!buf) buf=getenv("LC_ALL");
659 if (!buf) buf=getenv("LC_MESSAGES");
660 if (!buf) buf=getenv("LC_CTYPE");
661 if (!buf) return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
663 if (!strcmp(buf,"POSIX") || !strcmp(buf,"C")) {
664 return MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
667 lang=buf;
669 do {
670 next=strchr(lang,':'); if (next) *next++='\0';
671 dialect=strchr(lang,'@'); if (dialect) *dialect++='\0';
672 charset=strchr(lang,'.'); if (charset) *charset++='\0';
673 country=strchr(lang,'_'); if (country) *country++='\0';
675 ret=MAIN_GetLanguageID(lang, country, charset, dialect);
677 lang=next;
679 } while (lang && !ret);
681 /* FIXME : are strings returned by getenv() to be free()'ed ? */
682 userLCID = (LANGID)ret;
684 return userLCID;
687 /***********************************************************************
688 * GetSystemDefaultLangID [KERNEL32.401] [OLE2NLS.4]
690 LANGID WINAPI GetSystemDefaultLangID()
692 return GetUserDefaultLangID();
695 /******************************************************************************
696 * ConvertDefaultLocale32 [KERNEL32.147]
698 LCID WINAPI ConvertDefaultLocale32 (LCID lcid)
699 { switch (lcid)
700 { case LOCALE_SYSTEM_DEFAULT:
701 return GetSystemDefaultLCID();
702 case LOCALE_USER_DEFAULT:
703 return GetUserDefaultLCID();
704 case 0:
705 return MAKELCID (LANG_NEUTRAL, SUBLANG_NEUTRAL);
707 return MAKELANGID( PRIMARYLANGID(lcid), SUBLANG_NEUTRAL);
709 /******************************************************************************
710 * GetLocaleInfoA [KERNEL32.342]
712 * NOTES
713 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
715 * MS online documentation states that the string returned is NULL terminated
716 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
717 * terminated string".
719 INT WINAPI GetLocaleInfoA(LCID lcid,LCTYPE LCType,LPSTR buf,INT len)
721 LPCSTR retString;
722 int found,i;
723 int lang=0;
724 char *pacKey;
725 char acBuffer[128];
726 DWORD dwBufferSize=128;
728 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid,LCType,buf,len);
730 if (len && (! buf) ) {
731 SetLastError(ERROR_INSUFFICIENT_BUFFER);
732 return 0;
735 if (lcid ==0 || lcid == LANG_SYSTEM_DEFAULT || (LCType & LOCALE_NOUSEROVERRIDE) ) /* 0x00, 0x400 */
737 lcid = GetSystemDefaultLCID();
739 else if (lcid == LANG_USER_DEFAULT) /*0x800*/
741 lcid = GetUserDefaultLCID();
743 LCType &= ~(LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP);
745 /* As an option, we could obtain the value from win.ini.
746 This would not match the Wine compile-time option.
747 Also, not all identifiers are available from win.ini */
748 retString=0;
749 /* If we are through all of this, retLen should not be zero anymore.
750 If it is, the value is not supported */
751 i=0;
752 while (locale_name2id[i].name!=NULL) {
753 if (LCType == locale_name2id[i].id) {
754 retString = locale_name2id[i].name;
755 break;
757 i++;
759 if (!retString) {
760 FIXME("Unkown LC type %lX\n",LCType);
761 return 0;
764 found=0;
766 /* First, check if it's in the registry. */
768 if ( (pacKey = GetLocaleSubkeyName(LCType)) )
770 char acRealKey[128];
771 HKEY hKey;
773 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
775 if ( RegOpenKeyExA( HKEY_CURRENT_USER, acRealKey,
776 0, KEY_READ, &hKey) == ERROR_SUCCESS )
778 if ( RegQueryValueExA( hKey, NULL, NULL, NULL, (LPBYTE)acBuffer,
779 &dwBufferSize ) == ERROR_SUCCESS )
781 retString = acBuffer;
782 found = 1;
784 RegCloseKey(hKey);
788 /* If not in the registry, get it from the NLS entries. */
790 lang=lcid;
791 for (i=0;(i<3 && !found);i++) {
792 int j;
794 for (j=0;j<sizeof(langlocales)/sizeof(langlocales[0]);j++) {
795 if (langlocales[j].lang == lang) {
796 int k;
798 for (k=0;k<sizeof(langlocales[j].locvars)/sizeof(langlocales[j].locvars[0]) && (langlocales[j].locvars[k].type);k++) {
799 if (langlocales[j].locvars[k].type == LCType) {
800 found = 1;
801 retString = langlocales[j].locvars[k].val;
802 break;
805 if (found)
806 break;
809 /* language not found, try without a sublanguage*/
810 if (i==1) lang=MAKELANGID( PRIMARYLANGID(lang), SUBLANG_DEFAULT);
811 /* mask the LC Value */
812 if (i==2) LCType &= 0xfff;
815 if(!found) {
816 ERR("'%s' not supported for your language (%04X).\n",
817 retString,(WORD)lcid);
818 SetLastError(ERROR_INVALID_PARAMETER);
819 return 0;
821 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
822 if (LCType == LOCALE_FONTSIGNATURE) {
823 if (len)
824 memcpy(buf, retString, (len<=sizeof(FONTSIGNATURE))?len:sizeof(FONTSIGNATURE));
825 return sizeof(FONTSIGNATURE);
827 /* if len=0 return only the length, don't touch the buffer*/
828 if (len) lstrcpynA(buf,retString,len);
829 return strlen(retString)+1;
832 /******************************************************************************
833 * GetLocaleInfoW [KERNEL32.343]
835 * NOTES
836 * MS documentation states that len "specifies the size, in bytes (ANSI version)
837 * or characters (Unicode version), of" wbuf. Thus the number returned is
838 * the same between GetLocaleInfoW and GetLocaleInfoA.
840 INT WINAPI GetLocaleInfoW(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT len)
841 { WORD wlen;
842 LPSTR abuf;
844 if (len && (! wbuf) )
845 { SetLastError(ERROR_INSUFFICIENT_BUFFER);
846 return 0;
849 abuf = (LPSTR)HeapAlloc(GetProcessHeap(),0,len);
850 wlen = GetLocaleInfoA(lcid, LCType, abuf, len);
852 if (wlen && len) /* if len=0 return only the length*/
853 lstrcpynAtoW(wbuf,abuf,len);
855 HeapFree(GetProcessHeap(),0,abuf);
856 return wlen;
859 /******************************************************************************
861 * GetLocaleSubkeyName [helper function]
863 * - For use with the registry.
864 * - Gets the registry subkey name for a given lctype.
866 static char *GetLocaleSubkeyName( DWORD lctype )
868 char *pacKey=NULL;
870 switch ( lctype )
872 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
873 * the values are stored in the registry, confirmed under Windows,
874 * for the ones that actually assign pacKey. Cases that aren't finished
875 * have not been confirmed, so that must be done before they can be
876 * added.
878 case LOCALE_SDATE : /* The date separator. */
879 pacKey = "sDate";
880 break;
881 case LOCALE_ICURRDIGITS:
882 pacKey = "iCurrDigits";
883 break;
884 case LOCALE_SDECIMAL :
885 pacKey = "sDecimal";
886 break;
887 case LOCALE_ICURRENCY:
888 pacKey = "iCurrency";
889 break;
890 case LOCALE_SGROUPING :
891 pacKey = "sGrouping";
892 break;
893 case LOCALE_IDIGITS:
894 pacKey = "iDigits";
895 break;
896 case LOCALE_SLIST :
897 pacKey = "sList";
898 break;
899 /* case LOCALE_ICALENDARTYPE: */
900 /* case LOCALE_IFIRSTDAYOFWEEK: */
901 /* case LOCALE_IFIRSTWEEKOFYEAR: */
902 /* case LOCALE_SYEARMONTH : */
903 /* case LOCALE_SPOSITIVESIGN : */
904 /* case LOCALE_IPAPERSIZE: */
905 /* break; */
906 case LOCALE_SLONGDATE :
907 pacKey = "sLongDate";
908 break;
909 case LOCALE_SMONDECIMALSEP :
910 pacKey = "sMonDecimalSep";
911 break;
912 case LOCALE_SMONGROUPING:
913 pacKey = "sMonGrouping";
914 break;
915 case LOCALE_IMEASURE:
916 pacKey = "iMeasure";
917 break;
918 case LOCALE_SMONTHOUSANDSEP :
919 pacKey = "sMonThousandSep";
920 break;
921 case LOCALE_INEGCURR:
922 pacKey = "iNegCurr";
923 break;
924 case LOCALE_SNEGATIVESIGN :
925 pacKey = "sNegativeSign";
926 break;
927 case LOCALE_INEGNUMBER:
928 pacKey = "iNegNumber";
929 break;
930 case LOCALE_SSHORTDATE :
931 pacKey = "sShortDate";
932 break;
933 case LOCALE_ILDATE: /* Long Date format ordering specifier. */
934 pacKey = "iLDate";
935 break;
936 case LOCALE_ILZERO:
937 pacKey = "iLZero";
938 break;
939 case LOCALE_ITLZERO:
940 pacKey = "iTLZero";
941 break;
942 case LOCALE_ITIME: /* Time format specifier. */
943 pacKey = "iTime";
944 break;
945 case LOCALE_STHOUSAND :
946 pacKey = "sThousand";
947 break;
948 case LOCALE_S1159: /* AM */
949 pacKey = "s1159";
950 break;
951 case LOCALE_STIME:
952 pacKey = "sTime";
953 break;
954 case LOCALE_S2359: /* PM */
955 pacKey = "s2359";
956 break;
957 case LOCALE_STIMEFORMAT :
958 pacKey = "sTimeFormat";
959 break;
960 case LOCALE_SCURRENCY:
961 pacKey = "sCurrency";
962 break;
964 /* The following are not listed under MSDN as supported,
965 * but seem to be used and also stored in the registry.
968 case LOCALE_IDATE:
969 pacKey = "iDate";
970 break;
971 case LOCALE_SCOUNTRY:
972 pacKey = "sCountry";
973 break;
974 case LOCALE_ICOUNTRY:
975 pacKey = "iCountry";
976 break;
977 case LOCALE_SLANGUAGE:
978 pacKey = "sLanguage";
979 break;
981 default:
982 break;
985 return( pacKey );
988 /******************************************************************************
989 * SetLocaleInfoA [KERNEL32.656]
991 BOOL16 WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
993 HKEY hKey;
994 char *pacKey;
995 char acRealKey[128];
997 if ( (pacKey = GetLocaleSubkeyName(lctype)) )
999 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
1000 if ( RegCreateKeyA( HKEY_CURRENT_USER, acRealKey,
1001 &hKey ) == ERROR_SUCCESS )
1003 if ( RegSetValueExA( hKey, NULL, 0, REG_SZ,
1004 data, strlen(data)+1 ) != ERROR_SUCCESS )
1006 ERR("SetLocaleInfoA: %s did not work\n", pacKey );
1008 RegCloseKey( hKey );
1011 else
1013 FIXME("(%ld,%ld,%s): stub\n",lcid,lctype,data);
1015 return TRUE;
1018 /******************************************************************************
1019 * IsValidLocale [KERNEL32.489]
1021 BOOL WINAPI IsValidLocale(LCID lcid,DWORD flags)
1023 /* we support ANY language. Well, at least say that...*/
1024 return TRUE;
1027 /******************************************************************************
1028 * EnumSystemLocalesW [KERNEL32.209]
1030 BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum,
1031 DWORD flags )
1033 int i;
1034 BOOL ret;
1035 WCHAR buffer[200];
1036 HKEY xhkey;
1038 TRACE_(win32)("(%p,%08lx)\n",lpfnLocaleEnum,flags );
1039 /* see if we can reuse the Win95 registry entries.... */
1040 if (ERROR_SUCCESS==RegOpenKeyA(HKEY_LOCAL_MACHINE,"System\\CurrentControlSet\\control\\Nls\\Locale\\",&xhkey)) {
1041 i=0;
1042 while (1) {
1043 if (ERROR_SUCCESS!=RegEnumKeyW(xhkey,i,buffer,sizeof(buffer)))
1044 break;
1045 if (!lpfnLocaleEnum(buffer))
1046 break;
1047 i++;
1049 RegCloseKey(xhkey);
1050 return TRUE;
1053 i=0;
1054 while (languages[i].langid!=0)
1056 LPWSTR cp;
1057 char xbuffer[10];
1059 sprintf(xbuffer,"%08lx",(DWORD)languages[i].langid);
1061 cp = HEAP_strdupAtoW( GetProcessHeap(), 0, xbuffer );
1062 ret = lpfnLocaleEnum(cp);
1063 HeapFree( GetProcessHeap(), 0, cp );
1064 if (!ret) break;
1065 i++;
1067 return TRUE;
1070 /******************************************************************************
1071 * EnumSystemLocalesA [KERNEL32.208]
1073 BOOL WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum,
1074 DWORD flags)
1076 int i;
1077 CHAR buffer[200];
1078 HKEY xhkey;
1080 TRACE_(win32)("(%p,%08lx)\n",
1081 lpfnLocaleEnum,flags
1084 if ( ERROR_SUCCESS==RegOpenKeyA(HKEY_LOCAL_MACHINE,
1085 "System\\CurrentControlSet\\Control\\Nls\\Locale\\",
1086 &xhkey)) {
1087 i=0;
1088 while (1) {
1089 DWORD size=sizeof(buffer);
1090 if (ERROR_SUCCESS!=RegEnumValueA(xhkey,i,buffer,&size,NULL,
1091 NULL, NULL,NULL))
1092 break;
1093 if (size && !lpfnLocaleEnum(buffer))
1094 break;
1095 i++;
1097 RegCloseKey(xhkey);
1098 return TRUE;
1100 i=0;
1101 while (languages[i].langid!=0) {
1102 sprintf(buffer,"%08lx",(DWORD)languages[i].langid);
1103 if (!lpfnLocaleEnum(buffer))
1104 break;
1105 i++;
1107 return TRUE;
1110 static const unsigned char CT_CType2_LUT[] = {
1111 C2_NOTAPPLICABLE, /* - 0 */
1112 C2_NOTAPPLICABLE, /* - 1 */
1113 C2_NOTAPPLICABLE, /* - 2 */
1114 C2_NOTAPPLICABLE, /* - 3 */
1115 C2_NOTAPPLICABLE, /* - 4 */
1116 C2_NOTAPPLICABLE, /* - 5 */
1117 C2_NOTAPPLICABLE, /* - 6 */
1118 C2_NOTAPPLICABLE, /* - 7 */
1119 C2_NOTAPPLICABLE, /* - 8 */
1120 C2_SEGMENTSEPARATOR, /* - 9 */
1121 C2_NOTAPPLICABLE, /* - 10 */
1122 C2_NOTAPPLICABLE, /* - 11 */
1123 C2_NOTAPPLICABLE, /* - 12 */
1124 C2_NOTAPPLICABLE, /* - 13 */
1125 C2_NOTAPPLICABLE, /* - 14 */
1126 C2_NOTAPPLICABLE, /* - 15 */
1127 C2_NOTAPPLICABLE, /* - 16 */
1128 C2_NOTAPPLICABLE, /* - 17 */
1129 C2_NOTAPPLICABLE, /* - 18 */
1130 C2_NOTAPPLICABLE, /* - 19 */
1131 C2_NOTAPPLICABLE, /* - 20 */
1132 C2_NOTAPPLICABLE, /* - 21 */
1133 C2_NOTAPPLICABLE, /* - 22 */
1134 C2_NOTAPPLICABLE, /* - 23 */
1135 C2_NOTAPPLICABLE, /* - 24 */
1136 C2_NOTAPPLICABLE, /* - 25 */
1137 C2_NOTAPPLICABLE, /* - 26 */
1138 C2_NOTAPPLICABLE, /* - 27 */
1139 C2_NOTAPPLICABLE, /* - 28 */
1140 C2_NOTAPPLICABLE, /* - 29 */
1141 C2_NOTAPPLICABLE, /* - 30 */
1142 C2_NOTAPPLICABLE, /* - 31 */
1143 C2_WHITESPACE, /* - 32 */
1144 C2_OTHERNEUTRAL, /* ! - 33 */
1145 C2_OTHERNEUTRAL, /* " - 34 */ /* " */
1146 C2_EUROPETERMINATOR, /* # - 35 */
1147 C2_EUROPETERMINATOR, /* $ - 36 */
1148 C2_EUROPETERMINATOR, /* % - 37 */
1149 C2_LEFTTORIGHT, /* & - 38 */
1150 C2_OTHERNEUTRAL, /* ' - 39 */
1151 C2_OTHERNEUTRAL, /* ( - 40 */
1152 C2_OTHERNEUTRAL, /* ) - 41 */
1153 C2_OTHERNEUTRAL, /* * - 42 */
1154 C2_EUROPETERMINATOR, /* + - 43 */
1155 C2_COMMONSEPARATOR, /* , - 44 */
1156 C2_EUROPETERMINATOR, /* - - 45 */
1157 C2_EUROPESEPARATOR, /* . - 46 */
1158 C2_EUROPESEPARATOR, /* / - 47 */
1159 C2_EUROPENUMBER, /* 0 - 48 */
1160 C2_EUROPENUMBER, /* 1 - 49 */
1161 C2_EUROPENUMBER, /* 2 - 50 */
1162 C2_EUROPENUMBER, /* 3 - 51 */
1163 C2_EUROPENUMBER, /* 4 - 52 */
1164 C2_EUROPENUMBER, /* 5 - 53 */
1165 C2_EUROPENUMBER, /* 6 - 54 */
1166 C2_EUROPENUMBER, /* 7 - 55 */
1167 C2_EUROPENUMBER, /* 8 - 56 */
1168 C2_EUROPENUMBER, /* 9 - 57 */
1169 C2_COMMONSEPARATOR, /* : - 58 */
1170 C2_OTHERNEUTRAL, /* ; - 59 */
1171 C2_OTHERNEUTRAL, /* < - 60 */
1172 C2_OTHERNEUTRAL, /* = - 61 */
1173 C2_OTHERNEUTRAL, /* > - 62 */
1174 C2_OTHERNEUTRAL, /* ? - 63 */
1175 C2_LEFTTORIGHT, /* @ - 64 */
1176 C2_LEFTTORIGHT, /* A - 65 */
1177 C2_LEFTTORIGHT, /* B - 66 */
1178 C2_LEFTTORIGHT, /* C - 67 */
1179 C2_LEFTTORIGHT, /* D - 68 */
1180 C2_LEFTTORIGHT, /* E - 69 */
1181 C2_LEFTTORIGHT, /* F - 70 */
1182 C2_LEFTTORIGHT, /* G - 71 */
1183 C2_LEFTTORIGHT, /* H - 72 */
1184 C2_LEFTTORIGHT, /* I - 73 */
1185 C2_LEFTTORIGHT, /* J - 74 */
1186 C2_LEFTTORIGHT, /* K - 75 */
1187 C2_LEFTTORIGHT, /* L - 76 */
1188 C2_LEFTTORIGHT, /* M - 77 */
1189 C2_LEFTTORIGHT, /* N - 78 */
1190 C2_LEFTTORIGHT, /* O - 79 */
1191 C2_LEFTTORIGHT, /* P - 80 */
1192 C2_LEFTTORIGHT, /* Q - 81 */
1193 C2_LEFTTORIGHT, /* R - 82 */
1194 C2_LEFTTORIGHT, /* S - 83 */
1195 C2_LEFTTORIGHT, /* T - 84 */
1196 C2_LEFTTORIGHT, /* U - 85 */
1197 C2_LEFTTORIGHT, /* V - 86 */
1198 C2_LEFTTORIGHT, /* W - 87 */
1199 C2_LEFTTORIGHT, /* X - 88 */
1200 C2_LEFTTORIGHT, /* Y - 89 */
1201 C2_LEFTTORIGHT, /* Z - 90 */
1202 C2_OTHERNEUTRAL, /* [ - 91 */
1203 C2_OTHERNEUTRAL, /* \ - 92 */
1204 C2_OTHERNEUTRAL, /* ] - 93 */
1205 C2_OTHERNEUTRAL, /* ^ - 94 */
1206 C2_OTHERNEUTRAL, /* _ - 95 */
1207 C2_OTHERNEUTRAL, /* ` - 96 */
1208 C2_LEFTTORIGHT, /* a - 97 */
1209 C2_LEFTTORIGHT, /* b - 98 */
1210 C2_LEFTTORIGHT, /* c - 99 */
1211 C2_LEFTTORIGHT, /* d - 100 */
1212 C2_LEFTTORIGHT, /* e - 101 */
1213 C2_LEFTTORIGHT, /* f - 102 */
1214 C2_LEFTTORIGHT, /* g - 103 */
1215 C2_LEFTTORIGHT, /* h - 104 */
1216 C2_LEFTTORIGHT, /* i - 105 */
1217 C2_LEFTTORIGHT, /* j - 106 */
1218 C2_LEFTTORIGHT, /* k - 107 */
1219 C2_LEFTTORIGHT, /* l - 108 */
1220 C2_LEFTTORIGHT, /* m - 109 */
1221 C2_LEFTTORIGHT, /* n - 110 */
1222 C2_LEFTTORIGHT, /* o - 111 */
1223 C2_LEFTTORIGHT, /* p - 112 */
1224 C2_LEFTTORIGHT, /* q - 113 */
1225 C2_LEFTTORIGHT, /* r - 114 */
1226 C2_LEFTTORIGHT, /* s - 115 */
1227 C2_LEFTTORIGHT, /* t - 116 */
1228 C2_LEFTTORIGHT, /* u - 117 */
1229 C2_LEFTTORIGHT, /* v - 118 */
1230 C2_LEFTTORIGHT, /* w - 119 */
1231 C2_LEFTTORIGHT, /* x - 120 */
1232 C2_LEFTTORIGHT, /* y - 121 */
1233 C2_LEFTTORIGHT, /* z - 122 */
1234 C2_OTHERNEUTRAL, /* { - 123 */
1235 C2_OTHERNEUTRAL, /* | - 124 */
1236 C2_OTHERNEUTRAL, /* } - 125 */
1237 C2_OTHERNEUTRAL, /* ~ - 126 */
1238 C2_NOTAPPLICABLE, /* \x7f - 127 */
1239 C2_NOTAPPLICABLE, /* € - 128 */
1240 C2_NOTAPPLICABLE, /* � - 129 */
1241 C2_OTHERNEUTRAL, /* ‚ - 130 */
1242 C2_LEFTTORIGHT, /* ƒ - 131 */
1243 C2_OTHERNEUTRAL, /* „ - 132 */
1244 C2_OTHERNEUTRAL, /* … - 133 */
1245 C2_OTHERNEUTRAL, /* † - 134 */
1246 C2_OTHERNEUTRAL, /* ‡ - 135 */
1247 C2_LEFTTORIGHT, /* ˆ - 136 */
1248 C2_EUROPETERMINATOR, /* ‰ - 137 */
1249 C2_LEFTTORIGHT, /* Š - 138 */
1250 C2_OTHERNEUTRAL, /* ‹ - 139 */
1251 C2_LEFTTORIGHT, /* Œ - 140 */
1252 C2_NOTAPPLICABLE, /* � - 141 */
1253 C2_NOTAPPLICABLE, /* Ž - 142 */
1254 C2_NOTAPPLICABLE, /* � - 143 */
1255 C2_NOTAPPLICABLE, /* � - 144 */
1256 C2_OTHERNEUTRAL, /* ‘ - 145 */
1257 C2_OTHERNEUTRAL, /* ’ - 146 */
1258 C2_OTHERNEUTRAL, /* “ - 147 */
1259 C2_OTHERNEUTRAL, /* ” - 148 */
1260 C2_OTHERNEUTRAL, /* • - 149 */
1261 C2_OTHERNEUTRAL, /* – - 150 */
1262 C2_OTHERNEUTRAL, /* — - 151 */
1263 C2_LEFTTORIGHT, /* ˜ - 152 */
1264 C2_OTHERNEUTRAL, /* ™ - 153 */
1265 C2_LEFTTORIGHT, /* š - 154 */
1266 C2_OTHERNEUTRAL, /* › - 155 */
1267 C2_LEFTTORIGHT, /* œ - 156 */
1268 C2_NOTAPPLICABLE, /* � - 157 */
1269 C2_NOTAPPLICABLE, /* ž - 158 */
1270 C2_LEFTTORIGHT, /* Ÿ - 159 */
1271 C2_WHITESPACE, /*   - 160 */
1272 C2_OTHERNEUTRAL, /* ¡ - 161 */
1273 C2_EUROPETERMINATOR, /* ¢ - 162 */
1274 C2_EUROPETERMINATOR, /* £ - 163 */
1275 C2_EUROPETERMINATOR, /* ¤ - 164 */
1276 C2_EUROPETERMINATOR, /* ¥ - 165 */
1277 C2_OTHERNEUTRAL, /* ¦ - 166 */
1278 C2_OTHERNEUTRAL, /* § - 167 */
1279 C2_OTHERNEUTRAL, /* ¨ - 168 */
1280 C2_OTHERNEUTRAL, /* © - 169 */
1281 C2_OTHERNEUTRAL, /* ª - 170 */
1282 C2_OTHERNEUTRAL, /* « - 171 */
1283 C2_OTHERNEUTRAL, /* ¬ - 172 */
1284 C2_OTHERNEUTRAL, /* ­ - 173 */
1285 C2_OTHERNEUTRAL, /* ® - 174 */
1286 C2_OTHERNEUTRAL, /* ¯ - 175 */
1287 C2_EUROPETERMINATOR, /* ° - 176 */
1288 C2_EUROPETERMINATOR, /* ± - 177 */
1289 C2_EUROPENUMBER, /* ² - 178 */
1290 C2_EUROPENUMBER, /* ³ - 179 */
1291 C2_OTHERNEUTRAL, /* ´ - 180 */
1292 C2_OTHERNEUTRAL, /* µ - 181 */
1293 C2_OTHERNEUTRAL, /* ¶ - 182 */
1294 C2_OTHERNEUTRAL, /* · - 183 */
1295 C2_OTHERNEUTRAL, /* ¸ - 184 */
1296 C2_EUROPENUMBER, /* ¹ - 185 */
1297 C2_OTHERNEUTRAL, /* º - 186 */
1298 C2_OTHERNEUTRAL, /* » - 187 */
1299 C2_OTHERNEUTRAL, /* ¼ - 188 */
1300 C2_OTHERNEUTRAL, /* ½ - 189 */
1301 C2_OTHERNEUTRAL, /* ¾ - 190 */
1302 C2_OTHERNEUTRAL, /* ¿ - 191 */
1303 C2_LEFTTORIGHT, /* À - 192 */
1304 C2_LEFTTORIGHT, /* Á - 193 */
1305 C2_LEFTTORIGHT, /* Â - 194 */
1306 C2_LEFTTORIGHT, /* Ã - 195 */
1307 C2_LEFTTORIGHT, /* Ä - 196 */
1308 C2_LEFTTORIGHT, /* Å - 197 */
1309 C2_LEFTTORIGHT, /* Æ - 198 */
1310 C2_LEFTTORIGHT, /* Ç - 199 */
1311 C2_LEFTTORIGHT, /* È - 200 */
1312 C2_LEFTTORIGHT, /* É - 201 */
1313 C2_LEFTTORIGHT, /* Ê - 202 */
1314 C2_LEFTTORIGHT, /* Ë - 203 */
1315 C2_LEFTTORIGHT, /* Ì - 204 */
1316 C2_LEFTTORIGHT, /* Í - 205 */
1317 C2_LEFTTORIGHT, /* Î - 206 */
1318 C2_LEFTTORIGHT, /* Ï - 207 */
1319 C2_LEFTTORIGHT, /* Ð - 208 */
1320 C2_LEFTTORIGHT, /* Ñ - 209 */
1321 C2_LEFTTORIGHT, /* Ò - 210 */
1322 C2_LEFTTORIGHT, /* Ó - 211 */
1323 C2_LEFTTORIGHT, /* Ô - 212 */
1324 C2_LEFTTORIGHT, /* Õ - 213 */
1325 C2_LEFTTORIGHT, /* Ö - 214 */
1326 C2_OTHERNEUTRAL, /* × - 215 */
1327 C2_LEFTTORIGHT, /* Ø - 216 */
1328 C2_LEFTTORIGHT, /* Ù - 217 */
1329 C2_LEFTTORIGHT, /* Ú - 218 */
1330 C2_LEFTTORIGHT, /* Û - 219 */
1331 C2_LEFTTORIGHT, /* Ü - 220 */
1332 C2_LEFTTORIGHT, /* Ý - 221 */
1333 C2_LEFTTORIGHT, /* Þ - 222 */
1334 C2_LEFTTORIGHT, /* ß - 223 */
1335 C2_LEFTTORIGHT, /* à - 224 */
1336 C2_LEFTTORIGHT, /* á - 225 */
1337 C2_LEFTTORIGHT, /* â - 226 */
1338 C2_LEFTTORIGHT, /* ã - 227 */
1339 C2_LEFTTORIGHT, /* ä - 228 */
1340 C2_LEFTTORIGHT, /* å - 229 */
1341 C2_LEFTTORIGHT, /* æ - 230 */
1342 C2_LEFTTORIGHT, /* ç - 231 */
1343 C2_LEFTTORIGHT, /* è - 232 */
1344 C2_LEFTTORIGHT, /* é - 233 */
1345 C2_LEFTTORIGHT, /* ê - 234 */
1346 C2_LEFTTORIGHT, /* ë - 235 */
1347 C2_LEFTTORIGHT, /* ì - 236 */
1348 C2_LEFTTORIGHT, /* í - 237 */
1349 C2_LEFTTORIGHT, /* î - 238 */
1350 C2_LEFTTORIGHT, /* ï - 239 */
1351 C2_LEFTTORIGHT, /* ð - 240 */
1352 C2_LEFTTORIGHT, /* ñ - 241 */
1353 C2_LEFTTORIGHT, /* ò - 242 */
1354 C2_LEFTTORIGHT, /* ó - 243 */
1355 C2_LEFTTORIGHT, /* ô - 244 */
1356 C2_LEFTTORIGHT, /* õ - 245 */
1357 C2_LEFTTORIGHT, /* ö - 246 */
1358 C2_OTHERNEUTRAL, /* ÷ - 247 */
1359 C2_LEFTTORIGHT, /* ø - 248 */
1360 C2_LEFTTORIGHT, /* ù - 249 */
1361 C2_LEFTTORIGHT, /* ú - 250 */
1362 C2_LEFTTORIGHT, /* û - 251 */
1363 C2_LEFTTORIGHT, /* ü - 252 */
1364 C2_LEFTTORIGHT, /* ý - 253 */
1365 C2_LEFTTORIGHT, /* þ - 254 */
1366 C2_LEFTTORIGHT /* ÿ - 255 */
1369 const WORD OLE2NLS_CT_CType3_LUT[] = {
1370 0x0000, /* - 0 */
1371 0x0000, /* - 1 */
1372 0x0000, /* - 2 */
1373 0x0000, /* - 3 */
1374 0x0000, /* - 4 */
1375 0x0000, /* - 5 */
1376 0x0000, /* - 6 */
1377 0x0000, /* - 7 */
1378 0x0000, /* - 8 */
1379 0x0008, /* - 9 */
1380 0x0008, /* - 10 */
1381 0x0008, /* - 11 */
1382 0x0008, /* - 12 */
1383 0x0008, /* - 13 */
1384 0x0000, /* - 14 */
1385 0x0000, /* - 15 */
1386 0x0000, /* - 16 */
1387 0x0000, /* - 17 */
1388 0x0000, /* - 18 */
1389 0x0000, /* - 19 */
1390 0x0000, /* - 20 */
1391 0x0000, /* - 21 */
1392 0x0000, /* - 22 */
1393 0x0000, /* - 23 */
1394 0x0000, /* - 24 */
1395 0x0000, /* - 25 */
1396 0x0000, /* - 26 */
1397 0x0000, /* - 27 */
1398 0x0000, /* - 28 */
1399 0x0000, /* - 29 */
1400 0x0000, /* - 30 */
1401 0x0000, /* - 31 */
1402 0x0048, /* - 32 */
1403 0x0048, /* ! - 33 */
1404 0x0448, /* " - 34 */ /* " */
1405 0x0048, /* # - 35 */
1406 0x0448, /* $ - 36 */
1407 0x0048, /* % - 37 */
1408 0x0048, /* & - 38 */
1409 0x0440, /* ' - 39 */
1410 0x0048, /* ( - 40 */
1411 0x0048, /* ) - 41 */
1412 0x0048, /* * - 42 */
1413 0x0048, /* + - 43 */
1414 0x0048, /* , - 44 */
1415 0x0440, /* - - 45 */
1416 0x0048, /* . - 46 */
1417 0x0448, /* / - 47 */
1418 0x0040, /* 0 - 48 */
1419 0x0040, /* 1 - 49 */
1420 0x0040, /* 2 - 50 */
1421 0x0040, /* 3 - 51 */
1422 0x0040, /* 4 - 52 */
1423 0x0040, /* 5 - 53 */
1424 0x0040, /* 6 - 54 */
1425 0x0040, /* 7 - 55 */
1426 0x0040, /* 8 - 56 */
1427 0x0040, /* 9 - 57 */
1428 0x0048, /* : - 58 */
1429 0x0048, /* ; - 59 */
1430 0x0048, /* < - 60 */
1431 0x0448, /* = - 61 */
1432 0x0048, /* > - 62 */
1433 0x0048, /* ? - 63 */
1434 0x0448, /* @ - 64 */
1435 0x8040, /* A - 65 */
1436 0x8040, /* B - 66 */
1437 0x8040, /* C - 67 */
1438 0x8040, /* D - 68 */
1439 0x8040, /* E - 69 */
1440 0x8040, /* F - 70 */
1441 0x8040, /* G - 71 */
1442 0x8040, /* H - 72 */
1443 0x8040, /* I - 73 */
1444 0x8040, /* J - 74 */
1445 0x8040, /* K - 75 */
1446 0x8040, /* L - 76 */
1447 0x8040, /* M - 77 */
1448 0x8040, /* N - 78 */
1449 0x8040, /* O - 79 */
1450 0x8040, /* P - 80 */
1451 0x8040, /* Q - 81 */
1452 0x8040, /* R - 82 */
1453 0x8040, /* S - 83 */
1454 0x8040, /* T - 84 */
1455 0x8040, /* U - 85 */
1456 0x8040, /* V - 86 */
1457 0x8040, /* W - 87 */
1458 0x8040, /* X - 88 */
1459 0x8040, /* Y - 89 */
1460 0x8040, /* Z - 90 */
1461 0x0048, /* [ - 91 */
1462 0x0448, /* \ - 92 */
1463 0x0048, /* ] - 93 */
1464 0x0448, /* ^ - 94 */
1465 0x0448, /* _ - 95 */
1466 0x0448, /* ` - 96 */
1467 0x8040, /* a - 97 */
1468 0x8040, /* b - 98 */
1469 0x8040, /* c - 99 */
1470 0x8040, /* d - 100 */
1471 0x8040, /* e - 101 */
1472 0x8040, /* f - 102 */
1473 0x8040, /* g - 103 */
1474 0x8040, /* h - 104 */
1475 0x8040, /* i - 105 */
1476 0x8040, /* j - 106 */
1477 0x8040, /* k - 107 */
1478 0x8040, /* l - 108 */
1479 0x8040, /* m - 109 */
1480 0x8040, /* n - 110 */
1481 0x8040, /* o - 111 */
1482 0x8040, /* p - 112 */
1483 0x8040, /* q - 113 */
1484 0x8040, /* r - 114 */
1485 0x8040, /* s - 115 */
1486 0x8040, /* t - 116 */
1487 0x8040, /* u - 117 */
1488 0x8040, /* v - 118 */
1489 0x8040, /* w - 119 */
1490 0x8040, /* x - 120 */
1491 0x8040, /* y - 121 */
1492 0x8040, /* z - 122 */
1493 0x0048, /* { - 123 */
1494 0x0048, /* | - 124 */
1495 0x0048, /* } - 125 */
1496 0x0448, /* ~ - 126 */
1497 0x0000, /* \x7f - 127 */
1498 0x0000, /* € - 128 */
1499 0x0000, /* � - 129 */
1500 0x0008, /* ‚ - 130 */
1501 0x8000, /* ƒ - 131 */
1502 0x0008, /* „ - 132 */
1503 0x0008, /* … - 133 */
1504 0x0008, /* † - 134 */
1505 0x0008, /* ‡ - 135 */
1506 0x0001, /* ˆ - 136 */
1507 0x0008, /* ‰ - 137 */
1508 0x8003, /* Š - 138 */
1509 0x0008, /* ‹ - 139 */
1510 0x8000, /* Œ - 140 */
1511 0x0000, /* � - 141 */
1512 0x0000, /* Ž - 142 */
1513 0x0000, /* � - 143 */
1514 0x0000, /* � - 144 */
1515 0x0088, /* ‘ - 145 */
1516 0x0088, /* ’ - 146 */
1517 0x0088, /* “ - 147 */
1518 0x0088, /* ” - 148 */
1519 0x0008, /* • - 149 */
1520 0x0400, /* – - 150 */
1521 0x0400, /* — - 151 */
1522 0x0408, /* ˜ - 152 */
1523 0x0000, /* ™ - 153 */
1524 0x8003, /* š - 154 */
1525 0x0008, /* › - 155 */
1526 0x8000, /* œ - 156 */
1527 0x0000, /* � - 157 */
1528 0x0000, /* ž - 158 */
1529 0x8003, /* Ÿ - 159 */
1530 0x0008, /*   - 160 */
1531 0x0008, /* ¡ - 161 */
1532 0x0048, /* ¢ - 162 */
1533 0x0048, /* £ - 163 */
1534 0x0008, /* ¤ - 164 */
1535 0x0048, /* ¥ - 165 */
1536 0x0048, /* ¦ - 166 */
1537 0x0008, /* § - 167 */
1538 0x0408, /* ¨ - 168 */
1539 0x0008, /* © - 169 */
1540 0x0400, /* ª - 170 */
1541 0x0008, /* « - 171 */
1542 0x0048, /* ¬ - 172 */
1543 0x0408, /* ­ - 173 */
1544 0x0008, /* ® - 174 */
1545 0x0448, /* ¯ - 175 */
1546 0x0008, /* ° - 176 */
1547 0x0008, /* ± - 177 */
1548 0x0000, /* ² - 178 */
1549 0x0000, /* ³ - 179 */
1550 0x0408, /* ´ - 180 */
1551 0x0008, /* µ - 181 */
1552 0x0008, /* ¶ - 182 */
1553 0x0008, /* · - 183 */
1554 0x0408, /* ¸ - 184 */
1555 0x0000, /* ¹ - 185 */
1556 0x0400, /* º - 186 */
1557 0x0008, /* » - 187 */
1558 0x0000, /* ¼ - 188 */
1559 0x0000, /* ½ - 189 */
1560 0x0000, /* ¾ - 190 */
1561 0x0008, /* ¿ - 191 */
1562 0x8003, /* À - 192 */
1563 0x8003, /* Á - 193 */
1564 0x8003, /* Â - 194 */
1565 0x8003, /* Ã - 195 */
1566 0x8003, /* Ä - 196 */
1567 0x8003, /* Å - 197 */
1568 0x8000, /* Æ - 198 */
1569 0x8003, /* Ç - 199 */
1570 0x8003, /* È - 200 */
1571 0x8003, /* É - 201 */
1572 0x8003, /* Ê - 202 */
1573 0x8003, /* Ë - 203 */
1574 0x8003, /* Ì - 204 */
1575 0x8003, /* Í - 205 */
1576 0x8003, /* Î - 206 */
1577 0x8003, /* Ï - 207 */
1578 0x8000, /* Ð - 208 */
1579 0x8003, /* Ñ - 209 */
1580 0x8003, /* Ò - 210 */
1581 0x8003, /* Ó - 211 */
1582 0x8003, /* Ô - 212 */
1583 0x8003, /* Õ - 213 */
1584 0x8003, /* Ö - 214 */
1585 0x0008, /* × - 215 */
1586 0x8003, /* Ø - 216 */
1587 0x8003, /* Ù - 217 */
1588 0x8003, /* Ú - 218 */
1589 0x8003, /* Û - 219 */
1590 0x8003, /* Ü - 220 */
1591 0x8003, /* Ý - 221 */
1592 0x8000, /* Þ - 222 */
1593 0x8000, /* ß - 223 */
1594 0x8003, /* à - 224 */
1595 0x8003, /* á - 225 */
1596 0x8003, /* â - 226 */
1597 0x8003, /* ã - 227 */
1598 0x8003, /* ä - 228 */
1599 0x8003, /* å - 229 */
1600 0x8000, /* æ - 230 */
1601 0x8003, /* ç - 231 */
1602 0x8003, /* è - 232 */
1603 0x8003, /* é - 233 */
1604 0x8003, /* ê - 234 */
1605 0x8003, /* ë - 235 */
1606 0x8003, /* ì - 236 */
1607 0x8003, /* í - 237 */
1608 0x8003, /* î - 238 */
1609 0x8003, /* ï - 239 */
1610 0x8000, /* ð - 240 */
1611 0x8003, /* ñ - 241 */
1612 0x8003, /* ò - 242 */
1613 0x8003, /* ó - 243 */
1614 0x8003, /* ô - 244 */
1615 0x8003, /* õ - 245 */
1616 0x8003, /* ö - 246 */
1617 0x0008, /* ÷ - 247 */
1618 0x8003, /* ø - 248 */
1619 0x8003, /* ù - 249 */
1620 0x8003, /* ú - 250 */
1621 0x8003, /* û - 251 */
1622 0x8003, /* ü - 252 */
1623 0x8003, /* ý - 253 */
1624 0x8000, /* þ - 254 */
1625 0x8003 /* ÿ - 255 */
1628 /******************************************************************************
1629 * GetStringTypeA [KERNEL32.396]
1631 BOOL WINAPI GetStringTypeA(LCID locale,DWORD dwInfoType,LPCSTR src,
1632 INT cchSrc,LPWORD chartype)
1634 return GetStringTypeExA(locale,dwInfoType,src,cchSrc,chartype);
1637 /******************************************************************************
1638 * GetStringTypeExA [KERNEL32.397]
1640 * FIXME: Ignores the locale.
1642 BOOL WINAPI GetStringTypeExA(LCID locale,DWORD dwInfoType,LPCSTR src,
1643 INT cchSrc,LPWORD chartype)
1645 int i;
1647 if ((src==NULL) || (chartype==NULL) || (src==(LPSTR)chartype))
1649 SetLastError(ERROR_INVALID_PARAMETER);
1650 return FALSE;
1653 if (cchSrc==-1)
1654 cchSrc=lstrlenA(src)+1;
1656 switch (dwInfoType) {
1657 case CT_CTYPE1:
1658 for (i=0;i<cchSrc;i++)
1660 chartype[i] = 0;
1661 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1662 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1663 if (islower(src[i])) chartype[i]|=C1_LOWER;
1664 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1665 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1666 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1667 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1668 /* FIXME: isblank() is a GNU extension */
1669 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1670 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1671 /* C1_XDIGIT */
1673 return TRUE;
1675 case CT_CTYPE2:
1676 for (i=0;i<cchSrc;i++)
1678 chartype[i]=(WORD)CT_CType2_LUT[i];
1680 return TRUE;
1682 case CT_CTYPE3:
1683 for (i=0;i<cchSrc;i++)
1685 chartype[i]=OLE2NLS_CT_CType3_LUT[i];
1687 return TRUE;
1689 default:
1690 ERR("Unknown dwInfoType:%ld\n",dwInfoType);
1691 return FALSE;
1695 /******************************************************************************
1696 * GetStringTypeW [KERNEL32.399]
1698 * NOTES
1699 * Yes, this is missing LCID locale. MS fault.
1701 BOOL WINAPI GetStringTypeW(DWORD dwInfoType,LPCWSTR src,INT cchSrc,
1702 LPWORD chartype)
1704 return GetStringTypeExW(0/*defaultlocale*/,dwInfoType,src,cchSrc,chartype);
1707 /******************************************************************************
1708 * GetStringTypeExW [KERNEL32.398]
1710 * FIXME: unicode chars are assumed chars
1712 BOOL WINAPI GetStringTypeExW(LCID locale,DWORD dwInfoType,LPCWSTR src,
1713 INT cchSrc,LPWORD chartype)
1715 int i;
1718 if (cchSrc==-1)
1719 cchSrc=lstrlenW(src)+1;
1721 switch (dwInfoType) {
1722 case CT_CTYPE2:
1723 FIXME("CT_CTYPE2 not supported.\n");
1724 return FALSE;
1725 case CT_CTYPE3:
1726 FIXME("CT_CTYPE3 not supported.\n");
1727 return FALSE;
1728 default:break;
1730 for (i=0;i<cchSrc;i++) {
1731 chartype[i] = 0;
1732 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1733 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1734 if (islower(src[i])) chartype[i]|=C1_LOWER;
1735 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1736 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1737 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1738 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1739 /* FIXME: isblank() is a GNU extension */
1740 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1741 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1742 /* C1_XDIGIT */
1744 return TRUE;
1747 /*****************************************************************
1748 * WINE_GetLanguageName [internal]
1750 static LPCSTR WINE_GetLanguageName( UINT langid )
1752 int i;
1753 for ( i = 0; languages[i].langid != 0; i++ )
1754 if ( langid == languages[i].langid )
1755 break;
1757 return languages[i].langname;
1760 /***********************************************************************
1761 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1763 DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
1765 char buffer[80];
1766 LPCSTR name;
1767 DWORD result;
1770 * First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
1771 * from the registry.
1774 sprintf( buffer,
1775 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
1776 wLang );
1778 result = RegQueryValueA( HKEY_LOCAL_MACHINE, buffer, szLang, (LPDWORD)&nSize );
1779 if ( result == ERROR_SUCCESS || result == ERROR_MORE_DATA )
1780 return nSize;
1783 * If that fails, use the internal table
1786 name = WINE_GetLanguageName( wLang );
1787 lstrcpynA( szLang, name, nSize );
1788 return lstrlenA( name );
1791 /***********************************************************************
1792 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1794 DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
1796 char buffer[80];
1797 LPWSTR keyname;
1798 LPCSTR name;
1799 DWORD result;
1802 * First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
1803 * from the registry.
1806 sprintf( buffer,
1807 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
1808 wLang );
1810 keyname = HEAP_strdupAtoW( GetProcessHeap(), 0, buffer );
1811 result = RegQueryValueW( HKEY_LOCAL_MACHINE, keyname, szLang, (LPDWORD)&nSize );
1812 HeapFree( GetProcessHeap(), 0, keyname );
1814 if ( result == ERROR_SUCCESS || result == ERROR_MORE_DATA )
1815 return nSize;
1818 * If that fails, use the internal table
1821 name = WINE_GetLanguageName( wLang );
1822 lstrcpynAtoW( szLang, name, nSize );
1823 return lstrlenA( name );
1827 static const unsigned char LCM_Unicode_LUT[] = {
1828 6 , 3, /* - 1 */
1829 6 , 4, /* - 2 */
1830 6 , 5, /* - 3 */
1831 6 , 6, /* - 4 */
1832 6 , 7, /* - 5 */
1833 6 , 8, /* - 6 */
1834 6 , 9, /* - 7 */
1835 6 , 10, /* - 8 */
1836 7 , 5, /* - 9 */
1837 7 , 6, /* - 10 */
1838 7 , 7, /* - 11 */
1839 7 , 8, /* - 12 */
1840 7 , 9, /* - 13 */
1841 6 , 11, /* - 14 */
1842 6 , 12, /* - 15 */
1843 6 , 13, /* - 16 */
1844 6 , 14, /* - 17 */
1845 6 , 15, /* - 18 */
1846 6 , 16, /* - 19 */
1847 6 , 17, /* - 20 */
1848 6 , 18, /* - 21 */
1849 6 , 19, /* - 22 */
1850 6 , 20, /* - 23 */
1851 6 , 21, /* - 24 */
1852 6 , 22, /* - 25 */
1853 6 , 23, /* - 26 */
1854 6 , 24, /* - 27 */
1855 6 , 25, /* - 28 */
1856 6 , 26, /* - 29 */
1857 6 , 27, /* - 30 */
1858 6 , 28, /* - 31 */
1859 7 , 2, /* - 32 */
1860 7 , 28, /* ! - 33 */
1861 7 , 29, /* " - 34 */ /* " */
1862 7 , 31, /* # - 35 */
1863 7 , 33, /* $ - 36 */
1864 7 , 35, /* % - 37 */
1865 7 , 37, /* & - 38 */
1866 6 , 128, /* ' - 39 */
1867 7 , 39, /* ( - 40 */
1868 7 , 42, /* ) - 41 */
1869 7 , 45, /* * - 42 */
1870 8 , 3, /* + - 43 */
1871 7 , 47, /* , - 44 */
1872 6 , 130, /* - - 45 */
1873 7 , 51, /* . - 46 */
1874 7 , 53, /* / - 47 */
1875 12 , 3, /* 0 - 48 */
1876 12 , 33, /* 1 - 49 */
1877 12 , 51, /* 2 - 50 */
1878 12 , 70, /* 3 - 51 */
1879 12 , 88, /* 4 - 52 */
1880 12 , 106, /* 5 - 53 */
1881 12 , 125, /* 6 - 54 */
1882 12 , 144, /* 7 - 55 */
1883 12 , 162, /* 8 - 56 */
1884 12 , 180, /* 9 - 57 */
1885 7 , 55, /* : - 58 */
1886 7 , 58, /* ; - 59 */
1887 8 , 14, /* < - 60 */
1888 8 , 18, /* = - 61 */
1889 8 , 20, /* > - 62 */
1890 7 , 60, /* ? - 63 */
1891 7 , 62, /* @ - 64 */
1892 14 , 2, /* A - 65 */
1893 14 , 9, /* B - 66 */
1894 14 , 10, /* C - 67 */
1895 14 , 26, /* D - 68 */
1896 14 , 33, /* E - 69 */
1897 14 , 35, /* F - 70 */
1898 14 , 37, /* G - 71 */
1899 14 , 44, /* H - 72 */
1900 14 , 50, /* I - 73 */
1901 14 , 53, /* J - 74 */
1902 14 , 54, /* K - 75 */
1903 14 , 72, /* L - 76 */
1904 14 , 81, /* M - 77 */
1905 14 , 112, /* N - 78 */
1906 14 , 124, /* O - 79 */
1907 14 , 126, /* P - 80 */
1908 14 , 137, /* Q - 81 */
1909 14 , 138, /* R - 82 */
1910 14 , 145, /* S - 83 */
1911 14 , 153, /* T - 84 */
1912 14 , 159, /* U - 85 */
1913 14 , 162, /* V - 86 */
1914 14 , 164, /* W - 87 */
1915 14 , 166, /* X - 88 */
1916 14 , 167, /* Y - 89 */
1917 14 , 169, /* Z - 90 */
1918 7 , 63, /* [ - 91 */
1919 7 , 65, /* \ - 92 */
1920 7 , 66, /* ] - 93 */
1921 7 , 67, /* ^ - 94 */
1922 7 , 68, /* _ - 95 */
1923 7 , 72, /* ` - 96 */
1924 14 , 2, /* a - 97 */
1925 14 , 9, /* b - 98 */
1926 14 , 10, /* c - 99 */
1927 14 , 26, /* d - 100 */
1928 14 , 33, /* e - 101 */
1929 14 , 35, /* f - 102 */
1930 14 , 37, /* g - 103 */
1931 14 , 44, /* h - 104 */
1932 14 , 50, /* i - 105 */
1933 14 , 53, /* j - 106 */
1934 14 , 54, /* k - 107 */
1935 14 , 72, /* l - 108 */
1936 14 , 81, /* m - 109 */
1937 14 , 112, /* n - 110 */
1938 14 , 124, /* o - 111 */
1939 14 , 126, /* p - 112 */
1940 14 , 137, /* q - 113 */
1941 14 , 138, /* r - 114 */
1942 14 , 145, /* s - 115 */
1943 14 , 153, /* t - 116 */
1944 14 , 159, /* u - 117 */
1945 14 , 162, /* v - 118 */
1946 14 , 164, /* w - 119 */
1947 14 , 166, /* x - 120 */
1948 14 , 167, /* y - 121 */
1949 14 , 169, /* z - 122 */
1950 7 , 74, /* { - 123 */
1951 7 , 76, /* | - 124 */
1952 7 , 78, /* } - 125 */
1953 7 , 80, /* ~ - 126 */
1954 6 , 29, /* \x7f - 127 */
1955 6 , 30, /* € - 128 */
1956 6 , 31, /* � - 129 */
1957 7 , 123, /* ‚ - 130 */
1958 14 , 35, /* ƒ - 131 */
1959 7 , 127, /* „ - 132 */
1960 10 , 21, /* … - 133 */
1961 10 , 15, /* † - 134 */
1962 10 , 16, /* ‡ - 135 */
1963 7 , 67, /* ˆ - 136 */
1964 10 , 22, /* ‰ - 137 */
1965 14 , 145, /* Š - 138 */
1966 7 , 136, /* ‹ - 139 */
1967 14 + 16 , 124, /* Œ - 140 */
1968 6 , 43, /* � - 141 */
1969 6 , 44, /* Ž - 142 */
1970 6 , 45, /* � - 143 */
1971 6 , 46, /* � - 144 */
1972 7 , 121, /* ‘ - 145 */
1973 7 , 122, /* ’ - 146 */
1974 7 , 125, /* “ - 147 */
1975 7 , 126, /* ” - 148 */
1976 10 , 17, /* • - 149 */
1977 6 , 137, /* – - 150 */
1978 6 , 139, /* — - 151 */
1979 7 , 93, /* ˜ - 152 */
1980 14 , 156, /* ™ - 153 */
1981 14 , 145, /* š - 154 */
1982 7 , 137, /* › - 155 */
1983 14 + 16 , 124, /* œ - 156 */
1984 6 , 59, /* � - 157 */
1985 6 , 60, /* ž - 158 */
1986 14 , 167, /* Ÿ - 159 */
1987 7 , 4, /*   - 160 */
1988 7 , 81, /* ¡ - 161 */
1989 10 , 2, /* ¢ - 162 */
1990 10 , 3, /* £ - 163 */
1991 10 , 4, /* ¤ - 164 */
1992 10 , 5, /* ¥ - 165 */
1993 7 , 82, /* ¦ - 166 */
1994 10 , 6, /* § - 167 */
1995 7 , 83, /* ¨ - 168 */
1996 10 , 7, /* © - 169 */
1997 14 , 2, /* ª - 170 */
1998 8 , 24, /* « - 171 */
1999 10 , 8, /* ¬ - 172 */
2000 6 , 131, /* ­ - 173 */
2001 10 , 9, /* ® - 174 */
2002 7 , 84, /* ¯ - 175 */
2003 10 , 10, /* ° - 176 */
2004 8 , 23, /* ± - 177 */
2005 12 , 51, /* ² - 178 */
2006 12 , 70, /* ³ - 179 */
2007 7 , 85, /* ´ - 180 */
2008 10 , 11, /* µ - 181 */
2009 10 , 12, /* ¶ - 182 */
2010 10 , 13, /* · - 183 */
2011 7 , 86, /* ¸ - 184 */
2012 12 , 33, /* ¹ - 185 */
2013 14 , 124, /* º - 186 */
2014 8 , 26, /* » - 187 */
2015 12 , 21, /* ¼ - 188 */
2016 12 , 25, /* ½ - 189 */
2017 12 , 29, /* ¾ - 190 */
2018 7 , 87, /* ¿ - 191 */
2019 14 , 2, /* À - 192 */
2020 14 , 2, /* Á - 193 */
2021 14 , 2, /* Â - 194 */
2022 14 , 2, /* Ã - 195 */
2023 14 , 2, /* Ä - 196 */
2024 14 , 2, /* Å - 197 */
2025 14 + 16 , 2, /* Æ - 198 */
2026 14 , 10, /* Ç - 199 */
2027 14 , 33, /* È - 200 */
2028 14 , 33, /* É - 201 */
2029 14 , 33, /* Ê - 202 */
2030 14 , 33, /* Ë - 203 */
2031 14 , 50, /* Ì - 204 */
2032 14 , 50, /* Í - 205 */
2033 14 , 50, /* Î - 206 */
2034 14 , 50, /* Ï - 207 */
2035 14 , 26, /* Ð - 208 */
2036 14 , 112, /* Ñ - 209 */
2037 14 , 124, /* Ò - 210 */
2038 14 , 124, /* Ó - 211 */
2039 14 , 124, /* Ô - 212 */
2040 14 , 124, /* Õ - 213 */
2041 14 , 124, /* Ö - 214 */
2042 8 , 28, /* × - 215 */
2043 14 , 124, /* Ø - 216 */
2044 14 , 159, /* Ù - 217 */
2045 14 , 159, /* Ú - 218 */
2046 14 , 159, /* Û - 219 */
2047 14 , 159, /* Ü - 220 */
2048 14 , 167, /* Ý - 221 */
2049 14 + 32 , 153, /* Þ - 222 */
2050 14 + 48 , 145, /* ß - 223 */
2051 14 , 2, /* à - 224 */
2052 14 , 2, /* á - 225 */
2053 14 , 2, /* â - 226 */
2054 14 , 2, /* ã - 227 */
2055 14 , 2, /* ä - 228 */
2056 14 , 2, /* å - 229 */
2057 14 + 16 , 2, /* æ - 230 */
2058 14 , 10, /* ç - 231 */
2059 14 , 33, /* è - 232 */
2060 14 , 33, /* é - 233 */
2061 14 , 33, /* ê - 234 */
2062 14 , 33, /* ë - 235 */
2063 14 , 50, /* ì - 236 */
2064 14 , 50, /* í - 237 */
2065 14 , 50, /* î - 238 */
2066 14 , 50, /* ï - 239 */
2067 14 , 26, /* ð - 240 */
2068 14 , 112, /* ñ - 241 */
2069 14 , 124, /* ò - 242 */
2070 14 , 124, /* ó - 243 */
2071 14 , 124, /* ô - 244 */
2072 14 , 124, /* õ - 245 */
2073 14 , 124, /* ö - 246 */
2074 8 , 29, /* ÷ - 247 */
2075 14 , 124, /* ø - 248 */
2076 14 , 159, /* ù - 249 */
2077 14 , 159, /* ú - 250 */
2078 14 , 159, /* û - 251 */
2079 14 , 159, /* ü - 252 */
2080 14 , 167, /* ý - 253 */
2081 14 + 32 , 153, /* þ - 254 */
2082 14 , 167 /* ÿ - 255 */ };
2084 static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
2086 #define LCM_Diacritic_Start 131
2088 static const unsigned char LCM_Diacritic_LUT[] = {
2089 123, /* ƒ - 131 */
2090 2, /* „ - 132 */
2091 2, /* … - 133 */
2092 2, /* † - 134 */
2093 2, /* ‡ - 135 */
2094 3, /* ˆ - 136 */
2095 2, /* ‰ - 137 */
2096 20, /* Š - 138 */
2097 2, /* ‹ - 139 */
2098 2, /* Œ - 140 */
2099 2, /* � - 141 */
2100 2, /* Ž - 142 */
2101 2, /* � - 143 */
2102 2, /* � - 144 */
2103 2, /* ‘ - 145 */
2104 2, /* ’ - 146 */
2105 2, /* “ - 147 */
2106 2, /* ” - 148 */
2107 2, /* • - 149 */
2108 2, /* – - 150 */
2109 2, /* — - 151 */
2110 2, /* ˜ - 152 */
2111 2, /* ™ - 153 */
2112 20, /* š - 154 */
2113 2, /* › - 155 */
2114 2, /* œ - 156 */
2115 2, /* � - 157 */
2116 2, /* ž - 158 */
2117 19, /* Ÿ - 159 */
2118 2, /*   - 160 */
2119 2, /* ¡ - 161 */
2120 2, /* ¢ - 162 */
2121 2, /* £ - 163 */
2122 2, /* ¤ - 164 */
2123 2, /* ¥ - 165 */
2124 2, /* ¦ - 166 */
2125 2, /* § - 167 */
2126 2, /* ¨ - 168 */
2127 2, /* © - 169 */
2128 3, /* ª - 170 */
2129 2, /* « - 171 */
2130 2, /* ¬ - 172 */
2131 2, /* ­ - 173 */
2132 2, /* ® - 174 */
2133 2, /* ¯ - 175 */
2134 2, /* ° - 176 */
2135 2, /* ± - 177 */
2136 2, /* ² - 178 */
2137 2, /* ³ - 179 */
2138 2, /* ´ - 180 */
2139 2, /* µ - 181 */
2140 2, /* ¶ - 182 */
2141 2, /* · - 183 */
2142 2, /* ¸ - 184 */
2143 2, /* ¹ - 185 */
2144 3, /* º - 186 */
2145 2, /* » - 187 */
2146 2, /* ¼ - 188 */
2147 2, /* ½ - 189 */
2148 2, /* ¾ - 190 */
2149 2, /* ¿ - 191 */
2150 15, /* À - 192 */
2151 14, /* Á - 193 */
2152 18, /* Â - 194 */
2153 25, /* Ã - 195 */
2154 19, /* Ä - 196 */
2155 26, /* Å - 197 */
2156 2, /* Æ - 198 */
2157 28, /* Ç - 199 */
2158 15, /* È - 200 */
2159 14, /* É - 201 */
2160 18, /* Ê - 202 */
2161 19, /* Ë - 203 */
2162 15, /* Ì - 204 */
2163 14, /* Í - 205 */
2164 18, /* Î - 206 */
2165 19, /* Ï - 207 */
2166 104, /* Ð - 208 */
2167 25, /* Ñ - 209 */
2168 15, /* Ò - 210 */
2169 14, /* Ó - 211 */
2170 18, /* Ô - 212 */
2171 25, /* Õ - 213 */
2172 19, /* Ö - 214 */
2173 2, /* × - 215 */
2174 33, /* Ø - 216 */
2175 15, /* Ù - 217 */
2176 14, /* Ú - 218 */
2177 18, /* Û - 219 */
2178 19, /* Ü - 220 */
2179 14, /* Ý - 221 */
2180 2, /* Þ - 222 */
2181 2, /* ß - 223 */
2182 15, /* à - 224 */
2183 14, /* á - 225 */
2184 18, /* â - 226 */
2185 25, /* ã - 227 */
2186 19, /* ä - 228 */
2187 26, /* å - 229 */
2188 2, /* æ - 230 */
2189 28, /* ç - 231 */
2190 15, /* è - 232 */
2191 14, /* é - 233 */
2192 18, /* ê - 234 */
2193 19, /* ë - 235 */
2194 15, /* ì - 236 */
2195 14, /* í - 237 */
2196 18, /* î - 238 */
2197 19, /* ï - 239 */
2198 104, /* ð - 240 */
2199 25, /* ñ - 241 */
2200 15, /* ò - 242 */
2201 14, /* ó - 243 */
2202 18, /* ô - 244 */
2203 25, /* õ - 245 */
2204 19, /* ö - 246 */
2205 2, /* ÷ - 247 */
2206 33, /* ø - 248 */
2207 15, /* ù - 249 */
2208 14, /* ú - 250 */
2209 18, /* û - 251 */
2210 19, /* ü - 252 */
2211 14, /* ý - 253 */
2212 2, /* þ - 254 */
2213 19, /* ÿ - 255 */
2216 /******************************************************************************
2217 * OLE2NLS_isPunctuation [INTERNAL]
2219 static int OLE2NLS_isPunctuation(unsigned char c)
2221 /* "punctuation character" in this context is a character which is
2222 considered "less important" during word sort comparison.
2223 See LCMapString implementation for the precise definition
2224 of "less important". */
2226 return (LCM_Unicode_LUT[-2+2*c]==6);
2229 /******************************************************************************
2230 * OLE2NLS_isNonSpacing [INTERNAL]
2232 static int OLE2NLS_isNonSpacing(unsigned char c)
2234 /* This function is used by LCMapStringA. Characters
2235 for which it returns true are ignored when mapping a
2236 string with NORM_IGNORENONSPACE */
2237 return ((c==136) || (c==170) || (c==186));
2240 /******************************************************************************
2241 * OLE2NLS_isSymbol [INTERNAL]
2243 static int OLE2NLS_isSymbol(unsigned char c)
2245 /* This function is used by LCMapStringA. Characters
2246 for which it returns true are ignored when mapping a
2247 string with NORM_IGNORESYMBOLS */
2248 return ( (c!=0) && !IsCharAlphaNumericA(c) );
2251 /******************************************************************************
2252 * identity [Internal]
2254 static int identity(int c)
2256 return c;
2259 /*************************************************************************
2260 * LCMapStringA [KERNEL32.492]
2262 * Convert a string, or generate a sort key from it.
2264 * If (mapflags & LCMAP_SORTKEY), the function will generate
2265 * a sort key for the source string. Else, it will convert it
2266 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
2268 * RETURNS
2269 * Error : 0.
2270 * Success : length of the result string.
2272 * NOTES
2273 * If called with scrlen = -1, the function will compute the length
2274 * of the 0-terminated string strsrc by itself.
2276 * If called with dstlen = 0, returns the buffer length that
2277 * would be required.
2279 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
2280 * as if they are equal.
2281 * In the only code page implemented so far, there may not be
2282 * wide characters in strings passed to LCMapStringA,
2283 * so there is nothing to be done for this flag.
2285 INT WINAPI LCMapStringA(
2286 LCID lcid /* locale identifier created with MAKELCID;
2287 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
2288 predefined values. */,
2289 DWORD mapflags /* flags */,
2290 LPCSTR srcstr /* source buffer */,
2291 INT srclen /* source length */,
2292 LPSTR dststr /* destination buffer */,
2293 INT dstlen /* destination buffer length */)
2295 int i;
2297 TRACE_(string)("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
2298 lcid,mapflags,srcstr,srclen,dststr,dstlen);
2300 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2302 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
2303 SetLastError(ERROR_INVALID_PARAMETER);
2304 return 0;
2306 if (srclen == -1)
2307 srclen = lstrlenA(srcstr) + 1 ; /* (include final '\0') */
2309 #define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
2310 LCMAP_LOWERCASE | \
2311 LCMAP_SORTKEY | \
2312 NORM_IGNORECASE | \
2313 NORM_IGNORENONSPACE | \
2314 SORT_STRINGSORT | \
2315 NORM_IGNOREWIDTH | \
2316 NORM_IGNOREKANATYPE)
2317 /* FIXME: as long as we don't support Kanakana nor Hirigana
2318 * characters, we can support NORM_IGNOREKANATYPE
2320 if (mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS)
2322 FIXME_(string)("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
2323 "unimplemented flags: 0x%08lx\n",
2324 lcid,
2325 mapflags,
2326 srcstr,
2327 srclen,
2328 dststr,
2329 dstlen,
2330 mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS
2334 if ( !(mapflags & LCMAP_SORTKEY) )
2336 int i,j;
2337 int (*f)(int) = identity;
2338 int flag_ignorenonspace = mapflags & NORM_IGNORENONSPACE;
2339 int flag_ignoresymbols = mapflags & NORM_IGNORESYMBOLS;
2341 if (flag_ignorenonspace || flag_ignoresymbols)
2343 /* For some values of mapflags, the length of the resulting
2344 string is not known at this point. Windows does map the string
2345 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
2346 these cases. */
2347 if (dstlen==0)
2349 /* Compute required length */
2350 for (i=j=0; i < srclen; i++)
2352 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
2353 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
2354 j++;
2356 return j;
2359 else
2361 if (dstlen==0)
2362 return srclen;
2363 if (dstlen<srclen)
2365 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2366 return 0;
2369 if (mapflags & LCMAP_UPPERCASE)
2370 f = toupper;
2371 else if (mapflags & LCMAP_LOWERCASE)
2372 f = tolower;
2373 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
2374 for (i=j=0; (i<srclen) && (j<dstlen) ; i++)
2376 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
2377 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
2379 dststr[j] = (CHAR) f(srcstr[i]);
2380 j++;
2383 return j;
2386 /* FIXME: This function completely ignores the "lcid" parameter. */
2387 /* else ... (mapflags & LCMAP_SORTKEY) */
2389 int unicode_len=0;
2390 int case_len=0;
2391 int diacritic_len=0;
2392 int delayed_punctuation_len=0;
2393 char *case_component;
2394 char *diacritic_component;
2395 char *delayed_punctuation_component;
2396 int room,count;
2397 int flag_stringsort = mapflags & SORT_STRINGSORT;
2399 /* compute how much room we will need */
2400 for (i=0;i<srclen;i++)
2402 int ofs;
2403 unsigned char source_char = srcstr[i];
2404 if (source_char!='\0')
2406 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
2408 unicode_len++;
2409 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
2410 unicode_len++; /* double letter */
2412 else
2414 delayed_punctuation_len++;
2418 if (isupper(source_char))
2419 case_len=unicode_len;
2421 ofs = source_char - LCM_Diacritic_Start;
2422 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
2423 diacritic_len=unicode_len;
2426 if (mapflags & NORM_IGNORECASE)
2427 case_len=0;
2428 if (mapflags & NORM_IGNORENONSPACE)
2429 diacritic_len=0;
2431 room = 2 * unicode_len /* "unicode" component */
2432 + diacritic_len /* "diacritic" component */
2433 + case_len /* "case" component */
2434 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
2435 + 4 /* four '\1' separators */
2436 + 1 ; /* terminal '\0' */
2437 if (dstlen==0)
2438 return room;
2439 else if (dstlen<room)
2441 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2442 return 0;
2444 #if 0
2445 /*FIXME the Pointercheck should not be nessesary */
2446 if (IsBadWritePtr (dststr,room))
2447 { ERR_(string)("bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
2448 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2449 return 0;
2451 #endif
2452 /* locate each component, write separators */
2453 diacritic_component = dststr + 2*unicode_len ;
2454 *diacritic_component++ = '\1';
2455 case_component = diacritic_component + diacritic_len ;
2456 *case_component++ = '\1';
2457 delayed_punctuation_component = case_component + case_len ;
2458 *delayed_punctuation_component++ = '\1';
2459 *delayed_punctuation_component++ = '\1';
2461 /* read source string char by char, write
2462 corresponding weight in each component. */
2463 for (i=0,count=0;i<srclen;i++)
2465 unsigned char source_char=srcstr[i];
2466 if (source_char!='\0')
2468 int type,longcode;
2469 type = LCM_Unicode_LUT[-2+2*source_char];
2470 longcode = type >> 4;
2471 type &= 15;
2472 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
2474 UINT16 encrypted_location = (1<<15) + 7 + 4*count;
2475 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
2476 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
2477 /* big-endian is used here because it lets string comparison be
2478 compatible with numerical comparison */
2480 *delayed_punctuation_component++ = type;
2481 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
2482 /* assumption : a punctuation character is never a
2483 double or accented letter */
2485 else
2487 dststr[2*count] = type;
2488 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
2489 if (longcode)
2491 if (count<case_len)
2492 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2493 if (count<diacritic_len)
2494 diacritic_component[count] = 2; /* assumption: a double letter
2495 is never accented */
2496 count++;
2498 dststr[2*count] = type;
2499 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
2500 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
2501 32 in the first column of LCM_Unicode_LUT --> longcode = 2
2502 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
2505 if (count<case_len)
2506 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2507 if (count<diacritic_len)
2509 int ofs = source_char - LCM_Diacritic_Start;
2510 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
2512 count++;
2516 dststr[room-1] = '\0';
2517 return room;
2521 /*************************************************************************
2522 * LCMapStringW [KERNEL32.493]
2524 * Convert a string, or generate a sort key from it.
2526 * NOTE
2528 * See LCMapStringA for documentation
2530 INT WINAPI LCMapStringW(
2531 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT srclen,LPWSTR dststr,
2532 INT dstlen)
2534 int i;
2536 TRACE_(string)("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2537 lcid, mapflags, srcstr, srclen, dststr, dstlen);
2539 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2541 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
2542 SetLastError(ERROR_INVALID_PARAMETER);
2543 return 0;
2545 if (srclen==-1)
2546 srclen = lstrlenW(srcstr)+1;
2548 /* FIXME: Both this function and it's companion LCMapStringA()
2549 * completely ignore the "lcid" parameter. In place of the "lcid"
2550 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2551 * environment variable prior to invoking this function. */
2552 if (mapflags & LCMAP_SORTKEY)
2554 /* Possible values of LC_COLLATE. */
2555 char *lc_collate_default = 0; /* value prior to this function */
2556 char *lc_collate_env = 0; /* value retrieved from the environment */
2558 /* General purpose index into strings of any type. */
2559 int str_idx = 0;
2561 /* Lengths of various strings where the length is measured in
2562 * wide characters for wide character strings and in bytes for
2563 * native strings. The lengths include the NULL terminator. */
2564 size_t returned_len = 0;
2565 size_t src_native_len = 0;
2566 size_t dst_native_len = 0;
2567 size_t dststr_libc_len = 0;
2569 /* Native (character set determined by locale) versions of the
2570 * strings source and destination strings. */
2571 LPSTR src_native = 0;
2572 LPSTR dst_native = 0;
2574 /* Version of the source and destination strings using the
2575 * "wchar_t" Unicode data type needed by various libc functions. */
2576 wchar_t *srcstr_libc = 0;
2577 wchar_t *dststr_libc = 0;
2579 if(!(srcstr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2580 srclen * sizeof(wchar_t))))
2582 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2583 srclen * sizeof(wchar_t));
2584 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2585 return 0;
2588 /* Convert source string to a libc Unicode string. */
2589 for(str_idx = 0; str_idx < srclen; str_idx++)
2591 srcstr_libc[str_idx] = srcstr[str_idx];
2594 /* src_native should contain at most 3 bytes for each
2595 * multibyte characters in the original srcstr string. */
2596 src_native_len = 3 * srclen;
2597 if(!(src_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0,
2598 src_native_len)))
2600 ERR("Unable to allocate %d bytes for src_native\n", src_native_len);
2601 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2602 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2603 return 0;
2606 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2607 * current value is backed up so it can be restored after the
2608 * last LC_COLLATE sensitive function returns.
2610 * Even though the locale is adjusted for a minimum amount of
2611 * time a race condition exists where other threads may be
2612 * affected if they invoke LC_COLLATE sensitive functions. One
2613 * possible solution is to wrap all LC_COLLATE sensitive Wine
2614 * functions, like LCMapStringW(), in a mutex.
2616 * Another enhancement to the following would be to set the
2617 * LC_COLLATE locale category as a function of the "lcid"
2618 * parameter instead of the "LC_COLLATE" environment variable. */
2619 if(!(lc_collate_default = setlocale(LC_COLLATE, NULL)))
2621 ERR("Unable to query the LC_COLLATE catagory\n");
2622 SetLastError(ERROR_INVALID_PARAMETER);
2623 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2624 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2625 return 0;
2628 if(!(lc_collate_env = setlocale(LC_COLLATE, "")))
2630 ERR("Unable to inherit the LC_COLLATE locale category from the "
2631 "environment. The \"LC_COLLATE\" environment variable is "
2632 "\"%s\".\n", getenv("LC_COLLATE") ?
2633 getenv("LC_COLLATE") : "<unset>");
2634 SetLastError(ERROR_INVALID_PARAMETER);
2635 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2636 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2637 return 0;
2640 TRACE_(string)("lc_collate_default = %s\n", lc_collate_default);
2641 TRACE_(string)("lc_collate_env = %s\n", lc_collate_env);
2643 /* Convert the libc Unicode string to a native multibyte character
2644 * string. */
2645 returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1;
2646 if(returned_len == 0)
2648 LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(),
2649 0, srcstr);
2650 ERR("wcstombs failed. The string specified (%s) may contains an "
2651 "invalid character.\n", srcstr_ascii);
2652 SetLastError(ERROR_INVALID_PARAMETER);
2653 if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii);
2654 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2655 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2656 setlocale(LC_COLLATE, lc_collate_default);
2657 return 0;
2659 else if(returned_len > src_native_len)
2661 src_native[src_native_len - 1] = 0;
2662 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2663 "than expected (%d bytes).\n", src_native, returned_len,
2664 dst_native_len);
2666 /* Since this is an internal error I'm not sure what the correct
2667 * error code is. */
2668 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2670 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2671 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2672 setlocale(LC_COLLATE, lc_collate_default);
2673 return 0;
2675 src_native_len = returned_len;
2677 TRACE_(string)("src_native = %s src_native_len = %d\n",
2678 src_native, src_native_len);
2680 /* dst_native seems to contain at most 4 bytes for each byte in
2681 * the original src_native string. Change if need be since this
2682 * isn't documented by the strxfrm() man page. */
2683 dst_native_len = 4 * src_native_len;
2684 if(!(dst_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0, dst_native_len)))
2686 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len);
2687 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2688 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2689 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2690 setlocale(LC_COLLATE, lc_collate_default);
2691 return 0;
2694 /* The actual translation is done by the following call to
2695 * strxfrm(). The surrounding code could have been simplified
2696 * by calling wcsxfrm() instead except that wcsxfrm() is not
2697 * available on older Linux systems (RedHat 4.1 with
2698 * libc-5.3.12-17).
2700 * Also, it is possible that the translation could be done by
2701 * various tables as it is done in LCMapStringA(). However, I'm
2702 * not sure what those tables are. */
2703 returned_len = strxfrm(dst_native, src_native, dst_native_len) + 1;
2705 if(returned_len > dst_native_len)
2707 dst_native[dst_native_len - 1] = 0;
2708 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2709 "than expected (%d bytes).\n", dst_native, returned_len,
2710 dst_native_len);
2712 /* Since this is an internal error I'm not sure what the correct
2713 * error code is. */
2714 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2716 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2717 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2718 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2719 setlocale(LC_COLLATE, lc_collate_default);
2720 return 0;
2722 dst_native_len = returned_len;
2724 TRACE_(string)("dst_native = %s dst_native_len = %d\n",
2725 dst_native, dst_native_len);
2727 dststr_libc_len = dst_native_len;
2728 if(!(dststr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2729 dststr_libc_len * sizeof(wchar_t))))
2731 ERR("Unable to allocate %d bytes for dststr_libc\n",
2732 dststr_libc_len * sizeof(wchar_t));
2733 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2734 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2735 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2736 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2737 setlocale(LC_COLLATE, lc_collate_default);
2738 return 0;
2741 /* Convert the native multibyte string to a libc Unicode string. */
2742 returned_len = mbstowcs(dststr_libc, dst_native, dst_native_len) + 1;
2744 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2745 * function has returned. */
2746 setlocale(LC_COLLATE, lc_collate_default);
2748 if(returned_len == 0)
2750 ERR("mbstowcs failed. The native version of the translated string "
2751 "(%s) may contain an invalid character.\n", dst_native);
2752 SetLastError(ERROR_INVALID_PARAMETER);
2753 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2754 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2755 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2756 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2757 return 0;
2759 if(dstlen)
2761 if(returned_len > dstlen)
2763 ERR("mbstowcs returned a string that was longer (%d chars) "
2764 "than the buffer provided (%d chars).\n", returned_len,
2765 dstlen);
2766 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2767 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2768 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2769 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2770 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2771 return 0;
2773 dstlen = returned_len;
2775 /* Convert a libc Unicode string to the destination string. */
2776 for(str_idx = 0; str_idx < dstlen; str_idx++)
2778 dststr[str_idx] = dststr_libc[str_idx];
2780 TRACE_(string)("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2781 *(((int *)dststr) + 0),
2782 *(((int *)dststr) + 1),
2783 *(((int *)dststr) + 2),
2784 *(((int *)dststr) + 3));
2786 else
2788 dstlen = returned_len;
2790 TRACE_(string)("dstlen (return) = %d\n", dstlen);
2791 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2792 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2793 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2794 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2795 return dstlen;
2797 else
2799 int (*f)(int)=identity;
2801 if (dstlen==0)
2802 return srclen;
2803 if (dstlen<srclen)
2805 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2806 return 0;
2809 if (mapflags & LCMAP_UPPERCASE)
2810 f = toupper;
2811 else if (mapflags & LCMAP_LOWERCASE)
2812 f = tolower;
2813 for (i=0; i < srclen; i++)
2814 dststr[i] = (WCHAR) f(srcstr[i]);
2815 return srclen;
2820 /***********************************************************************
2821 * OLE2NLS_EstimateMappingLength
2823 * Estimates the number of characters required to hold the string
2824 * computed by LCMapStringA.
2826 * The size is always over-estimated, with a fixed limit on the
2827 * amount of estimation error.
2829 * Note that len == -1 is not permitted.
2831 static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
2832 LPCSTR str, DWORD len)
2834 /* Estimate only for small strings to keep the estimation error from
2835 * becoming too large. */
2836 if (len < 128) return len * 8 + 5;
2837 else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
2840 /******************************************************************************
2841 * CompareStringA [KERNEL32.143]
2842 * Compares two strings using locale
2844 * RETURNS
2846 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2847 * failure: 0
2849 * NOTES
2851 * Defaults to a word sort, but uses a string sort if
2852 * SORT_STRINGSORT is set.
2853 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2855 * BUGS
2857 * This implementation ignores the locale
2859 * FIXME
2861 * Quite inefficient.
2863 UINT WINAPI CompareStringA(
2864 DWORD lcid, /* locale ID */
2865 DWORD fdwStyle, /* comparison-style options */
2866 LPCSTR s1, /* first string */
2867 DWORD l1, /* length of first string */
2868 LPCSTR s2, /* second string */
2869 DWORD l2) /* length of second string */
2871 int mapstring_flags;
2872 int len1,len2;
2873 int result;
2874 LPSTR sk1,sk2;
2875 TRACE("%s and %s\n",
2876 debugstr_a (s1), debugstr_a (s2));
2878 if ( (s1==NULL) || (s2==NULL) )
2880 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
2881 SetLastError(ERROR_INVALID_PARAMETER);
2882 return 0;
2885 if(fdwStyle & NORM_IGNORESYMBOLS)
2886 FIXME("IGNORESYMBOLS not supported\n");
2888 if (l1 == -1) l1 = lstrlenA(s1);
2889 if (l2 == -1) l2 = lstrlenA(s2);
2891 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2892 len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
2893 len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
2895 if ((len1==0)||(len2==0))
2896 return 0; /* something wrong happened */
2898 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
2899 sk2 = sk1 + len1;
2900 if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
2901 || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2903 ERR("Bug in LCmapStringA.\n");
2904 result = 0;
2906 else
2908 /* strcmp doesn't necessarily return -1, 0, or 1 */
2909 result = strcmp(sk1,sk2);
2911 HeapFree(GetProcessHeap(),0,sk1);
2913 if (result < 0)
2914 return 1;
2915 if (result == 0)
2916 return 2;
2918 /* must be greater, if we reach this point */
2919 return 3;
2922 /******************************************************************************
2923 * CompareStringW [KERNEL32.144]
2924 * This implementation ignores the locale
2925 * FIXME : Does only string sort. Should
2926 * be reimplemented the same way as CompareStringA.
2928 UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
2929 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2931 int len,ret;
2932 if(fdwStyle & NORM_IGNORENONSPACE)
2933 FIXME("IGNORENONSPACE not supprted\n");
2934 if(fdwStyle & NORM_IGNORESYMBOLS)
2935 FIXME("IGNORESYMBOLS not supported\n");
2937 /* Is strcmp defaulting to string sort or to word sort?? */
2938 /* FIXME: Handle NORM_STRINGSORT */
2939 l1 = (l1==-1)?lstrlenW(s1):l1;
2940 l2 = (l2==-1)?lstrlenW(s2):l2;
2941 len = l1<l2 ? l1:l2;
2942 ret = (fdwStyle & NORM_IGNORECASE) ? strncmpiW(s1,s2,len) : strncmpW(s1,s2,len);
2943 /* not equal, return 1 or 3 */
2944 if(ret!=0) return ret+2;
2945 /* same len, return 2 */
2946 if(l1==l2) return 2;
2947 /* the longer one is lexically greater */
2948 return (l1<l2)? 1 : 3;
2951 /******************************************************************************
2952 * OLE_GetFormatA [Internal]
2954 * FIXME
2955 * If datelen == 0, it should return the reguired string length.
2957 This function implements stuff for GetDateFormat() and
2958 GetTimeFormat().
2960 d single-digit (no leading zero) day (of month)
2961 dd two-digit day (of month)
2962 ddd short day-of-week name
2963 dddd long day-of-week name
2964 M single-digit month
2965 MM two-digit month
2966 MMM short month name
2967 MMMM full month name
2968 y two-digit year, no leading 0
2969 yy two-digit year
2970 yyyy four-digit year
2971 gg era string
2972 h hours with no leading zero (12-hour)
2973 hh hours with full two digits
2974 H hours with no leading zero (24-hour)
2975 HH hours with full two digits
2976 m minutes with no leading zero
2977 mm minutes with full two digits
2978 s seconds with no leading zero
2979 ss seconds with full two digits
2980 t time marker (A or P)
2981 tt time marker (AM, PM)
2982 '' used to quote literal characters
2983 '' (within a quoted string) indicates a literal '
2985 These functions REQUIRE valid locale, date, and format.
2987 static INT OLE_GetFormatA(LCID locale,
2988 DWORD flags,
2989 DWORD tflags,
2990 LPSYSTEMTIME xtime,
2991 LPCSTR _format, /*in*/
2992 LPSTR date, /*out*/
2993 INT datelen)
2995 INT inpos, outpos;
2996 int count, type, inquote, Overflow;
2997 char buf[40];
2998 char format[40];
2999 char * pos;
3000 int buflen;
3002 const char * _dgfmt[] = { "%d", "%02d" };
3003 const char ** dgfmt = _dgfmt - 1;
3005 /* report, for debugging */
3006 TRACE("(0x%lx,0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
3007 locale, flags, tflags,
3008 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
3009 _format, _format, date, datelen);
3011 if(datelen == 0) {
3012 FIXME("datelen = 0, returning 255\n");
3013 return 255;
3016 /* initalize state variables and output buffer */
3017 inpos = outpos = 0;
3018 count = 0; inquote = 0; Overflow = 0;
3019 type = '\0';
3020 date[0] = buf[0] = '\0';
3022 strcpy(format,_format);
3024 /* alter the formatstring, while it works for all languages now in wine
3025 its possible that it fails when the time looks like ss:mm:hh as example*/
3026 if (tflags & (TIME_NOMINUTESORSECONDS))
3027 { if ((pos = strstr ( format, ":mm")))
3028 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
3031 if (tflags & (TIME_NOSECONDS))
3032 { if ((pos = strstr ( format, ":ss")))
3033 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
3037 for (inpos = 0;; inpos++) {
3038 /* 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]); */
3039 if (inquote) {
3040 if (format[inpos] == '\'') {
3041 if (format[inpos+1] == '\'') {
3042 inpos += 1;
3043 date[outpos++] = '\'';
3044 } else {
3045 inquote = 0;
3046 continue; /* we did nothing to the output */
3048 } else if (format[inpos] == '\0') {
3049 date[outpos++] = '\0';
3050 if (outpos > datelen) Overflow = 1;
3051 break;
3052 } else {
3053 date[outpos++] = format[inpos];
3054 if (outpos > datelen) {
3055 Overflow = 1;
3056 date[outpos-1] = '\0'; /* this is the last place where
3057 it's safe to write */
3058 break;
3061 } else if ( (count && (format[inpos] != type))
3062 || count == 4
3063 || (count == 2 && strchr("ghHmst", type)) )
3065 if (type == 'd') {
3066 if (count == 4) {
3067 GetLocaleInfoA(locale,
3068 LOCALE_SDAYNAME1
3069 + xtime->wDayOfWeek - 1,
3070 buf, sizeof(buf));
3071 } else if (count == 3) {
3072 GetLocaleInfoA(locale,
3073 LOCALE_SABBREVDAYNAME1
3074 + xtime->wDayOfWeek - 1,
3075 buf, sizeof(buf));
3076 } else {
3077 sprintf(buf, dgfmt[count], xtime->wDay);
3079 } else if (type == 'M') {
3080 if (count == 3) {
3081 GetLocaleInfoA(locale,
3082 LOCALE_SABBREVMONTHNAME1
3083 + xtime->wMonth - 1,
3084 buf, sizeof(buf));
3085 } else if (count == 4) {
3086 GetLocaleInfoA(locale,
3087 LOCALE_SMONTHNAME1
3088 + xtime->wMonth - 1,
3089 buf, sizeof(buf));
3090 } else {
3091 sprintf(buf, dgfmt[count], xtime->wMonth);
3093 } else if (type == 'y') {
3094 if (count == 4) {
3095 sprintf(buf, "%d", xtime->wYear);
3096 } else if (count == 3) {
3097 strcpy(buf, "yyy");
3098 WARN("unknown format, c=%c, n=%d\n", type, count);
3099 } else {
3100 sprintf(buf, dgfmt[count], xtime->wYear % 100);
3102 } else if (type == 'g') {
3103 if (count == 2) {
3104 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
3105 strcpy(buf, "AD");
3106 } else {
3107 strcpy(buf, "g");
3108 WARN("unknown format, c=%c, n=%d\n", type, count);
3110 } else if (type == 'h') {
3111 /* gives us hours 1:00 -- 12:00 */
3112 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
3113 } else if (type == 'H') {
3114 /* 24-hour time */
3115 sprintf(buf, dgfmt[count], xtime->wHour);
3116 } else if ( type == 'm') {
3117 sprintf(buf, dgfmt[count], xtime->wMinute);
3118 } else if ( type == 's') {
3119 sprintf(buf, dgfmt[count], xtime->wSecond);
3120 } else if (type == 't') {
3121 if (count == 1) {
3122 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
3123 } else if (count == 2) {
3124 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
3125 GetLocaleInfoA(locale,
3126 (xtime->wHour<12)
3127 ? LOCALE_S1159 : LOCALE_S2359,
3128 buf, sizeof(buf));
3132 /* we need to check the next char in the format string
3133 again, no matter what happened */
3134 inpos--;
3136 /* add the contents of buf to the output */
3137 buflen = strlen(buf);
3138 if (outpos + buflen < datelen) {
3139 date[outpos] = '\0'; /* for strcat to hook onto */
3140 strcat(date, buf);
3141 outpos += buflen;
3142 } else {
3143 date[outpos] = '\0';
3144 strncat(date, buf, datelen - outpos);
3145 date[datelen - 1] = '\0';
3146 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3147 WARN("insufficient buffer\n");
3148 return 0;
3151 /* reset the variables we used to keep track of this item */
3152 count = 0;
3153 type = '\0';
3154 } else if (format[inpos] == '\0') {
3155 /* we can't check for this at the loop-head, because
3156 that breaks the printing of the last format-item */
3157 date[outpos] = '\0';
3158 break;
3159 } else if (count) {
3160 /* continuing a code for an item */
3161 count +=1;
3162 continue;
3163 } else if (strchr("hHmstyMdg", format[inpos])) {
3164 type = format[inpos];
3165 count = 1;
3166 continue;
3167 } else if (format[inpos] == '\'') {
3168 inquote = 1;
3169 continue;
3170 } else {
3171 date[outpos++] = format[inpos];
3173 /* now deal with a possible buffer overflow */
3174 if (outpos >= datelen) {
3175 date[datelen - 1] = '\0';
3176 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3177 return 0;
3181 if (Overflow) {
3182 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3185 /* finish it off with a string terminator */
3186 outpos++;
3187 /* sanity check */
3188 if (outpos > datelen-1) outpos = datelen-1;
3189 date[outpos] = '\0';
3191 TRACE("OLE_GetFormatA returns string '%s', len %d\n",
3192 date, outpos);
3193 return outpos;
3196 /******************************************************************************
3197 * OLE_GetFormatW [INTERNAL]
3199 static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
3200 LPSYSTEMTIME xtime,
3201 LPCWSTR format,
3202 LPWSTR output, INT outlen)
3204 INT inpos, outpos;
3205 int count, type=0, inquote;
3206 int Overflow; /* loop check */
3207 WCHAR buf[40];
3208 int buflen=0;
3209 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
3210 WCHAR arg2[] = {'%','0','2','d',0};
3211 WCHAR *argarr[3];
3212 int datevars=0, timevars=0;
3214 argarr[0] = arg0;
3215 argarr[1] = arg1;
3216 argarr[2] = arg2;
3218 /* make a debug report */
3219 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
3220 "%p with max len %d\n",
3221 locale, flags, tflags,
3222 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
3223 debugstr_w(format), format, output, outlen);
3225 if(outlen == 0) {
3226 FIXME("outlen = 0, returning 255\n");
3227 return 255;
3230 /* initialize state variables */
3231 inpos = outpos = 0;
3232 count = 0;
3233 inquote = Overflow = 0;
3234 /* this is really just a sanity check */
3235 output[0] = buf[0] = 0;
3237 /* this loop is the core of the function */
3238 for (inpos = 0; /* we have several break points */ ; inpos++) {
3239 if (inquote) {
3240 if (format[inpos] == (WCHAR) '\'') {
3241 if (format[inpos+1] == '\'') {
3242 inpos++;
3243 output[outpos++] = '\'';
3244 } else {
3245 inquote = 0;
3246 continue;
3248 } else if (format[inpos] == 0) {
3249 output[outpos++] = 0;
3250 if (outpos > outlen) Overflow = 1;
3251 break; /* normal exit (within a quote) */
3252 } else {
3253 output[outpos++] = format[inpos]; /* copy input */
3254 if (outpos > outlen) {
3255 Overflow = 1;
3256 output[outpos-1] = 0;
3257 break;
3260 } else if ( (count && (format[inpos] != type))
3261 || ( (count==4 && type =='y') ||
3262 (count==4 && type =='M') ||
3263 (count==4 && type =='d') ||
3264 (count==2 && type =='g') ||
3265 (count==2 && type =='h') ||
3266 (count==2 && type =='H') ||
3267 (count==2 && type =='m') ||
3268 (count==2 && type =='s') ||
3269 (count==2 && type =='t') ) ) {
3270 if (type == 'd') {
3271 if (count == 3) {
3272 GetLocaleInfoW(locale,
3273 LOCALE_SDAYNAME1 + xtime->wDayOfWeek -1,
3274 buf, sizeof(buf)/sizeof(WCHAR) );
3275 } else if (count == 3) {
3276 GetLocaleInfoW(locale,
3277 LOCALE_SABBREVDAYNAME1 +
3278 xtime->wDayOfWeek -1,
3279 buf, sizeof(buf)/sizeof(WCHAR) );
3280 } else {
3281 wsnprintfW(buf, 5, argarr[count], xtime->wDay );
3283 } else if (type == 'M') {
3284 if (count == 4) {
3285 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
3286 xtime->wMonth -1, buf,
3287 sizeof(buf)/sizeof(WCHAR) );
3288 } else if (count == 3) {
3289 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
3290 xtime->wMonth -1, buf,
3291 sizeof(buf)/sizeof(WCHAR) );
3292 } else {
3293 wsnprintfW(buf, 5, argarr[count], xtime->wMonth);
3295 } else if (type == 'y') {
3296 if (count == 4) {
3297 wsnprintfW(buf, 6, argarr[1] /* "%d" */,
3298 xtime->wYear);
3299 } else if (count == 3) {
3300 lstrcpynAtoW(buf, "yyy", 5);
3301 } else {
3302 wsnprintfW(buf, 6, argarr[count],
3303 xtime->wYear % 100);
3305 } else if (type == 'g') {
3306 if (count == 2) {
3307 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
3308 lstrcpynAtoW(buf, "AD", 5);
3309 } else {
3310 /* Win API sez we copy it verbatim */
3311 lstrcpynAtoW(buf, "g", 5);
3313 } else if (type == 'h') {
3314 /* hours 1:00-12:00 --- is this right? */
3315 wsnprintfW(buf, 5, argarr[count],
3316 (xtime->wHour-1)%12 +1);
3317 } else if (type == 'H') {
3318 wsnprintfW(buf, 5, argarr[count],
3319 xtime->wHour);
3320 } else if (type == 'm' ) {
3321 wsnprintfW(buf, 5, argarr[count],
3322 xtime->wMinute);
3323 } else if (type == 's' ) {
3324 wsnprintfW(buf, 5, argarr[count],
3325 xtime->wSecond);
3326 } else if (type == 't') {
3327 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
3328 LOCALE_S1159 : LOCALE_S2359,
3329 buf, sizeof(buf) );
3330 if (count == 1) {
3331 buf[1] = 0;
3335 /* no matter what happened, we need to check this next
3336 character the next time we loop through */
3337 inpos--;
3339 /* cat buf onto the output */
3340 outlen = lstrlenW(buf);
3341 if (outpos + buflen < outlen) {
3342 lstrcpyW( output + outpos, buf );
3343 outpos += buflen;
3344 } else {
3345 lstrcpynW( output + outpos, buf, outlen - outpos );
3346 Overflow = 1;
3347 break; /* Abnormal exit */
3350 /* reset the variables we used this time */
3351 count = 0;
3352 type = '\0';
3353 } else if (format[inpos] == 0) {
3354 /* we can't check for this at the beginning, because that
3355 would keep us from printing a format spec that ended the
3356 string */
3357 output[outpos] = 0;
3358 break; /* NORMAL EXIT */
3359 } else if (count) {
3360 /* how we keep track of the middle of a format spec */
3361 count++;
3362 continue;
3363 } else if ( (datevars && (format[inpos]=='d' ||
3364 format[inpos]=='M' ||
3365 format[inpos]=='y' ||
3366 format[inpos]=='g') ) ||
3367 (timevars && (format[inpos]=='H' ||
3368 format[inpos]=='h' ||
3369 format[inpos]=='m' ||
3370 format[inpos]=='s' ||
3371 format[inpos]=='t') ) ) {
3372 type = format[inpos];
3373 count = 1;
3374 continue;
3375 } else if (format[inpos] == '\'') {
3376 inquote = 1;
3377 continue;
3378 } else {
3379 /* unquoted literals */
3380 output[outpos++] = format[inpos];
3384 if (Overflow) {
3385 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3386 WARN(" buffer overflow\n");
3389 /* final string terminator and sanity check */
3390 outpos++;
3391 if (outpos > outlen-1) outpos = outlen-1;
3392 output[outpos] = '0';
3394 TRACE(" returning %s\n", debugstr_w(output));
3396 return (!Overflow) ? outlen : 0;
3401 /******************************************************************************
3402 * GetDateFormatA [KERNEL32.310]
3403 * Makes an ASCII string of the date
3405 * This function uses format to format the date, or, if format
3406 * is NULL, uses the default for the locale. format is a string
3407 * of literal fields and characters as follows:
3409 * - d single-digit (no leading zero) day (of month)
3410 * - dd two-digit day (of month)
3411 * - ddd short day-of-week name
3412 * - dddd long day-of-week name
3413 * - M single-digit month
3414 * - MM two-digit month
3415 * - MMM short month name
3416 * - MMMM full month name
3417 * - y two-digit year, no leading 0
3418 * - yy two-digit year
3419 * - yyyy four-digit year
3420 * - gg era string
3423 INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
3424 LPSYSTEMTIME xtime,
3425 LPCSTR format, LPSTR date,INT datelen)
3428 char format_buf[40];
3429 LPCSTR thisformat;
3430 SYSTEMTIME t;
3431 LPSYSTEMTIME thistime;
3432 LCID thislocale;
3433 INT ret;
3435 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
3436 locale,flags,xtime,format,date,datelen);
3438 if (!locale) {
3439 locale = LOCALE_SYSTEM_DEFAULT;
3442 if (locale == LOCALE_SYSTEM_DEFAULT) {
3443 thislocale = GetSystemDefaultLCID();
3444 } else if (locale == LOCALE_USER_DEFAULT) {
3445 thislocale = GetUserDefaultLCID();
3446 } else {
3447 thislocale = locale;
3450 if (xtime == NULL) {
3451 GetSystemTime(&t);
3452 thistime = &t;
3453 } else {
3454 thistime = xtime;
3457 if (format == NULL) {
3458 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
3459 ? LOCALE_SLONGDATE
3460 : LOCALE_SSHORTDATE),
3461 format_buf, sizeof(format_buf));
3462 thisformat = format_buf;
3463 } else {
3464 thisformat = format;
3468 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
3469 date, datelen);
3472 TRACE(
3473 "GetDateFormatA() returning %d, with data=%s\n",
3474 ret, date);
3475 return ret;
3478 /******************************************************************************
3479 * GetDateFormatW [KERNEL32.311]
3480 * Makes a Unicode string of the date
3482 * Acts the same as GetDateFormatA(), except that it's Unicode.
3483 * Accepts & returns sizes as counts of Unicode characters.
3486 INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
3487 LPSYSTEMTIME xtime,
3488 LPCWSTR format,
3489 LPWSTR date, INT datelen)
3491 unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
3493 FIXME("STUB (should call OLE_GetFormatW)\n");
3494 lstrcpynW(date, datearr, datelen);
3495 return ( datelen < 9) ? datelen : 9;
3500 /**************************************************************************
3501 * EnumDateFormatsA (KERNEL32.198)
3503 BOOL WINAPI EnumDateFormatsA(
3504 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3506 LCID Loc = GetUserDefaultLCID();
3507 if(!lpDateFmtEnumProc)
3509 SetLastError(ERROR_INVALID_PARAMETER);
3510 return FALSE;
3513 switch( Loc )
3516 case 0x00000407: /* (Loc,"de_DE") */
3518 switch(dwFlags)
3520 case DATE_SHORTDATE:
3521 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3522 if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
3523 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3524 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3525 return TRUE;
3526 case DATE_LONGDATE:
3527 if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
3528 if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
3529 if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
3530 return TRUE;
3531 default:
3532 FIXME("Unknown date format (%ld)\n", dwFlags);
3533 SetLastError(ERROR_INVALID_PARAMETER);
3534 return FALSE;
3538 case 0x0000040c: /* (Loc,"fr_FR") */
3540 switch(dwFlags)
3542 case DATE_SHORTDATE:
3543 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3544 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3545 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3546 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3547 return TRUE;
3548 case DATE_LONGDATE:
3549 if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
3550 if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
3551 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3552 return TRUE;
3553 default:
3554 FIXME("Unknown date format (%ld)\n", dwFlags);
3555 SetLastError(ERROR_INVALID_PARAMETER);
3556 return FALSE;
3560 case 0x00000c0c: /* (Loc,"fr_CA") */
3562 switch(dwFlags)
3564 case DATE_SHORTDATE:
3565 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3566 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3567 if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
3568 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3569 return TRUE;
3570 case DATE_LONGDATE:
3571 if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
3572 if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
3573 return TRUE;
3574 default:
3575 FIXME("Unknown date format (%ld)\n", dwFlags);
3576 SetLastError(ERROR_INVALID_PARAMETER);
3577 return FALSE;
3581 case 0x00000809: /* (Loc,"en_UK") */
3583 switch(dwFlags)
3585 case DATE_SHORTDATE:
3586 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3587 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3588 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3589 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3590 return TRUE;
3591 case DATE_LONGDATE:
3592 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3593 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3594 return TRUE;
3595 default:
3596 FIXME("Unknown date format (%ld)\n", dwFlags);
3597 SetLastError(ERROR_INVALID_PARAMETER);
3598 return FALSE;
3602 case 0x00000c09: /* (Loc,"en_AU") */
3604 switch(dwFlags)
3606 case DATE_SHORTDATE:
3607 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3608 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3609 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3610 return TRUE;
3611 case DATE_LONGDATE:
3612 if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
3613 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3614 return TRUE;
3615 default:
3616 FIXME("Unknown date format (%ld)\n", dwFlags);
3617 SetLastError(ERROR_INVALID_PARAMETER);
3618 return FALSE;
3622 case 0x00001009: /* (Loc,"en_CA") */
3624 switch(dwFlags)
3626 case DATE_SHORTDATE:
3627 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3628 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3629 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3630 if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
3631 return TRUE;
3632 case DATE_LONGDATE:
3633 if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
3634 if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
3635 return TRUE;
3636 default:
3637 FIXME("Unknown date format (%ld)\n", dwFlags);
3638 SetLastError(ERROR_INVALID_PARAMETER);
3639 return FALSE;
3643 case 0x00001409: /* (Loc,"en_NZ") */
3645 switch(dwFlags)
3647 case DATE_SHORTDATE:
3648 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3649 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3650 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3651 return TRUE;
3652 case DATE_LONGDATE:
3653 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3654 if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
3655 return TRUE;
3656 default:
3657 FIXME("Unknown date format (%ld)\n", dwFlags);
3658 SetLastError(ERROR_INVALID_PARAMETER);
3659 return FALSE;
3663 case 0x00001809: /* (Loc,"en_IE") */
3665 switch(dwFlags)
3667 case DATE_SHORTDATE:
3668 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3669 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3670 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3671 return TRUE;
3672 case DATE_LONGDATE:
3673 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3674 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3675 return TRUE;
3676 default:
3677 FIXME("Unknown date format (%ld)\n", dwFlags);
3678 SetLastError(ERROR_INVALID_PARAMETER);
3679 return FALSE;
3683 case 0x00001c09: /* (Loc,"en_ZA") */
3685 switch(dwFlags)
3687 case DATE_SHORTDATE:
3688 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3689 return TRUE;
3690 case DATE_LONGDATE:
3691 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3692 return TRUE;
3693 default:
3694 FIXME("Unknown date format (%ld)\n", dwFlags);
3695 SetLastError(ERROR_INVALID_PARAMETER);
3696 return FALSE;
3700 case 0x00002009: /* (Loc,"en_JM") */
3702 switch(dwFlags)
3704 case DATE_SHORTDATE:
3705 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3706 return TRUE;
3707 case DATE_LONGDATE:
3708 if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
3709 if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
3710 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
3711 if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
3712 return TRUE;
3713 default:
3714 FIXME("Unknown date format (%ld)\n", dwFlags);
3715 SetLastError(ERROR_INVALID_PARAMETER);
3716 return FALSE;
3720 case 0x00002809: /* (Loc,"en_BZ") */
3721 case 0x00002c09: /* (Loc,"en_TT") */
3723 switch(dwFlags)
3725 case DATE_SHORTDATE:
3726 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3727 return TRUE;
3728 case DATE_LONGDATE:
3729 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
3730 return TRUE;
3731 default:
3732 FIXME("Unknown date format (%ld)\n", dwFlags);
3733 SetLastError(ERROR_INVALID_PARAMETER);
3734 return FALSE;
3738 default: /* default to US English "en_US" */
3740 switch(dwFlags)
3742 case DATE_SHORTDATE:
3743 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
3744 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
3745 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
3746 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
3747 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3748 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
3749 return TRUE;
3750 case DATE_LONGDATE:
3751 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
3752 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
3753 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
3754 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
3755 return TRUE;
3756 default:
3757 FIXME("Unknown date format (%ld)\n", dwFlags);
3758 SetLastError(ERROR_INVALID_PARAMETER);
3759 return FALSE;
3765 /**************************************************************************
3766 * EnumDateFormatsW (KERNEL32.199)
3768 BOOL WINAPI EnumDateFormatsW(
3769 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3771 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
3772 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3773 return FALSE;
3776 /**************************************************************************
3777 * EnumTimeFormatsA (KERNEL32.210)
3779 BOOL WINAPI EnumTimeFormatsA(
3780 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3782 LCID Loc = GetUserDefaultLCID();
3783 if(!lpTimeFmtEnumProc)
3785 SetLastError(ERROR_INVALID_PARAMETER);
3786 return FALSE;
3788 if(dwFlags)
3790 FIXME("Unknown time format (%ld)\n", dwFlags);
3793 switch( Loc )
3795 case 0x00000407: /* (Loc,"de_DE") */
3797 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3798 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3799 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3800 if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
3801 if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
3802 return TRUE;
3805 case 0x0000040c: /* (Loc,"fr_FR") */
3806 case 0x00000c0c: /* (Loc,"fr_CA") */
3808 if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
3809 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3810 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3811 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3812 if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
3813 return TRUE;
3816 case 0x00000809: /* (Loc,"en_UK") */
3817 case 0x00000c09: /* (Loc,"en_AU") */
3818 case 0x00001409: /* (Loc,"en_NZ") */
3819 case 0x00001809: /* (Loc,"en_IE") */
3821 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3822 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3823 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3824 return TRUE;
3827 case 0x00001c09: /* (Loc,"en_ZA") */
3828 case 0x00002809: /* (Loc,"en_BZ") */
3829 case 0x00002c09: /* (Loc,"en_TT") */
3831 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3832 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3833 return TRUE;
3836 default: /* default to US style "en_US" */
3838 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3839 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3840 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3841 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3842 return TRUE;
3847 /**************************************************************************
3848 * EnumTimeFormatsW (KERNEL32.211)
3850 BOOL WINAPI EnumTimeFormatsW(
3851 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3853 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
3854 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3855 return FALSE;
3858 /**************************************************************************
3859 * This function is used just locally !
3860 * Description: Inverts a string.
3862 static void OLE_InvertString(char* string)
3864 char sTmpArray[128];
3865 INT counter, i = 0;
3867 for (counter = strlen(string); counter > 0; counter--)
3869 memcpy(sTmpArray + i, string + counter-1, 1);
3870 i++;
3872 memcpy(sTmpArray + i, "\0", 1);
3873 strcpy(string, sTmpArray);
3876 /***************************************************************************************
3877 * This function is used just locally !
3878 * Description: Test if the given string (psNumber) is valid or not.
3879 * The valid characters are the following:
3880 * - Characters '0' through '9'.
3881 * - One decimal point (dot) if the number is a floating-point value.
3882 * - A minus sign in the first character position if the number is
3883 * a negative value.
3884 * If the function succeeds, psBefore/psAfter will point to the string
3885 * on the right/left of the decimal symbol. pbNegative indicates if the
3886 * number is negative.
3888 static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
3890 char sNumberSet[] = "0123456789";
3891 BOOL bInDecimal = FALSE;
3893 /* Test if we do have a minus sign */
3894 if ( *pInput == '-' )
3896 *pbNegative = TRUE;
3897 pInput++; /* Jump to the next character. */
3900 while(*pInput != '\0')
3902 /* Do we have a valid numeric character */
3903 if ( strchr(sNumberSet, *pInput) != NULL )
3905 if (bInDecimal == TRUE)
3906 *psAfter++ = *pInput;
3907 else
3908 *psBefore++ = *pInput;
3910 else
3912 /* Is this a decimal point (dot) */
3913 if ( *pInput == '.' )
3915 /* Is it the first time we find it */
3916 if ((bInDecimal == FALSE))
3917 bInDecimal = TRUE;
3918 else
3919 return -1; /* ERROR: Invalid parameter */
3921 else
3923 /* It's neither a numeric character, nor a decimal point.
3924 * Thus, return an error.
3926 return -1;
3929 pInput++;
3932 /* Add an End of Line character to the output buffers */
3933 *psBefore = '\0';
3934 *psAfter = '\0';
3936 return 0;
3939 /**************************************************************************
3940 * This function is used just locally !
3941 * Description: A number could be formatted using different numbers
3942 * of "digits in group" (example: 4;3;2;0).
3943 * The first parameter of this function is an array
3944 * containing the rule to be used. It's format is the following:
3945 * |NDG|DG1|DG2|...|0|
3946 * where NDG is the number of used "digits in group" and DG1, DG2,
3947 * are the corresponding "digits in group".
3948 * Thus, this function returns the grouping value in the array
3949 * pointed by the second parameter.
3951 static INT OLE_GetGrouping(char* sRule, INT index)
3953 char sData[2], sRuleSize[2];
3954 INT nData, nRuleSize;
3956 memcpy(sRuleSize, sRule, 1);
3957 memcpy(sRuleSize+1, "\0", 1);
3958 nRuleSize = atoi(sRuleSize);
3960 if (index > 0 && index < nRuleSize)
3962 memcpy(sData, sRule+index, 1);
3963 memcpy(sData+1, "\0", 1);
3964 nData = atoi(sData);
3967 else
3969 memcpy(sData, sRule+nRuleSize-1, 1);
3970 memcpy(sData+1, "\0", 1);
3971 nData = atoi(sData);
3974 return nData;
3977 /**************************************************************************
3978 * GetNumberFormatA (KERNEL32.355)
3980 INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
3981 LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
3982 LPSTR lpNumberStr, int cchNumber)
3984 char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
3985 INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
3986 char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
3987 char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
3988 char *pStr = NULL, *pTmpStr = NULL;
3989 LCID systemDefaultLCID;
3990 BOOL bNegative = FALSE;
3991 enum Operations
3993 USE_PARAMETER,
3994 USE_LOCALEINFO,
3995 USE_SYSTEMDEFAULT,
3996 RETURN_ERROR
3997 } used_operation;
3999 strncpy(sNumber, lpvalue, 128);
4000 sNumber[127] = '\0';
4002 /* Make sure we have a valid input string, get the number
4003 * of digits before and after the decimal symbol, and check
4004 * if this is a negative number.
4006 if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
4008 nNumberDecimal = strlen(sDigitsBeforeDecimal);
4009 nDigits = strlen(sDigitsAfterDecimal);
4011 else
4013 SetLastError(ERROR_INVALID_PARAMETER);
4014 return 0;
4017 /* Which source will we use to format the string */
4018 used_operation = RETURN_ERROR;
4019 if (lpFormat != NULL)
4021 if (dwflags == 0)
4022 used_operation = USE_PARAMETER;
4024 else
4026 if (dwflags & LOCALE_NOUSEROVERRIDE)
4027 used_operation = USE_LOCALEINFO;
4028 else
4029 used_operation = USE_SYSTEMDEFAULT;
4032 /* Load the fields we need */
4033 switch(used_operation)
4035 case USE_LOCALEINFO:
4036 GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
4037 GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
4038 GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
4039 GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
4040 GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
4041 GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
4042 break;
4043 case USE_PARAMETER:
4044 sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
4045 strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
4046 sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
4047 strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
4048 sprintf(sILZero, "%d",lpFormat->LeadingZero);
4049 sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
4050 break;
4051 case USE_SYSTEMDEFAULT:
4052 systemDefaultLCID = GetSystemDefaultLCID();
4053 GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
4054 GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
4055 GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
4056 GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
4057 GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
4058 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
4059 break;
4060 default:
4061 SetLastError(ERROR_INVALID_PARAMETER);
4062 return 0;
4065 nNumberDigits = atoi(sNumberDigits);
4067 /* Remove the ";" */
4068 i=0;
4069 j = 1;
4070 for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
4072 if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
4074 memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
4075 i++;
4076 j++;
4079 sprintf(sBuffer, "%d", i);
4080 memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
4081 memcpy(sRule + j, "\0", 1);
4083 /* First, format the digits before the decimal. */
4084 if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
4086 /* Working on an inverted string is easier ! */
4087 OLE_InvertString(sDigitsBeforeDecimal);
4089 nStep = nCounter = i = j = 0;
4090 nRuleIndex = 1;
4091 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
4093 /* Here, we will loop until we reach the end of the string.
4094 * An internal counter (j) is used in order to know when to
4095 * insert the "digit group symbol".
4097 while (nNumberDecimal > 0)
4099 i = nCounter + nStep;
4100 memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
4101 nCounter++;
4102 j++;
4103 if (j >= nGrouping)
4105 j = 0;
4106 if (nRuleIndex < sRule[0])
4107 nRuleIndex++;
4108 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
4109 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
4110 nStep+= strlen(sDigitGroupSymbol);
4113 nNumberDecimal--;
4116 memcpy(sDestination + i+1, "\0", 1);
4117 /* Get the string in the right order ! */
4118 OLE_InvertString(sDestination);
4120 else
4122 nLZ = atoi(sILZero);
4123 if (nLZ != 0)
4125 /* Use 0.xxx instead of .xxx */
4126 memcpy(sDestination, "0", 1);
4127 memcpy(sDestination+1, "\0", 1);
4129 else
4130 memcpy(sDestination, "\0", 1);
4134 /* Second, format the digits after the decimal. */
4135 j = 0;
4136 nCounter = nNumberDigits;
4137 if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
4139 i = strlen(sNumber) - strlen(pStr) + 1;
4140 strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
4141 j = strlen(sDigitsAfterDecimal);
4142 if (j < nNumberDigits)
4143 nCounter = nNumberDigits-j;
4145 for (i=0;i<nCounter;i++)
4146 memcpy(sDigitsAfterDecimal+i+j, "0", 1);
4147 memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
4149 i = strlen(sDestination);
4150 j = strlen(sDigitsAfterDecimal);
4151 /* Finally, construct the resulting formatted string. */
4153 for (nCounter=0; nCounter<i; nCounter++)
4154 memcpy(sNumber + nCounter, sDestination + nCounter, 1);
4156 memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
4158 for (i=0; i<j; i++)
4159 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
4160 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
4162 /* Is it a negative number */
4163 if (bNegative == TRUE)
4165 i = atoi(sNegNumber);
4166 pStr = sDestination;
4167 pTmpStr = sNumber;
4168 switch (i)
4170 case 0:
4171 *pStr++ = '(';
4172 while (*sNumber != '\0')
4173 *pStr++ = *pTmpStr++;
4174 *pStr++ = ')';
4175 break;
4176 case 1:
4177 *pStr++ = '-';
4178 while (*pTmpStr != '\0')
4179 *pStr++ = *pTmpStr++;
4180 break;
4181 case 2:
4182 *pStr++ = '-';
4183 *pStr++ = ' ';
4184 while (*pTmpStr != '\0')
4185 *pStr++ = *pTmpStr++;
4186 break;
4187 case 3:
4188 while (*pTmpStr != '\0')
4189 *pStr++ = *pTmpStr++;
4190 *pStr++ = '-';
4191 break;
4192 case 4:
4193 while (*pTmpStr != '\0')
4194 *pStr++ = *pTmpStr++;
4195 *pStr++ = ' ';
4196 *pStr++ = '-';
4197 break;
4198 default:
4199 while (*pTmpStr != '\0')
4200 *pStr++ = *pTmpStr++;
4201 break;
4204 else
4205 strcpy(sDestination, sNumber);
4207 /* If cchNumber is zero, then returns the number of bytes or characters
4208 * required to hold the formatted number string
4210 if (cchNumber==0)
4211 retVal = strlen(sDestination) + 1;
4212 else
4214 strncpy (lpNumberStr, sDestination, cchNumber-1);
4215 *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
4216 retVal = strlen(lpNumberStr);
4219 return retVal;
4222 /**************************************************************************
4223 * GetNumberFormatW (KERNEL32.xxx)
4225 INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
4226 LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
4227 LPWSTR lpNumberStr, int cchNumber)
4229 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue));
4231 lstrcpynW( lpNumberStr, lpvalue, cchNumber );
4232 return cchNumber? lstrlenW( lpNumberStr ) : 0;
4235 /**************************************************************************
4236 * GetCurrencyFormatA (KERNEL32.302)
4238 INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
4239 LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
4240 LPSTR lpCurrencyStr, int cchCurrency)
4242 UINT nPosOrder, nNegOrder;
4243 INT retVal;
4244 char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
4245 char *pDestination = sDestination;
4246 char sNumberFormated[128];
4247 char *pNumberFormated = sNumberFormated;
4248 LCID systemDefaultLCID;
4249 BOOL bIsPositive = FALSE, bValidFormat = FALSE;
4250 enum Operations
4252 USE_PARAMETER,
4253 USE_LOCALEINFO,
4254 USE_SYSTEMDEFAULT,
4255 RETURN_ERROR
4256 } used_operation;
4258 NUMBERFMTA numberFmt;
4260 /* Which source will we use to format the string */
4261 used_operation = RETURN_ERROR;
4262 if (lpFormat != NULL)
4264 if (dwflags == 0)
4265 used_operation = USE_PARAMETER;
4267 else
4269 if (dwflags & LOCALE_NOUSEROVERRIDE)
4270 used_operation = USE_LOCALEINFO;
4271 else
4272 used_operation = USE_SYSTEMDEFAULT;
4275 /* Load the fields we need */
4276 switch(used_operation)
4278 case USE_LOCALEINFO:
4279 /* Specific to CURRENCYFMTA*/
4280 GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
4281 GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
4282 GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
4284 nPosOrder = atoi(sPosOrder);
4285 nNegOrder = atoi(sNegOrder);
4286 break;
4287 case USE_PARAMETER:
4288 /* Specific to CURRENCYFMTA*/
4289 nNegOrder = lpFormat->NegativeOrder;
4290 nPosOrder = lpFormat->PositiveOrder;
4291 strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
4292 break;
4293 case USE_SYSTEMDEFAULT:
4294 systemDefaultLCID = GetSystemDefaultLCID();
4295 /* Specific to CURRENCYFMTA*/
4296 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
4297 GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
4298 GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
4300 nPosOrder = atoi(sPosOrder);
4301 nNegOrder = atoi(sNegOrder);
4302 break;
4303 default:
4304 SetLastError(ERROR_INVALID_PARAMETER);
4305 return 0;
4308 /* Construct a temporary number format structure */
4309 if (lpFormat != NULL)
4311 numberFmt.NumDigits = lpFormat->NumDigits;
4312 numberFmt.LeadingZero = lpFormat->LeadingZero;
4313 numberFmt.Grouping = lpFormat->Grouping;
4314 numberFmt.NegativeOrder = 0;
4315 numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
4316 numberFmt.lpThousandSep = lpFormat->lpThousandSep;
4317 bValidFormat = TRUE;
4320 /* Make a call to GetNumberFormatA() */
4321 if (*lpvalue == '-')
4323 bIsPositive = FALSE;
4324 retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
4326 else
4328 bIsPositive = TRUE;
4329 retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
4332 if (retVal == 0)
4333 return 0;
4335 /* construct the formatted string */
4336 if (bIsPositive)
4338 switch (nPosOrder)
4340 case 0: /* Prefix, no separation */
4341 strcpy (pDestination, sCurrencySymbol);
4342 strcat (pDestination, pNumberFormated);
4343 break;
4344 case 1: /* Suffix, no separation */
4345 strcpy (pDestination, pNumberFormated);
4346 strcat (pDestination, sCurrencySymbol);
4347 break;
4348 case 2: /* Prefix, 1 char separation */
4349 strcpy (pDestination, sCurrencySymbol);
4350 strcat (pDestination, " ");
4351 strcat (pDestination, pNumberFormated);
4352 break;
4353 case 3: /* Suffix, 1 char separation */
4354 strcpy (pDestination, pNumberFormated);
4355 strcat (pDestination, " ");
4356 strcat (pDestination, sCurrencySymbol);
4357 break;
4358 default:
4359 SetLastError(ERROR_INVALID_PARAMETER);
4360 return 0;
4363 else /* negative number */
4365 switch (nNegOrder)
4367 case 0: /* format: ($1.1) */
4368 strcpy (pDestination, "(");
4369 strcat (pDestination, sCurrencySymbol);
4370 strcat (pDestination, pNumberFormated);
4371 strcat (pDestination, ")");
4372 break;
4373 case 1: /* format: -$1.1 */
4374 strcpy (pDestination, "-");
4375 strcat (pDestination, sCurrencySymbol);
4376 strcat (pDestination, pNumberFormated);
4377 break;
4378 case 2: /* format: $-1.1 */
4379 strcpy (pDestination, sCurrencySymbol);
4380 strcat (pDestination, "-");
4381 strcat (pDestination, pNumberFormated);
4382 break;
4383 case 3: /* format: $1.1- */
4384 strcpy (pDestination, sCurrencySymbol);
4385 strcat (pDestination, pNumberFormated);
4386 strcat (pDestination, "-");
4387 break;
4388 case 4: /* format: (1.1$) */
4389 strcpy (pDestination, "(");
4390 strcat (pDestination, pNumberFormated);
4391 strcat (pDestination, sCurrencySymbol);
4392 strcat (pDestination, ")");
4393 break;
4394 case 5: /* format: -1.1$ */
4395 strcpy (pDestination, "-");
4396 strcat (pDestination, pNumberFormated);
4397 strcat (pDestination, sCurrencySymbol);
4398 break;
4399 case 6: /* format: 1.1-$ */
4400 strcpy (pDestination, pNumberFormated);
4401 strcat (pDestination, "-");
4402 strcat (pDestination, sCurrencySymbol);
4403 break;
4404 case 7: /* format: 1.1$- */
4405 strcpy (pDestination, pNumberFormated);
4406 strcat (pDestination, sCurrencySymbol);
4407 strcat (pDestination, "-");
4408 break;
4409 case 8: /* format: -1.1 $ */
4410 strcpy (pDestination, "-");
4411 strcat (pDestination, pNumberFormated);
4412 strcat (pDestination, " ");
4413 strcat (pDestination, sCurrencySymbol);
4414 break;
4415 case 9: /* format: -$ 1.1 */
4416 strcpy (pDestination, "-");
4417 strcat (pDestination, sCurrencySymbol);
4418 strcat (pDestination, " ");
4419 strcat (pDestination, pNumberFormated);
4420 break;
4421 case 10: /* format: 1.1 $- */
4422 strcpy (pDestination, pNumberFormated);
4423 strcat (pDestination, " ");
4424 strcat (pDestination, sCurrencySymbol);
4425 strcat (pDestination, "-");
4426 break;
4427 case 11: /* format: $ 1.1- */
4428 strcpy (pDestination, sCurrencySymbol);
4429 strcat (pDestination, " ");
4430 strcat (pDestination, pNumberFormated);
4431 strcat (pDestination, "-");
4432 break;
4433 case 12: /* format: $ -1.1 */
4434 strcpy (pDestination, sCurrencySymbol);
4435 strcat (pDestination, " ");
4436 strcat (pDestination, "-");
4437 strcat (pDestination, pNumberFormated);
4438 break;
4439 case 13: /* format: 1.1- $ */
4440 strcpy (pDestination, pNumberFormated);
4441 strcat (pDestination, "-");
4442 strcat (pDestination, " ");
4443 strcat (pDestination, sCurrencySymbol);
4444 break;
4445 case 14: /* format: ($ 1.1) */
4446 strcpy (pDestination, "(");
4447 strcat (pDestination, sCurrencySymbol);
4448 strcat (pDestination, " ");
4449 strcat (pDestination, pNumberFormated);
4450 strcat (pDestination, ")");
4451 break;
4452 case 15: /* format: (1.1 $) */
4453 strcpy (pDestination, "(");
4454 strcat (pDestination, pNumberFormated);
4455 strcat (pDestination, " ");
4456 strcat (pDestination, sCurrencySymbol);
4457 strcat (pDestination, ")");
4458 break;
4459 default:
4460 SetLastError(ERROR_INVALID_PARAMETER);
4461 return 0;
4465 if (cchCurrency == 0)
4466 return strlen(pDestination) + 1;
4468 else
4470 strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
4471 *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
4472 return strlen(lpCurrencyStr);
4476 /**************************************************************************
4477 * GetCurrencyFormatW (KERNEL32.303)
4479 INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
4480 LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
4481 LPWSTR lpCurrencyStr, int cchCurrency)
4483 FIXME("This API function is NOT implemented !\n");
4484 return 0;
4487 /******************************************************************************
4488 * OLE2NLS_CheckLocale [intern]
4490 static LCID OLE2NLS_CheckLocale (LCID locale)
4492 if (!locale)
4493 { locale = LOCALE_SYSTEM_DEFAULT;
4496 if (locale == LOCALE_SYSTEM_DEFAULT)
4497 { return GetSystemDefaultLCID();
4499 else if (locale == LOCALE_USER_DEFAULT)
4500 { return GetUserDefaultLCID();
4502 else
4503 { return locale;
4506 /******************************************************************************
4507 * GetTimeFormatA [KERNEL32.422]
4508 * Makes an ASCII string of the time
4510 * Formats date according to format, or locale default if format is
4511 * NULL. The format consists of literal characters and fields as follows:
4513 * h hours with no leading zero (12-hour)
4514 * hh hours with full two digits
4515 * H hours with no leading zero (24-hour)
4516 * HH hours with full two digits
4517 * m minutes with no leading zero
4518 * mm minutes with full two digits
4519 * s seconds with no leading zero
4520 * ss seconds with full two digits
4521 * t time marker (A or P)
4522 * tt time marker (AM, PM)
4525 INT WINAPI
4526 GetTimeFormatA(LCID locale, /* in */
4527 DWORD flags, /* in */
4528 LPSYSTEMTIME xtime, /* in */
4529 LPCSTR format, /* in */
4530 LPSTR timestr, /* out */
4531 INT timelen /* in */)
4532 { char format_buf[40];
4533 LPCSTR thisformat;
4534 SYSTEMTIME t;
4535 LPSYSTEMTIME thistime;
4536 LCID thislocale=0;
4537 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4538 INT ret;
4540 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
4542 thislocale = OLE2NLS_CheckLocale ( locale );
4544 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
4545 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4548 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
4550 if (format == NULL)
4551 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4552 { thislocale = GetSystemDefaultLCID();
4554 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
4555 thisformat = format_buf;
4557 else
4558 { thisformat = format;
4561 if (xtime == NULL) /* NULL means use the current local time*/
4562 { GetLocalTime(&t);
4563 thistime = &t;
4565 else
4566 { thistime = xtime;
4568 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
4569 timestr, timelen);
4570 return ret;
4574 /******************************************************************************
4575 * GetTimeFormatW [KERNEL32.423]
4576 * Makes a Unicode string of the time
4578 INT WINAPI
4579 GetTimeFormatW(LCID locale, /* in */
4580 DWORD flags, /* in */
4581 LPSYSTEMTIME xtime, /* in */
4582 LPCWSTR format, /* in */
4583 LPWSTR timestr, /* out */
4584 INT timelen /* in */)
4585 { WCHAR format_buf[40];
4586 LPCWSTR thisformat;
4587 SYSTEMTIME t;
4588 LPSYSTEMTIME thistime;
4589 LCID thislocale=0;
4590 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4591 INT ret;
4593 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
4594 xtime,debugstr_w(format),timestr,timelen);
4596 thislocale = OLE2NLS_CheckLocale ( locale );
4598 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
4599 { FIXME("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
4602 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
4604 if (format == NULL)
4605 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4606 { thislocale = GetSystemDefaultLCID();
4608 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
4609 thisformat = format_buf;
4611 else
4612 { thisformat = format;
4615 if (xtime == NULL) /* NULL means use the current local time*/
4616 { GetSystemTime(&t);
4617 thistime = &t;
4619 else
4620 { thistime = xtime;
4623 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
4624 timestr, timelen);
4625 return ret;
4628 /******************************************************************************
4629 * EnumCalendarInfoA [KERNEL32.196]
4631 BOOL WINAPI EnumCalendarInfoA(
4632 CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
4634 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);
4635 return FALSE;