f6e63646e981f2a24316f4aa244c746a320c0b89
[reactos.git] / reactos / dll / win32 / kernel32 / winnls / string / lang.c
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>
28 DEBUG_CHANNEL(nls);
29
30 #include "lcformat_private.h"
31
32 #define REG_SZ 1
33 extern int wine_fold_string(int flags, const WCHAR *src, int srclen, WCHAR *dst, int dstlen);
34 extern int wine_get_sortkey(int flags, const WCHAR *src, int srclen, char *dst, int dstlen);
35 extern int wine_compare_string(int flags, const WCHAR *str1, int len1, const WCHAR *str2, int len2);
36 extern DWORD GetLocalisedText(DWORD dwResId, WCHAR *lpszDest, DWORD dwDestSize);
37 #define NLSRC_OFFSET 5000 /* FIXME */
38
39 extern HMODULE kernel32_handle;
40
41 #define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|\
42 LOCALE_RETURN_NUMBER|LOCALE_RETURN_GENITIVE_NAMES)
43
44 static const WCHAR szLocaleKeyName[] = {
45 '\\', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', '\\',
46 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
47 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
48 'C','o','n','t','r','o','l','\\','N','l','s','\\','L','o','c','a','l','e',0
49 };
50
51 static const WCHAR szLangGroupsKeyName[] = {
52 '\\', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', '\\',
53 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
54 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
55 'C','o','n','t','r','o','l','\\','N','l','s','\\',
56 'L','a','n','g','u','a','g','e',' ','G','r','o','u','p','s',0
57 };
58
59 #ifndef __REACTOS__
60 /* Charset to codepage map, sorted by name. */
61 static const struct charset_entry
62 {
63 const char *charset_name;
64 UINT codepage;
65 } charset_names[] =
66 {
67 { "BIG5", 950 },
68 { "CP1250", 1250 },
69 { "CP1251", 1251 },
70 { "CP1252", 1252 },
71 { "CP1253", 1253 },
72 { "CP1254", 1254 },
73 { "CP1255", 1255 },
74 { "CP1256", 1256 },
75 { "CP1257", 1257 },
76 { "CP1258", 1258 },
77 { "CP932", 932 },
78 { "CP936", 936 },
79 { "CP949", 949 },
80 { "CP950", 950 },
81 { "EUCJP", 20932 },
82 { "GB2312", 936 },
83 { "IBM037", 37 },
84 { "IBM1026", 1026 },
85 { "IBM424", 424 },
86 { "IBM437", 437 },
87 { "IBM500", 500 },
88 { "IBM850", 850 },
89 { "IBM852", 852 },
90 { "IBM855", 855 },
91 { "IBM857", 857 },
92 { "IBM860", 860 },
93 { "IBM861", 861 },
94 { "IBM862", 862 },
95 { "IBM863", 863 },
96 { "IBM864", 864 },
97 { "IBM865", 865 },
98 { "IBM866", 866 },
99 { "IBM869", 869 },
100 { "IBM874", 874 },
101 { "IBM875", 875 },
102 { "ISO88591", 28591 },
103 { "ISO885910", 28600 },
104 { "ISO885913", 28603 },
105 { "ISO885914", 28604 },
106 { "ISO885915", 28605 },
107 { "ISO885916", 28606 },
108 { "ISO88592", 28592 },
109 { "ISO88593", 28593 },
110 { "ISO88594", 28594 },
111 { "ISO88595", 28595 },
112 { "ISO88596", 28596 },
113 { "ISO88597", 28597 },
114 { "ISO88598", 28598 },
115 { "ISO88599", 28599 },
116 { "KOI8R", 20866 },
117 { "KOI8U", 21866 },
118 { "UTF8", CP_UTF8 }
119 };
120 #endif
121
122 struct locale_name
123 {
124 WCHAR win_name[128]; /* Windows name ("en-US") */
125 WCHAR lang[128]; /* language ("en") (note: buffer contains the other strings too) */
126 WCHAR *country; /* country ("US") */
127 WCHAR *charset; /* charset ("UTF-8") for Unix format only */
128 WCHAR *script; /* script ("Latn") for Windows format only */
129 WCHAR *modifier; /* modifier or sort order */
130 LCID lcid; /* corresponding LCID */
131 int matches; /* number of elements matching LCID (0..4) */
132 UINT codepage; /* codepage corresponding to charset */
133 };
134
135 /* locale ids corresponding to the various Unix locale parameters */
136 static LCID lcid_LC_COLLATE;
137 static LCID lcid_LC_CTYPE;
138 static LCID lcid_LC_MONETARY;
139 static LCID lcid_LC_NUMERIC;
140 static LCID lcid_LC_TIME;
141 static LCID lcid_LC_PAPER;
142 static LCID lcid_LC_MEASUREMENT;
143 static LCID lcid_LC_TELEPHONE;
144
145 static const WCHAR iCalendarTypeW[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
146 static const WCHAR iCountryW[] = {'i','C','o','u','n','t','r','y',0};
147 static const WCHAR iCurrDigitsW[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
148 static const WCHAR iCurrencyW[] = {'i','C','u','r','r','e','n','c','y',0};
149 static const WCHAR iDateW[] = {'i','D','a','t','e',0};
150 static const WCHAR iDigitsW[] = {'i','D','i','g','i','t','s',0};
151 static const WCHAR iFirstDayOfWeekW[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
152 static const WCHAR iFirstWeekOfYearW[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
153 static const WCHAR iLDateW[] = {'i','L','D','a','t','e',0};
154 static const WCHAR iLZeroW[] = {'i','L','Z','e','r','o',0};
155 static const WCHAR iMeasureW[] = {'i','M','e','a','s','u','r','e',0};
156 static const WCHAR iNegCurrW[] = {'i','N','e','g','C','u','r','r',0};
157 static const WCHAR iNegNumberW[] = {'i','N','e','g','N','u','m','b','e','r',0};
158 static const WCHAR iPaperSizeW[] = {'i','P','a','p','e','r','S','i','z','e',0};
159 static const WCHAR iTLZeroW[] = {'i','T','L','Z','e','r','o',0};
160 static const WCHAR iTimePrefixW[] = {'i','T','i','m','e','P','r','e','f','i','x',0};
161 static const WCHAR iTimeW[] = {'i','T','i','m','e',0};
162 static const WCHAR s1159W[] = {'s','1','1','5','9',0};
163 static const WCHAR s2359W[] = {'s','2','3','5','9',0};
164 static const WCHAR sCountryW[] = {'s','C','o','u','n','t','r','y',0};
165 static const WCHAR sCurrencyW[] = {'s','C','u','r','r','e','n','c','y',0};
166 static const WCHAR sDateW[] = {'s','D','a','t','e',0};
167 static const WCHAR sDecimalW[] = {'s','D','e','c','i','m','a','l',0};
168 static const WCHAR sGroupingW[] = {'s','G','r','o','u','p','i','n','g',0};
169 static const WCHAR sLanguageW[] = {'s','L','a','n','g','u','a','g','e',0};
170 static const WCHAR sListW[] = {'s','L','i','s','t',0};
171 static const WCHAR sLongDateW[] = {'s','L','o','n','g','D','a','t','e',0};
172 static const WCHAR sMonDecimalSepW[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
173 static const WCHAR sMonGroupingW[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
174 static const WCHAR sMonThousandSepW[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
175 static const WCHAR sNativeDigitsW[] = {'s','N','a','t','i','v','e','D','i','g','i','t','s',0};
176 static const WCHAR sNegativeSignW[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
177 static const WCHAR sPositiveSignW[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
178 static const WCHAR sShortDateW[] = {'s','S','h','o','r','t','D','a','t','e',0};
179 static const WCHAR sThousandW[] = {'s','T','h','o','u','s','a','n','d',0};
180 static const WCHAR sTimeFormatW[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
181 static const WCHAR sTimeW[] = {'s','T','i','m','e',0};
182 static const WCHAR sYearMonthW[] = {'s','Y','e','a','r','M','o','n','t','h',0};
183 static const WCHAR NumShapeW[] = {'N','u','m','s','h','a','p','e',0};
184
185 static struct registry_value
186 {
187 DWORD lctype;
188 const WCHAR *name;
189 WCHAR *cached_value;
190 } registry_values[] =
191 {
192 { LOCALE_ICALENDARTYPE, iCalendarTypeW },
193 { LOCALE_ICURRDIGITS, iCurrDigitsW },
194 { LOCALE_ICURRENCY, iCurrencyW },
195 { LOCALE_IDIGITS, iDigitsW },
196 { LOCALE_IFIRSTDAYOFWEEK, iFirstDayOfWeekW },
197 { LOCALE_IFIRSTWEEKOFYEAR, iFirstWeekOfYearW },
198 { LOCALE_ILZERO, iLZeroW },
199 { LOCALE_IMEASURE, iMeasureW },
200 { LOCALE_INEGCURR, iNegCurrW },
201 { LOCALE_INEGNUMBER, iNegNumberW },
202 { LOCALE_IPAPERSIZE, iPaperSizeW },
203 { LOCALE_ITIME, iTimeW },
204 { LOCALE_S1159, s1159W },
205 { LOCALE_S2359, s2359W },
206 { LOCALE_SCURRENCY, sCurrencyW },
207 { LOCALE_SDATE, sDateW },
208 { LOCALE_SDECIMAL, sDecimalW },
209 { LOCALE_SGROUPING, sGroupingW },
210 { LOCALE_SLIST, sListW },
211 { LOCALE_SLONGDATE, sLongDateW },
212 { LOCALE_SMONDECIMALSEP, sMonDecimalSepW },
213 { LOCALE_SMONGROUPING, sMonGroupingW },
214 { LOCALE_SMONTHOUSANDSEP, sMonThousandSepW },
215 { LOCALE_SNEGATIVESIGN, sNegativeSignW },
216 { LOCALE_SPOSITIVESIGN, sPositiveSignW },
217 { LOCALE_SSHORTDATE, sShortDateW },
218 { LOCALE_STHOUSAND, sThousandW },
219 { LOCALE_STIME, sTimeW },
220 { LOCALE_STIMEFORMAT, sTimeFormatW },
221 { LOCALE_SYEARMONTH, sYearMonthW },
222 /* The following are not listed under MSDN as supported,
223 * but seem to be used and also stored in the registry.
224 */
225 { LOCALE_ICOUNTRY, iCountryW },
226 { LOCALE_IDATE, iDateW },
227 { LOCALE_ILDATE, iLDateW },
228 { LOCALE_ITLZERO, iTLZeroW },
229 { LOCALE_SCOUNTRY, sCountryW },
230 { LOCALE_SABBREVLANGNAME, sLanguageW },
231 /* The following are used in XP and later */
232 { LOCALE_IDIGITSUBSTITUTION, NumShapeW },
233 { LOCALE_SNATIVEDIGITS, sNativeDigitsW },
234 { LOCALE_ITIMEMARKPOSN, iTimePrefixW }
235 };
236
237 static RTL_CRITICAL_SECTION cache_section = { NULL, -1, 0, 0, 0, 0 };
238
239 #ifndef __REACTOS__
240 /* Copy Ascii string to Unicode without using codepages */
241 static inline void strcpynAtoW( WCHAR *dst, const char *src, size_t n )
242 {
243 while (n > 1 && *src)
244 {
245 *dst++ = (unsigned char)*src++;
246 n--;
247 }
248 if (n) *dst = 0;
249 }
250 #endif
251
252 /***********************************************************************
253 * get_lcid_codepage
254 *
255 * Retrieve the ANSI codepage for a given locale.
256 */
257 static inline UINT get_lcid_codepage( LCID lcid )
258 {
259 UINT ret;
260 if (!GetLocaleInfoW( lcid, LOCALE_IDEFAULTANSICODEPAGE|LOCALE_RETURN_NUMBER, (WCHAR *)&ret,
261 sizeof(ret)/sizeof(WCHAR) )) ret = 0;
262 return ret;
263 }
264
265 /***********************************************************************
266 * convert_default_lcid
267 *
268 * Get the default LCID to use for a given lctype in GetLocaleInfo.
269 */
270 static LCID convert_default_lcid( LCID lcid, LCTYPE lctype )
271 {
272 if (lcid == LOCALE_SYSTEM_DEFAULT ||
273 lcid == LOCALE_USER_DEFAULT ||
274 lcid == LOCALE_NEUTRAL)
275 {
276 LCID default_id = 0;
277
278 switch(lctype & 0xffff)
279 {
280 case LOCALE_SSORTNAME:
281 default_id = lcid_LC_COLLATE;
282 break;
283
284 case LOCALE_FONTSIGNATURE:
285 case LOCALE_IDEFAULTANSICODEPAGE:
286 case LOCALE_IDEFAULTCODEPAGE:
287 case LOCALE_IDEFAULTEBCDICCODEPAGE:
288 case LOCALE_IDEFAULTMACCODEPAGE:
289 case LOCALE_IDEFAULTUNIXCODEPAGE:
290 default_id = lcid_LC_CTYPE;
291 break;
292
293 case LOCALE_ICURRDIGITS:
294 case LOCALE_ICURRENCY:
295 case LOCALE_IINTLCURRDIGITS:
296 case LOCALE_INEGCURR:
297 case LOCALE_INEGSEPBYSPACE:
298 case LOCALE_INEGSIGNPOSN:
299 case LOCALE_INEGSYMPRECEDES:
300 case LOCALE_IPOSSEPBYSPACE:
301 case LOCALE_IPOSSIGNPOSN:
302 case LOCALE_IPOSSYMPRECEDES:
303 case LOCALE_SCURRENCY:
304 case LOCALE_SINTLSYMBOL:
305 case LOCALE_SMONDECIMALSEP:
306 case LOCALE_SMONGROUPING:
307 case LOCALE_SMONTHOUSANDSEP:
308 case LOCALE_SNATIVECURRNAME:
309 default_id = lcid_LC_MONETARY;
310 break;
311
312 case LOCALE_IDIGITS:
313 case LOCALE_IDIGITSUBSTITUTION:
314 case LOCALE_ILZERO:
315 case LOCALE_INEGNUMBER:
316 case LOCALE_SDECIMAL:
317 case LOCALE_SGROUPING:
318 //case LOCALE_SNAN:
319 case LOCALE_SNATIVEDIGITS:
320 case LOCALE_SNEGATIVESIGN:
321 //case LOCALE_SNEGINFINITY:
322 //case LOCALE_SPOSINFINITY:
323 case LOCALE_SPOSITIVESIGN:
324 case LOCALE_STHOUSAND:
325 default_id = lcid_LC_NUMERIC;
326 break;
327
328 case LOCALE_ICALENDARTYPE:
329 case LOCALE_ICENTURY:
330 case LOCALE_IDATE:
331 case LOCALE_IDAYLZERO:
332 case LOCALE_IFIRSTDAYOFWEEK:
333 case LOCALE_IFIRSTWEEKOFYEAR:
334 case LOCALE_ILDATE:
335 case LOCALE_IMONLZERO:
336 case LOCALE_IOPTIONALCALENDAR:
337 case LOCALE_ITIME:
338 case LOCALE_ITIMEMARKPOSN:
339 case LOCALE_ITLZERO:
340 case LOCALE_S1159:
341 case LOCALE_S2359:
342 case LOCALE_SABBREVDAYNAME1:
343 case LOCALE_SABBREVDAYNAME2:
344 case LOCALE_SABBREVDAYNAME3:
345 case LOCALE_SABBREVDAYNAME4:
346 case LOCALE_SABBREVDAYNAME5:
347 case LOCALE_SABBREVDAYNAME6:
348 case LOCALE_SABBREVDAYNAME7:
349 case LOCALE_SABBREVMONTHNAME1:
350 case LOCALE_SABBREVMONTHNAME2:
351 case LOCALE_SABBREVMONTHNAME3:
352 case LOCALE_SABBREVMONTHNAME4:
353 case LOCALE_SABBREVMONTHNAME5:
354 case LOCALE_SABBREVMONTHNAME6:
355 case LOCALE_SABBREVMONTHNAME7:
356 case LOCALE_SABBREVMONTHNAME8:
357 case LOCALE_SABBREVMONTHNAME9:
358 case LOCALE_SABBREVMONTHNAME10:
359 case LOCALE_SABBREVMONTHNAME11:
360 case LOCALE_SABBREVMONTHNAME12:
361 case LOCALE_SABBREVMONTHNAME13:
362 case LOCALE_SDATE:
363 case LOCALE_SDAYNAME1:
364 case LOCALE_SDAYNAME2:
365 case LOCALE_SDAYNAME3:
366 case LOCALE_SDAYNAME4:
367 case LOCALE_SDAYNAME5:
368 case LOCALE_SDAYNAME6:
369 case LOCALE_SDAYNAME7:
370 //case LOCALE_SDURATION:
371 case LOCALE_SLONGDATE:
372 case LOCALE_SMONTHNAME1:
373 case LOCALE_SMONTHNAME2:
374 case LOCALE_SMONTHNAME3:
375 case LOCALE_SMONTHNAME4:
376 case LOCALE_SMONTHNAME5:
377 case LOCALE_SMONTHNAME6:
378 case LOCALE_SMONTHNAME7:
379 case LOCALE_SMONTHNAME8:
380 case LOCALE_SMONTHNAME9:
381 case LOCALE_SMONTHNAME10:
382 case LOCALE_SMONTHNAME11:
383 case LOCALE_SMONTHNAME12:
384 case LOCALE_SMONTHNAME13:
385 case LOCALE_SSHORTDATE:
386 //case LOCALE_SSHORTESTDAYNAME1:
387 //case LOCALE_SSHORTESTDAYNAME2:
388 //case LOCALE_SSHORTESTDAYNAME3:
389 //case LOCALE_SSHORTESTDAYNAME4:
390 //case LOCALE_SSHORTESTDAYNAME5:
391 //case LOCALE_SSHORTESTDAYNAME6:
392 //case LOCALE_SSHORTESTDAYNAME7:
393 case LOCALE_STIME:
394 case LOCALE_STIMEFORMAT:
395 case LOCALE_SYEARMONTH:
396 default_id = lcid_LC_TIME;
397 break;
398
399 case LOCALE_IPAPERSIZE:
400 default_id = lcid_LC_PAPER;
401 break;
402
403 case LOCALE_IMEASURE:
404 default_id = lcid_LC_MEASUREMENT;
405 break;
406
407 case LOCALE_ICOUNTRY:
408 default_id = lcid_LC_TELEPHONE;
409 break;
410 }
411 if (default_id) lcid = default_id;
412 }
413 return ConvertDefaultLocale( lcid );
414 }
415
416 /***********************************************************************
417 * is_genitive_name_supported
418 *
419 * Determine could LCTYPE basically support genitive name form or not.
420 */
421 static BOOL is_genitive_name_supported( LCTYPE lctype )
422 {
423 switch(lctype & 0xffff)
424 {
425 case LOCALE_SMONTHNAME1:
426 case LOCALE_SMONTHNAME2:
427 case LOCALE_SMONTHNAME3:
428 case LOCALE_SMONTHNAME4:
429 case LOCALE_SMONTHNAME5:
430 case LOCALE_SMONTHNAME6:
431 case LOCALE_SMONTHNAME7:
432 case LOCALE_SMONTHNAME8:
433 case LOCALE_SMONTHNAME9:
434 case LOCALE_SMONTHNAME10:
435 case LOCALE_SMONTHNAME11:
436 case LOCALE_SMONTHNAME12:
437 case LOCALE_SMONTHNAME13:
438 return TRUE;
439 default:
440 return FALSE;
441 }
442 }
443
444 /***********************************************************************
445 * create_registry_key
446 *
447 * Create the Control Panel\\International registry key.
448 */
449 static inline HANDLE create_registry_key(void)
450 {
451 static const WCHAR cplW[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l',0};
452 static const WCHAR intlW[] = {'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
453 OBJECT_ATTRIBUTES attr;
454 UNICODE_STRING nameW;
455 HANDLE cpl_key, hkey = 0;
456
457 if (RtlOpenCurrentUser( KEY_ALL_ACCESS, &hkey ) != STATUS_SUCCESS) return 0;
458
459 attr.Length = sizeof(attr);
460 attr.RootDirectory = hkey;
461 attr.ObjectName = &nameW;
462 attr.Attributes = 0;
463 attr.SecurityDescriptor = NULL;
464 attr.SecurityQualityOfService = NULL;
465 RtlInitUnicodeString( &nameW, cplW );
466
467 if (!NtCreateKey( &cpl_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ))
468 {
469 NtClose( attr.RootDirectory );
470 attr.RootDirectory = cpl_key;
471 RtlInitUnicodeString( &nameW, intlW );
472 if (NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) hkey = 0;
473 }
474 NtClose( attr.RootDirectory );
475 return hkey;
476 }
477
478 /***********************************************************************
479 * GetUserDefaultLangID (KERNEL32.@)
480 *
481 * Get the default language Id for the current user.
482 *
483 * PARAMS
484 * None.
485 *
486 * RETURNS
487 * The current LANGID of the default language for the current user.
488 */
489 LANGID WINAPI GetUserDefaultLangID(void)
490 {
491 return LANGIDFROMLCID(GetUserDefaultLCID());
492 }
493
494
495 /***********************************************************************
496 * GetSystemDefaultLangID (KERNEL32.@)
497 *
498 * Get the default language Id for the system.
499 *
500 * PARAMS
501 * None.
502 *
503 * RETURNS
504 * The current LANGID of the default language for the system.
505 */
506 LANGID WINAPI GetSystemDefaultLangID(void)
507 {
508 return LANGIDFROMLCID(GetSystemDefaultLCID());
509 }
510
511
512 /***********************************************************************
513 * GetUserDefaultLCID (KERNEL32.@)
514 *
515 * Get the default locale Id for the current user.
516 *
517 * PARAMS
518 * None.
519 *
520 * RETURNS
521 * The current LCID of the default locale for the current user.
522 */
523 LCID WINAPI GetUserDefaultLCID(void)
524 {
525 LCID lcid;
526 NtQueryDefaultLocale( TRUE, &lcid );
527 return lcid;
528 }
529
530
531 /***********************************************************************
532 * GetSystemDefaultLCID (KERNEL32.@)
533 *
534 * Get the default locale Id for the system.
535 *
536 * PARAMS
537 * None.
538 *
539 * RETURNS
540 * The current LCID of the default locale for the system.
541 */
542 LCID WINAPI GetSystemDefaultLCID(void)
543 {
544 LCID lcid;
545 NtQueryDefaultLocale( FALSE, &lcid );
546 return lcid;
547 }
548
549
550 /***********************************************************************
551 * GetUserDefaultUILanguage (KERNEL32.@)
552 *
553 * Get the default user interface language Id for the current user.
554 *
555 * PARAMS
556 * None.
557 *
558 * RETURNS
559 * The current LANGID of the default UI language for the current user.
560 */
561 LANGID WINAPI GetUserDefaultUILanguage(void)
562 {
563 LANGID lang;
564 NtQueryDefaultUILanguage( &lang );
565 return lang;
566 }
567
568
569 /***********************************************************************
570 * GetSystemDefaultUILanguage (KERNEL32.@)
571 *
572 * Get the default user interface language Id for the system.
573 *
574 * PARAMS
575 * None.
576 *
577 * RETURNS
578 * The current LANGID of the default UI language for the system. This is
579 * typically the same language used during the installation process.
580 */
581 LANGID WINAPI GetSystemDefaultUILanguage(void)
582 {
583 LANGID lang;
584 NtQueryInstallUILanguage( &lang );
585 return lang;
586 }
587
588
589 /******************************************************************************
590 * get_registry_locale_info
591 *
592 * Retrieve user-modified locale info from the registry.
593 * Return length, 0 on error, -1 if not found.
594 */
595 static INT get_registry_locale_info( struct registry_value *registry_value, LPWSTR buffer, INT len )
596 {
597 DWORD size;
598 INT ret;
599 HANDLE hkey;
600 NTSTATUS status;
601 UNICODE_STRING nameW;
602 KEY_VALUE_PARTIAL_INFORMATION *info;
603 static const int info_size = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
604
605 RtlEnterCriticalSection( &cache_section );
606
607 if (!registry_value->cached_value)
608 {
609 if (!(hkey = create_registry_key()))
610 {
611 RtlLeaveCriticalSection( &cache_section );
612 return -1;
613 }
614
615 RtlInitUnicodeString( &nameW, registry_value->name );
616 size = info_size + len * sizeof(WCHAR);
617
618 if (!(info = HeapAlloc( GetProcessHeap(), 0, size )))
619 {
620 NtClose( hkey );
621 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
622 RtlLeaveCriticalSection( &cache_section );
623 return 0;
624 }
625
626 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, info, size, &size );
627
628 /* try again with a bigger buffer when we have to return the correct size */
629 if (status == STATUS_BUFFER_OVERFLOW && !buffer && size > info_size)
630 {
631 KEY_VALUE_PARTIAL_INFORMATION *new_info;
632 if ((new_info = HeapReAlloc( GetProcessHeap(), 0, info, size )))
633 {
634 info = new_info;
635 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, info, size, &size );
636 }
637 }
638
639 NtClose( hkey );
640
641 if (!status)
642 {
643 INT length = (size - info_size) / sizeof(WCHAR);
644 LPWSTR cached_value;
645
646 if (!length || ((WCHAR *)&info->Data)[length-1])
647 length++;
648
649 cached_value = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) );
650
651 if (!cached_value)
652 {
653 HeapFree( GetProcessHeap(), 0, info );
654 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
655 RtlLeaveCriticalSection( &cache_section );
656 return 0;
657 }
658
659 memcpy( cached_value, info->Data, (length-1) * sizeof(WCHAR) );
660 cached_value[length-1] = 0;
661 HeapFree( GetProcessHeap(), 0, info );
662 registry_value->cached_value = cached_value;
663 }
664 else
665 {
666 if (status == STATUS_BUFFER_OVERFLOW && !buffer)
667 {
668 ret = (size - info_size) / sizeof(WCHAR);
669 }
670 else if (status == STATUS_OBJECT_NAME_NOT_FOUND)
671 {
672 ret = -1;
673 }
674 else
675 {
676 SetLastError( RtlNtStatusToDosError(status) );
677 ret = 0;
678 }
679 HeapFree( GetProcessHeap(), 0, info );
680 RtlLeaveCriticalSection( &cache_section );
681 return ret;
682 }
683 }
684
685 ret = lstrlenW( registry_value->cached_value ) + 1;
686
687 if (buffer)
688 {
689 if (ret > len)
690 {
691 SetLastError( ERROR_INSUFFICIENT_BUFFER );
692 ret = 0;
693 }
694 else
695 {
696 lstrcpyW( buffer, registry_value->cached_value );
697 }
698 }
699
700 RtlLeaveCriticalSection( &cache_section );
701
702 return ret;
703 }
704
705
706 /******************************************************************************
707 * GetLocaleInfoA (KERNEL32.@)
708 *
709 * Get information about an aspect of a locale.
710 *
711 * PARAMS
712 * lcid [I] LCID of the locale
713 * lctype [I] LCTYPE_ flags from "winnls.h"
714 * buffer [O] Destination for the information
715 * len [I] Length of buffer in characters
716 *
717 * RETURNS
718 * Success: The size of the data requested. If buffer is non-NULL, it is filled
719 * with the information.
720 * Failure: 0. Use GetLastError() to determine the cause.
721 *
722 * NOTES
723 * - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
724 * - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
725 * which is a bit string.
726 */
727 INT WINAPI GetLocaleInfoA( LCID lcid, LCTYPE lctype, LPSTR buffer, INT len )
728 {
729 WCHAR *bufferW;
730 INT lenW, ret;
731
732 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid, lctype, buffer, len );
733
734 if (len < 0 || (len && !buffer))
735 {
736 SetLastError( ERROR_INVALID_PARAMETER );
737 return 0;
738 }
739 if (((lctype & ~LOCALE_LOCALEINFOFLAGSMASK) == LOCALE_SSHORTTIME) ||
740 (lctype & LOCALE_RETURN_GENITIVE_NAMES))
741 {
742 SetLastError( ERROR_INVALID_FLAGS );
743 return 0;
744 }
745
746 if (!len) buffer = NULL;
747
748 if (!(lenW = GetLocaleInfoW( lcid, lctype, NULL, 0 ))) return 0;
749
750 if (!(bufferW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
751 {
752 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
753 return 0;
754 }
755 if ((ret = GetLocaleInfoW( lcid, lctype, bufferW, lenW )))
756 {
757 if ((lctype & LOCALE_RETURN_NUMBER) ||
758 ((lctype & ~LOCALE_LOCALEINFOFLAGSMASK) == LOCALE_FONTSIGNATURE))
759 {
760 /* it's not an ASCII string, just bytes */
761 ret *= sizeof(WCHAR);
762 if (buffer)
763 {
764 if (ret <= len) memcpy( buffer, bufferW, ret );
765 else
766 {
767 SetLastError( ERROR_INSUFFICIENT_BUFFER );
768 ret = 0;
769 }
770 }
771 }
772 else
773 {
774 UINT codepage = CP_ACP;
775 if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
776 ret = WideCharToMultiByte( codepage, 0, bufferW, ret, buffer, len, NULL, NULL );
777 }
778 }
779 HeapFree( GetProcessHeap(), 0, bufferW );
780 return ret;
781 }
782
783 static int get_value_base_by_lctype( LCTYPE lctype )
784 {
785 return lctype == LOCALE_ILANGUAGE || lctype == LOCALE_IDEFAULTLANGUAGE ? 16 : 10;
786 }
787
788 /******************************************************************************
789 * get_locale_registry_value
790 *
791 * Gets the registry value name and cache for a given lctype.
792 */
793 static struct registry_value *get_locale_registry_value( DWORD lctype )
794 {
795 int i;
796 for (i=0; i < sizeof(registry_values)/sizeof(registry_values[0]); i++)
797 if (registry_values[i].lctype == lctype)
798 return &registry_values[i];
799 return NULL;
800 }
801
802 /******************************************************************************
803 * GetLocaleInfoW (KERNEL32.@)
804 *
805 * See GetLocaleInfoA.
806 */
807 INT WINAPI GetLocaleInfoW( LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len )
808 {
809 LANGID lang_id;
810 HRSRC hrsrc;
811 HGLOBAL hmem;
812 INT ret;
813 UINT lcflags;
814 const WCHAR *p;
815 unsigned int i;
816
817 if (len < 0 || (len && !buffer))
818 {
819 SetLastError( ERROR_INVALID_PARAMETER );
820 return 0;
821 }
822 if (lctype & LOCALE_RETURN_GENITIVE_NAMES &&
823 !is_genitive_name_supported( lctype ))
824 {
825 SetLastError( ERROR_INVALID_FLAGS );
826 return 0;
827 }
828
829 if (!len) buffer = NULL;
830
831 lcid = convert_default_lcid( lcid, lctype );
832
833 lcflags = lctype & LOCALE_LOCALEINFOFLAGSMASK;
834 lctype &= 0xffff;
835
836 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid, lctype, buffer, len );
837
838 /* first check for overrides in the registry */
839
840 if (!(lcflags & LOCALE_NOUSEROVERRIDE) &&
841 lcid == convert_default_lcid( LOCALE_USER_DEFAULT, lctype ))
842 {
843 struct registry_value *value = get_locale_registry_value(lctype);
844
845 if (value)
846 {
847 if (lcflags & LOCALE_RETURN_NUMBER)
848 {
849 WCHAR tmp[16];
850 ret = get_registry_locale_info( value, tmp, sizeof(tmp)/sizeof(WCHAR) );
851 if (ret > 0)
852 {
853 WCHAR *end;
854 UINT number = strtolW( tmp, &end, get_value_base_by_lctype( lctype ) );
855 if (*end) /* invalid number */
856 {
857 SetLastError( ERROR_INVALID_FLAGS );
858 return 0;
859 }
860 ret = sizeof(UINT)/sizeof(WCHAR);
861 if (!buffer) return ret;
862 if (ret > len)
863 {
864 SetLastError( ERROR_INSUFFICIENT_BUFFER );
865 return 0;
866 }
867 memcpy( buffer, &number, sizeof(number) );
868 }
869 }
870 else ret = get_registry_locale_info( value, buffer, len );
871
872 if (ret != -1) return ret;
873 }
874 }
875
876 /* now load it from kernel resources */
877
878 lang_id = LANGIDFROMLCID( lcid );
879
880 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
881 if (SUBLANGID(lang_id) == SUBLANG_NEUTRAL)
882 lang_id = MAKELANGID(PRIMARYLANGID(lang_id), SUBLANG_DEFAULT);
883
884 if (!(hrsrc = FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING,
885 ULongToPtr((lctype >> 4) + 1), lang_id )))
886 {
887 SetLastError( ERROR_INVALID_FLAGS ); /* no such lctype */
888 return 0;
889 }
890 if (!(hmem = LoadResource( kernel32_handle, hrsrc )))
891 return 0;
892
893 p = LockResource( hmem );
894 for (i = 0; i < (lctype & 0x0f); i++) p += *p + 1;
895
896 if (lcflags & LOCALE_RETURN_NUMBER) ret = sizeof(UINT)/sizeof(WCHAR);
897 else if (is_genitive_name_supported( lctype ) && *p)
898 {
899 /* genitive form's stored after a null separator from a nominative */
900 for (i = 1; i <= *p; i++) if (!p[i]) break;
901
902 if (i <= *p && (lcflags & LOCALE_RETURN_GENITIVE_NAMES))
903 {
904 ret = *p - i + 1;
905 p += i;
906 }
907 else ret = i;
908 }
909 else
910 ret = (lctype == LOCALE_FONTSIGNATURE) ? *p : *p + 1;
911
912 if (!buffer) return ret;
913
914 if (ret > len)
915 {
916 SetLastError( ERROR_INSUFFICIENT_BUFFER );
917 return 0;
918 }
919
920 if (lcflags & LOCALE_RETURN_NUMBER)
921 {
922 UINT number;
923 WCHAR *end, *tmp = HeapAlloc( GetProcessHeap(), 0, (*p + 1) * sizeof(WCHAR) );
924 if (!tmp) return 0;
925 memcpy( tmp, p + 1, *p * sizeof(WCHAR) );
926 tmp[*p] = 0;
927 number = strtolW( tmp, &end, get_value_base_by_lctype( lctype ) );
928 if (!*end)
929 memcpy( buffer, &number, sizeof(number) );
930 else /* invalid number */
931 {
932 SetLastError( ERROR_INVALID_FLAGS );
933 ret = 0;
934 }
935 HeapFree( GetProcessHeap(), 0, tmp );
936
937 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning number %d\n",
938 lcid, lctype, buffer, len, number );
939 }
940 else
941 {
942 memcpy( buffer, p + 1, ret * sizeof(WCHAR) );
943 if (lctype != LOCALE_FONTSIGNATURE) buffer[ret-1] = 0;
944
945 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning %d %s\n",
946 lcid, lctype, buffer, len, ret, debugstr_w(buffer) );
947 }
948 return ret;
949 }
950
951
952 /******************************************************************************
953 * SetLocaleInfoA [KERNEL32.@]
954 *
955 * Set information about an aspect of a locale.
956 *
957 * PARAMS
958 * lcid [I] LCID of the locale
959 * lctype [I] LCTYPE_ flags from "winnls.h"
960 * data [I] Information to set
961 *
962 * RETURNS
963 * Success: TRUE. The information given will be returned by GetLocaleInfoA()
964 * whenever it is called without LOCALE_NOUSEROVERRIDE.
965 * Failure: FALSE. Use GetLastError() to determine the cause.
966 *
967 * NOTES
968 * - Values are only be set for the current user locale; the system locale
969 * settings cannot be changed.
970 * - Any settings changed by this call are lost when the locale is changed by
971 * the control panel (in Wine, this happens every time you change LANG).
972 * - The native implementation of this function does not check that lcid matches
973 * the current user locale, and simply sets the new values. Wine warns you in
974 * this case, but behaves the same.
975 */
976 BOOL WINAPI SetLocaleInfoA(LCID lcid, LCTYPE lctype, LPCSTR data)
977 {
978 UINT codepage = CP_ACP;
979 WCHAR *strW;
980 DWORD len;
981 BOOL ret;
982
983 if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
984
985 if (!data)
986 {
987 SetLastError( ERROR_INVALID_PARAMETER );
988 return FALSE;
989 }
990 len = MultiByteToWideChar( codepage, 0, data, -1, NULL, 0 );
991 if (!(strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
992 {
993 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
994 return FALSE;
995 }
996 MultiByteToWideChar( codepage, 0, data, -1, strW, len );
997 ret = SetLocaleInfoW( lcid, lctype, strW );
998 HeapFree( GetProcessHeap(), 0, strW );
999 return ret;
1000 }
1001
1002
1003 /******************************************************************************
1004 * SetLocaleInfoW (KERNEL32.@)
1005 *
1006 * See SetLocaleInfoA.
1007 */
1008 BOOL WINAPI SetLocaleInfoW( LCID lcid, LCTYPE lctype, LPCWSTR data )
1009 {
1010 struct registry_value *value;
1011 static const WCHAR intlW[] = {'i','n','t','l',0 };
1012 UNICODE_STRING valueW;
1013 NTSTATUS status;
1014 HANDLE hkey;
1015
1016 lctype &= 0xffff;
1017 value = get_locale_registry_value( lctype );
1018
1019 if (!data || !value)
1020 {
1021 SetLastError( ERROR_INVALID_PARAMETER );
1022 return FALSE;
1023 }
1024
1025 if (lctype == LOCALE_IDATE || lctype == LOCALE_ILDATE)
1026 {
1027 SetLastError( ERROR_INVALID_FLAGS );
1028 return FALSE;
1029 }
1030
1031 TRACE("setting %x (%s) to %s\n", lctype, debugstr_w(value->name), debugstr_w(data) );
1032
1033 /* FIXME: should check that data to set is sane */
1034
1035 /* FIXME: profile functions should map to registry */
1036 WriteProfileStringW( intlW, value->name, data );
1037
1038 if (!(hkey = create_registry_key())) return FALSE;
1039 RtlInitUnicodeString( &valueW, value->name );
1040 status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, (PVOID)data, (strlenW(data)+1)*sizeof(WCHAR) );
1041
1042 RtlEnterCriticalSection( &cache_section );
1043 HeapFree( GetProcessHeap(), 0, value->cached_value );
1044 value->cached_value = NULL;
1045 RtlLeaveCriticalSection( &cache_section );
1046
1047 if (lctype == LOCALE_SSHORTDATE || lctype == LOCALE_SLONGDATE)
1048 {
1049 /* Set I-value from S value */
1050 WCHAR *lpD, *lpM, *lpY;
1051 WCHAR szBuff[2];
1052
1053 lpD = strrchrW(data, 'd');
1054 lpM = strrchrW(data, 'M');
1055 lpY = strrchrW(data, 'y');
1056
1057 if (lpD <= lpM)
1058 {
1059 szBuff[0] = '1'; /* D-M-Y */
1060 }
1061 else
1062 {
1063 if (lpY <= lpM)
1064 szBuff[0] = '2'; /* Y-M-D */
1065 else
1066 szBuff[0] = '0'; /* M-D-Y */
1067 }
1068
1069 szBuff[1] = '\0';
1070
1071 if (lctype == LOCALE_SSHORTDATE)
1072 lctype = LOCALE_IDATE;
1073 else
1074 lctype = LOCALE_ILDATE;
1075
1076 value = get_locale_registry_value( lctype );
1077
1078 WriteProfileStringW( intlW, value->name, szBuff );
1079
1080 RtlInitUnicodeString( &valueW, value->name );
1081 status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, szBuff, sizeof(szBuff) );
1082
1083 RtlEnterCriticalSection( &cache_section );
1084 HeapFree( GetProcessHeap(), 0, value->cached_value );
1085 value->cached_value = NULL;
1086 RtlLeaveCriticalSection( &cache_section );
1087 }
1088
1089 NtClose( hkey );
1090
1091 if (status) SetLastError( RtlNtStatusToDosError(status) );
1092 return !status;
1093 }
1094
1095 /***********************************************************************
1096 * GetThreadLocale (KERNEL32.@)
1097 *
1098 * Get the current threads locale.
1099 *
1100 * PARAMS
1101 * None.
1102 *
1103 * RETURNS
1104 * The LCID currently associated with the calling thread.
1105 */
1106 LCID WINAPI GetThreadLocale(void)
1107 {
1108 LCID ret = NtCurrentTeb()->CurrentLocale;
1109 if (!ret) NtCurrentTeb()->CurrentLocale = ret = GetUserDefaultLCID();
1110 return ret;
1111 }
1112
1113 /**********************************************************************
1114 * SetThreadLocale (KERNEL32.@)
1115 *
1116 * Set the current threads locale.
1117 *
1118 * PARAMS
1119 * lcid [I] LCID of the locale to set
1120 *
1121 * RETURNS
1122 * Success: TRUE. The threads locale is set to lcid.
1123 * Failure: FALSE. Use GetLastError() to determine the cause.
1124 */
1125 BOOL WINAPI SetThreadLocale( LCID lcid )
1126 {
1127 TRACE("(0x%04X)\n", lcid);
1128
1129 lcid = ConvertDefaultLocale(lcid);
1130
1131 if (lcid != GetThreadLocale())
1132 {
1133 if (!IsValidLocale(lcid, LCID_SUPPORTED))
1134 {
1135 SetLastError(ERROR_INVALID_PARAMETER);
1136 return FALSE;
1137 }
1138
1139 NtCurrentTeb()->CurrentLocale = lcid;
1140 }
1141 return TRUE;
1142 }
1143
1144 /******************************************************************************
1145 * ConvertDefaultLocale (KERNEL32.@)
1146 *
1147 * Convert a default locale identifier into a real identifier.
1148 *
1149 * PARAMS
1150 * lcid [I] LCID identifier of the locale to convert
1151 *
1152 * RETURNS
1153 * lcid unchanged, if not a default locale or its sublanguage is
1154 * not SUBLANG_NEUTRAL.
1155 * GetSystemDefaultLCID(), if lcid == LOCALE_SYSTEM_DEFAULT.
1156 * GetUserDefaultLCID(), if lcid == LOCALE_USER_DEFAULT or LOCALE_NEUTRAL.
1157 * Otherwise, lcid with sublanguage changed to SUBLANG_DEFAULT.
1158 */
1159 LCID WINAPI ConvertDefaultLocale( LCID lcid )
1160 {
1161 LANGID langid;
1162
1163 switch (lcid)
1164 {
1165 case LOCALE_INVARIANT:
1166 /* keep as-is */
1167 break;
1168 case LOCALE_SYSTEM_DEFAULT:
1169 lcid = GetSystemDefaultLCID();
1170 break;
1171 case LOCALE_USER_DEFAULT:
1172 case LOCALE_NEUTRAL:
1173 lcid = GetUserDefaultLCID();
1174 break;
1175 default:
1176 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
1177 langid = LANGIDFROMLCID(lcid);
1178 if (SUBLANGID(langid) == SUBLANG_NEUTRAL)
1179 {
1180 langid = MAKELANGID(PRIMARYLANGID(langid), SUBLANG_DEFAULT);
1181 lcid = MAKELCID(langid, SORTIDFROMLCID(lcid));
1182 }
1183 }
1184 return lcid;
1185 }
1186
1187
1188 /******************************************************************************
1189 * IsValidLocale (KERNEL32.@)
1190 *
1191 * Determine if a locale is valid.
1192 *
1193 * PARAMS
1194 * lcid [I] LCID of the locale to check
1195 * flags [I] LCID_SUPPORTED = Valid, LCID_INSTALLED = Valid and installed on the system
1196 *
1197 * RETURNS
1198 * TRUE, if lcid is valid,
1199 * FALSE, otherwise.
1200 *
1201 * NOTES
1202 * Wine does not currently make the distinction between supported and installed. All
1203 * languages supported are installed by default.
1204 */
1205 BOOL WINAPI IsValidLocale( LCID lcid, DWORD flags )
1206 {
1207 /* check if language is registered in the kernel32 resources */
1208 return FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING,
1209 (LPCWSTR)LOCALE_ILANGUAGE, LANGIDFROMLCID(lcid)) != 0;
1210 }
1211
1212
1213 static BOOL CALLBACK enum_lang_proc_a( HMODULE hModule, LPCSTR type,
1214 LPCSTR name, WORD LangID, LONG_PTR lParam )
1215 {
1216 LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
1217 char buf[20];
1218
1219 sprintf(buf, "%08x", (UINT)LangID);
1220 return lpfnLocaleEnum( buf );
1221 }
1222
1223 static BOOL CALLBACK enum_lang_proc_w( HMODULE hModule, LPCWSTR type,
1224 LPCWSTR name, WORD LangID, LONG_PTR lParam )
1225 {
1226 static const WCHAR formatW[] = {'%','0','8','x',0};
1227 LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
1228 WCHAR buf[20];
1229 sprintfW( buf, formatW, (UINT)LangID );
1230 return lpfnLocaleEnum( buf );
1231 }
1232
1233 /******************************************************************************
1234 * EnumSystemLocalesA (KERNEL32.@)
1235 *
1236 * Call a users function for each locale available on the system.
1237 *
1238 * PARAMS
1239 * lpfnLocaleEnum [I] Callback function to call for each locale
1240 * dwFlags [I] LOCALE_SUPPORTED=All supported, LOCALE_INSTALLED=Installed only
1241 *
1242 * RETURNS
1243 * Success: TRUE.
1244 * Failure: FALSE. Use GetLastError() to determine the cause.
1245 */
1246 BOOL WINAPI EnumSystemLocalesA( LOCALE_ENUMPROCA lpfnLocaleEnum, DWORD dwFlags )
1247 {
1248 TRACE("(%p,%08x)\n", lpfnLocaleEnum, dwFlags);
1249 EnumResourceLanguagesA( kernel32_handle, (LPSTR)RT_STRING,
1250 (LPCSTR)LOCALE_ILANGUAGE, enum_lang_proc_a,
1251 (LONG_PTR)lpfnLocaleEnum);
1252 return TRUE;
1253 }
1254
1255
1256 /******************************************************************************
1257 * EnumSystemLocalesW (KERNEL32.@)
1258 *
1259 * See EnumSystemLocalesA.
1260 */
1261 BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum, DWORD dwFlags )
1262 {
1263 TRACE("(%p,%08x)\n", lpfnLocaleEnum, dwFlags);
1264 EnumResourceLanguagesW( kernel32_handle, (LPWSTR)RT_STRING,
1265 (LPCWSTR)LOCALE_ILANGUAGE, enum_lang_proc_w,
1266 (LONG_PTR)lpfnLocaleEnum);
1267 return TRUE;
1268 }
1269
1270 /***********************************************************************
1271 * VerLanguageNameA (KERNEL32.@)
1272 *
1273 * Get the name of a language.
1274 *
1275 * PARAMS
1276 * wLang [I] LANGID of the language
1277 * szLang [O] Destination for the language name
1278 *
1279 * RETURNS
1280 * Success: The size of the language name. If szLang is non-NULL, it is filled
1281 * with the name.
1282 * Failure: 0. Use GetLastError() to determine the cause.
1283 *
1284 */
1285 DWORD WINAPI VerLanguageNameA( DWORD wLang, LPSTR szLang, DWORD nSize )
1286 {
1287 return GetLocaleInfoA( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
1288 }
1289
1290
1291 /***********************************************************************
1292 * VerLanguageNameW (KERNEL32.@)
1293 *
1294 * See VerLanguageNameA.
1295 */
1296 DWORD WINAPI VerLanguageNameW( DWORD wLang, LPWSTR szLang, DWORD nSize )
1297 {
1298 return GetLocaleInfoW( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
1299 }
1300
1301 /******************************************************************************
1302 * GetStringTypeW (KERNEL32.@)
1303 *
1304 * See GetStringTypeA.
1305 */
1306 BOOL WINAPI GetStringTypeW( DWORD type, LPCWSTR src, INT count, LPWORD chartype )
1307 {
1308 static const unsigned char type2_map[16] =
1309 {
1310 C2_NOTAPPLICABLE, /* unassigned */
1311 C2_LEFTTORIGHT, /* L */
1312 C2_RIGHTTOLEFT, /* R */
1313 C2_EUROPENUMBER, /* EN */
1314 C2_EUROPESEPARATOR, /* ES */
1315 C2_EUROPETERMINATOR, /* ET */
1316 C2_ARABICNUMBER, /* AN */
1317 C2_COMMONSEPARATOR, /* CS */
1318 C2_BLOCKSEPARATOR, /* B */
1319 C2_SEGMENTSEPARATOR, /* S */
1320 C2_WHITESPACE, /* WS */
1321 C2_OTHERNEUTRAL, /* ON */
1322 C2_RIGHTTOLEFT, /* AL */
1323 C2_NOTAPPLICABLE, /* NSM */
1324 C2_NOTAPPLICABLE, /* BN */
1325 C2_OTHERNEUTRAL /* LRE, LRO, RLE, RLO, PDF */
1326 };
1327
1328 if (!src)
1329 {
1330 SetLastError( ERROR_INVALID_PARAMETER );
1331 return FALSE;
1332 }
1333
1334 if (count == -1) count = strlenW(src) + 1;
1335 switch(type)
1336 {
1337 case CT_CTYPE1:
1338 while (count--) *chartype++ = get_char_typeW( *src++ ) & 0xfff;
1339 break;
1340 case CT_CTYPE2:
1341 while (count--) *chartype++ = type2_map[get_char_typeW( *src++ ) >> 12];
1342 break;
1343 case CT_CTYPE3:
1344 {
1345 WARN("CT_CTYPE3: semi-stub.\n");
1346 while (count--)
1347 {
1348 int c = *src;
1349 WORD type1, type3 = 0; /* C3_NOTAPPLICABLE */
1350
1351 type1 = get_char_typeW( *src++ ) & 0xfff;
1352 /* try to construct type3 from type1 */
1353 if(type1 & C1_SPACE) type3 |= C3_SYMBOL;
1354 if(type1 & C1_ALPHA) type3 |= C3_ALPHA;
1355 if ((c>=0x30A0)&&(c<=0x30FF)) type3 |= C3_KATAKANA;
1356 if ((c>=0x3040)&&(c<=0x309F)) type3 |= C3_HIRAGANA;
1357 if ((c>=0x4E00)&&(c<=0x9FAF)) type3 |= C3_IDEOGRAPH;
1358 if (c == 0x0640) type3 |= C3_KASHIDA;
1359 if ((c>=0x3000)&&(c<=0x303F)) type3 |= C3_SYMBOL;
1360
1361 if ((c>=0xD800)&&(c<=0xDBFF)) type3 |= C3_HIGHSURROGATE;
1362 if ((c>=0xDC00)&&(c<=0xDFFF)) type3 |= C3_LOWSURROGATE;
1363
1364 if ((c>=0xFF00)&&(c<=0xFF60)) type3 |= C3_FULLWIDTH;
1365 if ((c>=0xFF00)&&(c<=0xFF20)) type3 |= C3_SYMBOL;
1366 if ((c>=0xFF3B)&&(c<=0xFF40)) type3 |= C3_SYMBOL;
1367 if ((c>=0xFF5B)&&(c<=0xFF60)) type3 |= C3_SYMBOL;
1368 if ((c>=0xFF21)&&(c<=0xFF3A)) type3 |= C3_ALPHA;
1369 if ((c>=0xFF41)&&(c<=0xFF5A)) type3 |= C3_ALPHA;
1370 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_FULLWIDTH;
1371 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_SYMBOL;
1372
1373 if ((c>=0xFF61)&&(c<=0xFFDC)) type3 |= C3_HALFWIDTH;
1374 if ((c>=0xFF61)&&(c<=0xFF64)) type3 |= C3_SYMBOL;
1375 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_KATAKANA;
1376 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_ALPHA;
1377 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_HALFWIDTH;
1378 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_SYMBOL;
1379 *chartype++ = type3;
1380 }
1381 break;
1382 }
1383 default:
1384 SetLastError( ERROR_INVALID_PARAMETER );
1385 return FALSE;
1386 }
1387 return TRUE;
1388 }
1389
1390
1391 /******************************************************************************
1392 * GetStringTypeExW (KERNEL32.@)
1393 *
1394 * See GetStringTypeExA.
1395 */
1396 BOOL WINAPI GetStringTypeExW( LCID locale, DWORD type, LPCWSTR src, INT count, LPWORD chartype )
1397 {
1398 /* locale is ignored for Unicode */
1399 return GetStringTypeW( type, src, count, chartype );
1400 }
1401
1402
1403 /******************************************************************************
1404 * GetStringTypeA (KERNEL32.@)
1405 *
1406 * Get characteristics of the characters making up a string.
1407 *
1408 * PARAMS
1409 * locale [I] Locale Id for the string
1410 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1411 * src [I] String to analyse
1412 * count [I] Length of src in chars, or -1 if src is NUL terminated
1413 * chartype [O] Destination for the calculated characteristics
1414 *
1415 * RETURNS
1416 * Success: TRUE. chartype is filled with the requested characteristics of each char
1417 * in src.
1418 * Failure: FALSE. Use GetLastError() to determine the cause.
1419 */
1420 BOOL WINAPI GetStringTypeA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
1421 {
1422 UINT cp;
1423 INT countW;
1424 LPWSTR srcW;
1425 BOOL ret = FALSE;
1426
1427 if(count == -1) count = strlen(src) + 1;
1428
1429 if (!(cp = get_lcid_codepage( locale )))
1430 {
1431 FIXME("For locale %04x using current ANSI code page\n", locale);
1432 cp = GetACP();
1433 }
1434
1435 countW = MultiByteToWideChar(cp, 0, src, count, NULL, 0);
1436 if((srcW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
1437 {
1438 MultiByteToWideChar(cp, 0, src, count, srcW, countW);
1439 /*
1440 * NOTE: the target buffer has 1 word for each CHARACTER in the source
1441 * string, with multibyte characters there maybe be more bytes in count
1442 * than character space in the buffer!
1443 */
1444 ret = GetStringTypeW(type, srcW, countW, chartype);
1445 HeapFree(GetProcessHeap(), 0, srcW);
1446 }
1447 return ret;
1448 }
1449
1450 /******************************************************************************
1451 * GetStringTypeExA (KERNEL32.@)
1452 *
1453 * Get characteristics of the characters making up a string.
1454 *
1455 * PARAMS
1456 * locale [I] Locale Id for the string
1457 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1458 * src [I] String to analyse
1459 * count [I] Length of src in chars, or -1 if src is NUL terminated
1460 * chartype [O] Destination for the calculated characteristics
1461 *
1462 * RETURNS
1463 * Success: TRUE. chartype is filled with the requested characteristics of each char
1464 * in src.
1465 * Failure: FALSE. Use GetLastError() to determine the cause.
1466 */
1467 BOOL WINAPI GetStringTypeExA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
1468 {
1469 return GetStringTypeA(locale, type, src, count, chartype);
1470 }
1471
1472 /*************************************************************************
1473 * LCMapStringEx (KERNEL32.@)
1474 *
1475 * Map characters in a locale sensitive string.
1476 *
1477 * PARAMS
1478 * name [I] Locale name for the conversion.
1479 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h")
1480 * src [I] String to map
1481 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
1482 * dst [O] Destination for mapped string
1483 * dstlen [I] Length of dst in characters
1484 * version [I] reserved, must be NULL
1485 * reserved [I] reserved, must be NULL
1486 * lparam [I] reserved, must be 0
1487 *
1488 * RETURNS
1489 * Success: The length of the mapped string in dst, including the NUL terminator.
1490 * Failure: 0. Use GetLastError() to determine the cause.
1491 */
1492 INT WINAPI LCMapStringEx(LPCWSTR name, DWORD flags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen,
1493 LPNLSVERSIONINFO version, LPVOID reserved, LPARAM lparam)
1494 {
1495 LPWSTR dst_ptr;
1496
1497 if (version) FIXME("unsupported version structure %p\n", version);
1498 if (reserved) FIXME("unsupported reserved pointer %p\n", reserved);
1499 if (lparam)
1500 {
1501 static int once;
1502 if (!once++) FIXME("unsupported lparam %lx\n", lparam);
1503 }
1504
1505 if (!src || !srclen || dstlen < 0)
1506 {
1507 SetLastError(ERROR_INVALID_PARAMETER);
1508 return 0;
1509 }
1510
1511 /* mutually exclusive flags */
1512 if ((flags & (LCMAP_LOWERCASE | LCMAP_UPPERCASE)) == (LCMAP_LOWERCASE | LCMAP_UPPERCASE) ||
1513 (flags & (LCMAP_HIRAGANA | LCMAP_KATAKANA)) == (LCMAP_HIRAGANA | LCMAP_KATAKANA) ||
1514 (flags & (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH)) == (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH) ||
1515 (flags & (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE)) == (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE))
1516 {
1517 SetLastError(ERROR_INVALID_FLAGS);
1518 return 0;
1519 }
1520
1521 if (!dstlen) dst = NULL;
1522
1523 if (flags & LCMAP_SORTKEY)
1524 {
1525 INT ret;
1526 if (src == dst)
1527 {
1528 SetLastError(ERROR_INVALID_FLAGS);
1529 return 0;
1530 }
1531
1532 if (srclen < 0) srclen = strlenW(src);
1533
1534 TRACE("(%s,0x%08x,%s,%d,%p,%d)\n",
1535 debugstr_w(name), flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1536
1537 ret = wine_get_sortkey(flags, src, srclen, (char *)dst, dstlen);
1538 if (ret == 0)
1539 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1540 else
1541 ret++;
1542 return ret;
1543 }
1544
1545 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
1546 if (flags & SORT_STRINGSORT)
1547 {
1548 SetLastError(ERROR_INVALID_FLAGS);
1549 return 0;
1550 }
1551
1552 if (srclen < 0) srclen = strlenW(src) + 1;
1553
1554 TRACE("(%s,0x%08x,%s,%d,%p,%d)\n",
1555 debugstr_w(name), flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1556
1557 if (!dst) /* return required string length */
1558 {
1559 INT len;
1560
1561 for (len = 0; srclen; src++, srclen--)
1562 {
1563 WCHAR wch = *src;
1564 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
1565 * and skips white space and punctuation characters for
1566 * NORM_IGNORESYMBOLS.
1567 */
1568 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1569 continue;
1570 len++;
1571 }
1572 return len;
1573 }
1574
1575 if (flags & LCMAP_UPPERCASE)
1576 {
1577 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1578 {
1579 WCHAR wch = *src;
1580 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1581 continue;
1582 *dst_ptr++ = toupperW(wch);
1583 dstlen--;
1584 }
1585 }
1586 else if (flags & LCMAP_LOWERCASE)
1587 {
1588 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1589 {
1590 WCHAR wch = *src;
1591 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1592 continue;
1593 *dst_ptr++ = tolowerW(wch);
1594 dstlen--;
1595 }
1596 }
1597 else
1598 {
1599 if (src == dst)
1600 {
1601 SetLastError(ERROR_INVALID_FLAGS);
1602 return 0;
1603 }
1604 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1605 {
1606 WCHAR wch = *src;
1607 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1608 continue;
1609 *dst_ptr++ = wch;
1610 dstlen--;
1611 }
1612 }
1613
1614 if (srclen)
1615 {
1616 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1617 return 0;
1618 }
1619
1620 return dst_ptr - dst;
1621 }
1622
1623 /*************************************************************************
1624 * LCMapStringW (KERNEL32.@)
1625 *
1626 * See LCMapStringA.
1627 */
1628 INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen,
1629 LPWSTR dst, INT dstlen)
1630 {
1631 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
1632 lcid, flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1633
1634 return LCMapStringEx(NULL, flags, src, srclen, dst, dstlen, NULL, NULL, 0);
1635 }
1636
1637 /*************************************************************************
1638 * LCMapStringA (KERNEL32.@)
1639 *
1640 * Map characters in a locale sensitive string.
1641 *
1642 * PARAMS
1643 * lcid [I] LCID for the conversion.
1644 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h").
1645 * src [I] String to map
1646 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
1647 * dst [O] Destination for mapped string
1648 * dstlen [I] Length of dst in characters
1649 *
1650 * RETURNS
1651 * Success: The length of the mapped string in dst, including the NUL terminator.
1652 * Failure: 0. Use GetLastError() to determine the cause.
1653 */
1654 INT WINAPI LCMapStringA(LCID lcid, DWORD flags, LPCSTR src, INT srclen,
1655 LPSTR dst, INT dstlen)
1656 {
1657 WCHAR *bufW = NtCurrentTeb()->StaticUnicodeBuffer;
1658 LPWSTR srcW, dstW;
1659 INT ret = 0, srclenW, dstlenW;
1660 UINT locale_cp = CP_ACP;
1661
1662 if (!src || !srclen || dstlen < 0)
1663 {
1664 SetLastError(ERROR_INVALID_PARAMETER);
1665 return 0;
1666 }
1667
1668 if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
1669
1670 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, bufW, 260);
1671 if (srclenW)
1672 srcW = bufW;
1673 else
1674 {
1675 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, NULL, 0);
1676 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
1677 if (!srcW)
1678 {
1679 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1680 return 0;
1681 }
1682 MultiByteToWideChar(locale_cp, 0, src, srclen, srcW, srclenW);
1683 }
1684
1685 if (flags & LCMAP_SORTKEY)
1686 {
1687 if (src == dst)
1688 {
1689 SetLastError(ERROR_INVALID_FLAGS);
1690 goto map_string_exit;
1691 }
1692 ret = wine_get_sortkey(flags, srcW, srclenW, dst, dstlen);
1693 if (ret == 0)
1694 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1695 else
1696 ret++;
1697 goto map_string_exit;
1698 }
1699
1700 if (flags & SORT_STRINGSORT)
1701 {
1702 SetLastError(ERROR_INVALID_FLAGS);
1703 goto map_string_exit;
1704 }
1705
1706 dstlenW = LCMapStringEx(NULL, flags, srcW, srclenW, NULL, 0, NULL, NULL, 0);
1707 if (!dstlenW)
1708 goto map_string_exit;
1709
1710 dstW = HeapAlloc(GetProcessHeap(), 0, dstlenW * sizeof(WCHAR));
1711 if (!dstW)
1712 {
1713 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1714 goto map_string_exit;
1715 }
1716
1717 LCMapStringEx(NULL, flags, srcW, srclenW, dstW, dstlenW, NULL, NULL, 0);
1718 ret = WideCharToMultiByte(locale_cp, 0, dstW, dstlenW, dst, dstlen, NULL, NULL);
1719 HeapFree(GetProcessHeap(), 0, dstW);
1720
1721 map_string_exit:
1722 if (srcW != bufW) HeapFree(GetProcessHeap(), 0, srcW);
1723 return ret;
1724 }
1725
1726 /*************************************************************************
1727 * FoldStringA (KERNEL32.@)
1728 *
1729 * Map characters in a string.
1730 *
1731 * PARAMS
1732 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
1733 * src [I] String to map
1734 * srclen [I] Length of src, or -1 if src is NUL terminated
1735 * dst [O] Destination for mapped string
1736 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
1737 *
1738 * RETURNS
1739 * Success: The length of the string written to dst, including the terminating NUL. If
1740 * dstlen is 0, the value returned is the same, but nothing is written to dst,
1741 * and dst may be NULL.
1742 * Failure: 0. Use GetLastError() to determine the cause.
1743 */
1744 INT WINAPI FoldStringA(DWORD dwFlags, LPCSTR src, INT srclen,
1745 LPSTR dst, INT dstlen)
1746 {
1747 INT ret = 0, srclenW = 0;
1748 WCHAR *srcW = NULL, *dstW = NULL;
1749
1750 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
1751 {
1752 SetLastError(ERROR_INVALID_PARAMETER);
1753 return 0;
1754 }
1755
1756 srclenW = MultiByteToWideChar(CP_ACP, dwFlags & MAP_COMPOSITE ? MB_COMPOSITE : 0,
1757 src, srclen, NULL, 0);
1758 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
1759
1760 if (!srcW)
1761 {
1762 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1763 goto FoldStringA_exit;
1764 }
1765
1766 MultiByteToWideChar(CP_ACP, dwFlags & MAP_COMPOSITE ? MB_COMPOSITE : 0,
1767 src, srclen, srcW, srclenW);
1768
1769 dwFlags = (dwFlags & ~MAP_PRECOMPOSED) | MAP_FOLDCZONE;
1770
1771 ret = FoldStringW(dwFlags, srcW, srclenW, NULL, 0);
1772 if (ret && dstlen)
1773 {
1774 dstW = HeapAlloc(GetProcessHeap(), 0, ret * sizeof(WCHAR));
1775
1776 if (!dstW)
1777 {
1778 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1779 goto FoldStringA_exit;
1780 }
1781
1782 ret = FoldStringW(dwFlags, srcW, srclenW, dstW, ret);
1783 if (!WideCharToMultiByte(CP_ACP, 0, dstW, ret, dst, dstlen, NULL, NULL))
1784 {
1785 ret = 0;
1786 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1787 }
1788 }
1789
1790 HeapFree(GetProcessHeap(), 0, dstW);
1791
1792 FoldStringA_exit:
1793 HeapFree(GetProcessHeap(), 0, srcW);
1794 return ret;
1795 }
1796
1797 /*************************************************************************
1798 * FoldStringW (KERNEL32.@)
1799 *
1800 * See FoldStringA.
1801 */
1802 INT WINAPI FoldStringW(DWORD dwFlags, LPCWSTR src, INT srclen,
1803 LPWSTR dst, INT dstlen)
1804 {
1805 int ret;
1806
1807 switch (dwFlags & (MAP_COMPOSITE|MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES))
1808 {
1809 case 0:
1810 if (dwFlags)
1811 break;
1812 /* Fall through for dwFlags == 0 */
1813 case MAP_PRECOMPOSED|MAP_COMPOSITE:
1814 case MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES:
1815 case MAP_COMPOSITE|MAP_EXPAND_LIGATURES:
1816 SetLastError(ERROR_INVALID_FLAGS);
1817 return 0;
1818 }
1819
1820 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
1821 {
1822 SetLastError(ERROR_INVALID_PARAMETER);
1823 return 0;
1824 }
1825
1826 ret = wine_fold_string(dwFlags, src, srclen, dst, dstlen);
1827 if (!ret)
1828 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1829 return ret;
1830 }
1831
1832 /******************************************************************************
1833 * CompareStringEx (KERNEL32.@)
1834 */
1835 INT WINAPI CompareStringEx(LPCWSTR locale, DWORD flags, LPCWSTR str1, INT len1,
1836 LPCWSTR str2, INT len2, LPNLSVERSIONINFO version, LPVOID reserved, LPARAM lParam)
1837 {
1838 DWORD supported_flags = NORM_IGNORECASE|NORM_IGNORENONSPACE|NORM_IGNORESYMBOLS|SORT_STRINGSORT
1839 |NORM_IGNOREKANATYPE|NORM_IGNOREWIDTH|LOCALE_USE_CP_ACP;
1840 DWORD semistub_flags = NORM_LINGUISTIC_CASING|LINGUISTIC_IGNORECASE|0x10000000;
1841 /* 0x10000000 is related to diacritics in Arabic, Japanese, and Hebrew */
1842 INT ret;
1843 static int once;
1844
1845 if (version) FIXME("unexpected version parameter\n");
1846 if (reserved) FIXME("unexpected reserved value\n");
1847 if (lParam) FIXME("unexpected lParam\n");
1848
1849 if (!str1 || !str2)
1850 {
1851 SetLastError(ERROR_INVALID_PARAMETER);
1852 return 0;
1853 }
1854
1855 if (flags & ~(supported_flags|semistub_flags))
1856 {
1857 SetLastError(ERROR_INVALID_FLAGS);
1858 return 0;
1859 }
1860
1861 if (flags & semistub_flags)
1862 {
1863 if (!once++)
1864 FIXME("semi-stub behavior for flag(s) 0x%x\n", flags & semistub_flags);
1865 }
1866
1867 if (len1 < 0) len1 = strlenW(str1);
1868 if (len2 < 0) len2 = strlenW(str2);
1869
1870 ret = wine_compare_string(flags, str1, len1, str2, len2);
1871
1872 if (ret) /* need to translate result */
1873 return (ret < 0) ? CSTR_LESS_THAN : CSTR_GREATER_THAN;
1874 return CSTR_EQUAL;
1875 }
1876
1877 /******************************************************************************
1878 * CompareStringW (KERNEL32.@)
1879 *
1880 * See CompareStringA.
1881 */
1882 INT WINAPI CompareStringW(LCID lcid, DWORD flags,
1883 LPCWSTR str1, INT len1, LPCWSTR str2, INT len2)
1884 {
1885 return CompareStringEx(NULL, flags, str1, len1, str2, len2, NULL, NULL, 0);
1886 }
1887
1888 /******************************************************************************
1889 * CompareStringA (KERNEL32.@)
1890 *
1891 * Compare two locale sensitive strings.
1892 *
1893 * PARAMS
1894 * lcid [I] LCID for the comparison
1895 * flags [I] Flags for the comparison (NORM_ constants from "winnls.h").
1896 * str1 [I] First string to compare
1897 * len1 [I] Length of str1, or -1 if str1 is NUL terminated
1898 * str2 [I] Second string to compare
1899 * len2 [I] Length of str2, or -1 if str2 is NUL terminated
1900 *
1901 * RETURNS
1902 * Success: CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN depending on whether
1903 * str1 is less than, equal to or greater than str2 respectively.
1904 * Failure: FALSE. Use GetLastError() to determine the cause.
1905 */
1906 INT WINAPI CompareStringA(LCID lcid, DWORD flags,
1907 LPCSTR str1, INT len1, LPCSTR str2, INT len2)
1908 {
1909 WCHAR *buf1W = NtCurrentTeb()->StaticUnicodeBuffer;
1910 WCHAR *buf2W = buf1W + 130;
1911 LPWSTR str1W, str2W;
1912 INT len1W = 0, len2W = 0, ret;
1913 UINT locale_cp = CP_ACP;
1914
1915 if (!str1 || !str2)
1916 {
1917 SetLastError(ERROR_INVALID_PARAMETER);
1918 return 0;
1919 }
1920 if (len1 < 0) len1 = strlen(str1);
1921 if (len2 < 0) len2 = strlen(str2);
1922
1923 if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
1924
1925 if (len1)
1926 {
1927 if (len1 <= 130) len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
1928 if (len1W)
1929 str1W = buf1W;
1930 else
1931 {
1932 len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, NULL, 0);
1933 str1W = HeapAlloc(GetProcessHeap(), 0, len1W * sizeof(WCHAR));
1934 if (!str1W)
1935 {
1936 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1937 return 0;
1938 }
1939 MultiByteToWideChar(locale_cp, 0, str1, len1, str1W, len1W);
1940 }
1941 }
1942 else
1943 {
1944 len1W = 0;
1945 str1W = buf1W;
1946 }
1947
1948 if (len2)
1949 {
1950 if (len2 <= 130) len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
1951 if (len2W)
1952 str2W = buf2W;
1953 else
1954 {
1955 len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, NULL, 0);
1956 str2W = HeapAlloc(GetProcessHeap(), 0, len2W * sizeof(WCHAR));
1957 if (!str2W)
1958 {
1959 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
1960 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1961 return 0;
1962 }
1963 MultiByteToWideChar(locale_cp, 0, str2, len2, str2W, len2W);
1964 }
1965 }
1966 else
1967 {
1968 len2W = 0;
1969 str2W = buf2W;
1970 }
1971
1972 ret = CompareStringEx(NULL, flags, str1W, len1W, str2W, len2W, NULL, NULL, 0);
1973
1974 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
1975 if (str2W != buf2W) HeapFree(GetProcessHeap(), 0, str2W);
1976 return ret;
1977 }
1978
1979 static HANDLE NLS_RegOpenKey(HANDLE hRootKey, LPCWSTR szKeyName)
1980 {
1981 UNICODE_STRING keyName;
1982 OBJECT_ATTRIBUTES attr;
1983 HANDLE hkey;
1984
1985 RtlInitUnicodeString( &keyName, szKeyName );
1986 InitializeObjectAttributes(&attr, &keyName, 0, hRootKey, NULL);
1987
1988 if (NtOpenKey( &hkey, KEY_READ, &attr ) != STATUS_SUCCESS)
1989 hkey = 0;
1990
1991 return hkey;
1992 }
1993
1994 static BOOL NLS_RegEnumValue(HANDLE hKey, UINT ulIndex,
1995 LPWSTR szValueName, ULONG valueNameSize,
1996 LPWSTR szValueData, ULONG valueDataSize)
1997 {
1998 BYTE buffer[80];
1999 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
2000 DWORD dwLen;
2001
2002 if (NtEnumerateValueKey( hKey, ulIndex, KeyValueFullInformation,
2003 buffer, sizeof(buffer), &dwLen ) != STATUS_SUCCESS ||
2004 info->NameLength > valueNameSize ||
2005 info->DataLength > valueDataSize)
2006 {
2007 return FALSE;
2008 }
2009
2010 TRACE("info->Name %s info->DataLength %d\n", debugstr_w(info->Name), info->DataLength);
2011
2012 memcpy( szValueName, info->Name, info->NameLength);
2013 szValueName[info->NameLength / sizeof(WCHAR)] = '\0';
2014 memcpy( szValueData, buffer + info->DataOffset, info->DataLength );
2015 szValueData[info->DataLength / sizeof(WCHAR)] = '\0';
2016
2017 TRACE("returning %s %s\n", debugstr_w(szValueName), debugstr_w(szValueData));
2018 return TRUE;
2019 }
2020
2021 static BOOL NLS_RegGetDword(HANDLE hKey, LPCWSTR szValueName, DWORD *lpVal)
2022 {
2023 BYTE buffer[128];
2024 const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
2025 DWORD dwSize = sizeof(buffer);
2026 UNICODE_STRING valueName;
2027
2028 RtlInitUnicodeString( &valueName, szValueName );
2029
2030 TRACE("%p, %s\n", hKey, debugstr_w(szValueName));
2031 if (NtQueryValueKey( hKey, &valueName, KeyValuePartialInformation,
2032 buffer, dwSize, &dwSize ) == STATUS_SUCCESS &&
2033 info->DataLength == sizeof(DWORD))
2034 {
2035 memcpy(lpVal, info->Data, sizeof(DWORD));
2036 return TRUE;
2037 }
2038
2039 return FALSE;
2040 }
2041
2042 static BOOL NLS_GetLanguageGroupName(LGRPID lgrpid, LPWSTR szName, ULONG nameSize)
2043 {
2044 LANGID langId;
2045 LPCWSTR szResourceName = MAKEINTRESOURCEW(((lgrpid + 0x2000) >> 4) + 1);
2046 HRSRC hResource;
2047 BOOL bRet = FALSE;
2048
2049 /* FIXME: Is it correct to use the system default langid? */
2050 langId = GetSystemDefaultLangID();
2051
2052 if (SUBLANGID(langId) == SUBLANG_NEUTRAL)
2053 langId = MAKELANGID( PRIMARYLANGID(langId), SUBLANG_DEFAULT );
2054
2055 hResource = FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING, szResourceName, langId );
2056
2057 if (hResource)
2058 {
2059 HGLOBAL hResDir = LoadResource( kernel32_handle, hResource );
2060
2061 if (hResDir)
2062 {
2063 ULONG iResourceIndex = lgrpid & 0xf;
2064 LPCWSTR lpResEntry = LockResource( hResDir );
2065 ULONG i;
2066
2067 for (i = 0; i < iResourceIndex; i++)
2068 lpResEntry += *lpResEntry + 1;
2069
2070 if (*lpResEntry < nameSize)
2071 {
2072 memcpy( szName, lpResEntry + 1, *lpResEntry * sizeof(WCHAR) );
2073 szName[*lpResEntry] = '\0';
2074 bRet = TRUE;
2075 }
2076
2077 }
2078 FreeResource( hResource );
2079 }
2080 return bRet;
2081 }
2082
2083 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
2084 typedef struct
2085 {
2086 LANGUAGEGROUP_ENUMPROCA procA;
2087 LANGUAGEGROUP_ENUMPROCW procW;
2088 DWORD dwFlags;
2089 LONG_PTR lParam;
2090 } ENUMLANGUAGEGROUP_CALLBACKS;
2091
2092 /* Internal implementation of EnumSystemLanguageGroupsA/W */
2093 static BOOL NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS *lpProcs)
2094 {
2095 WCHAR szNumber[10], szValue[4];
2096 HANDLE hKey;
2097 BOOL bContinue = TRUE;
2098 ULONG ulIndex = 0;
2099
2100 if (!lpProcs)
2101 {
2102 SetLastError(ERROR_INVALID_PARAMETER);
2103 return FALSE;
2104 }
2105
2106 switch (lpProcs->dwFlags)
2107 {
2108 case 0:
2109 /* Default to LGRPID_INSTALLED */
2110 lpProcs->dwFlags = LGRPID_INSTALLED;
2111 /* Fall through... */
2112 case LGRPID_INSTALLED:
2113 case LGRPID_SUPPORTED:
2114 break;
2115 default:
2116 SetLastError(ERROR_INVALID_FLAGS);
2117 return FALSE;
2118 }
2119
2120 hKey = NLS_RegOpenKey( 0, szLangGroupsKeyName );
2121
2122 if (!hKey)
2123 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2124
2125 while (bContinue)
2126 {
2127 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
2128 szValue, sizeof(szValue) ))
2129 {
2130 BOOL bInstalled = szValue[0] == '1';
2131 LGRPID lgrpid = strtoulW( szNumber, NULL, 16 );
2132
2133 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber),
2134 bInstalled ? "" : "not ");
2135
2136 if (lpProcs->dwFlags == LGRPID_SUPPORTED || bInstalled)
2137 {
2138 WCHAR szGrpName[48];
2139
2140 if (!NLS_GetLanguageGroupName( lgrpid, szGrpName, sizeof(szGrpName) / sizeof(WCHAR) ))
2141 szGrpName[0] = '\0';
2142
2143 if (lpProcs->procW)
2144 bContinue = lpProcs->procW( lgrpid, szNumber, szGrpName, lpProcs->dwFlags,
2145 lpProcs->lParam );
2146 else
2147 {
2148 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
2149 char szGrpNameA[48];
2150
2151 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
2152 * or whether the language names are ever localised. Assume CP_ACP.
2153 */
2154
2155 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
2156 WideCharToMultiByte(CP_ACP, 0, szGrpName, -1, szGrpNameA, sizeof(szGrpNameA), 0, 0);
2157
2158 bContinue = lpProcs->procA( lgrpid, szNumberA, szGrpNameA, lpProcs->dwFlags,
2159 lpProcs->lParam );
2160 }
2161 }
2162
2163 ulIndex++;
2164 }
2165 else
2166 bContinue = FALSE;
2167
2168 if (!bContinue)
2169 break;
2170 }
2171
2172 if (hKey)
2173 NtClose( hKey );
2174
2175 return TRUE;
2176 }
2177
2178 /******************************************************************************
2179 * EnumSystemLanguageGroupsA (KERNEL32.@)
2180 *
2181 * Call a users function for each language group available on the system.
2182 *
2183 * PARAMS
2184 * pLangGrpEnumProc [I] Callback function to call for each language group
2185 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
2186 * lParam [I] User parameter to pass to pLangGrpEnumProc
2187 *
2188 * RETURNS
2189 * Success: TRUE.
2190 * Failure: FALSE. Use GetLastError() to determine the cause.
2191 */
2192 BOOL WINAPI EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc,
2193 DWORD dwFlags, LONG_PTR lParam)
2194 {
2195 ENUMLANGUAGEGROUP_CALLBACKS procs;
2196
2197 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
2198
2199 procs.procA = pLangGrpEnumProc;
2200 procs.procW = NULL;
2201 procs.dwFlags = dwFlags;
2202 procs.lParam = lParam;
2203
2204 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
2205 }
2206
2207 /******************************************************************************
2208 * EnumSystemLanguageGroupsW (KERNEL32.@)
2209 *
2210 * See EnumSystemLanguageGroupsA.
2211 */
2212 BOOL WINAPI EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc,
2213 DWORD dwFlags, LONG_PTR lParam)
2214 {
2215 ENUMLANGUAGEGROUP_CALLBACKS procs;
2216
2217 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
2218
2219 procs.procA = NULL;
2220 procs.procW = pLangGrpEnumProc;
2221 procs.dwFlags = dwFlags;
2222 procs.lParam = lParam;
2223
2224 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
2225 }
2226
2227 /******************************************************************************
2228 * IsValidLanguageGroup (KERNEL32.@)
2229 *
2230 * Determine if a language group is supported and/or installed.
2231 *
2232 * PARAMS
2233 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
2234 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
2235 *
2236 * RETURNS
2237 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
2238 * FALSE otherwise.
2239 */
2240 BOOL WINAPI IsValidLanguageGroup(LGRPID lgrpid, DWORD dwFlags)
2241 {
2242 static const WCHAR szFormat[] = { '%','x','\0' };
2243 WCHAR szValueName[16], szValue[2];
2244 BOOL bSupported = FALSE, bInstalled = FALSE;
2245 HANDLE hKey;
2246
2247
2248 switch (dwFlags)
2249 {
2250 case LGRPID_INSTALLED:
2251 case LGRPID_SUPPORTED:
2252
2253 hKey = NLS_RegOpenKey( 0, szLangGroupsKeyName );
2254
2255 sprintfW( szValueName, szFormat, lgrpid );
2256
2257 if (NLS_RegGetDword( hKey, szValueName, (LPDWORD)szValue ))
2258 {
2259 bSupported = TRUE;
2260
2261 if (szValue[0] == '1')
2262 bInstalled = TRUE;
2263 }
2264
2265 if (hKey)
2266 NtClose( hKey );
2267
2268 break;
2269 }
2270
2271 if ((dwFlags == LGRPID_SUPPORTED && bSupported) ||
2272 (dwFlags == LGRPID_INSTALLED && bInstalled))
2273 return TRUE;
2274
2275 return FALSE;
2276 }
2277
2278 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
2279 typedef struct
2280 {
2281 LANGGROUPLOCALE_ENUMPROCA procA;
2282 LANGGROUPLOCALE_ENUMPROCW procW;
2283 DWORD dwFlags;
2284 LGRPID lgrpid;
2285 LONG_PTR lParam;
2286 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS;
2287
2288 /* Internal implementation of EnumLanguageGrouplocalesA/W */
2289 static BOOL NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS *lpProcs)
2290 {
2291 static const WCHAR szAlternateSortsKeyName[] = {
2292 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
2293 };
2294 WCHAR szNumber[10], szValue[4];
2295 HANDLE hKey;
2296 BOOL bContinue = TRUE, bAlternate = FALSE;
2297 LGRPID lgrpid;
2298 ULONG ulIndex = 1; /* Ignore default entry of 1st key */
2299
2300 if (!lpProcs || !lpProcs->lgrpid || lpProcs->lgrpid > LGRPID_ARMENIAN)
2301 {
2302 SetLastError(ERROR_INVALID_PARAMETER);
2303 return FALSE;
2304 }
2305
2306 if (lpProcs->dwFlags)
2307 {
2308 SetLastError(ERROR_INVALID_FLAGS);
2309 return FALSE;
2310 }
2311
2312 hKey = NLS_RegOpenKey( 0, szLocaleKeyName );
2313
2314 if (!hKey)
2315 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2316
2317 while (bContinue)
2318 {
2319 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
2320 szValue, sizeof(szValue) ))
2321 {
2322 lgrpid = strtoulW( szValue, NULL, 16 );
2323
2324 TRACE("lcid %s, grpid %d (%smatched)\n", debugstr_w(szNumber),
2325 lgrpid, lgrpid == lpProcs->lgrpid ? "" : "not ");
2326
2327 if (lgrpid == lpProcs->lgrpid)
2328 {
2329 LCID lcid;
2330
2331 lcid = strtoulW( szNumber, NULL, 16 );
2332
2333 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
2334 * '00000437 ;Georgian'
2335 * At present we only pass the LCID string.
2336 */
2337
2338 if (lpProcs->procW)
2339 bContinue = lpProcs->procW( lgrpid, lcid, szNumber, lpProcs->lParam );
2340 else
2341 {
2342 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
2343
2344 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
2345
2346 bContinue = lpProcs->procA( lgrpid, lcid, szNumberA, lpProcs->lParam );
2347 }
2348 }
2349
2350 ulIndex++;
2351 }
2352 else
2353 {
2354 /* Finished enumerating this key */
2355 if (!bAlternate)
2356 {
2357 /* Enumerate alternate sorts also */
2358 hKey = NLS_RegOpenKey( hKey, szAlternateSortsKeyName );
2359 bAlternate = TRUE;
2360 ulIndex = 0;
2361 }
2362 else
2363 bContinue = FALSE; /* Finished both keys */
2364 }
2365
2366 if (!bContinue)
2367 break;
2368 }
2369
2370 if (hKey)
2371 NtClose( hKey );
2372
2373 return TRUE;
2374 }
2375
2376 enum locationkind {
2377 LOCATION_NATION = 0,
2378 LOCATION_REGION,
2379 LOCATION_BOTH
2380 };
2381
2382 struct geoinfo_t {
2383 GEOID id;
2384 WCHAR iso2W[3];
2385 WCHAR iso3W[4];
2386 GEOID parent;
2387 INT uncode;
2388 enum locationkind kind;
2389 };
2390
2391 static const struct geoinfo_t geoinfodata[] = {
2392 { 2, {'A','G',0}, {'A','T','G',0}, 10039880, 28 }, /* Antigua and Barbuda */
2393 { 3, {'A','F',0}, {'A','F','G',0}, 47614, 4 }, /* Afghanistan */
2394 { 4, {'D','Z',0}, {'D','Z','A',0}, 42487, 12 }, /* Algeria */
2395 { 5, {'A','Z',0}, {'A','Z','E',0}, 47611, 31 }, /* Azerbaijan */
2396 { 6, {'A','L',0}, {'A','L','B',0}, 47610, 8 }, /* Albania */
2397 { 7, {'A','M',0}, {'A','R','M',0}, 47611, 51 }, /* Armenia */
2398 { 8, {'A','D',0}, {'A','N','D',0}, 47610, 20 }, /* Andorra */
2399 { 9, {'A','O',0}, {'A','G','O',0}, 42484, 24 }, /* Angola */
2400 { 10, {'A','S',0}, {'A','S','M',0}, 26286, 16 }, /* American Samoa */
2401 { 11, {'A','R',0}, {'A','R','G',0}, 31396, 32 }, /* Argentina */
2402 { 12, {'A','U',0}, {'A','U','S',0}, 10210825, 36 }, /* Australia */
2403 { 14, {'A','T',0}, {'A','U','T',0}, 10210824, 40 }, /* Austria */
2404 { 17, {'B','H',0}, {'B','H','R',0}, 47611, 48 }, /* Bahrain */
2405 { 18, {'B','B',0}, {'B','R','B',0}, 10039880, 52 }, /* Barbados */
2406 { 19, {'B','W',0}, {'B','W','A',0}, 10039883, 72 }, /* Botswana */
2407 { 20, {'B','M',0}, {'B','M','U',0}, 23581, 60 }, /* Bermuda */
2408 { 21, {'B','E',0}, {'B','E','L',0}, 10210824, 56 }, /* Belgium */
2409 { 22, {'B','S',0}, {'B','H','S',0}, 10039880, 44 }, /* Bahamas, The */
2410 { 23, {'B','D',0}, {'B','G','D',0}, 47614, 50 }, /* Bangladesh */
2411 { 24, {'B','Z',0}, {'B','L','Z',0}, 27082, 84 }, /* Belize */
2412 { 25, {'B','A',0}, {'B','I','H',0}, 47610, 70 }, /* Bosnia and Herzegovina */
2413 { 26, {'B','O',0}, {'B','O','L',0}, 31396, 68 }, /* Bolivia */
2414 { 27, {'M','M',0}, {'M','M','R',0}, 47599, 104 }, /* Myanmar */
2415 { 28, {'B','J',0}, {'B','E','N',0}, 42483, 204 }, /* Benin */
2416 { 29, {'B','Y',0}, {'B','L','R',0}, 47609, 112 }, /* Belarus */
2417 { 30, {'S','B',0}, {'S','L','B',0}, 20900, 90 }, /* Solomon Islands */
2418 { 32, {'B','R',0}, {'B','R','A',0}, 31396, 76 }, /* Brazil */
2419 { 34, {'B','T',0}, {'B','T','N',0}, 47614, 64 }, /* Bhutan */
2420 { 35, {'B','G',0}, {'B','G','R',0}, 47609, 100 }, /* Bulgaria */
2421 { 37, {'B','N',0}, {'B','R','N',0}, 47599, 96 }, /* Brunei */
2422 { 38, {'B','I',0}, {'B','D','I',0}, 47603, 108 }, /* Burundi */
2423 { 39, {'C','A',0}, {'C','A','N',0}, 23581, 124 }, /* Canada */
2424 { 40, {'K','H',0}, {'K','H','M',0}, 47599, 116 }, /* Cambodia */
2425 { 41, {'T','D',0}, {'T','C','D',0}, 42484, 148 }, /* Chad */
2426 { 42, {'L','K',0}, {'L','K','A',0}, 47614, 144 }, /* Sri Lanka */
2427 { 43, {'C','G',0}, {'C','O','G',0}, 42484, 178 }, /* Congo */
2428 { 44, {'C','D',0}, {'C','O','D',0}, 42484, 180 }, /* Congo (DRC) */
2429 { 45, {'C','N',0}, {'C','H','N',0}, 47600, 156 }, /* China */
2430 { 46, {'C','L',0}, {'C','H','L',0}, 31396, 152 }, /* Chile */
2431 { 49, {'C','M',0}, {'C','M','R',0}, 42484, 120 }, /* Cameroon */
2432 { 50, {'K','M',0}, {'C','O','M',0}, 47603, 174 }, /* Comoros */
2433 { 51, {'C','O',0}, {'C','O','L',0}, 31396, 170 }, /* Colombia */
2434 { 54, {'C','R',0}, {'C','R','I',0}, 27082, 188 }, /* Costa Rica */
2435 { 55, {'C','F',0}, {'C','A','F',0}, 42484, 140 }, /* Central African Republic */
2436 { 56, {'C','U',0}, {'C','U','B',0}, 10039880, 192 }, /* Cuba */
2437 { 57, {'C','V',0}, {'C','P','V',0}, 42483, 132 }, /* Cape Verde */
2438 { 59, {'C','Y',0}, {'C','Y','P',0}, 47611, 196 }, /* Cyprus */
2439 { 61, {'D','K',0}, {'D','N','K',0}, 10039882, 208 }, /* Denmark */
2440 { 62, {'D','J',0}, {'D','J','I',0}, 47603, 262 }, /* Djibouti */
2441 { 63, {'D','M',0}, {'D','M','A',0}, 10039880, 212 }, /* Dominica */
2442 { 65, {'D','O',0}, {'D','O','M',0}, 10039880, 214 }, /* Dominican Republic */
2443 { 66, {'E','C',0}, {'E','C','U',0}, 31396, 218 }, /* Ecuador */
2444 { 67, {'E','G',0}, {'E','G','Y',0}, 42487, 818 }, /* Egypt */
2445 { 68, {'I','E',0}, {'I','R','L',0}, 10039882, 372 }, /* Ireland */
2446 { 69, {'G','Q',0}, {'G','N','Q',0}, 42484, 226 }, /* Equatorial Guinea */
2447 { 70, {'E','E',0}, {'E','S','T',0}, 10039882, 233 }, /* Estonia */
2448 { 71, {'E','R',0}, {'E','R','I',0}, 47603, 232 }, /* Eritrea */
2449 { 72, {'S','V',0}, {'S','L','V',0}, 27082, 222 }, /* El Salvador */
2450 { 73, {'E','T',0}, {'E','T','H',0}, 47603, 231 }, /* Ethiopia */
2451 { 75, {'C','Z',0}, {'C','Z','E',0}, 47609, 203 }, /* Czech Republic */
2452 { 77, {'F','I',0}, {'F','I','N',0}, 10039882, 246 }, /* Finland */
2453 { 78, {'F','J',0}, {'F','J','I',0}, 20900, 242 }, /* Fiji Islands */
2454 { 80, {'F','M',0}, {'F','S','M',0}, 21206, 583 }, /* Micronesia */
2455 { 81, {'F','O',0}, {'F','R','O',0}, 10039882, 234 }, /* Faroe Islands */
2456 { 84, {'F','R',0}, {'F','R','A',0}, 10210824, 250 }, /* France */
2457 { 86, {'G','M',0}, {'G','M','B',0}, 42483, 270 }, /* Gambia, The */
2458 { 87, {'G','A',0}, {'G','A','B',0}, 42484, 266 }, /* Gabon */
2459 { 88, {'G','E',0}, {'G','E','O',0}, 47611, 268 }, /* Georgia */
2460 { 89, {'G','H',0}, {'G','H','A',0}, 42483, 288 }, /* Ghana */
2461 { 90, {'G','I',0}, {'G','I','B',0}, 47610, 292 }, /* Gibraltar */
2462 { 91, {'G','D',0}, {'G','R','D',0}, 10039880, 308 }, /* Grenada */
2463 { 93, {'G','L',0}, {'G','R','L',0}, 23581, 304 }, /* Greenland */
2464 { 94, {'D','E',0}, {'D','E','U',0}, 10210824, 276 }, /* Germany */
2465 { 98, {'G','R',0}, {'G','R','C',0}, 47610, 300 }, /* Greece */
2466 { 99, {'G','T',0}, {'G','T','M',0}, 27082, 320 }, /* Guatemala */
2467 { 100, {'G','N',0}, {'G','I','N',0}, 42483, 324 }, /* Guinea */
2468 { 101, {'G','Y',0}, {'G','U','Y',0}, 31396, 328 }, /* Guyana */
2469 { 103, {'H','T',0}, {'H','T','I',0}, 10039880, 332 }, /* Haiti */
2470 { 104, {'H','K',0}, {'H','K','G',0}, 47600, 344 }, /* Hong Kong S.A.R. */
2471 { 106, {'H','N',0}, {'H','N','D',0}, 27082, 340 }, /* Honduras */
2472 { 108, {'H','R',0}, {'H','R','V',0}, 47610, 191 }, /* Croatia */
2473 { 109, {'H','U',0}, {'H','U','N',0}, 47609, 348 }, /* Hungary */
2474 { 110, {'I','S',0}, {'I','S','L',0}, 10039882, 352 }, /* Iceland */
2475 { 111, {'I','D',0}, {'I','D','N',0}, 47599, 360 }, /* Indonesia */
2476 { 113, {'I','N',0}, {'I','N','D',0}, 47614, 356 }, /* India */
2477 { 114, {'I','O',0}, {'I','O','T',0}, 39070, 86 }, /* British Indian Ocean Territory */
2478 { 116, {'I','R',0}, {'I','R','N',0}, 47614, 364 }, /* Iran */
2479 { 117, {'I','L',0}, {'I','S','R',0}, 47611, 376 }, /* Israel */
2480 { 118, {'I','T',0}, {'I','T','A',0}, 47610, 380 }, /* Italy */
2481 { 119, {'C','I',0}, {'C','I','V',0}, 42483, 384 }, /* Côte d'Ivoire */
2482 { 121, {'I','Q',0}, {'I','R','Q',0}, 47611, 368 }, /* Iraq */
2483 { 122, {'J','P',0}, {'J','P','N',0}, 47600, 392 }, /* Japan */
2484 { 124, {'J','M',0}, {'J','A','M',0}, 10039880, 388 }, /* Jamaica */
2485 { 125, {'S','J',0}, {'S','J','M',0}, 10039882, 744 }, /* Jan Mayen */
2486 { 126, {'J','O',0}, {'J','O','R',0}, 47611, 400 }, /* Jordan */
2487 { 127, {'X','X',0}, {'X','X',0}, 161832256 }, /* Johnston Atoll */
2488 { 129, {'K','E',0}, {'K','E','N',0}, 47603, 404 }, /* Kenya */
2489 { 130, {'K','G',0}, {'K','G','Z',0}, 47590, 417 }, /* Kyrgyzstan */
2490 { 131, {'K','P',0}, {'P','R','K',0}, 47600, 408 }, /* North Korea */
2491 { 133, {'K','I',0}, {'K','I','R',0}, 21206, 296 }, /* Kiribati */
2492 { 134, {'K','R',0}, {'K','O','R',0}, 47600, 410 }, /* Korea */
2493 { 136, {'K','W',0}, {'K','W','T',0}, 47611, 414 }, /* Kuwait */
2494 { 137, {'K','Z',0}, {'K','A','Z',0}, 47590, 398 }, /* Kazakhstan */
2495 { 138, {'L','A',0}, {'L','A','O',0}, 47599, 418 }, /* Laos */
2496 { 139, {'L','B',0}, {'L','B','N',0}, 47611, 422 }, /* Lebanon */
2497 { 140, {'L','V',0}, {'L','V','A',0}, 10039882, 428 }, /* Latvia */
2498 { 141, {'L','T',0}, {'L','T','U',0}, 10039882, 440 }, /* Lithuania */
2499 { 142, {'L','R',0}, {'L','B','R',0}, 42483, 430 }, /* Liberia */
2500 { 143, {'S','K',0}, {'S','V','K',0}, 47609, 703 }, /* Slovakia */
2501 { 145, {'L','I',0}, {'L','I','E',0}, 10210824, 438 }, /* Liechtenstein */
2502 { 146, {'L','S',0}, {'L','S','O',0}, 10039883, 426 }, /* Lesotho */
2503 { 147, {'L','U',0}, {'L','U','X',0}, 10210824, 442 }, /* Luxembourg */
2504 { 148, {'L','Y',0}, {'L','B','Y',0}, 42487, 434 }, /* Libya */
2505 { 149, {'M','G',0}, {'M','D','G',0}, 47603, 450 }, /* Madagascar */
2506 { 151, {'M','O',0}, {'M','A','C',0}, 47600, 446 }, /* Macao S.A.R. */
2507 { 152, {'M','D',0}, {'M','D','A',0}, 47609, 498 }, /* Moldova */
2508 { 154, {'M','N',0}, {'M','N','G',0}, 47600, 496 }, /* Mongolia */
2509 { 156, {'M','W',0}, {'M','W','I',0}, 47603, 454 }, /* Malawi */
2510 { 157, {'M','L',0}, {'M','L','I',0}, 42483, 466 }, /* Mali */
2511 { 158, {'M','C',0}, {'M','C','O',0}, 10210824, 492 }, /* Monaco */
2512 { 159, {'M','A',0}, {'M','A','R',0}, 42487, 504 }, /* Morocco */
2513 { 160, {'M','U',0}, {'M','U','S',0}, 47603, 480 }, /* Mauritius */
2514 { 162, {'M','R',0}, {'M','R','T',0}, 42483, 478 }, /* Mauritania */
2515 { 163, {'M','T',0}, {'M','L','T',0}, 47610, 470 }, /* Malta */
2516 { 164, {'O','M',0}, {'O','M','N',0}, 47611, 512 }, /* Oman */
2517 { 165, {'M','V',0}, {'M','D','V',0}, 47614, 462 }, /* Maldives */
2518 { 166, {'M','X',0}, {'M','E','X',0}, 27082, 484 }, /* Mexico */
2519 { 167, {'M','Y',0}, {'M','Y','S',0}, 47599, 458 }, /* Malaysia */
2520 { 168, {'M','Z',0}, {'M','O','Z',0}, 47603, 508 }, /* Mozambique */
2521 { 173, {'N','E',0}, {'N','E','R',0}, 42483, 562 }, /* Niger */
2522 { 174, {'V','U',0}, {'V','U','T',0}, 20900, 548 }, /* Vanuatu */
2523 { 175, {'N','G',0}, {'N','G','A',0}, 42483, 566 }, /* Nigeria */
2524 { 176, {'N','L',0}, {'N','L','D',0}, 10210824, 528 }, /* Netherlands */
2525 { 177, {'N','O',0}, {'N','O','R',0}, 10039882, 578 }, /* Norway */
2526 { 178, {'N','P',0}, {'N','P','L',0}, 47614, 524 }, /* Nepal */
2527 { 180, {'N','R',0}, {'N','R','U',0}, 21206, 520 }, /* Nauru */
2528 { 181, {'S','R',0}, {'S','U','R',0}, 31396, 740 }, /* Suriname */
2529 { 182, {'N','I',0}, {'N','I','C',0}, 27082, 558 }, /* Nicaragua */
2530 { 183, {'N','Z',0}, {'N','Z','L',0}, 10210825, 554 }, /* New Zealand */
2531 { 184, {'P','S',0}, {'P','S','E',0}, 47611, 275 }, /* Palestinian Authority */
2532 { 185, {'P','Y',0}, {'P','R','Y',0}, 31396, 600 }, /* Paraguay */
2533 { 187, {'P','E',0}, {'P','E','R',0}, 31396, 604 }, /* Peru */
2534 { 190, {'P','K',0}, {'P','A','K',0}, 47614, 586 }, /* Pakistan */
2535 { 191, {'P','L',0}, {'P','O','L',0}, 47609, 616 }, /* Poland */
2536 { 192, {'P','A',0}, {'P','A','N',0}, 27082, 591 }, /* Panama */
2537 { 193, {'P','T',0}, {'P','R','T',0}, 47610, 620 }, /* Portugal */
2538 { 194, {'P','G',0}, {'P','N','G',0}, 20900, 598 }, /* Papua New Guinea */
2539 { 195, {'P','W',0}, {'P','L','W',0}, 21206, 585 }, /* Palau */
2540 { 196, {'G','W',0}, {'G','N','B',0}, 42483, 624 }, /* Guinea-Bissau */
2541 { 197, {'Q','A',0}, {'Q','A','T',0}, 47611, 634 }, /* Qatar */
2542 { 198, {'R','E',0}, {'R','E','U',0}, 47603, 638 }, /* Reunion */
2543 { 199, {'M','H',0}, {'M','H','L',0}, 21206, 584 }, /* Marshall Islands */
2544 { 200, {'R','O',0}, {'R','O','U',0}, 47609, 642 }, /* Romania */
2545 { 201, {'P','H',0}, {'P','H','L',0}, 47599, 608 }, /* Philippines */
2546 { 202, {'P','R',0}, {'P','R','I',0}, 10039880, 630 }, /* Puerto Rico */
2547 { 203, {'R','U',0}, {'R','U','S',0}, 47609, 643 }, /* Russia */
2548 { 204, {'R','W',0}, {'R','W','A',0}, 47603, 646 }, /* Rwanda */
2549 { 205, {'S','A',0}, {'S','A','U',0}, 47611, 682 }, /* Saudi Arabia */
2550 { 206, {'P','M',0}, {'S','P','M',0}, 23581, 666 }, /* St. Pierre and Miquelon */
2551 { 207, {'K','N',0}, {'K','N','A',0}, 10039880, 659 }, /* St. Kitts and Nevis */
2552 { 208, {'S','C',0}, {'S','Y','C',0}, 47603, 690 }, /* Seychelles */
2553 { 209, {'Z','A',0}, {'Z','A','F',0}, 10039883, 710 }, /* South Africa */
2554 { 210, {'S','N',0}, {'S','E','N',0}, 42483, 686 }, /* Senegal */
2555 { 212, {'S','I',0}, {'S','V','N',0}, 47610, 705 }, /* Slovenia */
2556 { 213, {'S','L',0}, {'S','L','E',0}, 42483, 694 }, /* Sierra Leone */
2557 { 214, {'S','M',0}, {'S','M','R',0}, 47610, 674 }, /* San Marino */
2558 { 215, {'S','G',0}, {'S','G','P',0}, 47599, 702 }, /* Singapore */
2559 { 216, {'S','O',0}, {'S','O','M',0}, 47603, 706 }, /* Somalia */
2560 { 217, {'E','S',0}, {'E','S','P',0}, 47610, 724 }, /* Spain */
2561 { 218, {'L','C',0}, {'L','C','A',0}, 10039880, 662 }, /* St. Lucia */
2562 { 219, {'S','D',0}, {'S','D','N',0}, 42487, 736 }, /* Sudan */
2563 { 220, {'S','J',0}, {'S','J','M',0}, 10039882, 744 }, /* Svalbard */
2564 { 221, {'S','E',0}, {'S','W','E',0}, 10039882, 752 }, /* Sweden */
2565 { 222, {'S','Y',0}, {'S','Y','R',0}, 47611, 760 }, /* Syria */
2566 { 223, {'C','H',0}, {'C','H','E',0}, 10210824, 756 }, /* Switzerland */
2567 { 224, {'A','E',0}, {'A','R','E',0}, 47611, 784 }, /* United Arab Emirates */
2568 { 225, {'T','T',0}, {'T','T','O',0}, 10039880, 780 }, /* Trinidad and Tobago */
2569 { 227, {'T','H',0}, {'T','H','A',0}, 47599, 764 }, /* Thailand */
2570 { 228, {'T','J',0}, {'T','J','K',0}, 47590, 762 }, /* Tajikistan */
2571 { 231, {'T','O',0}, {'T','O','N',0}, 26286, 776 }, /* Tonga */
2572 { 232, {'T','G',0}, {'T','G','O',0}, 42483, 768 }, /* Togo */
2573 { 233, {'S','T',0}, {'S','T','P',0}, 42484, 678 }, /* São Tomé and Príncipe */
2574 { 234, {'T','N',0}, {'T','U','N',0}, 42487, 788 }, /* Tunisia */
2575 { 235, {'T','R',0}, {'T','U','R',0}, 47611, 792 }, /* Turkey */
2576 { 236, {'T','V',0}, {'T','U','V',0}, 26286, 798 }, /* Tuvalu */
2577 { 237, {'T','W',0}, {'T','W','N',0}, 47600, 158 }, /* Taiwan */
2578 { 238, {'T','M',0}, {'T','K','M',0}, 47590, 795 }, /* Turkmenistan */
2579 { 239, {'T','Z',0}, {'T','Z','A',0}, 47603, 834 }, /* Tanzania */
2580 { 240, {'U','G',0}, {'U','G','A',0}, 47603, 800 }, /* Uganda */
2581 { 241, {'U','A',0}, {'U','K','R',0}, 47609, 804 }, /* Ukraine */
2582 { 242, {'G','B',0}, {'G','B','R',0}, 10039882, 826 }, /* United Kingdom */
2583 { 244, {'U','S',0}, {'U','S','A',0}, 23581, 840 }, /* United States */
2584 { 245, {'B','F',0}, {'B','F','A',0}, 42483, 854 }, /* Burkina Faso */
2585 { 246, {'U','Y',0}, {'U','R','Y',0}, 31396, 858 }, /* Uruguay */
2586 { 247, {'U','Z',0}, {'U','Z','B',0}, 47590, 860 }, /* Uzbekistan */
2587 { 248, {'V','C',0}, {'V','C','T',0}, 10039880, 670 }, /* St. Vincent and the Grenadines */
2588 { 249, {'V','E',0}, {'V','E','N',0}, 31396, 862 }, /* Bolivarian Republic of Venezuela */
2589 { 251, {'V','N',0}, {'V','N','M',0}, 47599, 704 }, /* Vietnam */
2590 { 252, {'V','I',0}, {'V','I','R',0}, 10039880, 850 }, /* Virgin Islands */
2591 { 253, {'V','A',0}, {'V','A','T',0}, 47610, 336 }, /* Vatican City */
2592 { 254, {'N','A',0}, {'N','A','M',0}, 10039883, 516 }, /* Namibia */
2593 { 257, {'E','H',0}, {'E','S','H',0}, 42487, 732 }, /* Western Sahara (disputed) */
2594 { 258, {'X','X',0}, {'X','X',0}, 161832256 }, /* Wake Island */
2595 { 259, {'W','S',0}, {'W','S','M',0}, 26286, 882 }, /* Samoa */
2596 { 260, {'S','Z',0}, {'S','W','Z',0}, 10039883, 748 }, /* Swaziland */
2597 { 261, {'Y','E',0}, {'Y','E','M',0}, 47611, 887 }, /* Yemen */
2598 { 263, {'Z','M',0}, {'Z','M','B',0}, 47603, 894 }, /* Zambia */
2599 { 264, {'Z','W',0}, {'Z','W','E',0}, 47603, 716 }, /* Zimbabwe */
2600 { 269, {'C','S',0}, {'S','C','G',0}, 47610, 891 }, /* Serbia and Montenegro (Former) */
2601 { 270, {'M','E',0}, {'M','N','E',0}, 47610, 499 }, /* Montenegro */
2602 { 271, {'R','S',0}, {'S','R','B',0}, 47610, 688 }, /* Serbia */
2603 { 273, {'C','W',0}, {'C','U','W',0}, 10039880, 531 }, /* Curaçao */
2604 { 276, {'S','S',0}, {'S','S','D',0}, 42487, 728 }, /* South Sudan */
2605 { 300, {'A','I',0}, {'A','I','A',0}, 10039880, 660 }, /* Anguilla */
2606 { 301, {'A','Q',0}, {'A','T','A',0}, 39070, 10 }, /* Antarctica */
2607 { 302, {'A','W',0}, {'A','B','W',0}, 10039880, 533 }, /* Aruba */
2608 { 303, {'X','X',0}, {'X','X',0}, 39070 }, /* Ascension Island */
2609 { 304, {'X','X',0}, {'X','X',0}, 10210825 }, /* Ashmore and Cartier Islands */
2610 { 305, {'X','X',0}, {'X','X',0}, 161832256 }, /* Baker Island */
2611 { 306, {'B','V',0}, {'B','V','T',0}, 39070, 74 }, /* Bouvet Island */
2612 { 307, {'K','Y',0}, {'C','Y','M',0}, 10039880, 136 }, /* Cayman Islands */
2613 { 308, {'X','X',0}, {'X','X',0}, 10210824, 0, LOCATION_BOTH }, /* Channel Islands */
2614 { 309, {'C','X',0}, {'C','X','R',0}, 12, 162 }, /* Christmas Island */
2615 { 310, {'X','X',0}, {'X','X',0}, 27114 }, /* Clipperton Island */
2616 { 311, {'C','C',0}, {'C','C','K',0}, 10210825, 166 }, /* Cocos (Keeling) Islands */
2617 { 312, {'C','K',0}, {'C','O','K',0}, 26286, 184 }, /* Cook Islands */
2618 { 313, {'X','X',0}, {'X','X',0}, 10210825 }, /* Coral Sea Islands */
2619 { 314, {'X','X',0}, {'X','X',0}, 114 }, /* Diego Garcia */
2620 { 315, {'F','K',0}, {'F','L','K',0}, 31396, 238 }, /* Falkland Islands (Islas Malvinas) */
2621 { 317, {'G','F',0}, {'G','U','F',0}, 31396, 254 }, /* French Guiana */
2622 { 318, {'P','F',0}, {'P','Y','F',0}, 26286, 258 }, /* French Polynesia */
2623 { 319, {'T','F',0}, {'A','T','F',0}, 39070, 260 }, /* French Southern and Antarctic Lands */
2624 { 321, {'G','P',0}, {'G','L','P',0}, 10039880, 312 }, /* Guadeloupe */
2625 { 322, {'G','U',0}, {'G','U','M',0}, 21206, 316 }, /* Guam */
2626 { 323, {'X','X',0}, {'X','X',0}, 39070 }, /* Guantanamo Bay */
2627 { 324, {'G','G',0}, {'G','G','Y',0}, 308, 831 }, /* Guernsey */
2628 { 325, {'H','M',0}, {'H','M','D',0}, 39070, 334 }, /* Heard Island and McDonald Islands */
2629 { 326, {'X','X',0}, {'X','X',0}, 161832256 }, /* Howland Island */
2630 { 327, {'X','X',0}, {'X','X',0}, 161832256 }, /* Jarvis Island */
2631 { 328, {'J','E',0}, {'J','E','Y',0}, 308, 832 }, /* Jersey */
2632 { 329, {'X','X',0}, {'X','X',0}, 161832256 }, /* Kingman Reef */
2633 { 330, {'M','Q',0}, {'M','T','Q',0}, 10039880, 474 }, /* Martinique */
2634 { 331, {'Y','T',0}, {'M','Y','T',0}, 47603, 175 }, /* Mayotte */
2635 { 332, {'M','S',0}, {'M','S','R',0}, 10039880, 500 }, /* Montserrat */
2636 { 333, {'A','N',0}, {'A','N','T',0}, 10039880, 530, LOCATION_BOTH }, /* Netherlands Antilles (Former) */
2637 { 334, {'N','C',0}, {'N','C','L',0}, 20900, 540 }, /* New Caledonia */
2638 { 335, {'N','U',0}, {'N','I','U',0}, 26286, 570 }, /* Niue */
2639 { 336, {'N','F',0}, {'N','F','K',0}, 10210825, 574 }, /* Norfolk Island */
2640 { 337, {'M','P',0}, {'M','N','P',0}, 21206, 580 }, /* Northern Mariana Islands */
2641 { 338, {'X','X',0}, {'X','X',0}, 161832256 }, /* Palmyra Atoll */
2642 { 339, {'P','N',0}, {'P','C','N',0}, 26286, 612 }, /* Pitcairn Islands */
2643 { 340, {'X','X',0}, {'X','X',0}, 337 }, /* Rota Island */
2644 { 341, {'X','X',0}, {'X','X',0}, 337 }, /* Saipan */
2645 { 342, {'G','S',0}, {'S','G','S',0}, 39070, 239 }, /* South Georgia and the South Sandwich Islands */
2646 { 343, {'S','H',0}, {'S','H','N',0}, 42483, 654 }, /* St. Helena */
2647 { 346, {'X','X',0}, {'X','X',0}, 337 }, /* Tinian Island */
2648 { 347, {'T','K',0}, {'T','K','L',0}, 26286, 772 }, /* Tokelau */
2649 { 348, {'X','X',0}, {'X','X',0}, 39070 }, /* Tristan da Cunha */
2650 { 349, {'T','C',0}, {'T','C','A',0}, 10039880, 796 }, /* Turks and Caicos Islands */
2651 { 351, {'V','G',0}, {'V','G','B',0}, 10039880, 92 }, /* Virgin Islands, British */
2652 { 352, {'W','F',0}, {'W','L','F',0}, 26286, 876 }, /* Wallis and Futuna */
2653 { 742, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Africa */
2654 { 2129, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Asia */
2655 { 10541, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Europe */
2656 { 15126, {'I','M',0}, {'I','M','N',0}, 10039882, 833 }, /* Man, Isle of */
2657 { 19618, {'M','K',0}, {'M','K','D',0}, 47610, 807 }, /* Macedonia, Former Yugoslav Republic of */
2658 { 20900, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION }, /* Melanesia */
2659 { 21206, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION }, /* Micronesia */
2660 { 21242, {'X','X',0}, {'X','X',0}, 161832256 }, /* Midway Islands */
2661 { 23581, {'X','X',0}, {'X','X',0}, 10026358, 0, LOCATION_REGION }, /* Northern America */
2662 { 26286, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION }, /* Polynesia */
2663 { 27082, {'X','X',0}, {'X','X',0}, 161832257, 0, LOCATION_REGION }, /* Central America */
2664 { 27114, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Oceania */
2665 { 30967, {'S','X',0}, {'S','X','M',0}, 10039880, 534 }, /* Sint Maarten (Dutch part) */
2666 { 31396, {'X','X',0}, {'X','X',0}, 161832257, 0, LOCATION_REGION }, /* South America */
2667 { 31706, {'M','F',0}, {'M','A','F',0}, 10039880, 663 }, /* Saint Martin (French part) */
2668 { 39070, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* World */
2669 { 42483, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Western Africa */
2670 { 42484, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Middle Africa */
2671 { 42487, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Northern Africa */
2672 { 47590, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* Central Asia */
2673 { 47599, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* South-Eastern Asia */
2674 { 47600, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* Eastern Asia */
2675 { 47603, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Eastern Africa */
2676 { 47609, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION }, /* Eastern Europe */
2677 { 47610, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION }, /* Southern Europe */
2678 { 47611, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* Middle East */
2679 { 47614, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* Southern Asia */
2680 { 7299303, {'T','L',0}, {'T','L','S',0}, 47599, 626 }, /* Democratic Republic of Timor-Leste */
2681 { 10026358, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Americas */
2682 { 10028789, {'A','X',0}, {'A','L','A',0}, 10039882, 248 }, /* Åland Islands */
2683 { 10039880, {'X','X',0}, {'X','X',0}, 161832257, 0, LOCATION_REGION }, /* Caribbean */
2684 { 10039882, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION }, /* Northern Europe */
2685 { 10039883, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Southern Africa */
2686 { 10210824, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION }, /* Western Europe */
2687 { 10210825, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION }, /* Australia and New Zealand */
2688 { 161832015, {'B','L',0}, {'B','L','M',0}, 10039880, 652 }, /* Saint Barthélemy */
2689 { 161832256, {'U','M',0}, {'U','M','I',0}, 27114, 581 }, /* U.S. Minor Outlying Islands */
2690 { 161832257, {'X','X',0}, {'X','X',0}, 10026358, 0, LOCATION_REGION }, /* Latin America and the Caribbean */
2691 };
2692
2693 /******************************************************************************
2694 * EnumLanguageGroupLocalesA (KERNEL32.@)
2695 *
2696 * Call a users function for every locale in a language group available on the system.
2697 *
2698 * PARAMS
2699 * pLangGrpLcEnumProc [I] Callback function to call for each locale
2700 * lgrpid [I] Language group (LGRPID_ values from "winnls.h")
2701 * dwFlags [I] Reserved, set to 0
2702 * lParam [I] User parameter to pass to pLangGrpLcEnumProc
2703 *
2704 * RETURNS
2705 * Success: TRUE.
2706 * Failure: FALSE. Use GetLastError() to determine the cause.
2707 */
2708 BOOL WINAPI EnumLanguageGroupLocalesA(LANGGROUPLOCALE_ENUMPROCA pLangGrpLcEnumProc,
2709 LGRPID lgrpid, DWORD dwFlags, LONG_PTR lParam)
2710 {
2711 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks;
2712
2713 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc, lgrpid, dwFlags, lParam);
2714
2715 callbacks.procA = pLangGrpLcEnumProc;
2716 callbacks.procW = NULL;
2717 callbacks.dwFlags = dwFlags;
2718 callbacks.lgrpid = lgrpid;
2719 callbacks.lParam = lParam;
2720
2721 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc ? &callbacks : NULL );
2722 }
2723
2724 /******************************************************************************
2725 * EnumLanguageGroupLocalesW (KERNEL32.@)
2726 *
2727 * See EnumLanguageGroupLocalesA.
2728 */
2729 BOOL WINAPI EnumLanguageGroupLocalesW(LANGGROUPLOCALE_ENUMPROCW pLangGrpLcEnumProc,
2730 LGRPID lgrpid, DWORD dwFlags, LONG_PTR lParam)
2731 {
2732 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks;
2733
2734 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc, lgrpid, dwFlags, lParam);
2735
2736 callbacks.procA = NULL;
2737 callbacks.procW = pLangGrpLcEnumProc;
2738 callbacks.dwFlags = dwFlags;
2739 callbacks.lgrpid = lgrpid;
2740 callbacks.lParam = lParam;
2741
2742 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc ? &callbacks : NULL );
2743 }
2744
2745 /* Callback function ptrs for EnumSystemCodePagesA/W */
2746 typedef struct
2747 {
2748 CODEPAGE_ENUMPROCA procA;
2749 CODEPAGE_ENUMPROCW procW;
2750 DWORD dwFlags;
2751 } ENUMSYSTEMCODEPAGES_CALLBACKS;
2752
2753 /* Internal implementation of EnumSystemCodePagesA/W */
2754 static BOOL NLS_EnumSystemCodePages(ENUMSYSTEMCODEPAGES_CALLBACKS *lpProcs)
2755 {
2756 WCHAR szNumber[5 + 1], szValue[MAX_PATH];
2757 HANDLE hKey;
2758 BOOL bContinue = TRUE;
2759 ULONG ulIndex = 0;
2760
2761 if (!lpProcs)
2762 {
2763 SetLastError(ERROR_INVALID_PARAMETER);
2764 return FALSE;
2765 }
2766
2767 switch (lpProcs->dwFlags)
2768 {
2769 case CP_INSTALLED:
2770 case CP_SUPPORTED:
2771 break;
2772 default:
2773 SetLastError(ERROR_INVALID_FLAGS);
2774 return FALSE;
2775 }
2776
2777 hKey = NLS_RegOpenKey(0, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
2778 if (!hKey)
2779 {
2780 WARN("NLS_RegOpenKey() failed\n");
2781 return FALSE;
2782 }
2783
2784 while (bContinue)
2785 {
2786 if (NLS_RegEnumValue(hKey, ulIndex, szNumber, sizeof(szNumber),
2787 szValue, sizeof(szValue)))
2788 {
2789 if ((lpProcs->dwFlags == CP_SUPPORTED)||
2790 ((lpProcs->dwFlags == CP_INSTALLED)&&(wcslen(szValue) > 2)))
2791 {
2792 if (lpProcs->procW)
2793 {
2794 bContinue = lpProcs->procW(szNumber);
2795 }
2796 else
2797 {
2798 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
2799
2800 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
2801 bContinue = lpProcs->procA(szNumberA);
2802 }
2803 }
2804
2805 ulIndex++;
2806
2807 } else bContinue = FALSE;
2808
2809 if (!bContinue)
2810 break;
2811 }
2812
2813 if (hKey)
2814 NtClose(hKey);
2815
2816 return TRUE;
2817 }
2818
2819 /*
2820 * @implemented
2821 */
2822 BOOL
2823 WINAPI
2824 EnumSystemCodePagesW (
2825 CODEPAGE_ENUMPROCW lpCodePageEnumProc,
2826 DWORD dwFlags
2827 )
2828 {
2829 ENUMSYSTEMCODEPAGES_CALLBACKS procs;
2830
2831 TRACE("(%p,0x%08X,0x%08lX)\n", lpCodePageEnumProc, dwFlags);
2832
2833 procs.procA = NULL;
2834 procs.procW = lpCodePageEnumProc;
2835 procs.dwFlags = dwFlags;
2836
2837 return NLS_EnumSystemCodePages(lpCodePageEnumProc ? &procs : NULL);
2838 }
2839
2840
2841 /*
2842 * @implemented
2843 */
2844 BOOL
2845 WINAPI
2846 EnumSystemCodePagesA (
2847 CODEPAGE_ENUMPROCA lpCodePageEnumProc,
2848 DWORD dwFlags
2849 )
2850 {
2851 ENUMSYSTEMCODEPAGES_CALLBACKS procs;
2852
2853 TRACE("(%p,0x%08X,0x%08lX)\n", lpCodePageEnumProc, dwFlags);
2854
2855 procs.procA = lpCodePageEnumProc;
2856 procs.procW = NULL;
2857 procs.dwFlags = dwFlags;
2858
2859 return NLS_EnumSystemCodePages(lpCodePageEnumProc ? &procs : NULL);
2860 }
2861
2862 /******************************************************************************
2863 * EnumSystemGeoID (KERNEL32.@)
2864 *
2865 * Call a users function for every location available on the system.
2866 *
2867 * PARAMS
2868 * geoclass [I] Type of information desired (SYSGEOTYPE enum from "winnls.h")
2869 * parent [I] GEOID for the parent
2870 * enumproc [I] Callback function to call for each location
2871 *
2872 * RETURNS
2873 * Success: TRUE.
2874 * Failure: FALSE. Use GetLastError() to determine the cause.
2875 */
2876 BOOL WINAPI EnumSystemGeoID(GEOCLASS geoclass, GEOID parent, GEO_ENUMPROC enumproc)
2877 {
2878 INT i;
2879
2880 TRACE("(%d, %d, %p)\n", geoclass, parent, enumproc);
2881
2882 if (!enumproc) {
2883 SetLastError(ERROR_INVALID_PARAMETER);
2884 return FALSE;
2885 }
2886
2887 if (geoclass != GEOCLASS_NATION && geoclass != GEOCLASS_REGION) {
2888 SetLastError(ERROR_INVALID_FLAGS);
2889 return FALSE;
2890 }
2891
2892 for (i = 0; i < sizeof(geoinfodata)/sizeof(struct geoinfo_t); i++) {
2893 const struct geoinfo_t *ptr = &geoinfodata[i];
2894
2895 if (geoclass == GEOCLASS_NATION && (ptr->kind == LOCATION_REGION))
2896 continue;
2897
2898 if (geoclass == GEOCLASS_REGION && (ptr->kind == LOCATION_NATION))
2899 continue;
2900
2901 if (parent && ptr->parent != parent)
2902 continue;
2903
2904 if (!enumproc(ptr->id))
2905 return TRUE;
2906 }
2907
2908 return TRUE;
2909 }
2910
2911 /******************************************************************************
2912 * InvalidateNLSCache (KERNEL32.@)
2913 *
2914 * Invalidate the cache of NLS values.
2915 *
2916 * PARAMS
2917 * None.
2918 *
2919 * RETURNS
2920 * Success: TRUE.
2921 * Failure: FALSE.
2922 */
2923 BOOL WINAPI InvalidateNLSCache(void)
2924 {
2925 FIXME("() stub\n");
2926 return FALSE;
2927 }
2928
2929 /******************************************************************************
2930 * GetUserGeoID (KERNEL32.@)
2931 */
2932 GEOID WINAPI GetUserGeoID( GEOCLASS GeoClass )
2933 {
2934 GEOID ret = GEOID_NOT_AVAILABLE;
2935 static const WCHAR geoW[] = {'G','e','o',0};
2936 static const WCHAR nationW[] = {'N','a','t','i','o','n',0};
2937 WCHAR bufferW[40], *end;
2938 DWORD count;
2939 HANDLE hkey, hSubkey = 0;
2940 UNICODE_STRING keyW;
2941 const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)bufferW;
2942 RtlInitUnicodeString( &keyW, nationW );
2943 count = sizeof(bufferW);
2944
2945 if(!(hkey = create_registry_key())) return ret;
2946
2947 switch( GeoClass ){
2948 case GEOCLASS_NATION:
2949 if ((hSubkey = NLS_RegOpenKey(hkey, geoW)))
2950 {
2951 if((NtQueryValueKey(hSubkey, &keyW, KeyValuePartialInformation,
2952 bufferW, count, &count) == STATUS_SUCCESS ) && info->DataLength)
2953 ret = strtolW((LPCWSTR)info->Data, &end, 10);
2954 }
2955 break;
2956 case GEOCLASS_REGION:
2957 FIXME("GEOCLASS_REGION not handled yet\n");
2958 break;
2959 }
2960
2961 NtClose(hkey);
2962 if (hSubkey) NtClose(hSubkey);
2963 return ret;
2964 }
2965
2966 /******************************************************************************
2967 * SetUserGeoID (KERNEL32.@)
2968 */
2969 BOOL WINAPI SetUserGeoID( GEOID GeoID )
2970 {
2971 static const WCHAR geoW[] = {'G','e','o',0};
2972 static const WCHAR nationW[] = {'N','a','t','i','o','n',0};
2973 static const WCHAR formatW[] = {'%','i',0};
2974 UNICODE_STRING nameW,keyW;
2975 WCHAR bufferW[10];
2976 OBJECT_ATTRIBUTES attr;
2977 HANDLE hkey;
2978
2979 if(!(hkey = create_registry_key())) return FALSE;
2980
2981 attr.Length = sizeof(attr);
2982 attr.RootDirectory = hkey;
2983 attr.ObjectName = &nameW;
2984 attr.Attributes = 0;
2985 attr.SecurityDescriptor = NULL;
2986 attr.SecurityQualityOfService = NULL;
2987 RtlInitUnicodeString( &nameW, geoW );
2988 RtlInitUnicodeString( &keyW, nationW );
2989
2990 if (NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) != STATUS_SUCCESS)
2991
2992 {
2993 NtClose(attr.RootDirectory);
2994 return FALSE;
2995 }
2996
2997 sprintfW(bufferW, formatW, GeoID);
2998 NtSetValueKey(hkey, &keyW, 0, REG_SZ, bufferW, (strlenW(bufferW) + 1) * sizeof(WCHAR));
2999 NtClose(attr.RootDirectory);
3000 NtClose(hkey);
3001 return TRUE;
3002 }
3003
3004 typedef struct
3005 {
3006 union
3007 {
3008 UILANGUAGE_ENUMPROCA procA;
3009 UILANGUAGE_ENUMPROCW procW;
3010 } u;
3011 DWORD flags;
3012 LONG_PTR param;
3013 } ENUM_UILANG_CALLBACK;
3014
3015 static BOOL CALLBACK enum_uilang_proc_a( HMODULE hModule, LPCSTR type,
3016 LPCSTR name, WORD LangID, LONG_PTR lParam )
3017 {
3018 ENUM_UILANG_CALLBACK *enum_uilang = (ENUM_UILANG_CALLBACK *)lParam;
3019 char buf[20];
3020
3021 sprintf(buf, "%08x", (UINT)LangID);
3022 return enum_uilang->u.procA( buf, enum_uilang->param );
3023 }
3024
3025 static BOOL CALLBACK enum_uilang_proc_w( HMODULE hModule, LPCWSTR type,
3026 LPCWSTR name, WORD LangID, LONG_PTR lParam )
3027 {
3028 static const WCHAR formatW[] = {'%','0','8','x',0};
3029 ENUM_UILANG_CALLBACK *enum_uilang = (ENUM_UILANG_CALLBACK *)lParam;
3030 WCHAR buf[20];
3031
3032 sprintfW( buf, formatW, (UINT)LangID );
3033 return enum_uilang->u.procW( buf, enum_uilang->param );
3034 }
3035
3036 /******************************************************************************
3037 * EnumUILanguagesA (KERNEL32.@)
3038 */
3039 BOOL WINAPI EnumUILanguagesA(UILANGUAGE_ENUMPROCA pUILangEnumProc, DWORD dwFlags, LONG_PTR lParam)
3040 {
3041 ENUM_UILANG_CALLBACK enum_uilang;
3042
3043 TRACE("%p, %x, %lx\n", pUILangEnumProc, dwFlags, lParam);
3044
3045 if(!pUILangEnumProc) {
3046 SetLastError(ERROR_INVALID_PARAMETER);
3047 return FALSE;
3048 }
3049 if(dwFlags) {
3050 SetLastError(ERROR_INVALID_FLAGS);
3051 return FALSE;
3052 }
3053
3054 enum_uilang.u.procA = pUILangEnumProc;
3055 enum_uilang.flags = dwFlags;
3056 enum_uilang.param = lParam;
3057
3058 EnumResourceLanguagesA( kernel32_handle, (LPCSTR)RT_STRING,
3059 (LPCSTR)LOCALE_ILANGUAGE, enum_uilang_proc_a,
3060 (LONG_PTR)&enum_uilang);
3061 return TRUE;
3062 }
3063
3064 /******************************************************************************
3065 * EnumUILanguagesW (KERNEL32.@)
3066 */
3067 BOOL WINAPI EnumUILanguagesW(UILANGUAGE_ENUMPROCW pUILangEnumProc, DWORD dwFlags, LONG_PTR lParam)
3068 {
3069 ENUM_UILANG_CALLBACK enum_uilang;
3070
3071 TRACE("%p, %x, %lx\n", pUILangEnumProc, dwFlags, lParam);
3072
3073
3074 if(!pUILangEnumProc) {
3075 SetLastError(ERROR_INVALID_PARAMETER);
3076 return FALSE;
3077 }
3078 if(dwFlags) {
3079 SetLastError(ERROR_INVALID_FLAGS);
3080 return FALSE;
3081 }
3082
3083 enum_uilang.u.procW = pUILangEnumProc;
3084 enum_uilang.flags = dwFlags;
3085 enum_uilang.param = lParam;
3086
3087 EnumResourceLanguagesW( kernel32_handle, (LPCWSTR)RT_STRING,
3088 (LPCWSTR)LOCALE_ILANGUAGE, enum_uilang_proc_w,
3089 (LONG_PTR)&enum_uilang);
3090 return TRUE;
3091 }
3092
3093 static int
3094 NLS_GetGeoFriendlyName(GEOID Location, LPWSTR szFriendlyName, int cchData)
3095 {
3096 LPWSTR szBuffer;
3097 DWORD dwSize;
3098
3099 /* FIXME: move *.nls resources out of kernel32 into locale.nls */
3100 Location += NLSRC_OFFSET;
3101 Location &= 0xFFFF;
3102
3103 if(cchData == 0)
3104 return GetLocalisedText(Location, NULL, 0);
3105
3106 dwSize = cchData * sizeof(WCHAR);
3107 szBuffer = HeapAlloc(GetProcessHeap(), 0, dwSize);
3108
3109 if (!szBuffer)
3110 {
3111 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
3112 return 0;
3113 }
3114
3115 if(GetLocalisedText(Location, szBuffer, dwSize))
3116 {
3117 memcpy(szFriendlyName, szBuffer, dwSize);
3118 HeapFree(GetProcessHeap(), 0, szBuffer);
3119 return strlenW(szFriendlyName) + 1;
3120 }
3121
3122 HeapFree(GetProcessHeap(), 0, szBuffer);
3123 return 0;
3124 }
3125
3126 static const struct geoinfo_t *get_geoinfo_dataptr(GEOID geoid)
3127 {
3128 int min, max;
3129
3130 min = 0;
3131 max = sizeof(geoinfodata)/sizeof(struct geoinfo_t)-1;
3132
3133 while (min <= max) {
3134 const struct geoinfo_t *ptr;
3135 int n = (min+max)/2;
3136
3137 ptr = &geoinfodata[n];
3138 if (geoid == ptr->id)
3139 /* we don't need empty entry */
3140 return *ptr->iso2W ? ptr : NULL;
3141
3142 if (ptr->id > geoid)
3143 max = n-1;
3144 else
3145 min = n+1;
3146 }
3147
3148 return NULL;
3149 }
3150
3151 /******************************************************************************
3152 * GetGeoInfoW (KERNEL32.@)
3153 */
3154 INT WINAPI GetGeoInfoW(GEOID geoid, GEOTYPE geotype, LPWSTR data, int data_len, LANGID lang)
3155 {
3156 const struct geoinfo_t *ptr;
3157 const WCHAR *str = NULL;
3158 WCHAR buffW[12];
3159 LONG val = 0;
3160 INT len;
3161
3162 TRACE("%d %d %p %d %d\n", geoid, geotype, data, data_len, lang);
3163
3164 if (!(ptr = get_geoinfo_dataptr(geoid))) {
3165 SetLastError(ERROR_INVALID_PARAMETER);
3166 return 0;
3167 }
3168
3169 switch (geotype) {
3170 case GEO_FRIENDLYNAME:
3171 {
3172 return NLS_GetGeoFriendlyName(geoid, data, data_len);
3173 }
3174 case GEO_NATION:
3175 val = geoid;
3176 break;
3177 case GEO_ISO_UN_NUMBER:
3178 val = ptr->uncode;
3179 break;
3180 case GEO_PARENT:
3181 val = ptr->parent;
3182 break;
3183 case GEO_ISO2:
3184 case GEO_ISO3:
3185 {
3186 str = geotype == GEO_ISO2 ? ptr->iso2W : ptr->iso3W;
3187 break;
3188 }
3189 case GEO_RFC1766:
3190 case GEO_LCID:
3191 case GEO_OFFICIALNAME:
3192 case GEO_TIMEZONES:
3193 case GEO_OFFICIALLANGUAGES:
3194 case GEO_LATITUDE:
3195 case GEO_LONGITUDE:
3196 FIXME("type %d is not supported\n", geotype);
3197 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3198 return 0;
3199 default:
3200 WARN("unrecognized type %d\n", geotype);
3201 SetLastError(ERROR_INVALID_FLAGS);
3202 return 0;
3203 }
3204
3205 if (val) {
3206 static const WCHAR fmtW[] = {'%','d',0};
3207 sprintfW(buffW, fmtW, val);
3208 str = buffW;
3209 }
3210
3211 len = strlenW(str) + 1;
3212 if (!data || !data_len)
3213 return len;
3214
3215 memcpy(data, str, min(len, data_len)*sizeof(WCHAR));
3216 if (data_len < len)
3217 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3218 return data_len < len ? 0 : len;
3219 }
3220
3221 /******************************************************************************
3222 * GetGeoInfoA (KERNEL32.@)
3223 */
3224 INT WINAPI GetGeoInfoA(GEOID geoid, GEOTYPE geotype, LPSTR data, int data_len, LANGID lang)
3225 {
3226 WCHAR *buffW;
3227 INT len;
3228
3229 TRACE("%d %d %p %d %d\n", geoid, geotype, data, data_len, lang);
3230
3231 len = GetGeoInfoW(geoid, geotype, NULL, 0, lang);
3232 if (!len)
3233 return 0;
3234
3235 buffW = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
3236 if (!buffW)
3237 return 0;
3238
3239 GetGeoInfoW(geoid, geotype, buffW, len, lang);
3240 len = WideCharToMultiByte(CP_ACP, 0, buffW, -1, NULL, 0, NULL, NULL);
3241 if (!data || !data_len) {
3242 HeapFree(GetProcessHeap(), 0, buffW);
3243 return len;
3244 }
3245
3246 len = WideCharToMultiByte(CP_ACP, 0, buffW, -1, data, data_len, NULL, NULL);
3247 HeapFree(GetProcessHeap(), 0, buffW);
3248
3249 if (data_len < len)
3250 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3251 return data_len < len ? 0 : len;
3252 }