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