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