7c5b0d765d93602d1994d2696f44e3fb7781737d
[reactos.git] / reactos / dll / win32 / kernel32 / winnls / string / lang.c
1 /*
2 * Locale support
3 *
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
7 * Copyright 2002 Alexandre Julliard for CodeWeavers
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24 #include <k32.h>
25
26 #define NDEBUG
27 #include <debug.h>
28 DEBUG_CHANNEL(nls);
29
30 #include "lcformat_private.h"
31
32 #define REG_SZ 1
33 extern int wine_fold_string(int flags, const WCHAR *src, int srclen, WCHAR *dst, int dstlen);
34 extern int wine_get_sortkey(int flags, const WCHAR *src, int srclen, char *dst, int dstlen);
35 extern int wine_compare_string(int flags, const WCHAR *str1, int len1, const WCHAR *str2, int len2);
36 extern DWORD GetLocalisedText(DWORD dwResId, WCHAR *lpszDest, DWORD dwDestSize);
37 #define NLSRC_OFFSET 5000 /* FIXME */
38
39 extern HMODULE kernel32_handle;
40
41 #define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|\
42 LOCALE_RETURN_NUMBER|LOCALE_RETURN_GENITIVE_NAMES)
43
44 static const WCHAR szLocaleKeyName[] = {
45 '\\', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', '\\',
46 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
47 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
48 'C','o','n','t','r','o','l','\\','N','l','s','\\','L','o','c','a','l','e',0
49 };
50
51 static const WCHAR szLangGroupsKeyName[] = {
52 '\\', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', '\\',
53 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
54 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
55 'C','o','n','t','r','o','l','\\','N','l','s','\\',
56 'L','a','n','g','u','a','g','e',' ','G','r','o','u','p','s',0
57 };
58
59 #ifndef __REACTOS__
60 /* Charset to codepage map, sorted by name. */
61 static const struct charset_entry
62 {
63 const char *charset_name;
64 UINT codepage;
65 } charset_names[] =
66 {
67 { "BIG5", 950 },
68 { "CP1250", 1250 },
69 { "CP1251", 1251 },
70 { "CP1252", 1252 },
71 { "CP1253", 1253 },
72 { "CP1254", 1254 },
73 { "CP1255", 1255 },
74 { "CP1256", 1256 },
75 { "CP1257", 1257 },
76 { "CP1258", 1258 },
77 { "CP932", 932 },
78 { "CP936", 936 },
79 { "CP949", 949 },
80 { "CP950", 950 },
81 { "EUCJP", 20932 },
82 { "GB2312", 936 },
83 { "IBM037", 37 },
84 { "IBM1026", 1026 },
85 { "IBM424", 424 },
86 { "IBM437", 437 },
87 { "IBM500", 500 },
88 { "IBM850", 850 },
89 { "IBM852", 852 },
90 { "IBM855", 855 },
91 { "IBM857", 857 },
92 { "IBM860", 860 },
93 { "IBM861", 861 },
94 { "IBM862", 862 },
95 { "IBM863", 863 },
96 { "IBM864", 864 },
97 { "IBM865", 865 },
98 { "IBM866", 866 },
99 { "IBM869", 869 },
100 { "IBM874", 874 },
101 { "IBM875", 875 },
102 { "ISO88591", 28591 },
103 { "ISO885910", 28600 },
104 { "ISO885913", 28603 },
105 { "ISO885914", 28604 },
106 { "ISO885915", 28605 },
107 { "ISO885916", 28606 },
108 { "ISO88592", 28592 },
109 { "ISO88593", 28593 },
110 { "ISO88594", 28594 },
111 { "ISO88595", 28595 },
112 { "ISO88596", 28596 },
113 { "ISO88597", 28597 },
114 { "ISO88598", 28598 },
115 { "ISO88599", 28599 },
116 { "KOI8R", 20866 },
117 { "KOI8U", 21866 },
118 { "UTF8", CP_UTF8 }
119 };
120 #endif
121
122 struct locale_name
123 {
124 WCHAR win_name[128]; /* Windows name ("en-US") */
125 WCHAR lang[128]; /* language ("en") (note: buffer contains the other strings too) */
126 WCHAR *country; /* country ("US") */
127 WCHAR *charset; /* charset ("UTF-8") for Unix format only */
128 WCHAR *script; /* script ("Latn") for Windows format only */
129 WCHAR *modifier; /* modifier or sort order */
130 LCID lcid; /* corresponding LCID */
131 int matches; /* number of elements matching LCID (0..4) */
132 UINT codepage; /* codepage corresponding to charset */
133 };
134
135 /* locale ids corresponding to the various Unix locale parameters */
136 static LCID lcid_LC_COLLATE;
137 static LCID lcid_LC_CTYPE;
138 static LCID lcid_LC_MONETARY;
139 static LCID lcid_LC_NUMERIC;
140 static LCID lcid_LC_TIME;
141 static LCID lcid_LC_PAPER;
142 static LCID lcid_LC_MEASUREMENT;
143 static LCID lcid_LC_TELEPHONE;
144
145 #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 (!src) /* Abort and return FALSE when src is null */
1259 {
1260 SetLastError( ERROR_INVALID_PARAMETER );
1261 return FALSE;
1262 }
1263 if (count == -1) count = strlenW(src) + 1;
1264 switch(type)
1265 {
1266 case CT_CTYPE1:
1267 while (count--) *chartype++ = get_char_typeW( *src++ ) & 0xfff;
1268 break;
1269 case CT_CTYPE2:
1270 while (count--) *chartype++ = type2_map[get_char_typeW( *src++ ) >> 12];
1271 break;
1272 case CT_CTYPE3:
1273 {
1274 WARN("CT_CTYPE3: semi-stub.\n");
1275 while (count--)
1276 {
1277 int c = *src;
1278 WORD type1, type3 = 0; /* C3_NOTAPPLICABLE */
1279
1280 type1 = get_char_typeW( *src++ ) & 0xfff;
1281 /* try to construct type3 from type1 */
1282 if(type1 & C1_SPACE) type3 |= C3_SYMBOL;
1283 if(type1 & C1_ALPHA) type3 |= C3_ALPHA;
1284 if ((c>=0x30A0)&&(c<=0x30FF)) type3 |= C3_KATAKANA;
1285 if ((c>=0x3040)&&(c<=0x309F)) type3 |= C3_HIRAGANA;
1286 if ((c>=0x4E00)&&(c<=0x9FAF)) type3 |= C3_IDEOGRAPH;
1287 if ((c>=0x0600)&&(c<=0x06FF)) type3 |= C3_KASHIDA;
1288 if ((c>=0x3000)&&(c<=0x303F)) type3 |= C3_SYMBOL;
1289
1290 if ((c>=0xD800)&&(c<=0xDBFF)) type3 |= C3_HIGHSURROGATE;
1291 if ((c>=0xDC00)&&(c<=0xDFFF)) type3 |= C3_LOWSURROGATE;
1292
1293 if ((c>=0xFF00)&&(c<=0xFF60)) type3 |= C3_FULLWIDTH;
1294 if ((c>=0xFF00)&&(c<=0xFF20)) type3 |= C3_SYMBOL;
1295 if ((c>=0xFF3B)&&(c<=0xFF40)) type3 |= C3_SYMBOL;
1296 if ((c>=0xFF5B)&&(c<=0xFF60)) type3 |= C3_SYMBOL;
1297 if ((c>=0xFF21)&&(c<=0xFF3A)) type3 |= C3_ALPHA;
1298 if ((c>=0xFF41)&&(c<=0xFF5A)) type3 |= C3_ALPHA;
1299 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_FULLWIDTH;
1300 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_SYMBOL;
1301
1302 if ((c>=0xFF61)&&(c<=0xFFDC)) type3 |= C3_HALFWIDTH;
1303 if ((c>=0xFF61)&&(c<=0xFF64)) type3 |= C3_SYMBOL;
1304 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_KATAKANA;
1305 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_ALPHA;
1306 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_HALFWIDTH;
1307 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_SYMBOL;
1308 *chartype++ = type3;
1309 }
1310 break;
1311 }
1312 default:
1313 SetLastError( ERROR_INVALID_PARAMETER );
1314 return FALSE;
1315 }
1316 return TRUE;
1317 }
1318
1319
1320 /******************************************************************************
1321 * GetStringTypeExW (KERNEL32.@)
1322 *
1323 * See GetStringTypeExA.
1324 */
1325 BOOL WINAPI GetStringTypeExW( LCID locale, DWORD type, LPCWSTR src, INT count, LPWORD chartype )
1326 {
1327 /* locale is ignored for Unicode */
1328 return GetStringTypeW( type, src, count, chartype );
1329 }
1330
1331
1332 /******************************************************************************
1333 * GetStringTypeA (KERNEL32.@)
1334 *
1335 * Get characteristics of the characters making up a string.
1336 *
1337 * PARAMS
1338 * locale [I] Locale Id for the string
1339 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1340 * src [I] String to analyse
1341 * count [I] Length of src in chars, or -1 if src is NUL terminated
1342 * chartype [O] Destination for the calculated characteristics
1343 *
1344 * RETURNS
1345 * Success: TRUE. chartype is filled with the requested characteristics of each char
1346 * in src.
1347 * Failure: FALSE. Use GetLastError() to determine the cause.
1348 */
1349 BOOL WINAPI GetStringTypeA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
1350 {
1351 UINT cp;
1352 INT countW;
1353 LPWSTR srcW;
1354 BOOL ret = FALSE;
1355
1356 if(count == -1) count = strlen(src) + 1;
1357
1358 if (!(cp = get_lcid_codepage( locale )))
1359 {
1360 FIXME("For locale %04x using current ANSI code page\n", locale);
1361 cp = GetACP();
1362 }
1363
1364 countW = MultiByteToWideChar(cp, 0, src, count, NULL, 0);
1365 if((srcW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
1366 {
1367 MultiByteToWideChar(cp, 0, src, count, srcW, countW);
1368 /*
1369 * NOTE: the target buffer has 1 word for each CHARACTER in the source
1370 * string, with multibyte characters there maybe be more bytes in count
1371 * than character space in the buffer!
1372 */
1373 ret = GetStringTypeW(type, srcW, countW, chartype);
1374 HeapFree(GetProcessHeap(), 0, srcW);
1375 }
1376 return ret;
1377 }
1378
1379 /******************************************************************************
1380 * GetStringTypeExA (KERNEL32.@)
1381 *
1382 * Get characteristics of the characters making up a string.
1383 *
1384 * PARAMS
1385 * locale [I] Locale Id for the string
1386 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1387 * src [I] String to analyse
1388 * count [I] Length of src in chars, or -1 if src is NUL terminated
1389 * chartype [O] Destination for the calculated characteristics
1390 *
1391 * RETURNS
1392 * Success: TRUE. chartype is filled with the requested characteristics of each char
1393 * in src.
1394 * Failure: FALSE. Use GetLastError() to determine the cause.
1395 */
1396 BOOL WINAPI GetStringTypeExA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
1397 {
1398 return GetStringTypeA(locale, type, src, count, chartype);
1399 }
1400
1401 /*************************************************************************
1402 * LCMapStringEx (KERNEL32.@)
1403 *
1404 * Map characters in a locale sensitive string.
1405 *
1406 * PARAMS
1407 * name [I] Locale name for the conversion.
1408 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h")
1409 * src [I] String to map
1410 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
1411 * dst [O] Destination for mapped string
1412 * dstlen [I] Length of dst in characters
1413 * version [I] reserved, must be NULL
1414 * reserved [I] reserved, must be NULL
1415 * lparam [I] reserved, must be 0
1416 *
1417 * RETURNS
1418 * Success: The length of the mapped string in dst, including the NUL terminator.
1419 * Failure: 0. Use GetLastError() to determine the cause.
1420 */
1421 INT WINAPI LCMapStringEx(LPCWSTR name, DWORD flags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen,
1422 LPNLSVERSIONINFO version, LPVOID reserved, LPARAM lparam)
1423 {
1424 LPWSTR dst_ptr;
1425
1426 if (version) FIXME("unsupported version structure %p\n", version);
1427 if (reserved) FIXME("unsupported reserved pointer %p\n", reserved);
1428 if (lparam) FIXME("unsupported lparam %lx\n", lparam);
1429
1430 if (!src || !srclen || dstlen < 0)
1431 {
1432 SetLastError(ERROR_INVALID_PARAMETER);
1433 return 0;
1434 }
1435
1436 /* mutually exclusive flags */
1437 if ((flags & (LCMAP_LOWERCASE | LCMAP_UPPERCASE)) == (LCMAP_LOWERCASE | LCMAP_UPPERCASE) ||
1438 (flags & (LCMAP_HIRAGANA | LCMAP_KATAKANA)) == (LCMAP_HIRAGANA | LCMAP_KATAKANA) ||
1439 (flags & (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH)) == (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH) ||
1440 (flags & (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE)) == (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE))
1441 {
1442 SetLastError(ERROR_INVALID_FLAGS);
1443 return 0;
1444 }
1445
1446 if (!dstlen) dst = NULL;
1447
1448 if (flags & LCMAP_SORTKEY)
1449 {
1450 INT ret;
1451 if (src == dst)
1452 {
1453 SetLastError(ERROR_INVALID_FLAGS);
1454 return 0;
1455 }
1456
1457 if (srclen < 0) srclen = strlenW(src);
1458
1459 TRACE("(%s,0x%08x,%s,%d,%p,%d)\n",
1460 debugstr_w(name), flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1461
1462 ret = wine_get_sortkey(flags, src, srclen, (char *)dst, dstlen);
1463 if (ret == 0)
1464 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1465 else
1466 ret++;
1467 return ret;
1468 }
1469
1470 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
1471 if (flags & SORT_STRINGSORT)
1472 {
1473 SetLastError(ERROR_INVALID_FLAGS);
1474 return 0;
1475 }
1476
1477 if (srclen < 0) srclen = strlenW(src) + 1;
1478
1479 TRACE("(%s,0x%08x,%s,%d,%p,%d)\n",
1480 debugstr_w(name), flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1481
1482 if (!dst) /* return required string length */
1483 {
1484 INT len;
1485
1486 for (len = 0; srclen; src++, srclen--)
1487 {
1488 WCHAR wch = *src;
1489 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
1490 * and skips white space and punctuation characters for
1491 * NORM_IGNORESYMBOLS.
1492 */
1493 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1494 continue;
1495 len++;
1496 }
1497 return len;
1498 }
1499
1500 if (flags & LCMAP_UPPERCASE)
1501 {
1502 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1503 {
1504 WCHAR wch = *src;
1505 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1506 continue;
1507 *dst_ptr++ = toupperW(wch);
1508 dstlen--;
1509 }
1510 }
1511 else if (flags & LCMAP_LOWERCASE)
1512 {
1513 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1514 {
1515 WCHAR wch = *src;
1516 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1517 continue;
1518 *dst_ptr++ = tolowerW(wch);
1519 dstlen--;
1520 }
1521 }
1522 else
1523 {
1524 if (src == dst)
1525 {
1526 SetLastError(ERROR_INVALID_FLAGS);
1527 return 0;
1528 }
1529 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1530 {
1531 WCHAR wch = *src;
1532 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1533 continue;
1534 *dst_ptr++ = wch;
1535 dstlen--;
1536 }
1537 }
1538
1539 if (srclen)
1540 {
1541 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1542 return 0;
1543 }
1544
1545 return dst_ptr - dst;
1546 }
1547
1548 /*************************************************************************
1549 * LCMapStringW (KERNEL32.@)
1550 *
1551 * See LCMapStringA.
1552 */
1553 INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen,
1554 LPWSTR dst, INT dstlen)
1555 {
1556 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
1557 lcid, flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1558
1559 return LCMapStringEx(NULL, flags, src, srclen, dst, dstlen, NULL, NULL, 0);
1560 }
1561
1562 /*************************************************************************
1563 * LCMapStringA (KERNEL32.@)
1564 *
1565 * Map characters in a locale sensitive string.
1566 *
1567 * PARAMS
1568 * lcid [I] LCID for the conversion.
1569 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h").
1570 * src [I] String to map
1571 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
1572 * dst [O] Destination for mapped string
1573 * dstlen [I] Length of dst in characters
1574 *
1575 * RETURNS
1576 * Success: The length of the mapped string in dst, including the NUL terminator.
1577 * Failure: 0. Use GetLastError() to determine the cause.
1578 */
1579 INT WINAPI LCMapStringA(LCID lcid, DWORD flags, LPCSTR src, INT srclen,
1580 LPSTR dst, INT dstlen)
1581 {
1582 WCHAR *bufW = NtCurrentTeb()->StaticUnicodeBuffer;
1583 LPWSTR srcW, dstW;
1584 INT ret = 0, srclenW, dstlenW;
1585 UINT locale_cp = CP_ACP;
1586
1587 if (!src || !srclen || dstlen < 0)
1588 {
1589 SetLastError(ERROR_INVALID_PARAMETER);
1590 return 0;
1591 }
1592
1593 if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
1594
1595 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, bufW, 260);
1596 if (srclenW)
1597 srcW = bufW;
1598 else
1599 {
1600 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, NULL, 0);
1601 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
1602 if (!srcW)
1603 {
1604 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1605 return 0;
1606 }
1607 MultiByteToWideChar(locale_cp, 0, src, srclen, srcW, srclenW);
1608 }
1609
1610 if (flags & LCMAP_SORTKEY)
1611 {
1612 if (src == dst)
1613 {
1614 SetLastError(ERROR_INVALID_FLAGS);
1615 goto map_string_exit;
1616 }
1617 ret = wine_get_sortkey(flags, srcW, srclenW, dst, dstlen);
1618 if (ret == 0)
1619 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1620 else
1621 ret++;
1622 goto map_string_exit;
1623 }
1624
1625 if (flags & SORT_STRINGSORT)
1626 {
1627 SetLastError(ERROR_INVALID_FLAGS);
1628 goto map_string_exit;
1629 }
1630
1631 dstlenW = LCMapStringEx(NULL, flags, srcW, srclenW, NULL, 0, NULL, NULL, 0);
1632 if (!dstlenW)
1633 goto map_string_exit;
1634
1635 dstW = HeapAlloc(GetProcessHeap(), 0, dstlenW * sizeof(WCHAR));
1636 if (!dstW)
1637 {
1638 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1639 goto map_string_exit;
1640 }
1641
1642 LCMapStringEx(NULL, flags, srcW, srclenW, dstW, dstlenW, NULL, NULL, 0);
1643 ret = WideCharToMultiByte(locale_cp, 0, dstW, dstlenW, dst, dstlen, NULL, NULL);
1644 HeapFree(GetProcessHeap(), 0, dstW);
1645
1646 map_string_exit:
1647 if (srcW != bufW) HeapFree(GetProcessHeap(), 0, srcW);
1648 return ret;
1649 }
1650
1651 /*************************************************************************
1652 * FoldStringA (KERNEL32.@)
1653 *
1654 * Map characters in a string.
1655 *
1656 * PARAMS
1657 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
1658 * src [I] String to map
1659 * srclen [I] Length of src, or -1 if src is NUL terminated
1660 * dst [O] Destination for mapped string
1661 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
1662 *
1663 * RETURNS
1664 * Success: The length of the string written to dst, including the terminating NUL. If
1665 * dstlen is 0, the value returned is the same, but nothing is written to dst,
1666 * and dst may be NULL.
1667 * Failure: 0. Use GetLastError() to determine the cause.
1668 */
1669 INT WINAPI FoldStringA(DWORD dwFlags, LPCSTR src, INT srclen,
1670 LPSTR dst, INT dstlen)
1671 {
1672 INT ret = 0, srclenW = 0;
1673 WCHAR *srcW = NULL, *dstW = NULL;
1674
1675 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
1676 {
1677 SetLastError(ERROR_INVALID_PARAMETER);
1678 return 0;
1679 }
1680
1681 srclenW = MultiByteToWideChar(CP_ACP, dwFlags & MAP_COMPOSITE ? MB_COMPOSITE : 0,
1682 src, srclen, NULL, 0);
1683 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
1684
1685 if (!srcW)
1686 {
1687 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1688 goto FoldStringA_exit;
1689 }
1690
1691 MultiByteToWideChar(CP_ACP, dwFlags & MAP_COMPOSITE ? MB_COMPOSITE : 0,
1692 src, srclen, srcW, srclenW);
1693
1694 dwFlags = (dwFlags & ~MAP_PRECOMPOSED) | MAP_FOLDCZONE;
1695
1696 ret = FoldStringW(dwFlags, srcW, srclenW, NULL, 0);
1697 if (ret && dstlen)
1698 {
1699 dstW = HeapAlloc(GetProcessHeap(), 0, ret * sizeof(WCHAR));
1700
1701 if (!dstW)
1702 {
1703 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1704 goto FoldStringA_exit;
1705 }
1706
1707 ret = FoldStringW(dwFlags, srcW, srclenW, dstW, ret);
1708 if (!WideCharToMultiByte(CP_ACP, 0, dstW, ret, dst, dstlen, NULL, NULL))
1709 {
1710 ret = 0;
1711 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1712 }
1713 }
1714
1715 HeapFree(GetProcessHeap(), 0, dstW);
1716
1717 FoldStringA_exit:
1718 HeapFree(GetProcessHeap(), 0, srcW);
1719 return ret;
1720 }
1721
1722 /*************************************************************************
1723 * FoldStringW (KERNEL32.@)
1724 *
1725 * See FoldStringA.
1726 */
1727 INT WINAPI FoldStringW(DWORD dwFlags, LPCWSTR src, INT srclen,
1728 LPWSTR dst, INT dstlen)
1729 {
1730 int ret;
1731
1732 switch (dwFlags & (MAP_COMPOSITE|MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES))
1733 {
1734 case 0:
1735 if (dwFlags)
1736 break;
1737 /* Fall through for dwFlags == 0 */
1738 case MAP_PRECOMPOSED|MAP_COMPOSITE:
1739 case MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES:
1740 case MAP_COMPOSITE|MAP_EXPAND_LIGATURES:
1741 SetLastError(ERROR_INVALID_FLAGS);
1742 return 0;
1743 }
1744
1745 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
1746 {
1747 SetLastError(ERROR_INVALID_PARAMETER);
1748 return 0;
1749 }
1750
1751 ret = wine_fold_string(dwFlags, src, srclen, dst, dstlen);
1752 if (!ret)
1753 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1754 return ret;
1755 }
1756
1757 /******************************************************************************
1758 * CompareStringW (KERNEL32.@)
1759 *
1760 * See CompareStringA.
1761 */
1762 INT WINAPI CompareStringW(LCID lcid, DWORD flags,
1763 LPCWSTR str1, INT len1, LPCWSTR str2, INT len2)
1764 {
1765 static const DWORD supported_flags = NORM_IGNORECASE|NORM_IGNORENONSPACE|NORM_IGNORESYMBOLS|SORT_STRINGSORT
1766 |NORM_IGNOREKANATYPE|NORM_IGNOREWIDTH|LOCALE_USE_CP_ACP
1767 |NORM_LINGUISTIC_CASING|LINGUISTIC_IGNORECASE|0x10000000;
1768 static DWORD semistub_flags = NORM_LINGUISTIC_CASING|LINGUISTIC_IGNORECASE|0x10000000;
1769 /* 0x10000000 is related to diacritics in Arabic, Japanese, and Hebrew */
1770 INT ret;
1771
1772
1773 if (!str1 || !str2)
1774 {
1775 SetLastError(ERROR_INVALID_PARAMETER);
1776 return 0;
1777 }
1778
1779 if (flags & ~supported_flags)
1780 {
1781 SetLastError(ERROR_INVALID_FLAGS);
1782 return 0;
1783 }
1784
1785 if (flags & semistub_flags)
1786 {
1787 FIXME("semi-stub behavior for flag(s) 0x%x\n", flags & semistub_flags);
1788 semistub_flags &= ~flags;
1789 }
1790
1791 if (len1 < 0) len1 = strlenW(str1);
1792 if (len2 < 0) len2 = strlenW(str2);
1793
1794 ret = wine_compare_string(flags, str1, len1, str2, len2);
1795
1796 if (ret) /* need to translate result */
1797 return (ret < 0) ? CSTR_LESS_THAN : CSTR_GREATER_THAN;
1798 return CSTR_EQUAL;
1799 }
1800
1801 /******************************************************************************
1802 * CompareStringA (KERNEL32.@)
1803 *
1804 * Compare two locale sensitive strings.
1805 *
1806 * PARAMS
1807 * lcid [I] LCID for the comparison
1808 * flags [I] Flags for the comparison (NORM_ constants from "winnls.h").
1809 * str1 [I] First string to compare
1810 * len1 [I] Length of str1, or -1 if str1 is NUL terminated
1811 * str2 [I] Second string to compare
1812 * len2 [I] Length of str2, or -1 if str2 is NUL terminated
1813 *
1814 * RETURNS
1815 * Success: CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN depending on whether
1816 * str1 is less than, equal to or greater than str2 respectively.
1817 * Failure: FALSE. Use GetLastError() to determine the cause.
1818 */
1819 INT WINAPI CompareStringA(LCID lcid, DWORD flags,
1820 LPCSTR str1, INT len1, LPCSTR str2, INT len2)
1821 {
1822 WCHAR *buf1W = NtCurrentTeb()->StaticUnicodeBuffer;
1823 WCHAR *buf2W = buf1W + 130;
1824 LPWSTR str1W, str2W;
1825 INT len1W = 0, len2W = 0, ret;
1826 UINT locale_cp = CP_ACP;
1827
1828 if (!str1 || !str2)
1829 {
1830 SetLastError(ERROR_INVALID_PARAMETER);
1831 return 0;
1832 }
1833 if (len1 < 0) len1 = strlen(str1);
1834 if (len2 < 0) len2 = strlen(str2);
1835
1836 if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
1837
1838 if (len1)
1839 {
1840 if (len1 <= 130) len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
1841 if (len1W)
1842 str1W = buf1W;
1843 else
1844 {
1845 len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, NULL, 0);
1846 str1W = HeapAlloc(GetProcessHeap(), 0, len1W * sizeof(WCHAR));
1847 if (!str1W)
1848 {
1849 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1850 return 0;
1851 }
1852 MultiByteToWideChar(locale_cp, 0, str1, len1, str1W, len1W);
1853 }
1854 }
1855 else
1856 {
1857 len1W = 0;
1858 str1W = buf1W;
1859 }
1860
1861 if (len2)
1862 {
1863 if (len2 <= 130) len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
1864 if (len2W)
1865 str2W = buf2W;
1866 else
1867 {
1868 len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, NULL, 0);
1869 str2W = HeapAlloc(GetProcessHeap(), 0, len2W * sizeof(WCHAR));
1870 if (!str2W)
1871 {
1872 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
1873 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1874 return 0;
1875 }
1876 MultiByteToWideChar(locale_cp, 0, str2, len2, str2W, len2W);
1877 }
1878 }
1879 else
1880 {
1881 len2W = 0;
1882 str2W = buf2W;
1883 }
1884
1885 ret = CompareStringW(lcid, flags, str1W, len1W, str2W, len2W);
1886
1887 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
1888 if (str2W != buf2W) HeapFree(GetProcessHeap(), 0, str2W);
1889 return ret;
1890 }
1891
1892 static HANDLE NLS_RegOpenKey(HANDLE hRootKey, LPCWSTR szKeyName)
1893 {
1894 UNICODE_STRING keyName;
1895 OBJECT_ATTRIBUTES attr;
1896 HANDLE hkey;
1897
1898 RtlInitUnicodeString( &keyName, szKeyName );
1899 InitializeObjectAttributes(&attr, &keyName, OBJ_CASE_INSENSITIVE, hRootKey, NULL);
1900
1901 if (NtOpenKey( &hkey, KEY_READ, &attr ) != STATUS_SUCCESS)
1902 hkey = 0;
1903
1904 return hkey;
1905 }
1906
1907 static BOOL NLS_RegEnumValue(HANDLE hKey, UINT ulIndex,
1908 LPWSTR szValueName, ULONG valueNameSize,
1909 LPWSTR szValueData, ULONG valueDataSize)
1910 {
1911 BYTE buffer[80];
1912 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
1913 DWORD dwLen;
1914
1915 if (NtEnumerateValueKey( hKey, ulIndex, KeyValueFullInformation,
1916 buffer, sizeof(buffer), &dwLen ) != STATUS_SUCCESS ||
1917 info->NameLength > valueNameSize ||
1918 info->DataLength > valueDataSize)
1919 {
1920 return FALSE;
1921 }
1922
1923 TRACE("info->Name %s info->DataLength %d\n", debugstr_w(info->Name), info->DataLength);
1924
1925 memcpy( szValueName, info->Name, info->NameLength);
1926 szValueName[info->NameLength / sizeof(WCHAR)] = '\0';
1927 memcpy( szValueData, buffer + info->DataOffset, info->DataLength );
1928 szValueData[info->DataLength / sizeof(WCHAR)] = '\0';
1929
1930 TRACE("returning %s %s\n", debugstr_w(szValueName), debugstr_w(szValueData));
1931 return TRUE;
1932 }
1933
1934 static BOOL NLS_RegGetDword(HANDLE hKey, LPCWSTR szValueName, DWORD *lpVal)
1935 {
1936 BYTE buffer[128];
1937 const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
1938 DWORD dwSize = sizeof(buffer);
1939 UNICODE_STRING valueName;
1940
1941 RtlInitUnicodeString( &valueName, szValueName );
1942
1943 TRACE("%p, %s\n", hKey, debugstr_w(szValueName));
1944 if (NtQueryValueKey( hKey, &valueName, KeyValuePartialInformation,
1945 buffer, dwSize, &dwSize ) == STATUS_SUCCESS &&
1946 info->DataLength == sizeof(DWORD))
1947 {
1948 memcpy(lpVal, info->Data, sizeof(DWORD));
1949 return TRUE;
1950 }
1951
1952 return FALSE;
1953 }
1954
1955 static BOOL NLS_GetLanguageGroupName(LGRPID lgrpid, LPWSTR szName, ULONG nameSize)
1956 {
1957 LANGID langId;
1958 LPCWSTR szResourceName = MAKEINTRESOURCEW(((lgrpid + 0x2000) >> 4) + 1);
1959 HRSRC hResource;
1960 BOOL bRet = FALSE;
1961
1962 /* FIXME: Is it correct to use the system default langid? */
1963 langId = GetSystemDefaultLangID();
1964
1965 if (SUBLANGID(langId) == SUBLANG_NEUTRAL)
1966 langId = MAKELANGID( PRIMARYLANGID(langId), SUBLANG_DEFAULT );
1967
1968 hResource = FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING, szResourceName, langId );
1969
1970 if (hResource)
1971 {
1972 HGLOBAL hResDir = LoadResource( kernel32_handle, hResource );
1973
1974 if (hResDir)
1975 {
1976 ULONG iResourceIndex = lgrpid & 0xf;
1977 LPCWSTR lpResEntry = LockResource( hResDir );
1978 ULONG i;
1979
1980 for (i = 0; i < iResourceIndex; i++)
1981 lpResEntry += *lpResEntry + 1;
1982
1983 if (*lpResEntry < nameSize)
1984 {
1985 memcpy( szName, lpResEntry + 1, *lpResEntry * sizeof(WCHAR) );
1986 szName[*lpResEntry] = '\0';
1987 bRet = TRUE;
1988 }
1989
1990 }
1991 FreeResource( hResource );
1992 }
1993 return bRet;
1994 }
1995
1996 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
1997 typedef struct
1998 {
1999 LANGUAGEGROUP_ENUMPROCA procA;
2000 LANGUAGEGROUP_ENUMPROCW procW;
2001 DWORD dwFlags;
2002 LONG_PTR lParam;
2003 } ENUMLANGUAGEGROUP_CALLBACKS;
2004
2005 /* Internal implementation of EnumSystemLanguageGroupsA/W */
2006 static BOOL NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS *lpProcs)
2007 {
2008 WCHAR szNumber[10], szValue[4];
2009 HANDLE hKey;
2010 BOOL bContinue = TRUE;
2011 ULONG ulIndex = 0;
2012
2013 if (!lpProcs)
2014 {
2015 SetLastError(ERROR_INVALID_PARAMETER);
2016 return FALSE;
2017 }
2018
2019 switch (lpProcs->dwFlags)
2020 {
2021 case 0:
2022 /* Default to LGRPID_INSTALLED */
2023 lpProcs->dwFlags = LGRPID_INSTALLED;
2024 /* Fall through... */
2025 case LGRPID_INSTALLED:
2026 case LGRPID_SUPPORTED:
2027 break;
2028 default:
2029 SetLastError(ERROR_INVALID_FLAGS);
2030 return FALSE;
2031 }
2032
2033 hKey = NLS_RegOpenKey( 0, szLangGroupsKeyName );
2034
2035 if (!hKey)
2036 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2037
2038 while (bContinue)
2039 {
2040 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
2041 szValue, sizeof(szValue) ))
2042 {
2043 BOOL bInstalled = szValue[0] == '1' ? TRUE : FALSE;
2044 LGRPID lgrpid = strtoulW( szNumber, NULL, 16 );
2045
2046 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber),
2047 bInstalled ? "" : "not ");
2048
2049 if (lpProcs->dwFlags == LGRPID_SUPPORTED || bInstalled)
2050 {
2051 WCHAR szGrpName[48];
2052
2053 if (!NLS_GetLanguageGroupName( lgrpid, szGrpName, sizeof(szGrpName) / sizeof(WCHAR) ))
2054 szGrpName[0] = '\0';
2055
2056 if (lpProcs->procW)
2057 bContinue = lpProcs->procW( lgrpid, szNumber, szGrpName, lpProcs->dwFlags,
2058 lpProcs->lParam );
2059 else
2060 {
2061 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
2062 char szGrpNameA[48];
2063
2064 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
2065 * or whether the language names are ever localised. Assume CP_ACP.
2066 */
2067
2068 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
2069 WideCharToMultiByte(CP_ACP, 0, szGrpName, -1, szGrpNameA, sizeof(szGrpNameA), 0, 0);
2070
2071 bContinue = lpProcs->procA( lgrpid, szNumberA, szGrpNameA, lpProcs->dwFlags,
2072 lpProcs->lParam );
2073 }
2074 }
2075
2076 ulIndex++;
2077 }
2078 else
2079 bContinue = FALSE;
2080
2081 if (!bContinue)
2082 break;
2083 }
2084
2085 if (hKey)
2086 NtClose( hKey );
2087
2088 return TRUE;
2089 }
2090
2091 /******************************************************************************
2092 * EnumSystemLanguageGroupsA (KERNEL32.@)
2093 *
2094 * Call a users function for each language group available on the system.
2095 *
2096 * PARAMS
2097 * pLangGrpEnumProc [I] Callback function to call for each language group
2098 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
2099 * lParam [I] User parameter to pass to pLangGrpEnumProc
2100 *
2101 * RETURNS
2102 * Success: TRUE.
2103 * Failure: FALSE. Use GetLastError() to determine the cause.
2104 */
2105 BOOL WINAPI EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc,
2106 DWORD dwFlags, LONG_PTR lParam)
2107 {
2108 ENUMLANGUAGEGROUP_CALLBACKS procs;
2109
2110 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
2111
2112 procs.procA = pLangGrpEnumProc;
2113 procs.procW = NULL;
2114 procs.dwFlags = dwFlags;
2115 procs.lParam = lParam;
2116
2117 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
2118 }
2119
2120 /******************************************************************************
2121 * EnumSystemLanguageGroupsW (KERNEL32.@)
2122 *
2123 * See EnumSystemLanguageGroupsA.
2124 */
2125 BOOL WINAPI EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc,
2126 DWORD dwFlags, LONG_PTR lParam)
2127 {
2128 ENUMLANGUAGEGROUP_CALLBACKS procs;
2129
2130 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
2131
2132 procs.procA = NULL;
2133 procs.procW = pLangGrpEnumProc;
2134 procs.dwFlags = dwFlags;
2135 procs.lParam = lParam;
2136
2137 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
2138 }
2139
2140 /******************************************************************************
2141 * IsValidLanguageGroup (KERNEL32.@)
2142 *
2143 * Determine if a language group is supported and/or installed.
2144 *
2145 * PARAMS
2146 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
2147 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
2148 *
2149 * RETURNS
2150 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
2151 * FALSE otherwise.
2152 */
2153 BOOL WINAPI IsValidLanguageGroup(LGRPID lgrpid, DWORD dwFlags)
2154 {
2155 static const WCHAR szFormat[] = { '%','x','\0' };
2156 WCHAR szValueName[16], szValue[2];
2157 BOOL bSupported = FALSE, bInstalled = FALSE;
2158 HANDLE hKey;
2159
2160
2161 switch (dwFlags)
2162 {
2163 case LGRPID_INSTALLED:
2164 case LGRPID_SUPPORTED:
2165
2166 hKey = NLS_RegOpenKey( 0, szLangGroupsKeyName );
2167
2168 sprintfW( szValueName, szFormat, lgrpid );
2169
2170 if (NLS_RegGetDword( hKey, szValueName, (LPDWORD)szValue ))
2171 {
2172 bSupported = TRUE;
2173
2174 if (szValue[0] == '1')
2175 bInstalled = TRUE;
2176 }
2177
2178 if (hKey)
2179 NtClose( hKey );
2180
2181 break;
2182 }
2183
2184 if ((dwFlags == LGRPID_SUPPORTED && bSupported) ||
2185 (dwFlags == LGRPID_INSTALLED && bInstalled))
2186 return TRUE;
2187
2188 return FALSE;
2189 }
2190
2191 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
2192 typedef struct
2193 {
2194 LANGGROUPLOCALE_ENUMPROCA procA;
2195 LANGGROUPLOCALE_ENUMPROCW procW;
2196 DWORD dwFlags;
2197 LGRPID lgrpid;
2198 LONG_PTR lParam;
2199 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS;
2200
2201 /* Internal implementation of EnumLanguageGrouplocalesA/W */
2202 static BOOL NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS *lpProcs)
2203 {
2204 static const WCHAR szAlternateSortsKeyName[] = {
2205 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
2206 };
2207 WCHAR szNumber[10], szValue[4];
2208 HANDLE hKey;
2209 BOOL bContinue = TRUE, bAlternate = FALSE;
2210 LGRPID lgrpid;
2211 ULONG ulIndex = 1; /* Ignore default entry of 1st key */
2212
2213 if (!lpProcs || !lpProcs->lgrpid || lpProcs->lgrpid > LGRPID_ARMENIAN)
2214 {
2215 SetLastError(ERROR_INVALID_PARAMETER);
2216 return FALSE;
2217 }
2218
2219 if (lpProcs->dwFlags)
2220 {
2221 SetLastError(ERROR_INVALID_FLAGS);
2222 return FALSE;
2223 }
2224
2225 hKey = NLS_RegOpenKey( 0, szLocaleKeyName );
2226
2227 if (!hKey)
2228 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2229
2230 while (bContinue)
2231 {
2232 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
2233 szValue, sizeof(szValue) ))
2234 {
2235 lgrpid = strtoulW( szValue, NULL, 16 );
2236
2237 TRACE("lcid %s, grpid %d (%smatched)\n", debugstr_w(szNumber),
2238 lgrpid, lgrpid == lpProcs->lgrpid ? "" : "not ");
2239
2240 if (lgrpid == lpProcs->lgrpid)
2241 {
2242 LCID lcid;
2243
2244 lcid = strtoulW( szNumber, NULL, 16 );
2245
2246 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
2247 * '00000437 ;Georgian'
2248 * At present we only pass the LCID string.
2249 */
2250
2251 if (lpProcs->procW)
2252 bContinue = lpProcs->procW( lgrpid, lcid, szNumber, lpProcs->lParam );
2253 else
2254 {
2255 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
2256
2257 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
2258
2259 bContinue = lpProcs->procA( lgrpid, lcid, szNumberA, lpProcs->lParam );
2260 }
2261 }
2262
2263 ulIndex++;
2264 }
2265 else
2266 {
2267 /* Finished enumerating this key */
2268 if (!bAlternate)
2269 {
2270 /* Enumerate alternate sorts also */
2271 hKey = NLS_RegOpenKey( hKey, szAlternateSortsKeyName );
2272 bAlternate = TRUE;
2273 ulIndex = 0;
2274 }
2275 else
2276 bContinue = FALSE; /* Finished both keys */
2277 }
2278
2279 if (!bContinue)
2280 break;
2281 }
2282
2283 if (hKey)
2284 NtClose( hKey );
2285
2286 return TRUE;
2287 }
2288
2289 enum locationkind {
2290 LOCATION_NATION = 0,
2291 LOCATION_REGION,
2292 LOCATION_BOTH
2293 };
2294
2295 struct geoinfo_t {
2296 GEOID id;
2297 WCHAR iso2W[3];
2298 WCHAR iso3W[4];
2299 GEOID parent;
2300 INT uncode;
2301 enum locationkind kind;
2302 };
2303
2304 static const struct geoinfo_t geoinfodata[] = {
2305 { 2, {'A','G',0}, {'A','T','G',0}, 10039880, 28 }, /* Antigua and Barbuda */
2306 { 3, {'A','F',0}, {'A','F','G',0}, 47614, 4 }, /* Afghanistan */
2307 { 4, {'D','Z',0}, {'D','Z','A',0}, 42487, 12 }, /* Algeria */
2308 { 5, {'A','Z',0}, {'A','Z','E',0}, 47611, 31 }, /* Azerbaijan */
2309 { 6, {'A','L',0}, {'A','L','B',0}, 47610, 8 }, /* Albania */
2310 { 7, {'A','M',0}, {'A','R','M',0}, 47611, 51 }, /* Armenia */
2311 { 8, {'A','D',0}, {'A','N','D',0}, 47610, 20 }, /* Andorra */
2312 { 9, {'A','O',0}, {'A','G','O',0}, 42484, 24 }, /* Angola */
2313 { 10, {'A','S',0}, {'A','S','M',0}, 26286, 16 }, /* American Samoa */
2314 { 11, {'A','R',0}, {'A','R','G',0}, 31396, 32 }, /* Argentina */
2315 { 12, {'A','U',0}, {'A','U','S',0}, 10210825, 36 }, /* Australia */
2316 { 14, {'A','T',0}, {'A','U','T',0}, 10210824, 40 }, /* Austria */
2317 { 17, {'B','H',0}, {'B','H','R',0}, 47611, 48 }, /* Bahrain */
2318 { 18, {'B','B',0}, {'B','R','B',0}, 10039880, 52 }, /* Barbados */
2319 { 19, {'B','W',0}, {'B','W','A',0}, 10039883, 72 }, /* Botswana */
2320 { 20, {'B','M',0}, {'B','M','U',0}, 23581, 60 }, /* Bermuda */
2321 { 21, {'B','E',0}, {'B','E','L',0}, 10210824, 56 }, /* Belgium */
2322 { 22, {'B','S',0}, {'B','H','S',0}, 10039880, 44 }, /* Bahamas, The */
2323 { 23, {'B','D',0}, {'B','G','D',0}, 47614, 50 }, /* Bangladesh */
2324 { 24, {'B','Z',0}, {'B','L','Z',0}, 27082, 84 }, /* Belize */
2325 { 25, {'B','A',0}, {'B','I','H',0}, 47610, 70 }, /* Bosnia and Herzegovina */
2326 { 26, {'B','O',0}, {'B','O','L',0}, 31396, 68 }, /* Bolivia */
2327 { 27, {'M','M',0}, {'M','M','R',0}, 47599, 104 }, /* Myanmar */
2328 { 28, {'B','J',0}, {'B','E','N',0}, 42483, 204 }, /* Benin */
2329 { 29, {'B','Y',0}, {'B','L','R',0}, 47609, 112 }, /* Belarus */
2330 { 30, {'S','B',0}, {'S','L','B',0}, 20900, 90 }, /* Solomon Islands */
2331 { 32, {'B','R',0}, {'B','R','A',0}, 31396, 76 }, /* Brazil */
2332 { 34, {'B','T',0}, {'B','T','N',0}, 47614, 64 }, /* Bhutan */
2333 { 35, {'B','G',0}, {'B','G','R',0}, 47609, 100 }, /* Bulgaria */
2334 { 37, {'B','N',0}, {'B','R','N',0}, 47599, 96 }, /* Brunei */
2335 { 38, {'B','I',0}, {'B','D','I',0}, 47603, 108 }, /* Burundi */
2336 { 39, {'C','A',0}, {'C','A','N',0}, 23581, 124 }, /* Canada */
2337 { 40, {'K','H',0}, {'K','H','M',0}, 47599, 116 }, /* Cambodia */
2338 { 41, {'T','D',0}, {'T','C','D',0}, 42484, 148 }, /* Chad */
2339 { 42, {'L','K',0}, {'L','K','A',0}, 47614, 144 }, /* Sri Lanka */
2340 { 43, {'C','G',0}, {'C','O','G',0}, 42484, 178 }, /* Congo */
2341 { 44, {'C','D',0}, {'C','O','D',0}, 42484, 180 }, /* Congo (DRC) */
2342 { 45, {'C','N',0}, {'C','H','N',0}, 47600, 156 }, /* China */
2343 { 46, {'C','L',0}, {'C','H','L',0}, 31396, 152 }, /* Chile */
2344 { 49, {'C','M',0}, {'C','M','R',0}, 42484, 120 }, /* Cameroon */
2345 { 50, {'K','M',0}, {'C','O','M',0}, 47603, 174 }, /* Comoros */
2346 { 51, {'C','O',0}, {'C','O','L',0}, 31396, 170 }, /* Colombia */
2347 { 54, {'C','R',0}, {'C','R','I',0}, 27082, 188 }, /* Costa Rica */
2348 { 55, {'C','F',0}, {'C','A','F',0}, 42484, 140 }, /* Central African Republic */
2349 { 56, {'C','U',0}, {'C','U','B',0}, 10039880, 192 }, /* Cuba */
2350 { 57, {'C','V',0}, {'C','P','V',0}, 42483, 132 }, /* Cape Verde */
2351 { 59, {'C','Y',0}, {'C','Y','P',0}, 47611, 196 }, /* Cyprus */
2352 { 61, {'D','K',0}, {'D','N','K',0}, 10039882, 208 }, /* Denmark */
2353 { 62, {'D','J',0}, {'D','J','I',0}, 47603, 262 }, /* Djibouti */
2354 { 63, {'D','M',0}, {'D','M','A',0}, 10039880, 212 }, /* Dominica */
2355 { 65, {'D','O',0}, {'D','O','M',0}, 10039880, 214 }, /* Dominican Republic */
2356 { 66, {'E','C',0}, {'E','C','U',0}, 31396, 218 }, /* Ecuador */
2357 { 67, {'E','G',0}, {'E','G','Y',0}, 42487, 818 }, /* Egypt */
2358 { 68, {'I','E',0}, {'I','R','L',0}, 10039882, 372 }, /* Ireland */
2359 { 69, {'G','Q',0}, {'G','N','Q',0}, 42484, 226 }, /* Equatorial Guinea */
2360 { 70, {'E','E',0}, {'E','S','T',0}, 10039882, 233 }, /* Estonia */
2361 { 71, {'E','R',0}, {'E','R','I',0}, 47603, 232 }, /* Eritrea */
2362 { 72, {'S','V',0}, {'S','L','V',0}, 27082, 222 }, /* El Salvador */
2363 { 73, {'E','T',0}, {'E','T','H',0}, 47603, 231 }, /* Ethiopia */
2364 { 75, {'C','Z',0}, {'C','Z','E',0}, 47609, 203 }, /* Czech Republic */
2365 { 77, {'F','I',0}, {'F','I','N',0}, 10039882, 246 }, /* Finland */
2366 { 78, {'F','J',0}, {'F','J','I',0}, 20900, 242 }, /* Fiji Islands */
2367 { 80, {'F','M',0}, {'F','S','M',0}, 21206, 583 }, /* Micronesia */
2368 { 81, {'F','O',0}, {'F','R','O',0}, 10039882, 234 }, /* Faroe Islands */
2369 { 84, {'F','R',0}, {'F','R','A',0}, 10210824, 250 }, /* France */
2370 { 86, {'G','M',0}, {'G','M','B',0}, 42483, 270 }, /* Gambia, The */
2371 { 87, {'G','A',0}, {'G','A','B',0}, 42484, 266 }, /* Gabon */
2372 { 88, {'G','E',0}, {'G','E','O',0}, 47611, 268 }, /* Georgia */
2373 { 89, {'G','H',0}, {'G','H','A',0}, 42483, 288 }, /* Ghana */
2374 { 90, {'G','I',0}, {'G','I','B',0}, 47610, 292 }, /* Gibraltar */
2375 { 91, {'G','D',0}, {'G','R','D',0}, 10039880, 308 }, /* Grenada */
2376 { 93, {'G','L',0}, {'G','R','L',0}, 23581, 304 }, /* Greenland */
2377 { 94, {'D','E',0}, {'D','E','U',0}, 10210824, 276 }, /* Germany */
2378 { 98, {'G','R',0}, {'G','R','C',0}, 47610, 300 }, /* Greece */
2379 { 99, {'G','T',0}, {'G','T','M',0}, 27082, 320 }, /* Guatemala */
2380 { 100, {'G','N',0}, {'G','I','N',0}, 42483, 324 }, /* Guinea */
2381 { 101, {'G','Y',0}, {'G','U','Y',0}, 31396, 328 }, /* Guyana */
2382 { 103, {'H','T',0}, {'H','T','I',0}, 10039880, 332 }, /* Haiti */
2383 { 104, {'H','K',0}, {'H','K','G',0}, 47600, 344 }, /* Hong Kong S.A.R. */
2384 { 106, {'H','N',0}, {'H','N','D',0}, 27082, 340 }, /* Honduras */
2385 { 108, {'H','R',0}, {'H','R','V',0}, 47610, 191 }, /* Croatia */
2386 { 109, {'H','U',0}, {'H','U','N',0}, 47609, 348 }, /* Hungary */
2387 { 110, {'I','S',0}, {'I','S','L',0}, 10039882, 352 }, /* Iceland */
2388 { 111, {'I','D',0}, {'I','D','N',0}, 47599, 360 }, /* Indonesia */
2389 { 113, {'I','N',0}, {'I','N','D',0}, 47614, 356 }, /* India */
2390 { 114, {'I','O',0}, {'I','O','T',0}, 39070, 86 }, /* British Indian Ocean Territory */
2391 { 116, {'I','R',0}, {'I','R','N',0}, 47614, 364 }, /* Iran */
2392 { 117, {'I','L',0}, {'I','S','R',0}, 47611, 376 }, /* Israel */
2393 { 118, {'I','T',0}, {'I','T','A',0}, 47610, 380 }, /* Italy */
2394 { 119, {'C','I',0}, {'C','I','V',0}, 42483, 384 }, /* Côte d'Ivoire */
2395 { 121, {'I','Q',0}, {'I','R','Q',0}, 47611, 368 }, /* Iraq */
2396 { 122, {'J','P',0}, {'J','P','N',0}, 47600, 392 }, /* Japan */
2397 { 124, {'J','M',0}, {'J','A','M',0}, 10039880, 388 }, /* Jamaica */
2398 { 125, {'S','J',0}, {'S','J','M',0}, 10039882, 744 }, /* Jan Mayen */
2399 { 126, {'J','O',0}, {'J','O','R',0}, 47611, 400 }, /* Jordan */
2400 { 127, {'X','X',0}, {'X','X',0}, 161832256 }, /* Johnston Atoll */
2401 { 129, {'K','E',0}, {'K','E','N',0}, 47603, 404 }, /* Kenya */
2402 { 130, {'K','G',0}, {'K','G','Z',0}, 47590, 417 }, /* Kyrgyzstan */
2403 { 131, {'K','P',0}, {'P','R','K',0}, 47600, 408 }, /* North Korea */
2404 { 133, {'K','I',0}, {'K','I','R',0}, 21206, 296 }, /* Kiribati */
2405 { 134, {'K','R',0}, {'K','O','R',0}, 47600, 410 }, /* Korea */
2406 { 136, {'K','W',0}, {'K','W','T',0}, 47611, 414 }, /* Kuwait */
2407 { 137, {'K','Z',0}, {'K','A','Z',0}, 47590, 398 }, /* Kazakhstan */
2408 { 138, {'L','A',0}, {'L','A','O',0}, 47599, 418 }, /* Laos */
2409 { 139, {'L','B',0}, {'L','B','N',0}, 47611, 422 }, /* Lebanon */
2410 { 140, {'L','V',0}, {'L','V','A',0}, 10039882, 428 }, /* Latvia */
2411 { 141, {'L','T',0}, {'L','T','U',0}, 10039882, 440 }, /* Lithuania */
2412 { 142, {'L','R',0}, {'L','B','R',0}, 42483, 430 }, /* Liberia */
2413 { 143, {'S','K',0}, {'S','V','K',0}, 47609, 703 }, /* Slovakia */
2414 { 145, {'L','I',0}, {'L','I','E',0}, 10210824, 438 }, /* Liechtenstein */
2415 { 146, {'L','S',0}, {'L','S','O',0}, 10039883, 426 }, /* Lesotho */
2416 { 147, {'L','U',0}, {'L','U','X',0}, 10210824, 442 }, /* Luxembourg */
2417 { 148, {'L','Y',0}, {'L','B','Y',0}, 42487, 434 }, /* Libya */
2418 { 149, {'M','G',0}, {'M','D','G',0}, 47603, 450 }, /* Madagascar */
2419 { 151, {'M','O',0}, {'M','A','C',0}, 47600, 446 }, /* Macao S.A.R. */
2420 { 152, {'M','D',0}, {'M','D','A',0}, 47609, 498 }, /* Moldova */
2421 { 154, {'M','N',0}, {'M','N','G',0}, 47600, 496 }, /* Mongolia */
2422 { 156, {'M','W',0}, {'M','W','I',0}, 47603, 454 }, /* Malawi */
2423 { 157, {'M','L',0}, {'M','L','I',0}, 42483, 466 }, /* Mali */
2424 { 158, {'M','C',0}, {'M','C','O',0}, 10210824, 492 }, /* Monaco */
2425 { 159, {'M','A',0}, {'M','A','R',0}, 42487, 504 }, /* Morocco */
2426 { 160, {'M','U',0}, {'M','U','S',0}, 47603, 480 }, /* Mauritius */
2427 { 162, {'M','R',0}, {'M','R','T',0}, 42483, 478 }, /* Mauritania */
2428 { 163, {'M','T',0}, {'M','L','T',0}, 47610, 470 }, /* Malta */
2429 { 164, {'O','M',0}, {'O','M','N',0}, 47611, 512 }, /* Oman */
2430 { 165, {'M','V',0}, {'M','D','V',0}, 47614, 462 }, /* Maldives */
2431 { 166, {'M','X',0}, {'M','E','X',0}, 27082, 484 }, /* Mexico */
2432 { 167, {'M','Y',0}, {'M','Y','S',0}, 47599, 458 }, /* Malaysia */
2433 { 168, {'M','Z',0}, {'M','O','Z',0}, 47603, 508 }, /* Mozambique */
2434 { 173, {'N','E',0}, {'N','E','R',0}, 42483, 562 }, /* Niger */
2435 { 174, {'V','U',0}, {'V','U','T',0}, 20900, 548 }, /* Vanuatu */
2436 { 175, {'N','G',0}, {'N','G','A',0}, 42483, 566 }, /* Nigeria */
2437 { 176, {'N','L',0}, {'N','L','D',0}, 10210824, 528 }, /* Netherlands */
2438 { 177, {'N','O',0}, {'N','O','R',0}, 10039882, 578 }, /* Norway */
2439 { 178, {'N','P',0}, {'N','P','L',0}, 47614, 524 }, /* Nepal */
2440 { 180, {'N','R',0}, {'N','R','U',0}, 21206, 520 }, /* Nauru */
2441 { 181, {'S','R',0}, {'S','U','R',0}, 31396, 740 }, /* Suriname */
2442 { 182, {'N','I',0}, {'N','I','C',0}, 27082, 558 }, /* Nicaragua */
2443 { 183, {'N','Z',0}, {'N','Z','L',0}, 10210825, 554 }, /* New Zealand */
2444 { 184, {'P','S',0}, {'P','S','E',0}, 47611, 275 }, /* Palestinian Authority */
2445 { 185, {'P','Y',0}, {'P','R','Y',0}, 31396, 600 }, /* Paraguay */
2446 { 187, {'P','E',0}, {'P','E','R',0}, 31396, 604 }, /* Peru */
2447 { 190, {'P','K',0}, {'P','A','K',0}, 47614, 586 }, /* Pakistan */
2448 { 191, {'P','L',0}, {'P','O','L',0}, 47609, 616 }, /* Poland */
2449 { 192, {'P','A',0}, {'P','A','N',0}, 27082, 591 }, /* Panama */
2450 { 193, {'P','T',0}, {'P','R','T',0}, 47610, 620 }, /* Portugal */
2451 { 194, {'P','G',0}, {'P','N','G',0}, 20900, 598 }, /* Papua New Guinea */
2452 { 195, {'P','W',0}, {'P','L','W',0}, 21206, 585 }, /* Palau */
2453 { 196, {'G','W',0}, {'G','N','B',0}, 42483, 624 }, /* Guinea-Bissau */
2454 { 197, {'Q','A',0}, {'Q','A','T',0}, 47611, 634 }, /* Qatar */
2455 { 198, {'R','E',0}, {'R','E','U',0}, 47603, 638 }, /* Reunion */
2456 { 199, {'M','H',0}, {'M','H','L',0}, 21206, 584 }, /* Marshall Islands */
2457 { 200, {'R','O',0}, {'R','O','U',0}, 47609, 642 }, /* Romania */
2458 { 201, {'P','H',0}, {'P','H','L',0}, 47599, 608 }, /* Philippines */
2459 { 202, {'P','R',0}, {'P','R','I',0}, 10039880, 630 }, /* Puerto Rico */
2460 { 203, {'R','U',0}, {'R','U','S',0}, 47609, 643 }, /* Russia */
2461 { 204, {'R','W',0}, {'R','W','A',0}, 47603, 646 }, /* Rwanda */
2462 { 205, {'S','A',0}, {'S','A','U',0}, 47611, 682 }, /* Saudi Arabia */
2463 { 206, {'P','M',0}, {'S','P','M',0}, 23581, 666 }, /* St. Pierre and Miquelon */
2464 { 207, {'K','N',0}, {'K','N','A',0}, 10039880, 659 }, /* St. Kitts and Nevis */
2465 { 208, {'S','C',0}, {'S','Y','C',0}, 47603, 690 }, /* Seychelles */
2466 { 209, {'Z','A',0}, {'Z','A','F',0}, 10039883, 710 }, /* South Africa */
2467 { 210, {'S','N',0}, {'S','E','N',0}, 42483, 686 }, /* Senegal */
2468 { 212, {'S','I',0}, {'S','V','N',0}, 47610, 705 }, /* Slovenia */
2469 { 213, {'S','L',0}, {'S','L','E',0}, 42483, 694 }, /* Sierra Leone */
2470 { 214, {'S','M',0}, {'S','M','R',0}, 47610, 674 }, /* San Marino */
2471 { 215, {'S','G',0}, {'S','G','P',0}, 47599, 702 }, /* Singapore */
2472 { 216, {'S','O',0}, {'S','O','M',0}, 47603, 706 }, /* Somalia */
2473 { 217, {'E','S',0}, {'E','S','P',0}, 47610, 724 }, /* Spain */
2474 { 218, {'L','C',0}, {'L','C','A',0}, 10039880, 662 }, /* St. Lucia */
2475 { 219, {'S','D',0}, {'S','D','N',0}, 42487, 736 }, /* Sudan */
2476 { 220, {'S','J',0}, {'S','J','M',0}, 10039882, 744 }, /* Svalbard */
2477 { 221, {'S','E',0}, {'S','W','E',0}, 10039882, 752 }, /* Sweden */
2478 { 222, {'S','Y',0}, {'S','Y','R',0}, 47611, 760 }, /* Syria */
2479 { 223, {'C','H',0}, {'C','H','E',0}, 10210824, 756 }, /* Switzerland */
2480 { 224, {'A','E',0}, {'A','R','E',0}, 47611, 784 }, /* United Arab Emirates */
2481 { 225, {'T','T',0}, {'T','T','O',0}, 10039880, 780 }, /* Trinidad and Tobago */
2482 { 227, {'T','H',0}, {'T','H','A',0}, 47599, 764 }, /* Thailand */
2483 { 228, {'T','J',0}, {'T','J','K',0}, 47590, 762 }, /* Tajikistan */
2484 { 231, {'T','O',0}, {'T','O','N',0}, 26286, 776 }, /* Tonga */
2485 { 232, {'T','G',0}, {'T','G','O',0}, 42483, 768 }, /* Togo */
2486 { 233, {'S','T',0}, {'S','T','P',0}, 42484, 678 }, /* São Tomé and Príncipe */
2487 { 234, {'T','N',0}, {'T','U','N',0}, 42487, 788 }, /* Tunisia */
2488 { 235, {'T','R',0}, {'T','U','R',0}, 47611, 792 }, /* Turkey */
2489 { 236, {'T','V',0}, {'T','U','V',0}, 26286, 798 }, /* Tuvalu */
2490 { 237, {'T','W',0}, {'T','W','N',0}, 47600, 158 }, /* Taiwan */
2491 { 238, {'T','M',0}, {'T','K','M',0}, 47590, 795 }, /* Turkmenistan */
2492 { 239, {'T','Z',0}, {'T','Z','A',0}, 47603, 834 }, /* Tanzania */
2493 { 240, {'U','G',0}, {'U','G','A',0}, 47603, 800 }, /* Uganda */
2494 { 241, {'U','A',0}, {'U','K','R',0}, 47609, 804 }, /* Ukraine */
2495 { 242, {'G','B',0}, {'G','B','R',0}, 10039882, 826 }, /* United Kingdom */
2496 { 244, {'U','S',0}, {'U','S','A',0}, 23581, 840 }, /* United States */
2497 { 245, {'B','F',0}, {'B','F','A',0}, 42483, 854 }, /* Burkina Faso */
2498 { 246, {'U','Y',0}, {'U','R','Y',0}, 31396, 858 }, /* Uruguay */
2499 { 247, {'U','Z',0}, {'U','Z','B',0}, 47590, 860 }, /* Uzbekistan */
2500 { 248, {'V','C',0}, {'V','C','T',0}, 10039880, 670 }, /* St. Vincent and the Grenadines */
2501 { 249, {'V','E',0}, {'V','E','N',0}, 31396, 862 }, /* Bolivarian Republic of Venezuela */
2502 { 251, {'V','N',0}, {'V','N','M',0}, 47599, 704 }, /* Vietnam */
2503 { 252, {'V','I',0}, {'V','I','R',0}, 10039880, 850 }, /* Virgin Islands */
2504 { 253, {'V','A',0}, {'V','A','T',0}, 47610, 336 }, /* Vatican City */
2505 { 254, {'N','A',0}, {'N','A','M',0}, 10039883, 516 }, /* Namibia */
2506 { 257, {'E','H',0}, {'E','S','H',0}, 42487, 732 }, /* Western Sahara (disputed) */
2507 { 258, {'X','X',0}, {'X','X',0}, 161832256 }, /* Wake Island */
2508 { 259, {'W','S',0}, {'W','S','M',0}, 26286, 882 }, /* Samoa */
2509 { 260, {'S','Z',0}, {'S','W','Z',0}, 10039883, 748 }, /* Swaziland */
2510 { 261, {'Y','E',0}, {'Y','E','M',0}, 47611, 887 }, /* Yemen */
2511 { 263, {'Z','M',0}, {'Z','M','B',0}, 47603, 894 }, /* Zambia */
2512 { 264, {'Z','W',0}, {'Z','W','E',0}, 47603, 716 }, /* Zimbabwe */
2513 { 269, {'C','S',0}, {'S','C','G',0}, 47610, 891 }, /* Serbia and Montenegro (Former) */
2514 { 270, {'M','E',0}, {'M','N','E',0}, 47610, 499 }, /* Montenegro */
2515 { 271, {'R','S',0}, {'S','R','B',0}, 47610, 688 }, /* Serbia */
2516 { 273, {'C','W',0}, {'C','U','W',0}, 10039880, 531 }, /* Curaçao */
2517 { 276, {'S','S',0}, {'S','S','D',0}, 42487, 728 }, /* South Sudan */
2518 { 300, {'A','I',0}, {'A','I','A',0}, 10039880, 660 }, /* Anguilla */
2519 { 301, {'A','Q',0}, {'A','T','A',0}, 39070, 10 }, /* Antarctica */
2520 { 302, {'A','W',0}, {'A','B','W',0}, 10039880, 533 }, /* Aruba */
2521 { 303, {'X','X',0}, {'X','X',0}, 39070 }, /* Ascension Island */
2522 { 304, {'X','X',0}, {'X','X',0}, 10210825 }, /* Ashmore and Cartier Islands */
2523 { 305, {'X','X',0}, {'X','X',0}, 161832256 }, /* Baker Island */
2524 { 306, {'B','V',0}, {'B','V','T',0}, 39070, 74 }, /* Bouvet Island */
2525 { 307, {'K','Y',0}, {'C','Y','M',0}, 10039880, 136 }, /* Cayman Islands */
2526 { 308, {'X','X',0}, {'X','X',0}, 10210824, 0, LOCATION_BOTH }, /* Channel Islands */
2527 { 309, {'C','X',0}, {'C','X','R',0}, 12, 162 }, /* Christmas Island */
2528 { 310, {'X','X',0}, {'X','X',0}, 27114 }, /* Clipperton Island */
2529 { 311, {'C','C',0}, {'C','C','K',0}, 10210825, 166 }, /* Cocos (Keeling) Islands */
2530 { 312, {'C','K',0}, {'C','O','K',0}, 26286, 184 }, /* Cook Islands */
2531 { 313, {'X','X',0}, {'X','X',0}, 10210825 }, /* Coral Sea Islands */
2532 { 314, {'X','X',0}, {'X','X',0}, 114 }, /* Diego Garcia */
2533 { 315, {'F','K',0}, {'F','L','K',0}, 31396, 238 }, /* Falkland Islands (Islas Malvinas) */
2534 { 317, {'G','F',0}, {'G','U','F',0}, 31396, 254 }, /* French Guiana */
2535 { 318, {'P','F',0}, {'P','Y','F',0}, 26286, 258 }, /* French Polynesia */
2536 { 319, {'T','F',0}, {'A','T','F',0}, 39070, 260 }, /* French Southern and Antarctic Lands */
2537 { 321, {'G','P',0}, {'G','L','P',0}, 10039880, 312 }, /* Guadeloupe */
2538 { 322, {'G','U',0}, {'G','U','M',0}, 21206, 316 }, /* Guam */
2539 { 323, {'X','X',0}, {'X','X',0}, 39070 }, /* Guantanamo Bay */
2540 { 324, {'G','G',0}, {'G','G','Y',0}, 308, 831 }, /* Guernsey */
2541 { 325, {'H','M',0}, {'H','M','D',0}, 39070, 334 }, /* Heard Island and McDonald Islands */
2542 { 326, {'X','X',0}, {'X','X',0}, 161832256 }, /* Howland Island */
2543 { 327, {'X','X',0}, {'X','X',0}, 161832256 }, /* Jarvis Island */
2544 { 328, {'J','E',0}, {'J','E','Y',0}, 308, 832 }, /* Jersey */
2545 { 329, {'X','X',0}, {'X','X',0}, 161832256 }, /* Kingman Reef */
2546 { 330, {'M','Q',0}, {'M','T','Q',0}, 10039880, 474 }, /* Martinique */
2547 { 331, {'Y','T',0}, {'M','Y','T',0}, 47603, 175 }, /* Mayotte */
2548 { 332, {'M','S',0}, {'M','S','R',0}, 10039880, 500 }, /* Montserrat */
2549 { 333, {'A','N',0}, {'A','N','T',0}, 10039880, 530, LOCATION_BOTH }, /* Netherlands Antilles (Former) */
2550 { 334, {'N','C',0}, {'N','C','L',0}, 20900, 540 }, /* New Caledonia */
2551 { 335, {'N','U',0}, {'N','I','U',0}, 26286, 570 }, /* Niue */
2552 { 336, {'N','F',0}, {'N','F','K',0}, 10210825, 574 }, /* Norfolk Island */
2553 { 337, {'M','P',0}, {'M','N','P',0}, 21206, 580 }, /* Northern Mariana Islands */
2554 { 338, {'X','X',0}, {'X','X',0}, 161832256 }, /* Palmyra Atoll */
2555 { 339, {'P','N',0}, {'P','C','N',0}, 26286, 612 }, /* Pitcairn Islands */
2556 { 340, {'X','X',0}, {'X','X',0}, 337 }, /* Rota Island */
2557 { 341, {'X','X',0}, {'X','X',0}, 337 }, /* Saipan */
2558 { 342, {'G','S',0}, {'S','G','S',0}, 39070, 239 }, /* South Georgia and the South Sandwich Islands */
2559 { 343, {'S','H',0}, {'S','H','N',0}, 42483, 654 }, /* St. Helena */
2560 { 346, {'X','X',0}, {'X','X',0}, 337 }, /* Tinian Island */
2561 { 347, {'T','K',0}, {'T','K','L',0}, 26286, 772 }, /* Tokelau */
2562 { 348, {'X','X',0}, {'X','X',0}, 39070 }, /* Tristan da Cunha */
2563 { 349, {'T','C',0}, {'T','C','A',0}, 10039880, 796 }, /* Turks and Caicos Islands */
2564 { 351, {'V','G',0}, {'V','G','B',0}, 10039880, 92 }, /* Virgin Islands, British */
2565 { 352, {'W','F',0}, {'W','L','F',0}, 26286, 876 }, /* Wallis and Futuna */
2566 { 742, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Africa */
2567 { 2129, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Asia */
2568 { 10541, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Europe */
2569 { 15126, {'I','M',0}, {'I','M','N',0}, 10039882, 833 }, /* Man, Isle of */
2570 { 19618, {'M','K',0}, {'M','K','D',0}, 47610, 807 }, /* Macedonia, Former Yugoslav Republic of */
2571 { 20900, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION }, /* Melanesia */
2572 { 21206, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION }, /* Micronesia */
2573 { 21242, {'X','X',0}, {'X','X',0}, 161832256 }, /* Midway Islands */
2574 { 23581, {'X','X',0}, {'X','X',0}, 10026358, 0, LOCATION_REGION }, /* Northern America */
2575 { 26286, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION }, /* Polynesia */
2576 { 27082, {'X','X',0}, {'X','X',0}, 161832257, 0, LOCATION_REGION }, /* Central America */
2577 { 27114, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Oceania */
2578 { 30967, {'S','X',0}, {'S','X','M',0}, 10039880, 534 }, /* Sint Maarten (Dutch part) */
2579 { 31396, {'X','X',0}, {'X','X',0}, 161832257, 0, LOCATION_REGION }, /* South America */
2580 { 31706, {'M','F',0}, {'M','A','F',0}, 10039880, 663 }, /* Saint Martin (French part) */
2581 { 39070, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* World */
2582 { 42483, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Western Africa */
2583 { 42484, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Middle Africa */
2584 { 42487, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Northern Africa */
2585 { 47590, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* Central Asia */
2586 { 47599, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* South-Eastern Asia */
2587 { 47600, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* Eastern Asia */
2588 { 47603, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Eastern Africa */
2589 { 47609, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION }, /* Eastern Europe */
2590 { 47610, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION }, /* Southern Europe */
2591 { 47611, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* Middle East */
2592 { 47614, {'X','X',0}, {'X','X',0}, 2129, 0, LOCATION_REGION }, /* Southern Asia */
2593 { 7299303, {'T','L',0}, {'T','L','S',0}, 47599, 626 }, /* Democratic Republic of Timor-Leste */
2594 { 10026358, {'X','X',0}, {'X','X',0}, 39070, 0, LOCATION_REGION }, /* Americas */
2595 { 10028789, {'A','X',0}, {'A','L','A',0}, 10039882, 248 }, /* Åland Islands */
2596 { 10039880, {'X','X',0}, {'X','X',0}, 161832257, 0, LOCATION_REGION }, /* Caribbean */
2597 { 10039882, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION }, /* Northern Europe */
2598 { 10039883, {'X','X',0}, {'X','X',0}, 742, 0, LOCATION_REGION }, /* Southern Africa */
2599 { 10210824, {'X','X',0}, {'X','X',0}, 10541, 0, LOCATION_REGION }, /* Western Europe */
2600 { 10210825, {'X','X',0}, {'X','X',0}, 27114, 0, LOCATION_REGION }, /* Australia and New Zealand */
2601 { 161832015, {'B','L',0}, {'B','L','M',0}, 10039880, 652 }, /* Saint Barthélemy */
2602 { 161832256, {'U','M',0}, {'U','M','I',0}, 27114, 581 }, /* U.S. Minor Outlying Islands */
2603 { 161832257, {'X','X',0}, {'X','X',0}, 10026358, 0, LOCATION_REGION }, /* Latin America and the Caribbean */
2604 };
2605
2606 /******************************************************************************
2607 * EnumLanguageGroupLocalesA (KERNEL32.@)
2608 *
2609 * Call a users function for every locale in a language group available on the system.
2610 *
2611 * PARAMS
2612 * pLangGrpLcEnumProc [I] Callback function to call for each locale
2613 * lgrpid [I] Language group (LGRPID_ values from "winnls.h")
2614 * dwFlags [I] Reserved, set to 0
2615 * lParam [I] User parameter to pass to pLangGrpLcEnumProc
2616 *
2617 * RETURNS
2618 * Success: TRUE.
2619 * Failure: FALSE. Use GetLastError() to determine the cause.
2620 */
2621 BOOL WINAPI EnumLanguageGroupLocalesA(LANGGROUPLOCALE_ENUMPROCA pLangGrpLcEnumProc,
2622 LGRPID lgrpid, DWORD dwFlags, LONG_PTR lParam)
2623 {
2624 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks;
2625
2626 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc, lgrpid, dwFlags, lParam);
2627
2628 callbacks.procA = pLangGrpLcEnumProc;
2629 callbacks.procW = NULL;
2630 callbacks.dwFlags = dwFlags;
2631 callbacks.lgrpid = lgrpid;
2632 callbacks.lParam = lParam;
2633
2634 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc ? &callbacks : NULL );
2635 }
2636
2637 /******************************************************************************
2638 * EnumLanguageGroupLocalesW (KERNEL32.@)
2639 *
2640 * See EnumLanguageGroupLocalesA.
2641 */
2642 BOOL WINAPI EnumLanguageGroupLocalesW(LANGGROUPLOCALE_ENUMPROCW pLangGrpLcEnumProc,
2643 LGRPID lgrpid, DWORD dwFlags, LONG_PTR lParam)
2644 {
2645 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks;
2646
2647 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc, lgrpid, dwFlags, lParam);
2648
2649 callbacks.procA = NULL;
2650 callbacks.procW = pLangGrpLcEnumProc;
2651 callbacks.dwFlags = dwFlags;
2652 callbacks.lgrpid = lgrpid;
2653 callbacks.lParam = lParam;
2654
2655 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc ? &callbacks : NULL );
2656 }
2657
2658 /* Callback function ptrs for EnumSystemCodePagesA/W */
2659 typedef struct
2660 {
2661 CODEPAGE_ENUMPROCA procA;
2662 CODEPAGE_ENUMPROCW procW;
2663 DWORD dwFlags;
2664 } ENUMSYSTEMCODEPAGES_CALLBACKS;
2665
2666 /* Internal implementation of EnumSystemCodePagesA/W */
2667 static BOOL NLS_EnumSystemCodePages(ENUMSYSTEMCODEPAGES_CALLBACKS *lpProcs)
2668 {
2669 WCHAR szNumber[5 + 1], szValue[MAX_PATH];
2670 HANDLE hKey;
2671 BOOL bContinue = TRUE;
2672 ULONG ulIndex = 0;
2673
2674 if (!lpProcs)
2675 {
2676 SetLastError(ERROR_INVALID_PARAMETER);
2677 return FALSE;
2678 }
2679
2680 switch (lpProcs->dwFlags)
2681 {
2682 case CP_INSTALLED:
2683 case CP_SUPPORTED:
2684 break;
2685 default:
2686 SetLastError(ERROR_INVALID_FLAGS);
2687 return FALSE;
2688 }
2689
2690 hKey = NLS_RegOpenKey(0, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
2691 if (!hKey)
2692 {
2693 WARN("NLS_RegOpenKey() failed\n");
2694 return FALSE;
2695 }
2696
2697 while (bContinue)
2698 {
2699 if (NLS_RegEnumValue(hKey, ulIndex, szNumber, sizeof(szNumber),
2700 szValue, sizeof(szValue)))
2701 {
2702 if ((lpProcs->dwFlags == CP_SUPPORTED)||
2703 ((lpProcs->dwFlags == CP_INSTALLED)&&(wcslen(szValue) > 2)))
2704 {
2705 if (lpProcs->procW)
2706 {
2707 bContinue = lpProcs->procW(szNumber);
2708 }
2709 else
2710 {
2711 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
2712
2713 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
2714 bContinue = lpProcs->procA(szNumberA);
2715 }
2716 }
2717
2718 ulIndex++;
2719
2720 } else bContinue = FALSE;
2721
2722 if (!bContinue)
2723 break;
2724 }
2725
2726 if (hKey)
2727 NtClose(hKey);
2728
2729 return TRUE;
2730 }
2731
2732 /*
2733 * @implemented
2734 */
2735 BOOL
2736 WINAPI
2737 EnumSystemCodePagesW (
2738 CODEPAGE_ENUMPROCW lpCodePageEnumProc,
2739 DWORD dwFlags
2740 )
2741 {
2742 ENUMSYSTEMCODEPAGES_CALLBACKS procs;
2743
2744 TRACE("(%p,0x%08X,0x%08lX)\n", lpCodePageEnumProc, dwFlags);
2745
2746 procs.procA = NULL;
2747 procs.procW = lpCodePageEnumProc;
2748 procs.dwFlags = dwFlags;
2749
2750 return NLS_EnumSystemCodePages(lpCodePageEnumProc ? &procs : NULL);
2751 }
2752
2753
2754 /*
2755 * @implemented
2756 */
2757 BOOL
2758 WINAPI
2759 EnumSystemCodePagesA (
2760 CODEPAGE_ENUMPROCA lpCodePageEnumProc,
2761 DWORD dwFlags
2762 )
2763 {
2764 ENUMSYSTEMCODEPAGES_CALLBACKS procs;
2765
2766 TRACE("(%p,0x%08X,0x%08lX)\n", lpCodePageEnumProc, dwFlags);
2767
2768 procs.procA = lpCodePageEnumProc;
2769 procs.procW = NULL;
2770 procs.dwFlags = dwFlags;
2771
2772 return NLS_EnumSystemCodePages(lpCodePageEnumProc ? &procs : NULL);
2773 }
2774
2775 /******************************************************************************
2776 * EnumSystemGeoID (KERNEL32.@)
2777 *
2778 * Call a users function for every location available on the system.
2779 *
2780 * PARAMS
2781 * geoclass [I] Type of information desired (SYSGEOTYPE enum from "winnls.h")
2782 * parent [I] GEOID for the parent
2783 * enumproc [I] Callback function to call for each location
2784 *
2785 * RETURNS
2786 * Success: TRUE.
2787 * Failure: FALSE. Use GetLastError() to determine the cause.
2788 */
2789 BOOL WINAPI EnumSystemGeoID(GEOCLASS geoclass, GEOID parent, GEO_ENUMPROC enumproc)
2790 {
2791 INT i;
2792
2793 TRACE("(%d, %d, %p)\n", geoclass, parent, enumproc);
2794
2795 if (!enumproc) {
2796 SetLastError(ERROR_INVALID_PARAMETER);
2797 return FALSE;
2798 }
2799
2800 if (geoclass != GEOCLASS_NATION && geoclass != GEOCLASS_REGION) {
2801 SetLastError(ERROR_INVALID_FLAGS);
2802 return FALSE;
2803 }
2804
2805 for (i = 0; i < sizeof(geoinfodata)/sizeof(struct geoinfo_t); i++) {
2806 const struct geoinfo_t *ptr = &geoinfodata[i];
2807
2808 if (geoclass == GEOCLASS_NATION && (ptr->kind == LOCATION_REGION))
2809 continue;
2810
2811 if (geoclass == GEOCLASS_REGION && (ptr->kind == LOCATION_NATION))
2812 continue;
2813
2814 if (parent && ptr->parent != parent)
2815 continue;
2816
2817 if (!enumproc(ptr->id))
2818 return TRUE;
2819 }
2820
2821 return TRUE;
2822 }
2823
2824 /******************************************************************************
2825 * InvalidateNLSCache (KERNEL32.@)
2826 *
2827 * Invalidate the cache of NLS values.
2828 *
2829 * PARAMS
2830 * None.
2831 *
2832 * RETURNS
2833 * Success: TRUE.
2834 * Failure: FALSE.
2835 */
2836 BOOL WINAPI InvalidateNLSCache(void)
2837 {
2838 FIXME("() stub\n");
2839 return FALSE;
2840 }
2841
2842 /******************************************************************************
2843 * GetUserGeoID (KERNEL32.@)
2844 */
2845 GEOID WINAPI GetUserGeoID( GEOCLASS GeoClass )
2846 {
2847 GEOID ret = GEOID_NOT_AVAILABLE;
2848 static const WCHAR geoW[] = {'G','e','o',0};
2849 static const WCHAR nationW[] = {'N','a','t','i','o','n',0};
2850 WCHAR bufferW[40], *end;
2851 DWORD count;
2852 HANDLE hkey, hSubkey = 0;
2853 UNICODE_STRING keyW;
2854 const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)bufferW;
2855 RtlInitUnicodeString( &keyW, nationW );
2856 count = sizeof(bufferW);
2857
2858 if(!(hkey = create_registry_key())) return ret;
2859
2860 switch( GeoClass ){
2861 case GEOCLASS_NATION:
2862 if ((hSubkey = NLS_RegOpenKey(hkey, geoW)))
2863 {
2864 if((NtQueryValueKey(hSubkey, &keyW, KeyValuePartialInformation,
2865 bufferW, count, &count) == STATUS_SUCCESS ) && info->DataLength)
2866 ret = strtolW((LPCWSTR)info->Data, &end, 10);
2867 }
2868 break;
2869 case GEOCLASS_REGION:
2870 FIXME("GEOCLASS_REGION not handled yet\n");
2871 break;
2872 }
2873
2874 NtClose(hkey);
2875 if (hSubkey) NtClose(hSubkey);
2876 return ret;
2877 }
2878
2879 /******************************************************************************
2880 * SetUserGeoID (KERNEL32.@)
2881 */
2882 BOOL WINAPI SetUserGeoID( GEOID GeoID )
2883 {
2884 static const WCHAR geoW[] = {'G','e','o',0};
2885 static const WCHAR nationW[] = {'N','a','t','i','o','n',0};
2886 static const WCHAR formatW[] = {'%','i',0};
2887 UNICODE_STRING nameW,keyW;
2888 WCHAR bufferW[10];
2889 OBJECT_ATTRIBUTES attr;
2890 HANDLE hkey;
2891
2892 if(!(hkey = create_registry_key())) return FALSE;
2893
2894 attr.Length = sizeof(attr);
2895 attr.RootDirectory = hkey;
2896 attr.ObjectName = &nameW;
2897 attr.Attributes = 0;
2898 attr.SecurityDescriptor = NULL;
2899 attr.SecurityQualityOfService = NULL;
2900 RtlInitUnicodeString( &nameW, geoW );
2901 RtlInitUnicodeString( &keyW, nationW );
2902
2903 if (NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) != STATUS_SUCCESS)
2904
2905 {
2906 NtClose(attr.RootDirectory);
2907 return FALSE;
2908 }
2909
2910 sprintfW(bufferW, formatW, GeoID);
2911 NtSetValueKey(hkey, &keyW, 0, REG_SZ, bufferW, (strlenW(bufferW) + 1) * sizeof(WCHAR));
2912 NtClose(attr.RootDirectory);
2913 NtClose(hkey);
2914 return TRUE;
2915 }
2916
2917 typedef struct
2918 {
2919 union
2920 {
2921 UILANGUAGE_ENUMPROCA procA;
2922 UILANGUAGE_ENUMPROCW procW;
2923 } u;
2924 DWORD flags;
2925 LONG_PTR param;
2926 } ENUM_UILANG_CALLBACK;
2927
2928 static BOOL CALLBACK enum_uilang_proc_a( HMODULE hModule, LPCSTR type,
2929 LPCSTR name, WORD LangID, LONG_PTR lParam )
2930 {
2931 ENUM_UILANG_CALLBACK *enum_uilang = (ENUM_UILANG_CALLBACK *)lParam;
2932 char buf[20];
2933
2934 sprintf(buf, "%08x", (UINT)LangID);
2935 return enum_uilang->u.procA( buf, enum_uilang->param );
2936 }
2937
2938 static BOOL CALLBACK enum_uilang_proc_w( HMODULE hModule, LPCWSTR type,
2939 LPCWSTR name, WORD LangID, LONG_PTR lParam )
2940 {
2941 static const WCHAR formatW[] = {'%','0','8','x',0};
2942 ENUM_UILANG_CALLBACK *enum_uilang = (ENUM_UILANG_CALLBACK *)lParam;
2943 WCHAR buf[20];
2944
2945 sprintfW( buf, formatW, (UINT)LangID );
2946 return enum_uilang->u.procW( buf, enum_uilang->param );
2947 }
2948
2949 /******************************************************************************
2950 * EnumUILanguagesA (KERNEL32.@)
2951 */
2952 BOOL WINAPI EnumUILanguagesA(UILANGUAGE_ENUMPROCA pUILangEnumProc, DWORD dwFlags, LONG_PTR lParam)
2953 {
2954 ENUM_UILANG_CALLBACK enum_uilang;
2955
2956 TRACE("%p, %x, %lx\n", pUILangEnumProc, dwFlags, lParam);
2957
2958 if(!pUILangEnumProc) {
2959 SetLastError(ERROR_INVALID_PARAMETER);
2960 return FALSE;
2961 }
2962 if(dwFlags) {
2963 SetLastError(ERROR_INVALID_FLAGS);
2964 return FALSE;
2965 }
2966
2967 enum_uilang.u.procA = pUILangEnumProc;
2968 enum_uilang.flags = dwFlags;
2969 enum_uilang.param = lParam;
2970
2971 EnumResourceLanguagesA( kernel32_handle, (LPCSTR)RT_STRING,
2972 (LPCSTR)LOCALE_ILANGUAGE, enum_uilang_proc_a,
2973 (LONG_PTR)&enum_uilang);
2974 return TRUE;
2975 }
2976
2977 /******************************************************************************
2978 * EnumUILanguagesW (KERNEL32.@)
2979 */
2980 BOOL WINAPI EnumUILanguagesW(UILANGUAGE_ENUMPROCW pUILangEnumProc, DWORD dwFlags, LONG_PTR lParam)
2981 {
2982 ENUM_UILANG_CALLBACK enum_uilang;
2983
2984 TRACE("%p, %x, %lx\n", pUILangEnumProc, dwFlags, lParam);
2985
2986
2987 if(!pUILangEnumProc) {
2988 SetLastError(ERROR_INVALID_PARAMETER);
2989 return FALSE;
2990 }
2991 if(dwFlags) {
2992 SetLastError(ERROR_INVALID_FLAGS);
2993 return FALSE;
2994 }
2995
2996 enum_uilang.u.procW = pUILangEnumProc;
2997 enum_uilang.flags = dwFlags;
2998 enum_uilang.param = lParam;
2999
3000 EnumResourceLanguagesW( kernel32_handle, (LPCWSTR)RT_STRING,
3001 (LPCWSTR)LOCALE_ILANGUAGE, enum_uilang_proc_w,
3002 (LONG_PTR)&enum_uilang);
3003 return TRUE;
3004 }
3005
3006 static int
3007 NLS_GetGeoFriendlyName(GEOID Location, LPWSTR szFriendlyName, int cchData)
3008 {
3009 LPWSTR szBuffer;
3010 DWORD dwSize;
3011
3012 /* FIXME: move *.nls resources out of kernel32 into locale.nls */
3013 Location += NLSRC_OFFSET;
3014 Location &= 0xFFFF;
3015
3016 if(cchData == 0)
3017 return GetLocalisedText(Location, NULL, 0);
3018
3019 dwSize = cchData * sizeof(WCHAR);
3020 szBuffer = HeapAlloc(GetProcessHeap(), 0, dwSize);
3021
3022 if (!szBuffer)
3023 {
3024 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
3025 return 0;
3026 }
3027
3028 if(GetLocalisedText(Location, szBuffer, dwSize))
3029 {
3030 memcpy(szFriendlyName, szBuffer, dwSize);
3031 HeapFree(GetProcessHeap(), 0, szBuffer);
3032 return strlenW(szFriendlyName) + 1;
3033 }
3034
3035 HeapFree(GetProcessHeap(), 0, szBuffer);
3036 return 0;
3037 }
3038
3039 static const struct geoinfo_t *get_geoinfo_dataptr(GEOID geoid)
3040 {
3041 int min, max;
3042
3043 min = 0;
3044 max = sizeof(geoinfodata)/sizeof(struct geoinfo_t)-1;
3045
3046 while (min <= max) {
3047 const struct geoinfo_t *ptr;
3048 int n = (min+max)/2;
3049
3050 ptr = &geoinfodata[n];
3051 if (geoid == ptr->id)
3052 /* we don't need empty entry */
3053 return *ptr->iso2W ? ptr : NULL;
3054
3055 if (ptr->id > geoid)
3056 max = n-1;
3057 else
3058 min = n+1;
3059 }
3060
3061 return NULL;
3062 }
3063
3064 /******************************************************************************
3065 * GetGeoInfoW (KERNEL32.@)
3066 */
3067 INT WINAPI GetGeoInfoW(GEOID geoid, GEOTYPE geotype, LPWSTR data, int data_len, LANGID lang)
3068 {
3069 const struct geoinfo_t *ptr;
3070 const WCHAR *str = NULL;
3071 WCHAR buffW[12];
3072 LONG val = 0;
3073 INT len;
3074
3075 TRACE("%d %d %p %d %d\n", geoid, geotype, data, data_len, lang);
3076
3077 if (!(ptr = get_geoinfo_dataptr(geoid))) {
3078 SetLastError(ERROR_INVALID_PARAMETER);
3079 return 0;
3080 }
3081
3082 switch (geotype) {
3083 case GEO_FRIENDLYNAME:
3084 {
3085 return NLS_GetGeoFriendlyName(geoid, data, data_len);
3086 }
3087 case GEO_NATION:
3088 val = geoid;
3089 break;
3090 case GEO_ISO_UN_NUMBER:
3091 val = ptr->uncode;
3092 break;
3093 case GEO_PARENT:
3094 val = ptr->parent;
3095 break;
3096 case GEO_ISO2:
3097 case GEO_ISO3:
3098 {
3099 str = geotype == GEO_ISO2 ? ptr->iso2W : ptr->iso3W;
3100 break;
3101 }
3102 case GEO_RFC1766:
3103 case GEO_LCID:
3104 case GEO_OFFICIALNAME:
3105 case GEO_TIMEZONES:
3106 case GEO_OFFICIALLANGUAGES:
3107 case GEO_LATITUDE:
3108 case GEO_LONGITUDE:
3109 FIXME("type %d is not supported\n", geotype);
3110 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3111 return 0;
3112 default:
3113 WARN("unrecognized type %d\n", geotype);
3114 SetLastError(ERROR_INVALID_FLAGS);
3115 return 0;
3116 }
3117
3118 if (val) {
3119 static const WCHAR fmtW[] = {'%','d',0};
3120 sprintfW(buffW, fmtW, val);
3121 str = buffW;
3122 }
3123
3124 len = strlenW(str) + 1;
3125 if (!data || !data_len)
3126 return len;
3127
3128 memcpy(data, str, min(len, data_len)*sizeof(WCHAR));
3129 if (data_len < len)
3130 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3131 return data_len < len ? 0 : len;
3132 }
3133
3134 /******************************************************************************
3135 * GetGeoInfoA (KERNEL32.@)
3136 */
3137 INT WINAPI GetGeoInfoA(GEOID geoid, GEOTYPE geotype, LPSTR data, int data_len, LANGID lang)
3138 {
3139 WCHAR *buffW;
3140 INT len;
3141
3142 TRACE("%d %d %p %d %d\n", geoid, geotype, data, data_len, lang);
3143
3144 len = GetGeoInfoW(geoid, geotype, NULL, 0, lang);
3145 if (!len)
3146 return 0;
3147
3148 buffW = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
3149 if (!buffW)
3150 return 0;
3151
3152 GetGeoInfoW(geoid, geotype, buffW, len, lang);
3153 len = WideCharToMultiByte(CP_ACP, 0, buffW, -1, NULL, 0, NULL, NULL);
3154 if (!data || !data_len) {
3155 HeapFree(GetProcessHeap(), 0, buffW);
3156 return len;
3157 }
3158
3159 len = WideCharToMultiByte(CP_ACP, 0, buffW, -1, data, data_len, NULL, NULL);
3160 HeapFree(GetProcessHeap(), 0, buffW);
3161
3162 if (data_len < len)
3163 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3164 return data_len < len ? 0 : len;
3165 }