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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/port.h"
37 #include "winuser.h" /* for RT_STRINGW */
40 #include "wine/unicode.h"
44 #include "kernel_private.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(nls
);
49 #define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|LOCALE_RETURN_NUMBER)
51 /* current code pages */
52 static const union cptable
*ansi_cptable
;
53 static const union cptable
*oem_cptable
;
54 static const union cptable
*mac_cptable
;
55 static const union cptable
*unix_cptable
; /* NULL if UTF8 */
57 /* Charset to codepage map, sorted by name. */
58 static const struct charset_entry
60 const char *charset_name
;
93 { "ISO88591", 28591 },
94 { "ISO885910", 28600 },
95 { "ISO885913", 28603 },
96 { "ISO885914", 28604 },
97 { "ISO885915", 28605 },
98 { "ISO88592", 28592 },
99 { "ISO88593", 28593 },
100 { "ISO88594", 28594 },
101 { "ISO88595", 28595 },
102 { "ISO88596", 28596 },
103 { "ISO88597", 28597 },
104 { "ISO88598", 28598 },
105 { "ISO88599", 28599 },
111 #define NLS_MAX_LANGUAGES 20
115 LANGID found_lang_id
[NLS_MAX_LANGUAGES
];
116 WCHAR found_language
[NLS_MAX_LANGUAGES
][3];
117 WCHAR found_country
[NLS_MAX_LANGUAGES
][3];
122 /* copy Unicode string to Ascii without using codepages */
123 static inline void strcpyWtoA( char *dst
, const WCHAR
*src
)
125 while ((*dst
++ = *src
++));
128 /* Copy Ascii string to Unicode without using codepages */
129 static inline void strcpynAtoW( WCHAR
*dst
, const char *src
, size_t n
)
131 while (n
> 1 && *src
)
133 *dst
++ = (unsigned char)*src
++;
139 /* return a printable string for a language id */
140 static const char *debugstr_lang( LANGID lang
)
142 WCHAR langW
[4], countryW
[4];
144 LCID lcid
= MAKELCID( lang
, SORT_DEFAULT
);
146 GetLocaleInfoW(lcid
, LOCALE_SISO639LANGNAME
|LOCALE_NOUSEROVERRIDE
, langW
, sizeof(langW
)/sizeof(WCHAR
));
147 GetLocaleInfoW(lcid
, LOCALE_SISO3166CTRYNAME
|LOCALE_NOUSEROVERRIDE
, countryW
, sizeof(countryW
)/sizeof(WCHAR
));
148 strcpyWtoA( buffer
, langW
);
149 strcat( buffer
, "_" );
150 strcpyWtoA( buffer
+ strlen(buffer
), countryW
);
151 return wine_dbg_sprintf( "%s", buffer
);
154 /***********************************************************************
157 * Retrieve the ANSI codepage for a given locale.
159 inline static UINT
get_lcid_codepage( LCID lcid
)
162 if (!GetLocaleInfoW( lcid
, LOCALE_IDEFAULTANSICODEPAGE
|LOCALE_RETURN_NUMBER
, (WCHAR
*)&ret
,
163 sizeof(ret
)/sizeof(WCHAR
) )) ret
= 0;
168 /***********************************************************************
171 * Find the table for a given codepage, handling CP_ACP etc. pseudo-codepages
173 static const union cptable
*get_codepage_table( unsigned int codepage
)
175 const union cptable
*ret
= NULL
;
177 assert( ansi_cptable
); /* init must have been done already */
191 if (!(codepage
= NtCurrentTeb()->code_page
)) return ansi_cptable
;
194 if (codepage
== ansi_cptable
->info
.codepage
) return ansi_cptable
;
195 if (codepage
== oem_cptable
->info
.codepage
) return oem_cptable
;
196 if (codepage
== mac_cptable
->info
.codepage
) return mac_cptable
;
197 ret
= wine_cp_get_table( codepage
);
203 /***********************************************************************
204 * create_registry_key
206 * Create the Control Panel\\International registry key.
208 inline static HKEY
create_registry_key(void)
210 static const WCHAR intlW
[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
211 'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
212 OBJECT_ATTRIBUTES attr
;
213 UNICODE_STRING nameW
;
216 if (RtlOpenCurrentUser( KEY_ALL_ACCESS
, &hkey
) != STATUS_SUCCESS
) return 0;
218 attr
.Length
= sizeof(attr
);
219 attr
.RootDirectory
= hkey
;
220 attr
.ObjectName
= &nameW
;
222 attr
.SecurityDescriptor
= NULL
;
223 attr
.SecurityQualityOfService
= NULL
;
224 RtlInitUnicodeString( &nameW
, intlW
);
226 if (NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
) hkey
= 0;
227 NtClose( attr
.RootDirectory
);
232 /***********************************************************************
233 * LOCALE_InitRegistry
235 * Update registry contents on startup if the user locale has changed.
236 * This simulates the action of the Windows control panel.
238 void LOCALE_InitRegistry(void)
240 static const USHORT updateValues
[] = {
242 LOCALE_SCOUNTRY
, LOCALE_ICOUNTRY
,
243 LOCALE_S1159
, LOCALE_S2359
,
244 LOCALE_STIME
, LOCALE_ITIME
,
250 LOCALE_SCURRENCY
, LOCALE_ICURRENCY
,
257 LOCALE_IDIGITSUBSTITUTION
,
258 LOCALE_SNATIVEDIGITS
,
259 LOCALE_ITIMEMARKPOSN
,
260 LOCALE_ICALENDARTYPE
,
264 static const WCHAR LocaleW
[] = {'L','o','c','a','l','e',0};
265 UNICODE_STRING nameW
;
270 LCID lcid
= GetUserDefaultLCID();
272 if (!(hkey
= create_registry_key()))
273 return; /* don't do anything if we can't create the registry key */
275 RtlInitUnicodeString( &nameW
, LocaleW
);
276 count
= sizeof(bufferW
);
277 if (!NtQueryValueKey(hkey
, &nameW
, KeyValuePartialInformation
, (LPBYTE
)bufferW
, count
, &count
))
279 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)bufferW
;
280 LPCWSTR szValueText
= (LPCWSTR
)info
->Data
;
282 if (strtoulW( szValueText
, NULL
, 16 ) == lcid
) /* already set correctly */
287 TRACE( "updating registry, locale changed %s -> %08lx\n", debugstr_w(szValueText
), lcid
);
289 else TRACE( "updating registry, locale changed none -> %08lx\n", lcid
);
291 sprintf( buffer
, "%08lx", lcid
);
292 /* Note: '9' constant below is strlen(buffer) + 1 */
293 RtlMultiByteToUnicodeN( bufferW
, sizeof(bufferW
), NULL
, buffer
, 9 );
294 NtSetValueKey( hkey
, &nameW
, 0, REG_SZ
, bufferW
, 9 * sizeof(WCHAR
) );
297 for (i
= 0; i
< sizeof(updateValues
)/sizeof(updateValues
[0]); i
++)
299 GetLocaleInfoW( lcid
, updateValues
[i
] | LOCALE_NOUSEROVERRIDE
, bufferW
,
300 sizeof(bufferW
)/sizeof(WCHAR
) );
301 SetLocaleInfoW( lcid
, updateValues
[i
], bufferW
);
306 /***********************************************************************
307 * find_language_id_proc
309 static BOOL CALLBACK
find_language_id_proc( HMODULE hModule
, LPCWSTR type
,
310 LPCWSTR name
, WORD LangID
, LPARAM lParam
)
312 LANG_FIND_DATA
*l_data
= (LANG_FIND_DATA
*)lParam
;
313 LCID lcid
= MAKELCID(LangID
, SORT_DEFAULT
);
314 WCHAR buf_language
[128];
315 WCHAR buf_country
[128];
316 WCHAR buf_en_language
[128];
318 if(PRIMARYLANGID(LangID
) == LANG_NEUTRAL
)
319 return TRUE
; /* continue search */
324 GetLocaleInfoW(lcid
, LOCALE_SISO639LANGNAME
|LOCALE_NOUSEROVERRIDE
,
325 buf_language
, sizeof(buf_language
)/sizeof(WCHAR
));
326 GetLocaleInfoW(lcid
, LOCALE_SISO3166CTRYNAME
|LOCALE_NOUSEROVERRIDE
,
327 buf_country
, sizeof(buf_country
)/sizeof(WCHAR
));
329 if(l_data
->lang
[0] && !strcmpiW(l_data
->lang
, buf_language
))
331 if(l_data
->country
[0])
333 if(!strcmpiW(l_data
->country
, buf_country
))
335 l_data
->found_lang_id
[0] = LangID
;
337 TRACE("Found id %04X for lang %s country %s\n",
338 LangID
, debugstr_w(l_data
->lang
), debugstr_w(l_data
->country
));
339 return FALSE
; /* stop enumeration */
342 else goto found
; /* l_data->country not specified */
345 /* Just in case, check LOCALE_SENGLANGUAGE too,
346 * in hope that possible alias name might have that value.
348 buf_en_language
[0] = 0;
349 GetLocaleInfoW(lcid
, LOCALE_SENGLANGUAGE
|LOCALE_NOUSEROVERRIDE
,
350 buf_en_language
, sizeof(buf_en_language
)/sizeof(WCHAR
));
352 if(l_data
->lang
[0] && !strcmpiW(l_data
->lang
, buf_en_language
)) goto found
;
353 return TRUE
; /* not found, continue search */
356 l_data
->found_lang_id
[l_data
->n_found
] = LangID
;
357 strncpyW(l_data
->found_country
[l_data
->n_found
], buf_country
, 3);
358 strncpyW(l_data
->found_language
[l_data
->n_found
], buf_language
, 3);
360 TRACE("Found id %04X for lang %s\n", LangID
, debugstr_w(l_data
->lang
));
361 return (l_data
->n_found
< NLS_MAX_LANGUAGES
); /* continue search, unless we have enough */
365 /***********************************************************************
369 * Lang: a string whose two first chars are the iso name of a language.
370 * Country: a string whose two first chars are the iso name of country
371 * Charset: a string defining the chosen charset encoding
372 * Dialect: a string defining a variation of the locale
374 * all those values are from the standardized format of locale
375 * name in unix which is: Lang[_Country][.Charset][@Dialect]
378 * the numeric code of the language used by Windows
380 * FIXME: Charset and Dialect are not handled
382 static LANGID
get_language_id(LPCSTR Lang
, LPCSTR Country
, LPCSTR Charset
, LPCSTR Dialect
)
384 LANG_FIND_DATA l_data
;
388 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
393 strcpynAtoW(l_data
.lang
, Lang
, sizeof(l_data
.lang
));
395 if (Country
) strcpynAtoW(l_data
.country
, Country
, sizeof(l_data
.country
));
396 else l_data
.country
[0] = 0;
398 EnumResourceLanguagesW(kernel32_handle
, (LPCWSTR
)RT_STRING
, (LPCWSTR
)LOCALE_ILANGUAGE
,
399 find_language_id_proc
, (LPARAM
)&l_data
);
401 if (l_data
.n_found
== 1) goto END
;
405 if(l_data
.country
[0])
407 /* retry without country name */
408 l_data
.country
[0] = 0;
409 EnumResourceLanguagesW(kernel32_handle
, (LPCWSTR
)RT_STRING
, (LPCWSTR
)LOCALE_ILANGUAGE
,
410 find_language_id_proc
, (LONG
)&l_data
);
413 MESSAGE("Warning: Language '%s_%s' was not recognized, defaulting to English.\n",
415 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
417 else MESSAGE("Warning: Language '%s_%s' was not recognized, defaulting to '%s'.\n",
418 Lang
, Country
, debugstr_lang(l_data
.found_lang_id
[0]) );
422 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English.\n", Lang
);
423 l_data
.found_lang_id
[0] = MAKELANGID(LANG_ENGLISH
, SUBLANG_DEFAULT
);
430 if (Country
&& Country
[0])
431 MESSAGE("For language '%s_%s' several language ids were found:\n", Lang
, Country
);
433 MESSAGE("For language '%s' several language ids were found:\n", Lang
);
435 /* print a list of languages with their description */
436 for (i
= 0; i
< l_data
.n_found
; i
++)
440 GetLocaleInfoW( MAKELCID( l_data
.found_lang_id
[i
], SORT_DEFAULT
),
441 LOCALE_SLANGUAGE
|LOCALE_NOUSEROVERRIDE
, buffW
, sizeof(buffW
)/sizeof(WCHAR
));
442 strcpyWtoA( buffA
, buffW
);
443 MESSAGE( " %s (%04X) - %s\n", debugstr_lang(l_data
.found_lang_id
[i
]),
444 l_data
.found_lang_id
[i
], buffA
);
446 MESSAGE("Defaulting to '%s'. You should specify the exact language you want\n"
447 "by defining your LANG environment variable like this: LANG=%s\n",
448 debugstr_lang(l_data
.found_lang_id
[0]), debugstr_lang(l_data
.found_lang_id
[0]) );
451 TRACE("Returning %04X (%s)\n", l_data
.found_lang_id
[0], debugstr_lang(l_data
.found_lang_id
[0]));
452 return l_data
.found_lang_id
[0];
456 /***********************************************************************
457 * charset_cmp (internal)
459 static int charset_cmp( const void *name
, const void *entry
)
461 const struct charset_entry
*charset
= (struct charset_entry
*)entry
;
462 return strcasecmp( (char *)name
, charset
->charset_name
);
465 /***********************************************************************
468 static LCID
init_default_lcid( UINT
*unix_cp
)
470 char *buf
, *lang
,*country
,*charset
,*dialect
,*next
;
473 if ((lang
= getenv( "LC_ALL" )) ||
474 (lang
= getenv( "LC_CTYPE" )) ||
475 (lang
= getenv( "LANGUAGE" )) ||
476 (lang
= getenv( "LC_MESSAGES" )) ||
477 (lang
= getenv( "LANG" )))
479 if (!strcmp(lang
,"POSIX") || !strcmp(lang
,"C")) goto done
;
481 buf
= RtlAllocateHeap( GetProcessHeap(), 0, strlen(lang
) + 1 );
486 next
=strchr(lang
,':'); if (next
) *next
++='\0';
487 dialect
=strchr(lang
,'@'); if (dialect
) *dialect
++='\0';
488 charset
=strchr(lang
,'.'); if (charset
) *charset
++='\0';
489 country
=strchr(lang
,'_'); if (country
) *country
++='\0';
491 ret
= get_language_id(lang
, country
, charset
, dialect
);
494 const struct charset_entry
*entry
;
495 char charset_name
[16];
498 /* remove punctuation characters from charset name */
499 for (i
= j
= 0; charset
[i
] && j
< sizeof(charset_name
)-1; i
++)
500 if (isalnum(charset
[i
])) charset_name
[j
++] = charset
[i
];
503 entry
= bsearch( charset_name
, charset_names
,
504 sizeof(charset_names
)/sizeof(charset_names
[0]),
505 sizeof(charset_names
[0]), charset_cmp
);
508 *unix_cp
= entry
->codepage
;
509 TRACE("charset %s was mapped to cp %u\n", charset
, *unix_cp
);
512 FIXME("charset %s was not recognized\n", charset
);
516 } while (lang
&& !ret
);
518 if (!ret
) MESSAGE("Warning: language '%s' not recognized, defaulting to English\n", buf
);
519 RtlFreeHeap( GetProcessHeap(), 0, buf
);
523 if (!ret
) ret
= MAKELCID( MAKELANGID(LANG_ENGLISH
,SUBLANG_DEFAULT
), SORT_DEFAULT
) ;
528 /***********************************************************************
529 * GetUserDefaultLangID (KERNEL32.@)
531 * Get the default language Id for the current user.
537 * The current LANGID of the default language for the current user.
539 LANGID WINAPI
GetUserDefaultLangID(void)
541 return LANGIDFROMLCID(GetUserDefaultLCID());
545 /***********************************************************************
546 * GetSystemDefaultLangID (KERNEL32.@)
548 * Get the default language Id for the system.
554 * The current LANGID of the default language for the system.
556 LANGID WINAPI
GetSystemDefaultLangID(void)
558 return GetUserDefaultLangID();
562 /***********************************************************************
563 * GetUserDefaultLCID (KERNEL32.@)
565 * Get the default locale Id for the current user.
571 * The current LCID of the default locale for the current user.
573 LCID WINAPI
GetUserDefaultLCID(void)
576 NtQueryDefaultLocale( TRUE
, &lcid
);
581 /***********************************************************************
582 * GetSystemDefaultLCID (KERNEL32.@)
584 * Get the default locale Id for the system.
590 * The current LCID of the default locale for the system.
592 LCID WINAPI
GetSystemDefaultLCID(void)
595 NtQueryDefaultLocale( FALSE
, &lcid
);
600 /***********************************************************************
601 * GetUserDefaultUILanguage (KERNEL32.@)
603 * Get the default user interface language Id for the current user.
609 * The current LANGID of the default UI language for the current user.
611 LANGID WINAPI
GetUserDefaultUILanguage(void)
613 return GetUserDefaultLangID();
617 /***********************************************************************
618 * GetSystemDefaultUILanguage (KERNEL32.@)
620 * Get the default user interface language Id for the system.
626 * The current LANGID of the default UI language for the system. This is
627 * typically the same language used during the installation process.
629 LANGID WINAPI
GetSystemDefaultUILanguage(void)
631 return GetSystemDefaultLangID();
635 /******************************************************************************
636 * get_locale_value_name
638 * Gets the registry value name for a given lctype.
640 static const WCHAR
*get_locale_value_name( DWORD lctype
)
642 static const WCHAR iCalendarTypeW
[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
643 static const WCHAR iCountryW
[] = {'i','C','o','u','n','t','r','y',0};
644 static const WCHAR iCurrDigitsW
[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
645 static const WCHAR iCurrencyW
[] = {'i','C','u','r','r','e','n','c','y',0};
646 static const WCHAR iDateW
[] = {'i','D','a','t','e',0};
647 static const WCHAR iDigitsW
[] = {'i','D','i','g','i','t','s',0};
648 static const WCHAR iFirstDayOfWeekW
[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
649 static const WCHAR iFirstWeekOfYearW
[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
650 static const WCHAR iLDateW
[] = {'i','L','D','a','t','e',0};
651 static const WCHAR iLZeroW
[] = {'i','L','Z','e','r','o',0};
652 static const WCHAR iMeasureW
[] = {'i','M','e','a','s','u','r','e',0};
653 static const WCHAR iNegCurrW
[] = {'i','N','e','g','C','u','r','r',0};
654 static const WCHAR iNegNumberW
[] = {'i','N','e','g','N','u','m','b','e','r',0};
655 static const WCHAR iPaperSizeW
[] = {'i','P','a','p','e','r','S','i','z','e',0};
656 static const WCHAR iTLZeroW
[] = {'i','T','L','Z','e','r','o',0};
657 static const WCHAR iTimePrefixW
[] = {'i','T','i','m','e','P','r','e','f','i','x',0};
658 static const WCHAR iTimeW
[] = {'i','T','i','m','e',0};
659 static const WCHAR s1159W
[] = {'s','1','1','5','9',0};
660 static const WCHAR s2359W
[] = {'s','2','3','5','9',0};
661 static const WCHAR sCountryW
[] = {'s','C','o','u','n','t','r','y',0};
662 static const WCHAR sCurrencyW
[] = {'s','C','u','r','r','e','n','c','y',0};
663 static const WCHAR sDateW
[] = {'s','D','a','t','e',0};
664 static const WCHAR sDecimalW
[] = {'s','D','e','c','i','m','a','l',0};
665 static const WCHAR sGroupingW
[] = {'s','G','r','o','u','p','i','n','g',0};
666 static const WCHAR sLanguageW
[] = {'s','L','a','n','g','u','a','g','e',0};
667 static const WCHAR sListW
[] = {'s','L','i','s','t',0};
668 static const WCHAR sLongDateW
[] = {'s','L','o','n','g','D','a','t','e',0};
669 static const WCHAR sMonDecimalSepW
[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
670 static const WCHAR sMonGroupingW
[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
671 static const WCHAR sMonThousandSepW
[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
672 static const WCHAR sNativeDigitsW
[] = {'s','N','a','t','i','v','e','D','i','g','i','t','s',0};
673 static const WCHAR sNegativeSignW
[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
674 static const WCHAR sPositiveSignW
[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
675 static const WCHAR sShortDateW
[] = {'s','S','h','o','r','t','D','a','t','e',0};
676 static const WCHAR sThousandW
[] = {'s','T','h','o','u','s','a','n','d',0};
677 static const WCHAR sTimeFormatW
[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
678 static const WCHAR sTimeW
[] = {'s','T','i','m','e',0};
679 static const WCHAR sYearMonthW
[] = {'s','Y','e','a','r','M','o','n','t','h',0};
680 static const WCHAR NumShapeW
[] = {'N','u','m','s','h','a','p','e',0};
684 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
685 * the values are stored in the registry, confirmed under Windows.
687 case LOCALE_ICALENDARTYPE
: return iCalendarTypeW
;
688 case LOCALE_ICURRDIGITS
: return iCurrDigitsW
;
689 case LOCALE_ICURRENCY
: return iCurrencyW
;
690 case LOCALE_IDIGITS
: return iDigitsW
;
691 case LOCALE_IFIRSTDAYOFWEEK
: return iFirstDayOfWeekW
;
692 case LOCALE_IFIRSTWEEKOFYEAR
: return iFirstWeekOfYearW
;
693 case LOCALE_ILZERO
: return iLZeroW
;
694 case LOCALE_IMEASURE
: return iMeasureW
;
695 case LOCALE_INEGCURR
: return iNegCurrW
;
696 case LOCALE_INEGNUMBER
: return iNegNumberW
;
697 case LOCALE_IPAPERSIZE
: return iPaperSizeW
;
698 case LOCALE_ITIME
: return iTimeW
;
699 case LOCALE_S1159
: return s1159W
;
700 case LOCALE_S2359
: return s2359W
;
701 case LOCALE_SCURRENCY
: return sCurrencyW
;
702 case LOCALE_SDATE
: return sDateW
;
703 case LOCALE_SDECIMAL
: return sDecimalW
;
704 case LOCALE_SGROUPING
: return sGroupingW
;
705 case LOCALE_SLIST
: return sListW
;
706 case LOCALE_SLONGDATE
: return sLongDateW
;
707 case LOCALE_SMONDECIMALSEP
: return sMonDecimalSepW
;
708 case LOCALE_SMONGROUPING
: return sMonGroupingW
;
709 case LOCALE_SMONTHOUSANDSEP
: return sMonThousandSepW
;
710 case LOCALE_SNEGATIVESIGN
: return sNegativeSignW
;
711 case LOCALE_SPOSITIVESIGN
: return sPositiveSignW
;
712 case LOCALE_SSHORTDATE
: return sShortDateW
;
713 case LOCALE_STHOUSAND
: return sThousandW
;
714 case LOCALE_STIME
: return sTimeW
;
715 case LOCALE_STIMEFORMAT
: return sTimeFormatW
;
716 case LOCALE_SYEARMONTH
: return sYearMonthW
;
718 /* The following are not listed under MSDN as supported,
719 * but seem to be used and also stored in the registry.
721 case LOCALE_ICOUNTRY
: return iCountryW
;
722 case LOCALE_IDATE
: return iDateW
;
723 case LOCALE_ILDATE
: return iLDateW
;
724 case LOCALE_ITLZERO
: return iTLZeroW
;
725 case LOCALE_SCOUNTRY
: return sCountryW
;
726 case LOCALE_SLANGUAGE
: return sLanguageW
;
728 /* The following are used in XP and later */
729 case LOCALE_IDIGITSUBSTITUTION
: return NumShapeW
;
730 case LOCALE_SNATIVEDIGITS
: return sNativeDigitsW
;
731 case LOCALE_ITIMEMARKPOSN
: return iTimePrefixW
;
737 /******************************************************************************
738 * get_registry_locale_info
740 * Retrieve user-modified locale info from the registry.
741 * Return length, 0 on error, -1 if not found.
743 static INT
get_registry_locale_info( LPCWSTR value
, LPWSTR buffer
, INT len
)
749 UNICODE_STRING nameW
;
750 KEY_VALUE_PARTIAL_INFORMATION
*info
;
751 static const int info_size
= FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION
, Data
);
753 if (!(hkey
= create_registry_key())) return -1;
755 RtlInitUnicodeString( &nameW
, value
);
756 size
= info_size
+ len
* sizeof(WCHAR
);
758 if (!(info
= HeapAlloc( GetProcessHeap(), 0, size
)))
761 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
765 status
= NtQueryValueKey( hkey
, &nameW
, KeyValuePartialInformation
, info
, size
, &size
);
766 if (status
== STATUS_BUFFER_OVERFLOW
&& !buffer
) status
= 0;
770 ret
= (size
- info_size
) / sizeof(WCHAR
);
771 /* append terminating null if needed */
772 if (!ret
|| ((WCHAR
*)info
->Data
)[ret
-1])
774 if (ret
< len
|| !buffer
) ret
++;
777 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
783 memcpy( buffer
, info
->Data
, (ret
-1) * sizeof(WCHAR
) );
789 if (status
== STATUS_OBJECT_NAME_NOT_FOUND
) ret
= -1;
792 SetLastError( RtlNtStatusToDosError(status
) );
797 HeapFree( GetProcessHeap(), 0, info
);
802 /******************************************************************************
803 * GetLocaleInfoA (KERNEL32.@)
805 * Get information about an aspect of a locale.
808 * lcid [I] LCID of the locale
809 * lctype [I] LCTYPE_ flags from "winnls.h"
810 * buffer [O] Destination for the information
811 * len [I] Length of buffer in characters
814 * Success: The size of the data requested. If buffer is non-NULL, it is filled
815 * with the information.
816 * Failure: 0. Use GetLastError() to determine the cause.
819 * - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
820 * - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
821 * which is a bit string.
823 INT WINAPI
GetLocaleInfoA( LCID lcid
, LCTYPE lctype
, LPSTR buffer
, INT len
)
828 if (len
< 0 || (len
&& !buffer
))
830 SetLastError( ERROR_INVALID_PARAMETER
);
833 if (!len
) buffer
= NULL
;
835 if (!(lenW
= GetLocaleInfoW( lcid
, lctype
, NULL
, 0 ))) return 0;
837 if (!(bufferW
= HeapAlloc( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) )))
839 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
842 if ((ret
= GetLocaleInfoW( lcid
, lctype
, bufferW
, lenW
)))
844 if ((lctype
& LOCALE_RETURN_NUMBER
) ||
845 ((lctype
& ~LOCALE_LOCALEINFOFLAGSMASK
) == LOCALE_FONTSIGNATURE
))
847 /* it's not an ASCII string, just bytes */
848 ret
*= sizeof(WCHAR
);
851 if (ret
<= len
) memcpy( buffer
, bufferW
, ret
);
854 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
861 UINT codepage
= CP_ACP
;
862 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
863 ret
= WideCharToMultiByte( codepage
, 0, bufferW
, ret
, buffer
, len
, NULL
, NULL
);
866 HeapFree( GetProcessHeap(), 0, bufferW
);
871 /******************************************************************************
872 * GetLocaleInfoW (KERNEL32.@)
874 * See GetLocaleInfoA.
876 INT WINAPI
GetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPWSTR buffer
, INT len
)
886 if (len
< 0 || (len
&& !buffer
))
888 SetLastError( ERROR_INVALID_PARAMETER
);
891 if (!len
) buffer
= NULL
;
893 lcid
= ConvertDefaultLocale(lcid
);
895 lcflags
= lctype
& LOCALE_LOCALEINFOFLAGSMASK
;
898 /* first check for overrides in the registry */
900 if (!(lcflags
& LOCALE_NOUSEROVERRIDE
) && lcid
== GetUserDefaultLCID())
902 const WCHAR
*value
= get_locale_value_name(lctype
);
906 if (lcflags
& LOCALE_RETURN_NUMBER
)
909 ret
= get_registry_locale_info( value
, tmp
, sizeof(tmp
)/sizeof(WCHAR
) );
913 UINT number
= strtolW( tmp
, &end
, 10 );
914 if (*end
) /* invalid number */
916 SetLastError( ERROR_INVALID_FLAGS
);
919 ret
= sizeof(UINT
)/sizeof(WCHAR
);
920 if (!buffer
) return ret
;
923 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
926 memcpy( buffer
, &number
, sizeof(number
) );
929 else ret
= get_registry_locale_info( value
, buffer
, len
);
931 if (ret
!= -1) return ret
;
935 /* now load it from kernel resources */
937 lang_id
= LANGIDFROMLCID( lcid
);
939 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
940 if (SUBLANGID(lang_id
) == SUBLANG_NEUTRAL
)
941 lang_id
= MAKELANGID(PRIMARYLANGID(lang_id
), SUBLANG_DEFAULT
);
943 if (!(hrsrc
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
944 (LPCWSTR
)((lctype
>> 4) + 1), lang_id
)))
946 SetLastError( ERROR_INVALID_FLAGS
); /* no such lctype */
949 if (!(hmem
= LoadResource( kernel32_handle
, hrsrc
)))
952 p
= LockResource( hmem
);
953 for (i
= 0; i
< (lctype
& 0x0f); i
++) p
+= *p
+ 1;
955 if (lcflags
& LOCALE_RETURN_NUMBER
) ret
= sizeof(UINT
)/sizeof(WCHAR
);
956 else ret
= (lctype
== LOCALE_FONTSIGNATURE
) ? *p
: *p
+ 1;
958 if (!buffer
) return ret
;
962 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
966 if (lcflags
& LOCALE_RETURN_NUMBER
)
969 WCHAR
*end
, *tmp
= HeapAlloc( GetProcessHeap(), 0, (*p
+ 1) * sizeof(WCHAR
) );
971 memcpy( tmp
, p
+ 1, *p
* sizeof(WCHAR
) );
973 number
= strtolW( tmp
, &end
, 10 );
975 memcpy( buffer
, &number
, sizeof(number
) );
976 else /* invalid number */
978 SetLastError( ERROR_INVALID_FLAGS
);
981 HeapFree( GetProcessHeap(), 0, tmp
);
983 TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d) returning number %d\n",
984 lcid
, lctype
, buffer
, len
, number
);
988 memcpy( buffer
, p
+ 1, *p
* sizeof(WCHAR
) );
989 if (lctype
!= LOCALE_FONTSIGNATURE
) buffer
[ret
-1] = 0;
991 TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d) returning %d %s\n",
992 lcid
, lctype
, buffer
, len
, ret
, debugstr_w(buffer
) );
998 /******************************************************************************
999 * SetLocaleInfoA [KERNEL32.@]
1001 * Set information about an aspect of a locale.
1004 * lcid [I] LCID of the locale
1005 * lctype [I] LCTYPE_ flags from "winnls.h"
1006 * data [I] Information to set
1009 * Success: TRUE. The information given will be returned by GetLocaleInfoA()
1010 * whenever it is called without LOCALE_NOUSEROVERRIDE.
1011 * Failure: FALSE. Use GetLastError() to determine the cause.
1014 * - Values are only be set for the current user locale; the system locale
1015 * settings cannot be changed.
1016 * - Any settings changed by this call are lost when the locale is changed by
1017 * the control panel (in Wine, this happens every time you change LANG).
1018 * - The native implementation of this function does not check that lcid matches
1019 * the current user locale, and simply sets the new values. Wine warns you in
1020 * this case, but behaves the same.
1022 BOOL WINAPI
SetLocaleInfoA(LCID lcid
, LCTYPE lctype
, LPCSTR data
)
1024 UINT codepage
= CP_ACP
;
1029 lcid
= ConvertDefaultLocale(lcid
);
1031 if (!(lctype
& LOCALE_USE_CP_ACP
)) codepage
= get_lcid_codepage( lcid
);
1035 SetLastError( ERROR_INVALID_PARAMETER
);
1038 len
= MultiByteToWideChar( codepage
, 0, data
, -1, NULL
, 0 );
1039 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
1041 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1044 MultiByteToWideChar( codepage
, 0, data
, -1, strW
, len
);
1045 ret
= SetLocaleInfoW( lcid
, lctype
, strW
);
1046 HeapFree( GetProcessHeap(), 0, strW
);
1051 /******************************************************************************
1052 * SetLocaleInfoW (KERNEL32.@)
1054 * See SetLocaleInfoA.
1056 BOOL WINAPI
SetLocaleInfoW( LCID lcid
, LCTYPE lctype
, LPCWSTR data
)
1059 const WCHAR intlW
[] = {'i','n','t','l',0 };
1060 UNICODE_STRING valueW
;
1064 lcid
= ConvertDefaultLocale(lcid
);
1067 value
= get_locale_value_name( lctype
);
1069 if (!data
|| !value
)
1071 SetLastError( ERROR_INVALID_PARAMETER
);
1075 if (lctype
== LOCALE_IDATE
|| lctype
== LOCALE_ILDATE
)
1077 SetLastError( ERROR_INVALID_FLAGS
);
1081 if (lcid
!= GetUserDefaultLCID())
1083 /* Windows does not check that the lcid matches the current lcid */
1084 WARN("locale 0x%08lx isn't the current locale (0x%08lx), setting anyway!\n",
1085 lcid
, GetUserDefaultLCID());
1088 TRACE("setting %lx to %s\n", lctype
, debugstr_w(data
) );
1090 /* FIXME: should check that data to set is sane */
1092 /* FIXME: profile functions should map to registry */
1093 WriteProfileStringW( intlW
, value
, data
);
1095 if (!(hkey
= create_registry_key())) return FALSE
;
1096 RtlInitUnicodeString( &valueW
, value
);
1097 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, data
, (strlenW(data
)+1)*sizeof(WCHAR
) );
1099 if (lctype
== LOCALE_SDATE
|| lctype
== LOCALE_SLONGDATE
)
1101 /* Set I-value from S value */
1102 WCHAR
*lpD
, *lpM
, *lpY
;
1105 lpD
= strchrW(data
, 'd');
1106 lpM
= strchrW(data
, 'M');
1107 lpY
= strchrW(data
, 'y');
1111 szBuff
[0] = '1'; /* D-M-Y */
1116 szBuff
[0] = '2'; /* Y-M-D */
1118 szBuff
[0] = '0'; /* M-D-Y */
1123 if (lctype
== LOCALE_SDATE
)
1124 lctype
= LOCALE_IDATE
;
1126 lctype
= LOCALE_ILDATE
;
1128 value
= get_locale_value_name( lctype
);
1130 WriteProfileStringW( intlW
, value
, szBuff
);
1132 RtlInitUnicodeString( &valueW
, value
);
1133 status
= NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, szBuff
, sizeof(szBuff
) );
1138 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1143 /******************************************************************************
1144 * GetACP (KERNEL32.@)
1146 * Get the current Ansi code page Id for the system.
1152 * The current Ansi code page identifier for the system.
1154 UINT WINAPI
GetACP(void)
1156 assert( ansi_cptable
);
1157 return ansi_cptable
->info
.codepage
;
1161 /***********************************************************************
1162 * GetOEMCP (KERNEL32.@)
1164 * Get the current OEM code page Id for the system.
1170 * The current OEM code page identifier for the system.
1172 UINT WINAPI
GetOEMCP(void)
1174 assert( oem_cptable
);
1175 return oem_cptable
->info
.codepage
;
1179 /***********************************************************************
1180 * IsValidCodePage (KERNEL32.@)
1182 * Determine if a given code page identifier is valid.
1185 * codepage [I] Code page Id to verify.
1188 * TRUE, If codepage is valid and available on the system,
1191 BOOL WINAPI
IsValidCodePage( UINT codepage
)
1198 return wine_cp_get_table( codepage
) != NULL
;
1203 /***********************************************************************
1204 * IsDBCSLeadByteEx (KERNEL32.@)
1206 * Determine if a character is a lead byte in a given code page.
1209 * codepage [I] Code page for the test.
1210 * testchar [I] Character to test
1213 * TRUE, if testchar is a lead byte in codepage,
1216 BOOL WINAPI
IsDBCSLeadByteEx( UINT codepage
, BYTE testchar
)
1218 const union cptable
*table
= get_codepage_table( codepage
);
1219 return table
&& is_dbcs_leadbyte( table
, testchar
);
1223 /***********************************************************************
1224 * IsDBCSLeadByte (KERNEL32.@)
1225 * IsDBCSLeadByte (KERNEL.207)
1227 * Determine if a character is a lead byte.
1230 * testchar [I] Character to test
1233 * TRUE, if testchar is a lead byte in the Ansii code page,
1236 BOOL WINAPI
IsDBCSLeadByte( BYTE testchar
)
1238 if (!ansi_cptable
) return FALSE
;
1239 return is_dbcs_leadbyte( ansi_cptable
, testchar
);
1243 /***********************************************************************
1244 * GetCPInfo (KERNEL32.@)
1246 * Get information about a code page.
1249 * codepage [I] Code page number
1250 * cpinfo [O] Destination for code page information
1253 * Success: TRUE. cpinfo is updated with the information about codepage.
1254 * Failure: FALSE, if codepage is invalid or cpinfo is NULL.
1256 BOOL WINAPI
GetCPInfo( UINT codepage
, LPCPINFO cpinfo
)
1258 const union cptable
*table
= get_codepage_table( codepage
);
1262 SetLastError( ERROR_INVALID_PARAMETER
);
1265 if (table
->info
.def_char
& 0xff00)
1267 cpinfo
->DefaultChar
[0] = table
->info
.def_char
& 0xff00;
1268 cpinfo
->DefaultChar
[1] = table
->info
.def_char
& 0x00ff;
1272 cpinfo
->DefaultChar
[0] = table
->info
.def_char
& 0xff;
1273 cpinfo
->DefaultChar
[1] = 0;
1275 if ((cpinfo
->MaxCharSize
= table
->info
.char_size
) == 2)
1276 memcpy( cpinfo
->LeadByte
, table
->dbcs
.lead_bytes
, sizeof(cpinfo
->LeadByte
) );
1278 cpinfo
->LeadByte
[0] = cpinfo
->LeadByte
[1] = 0;
1283 /***********************************************************************
1284 * GetCPInfoExA (KERNEL32.@)
1286 * Get extended information about a code page.
1289 * codepage [I] Code page number
1290 * dwFlags [I] Reserved, must to 0.
1291 * cpinfo [O] Destination for code page information
1294 * Success: TRUE. cpinfo is updated with the information about codepage.
1295 * Failure: FALSE, if codepage is invalid or cpinfo is NULL.
1297 BOOL WINAPI
GetCPInfoExA( UINT codepage
, DWORD dwFlags
, LPCPINFOEXA cpinfo
)
1299 const union cptable
*table
= get_codepage_table( codepage
);
1301 if (!GetCPInfo( codepage
, (LPCPINFO
)cpinfo
))
1304 cpinfo
->CodePage
= codepage
;
1305 cpinfo
->UnicodeDefaultChar
= table
->info
.def_unicode_char
;
1306 strcpy(cpinfo
->CodePageName
, table
->info
.name
);
1310 /***********************************************************************
1311 * GetCPInfoExW (KERNEL32.@)
1313 * Unicode version of GetCPInfoExA.
1315 BOOL WINAPI
GetCPInfoExW( UINT codepage
, DWORD dwFlags
, LPCPINFOEXW cpinfo
)
1317 const union cptable
*table
= get_codepage_table( codepage
);
1319 if (!GetCPInfo( codepage
, (LPCPINFO
)cpinfo
))
1322 cpinfo
->CodePage
= codepage
;
1323 cpinfo
->UnicodeDefaultChar
= table
->info
.def_unicode_char
;
1324 MultiByteToWideChar( CP_ACP
, 0, table
->info
.name
, -1, cpinfo
->CodePageName
,
1325 sizeof(cpinfo
->CodePageName
)/sizeof(WCHAR
));
1329 /***********************************************************************
1330 * EnumSystemCodePagesA (KERNEL32.@)
1332 * Call a user defined function for every code page installed on the system.
1335 * lpfnCodePageEnum [I] User CODEPAGE_ENUMPROC to call with each found code page
1336 * flags [I] Reserved, set to 0.
1339 * TRUE, If all code pages have been enumerated, or
1340 * FALSE if lpfnCodePageEnum returned FALSE to stop the enumeration.
1342 BOOL WINAPI
EnumSystemCodePagesA( CODEPAGE_ENUMPROCA lpfnCodePageEnum
, DWORD flags
)
1344 const union cptable
*table
;
1350 if (!(table
= wine_cp_enum_table( index
++ ))) break;
1351 sprintf( buffer
, "%d", table
->info
.codepage
);
1352 if (!lpfnCodePageEnum( buffer
)) break;
1358 /***********************************************************************
1359 * EnumSystemCodePagesW (KERNEL32.@)
1361 * See EnumSystemCodePagesA.
1363 BOOL WINAPI
EnumSystemCodePagesW( CODEPAGE_ENUMPROCW lpfnCodePageEnum
, DWORD flags
)
1365 const union cptable
*table
;
1366 WCHAR buffer
[10], *p
;
1367 int page
, index
= 0;
1371 if (!(table
= wine_cp_enum_table( index
++ ))) break;
1372 p
= buffer
+ sizeof(buffer
)/sizeof(WCHAR
);
1374 page
= table
->info
.codepage
;
1377 *--p
= '0' + (page
% 10);
1380 if (!lpfnCodePageEnum( p
)) break;
1386 /***********************************************************************
1387 * MultiByteToWideChar (KERNEL32.@)
1389 * Convert a multibyte character string into a Unicode string.
1392 * page [I] Codepage character set to convert from
1393 * flags [I] Character mapping flags
1394 * src [I] Source string buffer
1395 * srclen [I] Length of src, or -1 if src is NUL terminated
1396 * dst [O] Destination buffer
1397 * dstlen [I] Length of dst, or 0 to compute the required length
1400 * Success: If dstlen > 0, the number of characters written to dst.
1401 * If dstlen == 0, the number of characters needed to perform the
1402 * conversion. In both cases the count includes the terminating NUL.
1403 * Failure: 0. Use GetLastError() to determine the cause. Possible errors are
1404 * ERROR_INSUFFICIENT_BUFFER, if not enough space is available in dst
1405 * and dstlen != 0; ERROR_INVALID_PARAMETER, if an invalid parameter
1406 * is passed, and ERROR_NO_UNICODE_TRANSLATION if no translation is
1409 INT WINAPI
MultiByteToWideChar( UINT page
, DWORD flags
, LPCSTR src
, INT srclen
,
1410 LPWSTR dst
, INT dstlen
)
1412 const union cptable
*table
;
1415 if (!src
|| (!dst
&& dstlen
))
1417 SetLastError( ERROR_INVALID_PARAMETER
);
1421 if (srclen
< 0) srclen
= strlen(src
) + 1;
1423 if (flags
& MB_USEGLYPHCHARS
) FIXME("MB_USEGLYPHCHARS not supported\n");
1430 SetLastError( ERROR_INVALID_PARAMETER
);
1433 ret
= wine_cpsymbol_mbstowcs( src
, srclen
, dst
, dstlen
);
1436 FIXME("UTF-7 not supported\n");
1437 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1442 ret
= wine_cp_mbstowcs( unix_cptable
, flags
, src
, srclen
, dst
, dstlen
);
1447 ret
= wine_utf8_mbstowcs( flags
, src
, srclen
, dst
, dstlen
);
1450 if (!(table
= get_codepage_table( page
)))
1452 SetLastError( ERROR_INVALID_PARAMETER
);
1455 ret
= wine_cp_mbstowcs( table
, flags
, src
, srclen
, dst
, dstlen
);
1463 case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER
); break;
1464 case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION
); break;
1472 /***********************************************************************
1473 * WideCharToMultiByte (KERNEL32.@)
1475 * Convert a Unicode character string into a multibyte string.
1478 * page [I] Code page character set to convert to
1479 * flags [I] Mapping Flags (MB_ constants from "winnls.h").
1480 * src [I] Source string buffer
1481 * srclen [I] Length of src, or -1 if src is NUL terminated
1482 * dst [O] Destination buffer
1483 * dstlen [I] Length of dst, or 0 to compute the required length
1484 * defchar [I] Default character to use for conversion if no exact
1485 * conversion can be made
1486 * used [O] Set if default character was used in the conversion
1489 * Success: If dstlen > 0, the number of characters written to dst.
1490 * If dstlen == 0, number of characters needed to perform the
1491 * conversion. In both cases the count includes the terminating NUL.
1492 * Failure: 0. Use GetLastError() to determine the cause. Possible errors are
1493 * ERROR_INSUFFICIENT_BUFFER, if not enough space is available in dst
1494 * and dstlen != 0, and ERROR_INVALID_PARAMETER, if an invalid
1495 * parameter was given.
1497 INT WINAPI
WideCharToMultiByte( UINT page
, DWORD flags
, LPCWSTR src
, INT srclen
,
1498 LPSTR dst
, INT dstlen
, LPCSTR defchar
, BOOL
*used
)
1500 const union cptable
*table
;
1503 if (!src
|| (!dst
&& dstlen
))
1505 SetLastError( ERROR_INVALID_PARAMETER
);
1509 if (srclen
< 0) srclen
= strlenW(src
) + 1;
1514 if( flags
|| defchar
|| used
)
1516 SetLastError( ERROR_INVALID_PARAMETER
);
1519 ret
= wine_cpsymbol_wcstombs( src
, srclen
, dst
, dstlen
);
1522 FIXME("UTF-7 not supported\n");
1523 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1528 ret
= wine_cp_wcstombs( unix_cptable
, flags
, src
, srclen
, dst
, dstlen
,
1529 defchar
, used
? &used_tmp
: NULL
);
1534 ret
= wine_utf8_wcstombs( src
, srclen
, dst
, dstlen
);
1537 if (!(table
= get_codepage_table( page
)))
1539 SetLastError( ERROR_INVALID_PARAMETER
);
1542 ret
= wine_cp_wcstombs( table
, flags
, src
, srclen
, dst
, dstlen
,
1543 defchar
, used
? &used_tmp
: NULL
);
1544 if (used
) *used
= used_tmp
;
1552 case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER
); break;
1553 case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION
); break;
1557 TRACE("cp %d %s -> %s\n", page
, debugstr_w(src
), debugstr_a(dst
));
1562 /***********************************************************************
1563 * GetThreadLocale (KERNEL32.@)
1565 * Get the current threads locale.
1571 * The LCID currently assocated with the calling thread.
1573 LCID WINAPI
GetThreadLocale(void)
1575 LCID ret
= NtCurrentTeb()->CurrentLocale
;
1576 if (!ret
) NtCurrentTeb()->CurrentLocale
= ret
= GetUserDefaultLCID();
1580 /**********************************************************************
1581 * SetThreadLocale (KERNEL32.@)
1583 * Set the current threads locale.
1586 * lcid [I] LCID of the locale to set
1589 * Success: TRUE. The threads locale is set to lcid.
1590 * Failure: FALSE. Use GetLastError() to determine the cause.
1592 BOOL WINAPI
SetThreadLocale( LCID lcid
)
1594 TRACE("(0x%04lX)\n", lcid
);
1596 lcid
= ConvertDefaultLocale(lcid
);
1598 if (lcid
!= GetThreadLocale())
1600 if (!IsValidLocale(lcid
, LCID_SUPPORTED
))
1602 SetLastError(ERROR_INVALID_PARAMETER
);
1606 NtCurrentTeb()->CurrentLocale
= lcid
;
1607 NtCurrentTeb()->code_page
= get_lcid_codepage( lcid
);
1612 /******************************************************************************
1613 * ConvertDefaultLocale (KERNEL32.@)
1615 * Convert a default locale identifier into a real identifier.
1618 * lcid [I] LCID identifier of the locale to convert
1621 * lcid unchanged, if not a default locale or its sublanguage is
1622 * not SUBLANG_NEUTRAL.
1623 * GetSystemDefaultLCID(), if lcid == LOCALE_SYSTEM_DEFAULT.
1624 * GetUserDefaultLCID(), if lcid == LOCALE_USER_DEFAULT or LOCALE_NEUTRAL.
1625 * Otherwise, lcid with sublanguage changed to SUBLANG_DEFAULT.
1627 LCID WINAPI
ConvertDefaultLocale( LCID lcid
)
1633 case LOCALE_SYSTEM_DEFAULT
:
1634 lcid
= GetSystemDefaultLCID();
1636 case LOCALE_USER_DEFAULT
:
1637 case LOCALE_NEUTRAL
:
1638 lcid
= GetUserDefaultLCID();
1641 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
1642 langid
= LANGIDFROMLCID(lcid
);
1643 if (SUBLANGID(langid
) == SUBLANG_NEUTRAL
)
1645 langid
= MAKELANGID(PRIMARYLANGID(langid
), SUBLANG_DEFAULT
);
1646 lcid
= MAKELCID(langid
, SORTIDFROMLCID(lcid
));
1653 /******************************************************************************
1654 * IsValidLocale (KERNEL32.@)
1656 * Determine if a locale is valid.
1659 * lcid [I] LCID of the locale to check
1660 * flags [I] LCID_SUPPORTED = Valid, LCID_INSTALLED = Valid and installed on the system
1663 * TRUE, if lcid is valid,
1667 * Wine does not currently make the distinction between supported and installed. All
1668 * languages supported are installed by default.
1670 BOOL WINAPI
IsValidLocale( LCID lcid
, DWORD flags
)
1672 /* check if language is registered in the kernel32 resources */
1673 return FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
,
1674 (LPCWSTR
)LOCALE_ILANGUAGE
, LANGIDFROMLCID(lcid
)) != 0;
1678 static BOOL CALLBACK
enum_lang_proc_a( HMODULE hModule
, LPCSTR type
,
1679 LPCSTR name
, WORD LangID
, LONG lParam
)
1681 LOCALE_ENUMPROCA lpfnLocaleEnum
= (LOCALE_ENUMPROCA
)lParam
;
1684 sprintf(buf
, "%08x", (UINT
)LangID
);
1685 return lpfnLocaleEnum( buf
);
1688 static BOOL CALLBACK
enum_lang_proc_w( HMODULE hModule
, LPCWSTR type
,
1689 LPCWSTR name
, WORD LangID
, LONG lParam
)
1691 static const WCHAR formatW
[] = {'%','0','8','x',0};
1692 LOCALE_ENUMPROCW lpfnLocaleEnum
= (LOCALE_ENUMPROCW
)lParam
;
1694 sprintfW( buf
, formatW
, (UINT
)LangID
);
1695 return lpfnLocaleEnum( buf
);
1698 /******************************************************************************
1699 * EnumSystemLocalesA (KERNEL32.@)
1701 * Call a users function for each locale available on the system.
1704 * lpfnLocaleEnum [I] Callback function to call for each locale
1705 * dwFlags [I] LOCALE_SUPPORTED=All supported, LOCALE_INSTALLED=Installed only
1709 * Failure: FALSE. Use GetLastError() to determine the cause.
1711 BOOL WINAPI
EnumSystemLocalesA( LOCALE_ENUMPROCA lpfnLocaleEnum
, DWORD dwFlags
)
1713 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
, dwFlags
);
1714 EnumResourceLanguagesA( kernel32_handle
, (LPSTR
)RT_STRING
,
1715 (LPCSTR
)LOCALE_ILANGUAGE
, enum_lang_proc_a
,
1716 (LONG
)lpfnLocaleEnum
);
1721 /******************************************************************************
1722 * EnumSystemLocalesW (KERNEL32.@)
1724 * See EnumSystemLocalesA.
1726 BOOL WINAPI
EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum
, DWORD dwFlags
)
1728 TRACE("(%p,%08lx)\n", lpfnLocaleEnum
, dwFlags
);
1729 EnumResourceLanguagesW( kernel32_handle
, (LPWSTR
)RT_STRING
,
1730 (LPCWSTR
)LOCALE_ILANGUAGE
, enum_lang_proc_w
,
1731 (LONG
)lpfnLocaleEnum
);
1736 /***********************************************************************
1737 * VerLanguageNameA (KERNEL32.@)
1739 * Get the name of a language.
1742 * wLang [I] LANGID of the language
1743 * szLang [O] Destination for the language name
1746 * Success: The size of the language name. If szLang is non-NULL, it is filled
1748 * Failure: 0. Use GetLastError() to determine the cause.
1751 DWORD WINAPI
VerLanguageNameA( UINT wLang
, LPSTR szLang
, UINT nSize
)
1753 return GetLocaleInfoA( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1757 /***********************************************************************
1758 * VerLanguageNameW (KERNEL32.@)
1760 * See VerLanguageNameA.
1762 DWORD WINAPI
VerLanguageNameW( UINT wLang
, LPWSTR szLang
, UINT nSize
)
1764 return GetLocaleInfoW( MAKELCID(wLang
, SORT_DEFAULT
), LOCALE_SENGLANGUAGE
, szLang
, nSize
);
1768 /******************************************************************************
1769 * GetStringTypeW (KERNEL32.@)
1771 * See GetStringTypeA.
1773 BOOL WINAPI
GetStringTypeW( DWORD type
, LPCWSTR src
, INT count
, LPWORD chartype
)
1775 if (count
== -1) count
= strlenW(src
) + 1;
1779 while (count
--) *chartype
++ = get_char_typeW( *src
++ ) & 0xfff;
1782 while (count
--) *chartype
++ = get_char_typeW( *src
++ ) >> 12;
1786 WARN("CT_CTYPE3: semi-stub.\n");
1790 WORD type1
, type3
= 0; /* C3_NOTAPPLICABLE */
1792 type1
= get_char_typeW( *src
++ ) & 0xfff;
1793 /* try to construct type3 from type1 */
1794 if(type1
& C1_SPACE
) type3
|= C3_SYMBOL
;
1795 if(type1
& C1_ALPHA
) type3
|= C3_ALPHA
;
1796 if ((c
>=0x30A0)&&(c
<=0x30FF)) type3
|= C3_KATAKANA
;
1797 if ((c
>=0x3040)&&(c
<=0x309F)) type3
|= C3_HIRAGANA
;
1798 if ((c
>=0x4E00)&&(c
<=0x9FAF)) type3
|= C3_IDEOGRAPH
;
1799 if ((c
>=0x0600)&&(c
<=0x06FF)) type3
|= C3_KASHIDA
;
1800 if ((c
>=0x3000)&&(c
<=0x303F)) type3
|= C3_SYMBOL
;
1802 if ((c
>=0xFF00)&&(c
<=0xFF60)) type3
|= C3_FULLWIDTH
;
1803 if ((c
>=0xFF00)&&(c
<=0xFF20)) type3
|= C3_SYMBOL
;
1804 if ((c
>=0xFF3B)&&(c
<=0xFF40)) type3
|= C3_SYMBOL
;
1805 if ((c
>=0xFF5B)&&(c
<=0xFF60)) type3
|= C3_SYMBOL
;
1806 if ((c
>=0xFF21)&&(c
<=0xFF3A)) type3
|= C3_ALPHA
;
1807 if ((c
>=0xFF41)&&(c
<=0xFF5A)) type3
|= C3_ALPHA
;
1808 if ((c
>=0xFFE0)&&(c
<=0xFFE6)) type3
|= C3_FULLWIDTH
;
1809 if ((c
>=0xFFE0)&&(c
<=0xFFE6)) type3
|= C3_SYMBOL
;
1811 if ((c
>=0xFF61)&&(c
<=0xFFDC)) type3
|= C3_HALFWIDTH
;
1812 if ((c
>=0xFF61)&&(c
<=0xFF64)) type3
|= C3_SYMBOL
;
1813 if ((c
>=0xFF65)&&(c
<=0xFF9F)) type3
|= C3_KATAKANA
;
1814 if ((c
>=0xFF65)&&(c
<=0xFF9F)) type3
|= C3_ALPHA
;
1815 if ((c
>=0xFFE8)&&(c
<=0xFFEE)) type3
|= C3_HALFWIDTH
;
1816 if ((c
>=0xFFE8)&&(c
<=0xFFEE)) type3
|= C3_SYMBOL
;
1817 *chartype
++ = type3
;
1822 SetLastError( ERROR_INVALID_PARAMETER
);
1829 /******************************************************************************
1830 * GetStringTypeExW (KERNEL32.@)
1832 * See GetStringTypeExA.
1834 BOOL WINAPI
GetStringTypeExW( LCID locale
, DWORD type
, LPCWSTR src
, INT count
, LPWORD chartype
)
1836 /* locale is ignored for Unicode */
1837 return GetStringTypeW( type
, src
, count
, chartype
);
1841 /******************************************************************************
1842 * GetStringTypeA (KERNEL32.@)
1844 * Get characteristics of the characters making up a string.
1847 * locale [I] Locale Id for the string
1848 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1849 * src [I] String to analyse
1850 * count [I] Length of src in chars, or -1 if src is NUL terminated
1851 * chartype [O] Destination for the calculated characteristics
1854 * Success: TRUE. chartype is filled with the requested characteristics of each char
1856 * Failure: FALSE. Use GetLastError() to determine the cause.
1858 BOOL WINAPI
GetStringTypeA( LCID locale
, DWORD type
, LPCSTR src
, INT count
, LPWORD chartype
)
1865 if(count
== -1) count
= strlen(src
) + 1;
1867 if (!(cp
= get_lcid_codepage( locale
)))
1869 FIXME("For locale %04lx using current ANSI code page\n", locale
);
1873 countW
= MultiByteToWideChar(cp
, 0, src
, count
, NULL
, 0);
1874 if((srcW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
1876 MultiByteToWideChar(cp
, 0, src
, count
, srcW
, countW
);
1878 * NOTE: the target buffer has 1 word for each CHARACTER in the source
1879 * string, with multibyte characters there maybe be more bytes in count
1880 * than character space in the buffer!
1882 ret
= GetStringTypeW(type
, srcW
, countW
, chartype
);
1883 HeapFree(GetProcessHeap(), 0, srcW
);
1888 /******************************************************************************
1889 * GetStringTypeExA (KERNEL32.@)
1891 * Get characteristics of the characters making up a string.
1894 * locale [I] Locale Id for the string
1895 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1896 * src [I] String to analyse
1897 * count [I] Length of src in chars, or -1 if src is NUL terminated
1898 * chartype [O] Destination for the calculated characteristics
1901 * Success: TRUE. chartype is filled with the requested characteristics of each char
1903 * Failure: FALSE. Use GetLastError() to determine the cause.
1905 BOOL WINAPI
GetStringTypeExA( LCID locale
, DWORD type
, LPCSTR src
, INT count
, LPWORD chartype
)
1907 return GetStringTypeA(locale
, type
, src
, count
, chartype
);
1911 /*************************************************************************
1912 * LCMapStringW (KERNEL32.@)
1916 INT WINAPI
LCMapStringW(LCID lcid
, DWORD flags
, LPCWSTR src
, INT srclen
,
1917 LPWSTR dst
, INT dstlen
)
1921 if (!src
|| !srclen
|| dstlen
< 0)
1923 SetLastError(ERROR_INVALID_PARAMETER
);
1927 /* mutually exclusive flags */
1928 if ((flags
& (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
)) == (LCMAP_LOWERCASE
| LCMAP_UPPERCASE
) ||
1929 (flags
& (LCMAP_HIRAGANA
| LCMAP_KATAKANA
)) == (LCMAP_HIRAGANA
| LCMAP_KATAKANA
) ||
1930 (flags
& (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
)) == (LCMAP_HALFWIDTH
| LCMAP_FULLWIDTH
) ||
1931 (flags
& (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
)) == (LCMAP_TRADITIONAL_CHINESE
| LCMAP_SIMPLIFIED_CHINESE
))
1933 SetLastError(ERROR_INVALID_FLAGS
);
1937 if (!dstlen
) dst
= NULL
;
1939 lcid
= ConvertDefaultLocale(lcid
);
1941 if (flags
& LCMAP_SORTKEY
)
1945 SetLastError(ERROR_INVALID_FLAGS
);
1949 if (srclen
< 0) srclen
= strlenW(src
);
1951 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1952 lcid
, flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
1954 return wine_get_sortkey(flags
, src
, srclen
, (char *)dst
, dstlen
);
1957 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
1958 if (flags
& SORT_STRINGSORT
)
1960 SetLastError(ERROR_INVALID_FLAGS
);
1964 if (srclen
< 0) srclen
= strlenW(src
) + 1;
1966 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1967 lcid
, flags
, debugstr_wn(src
, srclen
), srclen
, dst
, dstlen
);
1969 if (!dst
) /* return required string length */
1973 for (len
= 0; srclen
; src
++, srclen
--)
1976 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
1977 * and skips white space and punctuation characters for
1978 * NORM_IGNORESYMBOLS.
1980 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1987 if (flags
& LCMAP_UPPERCASE
)
1989 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
1992 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
1994 *dst_ptr
++ = toupperW(wch
);
1998 else if (flags
& LCMAP_LOWERCASE
)
2000 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
2003 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
2005 *dst_ptr
++ = tolowerW(wch
);
2013 SetLastError(ERROR_INVALID_FLAGS
);
2016 for (dst_ptr
= dst
; srclen
&& dstlen
; src
++, srclen
--)
2019 if ((flags
& NORM_IGNORESYMBOLS
) && (get_char_typeW(wch
) & (C1_PUNCT
| C1_SPACE
)))
2028 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2032 return dst_ptr
- dst
;
2035 /*************************************************************************
2036 * LCMapStringA (KERNEL32.@)
2038 * Map characters in a locale sensitive string.
2041 * lcid [I] LCID for the conversion.
2042 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h").
2043 * src [I] String to map
2044 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
2045 * dst [O] Destination for mapped string
2046 * dstlen [I] Length of dst in characters
2049 * Success: The length of the mapped string in dst, including the NUL terminator.
2050 * Failure: 0. Use GetLastError() to determine the cause.
2052 INT WINAPI
LCMapStringA(LCID lcid
, DWORD flags
, LPCSTR src
, INT srclen
,
2053 LPSTR dst
, INT dstlen
)
2055 WCHAR
*bufW
= NtCurrentTeb()->StaticUnicodeBuffer
;
2057 INT ret
= 0, srclenW
, dstlenW
;
2060 if (!src
|| !srclen
|| dstlen
< 0)
2062 SetLastError(ERROR_INVALID_PARAMETER
);
2066 locale_cp
= get_lcid_codepage(lcid
);
2068 srclenW
= MultiByteToWideChar(locale_cp
, 0, src
, srclen
, bufW
, 260);
2073 srclenW
= MultiByteToWideChar(locale_cp
, 0, src
, srclen
, NULL
, 0);
2074 srcW
= HeapAlloc(GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
));
2077 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2080 MultiByteToWideChar(locale_cp
, 0, src
, srclen
, srcW
, srclenW
);
2083 if (flags
& LCMAP_SORTKEY
)
2087 SetLastError(ERROR_INVALID_FLAGS
);
2088 goto map_string_exit
;
2090 ret
= wine_get_sortkey(flags
, srcW
, srclenW
, dst
, dstlen
);
2091 goto map_string_exit
;
2094 if (flags
& SORT_STRINGSORT
)
2096 SetLastError(ERROR_INVALID_FLAGS
);
2097 goto map_string_exit
;
2100 dstlenW
= LCMapStringW(lcid
, flags
, srcW
, srclenW
, NULL
, 0);
2102 goto map_string_exit
;
2104 dstW
= HeapAlloc(GetProcessHeap(), 0, dstlenW
* sizeof(WCHAR
));
2107 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2108 goto map_string_exit
;
2111 LCMapStringW(lcid
, flags
, srcW
, srclenW
, dstW
, dstlenW
);
2112 ret
= WideCharToMultiByte(locale_cp
, 0, dstW
, dstlenW
, dst
, dstlen
, NULL
, NULL
);
2113 HeapFree(GetProcessHeap(), 0, dstW
);
2116 if (srcW
!= bufW
) HeapFree(GetProcessHeap(), 0, srcW
);
2120 /*************************************************************************
2121 * FoldStringA (KERNEL32.@)
2123 * Map characters in a string.
2126 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
2127 * src [I] String to map
2128 * srclen [I] Length of src, or -1 if src is NUL terminated
2129 * dst [O] Destination for mapped string
2130 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
2133 * Success: The length of the string written to dst, including the terminating NUL. If
2134 * dstlen is 0, the value returned is the same, but nothing is written to dst,
2135 * and dst may be NULL.
2136 * Failure: 0. Use GetLastError() to determine the cause.
2138 INT WINAPI
FoldStringA(DWORD dwFlags
, LPCSTR src
, INT srclen
,
2139 LPSTR dst
, INT dstlen
)
2141 INT ret
= 0, srclenW
= 0;
2142 WCHAR
*srcW
= NULL
, *dstW
= NULL
;
2144 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
2146 SetLastError(ERROR_INVALID_PARAMETER
);
2150 srclenW
= MultiByteToWideChar(CP_ACP
, dwFlags
& MAP_COMPOSITE
? MB_COMPOSITE
: 0,
2151 src
, srclen
, NULL
, 0);
2152 srcW
= HeapAlloc(GetProcessHeap(), 0, srclenW
* sizeof(WCHAR
));
2156 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2157 goto FoldStringA_exit
;
2160 MultiByteToWideChar(CP_ACP
, dwFlags
& MAP_COMPOSITE
? MB_COMPOSITE
: 0,
2161 src
, srclen
, srcW
, srclenW
);
2163 dwFlags
= (dwFlags
& ~MAP_PRECOMPOSED
) | MAP_FOLDCZONE
;
2165 ret
= FoldStringW(dwFlags
, srcW
, srclenW
, NULL
, 0);
2168 dstW
= HeapAlloc(GetProcessHeap(), 0, ret
* sizeof(WCHAR
));
2172 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2173 goto FoldStringA_exit
;
2176 ret
= FoldStringW(dwFlags
, srcW
, srclenW
, dstW
, ret
);
2177 if (!WideCharToMultiByte(CP_ACP
, 0, dstW
, ret
, dst
, dstlen
, NULL
, NULL
))
2180 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2185 HeapFree(GetProcessHeap(), 0, dstW
);
2189 HeapFree(GetProcessHeap(), 0, srcW
);
2193 /*************************************************************************
2194 * FoldStringW (KERNEL32.@)
2198 INT WINAPI
FoldStringW(DWORD dwFlags
, LPCWSTR src
, INT srclen
,
2199 LPWSTR dst
, INT dstlen
)
2203 switch (dwFlags
& (MAP_COMPOSITE
|MAP_PRECOMPOSED
|MAP_EXPAND_LIGATURES
))
2208 /* Fall through for dwFlags == 0 */
2209 case MAP_PRECOMPOSED
|MAP_COMPOSITE
:
2210 case MAP_PRECOMPOSED
|MAP_EXPAND_LIGATURES
:
2211 case MAP_COMPOSITE
|MAP_EXPAND_LIGATURES
:
2212 SetLastError(ERROR_INVALID_FLAGS
);
2216 if (!src
|| !srclen
|| dstlen
< 0 || (dstlen
&& !dst
) || src
== dst
)
2218 SetLastError(ERROR_INVALID_PARAMETER
);
2222 ret
= wine_fold_string(dwFlags
, src
, srclen
, dst
, dstlen
);
2224 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2228 /******************************************************************************
2229 * CompareStringW (KERNEL32.@)
2231 * See CompareStringA.
2233 INT WINAPI
CompareStringW(LCID lcid
, DWORD style
,
2234 LPCWSTR str1
, INT len1
, LPCWSTR str2
, INT len2
)
2240 SetLastError(ERROR_INVALID_PARAMETER
);
2244 if( style
& ~(NORM_IGNORECASE
|NORM_IGNORENONSPACE
|NORM_IGNORESYMBOLS
|
2245 SORT_STRINGSORT
|NORM_IGNOREKANATYPE
|NORM_IGNOREWIDTH
|0x10000000) )
2247 SetLastError(ERROR_INVALID_FLAGS
);
2251 if (style
& 0x10000000)
2252 FIXME("Ignoring unknown style 0x10000000\n");
2254 if (len1
< 0) len1
= strlenW(str1
);
2255 if (len2
< 0) len2
= strlenW(str2
);
2257 ret
= wine_compare_string(style
, str1
, len1
, str2
, len2
);
2259 if (ret
) /* need to translate result */
2260 return (ret
< 0) ? CSTR_LESS_THAN
: CSTR_GREATER_THAN
;
2264 /******************************************************************************
2265 * CompareStringA (KERNEL32.@)
2267 * Compare two locale sensitive strings.
2270 * lcid [I] LCID for the comparason
2271 * style [I] Flags for the comparason (NORM_ constants from "winnls.h").
2272 * str1 [I] First string to compare
2273 * len1 [I] Length of str1, or -1 if str1 is NUL terminated
2274 * str2 [I] Second string to compare
2275 * len2 [I] Length of str2, or -1 if str2 is NUL terminated
2278 * Success: CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN depending on whether
2279 * str2 is less than, equal to or greater than str1 respectively.
2280 * Failure: FALSE. Use GetLastError() to determine the cause.
2282 INT WINAPI
CompareStringA(LCID lcid
, DWORD style
,
2283 LPCSTR str1
, INT len1
, LPCSTR str2
, INT len2
)
2285 WCHAR
*buf1W
= NtCurrentTeb()->StaticUnicodeBuffer
;
2286 WCHAR
*buf2W
= buf1W
+ 130;
2287 LPWSTR str1W
, str2W
;
2288 INT len1W
, len2W
, ret
;
2293 SetLastError(ERROR_INVALID_PARAMETER
);
2296 if (len1
< 0) len1
= strlen(str1
);
2297 if (len2
< 0) len2
= strlen(str2
);
2299 locale_cp
= get_lcid_codepage(lcid
);
2301 len1W
= MultiByteToWideChar(locale_cp
, 0, str1
, len1
, buf1W
, 130);
2306 len1W
= MultiByteToWideChar(locale_cp
, 0, str1
, len1
, NULL
, 0);
2307 str1W
= HeapAlloc(GetProcessHeap(), 0, len1W
* sizeof(WCHAR
));
2310 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2313 MultiByteToWideChar(locale_cp
, 0, str1
, len1
, str1W
, len1W
);
2315 len2W
= MultiByteToWideChar(locale_cp
, 0, str2
, len2
, buf2W
, 130);
2320 len2W
= MultiByteToWideChar(locale_cp
, 0, str2
, len2
, NULL
, 0);
2321 str2W
= HeapAlloc(GetProcessHeap(), 0, len2W
* sizeof(WCHAR
));
2324 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
2325 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2328 MultiByteToWideChar(locale_cp
, 0, str2
, len2
, str2W
, len2W
);
2331 ret
= CompareStringW(lcid
, style
, str1W
, len1W
, str2W
, len2W
);
2333 if (str1W
!= buf1W
) HeapFree(GetProcessHeap(), 0, str1W
);
2334 if (str2W
!= buf2W
) HeapFree(GetProcessHeap(), 0, str2W
);
2338 /*************************************************************************
2339 * lstrcmp (KERNEL32.@)
2340 * lstrcmpA (KERNEL32.@)
2342 * Compare two strings using the current thread locale.
2345 * str1 [I] First string to compare
2346 * str2 [I] Second string to compare
2349 * Success: A number less than, equal to or greater than 0 depending on whether
2350 * str2 is less than, equal to or greater than str1 respectively.
2351 * Failure: FALSE. Use GetLastError() to determine the cause.
2353 int WINAPI
lstrcmpA(LPCSTR str1
, LPCSTR str2
)
2355 int ret
= CompareStringA(GetThreadLocale(), 0, str1
, -1, str2
, -1);
2360 /*************************************************************************
2361 * lstrcmpi (KERNEL32.@)
2362 * lstrcmpiA (KERNEL32.@)
2364 * Compare two strings using the current thread locale, ignoring case.
2367 * str1 [I] First string to compare
2368 * str2 [I] Second string to compare
2371 * Success: A number less than, equal to or greater than 0 depending on whether
2372 * str2 is less than, equal to or greater than str1 respectively.
2373 * Failure: FALSE. Use GetLastError() to determine the cause.
2375 int WINAPI
lstrcmpiA(LPCSTR str1
, LPCSTR str2
)
2377 int ret
= CompareStringA(GetThreadLocale(), NORM_IGNORECASE
, str1
, -1, str2
, -1);
2382 /*************************************************************************
2383 * lstrcmpW (KERNEL32.@)
2387 int WINAPI
lstrcmpW(LPCWSTR str1
, LPCWSTR str2
)
2389 int ret
= CompareStringW(GetThreadLocale(), 0, str1
, -1, str2
, -1);
2394 /*************************************************************************
2395 * lstrcmpiW (KERNEL32.@)
2399 int WINAPI
lstrcmpiW(LPCWSTR str1
, LPCWSTR str2
)
2401 int ret
= CompareStringW(GetThreadLocale(), NORM_IGNORECASE
, str1
, -1, str2
, -1);
2406 /******************************************************************************
2409 void LOCALE_Init(void)
2411 extern void __wine_init_codepages( const union cptable
*ansi_cp
, const union cptable
*oem_cp
,
2412 const union cptable
*unix_cp
);
2414 UINT ansi_cp
= 1252, oem_cp
= 437, mac_cp
= 10000, unix_cp
= ~0U;
2415 LCID lcid
= init_default_lcid( &unix_cp
);
2417 NtSetDefaultLocale( FALSE
, lcid
);
2418 NtSetDefaultLocale( TRUE
, lcid
);
2420 ansi_cp
= get_lcid_codepage(lcid
);
2421 GetLocaleInfoW( lcid
, LOCALE_IDEFAULTMACCODEPAGE
| LOCALE_RETURN_NUMBER
,
2422 (LPWSTR
)&mac_cp
, sizeof(mac_cp
)/sizeof(WCHAR
) );
2423 GetLocaleInfoW( lcid
, LOCALE_IDEFAULTCODEPAGE
| LOCALE_RETURN_NUMBER
,
2424 (LPWSTR
)&oem_cp
, sizeof(oem_cp
)/sizeof(WCHAR
) );
2426 GetLocaleInfoW( lcid
, LOCALE_IDEFAULTUNIXCODEPAGE
| LOCALE_RETURN_NUMBER
,
2427 (LPWSTR
)&unix_cp
, sizeof(unix_cp
)/sizeof(WCHAR
) );
2429 if (!(ansi_cptable
= wine_cp_get_table( ansi_cp
)))
2430 ansi_cptable
= wine_cp_get_table( 1252 );
2431 if (!(oem_cptable
= wine_cp_get_table( oem_cp
)))
2432 oem_cptable
= wine_cp_get_table( 437 );
2433 if (!(mac_cptable
= wine_cp_get_table( mac_cp
)))
2434 mac_cptable
= wine_cp_get_table( 10000 );
2435 if (unix_cp
!= CP_UTF8
)
2437 if (!(unix_cptable
= wine_cp_get_table( unix_cp
)))
2438 unix_cptable
= wine_cp_get_table( 28591 );
2441 __wine_init_codepages( ansi_cptable
, oem_cptable
, unix_cptable
);
2443 TRACE( "ansi=%03d oem=%03d mac=%03d unix=%03d\n",
2444 ansi_cptable
->info
.codepage
, oem_cptable
->info
.codepage
,
2445 mac_cptable
->info
.codepage
, unix_cp
);
2448 static HKEY
NLS_RegOpenKey(HKEY hRootKey
, LPCWSTR szKeyName
)
2450 UNICODE_STRING keyName
;
2451 OBJECT_ATTRIBUTES attr
;
2454 RtlInitUnicodeString( &keyName
, szKeyName
);
2455 InitializeObjectAttributes(&attr
, &keyName
, 0, hRootKey
, NULL
);
2457 if (NtOpenKey( &hkey
, KEY_ALL_ACCESS
, &attr
) != STATUS_SUCCESS
)
2463 static HKEY
NLS_RegOpenSubKey(HKEY hRootKey
, LPCWSTR szKeyName
)
2465 HKEY hKey
= NLS_RegOpenKey(hRootKey
, szKeyName
);
2468 NtClose( hRootKey
);
2473 static BOOL
NLS_RegEnumSubKey(HKEY hKey
, UINT ulIndex
, LPWSTR szKeyName
,
2477 KEY_BASIC_INFORMATION
*info
= (KEY_BASIC_INFORMATION
*)buffer
;
2480 if (NtEnumerateKey( hKey
, ulIndex
, KeyBasicInformation
, buffer
,
2481 sizeof(buffer
), &dwLen
) != STATUS_SUCCESS
||
2482 info
->NameLength
> keyNameSize
)
2487 TRACE("info->Name %s info->NameLength %ld\n", debugstr_w(info
->Name
), info
->NameLength
);
2489 memcpy( szKeyName
, info
->Name
, info
->NameLength
);
2490 szKeyName
[info
->NameLength
/ sizeof(WCHAR
)] = '\0';
2492 TRACE("returning %s\n", debugstr_w(szKeyName
));
2496 static BOOL
NLS_RegEnumValue(HKEY hKey
, UINT ulIndex
,
2497 LPWSTR szValueName
, ULONG valueNameSize
,
2498 LPWSTR szValueData
, ULONG valueDataSize
)
2501 KEY_VALUE_FULL_INFORMATION
*info
= (KEY_VALUE_FULL_INFORMATION
*)buffer
;
2504 if (NtEnumerateValueKey( hKey
, ulIndex
, KeyValueFullInformation
,
2505 buffer
, sizeof(buffer
), &dwLen
) != STATUS_SUCCESS
||
2506 info
->NameLength
> valueNameSize
||
2507 info
->DataLength
> valueDataSize
)
2512 TRACE("info->Name %s info->DataLength %ld\n", debugstr_w(info
->Name
), info
->DataLength
);
2514 memcpy( szValueName
, info
->Name
, info
->NameLength
);
2515 szValueName
[info
->NameLength
/ sizeof(WCHAR
)] = '\0';
2516 memcpy( szValueData
, buffer
+ info
->DataOffset
, info
->DataLength
);
2517 szValueData
[info
->DataLength
/ sizeof(WCHAR
)] = '\0';
2519 TRACE("returning %s %s\n", debugstr_w(szValueName
), debugstr_w(szValueData
));
2523 static BOOL
NLS_RegGetDword(HKEY hKey
, LPCWSTR szValueName
, DWORD
*lpVal
)
2526 const KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buffer
;
2527 DWORD dwSize
= sizeof(buffer
);
2528 UNICODE_STRING valueName
;
2530 RtlInitUnicodeString( &valueName
, szValueName
);
2532 TRACE("%p, %s\n", hKey
, debugstr_w(szValueName
));
2533 if (NtQueryValueKey( hKey
, &valueName
, KeyValuePartialInformation
,
2534 buffer
, dwSize
, &dwSize
) == STATUS_SUCCESS
&&
2535 info
->DataLength
== sizeof(DWORD
))
2537 memcpy(lpVal
, info
->Data
, sizeof(DWORD
));
2544 static BOOL
NLS_GetLanguageGroupName(LGRPID lgrpid
, LPWSTR szName
, ULONG nameSize
)
2547 LPCWSTR szResourceName
= (LPCWSTR
)(((lgrpid
+ 0x2000) >> 4) + 1);
2551 /* FIXME: Is it correct to use the system default langid? */
2552 langId
= GetSystemDefaultLangID();
2554 if (SUBLANGID(langId
) == SUBLANG_NEUTRAL
)
2555 langId
= MAKELANGID( PRIMARYLANGID(langId
), SUBLANG_DEFAULT
);
2557 hResource
= FindResourceExW( kernel32_handle
, (LPWSTR
)RT_STRING
, szResourceName
, langId
);
2561 HGLOBAL hResDir
= LoadResource( kernel32_handle
, hResource
);
2565 ULONG iResourceIndex
= lgrpid
& 0xf;
2566 LPCWSTR lpResEntry
= LockResource( hResDir
);
2569 for (i
= 0; i
< iResourceIndex
; i
++)
2570 lpResEntry
+= *lpResEntry
+ 1;
2572 if (*lpResEntry
< nameSize
)
2574 memcpy( szName
, lpResEntry
+ 1, *lpResEntry
* sizeof(WCHAR
) );
2575 szName
[*lpResEntry
] = '\0';
2580 FreeResource( hResource
);
2585 /* Registry keys for NLS related information */
2586 static const WCHAR szNlsKeyName
[] = {
2587 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
2588 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
2589 'C','o','n','t','r','o','l','\\','N','l','s','\0'
2592 static const WCHAR szLangGroupsKeyName
[] = {
2593 'L','a','n','g','u','a','g','e',' ','G','r','o','u','p','s','\0'
2596 static const WCHAR szCountryListName
[] = {
2597 'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
2598 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
2599 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2600 'T','e','l','e','p','h','o','n','y','\\',
2601 'C','o','u','n','t','r','y',' ','L','i','s','t','\0'
2605 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
2608 LANGUAGEGROUP_ENUMPROCA procA
;
2609 LANGUAGEGROUP_ENUMPROCW procW
;
2612 } ENUMLANGUAGEGROUP_CALLBACKS
;
2614 /* Internal implementation of EnumSystemLanguageGroupsA/W */
2615 static BOOL
NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS
*lpProcs
)
2617 WCHAR szNumber
[10], szValue
[4];
2619 BOOL bContinue
= TRUE
;
2624 SetLastError(ERROR_INVALID_PARAMETER
);
2628 switch (lpProcs
->dwFlags
)
2631 /* Default to LGRPID_INSTALLED */
2632 lpProcs
->dwFlags
= LGRPID_INSTALLED
;
2633 /* Fall through... */
2634 case LGRPID_INSTALLED
:
2635 case LGRPID_SUPPORTED
:
2638 SetLastError(ERROR_INVALID_FLAGS
);
2642 hKey
= NLS_RegOpenSubKey( NLS_RegOpenKey( 0, szNlsKeyName
), szLangGroupsKeyName
);
2645 WARN("NLS registry key not found. Please apply the default registry file 'winedefault.reg'\n");
2649 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
2650 szValue
, sizeof(szValue
) ))
2652 BOOL bInstalled
= szValue
[0] == '1' ? TRUE
: FALSE
;
2653 LGRPID lgrpid
= strtoulW( szNumber
, NULL
, 16 );
2655 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber
),
2656 bInstalled
? "" : "not ");
2658 if (lpProcs
->dwFlags
== LGRPID_SUPPORTED
|| bInstalled
)
2660 WCHAR szGrpName
[48];
2662 if (!NLS_GetLanguageGroupName( lgrpid
, szGrpName
, sizeof(szGrpName
) / sizeof(WCHAR
) ))
2663 szGrpName
[0] = '\0';
2666 bContinue
= lpProcs
->procW( lgrpid
, szNumber
, szGrpName
, lpProcs
->dwFlags
,
2670 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
2671 char szGrpNameA
[48];
2673 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
2674 * or whether the language names are ever localised. Assume CP_ACP.
2677 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
2678 WideCharToMultiByte(CP_ACP
, 0, szGrpName
, -1, szGrpNameA
, sizeof(szGrpNameA
), 0, 0);
2680 bContinue
= lpProcs
->procA( lgrpid
, szNumberA
, szGrpNameA
, lpProcs
->dwFlags
,
2700 /******************************************************************************
2701 * EnumSystemLanguageGroupsA (KERNEL32.@)
2703 * Call a users function for each language group available on the system.
2706 * pLangGrpEnumProc [I] Callback function to call for each language group
2707 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
2708 * lParam [I] User parameter to pass to pLangGrpEnumProc
2712 * Failure: FALSE. Use GetLastError() to determine the cause.
2714 BOOL WINAPI
EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc
,
2715 DWORD dwFlags
, LONG_PTR lParam
)
2717 ENUMLANGUAGEGROUP_CALLBACKS procs
;
2719 TRACE("(%p,0x%08lX,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
2721 procs
.procA
= pLangGrpEnumProc
;
2723 procs
.dwFlags
= dwFlags
;
2724 procs
.lParam
= lParam
;
2726 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
2729 /******************************************************************************
2730 * EnumSystemLanguageGroupsW (KERNEL32.@)
2732 * See EnumSystemLanguageGroupsA.
2734 BOOL WINAPI
EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc
,
2735 DWORD dwFlags
, LONG_PTR lParam
)
2737 ENUMLANGUAGEGROUP_CALLBACKS procs
;
2739 TRACE("(%p,0x%08lX,0x%08lX)\n", pLangGrpEnumProc
, dwFlags
, lParam
);
2742 procs
.procW
= pLangGrpEnumProc
;
2743 procs
.dwFlags
= dwFlags
;
2744 procs
.lParam
= lParam
;
2746 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc
? &procs
: NULL
);
2749 /******************************************************************************
2750 * IsValidLanguageGroup (KERNEL32.@)
2752 * Determine if a language group is supported and/or installed.
2755 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
2756 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
2759 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
2762 BOOL WINAPI
IsValidLanguageGroup(LGRPID lgrpid
, DWORD dwFlags
)
2764 static const WCHAR szFormat
[] = { '%','x','\0' };
2765 WCHAR szValueName
[16], szValue
[2];
2766 BOOL bSupported
= FALSE
, bInstalled
= FALSE
;
2772 case LGRPID_INSTALLED
:
2773 case LGRPID_SUPPORTED
:
2775 hKey
= NLS_RegOpenSubKey( NLS_RegOpenKey( 0, szNlsKeyName
), szLangGroupsKeyName
);
2777 sprintfW( szValueName
, szFormat
, lgrpid
);
2779 if (NLS_RegGetDword( hKey
, szValueName
, (LPDWORD
)&szValue
))
2783 if (szValue
[0] == '1')
2793 if ((dwFlags
== LGRPID_SUPPORTED
&& bSupported
) ||
2794 (dwFlags
== LGRPID_INSTALLED
&& bInstalled
))
2800 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
2803 LANGGROUPLOCALE_ENUMPROCA procA
;
2804 LANGGROUPLOCALE_ENUMPROCW procW
;
2808 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS
;
2810 /* Internal implementation of EnumLanguageGrouplocalesA/W */
2811 static BOOL
NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS
*lpProcs
)
2813 static const WCHAR szLocaleKeyName
[] = {
2814 'L','o','c','a','l','e','\0'
2816 static const WCHAR szAlternateSortsKeyName
[] = {
2817 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
2819 WCHAR szNumber
[10], szValue
[4];
2821 BOOL bContinue
= TRUE
, bAlternate
= FALSE
;
2823 ULONG ulIndex
= 1; /* Ignore default entry of 1st key */
2825 if (!lpProcs
|| !lpProcs
->lgrpid
|| lpProcs
->lgrpid
> LGRPID_ARMENIAN
)
2827 SetLastError(ERROR_INVALID_PARAMETER
);
2831 if (lpProcs
->dwFlags
)
2833 SetLastError(ERROR_INVALID_FLAGS
);
2837 hKey
= NLS_RegOpenSubKey( NLS_RegOpenKey( 0, szNlsKeyName
), szLocaleKeyName
);
2840 WARN("NLS registry key not found. Please apply the default registry file 'winedefault.reg'\n");
2844 if (NLS_RegEnumValue( hKey
, ulIndex
, szNumber
, sizeof(szNumber
),
2845 szValue
, sizeof(szValue
) ))
2847 lgrpid
= strtoulW( szValue
, NULL
, 16 );
2849 TRACE("lcid %s, grpid %ld (%smatched)\n", debugstr_w(szNumber
),
2850 lgrpid
, lgrpid
== lpProcs
->lgrpid
? "" : "not ");
2852 if (lgrpid
== lpProcs
->lgrpid
)
2856 lcid
= strtoulW( szNumber
, NULL
, 16 );
2858 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
2859 * '00000437 ;Georgian'
2860 * At present we only pass the LCID string.
2864 bContinue
= lpProcs
->procW( lgrpid
, lcid
, szNumber
, lpProcs
->lParam
);
2867 char szNumberA
[sizeof(szNumber
)/sizeof(WCHAR
)];
2869 WideCharToMultiByte(CP_ACP
, 0, szNumber
, -1, szNumberA
, sizeof(szNumberA
), 0, 0);
2871 bContinue
= lpProcs
->procA( lgrpid
, lcid
, szNumberA
, lpProcs
->lParam
);
2879 /* Finished enumerating this key */
2882 /* Enumerate alternate sorts also */
2883 hKey
= NLS_RegOpenKey( hKey
, szAlternateSortsKeyName
);
2888 bContinue
= FALSE
; /* Finished both keys */
2901 /******************************************************************************
2902 * EnumLanguageGroupLocalesA (KERNEL32.@)
2904 * Call a users function for every locale in a language group available on the system.
2907 * pLangGrpLcEnumProc [I] Callback function to call for each locale
2908 * lgrpid [I] Language group (LGRPID_ values from "winnls.h")
2909 * dwFlags [I] Reserved, set to 0
2910 * lParam [I] User parameter to pass to pLangGrpLcEnumProc
2914 * Failure: FALSE. Use GetLastError() to determine the cause.
2916 BOOL WINAPI
EnumLanguageGroupLocalesA(LANGGROUPLOCALE_ENUMPROCA pLangGrpLcEnumProc
,
2917 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
2919 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
2921 TRACE("(%p,0x%08lX,0x%08lX,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
2923 callbacks
.procA
= pLangGrpLcEnumProc
;
2924 callbacks
.procW
= NULL
;
2925 callbacks
.dwFlags
= dwFlags
;
2926 callbacks
.lgrpid
= lgrpid
;
2927 callbacks
.lParam
= lParam
;
2929 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
2932 /******************************************************************************
2933 * EnumLanguageGroupLocalesW (KERNEL32.@)
2935 * See EnumLanguageGroupLocalesA.
2937 BOOL WINAPI
EnumLanguageGroupLocalesW(LANGGROUPLOCALE_ENUMPROCW pLangGrpLcEnumProc
,
2938 LGRPID lgrpid
, DWORD dwFlags
, LONG_PTR lParam
)
2940 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks
;
2942 TRACE("(%p,0x%08lX,0x%08lX,0x%08lX)\n", pLangGrpLcEnumProc
, lgrpid
, dwFlags
, lParam
);
2944 callbacks
.procA
= NULL
;
2945 callbacks
.procW
= pLangGrpLcEnumProc
;
2946 callbacks
.dwFlags
= dwFlags
;
2947 callbacks
.lgrpid
= lgrpid
;
2948 callbacks
.lParam
= lParam
;
2950 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc
? &callbacks
: NULL
);
2953 /******************************************************************************
2954 * EnumSystemGeoID (KERNEL32.@)
2956 * Call a users function for every location available on the system.
2959 * geoclass [I] Type of information desired (SYSGEOTYPE enum from "winnls.h")
2960 * reserved [I] Reserved, set to 0
2961 * pGeoEnumProc [I] Callback function to call for each location
2965 * Failure: FALSE. Use GetLastError() to determine the cause.
2967 BOOL WINAPI
EnumSystemGeoID(GEOCLASS geoclass
, GEOID reserved
, GEO_ENUMPROC pGeoEnumProc
)
2969 static const WCHAR szCountryCodeValueName
[] = {
2970 'C','o','u','n','t','r','y','C','o','d','e','\0'
2976 TRACE("(0x%08lX,0x%08lX,%p)\n", geoclass
, reserved
, pGeoEnumProc
);
2978 if (geoclass
!= GEOCLASS_NATION
|| reserved
|| !pGeoEnumProc
)
2980 SetLastError(ERROR_INVALID_PARAMETER
);
2984 hKey
= NLS_RegOpenKey( 0, szCountryListName
);
2986 while (NLS_RegEnumSubKey( hKey
, ulIndex
, szNumber
, sizeof(szNumber
) ))
2988 BOOL bContinue
= TRUE
;
2990 HKEY hSubKey
= NLS_RegOpenKey( hKey
, szNumber
);
2994 if (NLS_RegGetDword( hSubKey
, szCountryCodeValueName
, &dwGeoId
))
2996 TRACE("Got geoid %ld\n", dwGeoId
);
2998 if (!pGeoEnumProc( dwGeoId
))
3017 /******************************************************************************
3018 * InvalidateNLSCache (KERNEL32.@)
3020 * Invalidate the cache of NLS values.
3029 BOOL WINAPI
InvalidateNLSCache(void)
3035 /******************************************************************************
3036 * GetUserGeoID (KERNEL32.@)
3038 GEOID WINAPI
GetUserGeoID( GEOCLASS GeoClass
)
3040 FIXME("%ld\n",GeoClass
);
3041 return GEOID_NOT_AVAILABLE
;
3044 /******************************************************************************
3045 * SetUserGeoID (KERNEL32.@)
3047 BOOL WINAPI
SetUserGeoID( GEOID GeoID
)
3049 FIXME("%ld\n",GeoID
);