[KERNEL32] Sync GetStringTypeW with Wine
[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)
1259 {
1260 SetLastError( ERROR_INVALID_PARAMETER );
1261 return FALSE;
1262 }
1263
1264 if (count == -1) count = strlenW(src) + 1;
1265 switch(type)
1266 {
1267 case CT_CTYPE1:
1268 while (count--) *chartype++ = get_char_typeW( *src++ ) & 0xfff;
1269 break;
1270 case CT_CTYPE2:
1271 while (count--) *chartype++ = type2_map[get_char_typeW( *src++ ) >> 12];
1272 break;
1273 case CT_CTYPE3:
1274 {
1275 WARN("CT_CTYPE3: semi-stub.\n");
1276 while (count--)
1277 {
1278 int c = *src;
1279 WORD type1, type3 = 0; /* C3_NOTAPPLICABLE */
1280
1281 type1 = get_char_typeW( *src++ ) & 0xfff;
1282 /* try to construct type3 from type1 */
1283 if(type1 & C1_SPACE) type3 |= C3_SYMBOL;
1284 if(type1 & C1_ALPHA) type3 |= C3_ALPHA;
1285 if ((c>=0x30A0)&&(c<=0x30FF)) type3 |= C3_KATAKANA;
1286 if ((c>=0x3040)&&(c<=0x309F)) type3 |= C3_HIRAGANA;
1287 if ((c>=0x4E00)&&(c<=0x9FAF)) type3 |= C3_IDEOGRAPH;
1288 if (c == 0x0640) type3 |= C3_KASHIDA;
1289 if ((c>=0x3000)&&(c<=0x303F)) type3 |= C3_SYMBOL;
1290
1291 if ((c>=0xD800)&&(c<=0xDBFF)) type3 |= C3_HIGHSURROGATE;
1292 if ((c>=0xDC00)&&(c<=0xDFFF)) type3 |= C3_LOWSURROGATE;
1293
1294 if ((c>=0xFF00)&&(c<=0xFF60)) type3 |= C3_FULLWIDTH;
1295 if ((c>=0xFF00)&&(c<=0xFF20)) type3 |= C3_SYMBOL;
1296 if ((c>=0xFF3B)&&(c<=0xFF40)) type3 |= C3_SYMBOL;
1297 if ((c>=0xFF5B)&&(c<=0xFF60)) type3 |= C3_SYMBOL;
1298 if ((c>=0xFF21)&&(c<=0xFF3A)) type3 |= C3_ALPHA;
1299 if ((c>=0xFF41)&&(c<=0xFF5A)) type3 |= C3_ALPHA;
1300 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_FULLWIDTH;
1301 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_SYMBOL;
1302
1303 if ((c>=0xFF61)&&(c<=0xFFDC)) type3 |= C3_HALFWIDTH;
1304 if ((c>=0xFF61)&&(c<=0xFF64)) type3 |= C3_SYMBOL;
1305 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_KATAKANA;
1306 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_ALPHA;
1307 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_HALFWIDTH;
1308 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_SYMBOL;
1309 *chartype++ = type3;
1310 }
1311 break;
1312 }
1313 default:
1314 SetLastError( ERROR_INVALID_PARAMETER );
1315 return FALSE;
1316 }
1317 return TRUE;
1318 }
1319
1320
1321 /******************************************************************************
1322 * GetStringTypeExW (KERNEL32.@)
1323 *
1324 * See GetStringTypeExA.
1325 */
1326 BOOL WINAPI GetStringTypeExW( LCID locale, DWORD type, LPCWSTR src, INT count, LPWORD chartype )
1327 {
1328 /* locale is ignored for Unicode */
1329 return GetStringTypeW( type, src, count, chartype );
1330 }
1331
1332
1333 /******************************************************************************
1334 * GetStringTypeA (KERNEL32.@)
1335 *
1336 * Get characteristics of the characters making up a string.
1337 *
1338 * PARAMS
1339 * locale [I] Locale Id for the string
1340 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1341 * src [I] String to analyse
1342 * count [I] Length of src in chars, or -1 if src is NUL terminated
1343 * chartype [O] Destination for the calculated characteristics
1344 *
1345 * RETURNS
1346 * Success: TRUE. chartype is filled with the requested characteristics of each char
1347 * in src.
1348 * Failure: FALSE. Use GetLastError() to determine the cause.
1349 */
1350 BOOL WINAPI GetStringTypeA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
1351 {
1352 UINT cp;
1353 INT countW;
1354 LPWSTR srcW;
1355 BOOL ret = FALSE;
1356
1357 if(count == -1) count = strlen(src) + 1;
1358
1359 if (!(cp = get_lcid_codepage( locale )))
1360 {
1361 FIXME("For locale %04x using current ANSI code page\n", locale);
1362 cp = GetACP();
1363 }
1364
1365 countW = MultiByteToWideChar(cp, 0, src, count, NULL, 0);
1366 if((srcW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
1367 {
1368 MultiByteToWideChar(cp, 0, src, count, srcW, countW);
1369 /*
1370 * NOTE: the target buffer has 1 word for each CHARACTER in the source
1371 * string, with multibyte characters there maybe be more bytes in count
1372 * than character space in the buffer!
1373 */
1374 ret = GetStringTypeW(type, srcW, countW, chartype);
1375 HeapFree(GetProcessHeap(), 0, srcW);
1376 }
1377 return ret;
1378 }
1379
1380 /******************************************************************************
1381 * GetStringTypeExA (KERNEL32.@)
1382 *
1383 * Get characteristics of the characters making up a string.
1384 *
1385 * PARAMS
1386 * locale [I] Locale Id for the string
1387 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1388 * src [I] String to analyse
1389 * count [I] Length of src in chars, or -1 if src is NUL terminated
1390 * chartype [O] Destination for the calculated characteristics
1391 *
1392 * RETURNS
1393 * Success: TRUE. chartype is filled with the requested characteristics of each char
1394 * in src.
1395 * Failure: FALSE. Use GetLastError() to determine the cause.
1396 */
1397 BOOL WINAPI GetStringTypeExA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
1398 {
1399 return GetStringTypeA(locale, type, src, count, chartype);
1400 }
1401
1402 /*************************************************************************
1403 * LCMapStringEx (KERNEL32.@)
1404 *
1405 * Map characters in a locale sensitive string.
1406 *
1407 * PARAMS
1408 * name [I] Locale name for the conversion.
1409 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h")
1410 * src [I] String to map
1411 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
1412 * dst [O] Destination for mapped string
1413 * dstlen [I] Length of dst in characters
1414 * version [I] reserved, must be NULL
1415 * reserved [I] reserved, must be NULL
1416 * lparam [I] reserved, must be 0
1417 *
1418 * RETURNS
1419 * Success: The length of the mapped string in dst, including the NUL terminator.
1420 * Failure: 0. Use GetLastError() to determine the cause.
1421 */
1422 INT WINAPI LCMapStringEx(LPCWSTR name, DWORD flags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen,
1423 LPNLSVERSIONINFO version, LPVOID reserved, LPARAM lparam)
1424 {
1425 LPWSTR dst_ptr;
1426
1427 if (version) FIXME("unsupported version structure %p\n", version);
1428 if (reserved) FIXME("unsupported reserved pointer %p\n", reserved);
1429 if (lparam) FIXME("unsupported lparam %lx\n", lparam);
1430
1431 if (!src || !srclen || dstlen < 0)
1432 {
1433 SetLastError(ERROR_INVALID_PARAMETER);
1434 return 0;
1435 }
1436
1437 /* mutually exclusive flags */
1438 if ((flags & (LCMAP_LOWERCASE | LCMAP_UPPERCASE)) == (LCMAP_LOWERCASE | LCMAP_UPPERCASE) ||
1439 (flags & (LCMAP_HIRAGANA | LCMAP_KATAKANA)) == (LCMAP_HIRAGANA | LCMAP_KATAKANA) ||
1440 (flags & (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH)) == (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH) ||
1441 (flags & (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE)) == (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE))
1442 {
1443 SetLastError(ERROR_INVALID_FLAGS);
1444 return 0;
1445 }
1446
1447 if (!dstlen) dst = NULL;
1448
1449 if (flags & LCMAP_SORTKEY)
1450 {
1451 INT ret;
1452 if (src == dst)
1453 {
1454 SetLastError(ERROR_INVALID_FLAGS);
1455 return 0;
1456 }
1457
1458 if (srclen < 0) srclen = strlenW(src);
1459
1460 TRACE("(%s,0x%08x,%s,%d,%p,%d)\n",
1461 debugstr_w(name), flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1462
1463 ret = wine_get_sortkey(flags, src, srclen, (char *)dst, dstlen);
1464 if (ret == 0)
1465 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1466 else
1467 ret++;
1468 return ret;
1469 }
1470
1471 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
1472 if (flags & SORT_STRINGSORT)
1473 {
1474 SetLastError(ERROR_INVALID_FLAGS);
1475 return 0;
1476 }
1477
1478 if (srclen < 0) srclen = strlenW(src) + 1;
1479
1480 TRACE("(%s,0x%08x,%s,%d,%p,%d)\n",
1481 debugstr_w(name), flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1482
1483 if (!dst) /* return required string length */
1484 {
1485 INT len;
1486
1487 for (len = 0; srclen; src++, srclen--)
1488 {
1489 WCHAR wch = *src;
1490 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
1491 * and skips white space and punctuation characters for
1492 * NORM_IGNORESYMBOLS.
1493 */
1494 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1495 continue;
1496 len++;
1497 }
1498 return len;
1499 }
1500
1501 if (flags & LCMAP_UPPERCASE)
1502 {
1503 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1504 {
1505 WCHAR wch = *src;
1506 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1507 continue;
1508 *dst_ptr++ = toupperW(wch);
1509 dstlen--;
1510 }
1511 }
1512 else if (flags & LCMAP_LOWERCASE)
1513 {
1514 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1515 {
1516 WCHAR wch = *src;
1517 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1518 continue;
1519 *dst_ptr++ = tolowerW(wch);
1520 dstlen--;
1521 }
1522 }
1523 else
1524 {
1525 if (src == dst)
1526 {
1527 SetLastError(ERROR_INVALID_FLAGS);
1528 return 0;
1529 }
1530 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
1531 {
1532 WCHAR wch = *src;
1533 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
1534 continue;
1535 *dst_ptr++ = wch;
1536 dstlen--;
1537 }
1538 }
1539
1540 if (srclen)
1541 {
1542 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1543 return 0;
1544 }
1545
1546 return dst_ptr - dst;
1547 }
1548
1549 /*************************************************************************
1550 * LCMapStringW (KERNEL32.@)
1551 *
1552 * See LCMapStringA.
1553 */
1554 INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen,
1555 LPWSTR dst, INT dstlen)
1556 {
1557 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
1558 lcid, flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
1559
1560 return LCMapStringEx(NULL, flags, src, srclen, dst, dstlen, NULL, NULL, 0);
1561 }
1562
1563 /*************************************************************************
1564 * LCMapStringA (KERNEL32.@)
1565 *
1566 * Map characters in a locale sensitive string.
1567 *
1568 * PARAMS
1569 * lcid [I] LCID for the conversion.
1570 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h").
1571 * src [I] String to map
1572 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
1573 * dst [O] Destination for mapped string
1574 * dstlen [I] Length of dst in characters
1575 *
1576 * RETURNS
1577 * Success: The length of the mapped string in dst, including the NUL terminator.
1578 * Failure: 0. Use GetLastError() to determine the cause.
1579 */
1580 INT WINAPI LCMapStringA(LCID lcid, DWORD flags, LPCSTR src, INT srclen,
1581 LPSTR dst, INT dstlen)
1582 {
1583 WCHAR *bufW = NtCurrentTeb()->StaticUnicodeBuffer;
1584 LPWSTR srcW, dstW;
1585 INT ret = 0, srclenW, dstlenW;
1586 UINT locale_cp = CP_ACP;
1587
1588 if (!src || !srclen || dstlen < 0)
1589 {
1590 SetLastError(ERROR_INVALID_PARAMETER);
1591 return 0;
1592 }
1593
1594 if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
1595
1596 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, bufW, 260);
1597 if (srclenW)
1598 srcW = bufW;
1599 else
1600 {
1601 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, NULL, 0);
1602 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
1603 if (!srcW)
1604 {
1605 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1606 return 0;
1607 }
1608 MultiByteToWideChar(locale_cp, 0, src, srclen, srcW, srclenW);
1609 }
1610
1611 if (flags & LCMAP_SORTKEY)
1612 {
1613 if (src == dst)
1614 {
1615 SetLastError(ERROR_INVALID_FLAGS);
1616 goto map_string_exit;
1617 }
1618 ret = wine_get_sortkey(flags, srcW, srclenW, dst, dstlen);
1619 if (ret == 0)
1620 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1621 else
1622 ret++;
1623 goto map_string_exit;
1624 }
1625
1626 if (flags & SORT_STRINGSORT)
1627 {
1628 SetLastError(ERROR_INVALID_FLAGS);
1629 goto map_string_exit;
1630 }
1631
1632 dstlenW = LCMapStringEx(NULL, flags, srcW, srclenW, NULL, 0, NULL, NULL, 0);
1633 if (!dstlenW)
1634 goto map_string_exit;
1635
1636 dstW = HeapAlloc(GetProcessHeap(), 0, dstlenW * sizeof(WCHAR));
1637 if (!dstW)
1638 {
1639 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1640 goto map_string_exit;
1641 }
1642
1643 LCMapStringEx(NULL, flags, srcW, srclenW, dstW, dstlenW, NULL, NULL, 0);
1644 ret = WideCharToMultiByte(locale_cp, 0, dstW, dstlenW, dst, dstlen, NULL, NULL);
1645 HeapFree(GetProcessHeap(), 0, dstW);
1646
1647 map_string_exit:
1648 if (srcW != bufW) HeapFree(GetProcessHeap(), 0, srcW);
1649 return ret;
1650 }
1651
1652 /*************************************************************************
1653 * FoldStringA (KERNEL32.@)
1654 *
1655 * Map characters in a string.
1656 *
1657 * PARAMS
1658 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
1659 * src [I] String to map
1660 * srclen [I] Length of src, or -1 if src is NUL terminated
1661 * dst [O] Destination for mapped string
1662 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
1663 *
1664 * RETURNS
1665 * Success: The length of the string written to dst, including the terminating NUL. If
1666 * dstlen is 0, the value returned is the same, but nothing is written to dst,
1667 * and dst may be NULL.
1668 * Failure: 0. Use GetLastError() to determine the cause.
1669 */
1670 INT WINAPI FoldStringA(DWORD dwFlags, LPCSTR src, INT srclen,
1671 LPSTR dst, INT dstlen)
1672 {
1673 INT ret = 0, srclenW = 0;
1674 WCHAR *srcW = NULL, *dstW = NULL;
1675
1676 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
1677 {
1678 SetLastError(ERROR_INVALID_PARAMETER);
1679 return 0;
1680 }
1681
1682 srclenW = MultiByteToWideChar(CP_ACP, dwFlags & MAP_COMPOSITE ? MB_COMPOSITE : 0,
1683 src, srclen, NULL, 0);
1684 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
1685
1686 if (!srcW)
1687 {
1688 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1689 goto FoldStringA_exit;
1690 }
1691
1692 MultiByteToWideChar(CP_ACP, dwFlags & MAP_COMPOSITE ? MB_COMPOSITE : 0,
1693 src, srclen, srcW, srclenW);
1694
1695 dwFlags = (dwFlags & ~MAP_PRECOMPOSED) | MAP_FOLDCZONE;
1696
1697 ret = FoldStringW(dwFlags, srcW, srclenW, NULL, 0);
1698 if (ret && dstlen)
1699 {
1700 dstW = HeapAlloc(GetProcessHeap(), 0, ret * sizeof(WCHAR));
1701
1702 if (!dstW)
1703 {
1704 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1705 goto FoldStringA_exit;
1706 }
1707
1708 ret = FoldStringW(dwFlags, srcW, srclenW, dstW, ret);
1709 if (!WideCharToMultiByte(CP_ACP, 0, dstW, ret, dst, dstlen, NULL, NULL))
1710 {
1711 ret = 0;
1712 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1713 }
1714 }
1715
1716 HeapFree(GetProcessHeap(), 0, dstW);
1717
1718 FoldStringA_exit:
1719 HeapFree(GetProcessHeap(), 0, srcW);
1720 return ret;
1721 }
1722
1723 /*************************************************************************
1724 * FoldStringW (KERNEL32.@)
1725 *
1726 * See FoldStringA.
1727 */
1728 INT WINAPI FoldStringW(DWORD dwFlags, LPCWSTR src, INT srclen,
1729 LPWSTR dst, INT dstlen)
1730 {
1731 int ret;
1732
1733 switch (dwFlags & (MAP_COMPOSITE|MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES))
1734 {
1735 case 0:
1736 if (dwFlags)
1737 break;
1738 /* Fall through for dwFlags == 0 */
1739 case MAP_PRECOMPOSED|MAP_COMPOSITE:
1740 case MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES:
1741 case MAP_COMPOSITE|MAP_EXPAND_LIGATURES:
1742 SetLastError(ERROR_INVALID_FLAGS);
1743 return 0;
1744 }
1745
1746 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
1747 {
1748 SetLastError(ERROR_INVALID_PARAMETER);
1749 return 0;
1750 }
1751
1752 ret = wine_fold_string(dwFlags, src, srclen, dst, dstlen);
1753 if (!ret)
1754 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1755 return ret;
1756 }
1757
1758 /******************************************************************************
1759 * CompareStringW (KERNEL32.@)
1760 *
1761 * See CompareStringA.
1762 */
1763 INT WINAPI CompareStringW(LCID lcid, DWORD flags,
1764 LPCWSTR str1, INT len1, LPCWSTR str2, INT len2)
1765 {
1766 static const DWORD supported_flags = NORM_IGNORECASE|NORM_IGNORENONSPACE|NORM_IGNORESYMBOLS|SORT_STRINGSORT
1767 |NORM_IGNOREKANATYPE|NORM_IGNOREWIDTH|LOCALE_USE_CP_ACP
1768 |NORM_LINGUISTIC_CASING|LINGUISTIC_IGNORECASE|0x10000000;
1769 static DWORD semistub_flags = NORM_LINGUISTIC_CASING|LINGUISTIC_IGNORECASE|0x10000000;
1770 /* 0x10000000 is related to diacritics in Arabic, Japanese, and Hebrew */
1771 INT ret;
1772
1773
1774 if (!str1 || !str2)
1775 {
1776 SetLastError(ERROR_INVALID_PARAMETER);
1777 return 0;
1778 }
1779
1780 if (flags & ~supported_flags)
1781 {
1782 SetLastError(ERROR_INVALID_FLAGS);
1783 return 0;
1784 }
1785
1786 if (flags & semistub_flags)
1787 {
1788 FIXME("semi-stub behavior for flag(s) 0x%x\n", flags & semistub_flags);
1789 semistub_flags &= ~flags;
1790 }
1791
1792 if (len1 < 0) len1 = strlenW(str1);
1793 if (len2 < 0) len2 = strlenW(str2);
1794
1795 ret = wine_compare_string(flags, str1, len1, str2, len2);
1796
1797 if (ret) /* need to translate result */
1798 return (ret < 0) ? CSTR_LESS_THAN : CSTR_GREATER_THAN;
1799 return CSTR_EQUAL;
1800 }
1801
1802 /******************************************************************************
1803 * CompareStringA (KERNEL32.@)
1804 *
1805 * Compare two locale sensitive strings.
1806 *
1807 * PARAMS
1808 * lcid [I] LCID for the comparison
1809 * flags [I] Flags for the comparison (NORM_ constants from "winnls.h").
1810 * str1 [I] First string to compare
1811 * len1 [I] Length of str1, or -1 if str1 is NUL terminated
1812 * str2 [I] Second string to compare
1813 * len2 [I] Length of str2, or -1 if str2 is NUL terminated
1814 *
1815 * RETURNS
1816 * Success: CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN depending on whether
1817 * str1 is less than, equal to or greater than str2 respectively.
1818 * Failure: FALSE. Use GetLastError() to determine the cause.
1819 */
1820 INT WINAPI CompareStringA(LCID lcid, DWORD flags,
1821 LPCSTR str1, INT len1, LPCSTR str2, INT len2)
1822 {
1823 WCHAR *buf1W = NtCurrentTeb()->StaticUnicodeBuffer;
1824 WCHAR *buf2W = buf1W + 130;
1825 LPWSTR str1W, str2W;
1826 INT len1W = 0, len2W = 0, ret;
1827 UINT locale_cp = CP_ACP;
1828
1829 if (!str1 || !str2)
1830 {
1831 SetLastError(ERROR_INVALID_PARAMETER);
1832 return 0;
1833 }
1834 if (len1 < 0) len1 = strlen(str1);
1835 if (len2 < 0) len2 = strlen(str2);
1836
1837 if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
1838
1839 if (len1)
1840 {
1841 if (len1 <= 130) len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
1842 if (len1W)
1843 str1W = buf1W;
1844 else
1845 {
1846 len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, NULL, 0);
1847 str1W = HeapAlloc(GetProcessHeap(), 0, len1W * sizeof(WCHAR));
1848 if (!str1W)
1849 {
1850 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1851 return 0;
1852 }
1853 MultiByteToWideChar(locale_cp, 0, str1, len1, str1W, len1W);
1854 }
1855 }
1856 else
1857 {
1858 len1W = 0;
1859 str1W = buf1W;
1860 }
1861
1862 if (len2)
1863 {
1864 if (len2 <= 130) len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
1865 if (len2W)
1866 str2W = buf2W;
1867 else
1868 {
1869 len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, NULL, 0);
1870 str2W = HeapAlloc(GetProcessHeap(), 0, len2W * sizeof(WCHAR));
1871 if (!str2W)
1872 {
1873 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
1874 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1875 return 0;
1876 }
1877 MultiByteToWideChar(locale_cp, 0, str2, len2, str2W, len2W);
1878 }
1879 }
1880 else
1881 {
1882 len2W = 0;
1883 str2W = buf2W;
1884 }
1885
1886 ret = CompareStringW(lcid, flags, str1W, len1W, str2W, len2W);
1887
1888 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
1889 if (str2W != buf2W) HeapFree(GetProcessHeap(), 0, str2W);
1890 return ret;
1891 }
1892
1893 static HANDLE NLS_RegOpenKey(HANDLE hRootKey, LPCWSTR szKeyName)
1894 {
1895 UNICODE_STRING keyName;
1896 OBJECT_ATTRIBUTES attr;
1897 HANDLE hkey;
1898
1899 RtlInitUnicodeString( &keyName, szKeyName );
1900 InitializeObjectAttributes(&attr, &keyName, OBJ_CASE_INSENSITIVE, hRootKey, NULL);
1901
1902 if (NtOpenKey( &hkey, KEY_READ, &attr ) != STATUS_SUCCESS)
1903 hkey = 0;
1904
1905 return hkey;
1906 }
1907
1908 static BOOL NLS_RegEnumValue(HANDLE hKey, UINT ulIndex,
1909 LPWSTR szValueName, ULONG valueNameSize,
1910 LPWSTR szValueData, ULONG valueDataSize)
1911 {
1912 BYTE buffer[80];
1913 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
1914 DWORD dwLen;
1915
1916 if (NtEnumerateValueKey( hKey, ulIndex, KeyValueFullInformation,
1917 buffer, sizeof(buffer), &dwLen ) != STATUS_SUCCESS ||
1918 info->NameLength > valueNameSize ||
1919 info->DataLength > valueDataSize)
1920 {
1921 return FALSE;
1922 }
1923
1924 TRACE("info->Name %s info->DataLength %d\n", debugstr_w(info->Name), info->DataLength);
1925
1926 memcpy( szValueName, info->Name, info->NameLength);
1927 szValueName[info->NameLength / sizeof(WCHAR)] = '\0';
1928 memcpy( szValueData, buffer + info->DataOffset, info->DataLength );
1929 szValueData[info->DataLength / sizeof(WCHAR)] = '\0';
1930
1931 TRACE("returning %s %s\n", debugstr_w(szValueName), debugstr_w(szValueData));
1932 return TRUE;
1933 }
1934
1935 static BOOL NLS_RegGetDword(HANDLE hKey, LPCWSTR szValueName, DWORD *lpVal)
1936 {
1937 BYTE buffer[128];
1938 const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
1939 DWORD dwSize = sizeof(buffer);
1940 UNICODE_STRING valueName;
1941
1942 RtlInitUnicodeString( &valueName, szValueName );
1943
1944 TRACE("%p, %s\n", hKey, debugstr_w(szValueName));
1945 if (NtQueryValueKey( hKey, &valueName, KeyValuePartialInformation,
1946 buffer, dwSize, &dwSize ) == STATUS_SUCCESS &&
1947 info->DataLength == sizeof(DWORD))
1948 {
1949 memcpy(lpVal, info->Data, sizeof(DWORD));
1950 return TRUE;
1951 }
1952
1953 return FALSE;
1954 }
1955
1956 static BOOL NLS_GetLanguageGroupName(LGRPID lgrpid, LPWSTR szName, ULONG nameSize)
1957 {
1958 LANGID langId;
1959 LPCWSTR szResourceName = MAKEINTRESOURCEW(((lgrpid + 0x2000) >> 4) + 1);
1960 HRSRC hResource;
1961 BOOL bRet = FALSE;
1962
1963 /* FIXME: Is it correct to use the system default langid? */
1964 langId = GetSystemDefaultLangID();
1965
1966 if (SUBLANGID(langId) == SUBLANG_NEUTRAL)
1967 langId = MAKELANGID( PRIMARYLANGID(langId), SUBLANG_DEFAULT );
1968
1969 hResource = FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING, szResourceName, langId );
1970
1971 if (hResource)
1972 {
1973 HGLOBAL hResDir = LoadResource( kernel32_handle, hResource );
1974
1975 if (hResDir)
1976 {
1977 ULONG iResourceIndex = lgrpid & 0xf;
1978 LPCWSTR lpResEntry = LockResource( hResDir );
1979 ULONG i;
1980
1981 for (i = 0; i < iResourceIndex; i++)
1982 lpResEntry += *lpResEntry + 1;
1983
1984 if (*lpResEntry < nameSize)
1985 {
1986 memcpy( szName, lpResEntry + 1, *lpResEntry * sizeof(WCHAR) );
1987 szName[*lpResEntry] = '\0';
1988 bRet = TRUE;
1989 }
1990
1991 }
1992 FreeResource( hResource );
1993 }
1994 return bRet;
1995 }
1996
1997 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
1998 typedef struct
1999 {
2000 LANGUAGEGROUP_ENUMPROCA procA;
2001 LANGUAGEGROUP_ENUMPROCW procW;
2002 DWORD dwFlags;
2003 LONG_PTR lParam;
2004 } ENUMLANGUAGEGROUP_CALLBACKS;
2005
2006 /* Internal implementation of EnumSystemLanguageGroupsA/W */
2007 static BOOL NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS *lpProcs)
2008 {
2009 WCHAR szNumber[10], szValue[4];
2010 HANDLE hKey;
2011 BOOL bContinue = TRUE;
2012 ULONG ulIndex = 0;
2013
2014 if (!lpProcs)
2015 {
2016 SetLastError(ERROR_INVALID_PARAMETER);
2017 return FALSE;
2018 }
2019
2020 switch (lpProcs->dwFlags)
2021 {
2022 case 0:
2023 /* Default to LGRPID_INSTALLED */
2024 lpProcs->dwFlags = LGRPID_INSTALLED;
2025 /* Fall through... */
2026 case LGRPID_INSTALLED:
2027 case LGRPID_SUPPORTED:
2028 break;
2029 default:
2030 SetLastError(ERROR_INVALID_FLAGS);
2031 return FALSE;
2032 }
2033
2034 hKey = NLS_RegOpenKey( 0, szLangGroupsKeyName );
2035
2036 if (!hKey)
2037 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2038
2039 while (bContinue)
2040 {
2041 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
2042 szValue, sizeof(szValue) ))
2043 {
2044 BOOL bInstalled = szValue[0] == '1' ? TRUE : FALSE;
2045 LGRPID lgrpid = strtoulW( szNumber, NULL, 16 );
2046
2047 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber),
2048 bInstalled ? "" : "not ");
2049
2050 if (lpProcs->dwFlags == LGRPID_SUPPORTED || bInstalled)
2051 {
2052 WCHAR szGrpName[48];
2053
2054 if (!NLS_GetLanguageGroupName( lgrpid, szGrpName, sizeof(szGrpName) / sizeof(WCHAR) ))
2055 szGrpName[0] = '\0';
2056
2057 if (lpProcs->procW)
2058 bContinue = lpProcs->procW( lgrpid, szNumber, szGrpName, lpProcs->dwFlags,
2059 lpProcs->lParam );
2060 else
2061 {
2062 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
2063 char szGrpNameA[48];
2064
2065 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
2066 * or whether the language names are ever localised. Assume CP_ACP.
2067 */
2068
2069 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
2070 WideCharToMultiByte(CP_ACP, 0, szGrpName, -1, szGrpNameA, sizeof(szGrpNameA), 0, 0);
2071
2072 bContinue = lpProcs->procA( lgrpid, szNumberA, szGrpNameA, lpProcs->dwFlags,
2073 lpProcs->lParam );
2074 }
2075 }
2076
2077 ulIndex++;
2078 }
2079 else
2080 bContinue = FALSE;
2081
2082 if (!bContinue)
2083 break;
2084 }
2085
2086 if (hKey)
2087 NtClose( hKey );
2088
2089 return TRUE;
2090 }
2091
2092 /******************************************************************************
2093 * EnumSystemLanguageGroupsA (KERNEL32.@)
2094 *
2095 * Call a users function for each language group available on the system.
2096 *
2097 * PARAMS
2098 * pLangGrpEnumProc [I] Callback function to call for each language group
2099 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
2100 * lParam [I] User parameter to pass to pLangGrpEnumProc
2101 *
2102 * RETURNS
2103 * Success: TRUE.
2104 * Failure: FALSE. Use GetLastError() to determine the cause.
2105 */
2106 BOOL WINAPI EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc,
2107 DWORD dwFlags, LONG_PTR lParam)
2108 {
2109 ENUMLANGUAGEGROUP_CALLBACKS procs;
2110
2111 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
2112
2113 procs.procA = pLangGrpEnumProc;
2114 procs.procW = NULL;
2115 procs.dwFlags = dwFlags;
2116 procs.lParam = lParam;
2117
2118 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
2119 }
2120
2121 /******************************************************************************
2122 * EnumSystemLanguageGroupsW (KERNEL32.@)
2123 *
2124 * See EnumSystemLanguageGroupsA.
2125 */
2126 BOOL WINAPI EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc,
2127 DWORD dwFlags, LONG_PTR lParam)
2128 {
2129 ENUMLANGUAGEGROUP_CALLBACKS procs;
2130
2131 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
2132
2133 procs.procA = NULL;
2134 procs.procW = pLangGrpEnumProc;
2135 procs.dwFlags = dwFlags;
2136 procs.lParam = lParam;
2137
2138 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
2139 }
2140
2141 /******************************************************************************
2142 * IsValidLanguageGroup (KERNEL32.@)
2143 *
2144 * Determine if a language group is supported and/or installed.
2145 *
2146 * PARAMS
2147 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
2148 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
2149 *
2150 * RETURNS
2151 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
2152 * FALSE otherwise.
2153 */
2154 BOOL WINAPI IsValidLanguageGroup(LGRPID lgrpid, DWORD dwFlags)
2155 {
2156 static const WCHAR szFormat[] = { '%','x','\0' };
2157 WCHAR szValueName[16], szValue[2];
2158 BOOL bSupported = FALSE, bInstalled = FALSE;
2159 HANDLE hKey;
2160
2161
2162 switch (dwFlags)
2163 {
2164 case LGRPID_INSTALLED:
2165 case LGRPID_SUPPORTED:
2166
2167 hKey = NLS_RegOpenKey( 0, szLangGroupsKeyName );
2168
2169 sprintfW( szValueName, szFormat, lgrpid );
2170
2171 if (NLS_RegGetDword( hKey, szValueName, (LPDWORD)szValue ))
2172 {
2173 bSupported = TRUE;
2174
2175 if (szValue[0] == '1')
2176 bInstalled = TRUE;
2177 }
2178
2179 if (hKey)
2180 NtClose( hKey );
2181
2182 break;
2183 }
2184
2185 if ((dwFlags == LGRPID_SUPPORTED && bSupported) ||
2186 (dwFlags == LGRPID_INSTALLED && bInstalled))
2187 return TRUE;
2188
2189 return FALSE;
2190 }
2191
2192 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
2193 typedef struct
2194 {
2195 LANGGROUPLOCALE_ENUMPROCA procA;
2196 LANGGROUPLOCALE_ENUMPROCW procW;
2197 DWORD dwFlags;
2198 LGRPID lgrpid;
2199 LONG_PTR lParam;
2200 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS;
2201
2202 /* Internal implementation of EnumLanguageGrouplocalesA/W */
2203 static BOOL NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS *lpProcs)
2204 {
2205 static const WCHAR szAlternateSortsKeyName[] = {
2206 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
2207 };
2208 WCHAR szNumber[10], szValue[4];
2209 HANDLE hKey;
2210 BOOL bContinue = TRUE, bAlternate = FALSE;
2211 LGRPID lgrpid;
2212 ULONG ulIndex = 1; /* Ignore default entry of 1st key */
2213
2214 if (!lpProcs || !lpProcs->lgrpid || lpProcs->lgrpid > LGRPID_ARMENIAN)
2215 {
2216 SetLastError(ERROR_INVALID_PARAMETER);
2217 return FALSE;
2218 }
2219
2220 if (lpProcs->dwFlags)
2221 {
2222 SetLastError(ERROR_INVALID_FLAGS);
2223 return FALSE;
2224 }
2225
2226 hKey = NLS_RegOpenKey( 0, szLocaleKeyName );
2227
2228 if (!hKey)
2229 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2230
2231 while (bContinue)
2232 {
2233 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
2234 szValue, sizeof(szValue) ))
2235 {
2236 lgrpid = strtoulW( szValue, NULL, 16 );
2237
2238 TRACE("lcid %s, grpid %d (%smatched)\n", debugstr_w(szNumber),
2239 lgrpid, lgrpid == lpProcs->lgrpid ? "" : "not ");
2240
2241 if (lgrpid == lpProcs->lgrpid)
2242 {
2243 LCID lcid;
2244
2245 lcid = strtoulW( szNumber, NULL, 16 );
2246
2247 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
2248 * '00000437 ;Georgian'
2249 * At present we only pass the LCID string.
2250 */
2251
2252 if (lpProcs->procW)
2253 bContinue = lpProcs->procW( lgrpid, lcid, szNumber, lpProcs->lParam );
2254 else
2255 {
2256 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
2257
2258 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
2259
2260 bContinue = lpProcs->procA( lgrpid, lcid, szNumberA, lpProcs->lParam );
2261 }
2262 }
2263
2264 ulIndex++;
2265 }
2266 else
2267 {
2268 /* Finished enumerating this key */
2269 if (!bAlternate)
2270 {
2271 /* Enumerate alternate sorts also */
2272 hKey = NLS_RegOpenKey( hKey, szAlternateSortsKeyName );
2273 bAlternate = TRUE;
2274 ulIndex = 0;
2275 }
2276 else
2277 bContinue = FALSE; /* Finished both keys */
2278 }
2279
2280 if (!bContinue)
2281 break;
2282 }
2283
2284 if (hKey)
2285 NtClose( hKey );
2286
2287 return TRUE;
2288 }
2289
2290 enum locationkind {
2291 LOCATION_NATION = 0,
2292 LOCATION_REGION,
2293 LOCATION_BOTH
2294 };
2295
2296 struct geoinfo_t {
2297 GEOID id;
2298 WCHAR iso2W[3];
2299 WCHAR iso3W[4];
2300 GEOID parent;
2301 INT uncode;
2302 enum locationkind kind;
2303 };
2304
2305 static const struct geoinfo_t geoinfodata[] = {
2306 { 2, {'A','G',0}, {'A','T','G',0}, 10039880, 28 }, /* Antigua and Barbuda */
2307 { 3, {'A','F',0}, {'A','F','G',0}, 47614, 4 }, /* Afghanistan */
2308 { 4, {'D','Z',0}, {'D','Z','A',0}, 42487, 12 }, /* Algeria */
2309 { 5, {'A','Z',0}, {'A','Z','E',0}, 47611, 31 }, /* Azerbaijan */
2310 { 6, {'A','L',0}, {'A','L','B',0}, 47610, 8 }, /* Albania */
2311 { 7, {'A','M',0}, {'A','R','M',0}, 47611, 51 }, /* Armenia */
2312 { 8, {'A','D',0}, {'A','N','D',0}, 47610, 20 }, /* Andorra */
2313 { 9, {'A','O',0}, {'A','G','O',0}, 42484, 24 }, /* Angola */
2314 { 10, {'A','S',0}, {'A','S','M',0}, 26286, 16 }, /* American Samoa */
2315 { 11, {'A','R',0}, {'A','R','G',0}, 31396, 32 }, /* Argentina */
2316 { 12, {'A','U',0}, {'A','U','S',0}, 10210825, 36 }, /* Australia */
2317 { 14, {'A','T',0}, {'A','U','T',0}, 10210824, 40 }, /* Austria */
2318 { 17, {'B','H',0}, {'B','H','R',0}, 47611, 48 }, /* Bahrain */
2319 { 18, {'B','B',0}, {'B','R','B',0}, 10039880, 52 }, /* Barbados */
2320 { 19, {'B','W',0}, {'B','W','A',0}, 10039883, 72 }, /* Botswana */
2321 { 20, {'B','M',0}, {'B','M','U',0}, 23581, 60 }, /* Bermuda */
2322 { 21, {'B','E',0}, {'B','E','L',0}, 10210824, 56 }, /* Belgium */
2323 { 22, {'B','S',0}, {'B','H','S',0}, 10039880, 44 }, /* Bahamas, The */
2324 { 23, {'B','D',0}, {'B','G','D',0}, 47614, 50 }, /* Bangladesh */
2325 { 24, {'B','Z',0}, {'B','L','Z',0}, 27082, 84 }, /* Belize */
2326 { 25, {'B','A',0}, {'B','I','H',0}, 47610, 70 }, /* Bosnia and Herzegovina */
2327 { 26, {'B','O',0}, {'B','O','L',0}, 31396, 68 }, /* Bolivia */
2328 { 27, {'M','M',0}, {'M','M','R',0}, 47599, 104 }, /* Myanmar */
2329 { 28, {'B','J',0}, {'B','E','N',0}, 42483, 204 }, /* Benin */
2330 { 29, {'B','Y',0}, {'B','L','R',0}, 47609, 112 }, /* Belarus */
2331 { 30, {'S','B',0}, {'S','L','B',0}, 20900, 90 }, /* Solomon Islands */
2332 { 32, {'B','R',0}, {'B','R','A',0}, 31396, 76 }, /* Brazil */
2333 { 34, {'B','T',0}, {'B','T','N',0}, 47614, 64 }, /* Bhutan */
2334 { 35, {'B','G',0}, {'B','G','R',0}, 47609, 100 }, /* Bulgaria */
2335 { 37, {'B','N',0}, {'B','R','N',0}, 47599, 96 }, /* Brunei */
2336 { 38, {'B','I',0}, {'B','D','I',0}, 47603, 108 }, /* Burundi */
2337 { 39, {'C','A',0}, {'C','A','N',0}, 23581, 124 }, /* Canada */
2338 { 40, {'K','H',0}, {'K','H','M',0}, 47599, 116 }, /* Cambodia */
2339 { 41, {'T','D',0}, {'T','C','D',0}, 42484, 148 }, /* Chad */
2340 { 42, {'L','K',0}, {'L','K','A',0}, 47614, 144 }, /* Sri Lanka */
2341 { 43, {'C','G',0}, {'C','O','G',0}, 42484, 178 }, /* Congo */
2342 { 44, {'C','D',0}, {'C','O','D',0}, 42484, 180 }, /* Congo (DRC) */
2343 { 45, {'C','N',0}, {'C','H','N',0}, 47600, 156 }, /* China */
2344 { 46, {'C','L',0}, {'C','H','L',0}, 31396, 152 }, /* Chile */
2345 { 49, {'C','M',0}, {'C','M','R',0}, 42484, 120 }, /* Cameroon */
2346 { 50, {'K','M',0}, {'C','O','M',0}, 47603, 174 }, /* Comoros */
2347 { 51, {'C','O',0}, {'C','O','L',0}, 31396, 170 }, /* Colombia */
2348 { 54, {'C','R',0}, {'C','R','I',0}, 27082, 188 }, /* Costa Rica */
2349 { 55, {'C','F',0}, {'C','A','F',0}, 42484, 140 }, /* Central African Republic */
2350 { 56, {'C','U',0}, {'C','U','B',0}, 10039880, 192 }, /* Cuba */
2351 { 57, {'C','V',0}, {'C','P','V',0}, 42483, 132 }, /* Cape Verde */
2352 { 59, {'C','Y',0}, {'C','Y','P',0}, 47611, 196 }, /* Cyprus */
2353 { 61, {'D','K',0}, {'D','N','K',0}, 10039882, 208 }, /* Denmark */
2354 { 62, {'D','J',0}, {'D','J','I',0}, 47603, 262 }, /* Djibouti */
2355 { 63, {'D','M',0}, {'D','M','A',0}, 10039880, 212 }, /* Dominica */
2356 { 65, {'D','O',0}, {'D','O','M',0}, 10039880, 214 }, /* Dominican Republic */
2357 { 66, {'E','C',0}, {'E','C','U',0}, 31396, 218 }, /* Ecuador */
2358 { 67, {'E','G',0}, {'E','G','Y',0}, 42487, 818 }, /* Egypt */
2359 { 68, {'I','E',0}, {'I','R','L',0}, 10039882, 372 }, /* Ireland */
2360 { 69, {'G','Q',0}, {'G','N','Q',0}, 42484, 226 }, /* Equatorial Guinea */
2361 { 70, {'E','E',0}, {'E','S','T',0}, 10039882, 233 }, /* Estonia */
2362 { 71, {'E','R',0}, {'E','R','I',0}, 47603, 232 }, /* Eritrea */
2363 { 72, {'S','V',0}, {'S','L','V',0}, 27082, 222 }, /* El Salvador */
2364 { 73, {'E','T',0}, {'E','T','H',0}, 47603, 231 }, /* Ethiopia */
2365 { 75, {'C','Z',0}, {'C','Z','E',0}, 47609, 203 }, /* Czech Republic */
2366 { 77, {'F','I',0}, {'F','I','N',0}, 10039882, 246 }, /* Finland */
2367 { 78, {'F','J',0}, {'F','J','I',0}, 20900, 242 }, /* Fiji Islands */
2368 { 80, {'F','M',0}, {'F','S','M',0}, 21206, 583 }, /* Micronesia */
2369 { 81, {'F','O',0}, {'F','R','O',0}, 10039882, 234 }, /* Faroe Islands */
2370 { 84, {'F','R',0}, {'F','R','A',0}, 10210824, 250 }, /* France */
2371 { 86, {'G','M',0}, {'G','M','B',0}, 42483, 270 }, /* Gambia, The */
2372 { 87, {'G','A',0}, {'G','A','B',0}, 42484, 266 }, /* Gabon */
2373 { 88, {'G','E',0}, {'G','E','O',0}, 47611, 268 }, /* Georgia */
2374 { 89, {'G','H',0}, {'G','H','A',0}, 42483, 288 }, /* Ghana */
2375 { 90, {'G','I',0}, {'G','I','B',0}, 47610, 292 }, /* Gibraltar */
2376 { 91, {'G','D',0}, {'G','R','D',0}, 10039880, 308 }, /* Grenada */
2377 { 93, {'G','L',0}, {'G','R','L',0}, 23581, 304 }, /* Greenland */
2378 { 94, {'D','E',0}, {'D','E','U',0}, 10210824, 276 }, /* Germany */
2379 { 98, {'G','R',0}, {'G','R','C',0}, 47610, 300 }, /* Greece */
2380 { 99, {'G','T',0}, {'G','T','M',0}, 27082, 320 }, /* Guatemala */
2381 { 100, {'G','N',0}, {'G','I','N',0}, 42483, 324 }, /* Guinea */
2382 { 101, {'G','Y',0}, {'G','U','Y',0}, 31396, 328 }, /* Guyana */
2383 { 103, {'H','T',0}, {'H','T','I',0}, 10039880, 332 }, /* Haiti */
2384 { 104, {'H','K',0}, {'H','K','G',0}, 47600, 344 }, /* Hong Kong S.A.R. */
2385 { 106, {'H','N',0}, {'H','N','D',0}, 27082, 340 }, /* Honduras */
2386 { 108, {'H','R',0}, {'H','R','V',0}, 47610, 191 }, /* Croatia */
2387 { 109, {'H','U',0}, {'H','U','N',0}, 47609, 348 }, /* Hungary */
2388 { 110, {'I','S',0}, {'I','S','L',0}, 10039882, 352 }, /* Iceland */
2389 { 111, {'I','D',0}, {'I','D','N',0}, 47599, 360 }, /* Indonesia */
2390 { 113, {'I','N',0}, {'I','N','D',0}, 47614, 356 }, /* India */
2391 { 114, {'I','O',0}, {'I','O','T',0}, 39070, 86 }, /* British Indian Ocean Territory */
2392 { 116, {'I','R',0}, {'I','R','N',0}, 47614, 364 }, /* Iran */
2393 { 117, {'I','L',0}, {'I','S','R',0}, 47611, 376 }, /* Israel */
2394 { 118, {'I','T',0}, {'I','T','A',0}, 47610, 380 }, /* Italy */
2395 { 119, {'C','I',0}, {'C','I','V',0}, 42483, 384 }, /* Côte d'Ivoire */
2396 { 121, {'I','Q',0}, {'I','R','Q',0}, 47611, 368 }, /* Iraq */
2397 { 122, {'J','P',0}, {'J','P','N',0}, 47600, 392 }, /* Japan */
2398 { 124, {'J','M',0}, {'J','A','M',0}, 10039880, 388 }, /* Jamaica */
2399 { 125, {'S','J',0}, {'S','J','M',0}, 10039882, 744 }, /* Jan Mayen */
2400 { 126, {'J','O',0}, {'J','O','R',0}, 47611, 400 }, /* Jordan */
2401 { 127, {'X','X',0}, {'X','X',0}, 161832256 }, /* Johnston Atoll */
2402 { 129, {'K','E',0}, {'K','E','N',0}, 47603, 404 }, /* Kenya */
2403 { 130, {'K','G',0}, {'K','G','Z',0}, 47590, 417 }, /* Kyrgyzstan */
2404 { 131, {'K','P',0}, {'P','R','K',0}, 47600, 408 }, /* North Korea */
2405 { 133, {'K','I',0}, {'K','I','R',0}, 21206, 296 }, /* Kiribati */
2406 { 134, {'K','R',0}, {'K','O','R',0}, 47600, 410 }, /* Korea */
2407 { 136, {'K','W',0}, {'K','W','T',0}, 47611, 414 }, /* Kuwait */
2408 { 137, {'K','Z',0}, {'K','A','Z',0}, 47590, 398 }, /* Kazakhstan */
2409 { 138, {'L','A',0}, {'L','A','O',0}, 47599, 418 }, /* Laos */
2410 { 139, {'L','B',0}, {'L','B','N',0}, 47611, 422 }, /* Lebanon */
2411 { 140, {'L','V',0}, {'L','V','A',0}, 10039882, 428 }, /* Latvia */
2412 { 141, {'L','T',0}, {'L','T','U',0}, 10039882, 440 }, /* Lithuania */
2413 { 142, {'L','R',0}, {'L','B','R',0}, 42483, 430 }, /* Liberia */
2414 { 143, {'S','K',0}, {'S','V','K',0}, 47609, 703 }, /* Slovakia */
2415 { 145, {'L','I',0}, {'L','I','E',0}, 10210824, 438 }, /* Liechtenstein */
2416 { 146, {'L','S',0}, {'L','S','O',0}, 10039883, 426 }, /* Lesotho */
2417 { 147, {'L','U',0}, {'L','U','X',0}, 10210824, 442 }, /* Luxembourg */
2418 { 148, {'L','Y',0}, {'L','B','Y',0}, 42487, 434 }, /* Libya */
2419 { 149, {'M','G',0}, {'M','D','G',0}, 47603, 450 }, /* Madagascar */
2420 { 151, {'M','O',0}, {'M','A','C',0}, 47600, 446 }, /* Macao S.A.R. */
2421 { 152, {'M','D',0}, {'M','D','A',0}, 47609, 498 }, /* Moldova */
2422 { 154, {'M','N',0}, {'M','N','G',0}, 47600, 496 }, /* Mongolia */
2423 { 156, {'M','W',0}, {'M','W','I',0}, 47603, 454 }, /* Malawi */
2424 { 157, {'M','L',0}, {'M','L','I',0}, 42483, 466 }, /* Mali */
2425 { 158, {'M','C',0}, {'M','C','O',0}, 10210824, 492 }, /* Monaco */
2426 { 159, {'M','A',0}, {'M','A','R',0}, 42487, 504 }, /* Morocco */
2427 { 160, {'M','U',0}, {'M','U','S',0}, 47603, 480 }, /* Mauritius */
2428 { 162, {'M','R',0}, {'M','R','T',0}, 42483, 478 }, /* Mauritania */
2429 { 163, {'M','T',0}, {'M','L','T',0}, 47610, 470 }, /* Malta */
2430 { 164, {'O','M',0}, {'O','M','N',0}, 47611, 512 }, /* Oman */
2431 { 165, {'M','V',0}, {'M','D','V',0}, 47614, 462 }, /* Maldives */
2432 { 166, {'M','X',0}, {'M','E','X',0}, 27082, 484 }, /* Mexico */
2433 { 167, {'M','Y',0}, {'M','Y','S',0}, 47599, 458 }, /* Malaysia */
2434 { 168, {'M','Z',0}, {'M','O','Z',0}, 47603, 508 }, /* Mozambique */
2435 { 173, {'N','E',0}, {'N','E','R',0}, 42483, 562 }, /* Niger */
2436 { 174, {'V','U',0}, {'V','U','T',0}, 20900, 548 }, /* Vanuatu */
2437 { 175, {'N','G',0}, {'N','G','A',0}, 42483, 566 }, /* Nigeria */
2438 { 176, {'N','L',0}, {'N','L','D',0}, 10210824, 528 }, /* Netherlands */
2439 { 177, {'N','O',0}, {'N','O','R',0}, 10039882, 578 }, /* Norway */
2440 { 178, {'N','P',0}, {'N','P','L',0}, 47614, 524 }, /* Nepal */
2441 { 180, {'N','R',0}, {'N','R','U',0}, 21206, 520 }, /* Nauru */
2442 { 181, {'S','R',0}, {'S','U','R',0}, 31396, 740 }, /* Suriname */
2443 { 182, {'N','I',0}, {'N','I','C',0}, 27082, 558 }, /* Nicaragua */
2444 { 183, {'N','Z',0}, {'N','Z','L',0}, 10210825, 554 }, /* New Zealand */
2445 { 184, {'P','S',0}, {'P','S','E',0}, 47611, 275 }, /* Palestinian Authority */
2446 { 185, {'P','Y',0}, {'P','R','Y',0}, 31396, 600 }, /* Paraguay */
2447 { 187, {'P','E',0}, {'P','E','R',0}, 31396, 604 }, /* Peru */
2448 { 190, {'P','K',0}, {'P','A','K',0}, 47614, 586 }, /* Pakistan */
2449 { 191, {'P','L',0}, {'P','O','L',0}, 47609, 616 }, /* Poland */
2450 { 192, {'P','A',0}, {'P','A','N',0}, 27082, 591 }, /* Panama */
2451 { 193, {'P','T',0}, {'P','R','T',0}, 47610, 620 }, /* Portugal */
2452 { 194, {'P','G',0}, {'P','N','G',0}, 20900, 598 }, /* Papua New Guinea */
2453 { 195, {'P','W',0}, {'P','L','W',0}, 21206, 585 }, /* Palau */
2454 { 196, {'G','W',0}, {'G','N','B',0}, 42483, 624 }, /* Guinea-Bissau */
2455 { 197, {'Q','A',0}, {'Q','A','T',0}, 47611, 634 }, /* Qatar */
2456 { 198, {'R','E',0}, {'R','E','U',0}, 47603, 638 }, /* Reunion */
2457 { 199, {'M','H',0}, {'M','H','L',0}, 21206, 584 }, /* Marshall Islands */
2458 { 200, {'R','O',0}, {'R','O','U',0}, 47609, 642 }, /* Romania */
2459 { 201, {'P','H',0}, {'P','H','L',0}, 47599, 608 }, /* Philippines */
2460 { 202, {'P','R',0}, {'P','R','I',0}, 10039880, 630 }, /* Puerto Rico */
2461 { 203, {'R','U',0}, {'R','U','S',0}, 47609, 643 }, /* Russia */
2462 { 204, {'R','W',0}, {'R','W','A',0}, 47603, 646 }, /* Rwanda */
2463 { 205, {'S','A',0}, {'S','A','U',0}, 47611, 682 }, /* Saudi Arabia */
2464 { 206, {'P','M',0}, {'S','P','M',0}, 23581, 666 }, /* St. Pierre and Miquelon */
2465 { 207, {'K','N',0}, {'K','N','A',0}, 10039880, 659 }, /* St. Kitts and Nevis */
2466 { 208, {'S','C',0}, {'S','Y','C',0}, 47603, 690 }, /* Seychelles */
2467 { 209, {'Z','A',0}, {'Z','A','F',0}, 10039883, 710 }, /* South Africa */
2468 { 210, {'S','N',0}, {'S','E','N',0}, 42483, 686 }, /* Senegal */
2469 { 212, {'S','I',0}, {'S','V','N',0}, 47610, 705 }, /* Slovenia */
2470 { 213, {'S','L',0}, {'S','L','E',0}, 42483, 694 }, /* Sierra Leone */
2471 { 214, {'S','M',0}, {'S','M','R',0}, 47610, 674 }, /* San Marino */
2472 { 215, {'S','G',0}, {'S','G','P',0}, 47599, 702 }, /* Singapore */
2473 { 216, {'S','O',0}, {'S','O','M',0}, 47603, 706 }, /* Somalia */
2474 { 217, {'E','S',0}, {'E','S','P',0}, 47610, 724 }, /* Spain */
2475 { 218, {'L','C',0}, {'L','C','A',0}, 10039880, 662 }, /* St. Lucia */
2476 { 219, {'S','D',0}, {'S','D','N',0}, 42487, 736 }, /* Sudan */
2477 { 220, {'S','J',0}, {'S','J','M',0}, 10039882, 744 }, /* Svalbard */
2478 { 221, {'S','E',0}, {'S','W','E',0}, 10039882, 752 }, /* Sweden */
2479 { 222, {'S','Y',0}, {'S','Y','R',0}, 47611, 760 }, /* Syria */
2480 { 223, {'C','H',0}, {'C','H','E',0}, 10210824, 756 }, /* Switzerland */
2481 { 224, {'A','E',0}, {'A','R','E',0}, 47611, 784 }, /* United Arab Emirates */
2482 { 225, {'T','T',0}, {'T','T','O',0}, 10039880, 780 }, /* Trinidad and Tobago */
2483 { 227, {'T','H',0}, {'T','H','A',0}, 47599, 764 }, /* Thailand */
2484 { 228, {'T','J',0}, {'T','J','K',0}, 47590, 762 }, /* Tajikistan */
2485 { 231, {'T','O',0}, {'T','O','N',0}, 26286, 776 }, /* Tonga */
2486 { 232, {'T','G',0}, {'T','G','O',0}, 42483, 768 }, /* Togo */
2487 { 233, {'S','T',0}, {'S','T','P',0}, 42484, 678 }, /* São Tomé and Príncipe */
2488 { 234, {'T','N',0}, {'T','U','N',0}, 42487, 788 }, /* Tunisia */
2489 { 235, {'T','R',0}, {'T','U','R',0}, 47611, 792 }, /* Turkey */
2490 { 236, {'T','V',0}, {'T','U','V',0}, 26286, 798 }, /* Tuvalu */
2491 { 237, {'T','W',0}, {'T','W','N',0}, 47600, 158 }, /* Taiwan */
2492 { 238, {'T','M',0}, {'T','K','M',0}, 47590, 795 }, /* Turkmenistan */
2493 { 239, {'T','Z',0}, {'T','Z','A',0}, 47603, 834 }, /* Tanzania */
2494 { 240, {'U','G',0}, {'U','G','A',0}, 47603, 800 }, /* Uganda */
2495 { 241, {'U','A',0}, {'U','K','R',0}, 47609, 804 }, /* Ukraine */
2496 { 242, {'G','B',0}, {'G','B','R',0}, 10039882, 826 }, /* United Kingdom */
2497 { 244, {'U','S',0}, {'U','S','A',0}, 23581, 840 }, /* United States */
2498 { 245, {'B','F',0}, {'B','F','A',0}, 42483, 854 }, /* Burkina Faso */
2499 { 246, {'U','Y',0}, {'U','R','Y',0}, 31396, 858 }, /* Uruguay */
2500 { 247, {'U','Z',0}, {'U','Z','B',0}, 47590, 860 }, /* Uzbekistan */
2501 { 248, {'V','C',0}, {'V','C','T',0}, 10039880, 670 }, /* St. Vincent and the Grenadines */
2502 { 249, {'V','E',0}, {'V','E','N',0}, 31396, 862 }, /* Bolivarian Republic of Venezuela */
2503 { 251, {'V','N',0}, {'V','N','M',0}, 47599, 704 }, /* Vietnam */
2504 { 252, {'V','I',0}, {'V','I','R',0}, 10039880, 850 }, /* Virgin Islands */
2505 { 253, {'V','A',0}, {'V','A','T',0}, 47610, 336 }, /* Vatican City */
2506 { 254, {'N','A',0}, {'N','A','M',0}, 10039883, 516 }, /* Namibia */
2507 { 257, {'E','H',0}, {'E','S','H',0}, 42487, 732 }, /* Western Sahara (disputed) */
2508 { 258, {'X','X',0}, {'X','X',0}, 161832256 }, /* Wake Island */
2509 { 259, {'W','S',0}, {'W','S','M',0}, 26286, 882 }, /* Samoa */
2510 { 260, {'S','Z',0}, {'S','W','Z',0}, 10039883, 748 }, /* Swaziland */
2511 { 261, {'Y','E',0}, {'Y','E','M',0}, 47611, 887 }, /* Yemen */
2512 { 263, {'Z','M',0}, {'Z','M','B',0}, 47603, 894 }, /* Zambia */
2513 { 264, {'Z','W',0}, {'Z','W','E',0}, 47603, 716 }, /* Zimbabwe */
2514 { 269, {'C','S',0}, {'S','C','G',0}, 47610, 891 }, /* Serbia and Montenegro (Former) */
2515 { 270, {'M','E',0}, {'M','N','E',0}, 47610, 499 }, /* Montenegro */
2516 { 271, {'R','S',0}, {'S','R','B',0}, 47610, 688 }, /* Serbia */
2517 { 273, {'C','W',0}, {'C','U','W',0}, 10039880, 531 }, /* Curaçao */
2518 { 276, {'S','S',0}, {'S','S','D',0}, 42487, 728 }, /* South Sudan */
2519 { 300, {'A','I',0}, {'A','I','A',0}, 10039880, 660 }, /* Anguilla */
2520 { 301, {'A','Q',0}, {'A','T','A',0}, 39070, 10 }, /* Antarctica */
2521 { 302, {'A','W',0}, {'A','B','W',0}, 10039880, 533 }, /* Aruba */
2522 { 303, {'X','X',0}, {'X','X',0}, 39070 }, /* Ascension Island */
2523 { 304, {'X','X',0}, {'X','X',0}, 10210825 }, /* Ashmore and Cartier Islands */
2524 { 305, {'X','X',0}, {'X','X',0}, 161832256 }, /* Baker Island */
2525 { 306, {'B','V',0}, {'B','V','T',0}, 39070, 74 }, /* Bouvet Island */
2526 { 307, {'K','Y',0}, {'C','Y','M',0}, 10039880, 136 }, /* Cayman Islands */
2527 { 308, {'X','X',0}, {'X','X',0}, 10210824, 0, LOCATION_BOTH }, /* Channel Islands */
2528 { 309, {'C','X',0}, {'C','X','R',0}, 12, 162 }, /* Christmas Island */
2529 { 310, {'X','X',0}, {'X','X',0}, 27114 }, /* Clipperton Island */
2530 { 311, {'C','C',0}, {'C','C','K',0}, 10210825, 166 }, /* Cocos (Keeling) Islands */
2531 { 312, {'C','K',0}, {'C','O','K',0}, 26286, 184 }, /* Cook Islands */
2532 { 313, {'X','X',0}, {'X','X',0}, 10210825 }, /* Coral Sea Islands */
2533 { 314, {'X','X',0}, {'X','X',0}, 114 }, /* Diego Garcia */
2534 { 315, {'F','K',0}, {'F','L','K',0}, 31396, 238 }, /* Falkland Islands (Islas Malvinas) */
2535 { 317, {'G','F',0}, {'G','U','F',0}, 31396, 254 }, /* French Guiana */
2536 { 318, {'P','F',0}, {'P','Y','F',0}, 26286, 258 }, /* French Polynesia */
2537 { 319, {'T','F',0}, {'A','T','F',0}, 39070, 260 }, /* French Southern and Antarctic Lands */
2538 { 321, {'G','P',0}, {'G','L','P',0}, 10039880, 312 }, /* Guadeloupe */
2539 { 322, {'G','U',0}, {'G','U','M',0}, 21206, 316 }, /* Guam */
2540 { 323, {'X','X',0}, {'X','X',0}, 39070 }, /* Guantanamo Bay */
2541 { 324, {'G','G',0}, {'G','G','Y',0}, 308, 831 }, /* Guernsey */
2542 { 325, {'H','M',0}, {'H','M','D',0}, 39070, 334 }, /* Heard Island and McDonald Islands */
2543 { 326, {'X','X',0}, {'X','X',0}, 161832256 }, /* Howland Island */