ReactOS 0.4.15-dev-6703-g6528ab8
lang.c
Go to the documentation of this file.
1/*
2 * Locale support
3 *
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
7 * Copyright 2002 Alexandre Julliard for CodeWeavers
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <k32.h>
25
26#define NDEBUG
27#include <debug.h>
29
30#include "lcformat_private.h"
31#ifdef __REACTOS__
32 #include "japanese.h"
33#endif
34
35#undef WINVER
36#define WINVER DLL_EXPORT_VERSION
37
38/* From winnls.h */
39#define LOCALE_NAME_USER_DEFAULT NULL
40
41#define REG_SZ 1
42extern int wine_fold_string(int flags, const WCHAR *src, int srclen, WCHAR *dst, int dstlen);
43extern int wine_get_sortkey(int flags, const WCHAR *src, int srclen, char *dst, int dstlen);
44extern int wine_compare_string(int flags, const WCHAR *str1, int len1, const WCHAR *str2, int len2);
45#ifdef __REACTOS__
47#else
49#endif
50#define NLSRC_OFFSET 5000 /* FIXME */
51
53
54#define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|\
55 LOCALE_RETURN_NUMBER|LOCALE_RETURN_GENITIVE_NAMES)
56
57static const WCHAR szLocaleKeyName[] = {
58 '\\', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', '\\',
59 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
60 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
61 'C','o','n','t','r','o','l','\\','N','l','s','\\','L','o','c','a','l','e',0
62};
63
64static const WCHAR szLangGroupsKeyName[] = {
65 '\\', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', '\\',
66 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
67 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
68 'C','o','n','t','r','o','l','\\','N','l','s','\\',
69 'L','a','n','g','u','a','g','e',' ','G','r','o','u','p','s',0
70};
71
72#if (WINVER >= 0x0600)
73/* Charset to codepage map, sorted by name. */
74static const struct charset_entry
75{
76 const char *charset_name;
78} charset_names[] =
79{
80 { "BIG5", 950 },
81 { "CP1250", 1250 },
82 { "CP1251", 1251 },
83 { "CP1252", 1252 },
84 { "CP1253", 1253 },
85 { "CP1254", 1254 },
86 { "CP1255", 1255 },
87 { "CP1256", 1256 },
88 { "CP1257", 1257 },
89 { "CP1258", 1258 },
90 { "CP932", 932 },
91 { "CP936", 936 },
92 { "CP949", 949 },
93 { "CP950", 950 },
94 { "EUCJP", 20932 },
95 { "GB2312", 936 },
96 { "IBM037", 37 },
97 { "IBM1026", 1026 },
98 { "IBM424", 424 },
99 { "IBM437", 437 },
100 { "IBM500", 500 },
101 { "IBM850", 850 },
102 { "IBM852", 852 },
103 { "IBM855", 855 },
104 { "IBM857", 857 },
105 { "IBM860", 860 },
106 { "IBM861", 861 },
107 { "IBM862", 862 },
108 { "IBM863", 863 },
109 { "IBM864", 864 },
110 { "IBM865", 865 },
111 { "IBM866", 866 },
112 { "IBM869", 869 },
113 { "IBM874", 874 },
114 { "IBM875", 875 },
115 { "ISO88591", 28591 },
116 { "ISO885910", 28600 },
117 { "ISO885913", 28603 },
118 { "ISO885914", 28604 },
119 { "ISO885915", 28605 },
120 { "ISO885916", 28606 },
121 { "ISO88592", 28592 },
122 { "ISO88593", 28593 },
123 { "ISO88594", 28594 },
124 { "ISO88595", 28595 },
125 { "ISO88596", 28596 },
126 { "ISO88597", 28597 },
127 { "ISO88598", 28598 },
128 { "ISO88599", 28599 },
129 { "KOI8R", 20866 },
130 { "KOI8U", 21866 },
131 { "UTF8", CP_UTF8 }
132};
133#endif
134
136{
137 WCHAR win_name[128]; /* Windows name ("en-US") */
138 WCHAR lang[128]; /* language ("en") (note: buffer contains the other strings too) */
139 WCHAR *country; /* country ("US") */
140 WCHAR *charset; /* charset ("UTF-8") for Unix format only */
141 WCHAR *script; /* script ("Latn") for Windows format only */
142 WCHAR *modifier; /* modifier or sort order */
143 LCID lcid; /* corresponding LCID */
144 int matches; /* number of elements matching LCID (0..4) */
145 UINT codepage; /* codepage corresponding to charset */
146};
147
148/* locale ids corresponding to the various Unix locale parameters */
157
158static const WCHAR iCalendarTypeW[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
159static const WCHAR iCountryW[] = {'i','C','o','u','n','t','r','y',0};
160static const WCHAR iCurrDigitsW[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
161static const WCHAR iCurrencyW[] = {'i','C','u','r','r','e','n','c','y',0};
162static const WCHAR iDateW[] = {'i','D','a','t','e',0};
163static const WCHAR iDigitsW[] = {'i','D','i','g','i','t','s',0};
164static const WCHAR iFirstDayOfWeekW[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
165static const WCHAR iFirstWeekOfYearW[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
166static const WCHAR iLDateW[] = {'i','L','D','a','t','e',0};
167static const WCHAR iLZeroW[] = {'i','L','Z','e','r','o',0};
168static const WCHAR iMeasureW[] = {'i','M','e','a','s','u','r','e',0};
169static const WCHAR iNegCurrW[] = {'i','N','e','g','C','u','r','r',0};
170static const WCHAR iNegNumberW[] = {'i','N','e','g','N','u','m','b','e','r',0};
171static const WCHAR iPaperSizeW[] = {'i','P','a','p','e','r','S','i','z','e',0};
172static const WCHAR iTLZeroW[] = {'i','T','L','Z','e','r','o',0};
173static const WCHAR iTimePrefixW[] = {'i','T','i','m','e','P','r','e','f','i','x',0};
174static const WCHAR iTimeW[] = {'i','T','i','m','e',0};
175static const WCHAR s1159W[] = {'s','1','1','5','9',0};
176static const WCHAR s2359W[] = {'s','2','3','5','9',0};
177static const WCHAR sCountryW[] = {'s','C','o','u','n','t','r','y',0};
178static const WCHAR sCurrencyW[] = {'s','C','u','r','r','e','n','c','y',0};
179static const WCHAR sDateW[] = {'s','D','a','t','e',0};
180static const WCHAR sDecimalW[] = {'s','D','e','c','i','m','a','l',0};
181static const WCHAR sGroupingW[] = {'s','G','r','o','u','p','i','n','g',0};
182static const WCHAR sLanguageW[] = {'s','L','a','n','g','u','a','g','e',0};
183static const WCHAR sListW[] = {'s','L','i','s','t',0};
184static const WCHAR sLongDateW[] = {'s','L','o','n','g','D','a','t','e',0};
185static const WCHAR sMonDecimalSepW[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
186static const WCHAR sMonGroupingW[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
187static const WCHAR sMonThousandSepW[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
188static const WCHAR sNativeDigitsW[] = {'s','N','a','t','i','v','e','D','i','g','i','t','s',0};
189static const WCHAR sNegativeSignW[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
190static const WCHAR sPositiveSignW[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
191static const WCHAR sShortDateW[] = {'s','S','h','o','r','t','D','a','t','e',0};
192static const WCHAR sThousandW[] = {'s','T','h','o','u','s','a','n','d',0};
193static const WCHAR sTimeFormatW[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
194static const WCHAR sTimeW[] = {'s','T','i','m','e',0};
195static const WCHAR sYearMonthW[] = {'s','Y','e','a','r','M','o','n','t','h',0};
196static const WCHAR NumShapeW[] = {'N','u','m','s','h','a','p','e',0};
197
198static struct registry_value
199{
201 const WCHAR *name;
203} registry_values[] =
204{
215 { LOCALE_IPAPERSIZE, iPaperSizeW },
216 { LOCALE_ITIME, iTimeW },
217 { LOCALE_S1159, s1159W },
218 { LOCALE_S2359, s2359W },
220 { LOCALE_SDATE, sDateW },
223 { LOCALE_SLIST, sListW },
232 { LOCALE_STIME, sTimeW },
234 { LOCALE_SYEARMONTH, sYearMonthW },
235 /* The following are not listed under MSDN as supported,
236 * but seem to be used and also stored in the registry.
237 */
239 { LOCALE_IDATE, iDateW },
244 /* The following are used in XP and later */
245 { LOCALE_IDIGITSUBSTITUTION, NumShapeW },
249
250static RTL_CRITICAL_SECTION cache_section = { NULL, -1, 0, 0, 0, 0 };
251
252#ifndef __REACTOS__
253/* Copy Ascii string to Unicode without using codepages */
254static inline void strcpynAtoW( WCHAR *dst, const char *src, size_t n )
255{
256 while (n > 1 && *src)
257 {
258 *dst++ = (unsigned char)*src++;
259 n--;
260 }
261 if (n) *dst = 0;
262}
263#endif
264
265/***********************************************************************
266 * get_lcid_codepage
267 *
268 * Retrieve the ANSI codepage for a given locale.
269 */
270static inline UINT get_lcid_codepage( LCID lcid )
271{
272 UINT ret;
273 if (!GetLocaleInfoW( lcid, LOCALE_IDEFAULTANSICODEPAGE|LOCALE_RETURN_NUMBER, (WCHAR *)&ret,
274 sizeof(ret)/sizeof(WCHAR) )) ret = 0;
275 return ret;
276}
277
278#if (WINVER >= 0x0600)
279/***********************************************************************
280 * charset_cmp (internal)
281 */
282static int charset_cmp( const void *name, const void *entry )
283{
284 const struct charset_entry *charset = entry;
285 return strcasecmp( name, charset->charset_name );
286}
287
288/***********************************************************************
289 * find_charset
290 */
291static UINT find_charset( const WCHAR *name )
292{
293 const struct charset_entry *entry;
294 char charset_name[16];
295 size_t i, j;
296
297 /* remove punctuation characters from charset name */
298 for (i = j = 0; name[i] && j < sizeof(charset_name)-1; i++)
299 if (isalnum((unsigned char)name[i])) charset_name[j++] = name[i];
300 charset_name[j] = 0;
301
302 entry = bsearch( charset_name, charset_names, ARRAY_SIZE( charset_names ),
303 sizeof(charset_names[0]), charset_cmp );
304 if (entry) return entry->codepage;
305 return 0;
306}
307
308static LANGID get_default_sublang( LANGID lang )
309{
310 switch (lang)
311 {
321 }
323 return lang;
324}
325
326/***********************************************************************
327 * find_locale_id_callback
328 */
329static BOOL CALLBACK find_locale_id_callback( HMODULE hModule, LPCWSTR type,
331{
332 struct locale_name *data = (struct locale_name *)lParam;
333 WCHAR buffer[128];
334 int matches = 0;
335 LCID lcid = MAKELCID( lang, SORT_DEFAULT ); /* FIXME: handle sort order */
336
337 if (PRIMARYLANGID(lang) == LANG_NEUTRAL) return TRUE; /* continue search */
338
339 /* first check exact name */
340 if (data->win_name[0] &&
342 {
343 if (!strcmpiW( data->win_name, buffer ))
344 {
345 matches = 4; /* everything matches */
346 goto done;
347 }
348 }
349
352 return TRUE;
353 if (strcmpiW( buffer, data->lang )) return TRUE;
354 matches++; /* language name matched */
355
356 if (data->script)
357 {
358 if (GetLocaleInfoW( lcid, LOCALE_SSCRIPTS | LOCALE_NOUSEROVERRIDE,
360 {
361 const WCHAR *p = buffer;
362 unsigned int len = strlenW( data->script );
363 while (*p)
364 {
365 if (!strncmpiW( p, data->script, len ) && (!p[len] || p[len] == ';')) break;
366 if (!(p = strchrW( p, ';'))) goto done;
367 p++;
368 }
369 if (!*p) goto done;
370 matches++; /* script matched */
371 }
372 }
373
374 if (data->country)
375 {
378 {
379 if (strcmpiW( buffer, data->country )) goto done;
380 matches++; /* country name matched */
381 }
382 }
383 else /* match default language */
384 {
385 LANGID def_lang = data->script ? lang : MAKELANGID( PRIMARYLANGID(lang), LANG_NEUTRAL );
386 if (lang == get_default_sublang( def_lang )) matches++;
387 }
388
389 if (data->codepage)
390 {
391 UINT unix_cp;
392 if (GetLocaleInfoW( lcid, LOCALE_IDEFAULTUNIXCODEPAGE | LOCALE_RETURN_NUMBER,
393 (LPWSTR)&unix_cp, sizeof(unix_cp)/sizeof(WCHAR) ))
394 {
395 if (unix_cp == data->codepage) matches++;
396 }
397 }
398
399 /* FIXME: check sort order */
400
401done:
402 if (matches > data->matches)
403 {
404 data->lcid = lcid;
405 data->matches = matches;
406 }
407 return (data->matches < 4); /* no need to continue for perfect match */
408}
409
410
411/***********************************************************************
412 * parse_locale_name
413 *
414 * Parse a locale name into a struct locale_name, handling both Windows and Unix formats.
415 * Unix format is: lang[_country][.charset][@modifier]
416 * Windows format is: lang[-script][-country][_modifier]
417 */
418static void parse_locale_name( const WCHAR *str, struct locale_name *name )
419{
420 static const WCHAR sepW[] = {'-','_','.','@',0};
421 static const WCHAR winsepW[] = {'-','_',0};
422 static const WCHAR posixW[] = {'P','O','S','I','X',0};
423 static const WCHAR cW[] = {'C',0};
424 static const WCHAR latinW[] = {'l','a','t','i','n',0};
425 static const WCHAR latnW[] = {'-','L','a','t','n',0};
426 WCHAR *p;
427
428 TRACE("%s\n", debugstr_w(str));
429
430 name->country = name->charset = name->script = name->modifier = NULL;
432 name->matches = 0;
433 name->codepage = 0;
434 name->win_name[0] = 0;
435 lstrcpynW( name->lang, str, ARRAY_SIZE( name->lang ));
436
437 if (!*name->lang)
438 {
439 name->lcid = LOCALE_INVARIANT;
440 name->matches = 4;
441 return;
442 }
443
444 if (!(p = strpbrkW( name->lang, sepW )))
445 {
446 if (!strcmpW( name->lang, posixW ) || !strcmpW( name->lang, cW ))
447 {
448 name->matches = 4; /* perfect match for default English lcid */
449 return;
450 }
451 strcpyW( name->win_name, name->lang );
452 }
453 else if (*p == '-') /* Windows format */
454 {
455 strcpyW( name->win_name, name->lang );
456 *p++ = 0;
457 name->country = p;
458 if ((p = strpbrkW( p, winsepW )) && *p == '-')
459 {
460 *p++ = 0;
461 name->script = name->country;
462 name->country = p;
463 p = strpbrkW( p, winsepW );
464 }
465 if (p)
466 {
467 *p++ = 0;
468 name->modifier = p;
469 }
470 /* second value can be script or country, check length to resolve the ambiguity */
471 if (!name->script && strlenW( name->country ) == 4)
472 {
473 name->script = name->country;
474 name->country = NULL;
475 }
476 }
477 else /* Unix format */
478 {
479 if (*p == '_')
480 {
481 *p++ = 0;
482 name->country = p;
483 p = strpbrkW( p, sepW + 2 );
484 }
485 if (p && *p == '.')
486 {
487 *p++ = 0;
488 name->charset = p;
489 p = strchrW( p, '@' );
490 }
491 if (p)
492 {
493 *p++ = 0;
494 name->modifier = p;
495 }
496
497 if (name->charset)
498 name->codepage = find_charset( name->charset );
499
500 /* rebuild a Windows name if possible */
501
502 if (name->charset) goto done; /* can't specify charset in Windows format */
503 if (name->modifier && strcmpW( name->modifier, latinW ))
504 goto done; /* only Latn script supported for now */
505 strcpyW( name->win_name, name->lang );
506 if (name->modifier) strcatW( name->win_name, latnW );
507 if (name->country)
508 {
509 p = name->win_name + strlenW(name->win_name);
510 *p++ = '-';
511 strcpyW( p, name->country );
512 }
513 }
514done:
516 find_locale_id_callback, (LPARAM)name );
517}
518#endif
519
520/***********************************************************************
521 * convert_default_lcid
522 *
523 * Get the default LCID to use for a given lctype in GetLocaleInfo.
524 */
526{
530 {
531 LCID default_id = 0;
532
533 switch(lctype & 0xffff)
534 {
535 case LOCALE_SSORTNAME:
536 default_id = lcid_LC_COLLATE;
537 break;
538
542 case LOCALE_IDEFAULTEBCDICCODEPAGE:
545 default_id = lcid_LC_CTYPE;
546 break;
547
549 case LOCALE_ICURRENCY:
551 case LOCALE_INEGCURR:
558 case LOCALE_SCURRENCY:
563 case LOCALE_SNATIVECURRNAME:
564 default_id = lcid_LC_MONETARY;
565 break;
566
567 case LOCALE_IDIGITS:
568 case LOCALE_IDIGITSUBSTITUTION:
569 case LOCALE_ILZERO:
571 case LOCALE_SDECIMAL:
572 case LOCALE_SGROUPING:
573 //case LOCALE_SNAN:
576 //case LOCALE_SNEGINFINITY:
577 //case LOCALE_SPOSINFINITY:
579 case LOCALE_STHOUSAND:
580 default_id = lcid_LC_NUMERIC;
581 break;
582
584 case LOCALE_ICENTURY:
585 case LOCALE_IDATE:
586 case LOCALE_IDAYLZERO:
589 case LOCALE_ILDATE:
590 case LOCALE_IMONLZERO:
592 case LOCALE_ITIME:
594 case LOCALE_ITLZERO:
595 case LOCALE_S1159:
596 case LOCALE_S2359:
617 case LOCALE_SDATE:
618 case LOCALE_SDAYNAME1:
619 case LOCALE_SDAYNAME2:
620 case LOCALE_SDAYNAME3:
621 case LOCALE_SDAYNAME4:
622 case LOCALE_SDAYNAME5:
623 case LOCALE_SDAYNAME6:
624 case LOCALE_SDAYNAME7:
625 //case LOCALE_SDURATION:
626 case LOCALE_SLONGDATE:
641 //case LOCALE_SSHORTESTDAYNAME1:
642 //case LOCALE_SSHORTESTDAYNAME2:
643 //case LOCALE_SSHORTESTDAYNAME3:
644 //case LOCALE_SSHORTESTDAYNAME4:
645 //case LOCALE_SSHORTESTDAYNAME5:
646 //case LOCALE_SSHORTESTDAYNAME6:
647 //case LOCALE_SSHORTESTDAYNAME7:
648 case LOCALE_STIME:
650 case LOCALE_SYEARMONTH:
651 default_id = lcid_LC_TIME;
652 break;
653
654 case LOCALE_IPAPERSIZE:
655 default_id = lcid_LC_PAPER;
656 break;
657
658 case LOCALE_IMEASURE:
659 default_id = lcid_LC_MEASUREMENT;
660 break;
661
662 case LOCALE_ICOUNTRY:
663 default_id = lcid_LC_TELEPHONE;
664 break;
665 }
666 if (default_id) lcid = default_id;
667 }
668 return ConvertDefaultLocale( lcid );
669}
670
671/***********************************************************************
672 * is_genitive_name_supported
673 *
674 * Determine could LCTYPE basically support genitive name form or not.
675 */
677{
678 switch(lctype & 0xffff)
679 {
693 return TRUE;
694 default:
695 return FALSE;
696 }
697}
698
699/***********************************************************************
700 * create_registry_key
701 *
702 * Create the Control Panel\\International registry key.
703 */
704static inline HANDLE create_registry_key(void)
705{
706 static const WCHAR cplW[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l',0};
707 static const WCHAR intlW[] = {'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
710 HANDLE cpl_key, hkey = 0;
711
712 if (RtlOpenCurrentUser( KEY_ALL_ACCESS, &hkey ) != STATUS_SUCCESS) return 0;
713
714 attr.Length = sizeof(attr);
715 attr.RootDirectory = hkey;
716 attr.ObjectName = &nameW;
717 attr.Attributes = 0;
718 attr.SecurityDescriptor = NULL;
719 attr.SecurityQualityOfService = NULL;
720 RtlInitUnicodeString( &nameW, cplW );
721
722 if (!NtCreateKey( &cpl_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ))
723 {
724 NtClose( attr.RootDirectory );
725 attr.RootDirectory = cpl_key;
726 RtlInitUnicodeString( &nameW, intlW );
727 if (NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) hkey = 0;
728 }
729 NtClose( attr.RootDirectory );
730 return hkey;
731}
732
733/***********************************************************************
734 * GetUserDefaultLangID (KERNEL32.@)
735 *
736 * Get the default language Id for the current user.
737 *
738 * PARAMS
739 * None.
740 *
741 * RETURNS
742 * The current LANGID of the default language for the current user.
743 */
745{
747}
748
749
750/***********************************************************************
751 * GetSystemDefaultLangID (KERNEL32.@)
752 *
753 * Get the default language Id for the system.
754 *
755 * PARAMS
756 * None.
757 *
758 * RETURNS
759 * The current LANGID of the default language for the system.
760 */
762{
764}
765
766
767/***********************************************************************
768 * GetUserDefaultLCID (KERNEL32.@)
769 *
770 * Get the default locale Id for the current user.
771 *
772 * PARAMS
773 * None.
774 *
775 * RETURNS
776 * The current LCID of the default locale for the current user.
777 */
779{
780 LCID lcid;
782 return lcid;
783}
784
785
786/***********************************************************************
787 * GetSystemDefaultLCID (KERNEL32.@)
788 *
789 * Get the default locale Id for the system.
790 *
791 * PARAMS
792 * None.
793 *
794 * RETURNS
795 * The current LCID of the default locale for the system.
796 */
798{
799 LCID lcid;
801 return lcid;
802}
803
804
805/***********************************************************************
806 * GetUserDefaultUILanguage (KERNEL32.@)
807 *
808 * Get the default user interface language Id for the current user.
809 *
810 * PARAMS
811 * None.
812 *
813 * RETURNS
814 * The current LANGID of the default UI language for the current user.
815 */
817{
818 LANGID lang;
820 return lang;
821}
822
823
824/***********************************************************************
825 * GetSystemDefaultUILanguage (KERNEL32.@)
826 *
827 * Get the default user interface language Id for the system.
828 *
829 * PARAMS
830 * None.
831 *
832 * RETURNS
833 * The current LANGID of the default UI language for the system. This is
834 * typically the same language used during the installation process.
835 */
837{
838 LANGID lang;
840 return lang;
841}
842
843#if (WINVER >= 0x0600)
844/***********************************************************************
845 * LocaleNameToLCID (KERNEL32.@)
846 */
847LCID WINAPI LocaleNameToLCID( LPCWSTR name, DWORD flags )
848{
850 static int once;
851
852 if (flags && !once++)
853 FIXME( "unsupported flags %x\n", flags );
854
856 return GetUserDefaultLCID();
857
858 /* string parsing */
859 parse_locale_name( name, &locale_name );
860
861 TRACE( "found lcid %x for %s, matches %d\n",
863
864 if (!locale_name.matches)
865 {
867 return 0;
868 }
869
870 if (locale_name.matches == 1)
871 WARN( "locale %s not recognized, defaulting to %s\n",
873
874 return locale_name.lcid;
875}
876
877
878/***********************************************************************
879 * LCIDToLocaleName (KERNEL32.@)
880 */
881INT WINAPI LCIDToLocaleName( LCID lcid, LPWSTR name, INT count, DWORD flags )
882{
883 static int once;
884 if (flags && !once++) FIXME( "unsupported flags %x\n", flags );
885
887}
888#endif
889
890/******************************************************************************
891 * get_registry_locale_info
892 *
893 * Retrieve user-modified locale info from the registry.
894 * Return length, 0 on error, -1 if not found.
895 */
897{
898 DWORD size;
899 INT ret;
900 HANDLE hkey;
904 static const int info_size = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
905
907
909 {
910 if (!(hkey = create_registry_key()))
911 {
913 return -1;
914 }
915
917 size = info_size + len * sizeof(WCHAR);
918
919 if (!(info = HeapAlloc( GetProcessHeap(), 0, size )))
920 {
921 NtClose( hkey );
924 return 0;
925 }
926
928
929 /* try again with a bigger buffer when we have to return the correct size */
930 if (status == STATUS_BUFFER_OVERFLOW && !buffer && size > info_size)
931 {
933 if ((new_info = HeapReAlloc( GetProcessHeap(), 0, info, size )))
934 {
935 info = new_info;
937 }
938 }
939
940 NtClose( hkey );
941
942 if (!status)
943 {
944 INT length = (size - info_size) / sizeof(WCHAR);
945 LPWSTR cached_value;
946
947 if (!length || ((WCHAR *)&info->Data)[length-1])
948 length++;
949
950 cached_value = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) );
951
952 if (!cached_value)
953 {
957 return 0;
958 }
959
960 memcpy( cached_value, info->Data, (length-1) * sizeof(WCHAR) );
961 cached_value[length-1] = 0;
963 registry_value->cached_value = cached_value;
964 }
965 else
966 {
968 {
969 ret = (size - info_size) / sizeof(WCHAR);
970 }
972 {
973 ret = -1;
974 }
975 else
976 {
978 ret = 0;
979 }
982 return ret;
983 }
984 }
985
987
988 if (buffer)
989 {
990 if (ret > len)
991 {
993 ret = 0;
994 }
995 else
996 {
998 }
999 }
1000
1002
1003 return ret;
1004}
1005
1006
1007/******************************************************************************
1008 * GetLocaleInfoA (KERNEL32.@)
1009 *
1010 * Get information about an aspect of a locale.
1011 *
1012 * PARAMS
1013 * lcid [I] LCID of the locale
1014 * lctype [I] LCTYPE_ flags from "winnls.h"
1015 * buffer [O] Destination for the information
1016 * len [I] Length of buffer in characters
1017 *
1018 * RETURNS
1019 * Success: The size of the data requested. If buffer is non-NULL, it is filled
1020 * with the information.
1021 * Failure: 0. Use GetLastError() to determine the cause.
1022 *
1023 * NOTES
1024 * - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
1025 * - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
1026 * which is a bit string.
1027 */
1029{
1030 WCHAR *bufferW;
1031 INT lenW, ret;
1032
1033 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid, lctype, buffer, len );
1034
1035 if (len < 0 || (len && !buffer))
1036 {
1038 return 0;
1039 }
1040 if (((lctype & ~LOCALE_LOCALEINFOFLAGSMASK) == LOCALE_SSHORTTIME) ||
1042 {
1044 return 0;
1045 }
1046
1047 if (!len) buffer = NULL;
1048
1049 if (!(lenW = GetLocaleInfoW( lcid, lctype, NULL, 0 ))) return 0;
1050
1051 if (!(bufferW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
1052 {
1054 return 0;
1055 }
1056 if ((ret = GetLocaleInfoW( lcid, lctype, bufferW, lenW )))
1057 {
1058 if ((lctype & LOCALE_RETURN_NUMBER) ||
1060 {
1061 /* it's not an ASCII string, just bytes */
1062 ret *= sizeof(WCHAR);
1063 if (buffer)
1064 {
1065 if (ret <= len) memcpy( buffer, bufferW, ret );
1066 else
1067 {
1069 ret = 0;
1070 }
1071 }
1072 }
1073 else
1074 {
1076 if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
1077 ret = WideCharToMultiByte( codepage, 0, bufferW, ret, buffer, len, NULL, NULL );
1078 }
1079 }
1080 HeapFree( GetProcessHeap(), 0, bufferW );
1081 return ret;
1082}
1083
1085{
1086 return lctype == LOCALE_ILANGUAGE || lctype == LOCALE_IDEFAULTLANGUAGE ? 16 : 10;
1087}
1088
1089/******************************************************************************
1090 * get_locale_registry_value
1091 *
1092 * Gets the registry value name and cache for a given lctype.
1093 */
1095{
1096 int i;
1097 for (i=0; i < sizeof(registry_values)/sizeof(registry_values[0]); i++)
1099 return &registry_values[i];
1100 return NULL;
1101}
1102
1103/******************************************************************************
1104 * GetLocaleInfoW (KERNEL32.@)
1105 *
1106 * See GetLocaleInfoA.
1107 */
1109{
1110 LANGID lang_id;
1111 HRSRC hrsrc;
1112 HGLOBAL hmem;
1113 LPCWSTR lpType, lpName;
1114 INT ret;
1115 UINT lcflags;
1116 const WCHAR *p;
1117 unsigned int i;
1118
1119 if (len < 0 || (len && !buffer))
1120 {
1122 return 0;
1123 }
1126 {
1128 return 0;
1129 }
1130
1131 if (!len) buffer = NULL;
1132
1133 lcid = convert_default_lcid( lcid, lctype );
1134
1136 lctype &= 0xffff;
1137
1138 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid, lctype, buffer, len );
1139
1140 /* first check for overrides in the registry */
1141
1142 if (!(lcflags & LOCALE_NOUSEROVERRIDE) &&
1144 {
1146
1147 if (value)
1148 {
1149 if (lcflags & LOCALE_RETURN_NUMBER)
1150 {
1151 WCHAR tmp[16];
1152 ret = get_registry_locale_info( value, tmp, sizeof(tmp)/sizeof(WCHAR) );
1153 if (ret > 0)
1154 {
1155 WCHAR *end;
1157 if (*end) /* invalid number */
1158 {
1160 return 0;
1161 }
1162 ret = sizeof(UINT)/sizeof(WCHAR);
1163 if (!buffer) return ret;
1164 if (ret > len)
1165 {
1167 return 0;
1168 }
1169 memcpy( buffer, &number, sizeof(number) );
1170 }
1171 }
1173
1174 if (ret != -1) return ret;
1175 }
1176 }
1177
1178 /* now load it from kernel resources */
1179
1180 lang_id = LANGIDFROMLCID( lcid );
1181
1182 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
1183 if (SUBLANGID(lang_id) == SUBLANG_NEUTRAL)
1184 lang_id = MAKELANGID(PRIMARYLANGID(lang_id), SUBLANG_DEFAULT);
1185
1187 {
1188 lpType = MAKEINTRESOURCEW(RT_STRING);
1190 }
1191 else
1192 {
1193 lpType = MAKEINTRESOURCEW(RT_RCDATA);
1195 }
1196
1197 if (!(hrsrc = FindResourceExW( kernel32_handle, lpType, lpName, lang_id )))
1198 {
1199 SetLastError( ERROR_INVALID_FLAGS ); /* no such lctype */
1200 return 0;
1201 }
1202 if (!(hmem = LoadResource( kernel32_handle, hrsrc )))
1203 return 0;
1204
1205 p = LockResource( hmem );
1207 {
1208 for (i = 0; i < (lctype & 0x0f); i++) p += *p + 1;
1209 }
1210
1211 if (lcflags & LOCALE_RETURN_NUMBER) ret = sizeof(UINT)/sizeof(WCHAR);
1212 else if (is_genitive_name_supported( lctype ) && *p)
1213 {
1214 /* genitive form's stored after a null separator from a nominative */
1215 for (i = 1; i <= *p; i++) if (!p[i]) break;
1216
1217 if (i <= *p && (lcflags & LOCALE_RETURN_GENITIVE_NAMES))
1218 {
1219 ret = *p - i + 1;
1220 p += i;
1221 }
1222 else ret = i;
1223 }
1224 else if (lctype != LOCALE_FONTSIGNATURE)
1225 ret = *p + 1;
1226 else
1227 ret = SizeofResource(kernel32_handle, hrsrc) / sizeof(WCHAR);
1228
1229 if (!buffer) return ret;
1230
1231 if (ret > len)
1232 {
1234 return 0;
1235 }
1236
1237 if (lcflags & LOCALE_RETURN_NUMBER)
1238 {
1239 UINT number;
1240 WCHAR *end, *tmp = HeapAlloc( GetProcessHeap(), 0, (*p + 1) * sizeof(WCHAR) );
1241 if (!tmp) return 0;
1242 memcpy( tmp, p + 1, *p * sizeof(WCHAR) );
1243 tmp[*p] = 0;
1245 if (!*end)
1246 memcpy( buffer, &number, sizeof(number) );
1247 else /* invalid number */
1248 {
1250 ret = 0;
1251 }
1252 HeapFree( GetProcessHeap(), 0, tmp );
1253
1254 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning number %d\n",
1255 lcid, lctype, buffer, len, number );
1256 }
1257 else
1258 {
1259 if (lctype != LOCALE_FONTSIGNATURE) p++;
1260 memcpy( buffer, p, ret * sizeof(WCHAR) );
1261 if (lctype != LOCALE_FONTSIGNATURE) buffer[ret-1] = 0;
1262
1263 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning %d %s\n",
1264 lcid, lctype, buffer, len, ret, debugstr_w(buffer) );
1265 }
1266 return ret;
1267}
1268
1269#if (WINVER >= 0x0600)
1271int
1272WINAPI
1273GetLocaleInfoEx(
1274 _In_opt_ LPCWSTR lpLocaleName,
1275 _In_ LCTYPE LCType,
1276 _Out_writes_opt_(cchData) LPWSTR lpLCData,
1277 _In_ int cchData)
1278{
1279 TRACE( "GetLocaleInfoEx not implemented (lcid=%s,lctype=0x%x,%s,%d)\n", debugstr_w(lpLocaleName), LCType, debugstr_w(lpLCData), cchData );
1280 return 0;
1281}
1282
1283BOOL
1284WINAPI
1285IsValidLocaleName(
1286 LPCWSTR lpLocaleName
1287)
1288{
1289 TRACE( "IsValidLocaleName not implemented (lpLocaleName=%s)\n", debugstr_w(lpLocaleName));
1290 return TRUE;
1291}
1292
1293INT
1294WINAPI
1295GetUserDefaultLocaleName(
1296 LPWSTR lpLocaleName,
1297 INT cchLocaleName
1298)
1299{
1300 TRACE( "GetUserDefaultLocaleName not implemented (lpLocaleName=%s, cchLocaleName=%d)\n", debugstr_w(lpLocaleName), cchLocaleName);
1301 return 0;
1302}
1303#endif
1304
1305/******************************************************************************
1306 * SetLocaleInfoA [KERNEL32.@]
1307 *
1308 * Set information about an aspect of a locale.
1309 *
1310 * PARAMS
1311 * lcid [I] LCID of the locale
1312 * lctype [I] LCTYPE_ flags from "winnls.h"
1313 * data [I] Information to set
1314 *
1315 * RETURNS
1316 * Success: TRUE. The information given will be returned by GetLocaleInfoA()
1317 * whenever it is called without LOCALE_NOUSEROVERRIDE.
1318 * Failure: FALSE. Use GetLastError() to determine the cause.
1319 *
1320 * NOTES
1321 * - Values are only be set for the current user locale; the system locale
1322 * settings cannot be changed.
1323 * - Any settings changed by this call are lost when the locale is changed by
1324 * the control panel (in Wine, this happens every time you change LANG).
1325 * - The native implementation of this function does not check that lcid matches
1326 * the current user locale, and simply sets the new values. Wine warns you in
1327 * this case, but behaves the same.
1328 */
1330{
1332 WCHAR *strW;
1333 DWORD len;
1334 BOOL ret;
1335
1337
1338 if (!data)
1339 {
1341 return FALSE;
1342 }
1343 len = MultiByteToWideChar( codepage, 0, data, -1, NULL, 0 );
1344 if (!(strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
1345 {
1347 return FALSE;
1348 }
1350 ret = SetLocaleInfoW( lcid, lctype, strW );
1351 HeapFree( GetProcessHeap(), 0, strW );
1352 return ret;
1353}
1354
1355
1356/******************************************************************************
1357 * SetLocaleInfoW (KERNEL32.@)
1358 *
1359 * See SetLocaleInfoA.
1360 */
1362{
1363 struct registry_value *value;
1364 static const WCHAR intlW[] = {'i','n','t','l',0 };
1367 HANDLE hkey;
1368
1369 lctype &= 0xffff;
1371
1372 if (!data || !value)
1373 {
1375 return FALSE;
1376 }
1377
1379 {
1381 return FALSE;
1382 }
1383
1384 TRACE("setting %x (%s) to %s\n", lctype, debugstr_w(value->name), debugstr_w(data) );
1385
1386 /* FIXME: should check that data to set is sane */
1387
1388 /* FIXME: profile functions should map to registry */
1389 WriteProfileStringW( intlW, value->name, data );
1390
1391 if (!(hkey = create_registry_key())) return FALSE;
1393 status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, (PVOID)data, (strlenW(data)+1)*sizeof(WCHAR) );
1394
1396 HeapFree( GetProcessHeap(), 0, value->cached_value );
1397 value->cached_value = NULL;
1399
1401 {
1402 /* Set I-value from S value */
1403 WCHAR *lpD, *lpM, *lpY;
1404 WCHAR szBuff[2];
1405
1406 lpD = strrchrW(data, 'd');
1407 lpM = strrchrW(data, 'M');
1408 lpY = strrchrW(data, 'y');
1409
1410 if (lpD <= lpM)
1411 {
1412 szBuff[0] = '1'; /* D-M-Y */
1413 }
1414 else
1415 {
1416 if (lpY <= lpM)
1417 szBuff[0] = '2'; /* Y-M-D */
1418 else
1419 szBuff[0] = '0'; /* M-D-Y */
1420 }
1421
1422 szBuff[1] = '\0';
1423
1426 else
1428
1430
1431 WriteProfileStringW( intlW, value->name, szBuff );
1432
1434 status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, szBuff, sizeof(szBuff) );
1435
1437 HeapFree( GetProcessHeap(), 0, value->cached_value );
1438 value->cached_value = NULL;
1440 }
1441
1442 NtClose( hkey );
1443
1445 return !status;
1446}
1447
1448/***********************************************************************
1449 * GetThreadLocale (KERNEL32.@)
1450 *
1451 * Get the current threads locale.
1452 *
1453 * PARAMS
1454 * None.
1455 *
1456 * RETURNS
1457 * The LCID currently associated with the calling thread.
1458 */
1460{
1461 LCID ret = NtCurrentTeb()->CurrentLocale;
1462 if (!ret) NtCurrentTeb()->CurrentLocale = ret = GetUserDefaultLCID();
1463 return ret;
1464}
1465
1466/**********************************************************************
1467 * SetThreadLocale (KERNEL32.@)
1468 *
1469 * Set the current threads locale.
1470 *
1471 * PARAMS
1472 * lcid [I] LCID of the locale to set
1473 *
1474 * RETURNS
1475 * Success: TRUE. The threads locale is set to lcid.
1476 * Failure: FALSE. Use GetLastError() to determine the cause.
1477 */
1479{
1480 TRACE("(0x%04X)\n", lcid);
1481
1482 lcid = ConvertDefaultLocale(lcid);
1483
1484 if (lcid != GetThreadLocale())
1485 {
1486 if (!IsValidLocale(lcid, LCID_SUPPORTED))
1487 {
1489 return FALSE;
1490 }
1491
1492 NtCurrentTeb()->CurrentLocale = lcid;
1493 }
1494 return TRUE;
1495}
1496
1497/******************************************************************************
1498 * ConvertDefaultLocale (KERNEL32.@)
1499 *
1500 * Convert a default locale identifier into a real identifier.
1501 *
1502 * PARAMS
1503 * lcid [I] LCID identifier of the locale to convert
1504 *
1505 * RETURNS
1506 * lcid unchanged, if not a default locale or its sublanguage is
1507 * not SUBLANG_NEUTRAL.
1508 * GetSystemDefaultLCID(), if lcid == LOCALE_SYSTEM_DEFAULT.
1509 * GetUserDefaultLCID(), if lcid == LOCALE_USER_DEFAULT or LOCALE_NEUTRAL.
1510 * Otherwise, lcid with sublanguage changed to SUBLANG_DEFAULT.
1511 */
1513{
1514 LANGID langid;
1515
1516 switch (lcid)
1517 {
1518 case LOCALE_INVARIANT:
1519 /* keep as-is */
1520 break;
1522 lcid = GetSystemDefaultLCID();
1523 break;
1525 case LOCALE_NEUTRAL:
1526 lcid = GetUserDefaultLCID();
1527 break;
1528 default:
1529 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
1530 langid = LANGIDFROMLCID(lcid);
1532 {
1534 lcid = MAKELCID(langid, SORTIDFROMLCID(lcid));
1535 }
1536 }
1537 return lcid;
1538}
1539
1540
1541/******************************************************************************
1542 * IsValidLocale (KERNEL32.@)
1543 *
1544 * Determine if a locale is valid.
1545 *
1546 * PARAMS
1547 * lcid [I] LCID of the locale to check
1548 * flags [I] LCID_SUPPORTED = Valid, LCID_INSTALLED = Valid and installed on the system
1549 *
1550 * RETURNS
1551 * TRUE, if lcid is valid,
1552 * FALSE, otherwise.
1553 *
1554 * NOTES
1555 * Wine does not currently make the distinction between supported and installed. All
1556 * languages supported are installed by default.
1557 */
1559{
1560 /* check if language is registered in the kernel32 resources */
1563}
1564
1565
1568{
1569 LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
1570 char buf[20];
1571
1572 sprintf(buf, "%08x", (UINT)LangID);
1573 return lpfnLocaleEnum( buf );
1574}
1575
1578{
1579 static const WCHAR formatW[] = {'%','0','8','x',0};
1580 LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
1581 WCHAR buf[20];
1582 sprintfW( buf, formatW, (UINT)LangID );
1583 return lpfnLocaleEnum( buf );
1584}
1585
1586/******************************************************************************
1587 * EnumSystemLocalesA (KERNEL32.@)
1588 *
1589 * Call a users function for each locale available on the system.
1590 *
1591 * PARAMS
1592 * lpfnLocaleEnum [I] Callback function to call for each locale
1593 * dwFlags [I] LOCALE_SUPPORTED=All supported, LOCALE_INSTALLED=Installed only
1594 *
1595 * RETURNS
1596 * Success: TRUE.
1597 * Failure: FALSE. Use GetLastError() to determine the cause.
1598 */
1600{
1601 TRACE("(%p,%08x)\n", lpfnLocaleEnum, dwFlags);
1604 (LONG_PTR)lpfnLocaleEnum);
1605 return TRUE;
1606}
1607
1608
1609/******************************************************************************
1610 * EnumSystemLocalesW (KERNEL32.@)
1611 *
1612 * See EnumSystemLocalesA.
1613 */
1615{
1616 TRACE("(%p,%08x)\n", lpfnLocaleEnum, dwFlags);
1619 (LONG_PTR)lpfnLocaleEnum);
1620 return TRUE;
1621}
1622
1623
1625{
1629};
1630
1633{
1635 WCHAR buffer[256];
1636 DWORD neutral;
1637 unsigned int flags;
1638
1642 LOCALE_INEUTRAL | LOCALE_NOUSEROVERRIDE | LOCALE_RETURN_NUMBER,
1643 (LPWSTR)&neutral, sizeof(neutral) / sizeof(WCHAR) ))
1644 neutral = 0;
1647 if (data->flags && !(data->flags & flags)) return TRUE;
1648 return data->proc( buffer, flags, data->lparam );
1649}
1650
1651/******************************************************************************
1652 * EnumSystemLocalesEx (KERNEL32.@)
1653 */
1655{
1657
1658 if (reserved)
1659 {
1661 return FALSE;
1662 }
1663 data.proc = proc;
1664 data.flags = flags;
1665 data.lparam = lparam;
1669 return TRUE;
1670}
1671
1672
1673/***********************************************************************
1674 * VerLanguageNameA (KERNEL32.@)
1675 *
1676 * Get the name of a language.
1677 *
1678 * PARAMS
1679 * wLang [I] LANGID of the language
1680 * szLang [O] Destination for the language name
1681 *
1682 * RETURNS
1683 * Success: The size of the language name. If szLang is non-NULL, it is filled
1684 * with the name.
1685 * Failure: 0. Use GetLastError() to determine the cause.
1686 *
1687 */
1689{
1690 return GetLocaleInfoA( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
1691}
1692
1693
1694/***********************************************************************
1695 * VerLanguageNameW (KERNEL32.@)
1696 *
1697 * See VerLanguageNameA.
1698 */
1700{
1701 return GetLocaleInfoW( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
1702}
1703
1704/******************************************************************************
1705 * GetStringTypeW (KERNEL32.@)
1706 *
1707 * See GetStringTypeA.
1708 */
1710{
1711 static const unsigned char type2_map[16] =
1712 {
1713 C2_NOTAPPLICABLE, /* unassigned */
1714 C2_LEFTTORIGHT, /* L */
1715 C2_RIGHTTOLEFT, /* R */
1716 C2_EUROPENUMBER, /* EN */
1717 C2_EUROPESEPARATOR, /* ES */
1718 C2_EUROPETERMINATOR, /* ET */
1719 C2_ARABICNUMBER, /* AN */
1720 C2_COMMONSEPARATOR, /* CS */
1721 C2_BLOCKSEPARATOR, /* B */
1722 C2_SEGMENTSEPARATOR, /* S */
1723 C2_WHITESPACE, /* WS */
1724 C2_OTHERNEUTRAL, /* ON */
1725 C2_RIGHTTOLEFT, /* AL */
1726 C2_NOTAPPLICABLE, /* NSM */
1727 C2_NOTAPPLICABLE, /* BN */
1728 C2_OTHERNEUTRAL /* LRE, LRO, RLE, RLO, PDF */
1729 };
1730
1731 if (!src)
1732 {
1734 return FALSE;
1735 }
1736
1737 if (count == -1) count = strlenW(src) + 1;
1738 switch(type)
1739 {
1740 case CT_CTYPE1:
1741 while (count--) *chartype++ = get_char_typeW( *src++ ) & 0xfff;
1742 break;
1743 case CT_CTYPE2:
1744 while (count--) *chartype++ = type2_map[get_char_typeW( *src++ ) >> 12];
1745 break;
1746 case CT_CTYPE3:
1747 {
1748 WARN("CT_CTYPE3: semi-stub.\n");
1749 while (count--)
1750 {
1751 int c = *src;
1752 WORD type1, type3 = 0; /* C3_NOTAPPLICABLE */
1753
1754 type1 = get_char_typeW( *src++ ) & 0xfff;
1755 /* try to construct type3 from type1 */
1756 if(type1 & C1_SPACE) type3 |= C3_SYMBOL;
1757 if(type1 & C1_ALPHA) type3 |= C3_ALPHA;
1758 if ((c>=0x30A0)&&(c<=0x30FF)) type3 |= C3_KATAKANA;
1759 if ((c>=0x3040)&&(c<=0x309F)) type3 |= C3_HIRAGANA;
1760 if ((c>=0x4E00)&&(c<=0x9FAF)) type3 |= C3_IDEOGRAPH;
1761 if (c == 0x0640) type3 |= C3_KASHIDA;
1762 if ((c>=0x3000)&&(c<=0x303F)) type3 |= C3_SYMBOL;
1763
1764 if ((c>=0xD800)&&(c<=0xDBFF)) type3 |= C3_HIGHSURROGATE;
1765 if ((c>=0xDC00)&&(c<=0xDFFF)) type3 |= C3_LOWSURROGATE;
1766
1767 if ((c>=0xFF00)&&(c<=0xFF60)) type3 |= C3_FULLWIDTH;
1768 if ((c>=0xFF00)&&(c<=0xFF20)) type3 |= C3_SYMBOL;
1769 if ((c>=0xFF3B)&&(c<=0xFF40)) type3 |= C3_SYMBOL;
1770 if ((c>=0xFF5B)&&(c<=0xFF60)) type3 |= C3_SYMBOL;
1771 if ((c>=0xFF21)&&(c<=0xFF3A)) type3 |= C3_ALPHA;
1772 if ((c>=0xFF41)&&(c<=0xFF5A)) type3 |= C3_ALPHA;
1773 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_FULLWIDTH;
1774 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_SYMBOL;
1775
1776 if ((c>=0xFF61)&&(c<=0xFFDC)) type3 |= C3_HALFWIDTH;
1777 if ((c>=0xFF61)&&(c<=0xFF64)) type3 |= C3_SYMBOL;
1778 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_KATAKANA;
1779 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_ALPHA;
1780 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_HALFWIDTH;
1781 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_SYMBOL;
1782 *chartype++ = type3;
1783 }
1784 break;
1785 }
1786 default:
1788 return FALSE;
1789 }
1790 return TRUE;
1791}
1792
1793
1794/******************************************************************************
1795 * GetStringTypeExW (KERNEL32.@)
1796 *
1797 * See GetStringTypeExA.
1798 */
1800{
1801 /* locale is ignored for Unicode */
1802 return GetStringTypeW( type, src, count, chartype );
1803}
1804
1805
1806/******************************************************************************
1807 * GetStringTypeA (KERNEL32.@)
1808 *
1809 * Get characteristics of the characters making up a string.
1810 *
1811 * PARAMS
1812 * locale [I] Locale Id for the string
1813 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1814 * src [I] String to analyse
1815 * count [I] Length of src in chars, or -1 if src is NUL terminated
1816 * chartype [O] Destination for the calculated characteristics
1817 *
1818 * RETURNS
1819 * Success: TRUE. chartype is filled with the requested characteristics of each char
1820 * in src.
1821 * Failure: FALSE. Use GetLastError() to determine the cause.
1822 */
1824{
1825 UINT cp;
1826 INT countW;
1827 LPWSTR srcW;
1828 BOOL ret = FALSE;
1829
1830 if(count == -1) count = strlen(src) + 1;
1831
1832 if (!(cp = get_lcid_codepage( locale )))
1833 {
1834 FIXME("For locale %04x using current ANSI code page\n", locale);
1835 cp = GetACP();
1836 }
1837
1838 countW = MultiByteToWideChar(cp, 0, src, count, NULL, 0);
1839 if((srcW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
1840 {
1841 MultiByteToWideChar(cp, 0, src, count, srcW, countW);
1842 /*
1843 * NOTE: the target buffer has 1 word for each CHARACTER in the source
1844 * string, with multibyte characters there maybe be more bytes in count
1845 * than character space in the buffer!
1846 */
1847 ret = GetStringTypeW(type, srcW, countW, chartype);
1848 HeapFree(GetProcessHeap(), 0, srcW);
1849 }
1850 return ret;
1851}
1852
1853/******************************************************************************
1854 * GetStringTypeExA (KERNEL32.@)
1855 *
1856 * Get characteristics of the characters making up a string.
1857 *
1858 * PARAMS
1859 * locale [I] Locale Id for the string
1860 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1861 * src [I] String to analyse
1862 * count [I] Length of src in chars, or -1 if src is NUL terminated
1863 * chartype [O] Destination for the calculated characteristics
1864 *
1865 * RETURNS
1866 * Success: TRUE. chartype is filled with the requested characteristics of each char
1867 * in src.
1868 * Failure: FALSE. Use GetLastError() to determine the cause.
1869 */
1871{
1872 return GetStringTypeA(locale, type, src, count, chartype);
1873}
1874
1875static inline void map_byterev(const WCHAR *src, int len, WCHAR *dst)
1876{
1877 while (len--)
1878 *dst++ = RtlUshortByteSwap(*src++);
1879}
1880
1881static int map_to_hiragana(const WCHAR *src, int srclen, WCHAR *dst, int dstlen)
1882{
1883 int pos;
1884 for (pos = 0; srclen; src++, srclen--, pos++)
1885 {
1886 /*
1887 * U+30A1 ... U+30F3: Katakana
1888 * U+30F4: Katakana Letter VU
1889 * U+30F5: Katakana Letter Small KA
1890 * U+30FD: Katakana Iteration Mark
1891 * U+30FE: Katakana Voiced Iteration Mark
1892 */
1893 WCHAR wch = *src;
1894 if ((0x30A1 <= wch && wch <= 0x30F3) ||
1895 wch == 0x30F4 || wch == 0x30F5 || wch == 0x30FD || wch == 0x30FE)
1896 {
1897 wch -= 0x60; /* Katakana to Hiragana */
1898 }
1899 if (pos < dstlen)
1900 dst[pos] = wch;
1901 }
1902 return pos;
1903}
1904
1905static int map_to_katakana(const WCHAR *src, int srclen, WCHAR *dst, int dstlen)
1906{
1907 int pos;
1908 for (pos = 0; srclen; src++, srclen--, pos++)
1909 {
1910 /*
1911 * U+3041 ... U+3093: Hiragana
1912 * U+3094: Hiragana Letter VU
1913 * U+3095: Hiragana Letter Small KA
1914 * U+309D: Hiragana Iteration Mark
1915 * U+309E: Hiragana Voiced Iteration Mark
1916 */
1917 WCHAR wch = *src;
1918 if ((0x3041 <= wch && wch <= 0x3093) ||
1919 wch == 3094 || wch == 0x3095 || wch == 0x309D || wch == 0x309E)
1920 {
1921 wch += 0x60; /* Hiragana to Katakana */
1922 }
1923 if (pos < dstlen)
1924 dst[pos] = wch;
1925 }
1926 return pos;
1927}
1928
1929/* The table that contains fullwidth characters and halfwidth characters */
1932{
1933#define DEFINE_FULL2HALF(full, half1, half2) { full, half1, half2 },
1934#include "full2half.h"
1935#undef DEFINE_FULL2HALF
1936};
1937#define GET_FULL(table, index) ((table)[index][0])
1938#define GET_HALF1(table, index) ((table)[index][1])
1939#define GET_HALF2(table, index) ((table)[index][2])
1940
1941/* The table that contains dakuten entries */
1944{
1945#define DEFINE_DAKUTEN(voiced, single1, single2, half1, half2) { voiced, single1, single2 },
1946#include "dakuten.h"
1947#undef DEFINE_DAKUTEN
1948};
1949#define GET_VOICED(table, index) ((table)[index][0])
1950#define GET_SINGLE1(table, index) ((table)[index][1])
1951#define GET_SINGLE2(table, index) ((table)[index][2])
1952
1953static int map_to_halfwidth(DWORD flags, const WCHAR *src, int srclen, WCHAR *dst, int dstlen)
1954{
1955 int pos, i;
1956 const int count1 = (int)ARRAY_SIZE(full2half_table);
1957 const FULL2HALF_ENTRY *table1 = full2half_table;
1958
1959 for (pos = 0; srclen; src++, srclen--, pos++)
1960 {
1961 WCHAR ch = *src;
1962
1963 if (flags & LCMAP_KATAKANA)
1964 map_to_katakana(&ch, 1, &ch, 1);
1965 else if (flags & LCMAP_HIRAGANA)
1966 map_to_hiragana(&ch, 1, &ch, 1);
1967
1968 if (ch < 0x3000) /* Quick judgment */
1969 {
1970 if (pos < dstlen)
1971 dst[pos] = ch;
1972 continue;
1973 }
1974
1975 if (0xFF01 <= ch && ch <= 0xFF5E) /* U+FF01 ... U+FF5E */
1976 {
1977 if (pos < dstlen)
1978 dst[pos] = ch - 0xFEE0; /* Fullwidth ASCII to halfwidth ASCII */
1979 continue;
1980 }
1981
1982 /* Search in table1 (full/half) */
1983 for (i = count1 - 1; i >= 0; --i) /* In reverse order */
1984 {
1985 if (GET_FULL(table1, i) != ch)
1986 continue;
1987
1988 if (GET_HALF2(table1, i) == 0)
1989 {
1990 if (pos < dstlen)
1991 dst[pos] = GET_HALF1(table1, i);
1992 }
1993 else if (!dstlen)
1994 {
1995 pos++;
1996 }
1997 else if (pos + 1 < dstlen)
1998 {
1999 dst[pos++] = GET_HALF1(table1, i);
2000 dst[pos ] = GET_HALF2(table1, i);
2001 }
2002 else
2003 {
2004 dst[pos] = ch;
2005 }
2006 break;
2007 }
2008
2009 if (i >= 0)
2010 continue;
2011
2012 if (pos < dstlen)
2013 dst[pos] = ch;
2014 }
2015
2016 return pos;
2017}
2018
2019static int map_to_fullwidth(const WCHAR *src, int srclen, WCHAR *dst, int dstlen)
2020{
2021 int pos, i;
2022 const FULL2HALF_ENTRY *table1 = full2half_table;
2023 const DAKUTEN_ENTRY *table2 = dakuten_table;
2024 const int count1 = (int)ARRAY_SIZE(full2half_table);
2025 const int count2 = (int)ARRAY_SIZE(dakuten_table);
2026
2027 for (pos = 0; srclen; src++, srclen--, pos++)
2028 {
2029 WCHAR ch = *src;
2030
2031 if (ch == 0x20) /* U+0020: Space */
2032 {
2033 if (pos < dstlen)
2034 dst[pos] = 0x3000; /* U+3000: Ideographic Space */
2035 continue;
2036 }
2037
2038 if (0x21 <= ch && ch <= 0x7E) /* Mappable halfwidth ASCII */
2039 {
2040 if (pos < dstlen)
2041 dst[pos] = ch + 0xFEE0; /* U+FF01 ... U+FF5E */
2042 continue;
2043 }
2044
2045 if (ch < 0xFF00) /* Quick judgment */
2046 {
2047 if (pos < dstlen)
2048 dst[pos] = ch;
2049 continue;
2050 }
2051
2052 /* Search in table1 (full/half) */
2053 for (i = count1 - 1; i >= 0; --i) /* In reverse order */
2054 {
2055 if (GET_HALF1(table1, i) != ch)
2056 continue; /* Mismatched */
2057
2058 if (GET_HALF2(table1, i) == 0)
2059 {
2060 if (pos < dstlen)
2061 dst[pos] = GET_FULL(table1, i);
2062 break;
2063 }
2064
2065 if (srclen <= 1 || GET_HALF2(table1, i) != src[1])
2066 continue; /* Mismatched */
2067
2068 --srclen;
2069 ++src;
2070
2071 if (pos < dstlen)
2072 dst[pos] = GET_FULL(table1, i);
2073 break;
2074 }
2075
2076 if (i >= 0)
2077 continue;
2078
2079 /* Search in table2 (dakuten) */
2080 for (i = count2 - 1; i >= 0; --i) /* In reverse order */
2081 {
2082 if (GET_SINGLE1(table2, i) != ch)
2083 continue; /* Mismatched */
2084
2085 if (srclen <= 1 || GET_SINGLE2(table2, i) != src[1])
2086 continue; /* Mismatched */
2087
2088 --srclen;
2089 ++src;
2090
2091 if (pos < dstlen)
2092 dst[pos] = GET_VOICED(table2, i);
2093 break;
2094 }
2095
2096 if (i >= 0)
2097 continue;
2098
2099 if (pos < dstlen)
2100 dst[pos] = ch;
2101 }
2102
2103 return pos;
2104}
2105
2106static int map_to_lowercase(DWORD flags, const WCHAR *src, int srclen, WCHAR *dst, int dstlen)
2107{
2108 int pos;
2109 for (pos = 0; srclen; src++, srclen--)
2110 {
2111 WCHAR wch = *src;
2113 continue;
2114 if (pos < dstlen)
2115 dst[pos] = tolowerW(wch);
2116 pos++;
2117 }
2118 return pos;
2119}
2120
2121static int map_to_uppercase(DWORD flags, const WCHAR *src, int srclen, WCHAR *dst, int dstlen)
2122{
2123 int pos;
2124 for (pos = 0; srclen; src++, srclen--)
2125 {
2126 WCHAR wch = *src;
2128 continue;
2129 if (pos < dstlen)
2130 dst[pos] = toupperW(wch);
2131 pos++;
2132 }
2133 return pos;
2134}
2135
2136typedef struct tagWCHAR_PAIR
2137{
2140
2141/* The table to convert Simplified Chinese to Traditional Chinese */
2142static const WCHAR_PAIR s_sim2tra[] =
2143{
2144#define DEFINE_SIM2TRA(from, to) { from, to },
2145#include "sim2tra.h"
2146#undef DEFINE_SIM2TRA
2147};
2148
2149/* The table to convert Traditional Chinese to Simplified Chinese */
2150static const WCHAR_PAIR s_tra2sim[] =
2151{
2152#define DEFINE_TRA2SIM(from, to) { from, to },
2153#include "tra2sim.h"
2154#undef DEFINE_TRA2SIM
2155};
2156
2157/* The comparison function to do bsearch */
2158static int compare_wchar_pair(const void *x, const void *y)
2159{
2160 const WCHAR_PAIR *a = x;
2161 const WCHAR_PAIR *b = y;
2162 if (a->from < b->from)
2163 return -1;
2164 if (a->from > b->from)
2165 return +1;
2166 return 0;
2167}
2168
2169static WCHAR find_wchar_pair(const WCHAR_PAIR *pairs, size_t count, WCHAR ch)
2170{
2171 PWCHAR_PAIR found = bsearch(&ch, pairs, count, sizeof(WCHAR_PAIR), compare_wchar_pair);
2172 if (found)
2173 return found->to;
2174 return ch;
2175}
2176
2178{
2179 int pos;
2180 for (pos = 0; srclen; src++, srclen--)
2181 {
2182 WCHAR wch = *src;
2183 if (pos < dstlen)
2185 pos++;
2186 }
2187 return pos;
2188}
2189
2191{
2192 int pos;
2193 for (pos = 0; srclen; src++, srclen--)
2194 {
2195 WCHAR wch = *src;
2196 if (pos < dstlen)
2198 pos++;
2199 }
2200 return pos;
2201}
2202
2204{
2205 int pos;
2206 WORD wC1, wC2, wC3;
2207 for (pos = 0; srclen; src++, srclen--)
2208 {
2209 WCHAR wch = *src;
2210 GetStringTypeW(CT_CTYPE1, &wch, 1, &wC1);
2211 GetStringTypeW(CT_CTYPE2, &wch, 1, &wC2);
2212 GetStringTypeW(CT_CTYPE3, &wch, 1, &wC3);
2214 {
2215 if ((wC1 & C1_PUNCT) || (wC3 & C3_SYMBOL))
2216 continue;
2217 }
2219 {
2220 if ((wC2 & C2_OTHERNEUTRAL) && (wC3 & (C3_NONSPACING | C3_DIACRITIC)))
2221 continue;
2222 }
2223 if (pos < dstlen)
2224 dst[pos] = wch;
2225 pos++;
2226 }
2227 return pos;
2228}
2229
2230static int lcmap_string(DWORD flags, const WCHAR *src, int srclen, WCHAR *dst, int dstlen)
2231{
2232 int ret = 0;
2233
2235 {
2237 return 0;
2238 }
2239
2241 {
2242 case LCMAP_HIRAGANA:
2244 break;
2245 case LCMAP_KATAKANA:
2247 break;
2248 case LCMAP_HALFWIDTH:
2250 break;
2253 break;
2256 break;
2257 case LCMAP_FULLWIDTH:
2259 break;
2262 if (dstlen && ret)
2264 break;
2267 if (dstlen && ret)
2269 break;
2272 break;
2275 break;
2277 case NORM_IGNORESYMBOLS:
2280 {
2282 return 0;
2283 }
2285 break;
2286 case 0:
2287 if (flags & LCMAP_LOWERCASE)
2288 {
2290 flags &= ~LCMAP_LOWERCASE;
2291 break;
2292 }
2293 if (flags & LCMAP_UPPERCASE)
2294 {
2296 flags &= ~LCMAP_UPPERCASE;
2297 break;
2298 }
2299 if (flags & LCMAP_BYTEREV)
2300 {
2301 if (dstlen == 0)
2302 {
2303 ret = srclen;
2304 break;
2305 }
2306 ret = min(srclen, dstlen);
2307 RtlCopyMemory(dst, src, ret * sizeof(WCHAR));
2308 break;
2309 }
2310 /* fall through */
2311 default:
2313 return 0;
2314 }
2315
2316 if (dstlen)
2317 {
2318 if (flags & LCMAP_LOWERCASE)
2320 if (flags & LCMAP_UPPERCASE)
2322 if (flags & LCMAP_BYTEREV)
2324
2325 if (dstlen < ret)
2326 {
2328 return 0;
2329 }
2330 }
2331
2332 return ret;
2333}
2334
2335/*************************************************************************
2336 * LCMapStringEx (KERNEL32.@)
2337 *
2338 * Map characters in a locale sensitive string.
2339 *
2340 * PARAMS
2341 * locale [I] Locale name for the conversion.
2342 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h")
2343 * src [I] String to map
2344 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
2345 * dst [O] Destination for mapped string
2346 * dstlen [I] Length of dst in characters
2347 * version [I] reserved, must be NULL
2348 * reserved [I] reserved, must be NULL
2349 * lparam [I] reserved, must be 0
2350 *
2351 * RETURNS
2352 * Success: The length of the mapped string in dst, including the NUL terminator.
2353 * Failure: 0. Use GetLastError() to determine the cause.
2354 */
2357{
2358 if (version) FIXME("unsupported version structure %p\n", version);
2359 if (reserved) FIXME("unsupported reserved pointer %p\n", reserved);
2360 if (handle)
2361 {
2362 static int once;
2363 if (!once++) FIXME("unsupported lparam %Ix\n", handle);
2364 }
2365
2366 if (!src || !srclen || dstlen < 0)
2367 {
2369 return 0;
2370 }
2371
2372 if (srclen < 0) srclen = lstrlenW(src) + 1;
2373
2374 TRACE( "(%s,0x%08lx,%s,%d,%p,%d)\n",
2376
2377 flags &= ~LOCALE_USE_CP_ACP;
2378
2379 if (src == dst && (flags & ~(LCMAP_LOWERCASE | LCMAP_UPPERCASE)))
2380 {
2382 return 0;
2383 }
2384
2385 if (!dstlen) dst = NULL;
2386
2387 if (flags & LCMAP_SORTKEY)
2388 {
2389 INT ret;
2390
2391 if (srclen < 0)
2392 srclen = strlenW(src);
2393
2394 ret = wine_get_sortkey(flags, src, srclen, (char *)dst, dstlen);
2395 if (ret == 0)
2397 else
2398 ret++;
2399 return ret;
2400 }
2401
2402 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
2403 if (flags & SORT_STRINGSORT)
2404 {
2406 return 0;
2407 }
2408
2409 return lcmap_string(flags, src, srclen, dst, dstlen);
2410}
2411
2412/*************************************************************************
2413 * LCMapStringW (KERNEL32.@)
2414 *
2415 * See LCMapStringA.
2416 */
2419{
2420 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
2422
2423 return LCMapStringEx(NULL, flags, src, srclen, dst, dstlen, NULL, NULL, 0);
2424}
2425
2426/*************************************************************************
2427 * LCMapStringA (KERNEL32.@)
2428 *
2429 * Map characters in a locale sensitive string.
2430 *
2431 * PARAMS
2432 * lcid [I] LCID for the conversion.
2433 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h").
2434 * src [I] String to map
2435 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
2436 * dst [O] Destination for mapped string
2437 * dstlen [I] Length of dst in characters
2438 *
2439 * RETURNS
2440 * Success: The length of the mapped string in dst, including the NUL terminator.
2441 * Failure: 0. Use GetLastError() to determine the cause.
2442 */
2445{
2446 WCHAR *bufW = NtCurrentTeb()->StaticUnicodeBuffer;
2447 LPWSTR srcW, dstW;
2448 INT ret = 0, srclenW, dstlenW;
2449 UINT locale_cp = CP_ACP;
2450
2451 if (!src || !srclen || dstlen < 0)
2452 {
2454 return 0;
2455 }
2456
2457 if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
2458
2459 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, bufW, 260);
2460 if (srclenW)
2461 srcW = bufW;
2462 else
2463 {
2464 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, NULL, 0);
2465 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
2466 if (!srcW)
2467 {
2469 return 0;
2470 }
2471 MultiByteToWideChar(locale_cp, 0, src, srclen, srcW, srclenW);
2472 }
2473
2474 if (flags & LCMAP_SORTKEY)
2475 {
2476 if (src == dst)
2477 {
2479 goto map_string_exit;
2480 }
2481 ret = wine_get_sortkey(flags, srcW, srclenW, dst, dstlen);
2482 if (ret == 0)
2484 else
2485 ret++;
2486 goto map_string_exit;
2487 }
2488
2489 if (flags & SORT_STRINGSORT)
2490 {
2492 goto map_string_exit;
2493 }
2494
2495 dstlenW = LCMapStringEx(NULL, flags, srcW, srclenW, NULL, 0, NULL, NULL, 0);
2496 if (!dstlenW)
2497 goto map_string_exit;
2498
2499 dstW = HeapAlloc(GetProcessHeap(), 0, dstlenW * sizeof(WCHAR));
2500 if (!dstW)
2501 {
2503 goto map_string_exit;
2504 }
2505
2506 LCMapStringEx(NULL, flags, srcW, srclenW, dstW, dstlenW, NULL, NULL, 0);
2507 ret = WideCharToMultiByte(locale_cp, 0, dstW, dstlenW, dst, dstlen, NULL, NULL);
2508 HeapFree(GetProcessHeap(), 0, dstW);
2509
2510map_string_exit:
2511 if (srcW != bufW) HeapFree(GetProcessHeap(), 0, srcW);
2512 return ret;
2513}
2514
2515/*************************************************************************
2516 * FoldStringA (KERNEL32.@)
2517 *
2518 * Map characters in a string.
2519 *
2520 * PARAMS
2521 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
2522 * src [I] String to map
2523 * srclen [I] Length of src, or -1 if src is NUL terminated
2524 * dst [O] Destination for mapped string
2525 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
2526 *
2527 * RETURNS
2528 * Success: The length of the string written to dst, including the terminating NUL. If
2529 * dstlen is 0, the value returned is the same, but nothing is written to dst,
2530 * and dst may be NULL.
2531 * Failure: 0. Use GetLastError() to determine the cause.
2532 */
2535{
2536 INT ret = 0, srclenW = 0;
2537 WCHAR *srcW = NULL, *dstW = NULL;
2538
2539 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
2540 {
2542 return 0;
2543 }
2544
2546 src, srclen, NULL, 0);
2547 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
2548
2549 if (!srcW)
2550 {
2552 goto FoldStringA_exit;
2553 }
2554
2556 src, srclen, srcW, srclenW);
2557
2558 dwFlags = (dwFlags & ~MAP_PRECOMPOSED) | MAP_FOLDCZONE;
2559
2560 ret = FoldStringW(dwFlags, srcW, srclenW, NULL, 0);
2561 if (ret && dstlen)
2562 {
2563 dstW = HeapAlloc(GetProcessHeap(), 0, ret * sizeof(WCHAR));
2564
2565 if (!dstW)
2566 {
2568 goto FoldStringA_exit;
2569 }
2570
2571 ret = FoldStringW(dwFlags, srcW, srclenW, dstW, ret);
2572 if (!WideCharToMultiByte(CP_ACP, 0, dstW, ret, dst, dstlen, NULL, NULL))
2573 {
2574 ret = 0;
2576 }
2577 }
2578
2579 HeapFree(GetProcessHeap(), 0, dstW);
2580
2581FoldStringA_exit:
2582 HeapFree(GetProcessHeap(), 0, srcW);
2583 return ret;
2584}
2585
2586/*************************************************************************
2587 * FoldStringW (KERNEL32.@)
2588 *
2589 * See FoldStringA.
2590 */
2593{
2594 int ret;
2595
2596 switch (dwFlags & (MAP_COMPOSITE|MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES))
2597 {
2598 case 0:
2599 if (dwFlags)
2600 break;
2601 /* Fall through for dwFlags == 0 */
2603 case MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES:
2604 case MAP_COMPOSITE|MAP_EXPAND_LIGATURES:
2606 return 0;
2607 }
2608
2609 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
2610 {
2612 return 0;
2613 }
2614
2616 if (!ret)
2618 return ret;
2619}
2620
2621/******************************************************************************
2622 * CompareStringEx (KERNEL32.@)
2623 */
2626{
2629 DWORD semistub_flags = NORM_LINGUISTIC_CASING|LINGUISTIC_IGNORECASE|0x10000000;
2630 /* 0x10000000 is related to diacritics in Arabic, Japanese, and Hebrew */
2631 INT ret;
2632 static int once;
2633
2634 if (version) FIXME("unexpected version parameter\n");
2635 if (reserved) FIXME("unexpected reserved value\n");
2636 if (lParam) FIXME("unexpected lParam\n");
2637
2638 if (!str1 || !str2)
2639 {
2641 return 0;
2642 }
2643
2644 if (flags & ~(supported_flags|semistub_flags))
2645 {
2647 return 0;
2648 }
2649
2650 if (flags & semistub_flags)
2651 {
2652 if (!once++)
2653 FIXME("semi-stub behavior for flag(s) 0x%x\n", flags & semistub_flags);
2654 }
2655
2656 if (len1 < 0) len1 = strlenW(str1);
2657 if (len2 < 0) len2 = strlenW(str2);
2658
2659 ret = wine_compare_string(flags, str1, len1, str2, len2);
2660
2661 if (ret) /* need to translate result */
2662 return (ret < 0) ? CSTR_LESS_THAN : CSTR_GREATER_THAN;
2663 return CSTR_EQUAL;
2664}
2665
2666/******************************************************************************
2667 * CompareStringW (KERNEL32.@)
2668 *
2669 * See CompareStringA.
2670 */
2672 LPCWSTR str1, INT len1, LPCWSTR str2, INT len2)
2673{
2674 return CompareStringEx(NULL, flags, str1, len1, str2, len2, NULL, NULL, 0);
2675}
2676
2677/******************************************************************************
2678 * CompareStringA (KERNEL32.@)
2679 *
2680 * Compare two locale sensitive strings.
2681 *
2682 * PARAMS
2683 * lcid [I] LCID for the comparison
2684 * flags [I] Flags for the comparison (NORM_ constants from "winnls.h").
2685 * str1 [I] First string to compare
2686 * len1 [I] Length of str1, or -1 if str1 is NUL terminated
2687 * str2 [I] Second string to compare
2688 * len2 [I] Length of str2, or -1 if str2 is NUL terminated
2689 *
2690 * RETURNS
2691 * Success: CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN depending on whether
2692 * str1 is less than, equal to or greater than str2 respectively.
2693 * Failure: FALSE. Use GetLastError() to determine the cause.
2694 */
2696 LPCSTR str1, INT len1, LPCSTR str2, INT len2)
2697{
2698 WCHAR *buf1W = NtCurrentTeb()->StaticUnicodeBuffer;
2699 WCHAR *buf2W = buf1W + 130;
2700 LPWSTR str1W, str2W;
2701 INT len1W = 0, len2W = 0, ret;
2702 UINT locale_cp = CP_ACP;
2703
2704 if (!str1 || !str2)
2705 {
2707 return 0;
2708 }
2709 if (len1 < 0) len1 = strlen(str1);
2710 if (len2 < 0) len2 = strlen(str2);
2711
2712 if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
2713
2714 if (len1)
2715 {
2716 if (len1 <= 130) len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
2717 if (len1W)
2718 str1W = buf1W;
2719 else
2720 {
2721 len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, NULL, 0);
2722 str1W = HeapAlloc(GetProcessHeap(), 0, len1W * sizeof(WCHAR));
2723 if (!str1W)
2724 {
2726 return 0;
2727 }
2728 MultiByteToWideChar(locale_cp, 0, str1, len1, str1W, len1W);
2729 }
2730 }
2731 else
2732 {
2733 len1W = 0;
2734 str1W = buf1W;
2735 }
2736
2737 if (len2)
2738 {
2739 if (len2 <= 130) len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
2740 if (len2W)
2741 str2W = buf2W;
2742 else
2743 {
2744 len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, NULL, 0);
2745 str2W = HeapAlloc(GetProcessHeap(), 0, len2W * sizeof(WCHAR));
2746 if (!str2W)
2747 {
2748 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
2750 return 0;
2751 }
2752 MultiByteToWideChar(locale_cp, 0, str2, len2, str2W, len2W);
2753 }
2754 }
2755 else
2756 {
2757 len2W = 0;
2758 str2W = buf2W;
2759 }
2760
2761 ret = CompareStringEx(NULL, flags, str1W, len1W, str2W, len2W, NULL, NULL, 0);
2762
2763 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
2764 if (str2W != buf2W) HeapFree(GetProcessHeap(), 0, str2W);
2765 return ret;
2766}
2767
2768#if (WINVER >= 0x0600)
2769/******************************************************************************
2770 * CompareStringOrdinal (KERNEL32.@)
2771 */
2772INT WINAPI CompareStringOrdinal(const WCHAR *str1, INT len1, const WCHAR *str2, INT len2, BOOL ignore_case)
2773{
2774 int ret;
2775
2776 if (!str1 || !str2)
2777 {
2779 return 0;
2780 }
2781 if (len1 < 0) len1 = strlenW(str1);
2782 if (len2 < 0) len2 = strlenW(str2);
2783
2784 ret = RtlCompareUnicodeStrings( str1, len1, str2, len2, ignore_case );
2785 if (ret < 0) return CSTR_LESS_THAN;
2786 if (ret > 0) return CSTR_GREATER_THAN;
2787 return CSTR_EQUAL;
2788}
2789#endif
2790
2791#ifdef __REACTOS__
2792HANDLE NLS_RegOpenKey(HANDLE hRootKey, LPCWSTR szKeyName)
2793#else
2794static HANDLE NLS_RegOpenKey(HANDLE hRootKey, LPCWSTR szKeyName)
2795#endif
2796{
2797 UNICODE_STRING keyName;
2799 HANDLE hkey;
2800
2801 RtlInitUnicodeString( &keyName, szKeyName );
2802#ifdef __REACTOS__
2804#else
2805 InitializeObjectAttributes(&attr, &keyName, 0, hRootKey, NULL);
2806#endif
2807
2808 if (NtOpenKey( &hkey, KEY_READ, &attr ) != STATUS_SUCCESS)
2809 hkey = 0;
2810
2811 return hkey;
2812}
2813
2814#ifdef __REACTOS__
2816 LPWSTR szValueName, ULONG valueNameSize,
2817 LPWSTR szValueData, ULONG valueDataSize)
2818#else
2820 LPWSTR szValueName, ULONG valueNameSize,
2821 LPWSTR szValueData, ULONG valueDataSize)
2822#endif
2823{
2824 BYTE buffer[80];
2826 DWORD dwLen;
2827
2829 buffer, sizeof(buffer), &dwLen ) != STATUS_SUCCESS ||
2830 info->NameLength > valueNameSize ||
2831 info->DataLength > valueDataSize)
2832 {
2833 return FALSE;
2834 }
2835
2836 TRACE("info->Name %s info->DataLength %d\n", debugstr_w(info->Name), info->DataLength);
2837
2838 memcpy( szValueName, info->Name, info->NameLength);
2839 szValueName[info->NameLength / sizeof(WCHAR)] = '\0';
2840 memcpy( szValueData, buffer + info->DataOffset, info->DataLength );
2841 szValueData[info->DataLength / sizeof(WCHAR)] = '\0';
2842
2843 TRACE("returning %s %s\n", debugstr_w(szValueName), debugstr_w(szValueData));
2844 return TRUE;
2845}
2846
2847static BOOL NLS_RegGetDword(HANDLE hKey, LPCWSTR szValueName, DWORD *lpVal)
2848{
2849 BYTE buffer[128];
2851 DWORD dwSize = sizeof(buffer);
2852 UNICODE_STRING valueName;
2853
2854 RtlInitUnicodeString( &valueName, szValueName );
2855
2856 TRACE("%p, %s\n", hKey, debugstr_w(szValueName));
2859 info->DataLength == sizeof(DWORD))
2860 {
2861 memcpy(lpVal, info->Data, sizeof(DWORD));
2862 return TRUE;
2863 }
2864
2865 return FALSE;
2866}
2867
2869{
2870 LANGID langId;
2871 LPCWSTR szResourceName = MAKEINTRESOURCEW(((lgrpid + 0x2000) >> 4) + 1);
2872 HRSRC hResource;
2873 BOOL bRet = FALSE;
2874
2875 /* FIXME: Is it correct to use the system default langid? */
2876 langId = GetSystemDefaultLangID();
2877
2878 if (SUBLANGID(langId) == SUBLANG_NEUTRAL)
2879 langId = MAKELANGID( PRIMARYLANGID(langId), SUBLANG_DEFAULT );
2880
2881 hResource = FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING, szResourceName, langId );
2882
2883 if (hResource)
2884 {
2885 HGLOBAL hResDir = LoadResource( kernel32_handle, hResource );
2886
2887 if (hResDir)
2888 {
2889 ULONG iResourceIndex = lgrpid & 0xf;
2890 LPCWSTR lpResEntry = LockResource( hResDir );
2891 ULONG i;
2892
2893 for (i = 0; i < iResourceIndex; i++)
2894 lpResEntry += *lpResEntry + 1;
2895
2896 if (*lpResEntry < nameSize)
2897 {
2898 memcpy( szName, lpResEntry + 1, *lpResEntry * sizeof(WCHAR) );
2899 szName[*lpResEntry] = '\0';
2900 bRet = TRUE;
2901 }
2902
2903 }
2904 FreeResource( hResource );
2905 }
2906 return bRet;
2907}
2908
2909/* Callback function ptrs for EnumSystemLanguageGroupsA/W */
2910typedef struct
2911{
2917
2918/* Internal implementation of EnumSystemLanguageGroupsA/W */
2920{
2921 WCHAR szNumber[10], szValue[4];
2922 HANDLE hKey;
2923 BOOL bContinue = TRUE;
2924 ULONG ulIndex = 0;
2925
2926 if (!lpProcs)
2927 {
2929 return FALSE;
2930 }
2931
2932 switch (lpProcs->dwFlags)
2933 {
2934 case 0:
2935 /* Default to LGRPID_INSTALLED */
2936 lpProcs->dwFlags = LGRPID_INSTALLED;
2937 /* Fall through... */
2938 case LGRPID_INSTALLED:
2939 case LGRPID_SUPPORTED:
2940 break;
2941 default:
2943 return FALSE;
2944 }
2945
2947
2948 if (!hKey)
2949 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2950
2951 while (bContinue)
2952 {
2953 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
2954 szValue, sizeof(szValue) ))
2955 {
2956 BOOL bInstalled = szValue[0] == '1';
2957 LGRPID lgrpid = strtoulW( szNumber, NULL, 16 );
2958
2959 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber),
2960 bInstalled ? "" : "not ");
2961
2962 if (lpProcs->dwFlags == LGRPID_SUPPORTED || bInstalled)
2963 {
2964 WCHAR szGrpName[48];
2965
2966 if (!NLS_GetLanguageGroupName( lgrpid, szGrpName, sizeof(szGrpName) / sizeof(WCHAR) ))
2967 szGrpName[0] = '\0';
2968
2969 if (lpProcs->procW)
2970 bContinue = lpProcs->procW( lgrpid, szNumber, szGrpName, lpProcs->dwFlags,
2971 lpProcs->lParam );
2972 else
2973 {
2974 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
2975 char szGrpNameA[48];
2976
2977 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
2978 * or whether the language names are ever localised. Assume CP_ACP.
2979 */
2980
2981 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
2982 WideCharToMultiByte(CP_ACP, 0, szGrpName, -1, szGrpNameA, sizeof(szGrpNameA), 0, 0);
2983
2984 bContinue = lpProcs->procA( lgrpid, szNumberA, szGrpNameA, lpProcs->dwFlags,
2985 lpProcs->lParam );
2986 }
2987 }
2988
2989 ulIndex++;
2990 }
2991 else
2992 bContinue = FALSE;
2993
2994 if (!bContinue)
2995 break;
2996 }
2997
2998 if (hKey)
2999 NtClose( hKey );
3000
3001 return TRUE;
3002}
3003
3004/******************************************************************************
3005 * EnumSystemLanguageGroupsA (KERNEL32.@)
3006 *
3007 * Call a users function for each language group available on the system.
3008 *
3009 * PARAMS
3010 * pLangGrpEnumProc [I] Callback function to call for each language group
3011 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
3012 * lParam [I] User parameter to pass to pLangGrpEnumProc
3013 *
3014 * RETURNS
3015 * Success: TRUE.
3016 * Failure: FALSE. Use GetLastError() to determine the cause.
3017 */
3020{
3022
3023 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
3024
3025 procs.procA = pLangGrpEnumProc;
3026 procs.procW = NULL;
3027 procs.dwFlags = dwFlags;
3028 procs.lParam = lParam;
3029
3030 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
3031}
3032
3033/******************************************************************************
3034 * EnumSystemLanguageGroupsW (KERNEL32.@)
3035 *
3036 * See EnumSystemLanguageGroupsA.
3037 */
3040{
3042
3043 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
3044
3045 procs.procA = NULL;
3046 procs.procW = pLangGrpEnumProc;
3047 procs.dwFlags = dwFlags;
3048 procs.lParam = lParam;
3049
3050 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
3051}
3052
3053/******************************************************************************
3054 * IsValidLanguageGroup (KERNEL32.@)
3055 *
3056 * Determine if a language group is supported and/or installed.
3057 *
3058 * PARAMS
3059 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
3060 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
3061 *
3062 * RETURNS
3063 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
3064 * FALSE otherwise.
3065 */
3067{
3068 static const WCHAR szFormat[] = { '%','x','\0' };
3069 WCHAR szValueName[16], szValue[2];
3070 BOOL bSupported = FALSE, bInstalled = FALSE;
3071 HANDLE hKey;
3072
3073
3074 switch (dwFlags)
3075 {
3076 case LGRPID_INSTALLED:
3077 case LGRPID_SUPPORTED:
3078
3080
3081 sprintfW( szValueName, szFormat, lgrpid );
3082
3083 if (NLS_RegGetDword( hKey, szValueName, (LPDWORD)szValue ))
3084 {
3085 bSupported = TRUE;
3086
3087 if (szValue[0] == '1')
3088 bInstalled = TRUE;
3089 }
3090
3091 if (hKey)
3092 NtClose( hKey );
3093
3094 break;
3095 }
3096
3097 if ((dwFlags == LGRPID_SUPPORTED && bSupported) ||
3098 (dwFlags == LGRPID_INSTALLED && bInstalled))
3099 return TRUE;
3100
3101 return FALSE;
3102}
3103
3104/* Callback function ptrs for EnumLanguageGrouplocalesA/W */
3105typedef struct
3106{
3113
3114/* Internal implementation of EnumLanguageGrouplocalesA/W */
3116{
3117 static const WCHAR szAlternateSortsKeyName[] = {
3118 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
3119 };
3120 WCHAR szNumber[10], szValue[4];
3121 HANDLE hKey;
3122 BOOL bContinue = TRUE, bAlternate = FALSE;
3123 LGRPID lgrpid;
3124 ULONG ulIndex = 1; /* Ignore default entry of 1st key */
3125
3126 if (!lpProcs || !lpProcs->lgrpid || lpProcs->lgrpid > LGRPID_ARMENIAN)
3127 {
3129 return FALSE;
3130 }
3131
3132 if (lpProcs->dwFlags)
3133 {
3135 return FALSE;
3136 }
3137
3139
3140 if (!hKey)
3141 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
3142
3143 while (bContinue)
3144 {
3145 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
3146 szValue, sizeof(szValue) ))
3147 {
3148 lgrpid = strtoulW( szValue, NULL, 16 );
3149
3150 TRACE("lcid %s, grpid %d (%smatched)\n", debugstr_w(szNumber),
3151 lgrpid, lgrpid == lpProcs->lgrpid ? "" : "not ");
3152
3153 if (lgrpid == lpProcs->lgrpid)
3154 {
3155 LCID lcid;
3156
3157 lcid = strtoulW( szNumber, NULL, 16 );
3158
3159 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
3160 * '00000437 ;Georgian'
3161 * At present we only pass the LCID string.
3162 */
3163
3164 if (lpProcs->procW)
3165 bContinue = lpProcs->procW( lgrpid, lcid, szNumber, lpProcs->lParam );
3166 else
3167 {
3168 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
3169
3170 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
3171
3172 bContinue = lpProcs->procA( lgrpid, lcid, szNumberA, lpProcs->lParam );
3173 }
3174 }
3175
3176 ulIndex++;
3177 }
3178 else
3179 {
3180 /* Finished enumerating this key */
3181 if (!bAlternate)
3182 {
3183 /* Enumerate alternate sorts also */
3184 hKey = NLS_RegOpenKey( hKey, szAlternateSortsKeyName );
3185 bAlternate = TRUE;
3186 ulIndex = 0;
3187 }
3188 else
3189 bContinue = FALSE; /* Finished both keys */
3190 }
3191
3192 if (!bContinue)
3193 break;
3194 }
3195
3196 if (hKey)
3197 NtClose( hKey );
3198
3199 return TRUE;
3200}
3201
3207
3215};
3216
3217static const struct geoinfo_t geoinfodata[] = {
3218 { 2, {'A','G',0}, {'A','T','G',0}, 10039880, 28 }, /* Antigua and Barbuda */
3219 { 3, {'A','F',0}, {'A','F','G',0}, 47614, 4 }, /* Afghanistan */
3220 { 4, {'D','Z',0}, {'D','Z','A',0}, 42487, 12 }, /* Algeria */
3221 { 5, {'A','Z',0}, {'A','Z','E',0}, 47611, 31 }, /* Azerbaijan */
3222 { 6, {'A','L',0}, {'A','L','B',0}, 47610, 8 }, /* Albania */
3223 { 7, {'A','M',0}, {'A','R','M',0}, 47611, 51 }, /* Armenia */
3224 { 8, {'A','D',0}, {'A','N','D',0}, 47610, 20 }, /* Andorra */
3225 { 9, {'A','O',0}, {'A','G','O',0}, 42484, 24 }, /* Angola */
3226 { 10, {'A','S',0}, {'A','S','M',0}, 26286, 16 }, /* American Samoa */
3227 { 11, {'A','R',0}, {'A','R','G',0}, 31396, 32 }, /* Argentina */
3228 { 12, {'A','U',0}, {'A','U','S',0}, 10210825, 36 }, /* Australia */
3229 { 14, {'A','T',0}, {'A','U','T',0}, 10210824, 40 }, /* Austria */
3230 { 17, {'B','H',0}, {'B','H','R',0}, 47611, 48 }, /* Bahrain */
3231 { 18, {'B','B',0}, {'B','R','B',0}, 10039880, 52 }, /* Barbados */
3232 { 19, {'B','W',0}, {'B','W','A',0}, 10039883, 72 }, /* Botswana */
3233 { 20, {'B','M',0}, {'B','M','U',0}, 23581, 60 }, /* Bermuda */
3234 { 21, {'B','E',0}, {'B','E','L',0}, 10210824, 56 }, /* Belgium */
3235 { 22, {'B','S',0}, {'B','H','S',0}, 10039880, 44 }, /* Bahamas, The */
3236 { 23, {'B','D',0}, {'B','G','D',0}, 47614, 50 }, /* Bangladesh */
3237 { 24, {'B','Z',0}, {'B','L','Z',0}, 27082, 84 }, /* Belize */
3238 { 25, {'B','A',0}, {'B','I','H',0}, 47610, 70 }, /* Bosnia and Herzegovina */
3239 { 26, {'B','O',0}, {'B','O','L',0}, 31396, 68 }, /* Bolivia */
3240 { 27, {'M','M',0}, {'M','M','R',0}, 47599, 104 }, /* Myanmar */
3241 { 28, {'B','J',0}, {'B','E','N',0}, 42483, 204 }, /* Benin */
3242 { 29, {'B','Y',0}, {'B','L','R',0}, 47609, 112 }, /* Belarus */
3243 { 30, {'S','B',0}, {'S','L','B',0}, 20900, 90 }, /* Solomon Islands */
3244 { 32, {'B','R',0}, {'B','R','A',0}, 31396, 76 }, /* Brazil */
3245 { 34, {'B','T',0}, {'B','T','N',0}, 47614, 64 }, /* Bhutan */
3246 { 35, {'B','G',0}, {'B','G','R',0}, 47609, 100 }, /* Bulgaria */
3247 { 37, {'B','N',0}, {'B','R','N',0}, 47599, 96 }, /* Brunei */
3248 { 38, {'B','I',0}, {'B','D','I',0}, 47603, 108 }, /* Burundi */
3249 { 39, {'C','A',0}, {'C','A','N',0}, 23581, 124 }, /* Canada */
3250 { 40, {'K','H',0}, {'K','H','M',0}, 47599, 116 }, /* Cambodia */
3251 { 41, {'T','D',0}, {'T','C','D',0}, 42484, 148 }, /* Chad */
3252 { 42, {'L','K',0}, {'L','K','A',0}, 47614, 144 }, /* Sri Lanka */
3253 { 43, {'C','G',0}, {'C','O','G',0}, 42484, 178 }, /* Congo */
3254 { 44, {'C','D',0}, {'C','O','D',0}, 42484, 180 }, /* Congo (DRC) */
3255 { 45, {'C','N',0}, {'C','H','N',0}, 47600, 156 }, /* China */
3256 { 46, {'C','L',0}, {'C','H','L',0}, 31396, 152 }, /* Chile */
3257 { 49, {'C','M',0}, {'C','M','R',0}, 42484, 120 }, /* Cameroon */
3258 { 50, {'K','M',0}, {'C','O','M',0}, 47603, 174 }, /* Comoros */
3259 { 51, {'C','O',0}, {'C','O','L',0}, 31396, 170 }, /* Colombia */
3260 { 54, {'C','R',0}, {'C','R','I',0}, 27082, 188 }, /* Costa Rica */
3261 { 55, {'C','F',0}, {'C','A','F',0}, 42484, 140 }, /* Central African Republic */
3262 { 56, {'C','U',0}, {'C','U','B',0}, 10039880, 192 }, /* Cuba */
3263 { 57, {'C','V',0}, {'C','P','V',0}, 42483, 132 }, /* Cape Verde */
3264 { 59, {'C','Y',0}, {'C','Y','P',0}, 47611, 196 }, /* Cyprus */
3265 { 61, {'D','K',0}, {'D','N','K',0}, 10039882, 208 }, /* Denmark */
3266 { 62, {'D','J',0}, {'D','J','I',0}, 47603, 262 }, /* Djibouti */
3267 { 63, {'D','M',0}, {'D','M','A',0}, 10039880, 212 }, /* Dominica */
3268 { 65, {'D','O',0}, {'D','O','M',0}, 10039880, 214 }, /* Dominican Republic */
3269 { 66, {'E','C',0}, {'E','C','U',0}, 31396, 218 }, /* Ecuador */
3270 { 67, {'E','G',0}, {'E','G','Y',0}, 42487, 818 }, /* Egypt */
3271 { 68, {'I','E',0}, {'I','R','L',0}, 10039882, 372 }, /* Ireland */
3272 { 69, {'G','Q',0}, {'G','N','Q',0}, 42484, 226 }, /* Equatorial Guinea */
3273 { 70, {'E','E',0}, {'E','S','T',0}, 10039882, 233 }, /* Estonia */
3274 { 71, {'E','R',0}, {'E','R','I',0}, 47603, 232 }, /* Eritrea */
3275 { 72, {'S','V',0}, {'S','L','V',0}, 27082, 222 }, /* El Salvador */
3276 { 73, {'E','T',0}, {'E','T','H',0}, 47603, 231 }, /* Ethiopia */
3277 { 75, {'C','Z',0}, {'C','Z','E',0}, 47609, 203 }, /* Czech Republic */
3278 { 77, {'F','I',0}, {'F','I','N',0}, 10039882, 246 }, /* Finland */
3279 { 78, {'F','J',0}, {'F','J','I',0}, 20900, 242 }, /* Fiji Islands */
3280 { 80, {'F','M',0}, {'F','S','M',0}, 21206, 583 }, /* Micronesia */
3281 { 81, {'F','O',0}, {'F','R','O',0}, 10039882, 234 }, /* Faroe Islands */
3282 { 84, {'F','R',0}, {'F','R','A',0}, 10210824, 250 }, /* France */
3283 { 86, {'G','M',0}, {'G','M','B',0}, 42483, 270 }, /* Gambia, The */
3284 { 87, {'G','A',0}, {'G','A','B',0}, 42484, 266 }, /* Gabon */
3285 { 88, {'G','E',0}, {'G','E','O',0}, 47611, 268 }, /* Georgia */
3286 { 89, {'G','H',0}, {'G','H','A',0}, 42483, 288 }, /* Ghana */
3287 { 90, {'G','I',0}, {'G','I','B',0}, 47610, 292 }, /* Gibraltar */
3288 { 91, {'G','D',0}, {'G','R','D',0}, 10039880, 308 }, /* Grenada */
3289 { 93, {'G','L',0}, {'G','R','L',0}, 23581, 304 }, /* Greenland */
3290 { 94, {'D','E',0}, {'D','E','U',0}, 10210824, 276 }, /* Germany */
3291 { 98, {'G','R',0}, {'G','R','C',0}, 47610, 300 }, /* Greece */
3292 { 99, {'G','T',0}, {'G','T','M',0}, 27082, 320 }, /* Guatemala */
3293 { 100, {'G','N',0}, {'G','I','N',0}, 42483, 324 }, /* Guinea */
3294 { 101, {'G','Y',0}, {'G','U','Y',0}, 31396, 328 }, /* Guyana */
3295 { 103, {'H','T',0}, {'H','T','I',0}, 10039880, 332 }, /* Haiti */
3296 { 104, {'H','K',0}, {'H','K','G',0}, 47600, 344 }, /* Hong Kong S.A.R. */
3297 { 106, {'H','N',0}, {'H','N','D',0}, 27082, 340 }, /* Honduras */
3298 { 108, {'H','R',0}, {'H','R','V',0}, 47610, 191 }, /* Croatia */
3299 { 109, {'H','U',0}, {'H','U','N',0}, 47609, 348 }, /* Hungary */
3300 { 110, {'I','S',0}, {'I','S','L',0}, 10039882, 352 }, /* Iceland */
3301 { 111, {'I','D',0}, {'I','D','N',0}, 47599, 360 }, /* Indonesia */
3302 { 113, {'I','N',0}, {'I','N','D',0}, 47614, 356 }, /* India */
3303 { 114, {'I','O',0}, {'I','O','T',0}, 39070, 86 }, /* British Indian Ocean Territory */
3304 { 116, {'I','R',0}, {'I','R','N',0}, 47614, 364 }, /* Iran */
3305 { 117, {'I','L',0}, {'I','S','R',0}, 47611, 376 }, /* Israel */
3306 { 118, {'I','T',0}, {'I','T','A',0}, 47610, 380 }, /* Italy */
3307 { 119, {'C','I',0}, {'C','I','V',0}, 42483, 384 }, /* Côte d'Ivoire */
3308 { 121, {'I','Q',0}, {'I','R','Q',0}, 47611, 368 }, /* Iraq */
3309 { 122, {'J','P',0}, {'J','P','N',0}, 47600, 392 }, /* Japan */
3310 { 124, {'J','M',0}, {'J','A','M',0}, 10039880, 388 }, /* Jamaica */
3311 { 125, {'S','J',0}, {'S','J','M',0}, 10039882, 744 }, /* Jan Mayen */
3312 { 126, {'J','O',0}, {'J','O','R',0}, 47611, 400 }, /* Jordan */
3313 { 127, {'X','X',0}, {'X','X',0}, 161832256 }, /* Johnston Atoll */
3314 { 129, {'K','E',0}, {'K','E','N',0}, 47603, 404 }, /* Kenya */
3315 { 130, {'K','G',0}, {'K','G','Z',0}, 47590, 417 }, /* Kyrgyzstan */
3316 { 131, {'K','P',0}, {'P','R','K',0}, 47600, 408 }, /* North Korea */
3317 { 133, {'K','I',0}, {'K','I','R',0}, 21206, 296 }, /* Kiribati */
3318 { 134, {'K','R',0}, {'K','O','R',0}, 47600, 410 }, /* Korea */
3319 { 136, {'K','W',0}, {'K','W','T',0}, 47611, 414 }, /* Kuwait */
3320 { 137, {'K','Z',0}, {'K','A','Z',0}, 47590, 398 }, /* Kazakhstan */
3321 { 138, {'L','A',0}, {'L','A','O',0}, 47599, 418 }, /* Laos */
3322 { 139, {'L','B',0}, {'L','B','N',0}, 47611, 422 }, /* Lebanon */
3323 { 140, {'L','V',0}, {'L','V','A',0}, 10039882, 428 }, /* Latvia */
3324 { 141, {'L','T',0}, {'L','T','U',0}, 10039882, 440 }, /* Lithuania */
3325 { 142, {'L','R',0}, {'L','B','R',0}, 42483, 430 }, /* Liberia */
3326 { 143, {'S','K',0}, {'S','V','K',0}, 47609, 703 }, /* Slovakia */
3327 { 145, {'L','I',0}, {'L','I','E',0}, 10210824, 438 }, /* Liechtenstein */
3328 { 146, {'L','S',0}, {'L','S','O',0}, 10039883, 426 }, /* Lesotho */
3329 { 147, {'L','U',0}, {'L','U','X',0}, 10210824, 442 }, /* Luxembourg */
3330 { 148, {'L','Y',0}, {'L','B','Y',0}, 42487, 434 }, /* Libya */
3331 { 149, {'M','G',0}, {'M','D','G',0}, 47603, 450 }, /* Madagascar */
3332 { 151, {'M','O',0}, {'M','A','C',0}, 47600, 446 }, /* Macao S.A.R. */
3333 { 152, {'M','D',0}, {'M','D','A',0}, 47609, 498 }, /* Moldova */
3334 { 154, {'M','N',0}, {'M','N','G',0}, 47600, 496 }, /* Mongolia */
3335 { 156, {'M','W',0}, {'M','W','I',0}, 47603, 454 }, /* Malawi */
3336 { 157, {'M','L',0}, {'M','L','I',0}, 42483, 466 }, /* Mali */
3337 { 158, {'M','C',0}, {'M','C','O',0}, 10210824, 492 }, /* Monaco */
3338 { 159, {'M','A',0}, {'M','A','R',0}, 42487, 504 }, /* Morocco */
3339 { 160, {'M','U',0}, {'M','U','S',0}, 47603, 480 }, /* Mauritius */
3340 { 162, {'M','R',0}, {'M','R','T',0}, 42483, 478 }, /* Mauritania */
3341 { 163, {'M','T',0}, {'M','L','T',0}, 47610, 470 }, /* Malta */
3342 { 164, {'O','M',0}, {'O','M','N',0}, 47611, 512 }, /* Oman */
3343 { 165, {'M','V',0}, {'M','D','V',0}, 47614, 462 }, /* Maldives */
3344 { 166, {'M','X',0}, {'M','E','X',0}, 27082, 484 }, /* Mexico */
3345 { 167, {'M','Y',0}, {'M','Y','S',0}, 47599, 458 }, /* Malaysia */
3346 { 168, {'M','Z',0}, {'M','O','Z',0}, 47603, 508 }, /* Mozambique */
3347 { 173, {'N','E',0}, {'N','E','R',0}, 42483, 562 }, /* Niger */
3348 { 174, {'V','U',0}, {'V','U','T',0}, 20900, 548 }, /* Vanuatu */
3349 { 175, {'N','G',0}, {'N','G','A',0}, 42483, 566 }, /* Nigeria */
3350 { 176, {'N','L',0}, {'N','L','D',0}, 10210824, 528 }, /* Netherlands */
3351 { 177, {'N','O',0}, {'N','O','R',0}, 10039882, 578 }, /* Norway */
3352 { 178, {'N','P',0}, {'N','P','L',0}, 47614, 524 }, /* Nepal */
3353 { 180, {'N','R',0}, {'N','R','U',0}, 21206, 520 }, /* Nauru */
3354 { 181, {'S','R',0}, {'S','U','R',0}, 31396, 740 }, /* Suriname */
3355 { 182, {'N','I',0}, {'N','I','C',0}, 27082, 558 }, /* Nicaragua */
3356 { 183, {'N','Z',0}, {'N','Z','L',0}, 10210825, 554 }, /* New Zealand */
3357 { 184, {'P','S',0}, {'P','S','E',0}, 47611, 275 }, /* Palestinian Authority */
3358 { 185, {'P','Y',0}, {'P','R','Y',0}, 31396, 600 }, /* Paraguay */
3359 { 187, {'P','E',0}, {'P','E','R',0}, 31396, 604 }, /* Peru */
3360 { 190, {'P','K',0}, {'P','A','K',0}, 47614, 586 }, /* Pakistan */
3361 { 191, {'P','L',0}, {'P','O','L',0}, 47609, 616 }, /* Poland */
3362 { 192, {'P','A',0}, {'P','A','N',0}, 27082, 591 }, /* Panama */
3363 { 193, {'P','T',0}, {'P','R','T',0}, 47610, 620 }, /* Portugal */
3364 { 194, {'P','G',0}, {'P','N','G',0}, 20900, 598 }, /* Papua New Guinea */
3365 { 195, {'P','W',0}, {'P','L','W',0}, 21206, 585 }, /* Palau */
3366 { 196, {'G','W',0}, {'G','N','B',0}, 42483, 624 }, /* Guinea-Bissau */
3367 { 197, {'Q','A',0}, {'Q','A','T',0}, 47611, 634 }, /* Qatar */
3368 { 198, {'R','E',0}, {'R','E','U',0}, 47603, 638 }, /* Reunion */
3369 { 199, {'M','H',0}, {'M','H','L',0}, 21206, 584 }, /* Marshall Islands */
3370 { 200, {'R','O',0}, {'R','O','U',0}, 47609, 642 }, /* Romania */
3371 { 201, {'P','H',0}, {'P','H','L',0}, 47599, 608 }, /* Philippines */
3372 { 202, {'P','R',0}, {'P','R','I',0}, 10039880, 630 }, /* Puerto Rico */
3373 { 203, {'R','U',0}, {'R','U','S',0}, 47609, 643 }, /* Russia */
3374 { 204, {'R','W',0}, {'R','W','A',0}, 47603, 646 }, /* Rwanda */
3375 { 205, {'S','A',0}, {'S','A','U',0}, 47611, 682 }, /* Saudi Arabia */
3376 { 206, {'P','M',0}, {'S','P','M',0}, 23581, 666 }, /* St. Pierre and Miquelon */
3377 { 207, {'K','N',0}, {'K','N','A',0}, 10039880, 659 }, /* St. Kitts and Nevis */
3378 { 208, {'S','C',0}, {'S','Y','C',0}, 47603, 690 }, /* Seychelles */
3379 { 209, {'Z','A',0}, {'Z','A','F',0}, 10039883, 710 }, /* South Africa */
3380 { 210, {'S','N',0}, {'S','E','N',0}, 42483, 686 }, /* Senegal */
3381 { 212, {'S','I',0}, {'S','V','N',0}, 47610, 705 }, /* Slovenia */
3382 { 213, {'S','L',0}, {'S','L','E',0}, 42483, 694 }, /* Sierra Leone */
3383 { 214, {'S','M',0}, {'S','M','R',0}, 47610, 674 }, /* San Marino */
3384 { 215, {'S','G',0}, {'S','G','P',0}, 47599, 702 }, /* Singapore */
3385 { 216, {'S','O',0}, {'S','O','M',0}, 47603, 706 }, /* Somalia */
3386 { 217, {'E','S',0}, {'E','S','P',0}, 47610, 724 }, /* Spain */
3387 { 218, {'L','C',0}, {'L','C','A',0}, 10039880, 662 }, /* St. Lucia */
3388 { 219, {'S','D',0}, {'S','D','N',0}, 42487, 736 }, /* Sudan */
3389 { 220, {'S','J',0}, {'S','J','M',0}, 10039882, 744 }, /* Svalbard */
3390 { 221, {'S','E',0}, {'S','W','E',0}, 10039882, 752 }, /* Sweden */
3391 { 222, {'S','Y',0}, {'S','Y','R',0}, 47611, 760 }, /* Syria */
3392 { 223, {'C','H',0}, {'C','H','E',0}, 10210824, 756 }, /* Switzerland */
3393 { 224, {'A','E',0}, {'A','R','E',0}, 47611, 784 }, /* United Arab Emirates */
3394 { 225, {'T','T',0}, {'T','T','O',0}, 10039880, 780 }, /* Trinidad and Tobago */
3395 { 227, {'T','H',0}, {'T','H','A',0}, 47599, 764 }, /* Thailand */
3396 { 228, {'T','J',0}, {'T','J','K',0}, 47590, 762 }, /* Tajikistan */
3397 { 231, {'T','O',0}, {'T','O','N',0}, 26286, 776 }, /* Tonga */
3398 { 232, {'T','G',0}, {'T','G','O',0}, 42483, 768 }, /* Togo */
3399 { 233, {'S','T',0}, {'S','T','P',0}, 42484, 678 }, /* São Tomé and Príncipe */
3400 { 234, {'T','N',0}, {'T','U','N',0}, 42487, 788 }, /* Tunisia */
3401 { 235, {'T','R',0}, {'T','U','R',0}, 47611, 792 }, /* Turkey */
3402 { 236, {'T','V',0}, {'T','U','V',0}, 26286, 798 }, /* Tuvalu */
3403 { 237, {'T','W',0}, {'T','W','N',0}, 47600, 158 }, /* Taiwan */
3404 { 238, {'T','M',0}, {'T','K','M',0}, 47590, 795 }, /* Turkmenistan */
3405 { 239, {'T','Z',0}, {'T','Z','A',0}, 47603, 834 }, /* Tanzania */
3406 { 240, {'U','G',0}, {'U','G','A',0}, 47603, 800 }, /* Uganda */
3407 { 241, {'U','A',0}, {'U','K','R',0}, 47609, 804 }, /* Ukraine */
3408 { 242, {'G','B',0}, {'G','B','R',0}, 10039882, 826 }, /* United Kingdom */
3409 { 244, {'U','S',0}, {'U','S','A',0}, 23581, 840 }, /* United States */
3410 { 245, {'B','F',0}, {'B','F','A',0}, 42483, 854 }, /* Burkina Faso */
3411 { 246, {'U','Y',0}, {'U','R','Y',0}, 31396, 858 }, /* Uruguay */
3412 { 247, {'U','Z',0}, {'U','Z','B',0}, 47590, 860 }, /* Uzbekistan */
3413 { 248, {'V','C',0}, {'V','C','T',0}, 10039880, 670 }, /* St. Vincent and the Grenadines */
3414 { 249, {'V','E',0}, {'V','E','N',0}, 31396, 862 }, /* Bolivarian Republic of Venezuela */
3415 { 251, {'V','N',0}, {'V','N','M',0}, 47599, 704 }, /* Vietnam */
3416 { 252, {'V','I',0}, {'V','I','R',0}, 10039880, 850 }, /* Virgin Islands */
3417 { 253, {'V','A',0}, {'V','A','T',0}, 47610, 336 }, /* Vatican City */
3418 { 254, {'N','A',0}, {'N','A','M',0}, 10039883, 516 }, /* Namibia */
3419 { 257, {'E','H',0}, {'E','S','H',0}, 42487, 732 }, /* Western Sahara (disputed) */
3420 { 258, {'X','X',0}, {'X','X',0}, 161832256 }, /* Wake Island */
3421 { 259, {'W','S',0}, {'W','S','M',0}, 26286, 882 }, /* Samoa */
3422 { 260, {'S','Z',0}, {'S','W','Z',0}, 10039883, 748 }, /* Swaziland */
3423 { 261, {'Y','E',0}, {'Y','E','M',0}, 47611, 887 }, /* Yemen */
3424 { 263, {'Z','M',0}, {'Z','M','B',0}, 47603, 894 }, /* Zambia */
3425 { 264, {'Z','W',0}, {'Z','W','E',0}, 47603, 716 }, /* Zimbabwe */
3426 { 269, {'C','S',0}, {'S','C','G',0}, 47610, 891 }, /* Serbia and Montenegro (Former) */
3427 { 270, {'M','E',0}, {'M','N','E',0}, 47610, 499 }, /* Montenegro */
3428 { 271, {'R','S',0}, {'S','R','B',0}, 47610, 688 }, /* Serbia */
3429 { 273, {'C','W',0}, {'C','U','W',0}, 10039880, 531 }, /* Curaçao */
3430 { 276, {'S','S',0}, {'S','S','D',0}, 42487, 728 }, /* South Sudan */
3431 { 300, {'A','I',0}, {'A','I','A',0}, 10039880, 660 }, /* Anguilla */
3432 { 301, {'A','Q',0}, {'A','T','A',0}, 39070, 10 }, /* Antarctica */
3433 { 302, {'A','W',0}, {'A','B','W',0}, 10039880, 533 }, /* Aruba */
3434 { 303, {'X','X',0}, {'X','X',0}, 39070 }, /* Ascension Island */
3435 { 304, {'X','X',0}, {'X','X',0}, 10210825 }, /* Ashmore and Cartier Islands */
3436 { 305, {'X','X',0}, {'X','X',0}, 161832256 }, /* Baker Island */
3437 { 306, {'B','V',0}, {'B','V','T',0}, 39070, 74 }, /* Bouvet Island */
3438 { 307, {'K','Y',0}, {'C','Y','M',0}, 10039880, 136 }, /* Cayman Islands */
3439 { 308, {'X','X',0}, {'X','X',0}, 10210824, 0, LOCATION_BOTH }, /* Channel Islands */
3440 { 309, {'C','X',0}, {'C','X','R',0}, 12, 162 }, /* Christmas Island */
3441 { 310, {'X','X',0}, {'X','X',0}, 27114 }, /* Clipperton Island */
3442 { 311, {'C','C',0}, {'C','C','K',0}, 10210825, 166 }, /* Cocos (Keeling) Islands */
3443 { 312, {'C','K',0}, {'C','O','K',0}, 26286, 184 }, /* Cook Islands */
3444 { 313, {'X','X',0}, {'X','X',0}, 10210825 }, /* Coral Sea Islands */
3445 { 314, {'X','X',0}, {'X','X',0}, 114 }, /* Diego Garcia */
3446 { 315, {'F','K',0}, {'F','L','K',0}, 31396, 238 }, /* Falkland Islands (Islas Malvinas) */
3447 { 317, {'G','F',0}, {'G','U','F',0}, 31396, 254 }, /* French Guiana */
3448 { 318, {'P','F',0}, {'P','Y','F',0}, 26286, 258 }, /* French Polynesia */
3449 { 319, {'T','F',0}, {'A','T','F',0}, 39070, 260 }, /* French Southern and Antarctic Lands */
3450 { 321, {'G','P',0}, {'G','L','P',0}, 10039880, 312 }, /* Guadeloupe */
3451 { 322, {'G','U',0}, {'G','U','M',0}, 21206, 316 }, /* Guam */
3452 { 323, {'X','X',0}, {'X','X',0}, 39070 }, /* Guantanamo Bay */
3453 { 324, {'G','G',0}, {'G','G','Y',0}, 308, 831 }, /* Guernsey */
3454 { 325, {'H','M',0}, {'H','M','D',0}, 39070, 334 }, /* Heard Island and McDonald Islands */
3455 { 326, {'X','X',0}, {'X','X',0}, 161832256 }, /* Howland Island */
3456 { 327, {'X','X',0}, {'X','X',0}, 161832256 }, /* Jarvis Island */
3457 { 328, {'J','E',0}, {'J','E','Y',0}, 308, 832 }, /* Jersey */
3458 { 329, {'X','X',0}, {'X','X',0}, 161832256 }, /* Kingman Reef */
3459 { 330, {'M','Q',0}, {'M','T','Q',0}, 10039880, 474 }, /* Martinique */
3460 { 331, {'Y','T',0}, {'M','Y','T',0}, 47603, 175 }, /* Mayotte */
3461 { 332, {'M','S',0}, {'M','S','R',0}, 10039880, 500 }, /* Montserrat */
3462 { 333, {'A','N',0}, {'A','N','T',0}, 10039880, 530, LOCATION_BOTH }, /* Netherlands Antilles (Former) */
3463 { 334, {'N','C',0}, {'N','C','L',0}, 20900, 540 }, /* New Caledonia */
3464 { 335, {'N','U',0}, {'N','I','U',0}, 26286, 570 }, /* Niue */
3465 { 336, {'N','F',0}, {'N','F','K',0}, 10210825, 574 }, /* Norfolk Island */
3466 { 337, {'M','P',0}, {'M','N','P',0}, 21206, 580 }, /* Northern Mariana Islands */
3467 { 338, {'X','X',0}, {'X','X',0}, 161832256 }, /* Palmyra Atoll */
3468 { 339, {'P','N',0}, {'P','C','N',0}, 26286, 612 }, /* Pitcairn Islands */
3469 { 340, {'X','X',0}, {'X','X',0}, 337 }, /* Rota Island */
3470 { 341, {'X','X',0}, {'X','X',0}, 337 }, /* Saipan */
3471 { 342, {'G','S',0}, {'S','G','S',0}, 39070, 239 }, /* South Georgia and the South Sandwich Islands */
3472 { 343, {'S','H',0}, {'S','H','N',0}, 42483, 654 }, /* St. Helena */
3473 { 346, {'X','X',0}, {'X','X',0}, 337 }, /* Tinian Island */
3474 { 347, {'T','K',0}, {'T','K','L',0}, 26286, 772 }, /* Tokelau */
3475 { 348, {'X','X',0}, {'X','X',0}, 39070 }, /* Tristan da Cunha */
3476 { 349, {'T','C',0}, {'T','C','A',0}, 10039880, 796 }, /* Turks and Caicos Islands */
3477 { 351, {'V','G',0}, {'V','G','B',0}, 10039880, 92 }, /* Virgin Islands, British */
3478 { 352, {'W','F',0}, {'W','L','F',0}, 26286, 876 }, /* Wallis and Futuna */
3479 { 742, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Africa */
3480 { 2129, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Asia */
3481 { 10541, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Europe */
3482 { 15126, {'I','M',0}, {'I','M','N',0}, 10039882, 833 }, /* Man, Isle of */
3483 { 19618, {'M','K',0}, {'M','K','D',0}, 47610, 807 }, /* Macedonia, Former Yugoslav Republic of */
3484 { 20900, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION }, /* Melanesia */
3485 { 21206, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION }, /* Micronesia */
3486 { 21242, {'X','X',0}, {'X','X',0}, 161832256 }, /* Midway Islands */
3487 { 23581, {'X','X',0}, {'X','X',0}, 10026358, 0, LOCATION_REGION }, /* Northern America */
3488 { 26286, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION }, /* Polynesia */
3489 { 27082, {'X','X',0}, {'X','X',0}, 161832257, 0, LOCATION_REGION }, /* Central America */
3490 { 27114, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Oceania */
3491 { 30967, {'S','X',0}, {'S','X','M',0}, 10039880, 534 }, /* Sint Maarten (Dutch part) */
3492 { 31396, {'X','X',0}, {'X','X',0}, 161832257, 0, LOCATION_REGION }, /* South America */
3493 { 31706, {'M','F',0}, {'M','A','F',0}, 10039880, 663 }, /* Saint Martin (French part) */
3494 { 39070, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* World */
3495 { 42483, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Western Africa */
3496 { 42484, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Middle Africa */
3497 { 42487, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Northern Africa */
3498 { 47590, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* Central Asia */
3499 { 47599, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* South-Eastern Asia */
3500 { 47600, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* Eastern Asia */
3501 { 47603, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Eastern Africa */
3502 { 47609, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION }, /* Eastern Europe */
3503 { 47610, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION }, /* Southern Europe */
3504 { 47611, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* Middle East */
3505 { 47614, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* Southern Asia */
3506 { 7299303, {'T','L',0}, {'T','L','S',0}, 47599, 626 }, /* Democratic Republic of Timor-Leste */
3507 { 10026358, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Americas */
3508 { 10028789, {'A','X',0}, {'A','L','A',0}, 10039882, 248 }, /* Åland Islands */
3509 { 10039880, {'X','X',0}, {'X','X',0}, 161832257, 0, LOCATION_REGION }, /* Caribbean */
3510 { 10039882, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION }, /* Northern Europe */
3511 { 10039883, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Southern Africa */
3512 { 10210824, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION }, /* Western Europe */
3513 { 10210825, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION }, /* Australia and New Zealand */
3514 { 161832015, {'B','L',0}, {'B','L','M',0}, 10039880, 652 }, /* Saint Barthélemy */
3515 { 161832256, {'U','M',0}, {'U','M','I',0}, 27114, 581 }, /* U.S. Minor Outlying Islands */
3516 { 161832257, {'X','X',0}, {'X','X',0}, 10026358, 0, LOCATION_REGION }, /* Latin America and the Caribbean */
3517};
3518
3519/******************************************************************************
3520 * EnumLanguageGroupLocalesA (KERNEL32.@)
3521 *
3522 * Call a users function for every locale in a language group available on the system.
3523 *
3524 * PARAMS
3525 * pLangGrpLcEnumProc [I] Callback function to call for each locale
3526 * lgrpid [I] Language group (LGRPID_ values from "winnls.h")
3527 * dwFlags [I] Reserved, set to 0
3528 * lParam [I] User parameter to pass to pLangGrpLcEnumProc
3529 *
3530 * RETURNS
3531 * Success: TRUE.
3532 * Failure: FALSE. Use GetLastError() to determine the cause.
3533 */
3536{
3538
3539 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc, lgrpid, dwFlags, lParam);
3540
3541 callbacks.procA = pLangGrpLcEnumProc;
3542 callbacks.procW = NULL;
3543 callbacks.dwFlags = dwFlags;
3544 callbacks.lgrpid = lgrpid;
3545 callbacks.lParam = lParam;
3546
3547 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc ? &callbacks : NULL );
3548}
3549
3550/******************************************************************************
3551 * EnumLanguageGroupLocalesW (KERNEL32.@)
3552 *
3553 * See EnumLanguageGroupLocalesA.
3554 */
3557{
3559
3560 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc, lgrpid, dwFlags, lParam);
3561
3562 callbacks.procA = NULL;
3563 callbacks.procW = pLangGrpLcEnumProc;
3564 callbacks.dwFlags = dwFlags;
3565 callbacks.lgrpid = lgrpid;
3566 callbacks.lParam = lParam;
3567
3568 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc ? &callbacks : NULL );
3569}
3570
3571/* Callback function ptrs for EnumSystemCodePagesA/W */
3572typedef struct
3573{
3578
3579/* Internal implementation of EnumSystemCodePagesA/W */
3581{
3582 WCHAR szNumber[5 + 1], szValue[MAX_PATH];
3583 HANDLE hKey;
3584 BOOL bContinue = TRUE;
3585 ULONG ulIndex = 0;
3586
3587 if (!lpProcs)
3588 {
3590 return FALSE;
3591 }
3592
3593 switch (lpProcs->dwFlags)
3594 {
3595 case CP_INSTALLED:
3596 case CP_SUPPORTED:
3597 break;
3598 default:
3600 return FALSE;
3601 }
3602
3603 hKey = NLS_RegOpenKey(0, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
3604 if (!hKey)
3605 {
3606 WARN("NLS_RegOpenKey() failed\n");
3607 return FALSE;
3608 }
3609
3610 while (bContinue)
3611 {
3612 if (NLS_RegEnumValue(hKey, ulIndex, szNumber, sizeof(szNumber),
3613 szValue, sizeof(szValue)))
3614 {
3615 if ((lpProcs->dwFlags == CP_SUPPORTED)||
3616 ((lpProcs->dwFlags == CP_INSTALLED)&&(wcslen(szValue) > 2)))
3617 {
3618 if (lpProcs->procW)
3619 {
3620 bContinue = lpProcs->procW(szNumber);
3621 }
3622 else
3623 {
3624 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
3625
3626 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
3627 bContinue = lpProcs->procA(szNumberA);
3628 }
3629 }
3630
3631 ulIndex++;
3632
3633 } else bContinue = FALSE;
3634
3635 if (!bContinue)
3636 break;
3637 }
3638
3639 if (hKey)
3640 NtClose(hKey);
3641
3642 return TRUE;
3643}
3644
3645/*
3646 * @implemented
3647 */
3648BOOL
3649WINAPI
3651 CODEPAGE_ENUMPROCW lpCodePageEnumProc,
3653 )
3654{
3656
3657 TRACE("(%p,0x%08X)\n", lpCodePageEnumProc, dwFlags);
3658
3659 procs.procA = NULL;
3660 procs.procW = lpCodePageEnumProc;
3661 procs.dwFlags = dwFlags;
3662
3663 return NLS_EnumSystemCodePages(lpCodePageEnumProc ? &procs : NULL);
3664}
3665
3666
3667/*
3668 * @implemented
3669 */
3670BOOL
3671WINAPI
3673 CODEPAGE_ENUMPROCA lpCodePageEnumProc,
3675 )
3676{
3678
3679 TRACE("(%p,0x%08X)\n", lpCodePageEnumProc, dwFlags);
3680
3681 procs.procA = lpCodePageEnumProc;
3682 procs.procW = NULL;
3683 procs.dwFlags = dwFlags;
3684
3685 return NLS_EnumSystemCodePages(lpCodePageEnumProc ? &procs : NULL);
3686}
3687
3688/******************************************************************************
3689 * EnumSystemGeoID (KERNEL32.@)
3690 *
3691 * Call a users function for every location available on the system.
3692 *
3693 * PARAMS
3694 * geoclass [I] Type of information desired (SYSGEOTYPE enum from "winnls.h")
3695 * parent [I] GEOID for the parent
3696 * enumproc [I] Callback function to call for each location
3697 *
3698 * RETURNS
3699 * Success: TRUE.
3700 * Failure: FALSE. Use GetLastError() to determine the cause.
3701 */
3703{
3704 INT i;
3705
3706 TRACE("(%d, %d, %p)\n", geoclass, parent, enumproc);
3707
3708 if (!enumproc) {
3710 return FALSE;
3711 }
3712
3713 if (geoclass != GEOCLASS_NATION && geoclass != GEOCLASS_REGION) {
3715 return FALSE;
3716 }
3717
3718 for (i = 0; i < sizeof(geoinfodata)/sizeof(struct geoinfo_t); i++) {
3719 const struct geoinfo_t *ptr = &geoinfodata[i];
3720
3721 if (geoclass == GEOCLASS_NATION && (ptr->kind == LOCATION_REGION))
3722 continue;
3723
3724 if (geoclass == GEOCLASS_REGION && (ptr->kind == LOCATION_NATION))
3725 continue;
3726
3727 if (parent && ptr->parent != parent)
3728 continue;
3729
3730 if (!enumproc(ptr->id))
3731 return TRUE;
3732 }
3733
3734 return TRUE;
3735}
3736
3737/******************************************************************************
3738 * InvalidateNLSCache (KERNEL32.@)
3739 *
3740 * Invalidate the cache of NLS values.
3741 *
3742 * PARAMS
3743 * None.
3744 *
3745 * RETURNS
3746 * Success: TRUE.
3747 * Failure: FALSE.
3748 */
3750{
3751#ifdef __REACTOS__
3753 return TRUE;
3754#else
3755 FIXME("() stub\n");
3756 return FALSE;
3757#endif
3758}
3759
3760/******************************************************************************
3761 * GetUserGeoID (KERNEL32.@)
3762 */
3764{
3766 static const WCHAR geoW[] = {'G','e','o',0};
3767 static const WCHAR nationW[] = {'N','a','t','i','o','n',0};
3768 WCHAR bufferW[40], *end;
3769 DWORD count;
3770 HANDLE hkey, hSubkey = 0;
3771 UNICODE_STRING keyW;
3773 RtlInitUnicodeString( &keyW, nationW );
3774 count = sizeof(bufferW);
3775
3776 if(!(hkey = create_registry_key())) return ret;
3777
3778 switch( GeoClass ){
3779 case GEOCLASS_NATION:
3780 if ((hSubkey = NLS_RegOpenKey(hkey, geoW)))
3781 {
3782 if((NtQueryValueKey(hSubkey, &keyW, KeyValuePartialInformation,
3783 bufferW, count, &count) == STATUS_SUCCESS ) && info->DataLength)
3784 ret = strtolW((LPCWSTR)info->Data, &end, 10);
3785 }
3786 break;
3787 case GEOCLASS_REGION:
3788 FIXME("GEOCLASS_REGION not handled yet\n");
3789 break;
3790 }
3791
3792 NtClose(hkey);
3793 if (hSubkey) NtClose(hSubkey);
3794 return ret;
3795}
3796
3797/******************************************************************************
3798 * SetUserGeoID (KERNEL32.@)
3799 */
3801{
3802 static const WCHAR geoW[] = {'G','e','o',0};
3803 static const WCHAR nationW[] = {'N','a','t','i','o','n',0};
3804 static const WCHAR formatW[] = {'%','i',0};
3805 UNICODE_STRING nameW,keyW;
3806 WCHAR bufferW[10];
3808 HANDLE hkey;
3809
3810 if(!(hkey = create_registry_key())) return FALSE;
3811
3812 attr.Length = sizeof(attr);
3813 attr.RootDirectory = hkey;
3814 attr.ObjectName = &nameW;
3815 attr.Attributes = 0;
3816 attr.SecurityDescriptor = NULL;
3817