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
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.
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.
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
30 #include "lcformat_private.h"
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 */
39 extern HMODULE kernel32_handle
;
41 #define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|\
42 LOCALE_RETURN_NUMBER|LOCALE_RETURN_GENITIVE_NAMES)
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
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
60 /* Charset to codepage map, sorted by name. */
61 static const struct charset_entry
63 const char *charset_name
;
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 },
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 */
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
;
146 /* Copy Ascii string to Unicode without using codepages */
147 static inline void strcpynAtoW( WCHAR
*dst
, const char *src
, size_t n
)
149 while (n
> 1 && *src
)
151 *dst
++ = (unsigned char)*src
++;
158 /***********************************************************************
161 * Retrieve the ANSI codepage for a given locale.
163 static inline UINT
get_lcid_codepage( LCID lcid
)
166 if (!GetLocaleInfoW( lcid
, LOCALE_IDEFAULTANSICODEPAGE
|LOCALE_RETURN_NUMBER
, (WCHAR
*)&ret
,
167 sizeof(ret
)/sizeof(WCHAR
) )) ret
= 0;
171 /***********************************************************************
172 * convert_default_lcid
174 * Get the default LCID to use for a given lctype in GetLocaleInfo.
176 static LCID
convert_default_lcid( LCID lcid
, LCTYPE lctype
)
178 if (lcid
== LOCALE_SYSTEM_DEFAULT
||
179 lcid
== LOCALE_USER_DEFAULT
||
180 lcid
== LOCALE_NEUTRAL
)
184 switch(lctype
& 0xffff)
186 case LOCALE_SSORTNAME
:
187 default_id
= lcid_LC_COLLATE
;
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
;
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
;
219 case LOCALE_IDIGITSUBSTITUTION
:
221 case LOCALE_INEGNUMBER
:
222 case LOCALE_SDECIMAL
:
223 case LOCALE_SGROUPING
:
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
;
234 case LOCALE_ICALENDARTYPE
:
235 case LOCALE_ICENTURY
:
237 case LOCALE_IDAYLZERO
:
238 case LOCALE_IFIRSTDAYOFWEEK
:
239 case LOCALE_IFIRSTWEEKOFYEAR
:
241 case LOCALE_IMONLZERO
:
242 case LOCALE_IOPTIONALCALENDAR
:
244 case LOCALE_ITIMEMARKPOSN
:
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
:
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:
300 case LOCALE_STIMEFORMAT
:
301 case LOCALE_SYEARMONTH
:
302 default_id
= lcid_LC_TIME
;
305 case LOCALE_IPAPERSIZE
:
306 default_id
= lcid_LC_PAPER
;
309 case LOCALE_IMEASURE
:
310 default_id
= lcid_LC_MEASUREMENT
;
313 case LOCALE_ICOUNTRY
:
314 default_id
= lcid_LC_TELEPHONE
;
317 if (default_id
) lcid
= default_id
;
319 return ConvertDefaultLocale( lcid
);
322 /***********************************************************************
323 * is_genitive_name_supported
325 * Determine could LCTYPE basically support genitive name form or not.
327 static BOOL
is_genitive_name_supported( LCTYPE lctype
)
329 switch(lctype
& 0xffff)
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
:
350 /***********************************************************************
351 * create_registry_key
353 * Create the Control Panel\\International registry key.
355 static inline HANDLE
create_registry_key(void)
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;
363 if (RtlOpenCurrentUser( KEY_ALL_ACCESS
, &hkey
) != STATUS_SUCCESS
) return 0;
365 attr
.Length
= sizeof(attr
);
366 attr
.RootDirectory
= hkey
;
367 attr
.ObjectName
= &nameW
;
369 attr
.SecurityDescriptor
= NULL
;
370 attr
.SecurityQualityOfService
= NULL
;
371 RtlInitUnicodeString( &nameW
, cplW
);
373 if (!NtCreateKey( &cpl_key
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
))
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;
380 NtClose( attr
.RootDirectory
);
384 /***********************************************************************
385 * GetUserDefaultLangID (KERNEL32.@)
387 * Get the default language Id for the current user.
393 * The current LANGID of the default language for the current user.
395 LANGID WINAPI
GetUserDefaultLangID(void)
397 return LANGIDFROMLCID(GetUserDefaultLCID());
401 /***********************************************************************
402 * GetSystemDefaultLangID (KERNEL32.@)
404 * Get the default language Id for the system.
410 * The current LANGID of the default language for the system.
412 LANGID WINAPI
GetSystemDefaultLangID(void)
414 return LANGIDFROMLCID(GetSystemDefaultLCID());
418 /***********************************************************************
419 * GetUserDefaultLCID (KERNEL32.@)
421 * Get the default locale Id for the current user.
427 * The current LCID of the default locale for the current user.
429 LCID WINAPI
GetUserDefaultLCID(void)
432 NtQueryDefaultLocale( TRUE
, &lcid
);
437 /***********************************************************************
438 * GetSystemDefaultLCID (KERNEL32.@)
440 * Get the default locale Id for the system.
446 * The current LCID of the default locale for the system.
448 LCID WINAPI
GetSystemDefaultLCID(void)
451 NtQueryDefaultLocale( FALSE
, &lcid
);
456 /***********************************************************************
457 * GetUserDefaultUILanguage (KERNEL32.@)
459 * Get the default user interface language Id for the current user.
465 * The current LANGID of the default UI language for the current user.
467 LANGID WINAPI
GetUserDefaultUILanguage(void)
470 NtQueryDefaultUILanguage( &lang
);
475 /***********************************************************************
476 * GetSystemDefaultUILanguage (KERNEL32.@)
478 * Get the default user interface language Id for the system.
484 * The current LANGID of the default UI language for the system. This is
485 * typically the same language used during the installation process.
487 LANGID WINAPI
GetSystemDefaultUILanguage(void)
490 NtQueryInstallUILanguage( &lang
);
494 /******************************************************************************
495 * get_locale_value_name
497 * Gets the registry value name for a given lctype.
499 static const WCHAR
*get_locale_value_name( DWORD lctype
)
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};
543 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
544 * the values are stored in the registry, confirmed under Windows.
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
;
577 /* The following are not listed under MSDN as supported,
578 * but seem to be used and also stored in the registry.
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
;
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
;
596 /******************************************************************************
597 * get_registry_locale_info
599 * Retrieve user-modified locale info from the registry.
600 * Return length, 0 on error, -1 if not found.
602 static INT
get_registry_locale_info( LPCWSTR value
, LPWSTR buffer
, INT len
)
608 UNICODE_STRING nameW
;
609 KEY_VALUE_PARTIAL_INFORMATION
*info
;
610 static const int info_size
= FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION
, Data
);
612 if (!(hkey
= create_registry_key())) return -1;
614 RtlInitUnicodeString( &nameW
, value
);
615 size
= info_size
+ len
* sizeof(WCHAR
);
617 if (!(info
= HeapAlloc( GetProcessHeap(), 0, size
)))
620 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
624 status
= NtQueryValueKey( hkey
, &nameW
, KeyValuePartialInformation
, info
, size
, &size
);
628 ret
= (size
- info_size
) / sizeof(WCHAR
);
629 /* append terminating null if needed */
630 if (!ret
|| ((WCHAR
*)info
->Data
)[ret
-1])
632 if (ret
< len
|| !buffer
) ret
++;
635 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
641 memcpy( buffer
, info
->Data
, (ret
-1) * sizeof(WCHAR
) );
645 else if (status
== STATUS_BUFFER_OVERFLOW
&& !buffer
)
647 ret
= (size
- info_size
) / sizeof(WCHAR
) + 1;
649 else if (status
== STATUS_OBJECT_NAME_NOT_FOUND
)
655 SetLastError( RtlNtStatusToDosError(status
) );
659 HeapFree( GetProcessHeap(), 0, info
);
664 /******************************************************************************
665 * GetLocaleInfoA (KERNEL32.@)
667 * Get information about an aspect of a locale.
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
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.
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.
685 INT WINAPI
GetLocaleInfoA( LCID lcid
, LCTYPE lctype
, LPSTR buffer
, INT len
)
690 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
692 if (len
< 0 || (len
&& !buffer
))
694 SetLastError( ERROR_INVALID_PARAMETER
);
697 if (lctype
& LOCALE_RETURN_GENITIVE_NAMES
)
699 SetLastError( ERROR_INVALID_FLAGS
);
703 if (!len
) buffer
= NULL
;
705 if (!(lenW
= GetLocaleInfoW( lcid
, lctype
, NULL
, 0 ))) return 0;
707 if (!(bufferW
= HeapAlloc( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) )))
709 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
712 if ((ret
= GetLocaleInfoW( lcid
, lctype
, bufferW
, lenW
)))
714 if ((lctype
& LOCALE_RETURN_NUMBER
) ||
715 ((lctype
& ~LOCALE_LOCALEINFOFLAGSMASK
) == LOCALE_FONTSIGNATURE
))
717 /* it's not an ASCII string, just bytes */
718 ret
*= sizeof(WCHAR
);
721 if (ret
<= len
) memcpy( buffer
, bufferW
, ret
);
724 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
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
);
736 HeapFree( GetProcessHeap(), 0, bufferW
);
740 static int get_value_base_by_lctype( LCTYPE lctype
)
742 return lctype
== LOCALE_ILANGUAGE
|| lctype
== LOCALE_IDEFAULTLANGUAGE
? 16 : 10;
745 /******************************************************************************
746 * GetLocaleInfoW (KERNEL32.@)
748 * See GetLocaleInfoA.
750 INT WINAPI
GetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPWSTR buffer
, INT len
)
760 if (len
< 0 || (len
&& !buffer
))
762 SetLastError( ERROR_INVALID_PARAMETER
);
765 if (lctype
& LOCALE_RETURN_GENITIVE_NAMES
&&
766 !is_genitive_name_supported( lctype
))
768 SetLastError( ERROR_INVALID_FLAGS
);
772 if (!len
) buffer
= NULL
;
774 lcid
= convert_default_lcid( lcid
, lctype
);
776 lcflags
= lctype
& LOCALE_LOCALEINFOFLAGSMASK
;
779 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid
, lctype
, buffer
, len
);
781 /* first check for overrides in the registry */
783 if (!(lcflags
& LOCALE_NOUSEROVERRIDE
) &&
784 lcid
== convert_default_lcid( LOCALE_USER_DEFAULT
, lctype
))
786 const WCHAR
*value
= get_locale_value_name(lctype
);
790 if (lcflags
& LOCALE_RETURN_NUMBER
)
793 ret
= get_registry_locale_info( value
, tmp
, sizeof(tmp
)/sizeof(WCHAR
) );
797 UINT number
= strtolW( tmp
, &end
, get_value_base_by_lctype( lctype
) );
798 if (*end
) /* invalid number */
800 SetLastError( ERROR_INVALID_FLAGS
);
803 ret
= sizeof(UINT
)/sizeof(WCHAR
);
804 if (!buffer
) return ret
;
807 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
810 memcpy( buffer
, &number
, sizeof(number
) );
813 else ret
= get_registry_locale_info( value
, buffer
, len
);
815 if (ret
!= -1) return ret
;
819 /* now load it from kernel resources */
821 lang_id
= LANGIDFROMLCID( lcid
);
823 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
824 if (SUBLANGID(lang_id
) == SUBLANG_NEUTRAL
)
825 lang_id
= MAKELANGID(PRIMARYLANGID(lang_id
), SUBLANG_DEFAULT
);
827 if (!(hrsrc
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
828 ULongToPtr((lctype
>> 4) + 1), lang_id
)))
830 SetLastError( ERROR_INVALID_FLAGS
); /* no such lctype */
833 if (!(hmem
= LoadResource( kernel32_handle
, hrsrc
)))
836 p
= LockResource( hmem
);
837 for (i
= 0; i
< (lctype
& 0x0f); i
++) p
+= *p
+ 1;
839 if (lcflags
& LOCALE_RETURN_NUMBER
) ret
= sizeof(UINT
)/sizeof(WCHAR
);
840 else if (is_genitive_name_supported( lctype
) && *p
)
842 /* genitive form's stored after a null separator from a nominative */
843 for (i
= 1; i
<= *p
; i
++) if (!p
[i
]) break;
845 if (i
<= *p
&& (lcflags
& LOCALE_RETURN_GENITIVE_NAMES
))
853 ret
= (lctype
== LOCALE_FONTSIGNATURE
) ? *p
: *p
+ 1;
855 if (!buffer
) return ret
;
859 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
863 if (lcflags
& LOCALE_RETURN_NUMBER
)
866 WCHAR
*end
, *tmp
= HeapAlloc( GetProcessHeap(), 0, (*p
+ 1) * sizeof(WCHAR
) );
868 memcpy( tmp
, p
+ 1, *p
* sizeof(WCHAR
) );
870 number
= strtolW( tmp
, &end
, get_value_base_by_lctype( lctype
) );
872 memcpy( buffer
, &number
, sizeof(number
) );
873 else /* invalid number */
875 SetLastError( ERROR_INVALID_FLAGS
);
878 HeapFree( GetProcessHeap(), 0, tmp
);
880 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning number %d\n",
881 lcid
, lctype
, buffer
, len
, number
);
885 memcpy( buffer
, p
+ 1, ret
* sizeof(WCHAR
) );
886 if (lctype
!= LOCALE_FONTSIGNATURE
) buffer
[ret
-1] = 0;
888 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning %d %s\n",
889 lcid
, lctype
, buffer
, len
, ret
, debugstr_w(buffer
) );
895 /******************************************************************************
896 * SetLocaleInfoA [KERNEL32.@]
898 * Set information about an aspect of a locale.
901 * lcid [I] LCID of the locale
902 * lctype [I] LCTYPE_ flags from "winnls.h"
903 * data [I] Information to set
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.
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.
919 BOOL WINAPI
SetLocaleInfoA(LCID lcid
, LCTYPE lctype
, LPCSTR data
)
921 UINT codepage
= CP_ACP
;
926 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
930 SetLastError( ERROR_INVALID_PARAMETER
);
933 len
= MultiByteToWideChar( codepage
, 0, data
, -1, NULL
, 0 );
934 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
936 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
939 MultiByteToWideChar( codepage
, 0, data
, -1, strW
, len
);
940 ret
= SetLocaleInfoW( lcid
, lctype
, strW
);
941 HeapFree( GetProcessHeap(), 0, strW
);
946 /******************************************************************************
947 * SetLocaleInfoW (KERNEL32.@)
949 * See SetLocaleInfoA.
951 BOOL WINAPI
SetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPCWSTR data
)
954 static const WCHAR intlW
[] = {'i','n','t','l',0 };
955 UNICODE_STRING valueW
;
960 value
= get_locale_value_name( lctype
);
964 SetLastError( ERROR_INVALID_PARAMETER
);
968 if (lctype
== LOCALE_IDATE
|| lctype
== LOCALE_ILDATE
)
970 SetLastError( ERROR_INVALID_FLAGS
);
974 TRACE("setting %x (%s) to %s\n", lctype
, debugstr_w(value
), debugstr_w(data
) );
976 /* FIXME: should check that data to set is sane */
978 /* FIXME: profile functions should map to registry */
979 WriteProfileStringW( intlW
, value
, data
);
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
) );
985 if (lctype
== LOCALE_SSHORTDATE
|| lctype
== LOCALE_SLONGDATE
)
987 /* Set I-value from S value */
988 WCHAR
*lpD
, *lpM
, *lpY
;
991 lpD
= strrchrW(data
, 'd');
992 lpM
= strrchrW(data
, 'M');
993 lpY
= strrchrW(data
, 'y');
997 szBuff
[0] = '1'; /* D-M-Y */
1002 szBuff
[0] = '2'; /* Y-M-D */
1004 szBuff
[0] = '0'; /* M-D-Y */
1009 if (lctype
== LOCALE_SSHORTDATE
)
1010 lctype
= LOCALE_IDATE
;
1012 lctype
= LOCALE_ILDATE
;
1014 value
= get_locale_value_name( lctype
);
1016 WriteProfileStringW( intlW
, value
, szBuff
);
1018 RtlInitUnicodeString( &valueW
, value
);
1019 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, szBuff
, sizeof(szBuff
) );
1024 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1028 /***********************************************************************
1029 * GetThreadLocale (KERNEL32.@)
1031 * Get the current threads locale.
1037 * The LCID currently associated with the calling thread.
1039 LCID WINAPI
GetThreadLocale(void)
1041 LCID ret
= NtCurrentTeb()->CurrentLocale
;
1042 if (!ret
) NtCurrentTeb()->CurrentLocale
= ret
= GetUserDefaultLCID();
1046 /**********************************************************************
1047 * SetThreadLocale (KERNEL32.@)
1049 * Set the current threads locale.
1052 * lcid [I] LCID of the locale to set
1055 * Success: TRUE. The threads locale is set to lcid.
1056 * Failure: FALSE. Use GetLastError() to determine the cause.
1058 BOOL WINAPI
SetThreadLocale( LCID lcid
)
1060 TRACE("(0x%04X)\n", lcid
);
1062 lcid
= ConvertDefaultLocale(lcid
);
1064 if (lcid
!= GetThreadLocale())
1066 if (!IsValidLocale(lcid
, LCID_SUPPORTED
))
1068 SetLastError(ERROR_INVALID_PARAMETER
);
1072 NtCurrentTeb()->CurrentLocale
= lcid
;
1077 /******************************************************************************
1078 * ConvertDefaultLocale (KERNEL32.@)
1080 * Convert a default locale identifier into a real identifier.
1083 * lcid [I] LCID identifier of the locale to convert
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.
1092 LCID WINAPI
ConvertDefaultLocale( LCID lcid
)
1098 case LOCALE_SYSTEM_DEFAULT
:
1099 lcid
= GetSystemDefaultLCID();
1101 case LOCALE_USER_DEFAULT
:
1102 case LOCALE_NEUTRAL
:
1103 lcid
= GetUserDefaultLCID();
1106 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
1107 langid
= LANGIDFROMLCID(lcid
);
1108 if (SUBLANGID(langid
) == SUBLANG_NEUTRAL
)
1110 langid
= MAKELANGID(PRIMARYLANGID(langid
), SUBLANG_DEFAULT
);
1111 lcid
= MAKELCID(langid
, SORTIDFROMLCID(lcid
));
1118 /******************************************************************************
1119 * IsValidLocale (KERNEL32.@)
1121 * Determine if a locale is valid.
1124 * lcid [I] LCID of the locale to check
1125 * flags [I] LCID_SUPPORTED = Valid, LCID_INSTALLED = Valid and installed on the system
1128 * TRUE, if lcid is valid,
1132 * Wine does not currently make the distinction between supported and installed. All
1133 * languages supported are installed by default.
1135 BOOL WINAPI
IsValidLocale( LCID lcid
, DWORD flags
)
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;
1143 static BOOL CALLBACK
enum_lang_proc_a( HMODULE hModule
, LPCSTR type
,
1144 LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
1146 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
1149 sprintf(buf
, "%08x", (UINT
)LangID
);
1150 return lpfnLocaleEnum( buf
);
1153 static BOOL CALLBACK
enum_lang_proc_w( HMODULE hModule
, LPCWSTR type
,
1154 LPCWSTR name
, WORD LangID
, LONG_PTR lParam
)
1156 static const WCHAR formatW
[] = {'%','0','8','x',0};
1157 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
1159 sprintfW( buf
, formatW
, (UINT
)LangID
);
1160 return lpfnLocaleEnum( buf
);
1163 /******************************************************************************
1164 * EnumSystemLocalesA (KERNEL32.@)
1166 * Call a users function for each locale available on the system.
1169 * lpfnLocaleEnum [I] Callback function to call for each locale
1170 * dwFlags [I] LOCALE_SUPPORTED=All supported, LOCALE_INSTALLED=Installed only
1174 * Failure: FALSE. Use GetLastError() to determine the cause.
1176 BOOL WINAPI
EnumSystemLocalesA( LOCALE_ENUMPROCA lpfnLocaleEnum
, DWORD dwFlags
)
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
);
1186 /******************************************************************************
1187 * EnumSystemLocalesW (KERNEL32.@)
1189 * See EnumSystemLocalesA.
1191 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
, DWORD dwFlags
)
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
);
1200 /***********************************************************************
1201 * VerLanguageNameA (KERNEL32.@)
1203 * Get the name of a language.
1206 * wLang [I] LANGID of the language
1207 * szLang [O] Destination for the language name
1210 * Success: The size of the language name. If szLang is non-NULL, it is filled
1212 * Failure: 0. Use GetLastError() to determine the cause.
1215 DWORD WINAPI
VerLanguageNameA( DWORD wLang
, LPSTR szLang
, DWORD nSize
)
1217 return GetLocaleInfoA( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1221 /***********************************************************************
1222 * VerLanguageNameW (KERNEL32.@)
1224 * See VerLanguageNameA.
1226 DWORD WINAPI
VerLanguageNameW( DWORD wLang
, LPWSTR szLang
, DWORD nSize
)
1228 return GetLocaleInfoW( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1231 /******************************************************************************
1232 * GetStringTypeW (KERNEL32.@)
1234 * See GetStringTypeA.
1236 BOOL WINAPI
GetStringTypeW( DWORD type
, LPCWSTR src
, INT count
, LPWORD chartype
)
1238 static const unsigned char type2_map
[16] =
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 */
1258 if (!src
) /* Abort and return FALSE when src is null */
1260 SetLastError( ERROR_INVALID_PARAMETER
);
1263 if (count
== -1) count
= strlenW(src
) + 1;
1267 while (count
--) *chartype
++ = get_char_typeW( *src
++ ) & 0xfff;
1270 while (count
--) *chartype
++ = type2_map
[get_char_typeW( *src
++ ) >> 12];
1274 WARN("CT_CTYPE3: semi-stub.\n");
1278 WORD type1
, type3
= 0; /* C3_NOTAPPLICABLE */
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
;
1290 if ((c
>=0xD800)&&(c
<=0xDBFF)) type3
|= C3_HIGHSURROGATE
;
1291 if ((c
>=0xDC00)&&(c
<=0xDFFF)) type3
|= C3_LOWSURROGATE
;
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
;
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
;
1313 SetLastError( ERROR_INVALID_PARAMETER
);
1320 /******************************************************************************
1321 * GetStringTypeExW (KERNEL32.@)
1323 * See GetStringTypeExA.
1325 BOOL WINAPI
GetStringTypeExW( LCID locale
, DWORD type
, LPCWSTR src
, INT count
, LPWORD chartype
)
1327 /* locale is ignored for Unicode */
1328 return GetStringTypeW( type
, src
, count
, chartype
);
1332 /******************************************************************************
1333 * GetStringTypeA (KERNEL32.@)
1335 * Get characteristics of the characters making up a string.
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
1345 * Success: TRUE. chartype is filled with the requested characteristics of each char
1347 * Failure: FALSE. Use GetLastError() to determine the cause.
1349 BOOL WINAPI
GetStringTypeA( LCID locale
, DWORD type
, LPCSTR src
, INT count
, LPWORD chartype
)
1356 if(count
== -1) count
= strlen(src
) + 1;
1358 if (!(cp
= get_lcid_codepage( locale
)))
1360 FIXME("For locale %04x using current ANSI code page\n", locale
);
1364 countW
= MultiByteToWideChar(cp
, 0, src
, count
, NULL
, 0);
1365 if((srcW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
1367 MultiByteToWideChar(cp
, 0, src
, count
, srcW
, countW
);
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!
1373 ret
= GetStringTypeW(type
, srcW
, countW
, chartype
);
1374 HeapFree(GetProcessHeap(), 0, srcW
);
1379 /******************************************************************************
1380 * GetStringTypeExA (KERNEL32.@)
1382 * Get characteristics of the characters making up a string.
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
1392 * Success: TRUE. chartype is filled with the requested characteristics of each char
1394 * Failure: FALSE. Use GetLastError() to determine the cause.
1396 BOOL WINAPI
GetStringTypeExA( LCID locale
, DWORD type
, LPCSTR src
, INT count
, LPWORD chartype
)
1398 return GetStringTypeA(locale
, type
, src
, count
, chartype
);
1401 /*************************************************************************
1402 * LCMapStringEx (KERNEL32.@)
1404 * Map characters in a locale sensitive string.
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
1418 * Success: The length of the mapped string in dst, including the NUL terminator.
1419 * Failure: 0. Use GetLastError() to determine the cause.
1421 INT WINAPI
LCMapStringEx(LPCWSTR name
, DWORD flags
, LPCWSTR src
, INT srclen
, LPWSTR dst
, INT dstlen
,
1422 LPNLSVERSIONINFO version
, LPVOID reserved
, LPARAM lparam
)
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
);
1430 if (!src
|| !srclen
|| dstlen
< 0)
1432 SetLastError(ERROR_INVALID_PARAMETER
);
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
))
1442 SetLastError(ERROR_INVALID_FLAGS
);
1446 if (!dstlen
) dst
= NULL
;
1448 if (flags
& LCMAP_SORTKEY
)
1453 SetLastError(ERROR_INVALID_FLAGS
);
1457 if (srclen
< 0) srclen
= strlenW(src
);
1459 TRACE("(%s,0x%08x,%s,%d,%p,%d)\n",
1460 debugstr_w(name
), flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
1462 ret
= wine_get_sortkey(flags
, src
, srclen
, (char *)dst
, dstlen
);
1464 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1470 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
1471 if (flags
& SORT_STRINGSORT
)
1473 SetLastError(ERROR_INVALID_FLAGS
);
1477 if (srclen
< 0) srclen
= strlenW(src
) + 1;
1479 TRACE("(%s,0x%08x,%s,%d,%p,%d)\n",
1480 debugstr_w(name
), flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
1482 if (!dst
) /* return required string length */
1486 for (len
= 0; srclen
; src
++, srclen
--)
1489 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
1490 * and skips white space and punctuation characters for
1491 * NORM_IGNORESYMBOLS.
1493 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1500 if (flags
& LCMAP_UPPERCASE
)
1502 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
1505 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1507 *dst_ptr
++ = toupperW(wch
);
1511 else if (flags
& LCMAP_LOWERCASE
)
1513 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
1516 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1518 *dst_ptr
++ = tolowerW(wch
);
1526 SetLastError(ERROR_INVALID_FLAGS
);
1529 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
1532 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1541 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1545 return dst_ptr
- dst
;
1548 /*************************************************************************
1549 * LCMapStringW (KERNEL32.@)
1553 INT WINAPI
LCMapStringW(LCID lcid
, DWORD flags
, LPCWSTR src
, INT srclen
,
1554 LPWSTR dst
, INT dstlen
)
1556 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
1557 lcid
, flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
1559 return LCMapStringEx(NULL
, flags
, src
, srclen
, dst
, dstlen
, NULL
, NULL
, 0);
1562 /*************************************************************************
1563 * LCMapStringA (KERNEL32.@)
1565 * Map characters in a locale sensitive string.
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
1576 * Success: The length of the mapped string in dst, including the NUL terminator.
1577 * Failure: 0. Use GetLastError() to determine the cause.
1579 INT WINAPI
LCMapStringA(LCID lcid
, DWORD flags
, LPCSTR src
, INT srclen
,
1580 LPSTR dst
, INT dstlen
)
1582 WCHAR
*bufW
= NtCurrentTeb()->StaticUnicodeBuffer
;
1584 INT ret
= 0, srclenW
, dstlenW
;
1585 UINT locale_cp
= CP_ACP
;
1587 if (!src
|| !srclen
|| dstlen
< 0)
1589 SetLastError(ERROR_INVALID_PARAMETER
);
1593 if (!(flags
& LOCALE_USE_CP_ACP
)) locale_cp
= get_lcid_codepage( lcid
);
1595 srclenW
= MultiByteToWideChar(locale_cp
, 0, src
, srclen
, bufW
, 260);
1600 srclenW
= MultiByteToWideChar(locale_cp
, 0, src
, srclen
, NULL
, 0);
1601 srcW
= HeapAlloc(GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
));
1604 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1607 MultiByteToWideChar(locale_cp
, 0, src
, srclen
, srcW
, srclenW
);
1610 if (flags
& LCMAP_SORTKEY
)
1614 SetLastError(ERROR_INVALID_FLAGS
);
1615 goto map_string_exit
;
1617 ret
= wine_get_sortkey(flags
, srcW
, srclenW
, dst
, dstlen
);
1619 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1622 goto map_string_exit
;
1625 if (flags
& SORT_STRINGSORT
)
1627 SetLastError(ERROR_INVALID_FLAGS
);
1628 goto map_string_exit
;
1631 dstlenW
= LCMapStringEx(NULL
, flags
, srcW
, srclenW
, NULL
, 0, NULL
, NULL
, 0);
1633 goto map_string_exit
;
1635 dstW
= HeapAlloc(GetProcessHeap(), 0, dstlenW
* sizeof(WCHAR
));
1638 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1639 goto map_string_exit
;
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
);
1647 if (srcW
!= bufW
) HeapFree(GetProcessHeap(), 0, srcW
);
1651 /*************************************************************************
1652 * FoldStringA (KERNEL32.@)
1654 * Map characters in a string.
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
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.
1669 INT WINAPI
FoldStringA(DWORD dwFlags
, LPCSTR src
, INT srclen
,
1670 LPSTR dst
, INT dstlen
)
1672 INT ret
= 0, srclenW
= 0;
1673 WCHAR
*srcW
= NULL
, *dstW
= NULL
;
1675 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
1677 SetLastError(ERROR_INVALID_PARAMETER
);
1681 srclenW
= MultiByteToWideChar(CP_ACP
, dwFlags
& MAP_COMPOSITE
? MB_COMPOSITE
: 0,
1682 src
, srclen
, NULL
, 0);
1683 srcW
= HeapAlloc(GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
));
1687 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1688 goto FoldStringA_exit
;
1691 MultiByteToWideChar(CP_ACP
, dwFlags
& MAP_COMPOSITE
? MB_COMPOSITE
: 0,
1692 src
, srclen
, srcW
, srclenW
);
1694 dwFlags
= (dwFlags
& ~MAP_PRECOMPOSED
) | MAP_FOLDCZONE
;
1696 ret
= FoldStringW(dwFlags
, srcW
, srclenW
, NULL
, 0);
1699 dstW
= HeapAlloc(GetProcessHeap(), 0, ret
* sizeof(WCHAR
));
1703 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1704 goto FoldStringA_exit
;
1707 ret
= FoldStringW(dwFlags
, srcW
, srclenW
, dstW
, ret
);
1708 if (!WideCharToMultiByte(CP_ACP
, 0, dstW
, ret
, dst
, dstlen
, NULL
, NULL
))
1711 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1715 HeapFree(GetProcessHeap(), 0, dstW
);
1718 HeapFree(GetProcessHeap(), 0, srcW
);
1722 /*************************************************************************
1723 * FoldStringW (KERNEL32.@)
1727 INT WINAPI
FoldStringW(DWORD dwFlags
, LPCWSTR src
, INT srclen
,
1728 LPWSTR dst
, INT dstlen
)
1732 switch (dwFlags
& (MAP_COMPOSITE
|MAP_PRECOMPOSED
|MAP_EXPAND_LIGATURES
))
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
);
1745 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
1747 SetLastError(ERROR_INVALID_PARAMETER
);
1751 ret
= wine_fold_string(dwFlags
, src
, srclen
, dst
, dstlen
);
1753 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1757 /******************************************************************************
1758 * CompareStringW (KERNEL32.@)
1760 * See CompareStringA.
1762 INT WINAPI
CompareStringW(LCID lcid
, DWORD flags
,
1763 LPCWSTR str1
, INT len1
, LPCWSTR str2
, INT len2
)
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 */
1775 SetLastError(ERROR_INVALID_PARAMETER
);
1779 if (flags
& ~supported_flags
)
1781 SetLastError(ERROR_INVALID_FLAGS
);
1785 if (flags
& semistub_flags
)
1787 FIXME("semi-stub behavior for flag(s) 0x%x\n", flags
& semistub_flags
);
1788 semistub_flags
&= ~flags
;
1791 if (len1
< 0) len1
= strlenW(str1
);
1792 if (len2
< 0) len2
= strlenW(str2
);
1794 ret
= wine_compare_string(flags
, str1
, len1
, str2
, len2
);
1796 if (ret
) /* need to translate result */
1797 return (ret
< 0) ? CSTR_LESS_THAN
: CSTR_GREATER_THAN
;
1801 /******************************************************************************
1802 * CompareStringA (KERNEL32.@)
1804 * Compare two locale sensitive strings.
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
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.
1819 INT WINAPI
CompareStringA(LCID lcid
, DWORD flags
,
1820 LPCSTR str1
, INT len1
, LPCSTR str2
, INT len2
)
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
;
1830 SetLastError(ERROR_INVALID_PARAMETER
);
1833 if (len1
< 0) len1
= strlen(str1
);
1834 if (len2
< 0) len2
= strlen(str2
);
1836 if (!(flags
& LOCALE_USE_CP_ACP
)) locale_cp
= get_lcid_codepage( lcid
);
1840 if (len1
<= 130) len1W
= MultiByteToWideChar(locale_cp
, 0, str1
, len1
, buf1W
, 130);
1845 len1W
= MultiByteToWideChar(locale_cp
, 0, str1
, len1
, NULL
, 0);
1846 str1W
= HeapAlloc(GetProcessHeap(), 0, len1W
* sizeof(WCHAR
));
1849 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1852 MultiByteToWideChar(locale_cp
, 0, str1
, len1
, str1W
, len1W
);
1863 if (len2
<= 130) len2W
= MultiByteToWideChar(locale_cp
, 0, str2
, len2
, buf2W
, 130);
1868 len2W
= MultiByteToWideChar(locale_cp
, 0, str2
, len2
, NULL
, 0);
1869 str2W
= HeapAlloc(GetProcessHeap(), 0, len2W
* sizeof(WCHAR
));
1872 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
1873 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1876 MultiByteToWideChar(locale_cp
, 0, str2
, len2
, str2W
, len2W
);
1885 ret
= CompareStringW(lcid
, flags
, str1W
, len1W
, str2W
, len2W
);
1887 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
1888 if (str2W
!= buf2W
) HeapFree(GetProcessHeap(), 0, str2W
);
1892 static HANDLE
NLS_RegOpenKey(HANDLE hRootKey
, LPCWSTR szKeyName
)
1894 UNICODE_STRING keyName
;
1895 OBJECT_ATTRIBUTES attr
;
1898 RtlInitUnicodeString( &keyName
, szKeyName
);
1899 InitializeObjectAttributes(&attr
, &keyName
, OBJ_CASE_INSENSITIVE
, hRootKey
, NULL
);
1901 if (NtOpenKey( &hkey
, KEY_READ
, &attr
) != STATUS_SUCCESS
)
1907 static BOOL
NLS_RegEnumValue(HANDLE hKey
, UINT ulIndex
,
1908 LPWSTR szValueName
, ULONG valueNameSize
,
1909 LPWSTR szValueData
, ULONG valueDataSize
)
1912 KEY_VALUE_FULL_INFORMATION
*info
= (KEY_VALUE_FULL_INFORMATION
*)buffer
;
1915 if (NtEnumerateValueKey( hKey
, ulIndex
, KeyValueFullInformation
,
1916 buffer
, sizeof(buffer
), &dwLen
) != STATUS_SUCCESS
||
1917 info
->NameLength
> valueNameSize
||
1918 info
->DataLength
> valueDataSize
)
1923 TRACE("info->Name %s info->DataLength %d\n", debugstr_w(info
->Name
), info
->DataLength
);
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';
1930 TRACE("returning %s %s\n", debugstr_w(szValueName
), debugstr_w(szValueData
));
1934 static BOOL
NLS_RegGetDword(HANDLE hKey
, LPCWSTR szValueName
, DWORD
*lpVal
)
1937 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buffer
;
1938 DWORD dwSize
= sizeof(buffer
);
1939 UNICODE_STRING valueName
;
1941 RtlInitUnicodeString( &valueName
, szValueName
);
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
))
1948 memcpy(lpVal
, info
->Data
, sizeof(DWORD
));
1955 static BOOL
NLS_GetLanguageGroupName(LGRPID lgrpid
, LPWSTR szName
, ULONG nameSize
)
1958 LPCWSTR szResourceName
= MAKEINTRESOURCEW(((lgrpid
+ 0x2000) >> 4) + 1);
1962 /* FIXME: Is it correct to use the system default langid? */
1963 langId
= GetSystemDefaultLangID();
1965 if (SUBLANGID(langId
) == SUBLANG_NEUTRAL
)
1966 langId
= MAKELANGID( PRIMARYLANGID(langId
), SUBLANG_DEFAULT
);
1968 hResource
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
, szResourceName
, langId
);
1972 HGLOBAL hResDir
= LoadResource( kernel32_handle
, hResource
);
1976 ULONG iResourceIndex
= lgrpid
& 0xf;
1977 LPCWSTR lpResEntry
= LockResource( hResDir
);
1980 for (i
= 0; i
< iResourceIndex
; i
++)
1981 lpResEntry
+= *lpResEntry
+ 1;
1983 if (*lpResEntry
< nameSize
)
1985 memcpy( szName
, lpResEntry
+ 1, *lpResEntry
* sizeof(WCHAR
) );
1986 szName
[*lpResEntry
] = '\0';
1991 FreeResource( hResource
);
1996 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
1999 LANGUAGEGROUP_ENUMPROCA procA
;
2000 LANGUAGEGROUP_ENUMPROCW procW
;
2003 } ENUMLANGUAGEGROUP_CALLBACKS
;
2005 /* Internal implementation of EnumSystemLanguageGroupsA/W */
2006 static BOOL
NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS
*lpProcs
)
2008 WCHAR szNumber
[10], szValue
[4];
2010 BOOL bContinue
= TRUE
;
2015 SetLastError(ERROR_INVALID_PARAMETER
);
2019 switch (lpProcs
->dwFlags
)
2022 /* Default to LGRPID_INSTALLED */
2023 lpProcs
->dwFlags
= LGRPID_INSTALLED
;
2024 /* Fall through... */
2025 case LGRPID_INSTALLED
:
2026 case LGRPID_SUPPORTED
:
2029 SetLastError(ERROR_INVALID_FLAGS
);
2033 hKey
= NLS_RegOpenKey( 0, szLangGroupsKeyName
);
2036 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2040 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
2041 szValue
, sizeof(szValue
) ))
2043 BOOL bInstalled
= szValue
[0] == '1' ? TRUE
: FALSE
;
2044 LGRPID lgrpid
= strtoulW( szNumber
, NULL
, 16 );
2046 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber
),
2047 bInstalled
? "" : "not ");
2049 if (lpProcs
->dwFlags
== LGRPID_SUPPORTED
|| bInstalled
)
2051 WCHAR szGrpName
[48];
2053 if (!NLS_GetLanguageGroupName( lgrpid
, szGrpName
, sizeof(szGrpName
) / sizeof(WCHAR
) ))
2054 szGrpName
[0] = '\0';
2057 bContinue
= lpProcs
->procW( lgrpid
, szNumber
, szGrpName
, lpProcs
->dwFlags
,
2061 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
2062 char szGrpNameA
[48];
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.
2068 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
2069 WideCharToMultiByte(CP_ACP
, 0, szGrpName
, -1, szGrpNameA
, sizeof(szGrpNameA
), 0, 0);
2071 bContinue
= lpProcs
->procA( lgrpid
, szNumberA
, szGrpNameA
, lpProcs
->dwFlags
,
2091 /******************************************************************************
2092 * EnumSystemLanguageGroupsA (KERNEL32.@)
2094 * Call a users function for each language group available on the system.
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
2103 * Failure: FALSE. Use GetLastError() to determine the cause.
2105 BOOL WINAPI
EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc
,
2106 DWORD dwFlags
, LONG_PTR lParam
)
2108 ENUMLANGUAGEGROUP_CALLBACKS procs
;
2110 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
2112 procs
.procA
= pLangGrpEnumProc
;
2114 procs
.dwFlags
= dwFlags
;
2115 procs
.lParam
= lParam
;
2117 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
2120 /******************************************************************************
2121 * EnumSystemLanguageGroupsW (KERNEL32.@)
2123 * See EnumSystemLanguageGroupsA.
2125 BOOL WINAPI
EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc
,
2126 DWORD dwFlags
, LONG_PTR lParam
)
2128 ENUMLANGUAGEGROUP_CALLBACKS procs
;
2130 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
2133 procs
.procW
= pLangGrpEnumProc
;
2134 procs
.dwFlags
= dwFlags
;
2135 procs
.lParam
= lParam
;
2137 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
2140 /******************************************************************************
2141 * IsValidLanguageGroup (KERNEL32.@)
2143 * Determine if a language group is supported and/or installed.
2146 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
2147 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
2150 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
2153 BOOL WINAPI
IsValidLanguageGroup(LGRPID lgrpid
, DWORD dwFlags
)
2155 static const WCHAR szFormat
[] = { '%','x','\0' };
2156 WCHAR szValueName
[16], szValue
[2];
2157 BOOL bSupported
= FALSE
, bInstalled
= FALSE
;
2163 case LGRPID_INSTALLED
:
2164 case LGRPID_SUPPORTED
:
2166 hKey
= NLS_RegOpenKey( 0, szLangGroupsKeyName
);
2168 sprintfW( szValueName
, szFormat
, lgrpid
);
2170 if (NLS_RegGetDword( hKey
, szValueName
, (LPDWORD
)szValue
))
2174 if (szValue
[0] == '1')
2184 if ((dwFlags
== LGRPID_SUPPORTED
&& bSupported
) ||
2185 (dwFlags
== LGRPID_INSTALLED
&& bInstalled
))
2191 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
2194 LANGGROUPLOCALE_ENUMPROCA procA
;
2195 LANGGROUPLOCALE_ENUMPROCW procW
;
2199 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS
;
2201 /* Internal implementation of EnumLanguageGrouplocalesA/W */
2202 static BOOL
NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS
*lpProcs
)
2204 static const WCHAR szAlternateSortsKeyName
[] = {
2205 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
2207 WCHAR szNumber
[10], szValue
[4];
2209 BOOL bContinue
= TRUE
, bAlternate
= FALSE
;
2211 ULONG ulIndex
= 1; /* Ignore default entry of 1st key */
2213 if (!lpProcs
|| !lpProcs
->lgrpid
|| lpProcs
->lgrpid
> LGRPID_ARMENIAN
)
2215 SetLastError(ERROR_INVALID_PARAMETER
);
2219 if (lpProcs
->dwFlags
)
2221 SetLastError(ERROR_INVALID_FLAGS
);
2225 hKey
= NLS_RegOpenKey( 0, szLocaleKeyName
);
2228 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2232 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
2233 szValue
, sizeof(szValue
) ))
2235 lgrpid
= strtoulW( szValue
, NULL
, 16 );
2237 TRACE("lcid %s, grpid %d (%smatched)\n", debugstr_w(szNumber
),
2238 lgrpid
, lgrpid
== lpProcs
->lgrpid
? "" : "not ");
2240 if (lgrpid
== lpProcs
->lgrpid
)
2244 lcid
= strtoulW( szNumber
, NULL
, 16 );
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.
2252 bContinue
= lpProcs
->procW( lgrpid
, lcid
, szNumber
, lpProcs
->lParam
);
2255 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
2257 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
2259 bContinue
= lpProcs
->procA( lgrpid
, lcid
, szNumberA
, lpProcs
->lParam
);
2267 /* Finished enumerating this key */
2270 /* Enumerate alternate sorts also */
2271 hKey
= NLS_RegOpenKey( hKey
, szAlternateSortsKeyName
);
2276 bContinue
= FALSE
; /* Finished both keys */
2290 LOCATION_NATION
= 0,
2301 enum locationkind kind
;
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 */
2606 /******************************************************************************
2607 * EnumLanguageGroupLocalesA (KERNEL32.@)
2609 * Call a users function for every locale in a language group available on the system.
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
2619 * Failure: FALSE. Use GetLastError() to determine the cause.
2621 BOOL WINAPI
EnumLanguageGroupLocalesA(LANGGROUPLOCALE_ENUMPROCA pLangGrpLcEnumProc
,
2622 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
2624 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
2626 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
2628 callbacks
.procA
= pLangGrpLcEnumProc
;
2629 callbacks
.procW
= NULL
;
2630 callbacks
.dwFlags
= dwFlags
;
2631 callbacks
.lgrpid
= lgrpid
;
2632 callbacks
.lParam
= lParam
;
2634 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
2637 /******************************************************************************
2638 * EnumLanguageGroupLocalesW (KERNEL32.@)
2640 * See EnumLanguageGroupLocalesA.
2642 BOOL WINAPI
EnumLanguageGroupLocalesW(LANGGROUPLOCALE_ENUMPROCW pLangGrpLcEnumProc
,
2643 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
2645 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
2647 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
2649 callbacks
.procA
= NULL
;
2650 callbacks
.procW
= pLangGrpLcEnumProc
;
2651 callbacks
.dwFlags
= dwFlags
;
2652 callbacks
.lgrpid
= lgrpid
;
2653 callbacks
.lParam
= lParam
;
2655 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
2658 /* Callback function ptrs for EnumSystemCodePagesA/W */
2661 CODEPAGE_ENUMPROCA procA
;
2662 CODEPAGE_ENUMPROCW procW
;
2664 } ENUMSYSTEMCODEPAGES_CALLBACKS
;
2666 /* Internal implementation of EnumSystemCodePagesA/W */
2667 static BOOL
NLS_EnumSystemCodePages(ENUMSYSTEMCODEPAGES_CALLBACKS
*lpProcs
)
2669 WCHAR szNumber
[5 + 1], szValue
[MAX_PATH
];
2671 BOOL bContinue
= TRUE
;
2676 SetLastError(ERROR_INVALID_PARAMETER
);
2680 switch (lpProcs
->dwFlags
)
2686 SetLastError(ERROR_INVALID_FLAGS
);
2690 hKey
= NLS_RegOpenKey(0, L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
2693 WARN("NLS_RegOpenKey() failed\n");
2699 if (NLS_RegEnumValue(hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
2700 szValue
, sizeof(szValue
)))
2702 if ((lpProcs
->dwFlags
== CP_SUPPORTED
)||
2703 ((lpProcs
->dwFlags
== CP_INSTALLED
)&&(wcslen(szValue
) > 2)))
2707 bContinue
= lpProcs
->procW(szNumber
);
2711 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
2713 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
2714 bContinue
= lpProcs
->procA(szNumberA
);
2720 } else bContinue
= FALSE
;
2737 EnumSystemCodePagesW (
2738 CODEPAGE_ENUMPROCW lpCodePageEnumProc
,
2742 ENUMSYSTEMCODEPAGES_CALLBACKS procs
;
2744 TRACE("(%p,0x%08X,0x%08lX)\n", lpCodePageEnumProc
, dwFlags
);
2747 procs
.procW
= lpCodePageEnumProc
;
2748 procs
.dwFlags
= dwFlags
;
2750 return NLS_EnumSystemCodePages(lpCodePageEnumProc
? &procs
: NULL
);
2759 EnumSystemCodePagesA (
2760 CODEPAGE_ENUMPROCA lpCodePageEnumProc
,
2764 ENUMSYSTEMCODEPAGES_CALLBACKS procs
;
2766 TRACE("(%p,0x%08X,0x%08lX)\n", lpCodePageEnumProc
, dwFlags
);
2768 procs
.procA
= lpCodePageEnumProc
;
2770 procs
.dwFlags
= dwFlags
;
2772 return NLS_EnumSystemCodePages(lpCodePageEnumProc
? &procs
: NULL
);
2775 /******************************************************************************
2776 * EnumSystemGeoID (KERNEL32.@)
2778 * Call a users function for every location available on the system.
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
2787 * Failure: FALSE. Use GetLastError() to determine the cause.
2789 BOOL WINAPI
EnumSystemGeoID(GEOCLASS geoclass
, GEOID parent
, GEO_ENUMPROC enumproc
)
2793 TRACE("(%d, %d, %p)\n", geoclass
, parent
, enumproc
);
2796 SetLastError(ERROR_INVALID_PARAMETER
);
2800 if (geoclass
!= GEOCLASS_NATION
&& geoclass
!= GEOCLASS_REGION
) {
2801 SetLastError(ERROR_INVALID_FLAGS
);
2805 for (i
= 0; i
< sizeof(geoinfodata
)/sizeof(struct geoinfo_t
); i
++) {
2806 const struct geoinfo_t
*ptr
= &geoinfodata
[i
];
2808 if (geoclass
== GEOCLASS_NATION
&& (ptr
->kind
== LOCATION_REGION
))
2811 if (geoclass
== GEOCLASS_REGION
&& (ptr
->kind
== LOCATION_NATION
))
2814 if (parent
&& ptr
->parent
!= parent
)
2817 if (!enumproc(ptr
->id
))
2824 /******************************************************************************
2825 * InvalidateNLSCache (KERNEL32.@)
2827 * Invalidate the cache of NLS values.
2836 BOOL WINAPI
InvalidateNLSCache(void)
2842 /******************************************************************************
2843 * GetUserGeoID (KERNEL32.@)
2845 GEOID WINAPI
GetUserGeoID( GEOCLASS GeoClass
)
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
;
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
);
2858 if(!(hkey
= create_registry_key())) return ret
;
2861 case GEOCLASS_NATION
:
2862 if ((hSubkey
= NLS_RegOpenKey(hkey
, geoW
)))
2864 if((NtQueryValueKey(hSubkey
, &keyW
, KeyValuePartialInformation
,
2865 bufferW
, count
, &count
) == STATUS_SUCCESS
) && info
->DataLength
)
2866 ret
= strtolW((LPCWSTR
)info
->Data
, &end
, 10);
2869 case GEOCLASS_REGION
:
2870 FIXME("GEOCLASS_REGION not handled yet\n");
2875 if (hSubkey
) NtClose(hSubkey
);
2879 /******************************************************************************
2880 * SetUserGeoID (KERNEL32.@)
2882 BOOL WINAPI
SetUserGeoID( GEOID GeoID
)
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
;
2889 OBJECT_ATTRIBUTES attr
;
2892 if(!(hkey
= create_registry_key())) return FALSE
;
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
);
2903 if (NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
)
2906 NtClose(attr
.RootDirectory
);
2910 sprintfW(bufferW
, formatW
, GeoID
);
2911 NtSetValueKey(hkey
, &keyW
, 0, REG_SZ
, bufferW
, (strlenW(bufferW
) + 1) * sizeof(WCHAR
));
2912 NtClose(attr
.RootDirectory
);
2921 UILANGUAGE_ENUMPROCA procA
;
2922 UILANGUAGE_ENUMPROCW procW
;
2926 } ENUM_UILANG_CALLBACK
;
2928 static BOOL CALLBACK
enum_uilang_proc_a( HMODULE hModule
, LPCSTR type
,
2929 LPCSTR name
, WORD LangID
, LONG_PTR lParam
)
2931 ENUM_UILANG_CALLBACK
*enum_uilang
= (ENUM_UILANG_CALLBACK
*)lParam
;
2934 sprintf(buf
, "%08x", (UINT
)LangID
);
2935 return enum_uilang
->u
.procA( buf
, enum_uilang
->param
);
2938 static BOOL CALLBACK
enum_uilang_proc_w( HMODULE hModule
, LPCWSTR type
,
2939 LPCWSTR name
, WORD LangID
, LONG_PTR lParam
)
2941 static const WCHAR formatW
[] = {'%','0','8','x',0};
2942 ENUM_UILANG_CALLBACK
*enum_uilang
= (ENUM_UILANG_CALLBACK
*)lParam
;
2945 sprintfW( buf
, formatW
, (UINT
)LangID
);
2946 return enum_uilang
->u
.procW( buf
, enum_uilang
->param
);
2949 /******************************************************************************
2950 * EnumUILanguagesA (KERNEL32.@)
2952 BOOL WINAPI
EnumUILanguagesA(UILANGUAGE_ENUMPROCA pUILangEnumProc
, DWORD dwFlags
, LONG_PTR lParam
)
2954 ENUM_UILANG_CALLBACK enum_uilang
;
2956 TRACE("%p, %x, %lx\n", pUILangEnumProc
, dwFlags
, lParam
);
2958 if(!pUILangEnumProc
) {
2959 SetLastError(ERROR_INVALID_PARAMETER
);
2963 SetLastError(ERROR_INVALID_FLAGS
);
2967 enum_uilang
.u
.procA
= pUILangEnumProc
;
2968 enum_uilang
.flags
= dwFlags
;
2969 enum_uilang
.param
= lParam
;
2971 EnumResourceLanguagesA( kernel32_handle
, (LPCSTR
)RT_STRING
,
2972 (LPCSTR
)LOCALE_ILANGUAGE
, enum_uilang_proc_a
,
2973 (LONG_PTR
)&enum_uilang
);
2977 /******************************************************************************
2978 * EnumUILanguagesW (KERNEL32.@)
2980 BOOL WINAPI
EnumUILanguagesW(UILANGUAGE_ENUMPROCW pUILangEnumProc
, DWORD dwFlags
, LONG_PTR lParam
)
2982 ENUM_UILANG_CALLBACK enum_uilang
;
2984 TRACE("%p, %x, %lx\n", pUILangEnumProc
, dwFlags
, lParam
);
2987 if(!pUILangEnumProc
) {
2988 SetLastError(ERROR_INVALID_PARAMETER
);
2992 SetLastError(ERROR_INVALID_FLAGS
);
2996 enum_uilang
.u
.procW
= pUILangEnumProc
;
2997 enum_uilang
.flags
= dwFlags
;
2998 enum_uilang
.param
= lParam
;
3000 EnumResourceLanguagesW( kernel32_handle
, (LPCWSTR
)RT_STRING
,
3001 (LPCWSTR
)LOCALE_ILANGUAGE
, enum_uilang_proc_w
,
3002 (LONG_PTR
)&enum_uilang
);
3007 NLS_GetGeoFriendlyName(GEOID Location
, LPWSTR szFriendlyName
, int cchData
)
3012 /* FIXME: move *.nls resources out of kernel32 into locale.nls */
3013 Location
+= NLSRC_OFFSET
;
3017 return GetLocalisedText(Location
, NULL
, 0);
3019 dwSize
= cchData
* sizeof(WCHAR
);
3020 szBuffer
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
3024 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3028 if(GetLocalisedText(Location
, szBuffer
, dwSize
))
3030 memcpy(szFriendlyName
, szBuffer
, dwSize
);
3031 HeapFree(GetProcessHeap(), 0, szBuffer
);
3032 return strlenW(szFriendlyName
) + 1;
3035 HeapFree(GetProcessHeap(), 0, szBuffer
);
3039 static const struct geoinfo_t
*get_geoinfo_dataptr(GEOID geoid
)
3044 max
= sizeof(geoinfodata
)/sizeof(struct geoinfo_t
)-1;
3046 while (min
<= max
) {
3047 const struct geoinfo_t
*ptr
;
3048 int n
= (min
+max
)/2;
3050 ptr
= &geoinfodata
[n
];
3051 if (geoid
== ptr
->id
)
3052 /* we don't need empty entry */
3053 return *ptr
->iso2W
? ptr
: NULL
;
3055 if (ptr
->id
> geoid
)
3064 /******************************************************************************
3065 * GetGeoInfoW (KERNEL32.@)
3067 INT WINAPI
GetGeoInfoW(GEOID geoid
, GEOTYPE geotype
, LPWSTR data
, int data_len
, LANGID lang
)
3069 const struct geoinfo_t
*ptr
;
3070 const WCHAR
*str
= NULL
;
3075 TRACE("%d %d %p %d %d\n", geoid
, geotype
, data
, data_len
, lang
);
3077 if (!(ptr
= get_geoinfo_dataptr(geoid
))) {
3078 SetLastError(ERROR_INVALID_PARAMETER
);
3083 case GEO_FRIENDLYNAME
:
3085 return NLS_GetGeoFriendlyName(geoid
, data
, data_len
);
3090 case GEO_ISO_UN_NUMBER
:
3099 str
= geotype
== GEO_ISO2
? ptr
->iso2W
: ptr
->iso3W
;
3104 case GEO_OFFICIALNAME
:
3106 case GEO_OFFICIALLANGUAGES
:
3109 FIXME("type %d is not supported\n", geotype
);
3110 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
3113 WARN("unrecognized type %d\n", geotype
);
3114 SetLastError(ERROR_INVALID_FLAGS
);
3119 static const WCHAR fmtW
[] = {'%','d',0};
3120 sprintfW(buffW
, fmtW
, val
);
3124 len
= strlenW(str
) + 1;
3125 if (!data
|| !data_len
)
3128 memcpy(data
, str
, min(len
, data_len
)*sizeof(WCHAR
));
3130 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3131 return data_len
< len
? 0 : len
;
3134 /******************************************************************************
3135 * GetGeoInfoA (KERNEL32.@)
3137 INT WINAPI
GetGeoInfoA(GEOID geoid
, GEOTYPE geotype
, LPSTR data
, int data_len
, LANGID lang
)
3142 TRACE("%d %d %p %d %d\n", geoid
, geotype
, data
, data_len
, lang
);
3144 len
= GetGeoInfoW(geoid
, geotype
, NULL
, 0, lang
);
3148 buffW
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
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
);
3159 len
= WideCharToMultiByte(CP_ACP
, 0, buffW
, -1, data
, data_len
, NULL
, NULL
);
3160 HeapFree(GetProcessHeap(), 0, buffW
);
3163 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3164 return data_len
< len
? 0 : len
;