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