Sweden-Number/dlls/kernel/locale.c

2187 lines
68 KiB
C

/*
* Locale support
*
* Copyright 1995 Martin von Loewis
* Copyright 1998 David Lee Lambert
* Copyright 2000 Julio César Gázquez
* Copyright 2002 Alexandre Julliard for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "wine/port.h"
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include "ntstatus.h"
#include "windef.h"
#include "winbase.h"
#include "winuser.h" /* for RT_STRINGW */
#include "winreg.h"
#include "winternl.h"
#include "wine/unicode.h"
#include "winnls.h"
#include "winerror.h"
#include "thread.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(nls);
#define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|LOCALE_RETURN_NUMBER)
static const WCHAR kernel32W[] = { 'K','E','R','N','E','L','3','2','\0' };
extern void CODEPAGE_Init( UINT ansi_cp, UINT oem_cp, UINT mac_cp, UINT unix_cp, LCID lcid );
/* Charset to codepage map, sorted by name. */
static const struct charset_entry
{
const char *charset_name;
UINT codepage;
} charset_names[] =
{
{ "CP1250", 1250 },
{ "CP1251", 1251 },
{ "CP1252", 1252 },
{ "CP1253", 1253 },
{ "CP1254", 1254 },
{ "CP1255", 1255 },
{ "CP1256", 1256 },
{ "CP1257", 1257 },
{ "CP1258", 1258 },
{ "IBM037", 37 },
{ "IBM1026", 1026 },
{ "IBM424", 424 },
{ "IBM437", 437 },
{ "IBM500", 500 },
{ "IBM850", 850 },
{ "IBM852", 852 },
{ "IBM855", 855 },
{ "IBM857", 857 },
{ "IBM860", 860 },
{ "IBM861", 861 },
{ "IBM862", 862 },
{ "IBM863", 863 },
{ "IBM864", 864 },
{ "IBM865", 865 },
{ "IBM866", 866 },
{ "IBM869", 869 },
{ "IBM874", 874 },
{ "IBM875", 875 },
{ "ISO88591", 28591 },
{ "ISO885910", 28600 },
{ "ISO885913", 28603 },
{ "ISO885914", 28604 },
{ "ISO885915", 28605 },
{ "ISO88592", 28592 },
{ "ISO88593", 28593 },
{ "ISO88594", 28594 },
{ "ISO88595", 28595 },
{ "ISO88596", 28596 },
{ "ISO88597", 28597 },
{ "ISO88598", 28598 },
{ "ISO88599", 28599 },
{ "KOI8R", 20866 },
{ "KOI8U", 20866 },
{ "UTF8", CP_UTF8 }
};
#define NLS_MAX_LANGUAGES 20
typedef struct {
char lang[128];
char country[128];
LANGID found_lang_id[NLS_MAX_LANGUAGES];
char found_language[NLS_MAX_LANGUAGES][3];
char found_country[NLS_MAX_LANGUAGES][3];
int n_found;
} LANG_FIND_DATA;
/***********************************************************************
* get_lcid_codepage
*
* Retrieve the ANSI codepage for a given locale.
*/
inline static UINT get_lcid_codepage( LCID lcid )
{
UINT ret;
if (!GetLocaleInfoW( lcid, LOCALE_IDEFAULTANSICODEPAGE|LOCALE_RETURN_NUMBER, (WCHAR *)&ret,
sizeof(ret)/sizeof(WCHAR) )) ret = 0;
return ret;
}
/***********************************************************************
* create_registry_key
*
* Create the Control Panel\\International registry key.
*/
inline static HKEY create_registry_key(void)
{
static const WCHAR intlW[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW;
HKEY hkey;
if (RtlOpenCurrentUser( KEY_ALL_ACCESS, &hkey ) != STATUS_SUCCESS) return 0;
attr.Length = sizeof(attr);
attr.RootDirectory = hkey;
attr.ObjectName = &nameW;
attr.Attributes = 0;
attr.SecurityDescriptor = NULL;
attr.SecurityQualityOfService = NULL;
RtlInitUnicodeString( &nameW, intlW );
if (NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) != STATUS_SUCCESS) hkey = 0;
NtClose( attr.RootDirectory );
return hkey;
}
/***********************************************************************
* update_registry
*
* Update registry contents on startup if the user locale has changed.
* This simulates the action of the Windows control panel.
*/
inline static void update_registry( LCID lcid )
{
static const USHORT updateValues[] = {
LOCALE_SLANGUAGE,
LOCALE_SCOUNTRY, LOCALE_ICOUNTRY,
LOCALE_S1159, LOCALE_S2359,
LOCALE_STIME, LOCALE_ITIME,
LOCALE_ITLZERO,
LOCALE_SSHORTDATE,
LOCALE_IDATE,
LOCALE_SLONGDATE,
LOCALE_SDATE,
LOCALE_SCURRENCY, LOCALE_ICURRENCY,
LOCALE_INEGCURR,
LOCALE_ICURRDIGITS,
LOCALE_SDECIMAL,
LOCALE_SLIST,
LOCALE_STHOUSAND,
LOCALE_IDIGITS,
LOCALE_IDIGITSUBSTITUTION,
LOCALE_SNATIVEDIGITS,
LOCALE_ITIMEMARKPOSN,
LOCALE_ICALENDARTYPE,
LOCALE_ILZERO,
LOCALE_IMEASURE
};
static const WCHAR LocaleW[] = {'L','o','c','a','l','e',0};
UNICODE_STRING nameW;
char buffer[20];
WCHAR bufferW[80];
DWORD count, i;
HKEY hkey;
if (!(hkey = create_registry_key()))
return; /* don't do anything if we can't create the registry key */
RtlInitUnicodeString( &nameW, LocaleW );
count = sizeof(bufferW);
if (!NtQueryValueKey(hkey, &nameW, KeyValuePartialInformation, (LPBYTE)bufferW, count, &count))
{
const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)bufferW;
LPCWSTR szValueText = (LPCWSTR)info->Data;
if (strtoulW( szValueText, NULL, 16 ) == lcid) /* already set correctly */
{
NtClose( hkey );
return;
}
TRACE( "updating registry, locale changed %s -> %08lx\n", debugstr_w(szValueText), lcid );
}
else TRACE( "updating registry, locale changed none -> %08lx\n", lcid );
sprintf( buffer, "%08lx", lcid );
/* Note: '9' constant below is strlen(buffer) + 1 */
RtlMultiByteToUnicodeN( bufferW, sizeof(bufferW), NULL, buffer, 9 );
NtSetValueKey( hkey, &nameW, 0, REG_SZ, bufferW, 9 * sizeof(WCHAR) );
NtClose( hkey );
for (i = 0; i < sizeof(updateValues)/sizeof(updateValues[0]); i++)
{
GetLocaleInfoW( lcid, updateValues[i] | LOCALE_NOUSEROVERRIDE, bufferW,
sizeof(bufferW)/sizeof(WCHAR) );
SetLocaleInfoW( lcid, updateValues[i], bufferW );
}
}
/***********************************************************************
* find_language_id_proc
*/
static BOOL CALLBACK find_language_id_proc( HMODULE hModule, LPCSTR type,
LPCSTR name, WORD LangID, LPARAM lParam )
{
LANG_FIND_DATA *l_data = (LANG_FIND_DATA *)lParam;
LCID lcid = MAKELCID(LangID, SORT_DEFAULT);
char buf_language[128];
char buf_country[128];
char buf_en_language[128];
TRACE("%04X\n", (UINT)LangID);
if(PRIMARYLANGID(LangID) == LANG_NEUTRAL)
return TRUE; /* continue search */
buf_language[0] = 0;
buf_country[0] = 0;
GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME|LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP,
buf_language, sizeof(buf_language));
TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language);
GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME|LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP,
buf_country, sizeof(buf_country));
TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country);
if(l_data->lang[0] && !strcasecmp(l_data->lang, buf_language))
{
if(l_data->country[0])
{
if(!strcasecmp(l_data->country, buf_country))
{
l_data->found_lang_id[0] = LangID;
l_data->n_found = 1;
TRACE("Found lang_id %04X for %s_%s\n", LangID, l_data->lang, l_data->country);
return FALSE; /* stop enumeration */
}
}
else /* l_data->country not specified */
{
if(l_data->n_found < NLS_MAX_LANGUAGES)
{
l_data->found_lang_id[l_data->n_found] = LangID;
strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
l_data->n_found++;
TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
return TRUE; /* continue search */
}
}
}
/* Just in case, check LOCALE_SENGLANGUAGE too,
* in hope that possible alias name might have that value.
*/
buf_en_language[0] = 0;
GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE|LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP,
buf_en_language, sizeof(buf_en_language));
TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language);
if(l_data->lang[0] && !strcasecmp(l_data->lang, buf_en_language))
{
l_data->found_lang_id[l_data->n_found] = LangID;
strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
l_data->n_found++;
TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
}
return TRUE; /* continue search */
}
/***********************************************************************
* get_language_id
*
* INPUT:
* Lang: a string whose two first chars are the iso name of a language.
* Country: a string whose two first chars are the iso name of country
* Charset: a string defining the chosen charset encoding
* Dialect: a string defining a variation of the locale
*
* all those values are from the standardized format of locale
* name in unix which is: Lang[_Country][.Charset][@Dialect]
*
* RETURNS:
* the numeric code of the language used by Windows
*
* FIXME: Charset and Dialect are not handled
*/
static LANGID get_language_id(LPCSTR Lang, LPCSTR Country, LPCSTR Charset, LPCSTR Dialect)
{
LANG_FIND_DATA l_data;
char lang_string[256];
HMODULE hKernel32;
if(!Lang)
{
l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
goto END;
}
memset(&l_data, 0, sizeof(LANG_FIND_DATA));
strncpy(l_data.lang, Lang, sizeof(l_data.lang));
if(Country && Country[0])
strncpy(l_data.country, Country, sizeof(l_data.country));
hKernel32 = GetModuleHandleW(kernel32W);
EnumResourceLanguagesA(hKernel32, (LPSTR)RT_STRING,
(LPCSTR)LOCALE_ILANGUAGE, find_language_id_proc, (LPARAM)&l_data);
strcpy(lang_string, l_data.lang);
if(l_data.country[0])
{
strcat(lang_string, "_");
strcat(lang_string, l_data.country);
}
if(!l_data.n_found)
{
if(l_data.country[0])
{
MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string);
l_data.country[0] = 0;
EnumResourceLanguagesA(hKernel32, (LPSTR)RT_STRING,
(LPCSTR)LOCALE_ILANGUAGE, find_language_id_proc, (LONG)&l_data);
}
}
/* Re-evaluate lang_string */
strcpy(lang_string, l_data.lang);
if(l_data.country[0])
{
strcat(lang_string, "_");
strcat(lang_string, l_data.country);
}
if(!l_data.n_found)
{
MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string);
l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
}
else
{
if(l_data.n_found == 1)
TRACE("For language '%s' lang_id %04X was found\n", lang_string, l_data.found_lang_id[0]);
else /* l_data->n_found > 1 */
{
int i;
MESSAGE("For language '%s' several language ids were found:\n", lang_string);
for(i = 0; i < l_data.n_found; i++)
MESSAGE("%s_%s - %04X; ", l_data.found_language[i], l_data.found_country[i], l_data.found_lang_id[i]);
MESSAGE("\nInstead of using first in the list, suggest to define\n"
"your LANG environment variable like this: LANG=%s_%s\n",
l_data.found_language[0], l_data.found_country[0]);
}
}
END:
TRACE("Returning %04X\n", l_data.found_lang_id[0]);
return l_data.found_lang_id[0];
}
/***********************************************************************
* charset_cmp (internal)
*/
static int charset_cmp( const void *name, const void *entry )
{
const struct charset_entry *charset = (struct charset_entry *)entry;
return strcasecmp( (char *)name, charset->charset_name );
}
/***********************************************************************
* init_default_lcid
*/
static LCID init_default_lcid( UINT *unix_cp )
{
char buf[256];
char *lang,*country,*charset,*dialect,*next;
LCID ret = 0;
if (GetEnvironmentVariableA( "LC_ALL", buf, sizeof(buf) ) ||
GetEnvironmentVariableA( "LC_CTYPE", buf, sizeof(buf) ) ||
GetEnvironmentVariableA( "LANGUAGE", buf, sizeof(buf) ) ||
GetEnvironmentVariableA( "LC_MESSAGES", buf, sizeof(buf) ) ||
GetEnvironmentVariableA( "LANG", buf, sizeof(buf) ))
{
if (!strcmp(buf,"POSIX") || !strcmp(buf,"C")) goto done;
lang=buf;
do {
next=strchr(lang,':'); if (next) *next++='\0';
dialect=strchr(lang,'@'); if (dialect) *dialect++='\0';
charset=strchr(lang,'.'); if (charset) *charset++='\0';
country=strchr(lang,'_'); if (country) *country++='\0';
ret = get_language_id(lang, country, charset, dialect);
if (ret && charset)
{
const struct charset_entry *entry;
char charset_name[16];
size_t i, j;
/* remove punctuation characters from charset name */
for (i = j = 0; charset[i] && j < sizeof(charset_name)-1; i++)
if (isalnum(charset[i])) charset_name[j++] = charset[i];
charset_name[j] = 0;
entry = bsearch( charset_name, charset_names,
sizeof(charset_names)/sizeof(charset_names[0]),
sizeof(charset_names[0]), charset_cmp );
if (entry)
{
*unix_cp = entry->codepage;
TRACE("charset %s was mapped to cp %u\n", charset, *unix_cp);
}
else
FIXME("charset %s was not recognized\n", charset);
}
lang=next;
} while (lang && !ret);
if (!ret) MESSAGE("Warning: language '%s' not recognized, defaulting to English\n", buf);
}
done:
if (!ret) ret = MAKELCID( MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), SORT_DEFAULT) ;
return ret;
}
/******************************************************************************
* get_locale_value_name
*
* Gets the registry value name for a given lctype.
*/
static const WCHAR *get_locale_value_name( DWORD lctype )
{
static const WCHAR iCalendarTypeW[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
static const WCHAR iCountryW[] = {'i','C','o','u','n','t','r','y',0};
static const WCHAR iCurrDigitsW[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
static const WCHAR iCurrencyW[] = {'i','C','u','r','r','e','n','c','y',0};
static const WCHAR iDateW[] = {'i','D','a','t','e',0};
static const WCHAR iDigitsW[] = {'i','D','i','g','i','t','s',0};
static const WCHAR iFirstDayOfWeekW[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
static const WCHAR iFirstWeekOfYearW[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
static const WCHAR iLDateW[] = {'i','L','D','a','t','e',0};
static const WCHAR iLZeroW[] = {'i','L','Z','e','r','o',0};
static const WCHAR iMeasureW[] = {'i','M','e','a','s','u','r','e',0};
static const WCHAR iNegCurrW[] = {'i','N','e','g','C','u','r','r',0};
static const WCHAR iNegNumberW[] = {'i','N','e','g','N','u','m','b','e','r',0};
static const WCHAR iPaperSizeW[] = {'i','P','a','p','e','r','S','i','z','e',0};
static const WCHAR iTLZeroW[] = {'i','T','L','Z','e','r','o',0};
static const WCHAR iTimePrefixW[] = {'i','T','i','m','e','P','r','e','f','i','x',0};
static const WCHAR iTimeW[] = {'i','T','i','m','e',0};
static const WCHAR s1159W[] = {'s','1','1','5','9',0};
static const WCHAR s2359W[] = {'s','2','3','5','9',0};
static const WCHAR sCountryW[] = {'s','C','o','u','n','t','r','y',0};
static const WCHAR sCurrencyW[] = {'s','C','u','r','r','e','n','c','y',0};
static const WCHAR sDateW[] = {'s','D','a','t','e',0};
static const WCHAR sDecimalW[] = {'s','D','e','c','i','m','a','l',0};
static const WCHAR sGroupingW[] = {'s','G','r','o','u','p','i','n','g',0};
static const WCHAR sLanguageW[] = {'s','L','a','n','g','u','a','g','e',0};
static const WCHAR sListW[] = {'s','L','i','s','t',0};
static const WCHAR sLongDateW[] = {'s','L','o','n','g','D','a','t','e',0};
static const WCHAR sMonDecimalSepW[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
static const WCHAR sMonGroupingW[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
static const WCHAR sMonThousandSepW[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
static const WCHAR sNativeDigitsW[] = {'s','N','a','t','i','v','e','D','i','g','i','t','s',0};
static const WCHAR sNegativeSignW[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
static const WCHAR sPositiveSignW[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
static const WCHAR sShortDateW[] = {'s','S','h','o','r','t','D','a','t','e',0};
static const WCHAR sThousandW[] = {'s','T','h','o','u','s','a','n','d',0};
static const WCHAR sTimeFormatW[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
static const WCHAR sTimeW[] = {'s','T','i','m','e',0};
static const WCHAR sYearMonthW[] = {'s','Y','e','a','r','M','o','n','t','h',0};
static const WCHAR NumShapeW[] = {'N','u','m','s','h','a','p','e',0};
switch (lctype & ~LOCALE_LOCALEINFOFLAGSMASK)
{
/* These values are used by SetLocaleInfo and GetLocaleInfo, and
* the values are stored in the registry, confirmed under Windows.
*/
case LOCALE_ICALENDARTYPE: return iCalendarTypeW;
case LOCALE_ICURRDIGITS: return iCurrDigitsW;
case LOCALE_ICURRENCY: return iCurrencyW;
case LOCALE_IDIGITS: return iDigitsW;
case LOCALE_IFIRSTDAYOFWEEK: return iFirstDayOfWeekW;
case LOCALE_IFIRSTWEEKOFYEAR: return iFirstWeekOfYearW;
case LOCALE_ILZERO: return iLZeroW;
case LOCALE_IMEASURE: return iMeasureW;
case LOCALE_INEGCURR: return iNegCurrW;
case LOCALE_INEGNUMBER: return iNegNumberW;
case LOCALE_IPAPERSIZE: return iPaperSizeW;
case LOCALE_ITIME: return iTimeW;
case LOCALE_S1159: return s1159W;
case LOCALE_S2359: return s2359W;
case LOCALE_SCURRENCY: return sCurrencyW;
case LOCALE_SDATE: return sDateW;
case LOCALE_SDECIMAL: return sDecimalW;
case LOCALE_SGROUPING: return sGroupingW;
case LOCALE_SLIST: return sListW;
case LOCALE_SLONGDATE: return sLongDateW;
case LOCALE_SMONDECIMALSEP: return sMonDecimalSepW;
case LOCALE_SMONGROUPING: return sMonGroupingW;
case LOCALE_SMONTHOUSANDSEP: return sMonThousandSepW;
case LOCALE_SNEGATIVESIGN: return sNegativeSignW;
case LOCALE_SPOSITIVESIGN: return sPositiveSignW;
case LOCALE_SSHORTDATE: return sShortDateW;
case LOCALE_STHOUSAND: return sThousandW;
case LOCALE_STIME: return sTimeW;
case LOCALE_STIMEFORMAT: return sTimeFormatW;
case LOCALE_SYEARMONTH: return sYearMonthW;
/* The following are not listed under MSDN as supported,
* but seem to be used and also stored in the registry.
*/
case LOCALE_ICOUNTRY: return iCountryW;
case LOCALE_IDATE: return iDateW;
case LOCALE_ILDATE: return iLDateW;
case LOCALE_ITLZERO: return iTLZeroW;
case LOCALE_SCOUNTRY: return sCountryW;
case LOCALE_SLANGUAGE: return sLanguageW;
/* The following are used in XP and later */
case LOCALE_IDIGITSUBSTITUTION: return NumShapeW;
case LOCALE_SNATIVEDIGITS: return sNativeDigitsW;
case LOCALE_ITIMEMARKPOSN: return iTimePrefixW;
}
return NULL;
}
/******************************************************************************
* get_registry_locale_info
*
* Retrieve user-modified locale info from the registry.
* Return length, 0 on error, -1 if not found.
*/
static INT get_registry_locale_info( LPCWSTR value, LPWSTR buffer, INT len )
{
DWORD size;
INT ret;
HKEY hkey;
NTSTATUS status;
UNICODE_STRING nameW;
KEY_VALUE_PARTIAL_INFORMATION *info;
static const int info_size = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
if (!(hkey = create_registry_key())) return -1;
RtlInitUnicodeString( &nameW, value );
size = info_size + len * sizeof(WCHAR);
if (!(info = HeapAlloc( GetProcessHeap(), 0, size )))
{
NtClose( hkey );
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return 0;
}
status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, info, size, &size );
if (status == STATUS_BUFFER_OVERFLOW && !buffer) status = 0;
if (!status)
{
ret = (size - info_size) / sizeof(WCHAR);
/* append terminating null if needed */
if (!ret || ((WCHAR *)info->Data)[ret-1])
{
if (ret < len || !buffer) ret++;
else
{
SetLastError( ERROR_INSUFFICIENT_BUFFER );
ret = 0;
}
}
if (ret && buffer)
{
memcpy( buffer, info->Data, (ret-1) * sizeof(WCHAR) );
buffer[ret-1] = 0;
}
}
else
{
if (status == STATUS_OBJECT_NAME_NOT_FOUND) ret = -1;
else
{
SetLastError( RtlNtStatusToDosError(status) );
ret = 0;
}
}
NtClose( hkey );
HeapFree( GetProcessHeap(), 0, info );
return ret;
}
/******************************************************************************
* GetLocaleInfoA (KERNEL32.@)
*
* Get information about an aspect of a locale.
*
* PARAMS
* lcid [I] LCID of the locale
* lctype [I] LCTYPE_ flags from "winnls.h"
* buffer [O] Destination for the information
* len [I] Length of buffer in characters
*
* RETURNS
* Success: The size of the data requested. If buffer is non-NULL, it is filled
* with the information.
* Failure: 0. Use GetLastError() to determine the cause.
*
* NOTES
* - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
* - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
* which is a bit string.
*/
INT WINAPI GetLocaleInfoA( LCID lcid, LCTYPE lctype, LPSTR buffer, INT len )
{
WCHAR *bufferW;
INT lenW, ret;
if (len < 0 || (len && !buffer))
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
if (!len) buffer = NULL;
if (!(lenW = GetLocaleInfoW( lcid, lctype, NULL, 0 ))) return 0;
if (!(bufferW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
{
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return 0;
}
if ((ret = GetLocaleInfoW( lcid, lctype, bufferW, lenW )))
{
if ((lctype & LOCALE_RETURN_NUMBER) ||
((lctype & ~LOCALE_LOCALEINFOFLAGSMASK) == LOCALE_FONTSIGNATURE))
{
/* it's not an ASCII string, just bytes */
ret *= sizeof(WCHAR);
if (buffer)
{
if (ret <= len) memcpy( buffer, bufferW, ret );
else
{
SetLastError( ERROR_INSUFFICIENT_BUFFER );
ret = 0;
}
}
}
else
{
UINT codepage = CP_ACP;
if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
ret = WideCharToMultiByte( codepage, 0, bufferW, ret, buffer, len, NULL, NULL );
}
}
HeapFree( GetProcessHeap(), 0, bufferW );
return ret;
}
/******************************************************************************
* GetLocaleInfoW (KERNEL32.@)
*
* See GetLocaleInfoA.
*/
INT WINAPI GetLocaleInfoW( LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len )
{
LANGID lang_id;
HRSRC hrsrc;
HGLOBAL hmem;
HMODULE hModule;
INT ret;
UINT lcflags;
const WCHAR *p;
unsigned int i;
if (len < 0 || (len && !buffer))
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
if (!len) buffer = NULL;
lcid = ConvertDefaultLocale(lcid);
lcflags = lctype & LOCALE_LOCALEINFOFLAGSMASK;
lctype &= ~LOCALE_LOCALEINFOFLAGSMASK;
/* first check for overrides in the registry */
if (!(lcflags & LOCALE_NOUSEROVERRIDE) && lcid == GetUserDefaultLCID())
{
const WCHAR *value = get_locale_value_name(lctype);
if (value && ((ret = get_registry_locale_info( value, buffer, len )) != -1)) return ret;
}
/* now load it from kernel resources */
lang_id = LANGIDFROMLCID( lcid );
/* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
if (SUBLANGID(lang_id) == SUBLANG_NEUTRAL)
lang_id = MAKELANGID(PRIMARYLANGID(lang_id), SUBLANG_DEFAULT);
hModule = GetModuleHandleW( kernel32W );
if (!(hrsrc = FindResourceExW( hModule, (LPWSTR)RT_STRING, (LPCWSTR)((lctype >> 4) + 1), lang_id )))
{
SetLastError( ERROR_INVALID_FLAGS ); /* no such lctype */
return 0;
}
if (!(hmem = LoadResource( hModule, hrsrc )))
return 0;
p = LockResource( hmem );
for (i = 0; i < (lctype & 0x0f); i++) p += *p + 1;
if (lcflags & LOCALE_RETURN_NUMBER) ret = sizeof(UINT)/sizeof(WCHAR);
else ret = (lctype == LOCALE_FONTSIGNATURE) ? *p : *p + 1;
if (!buffer) return ret;
if (ret > len)
{
SetLastError( ERROR_INSUFFICIENT_BUFFER );
return 0;
}
if (lcflags & LOCALE_RETURN_NUMBER)
{
UINT number;
WCHAR *end, *tmp = HeapAlloc( GetProcessHeap(), 0, (*p + 1) * sizeof(WCHAR) );
if (!tmp) return 0;
memcpy( tmp, p + 1, *p * sizeof(WCHAR) );
tmp[*p] = 0;
number = strtolW( tmp, &end, 10 );
if (!*end)
memcpy( buffer, &number, sizeof(number) );
else /* invalid number */
{
SetLastError( ERROR_INVALID_FLAGS );
ret = 0;
}
HeapFree( GetProcessHeap(), 0, tmp );
TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d) returning number %d\n",
lcid, lctype, buffer, len, number );
}
else
{
memcpy( buffer, p + 1, *p * sizeof(WCHAR) );
if (lctype != LOCALE_FONTSIGNATURE) buffer[ret-1] = 0;
TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d) returning %d %s\n",
lcid, lctype, buffer, len, ret, debugstr_w(buffer) );
}
return ret;
}
/******************************************************************************
* SetLocaleInfoA [KERNEL32.@]
*
* Set information about an aspect of a locale.
*
* PARAMS
* lcid [I] LCID of the locale
* lctype [I] LCTYPE_ flags from "winnls.h"
* data [I] Information to set
*
* RETURNS
* Success: TRUE. The information given will be returned by GetLocaleInfoA()
* whenever it is called without LOCALE_NOUSEROVERRIDE.
* Failure: FALSE. Use GetLastError() to determine the cause.
*
* NOTES
* - Values are only be set for the current user locale; the system locale
* settings cannot be changed.
* - Any settings changed by this call are lost when the locale is changed by
* the control panel (in Wine, this happens every time you change LANG).
* - The native implementation of this function does not check that lcid matches
* the current user locale, and simply sets the new values. Wine warns you in
* this case, but behaves the same.
*/
BOOL WINAPI SetLocaleInfoA(LCID lcid, LCTYPE lctype, LPCSTR data)
{
UINT codepage = CP_ACP;
WCHAR *strW;
DWORD len;
BOOL ret;
lcid = ConvertDefaultLocale(lcid);
if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
len = MultiByteToWideChar( codepage, 0, data, -1, NULL, 0 );
if (!(strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
{
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return FALSE;
}
MultiByteToWideChar( codepage, 0, data, -1, strW, len );
ret = SetLocaleInfoW( lcid, lctype, strW );
HeapFree( GetProcessHeap(), 0, strW );
return ret;
}
/******************************************************************************
* SetLocaleInfoW (KERNEL32.@)
*
* See SetLocaleInfoA.
*/
BOOL WINAPI SetLocaleInfoW( LCID lcid, LCTYPE lctype, LPCWSTR data )
{
const WCHAR *value;
const WCHAR intlW[] = {'i','n','t','l',0 };
UNICODE_STRING valueW;
NTSTATUS status;
HKEY hkey;
lcid = ConvertDefaultLocale(lcid);
lctype &= ~LOCALE_LOCALEINFOFLAGSMASK;
value = get_locale_value_name( lctype );
if (!data || !value)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
if (lctype == LOCALE_IDATE || lctype == LOCALE_ILDATE)
{
SetLastError( ERROR_INVALID_FLAGS );
return FALSE;
}
if (lcid != GetUserDefaultLCID())
{
/* Windows does not check that the lcid matches the current lcid */
WARN("locale 0x%08lx isn't the current locale (0x%08lx), setting anyway!\n",
lcid, GetUserDefaultLCID());
}
TRACE("setting %lx to %s\n", lctype, debugstr_w(data) );
/* FIXME: should check that data to set is sane */
/* FIXME: profile functions should map to registry */
WriteProfileStringW( intlW, value, data );
if (!(hkey = create_registry_key())) return FALSE;
RtlInitUnicodeString( &valueW, value );
status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, data, (strlenW(data)+1)*sizeof(WCHAR) );
if (lctype == LOCALE_SDATE || lctype == LOCALE_SLONGDATE)
{
/* Set I-value from S value */
WCHAR *lpD, *lpM, *lpY;
WCHAR szBuff[2];
lpD = strchrW(data, 'd');
lpM = strchrW(data, 'M');
lpY = strchrW(data, 'y');
if (lpD <= lpM)
{
szBuff[0] = '1'; /* D-M-Y */
}
else
{
if (lpY <= lpM)
szBuff[0] = '2'; /* Y-M-D */
else
szBuff[0] = '0'; /* M-D-Y */
}
szBuff[1] = '\0';
if (lctype == LOCALE_SDATE)
lctype = LOCALE_IDATE;
else
lctype = LOCALE_ILDATE;
value = get_locale_value_name( lctype );
WriteProfileStringW( intlW, value, szBuff );
RtlInitUnicodeString( &valueW, value );
status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, szBuff, sizeof(szBuff) );
}
NtClose( hkey );
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* GetThreadLocale (KERNEL32.@)
*
* Get the current threads locale.
*
* PARAMS
* None.
*
* RETURNS
* The LCID currently assocated with the calling thread.
*/
LCID WINAPI GetThreadLocale(void)
{
LCID ret = NtCurrentTeb()->CurrentLocale;
if (!ret) NtCurrentTeb()->CurrentLocale = ret = GetUserDefaultLCID();
return ret;
}
/**********************************************************************
* SetThreadLocale (KERNEL32.@)
*
* Set the current threads locale.
*
* PARAMS
* lcid [I] LCID of the locale to set
*
* RETURNS
* Success: TRUE. The threads locale is set to lcid.
* Failure: FALSE. Use GetLastError() to determine the cause.
*/
BOOL WINAPI SetThreadLocale( LCID lcid )
{
TRACE("(0x%04lX)\n", lcid);
lcid = ConvertDefaultLocale(lcid);
if (lcid != GetThreadLocale())
{
if (!IsValidLocale(lcid, LCID_SUPPORTED))
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
NtCurrentTeb()->CurrentLocale = lcid;
NtCurrentTeb()->code_page = get_lcid_codepage( lcid );
}
return TRUE;
}
/******************************************************************************
* ConvertDefaultLocale (KERNEL32.@)
*
* Convert a default locale identifier into a real identifier.
*
* PARAMS
* lcid [I] LCID identifier of the locale to convert
*
* RETURNS
* lcid unchanged, if not a default locale or is its sublanguage is
* not SUBLANG_NEUTRAL.
* GetSystemDefaultLCID(), if lcid == LOCALE_SYSTEM_DEFAULT.
* GetUserDefaultLCID(), if lcid == LOCALE_USER_DEFAULT or LOCALE_NEUTRAL.
* Otherwise, lcid with sublanguage cheanged to SUBLANG_DEFAULT.
*/
LCID WINAPI ConvertDefaultLocale( LCID lcid )
{
LANGID langid;
switch (lcid)
{
case LOCALE_SYSTEM_DEFAULT:
lcid = GetSystemDefaultLCID();
break;
case LOCALE_USER_DEFAULT:
case LOCALE_NEUTRAL:
lcid = GetUserDefaultLCID();
break;
default:
/* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
langid = LANGIDFROMLCID(lcid);
if (SUBLANGID(langid) == SUBLANG_NEUTRAL)
{
langid = MAKELANGID(PRIMARYLANGID(langid), SUBLANG_DEFAULT);
lcid = MAKELCID(langid, SORTIDFROMLCID(lcid));
}
}
return lcid;
}
/******************************************************************************
* IsValidLocale (KERNEL32.@)
*
* Determine if a locale is valid.
*
* PARAMS
* lcid [I] LCID of the locale to check
* flags [I] LCID_SUPPORTED = Valid, LCID_INSTALLED = Valid and installed on the system
*
* RETURN
* TRUE, if lcid is valid,
* FALSE, otherwise.
*
* NOTES
* Wine does not currently make the distinction between supported and installed. All
* languages supported are installed by default.
*/
BOOL WINAPI IsValidLocale( LCID lcid, DWORD flags )
{
/* check if language is registered in the kernel32 resources */
return FindResourceExW( GetModuleHandleW(kernel32W), (LPWSTR)RT_STRING,
(LPCWSTR)LOCALE_ILANGUAGE, LANGIDFROMLCID(lcid)) != 0;
}
static BOOL CALLBACK enum_lang_proc_a( HMODULE hModule, LPCSTR type,
LPCSTR name, WORD LangID, LONG lParam )
{
LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
char buf[20];
sprintf(buf, "%08x", (UINT)LangID);
return lpfnLocaleEnum( buf );
}
static BOOL CALLBACK enum_lang_proc_w( HMODULE hModule, LPCWSTR type,
LPCWSTR name, WORD LangID, LONG lParam )
{
static const WCHAR formatW[] = {'%','0','8','x',0};
LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
WCHAR buf[20];
sprintfW( buf, formatW, (UINT)LangID );
return lpfnLocaleEnum( buf );
}
/******************************************************************************
* EnumSystemLocalesA (KERNEL32.@)
*
* Call a users function for each locale available on the system.
*
* PARAMS
* lpfnLocaleEnum [I] Callback function to call for each locale
* dwFlags [I] LOCALE_SUPPORTED=All supported, LOCALE_INSTALLED=Installed only
*
* RETURNS
* Success: TRUE.
* Failure: FALSE. Use GetLastError() to determine the cause.
*/
BOOL WINAPI EnumSystemLocalesA( LOCALE_ENUMPROCA lpfnLocaleEnum, DWORD dwFlags )
{
TRACE("(%p,%08lx)\n", lpfnLocaleEnum, dwFlags);
EnumResourceLanguagesA( GetModuleHandleW(kernel32W), (LPSTR)RT_STRING,
(LPCSTR)LOCALE_ILANGUAGE, enum_lang_proc_a,
(LONG)lpfnLocaleEnum);
return TRUE;
}
/******************************************************************************
* EnumSystemLocalesW (KERNEL32.@)
*
* See EnumSystemLocalesA.
*/
BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum, DWORD dwFlags )
{
TRACE("(%p,%08lx)\n", lpfnLocaleEnum, dwFlags);
EnumResourceLanguagesW( GetModuleHandleW(kernel32W), (LPWSTR)RT_STRING,
(LPCWSTR)LOCALE_ILANGUAGE, enum_lang_proc_w,
(LONG)lpfnLocaleEnum);
return TRUE;
}
/***********************************************************************
* VerLanguageNameA (KERNEL32.@)
*
* Get the name of a language.
*
* PARAMS
* wLang [I] LANGID of the language
* szLang [O] Destination for the language name
*
* RETURNS
* Success: The size of the language name. If szLang is non-NULL, it is filled
* with the name.
* Failure: 0. Use GetLastError() to determine the cause.
*
*/
DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
{
return GetLocaleInfoA( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
}
/***********************************************************************
* VerLanguageNameW (KERNEL32.@)
*
* See VerLanguageNameA.
*/
DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
{
return GetLocaleInfoW( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
}
/******************************************************************************
* GetStringTypeW (KERNEL32.@)
*/
BOOL WINAPI GetStringTypeW( DWORD type, LPCWSTR src, INT count, LPWORD chartype )
{
if (count == -1) count = strlenW(src) + 1;
switch(type)
{
case CT_CTYPE1:
while (count--) *chartype++ = get_char_typeW( *src++ ) & 0xfff;
break;
case CT_CTYPE2:
while (count--) *chartype++ = get_char_typeW( *src++ ) >> 12;
break;
case CT_CTYPE3:
{
WARN("CT_CTYPE3: semi-stub.\n");
while (count--)
{
int c = *src;
WORD type1, type3 = 0; /* C3_NOTAPPLICABLE */
type1 = get_char_typeW( *src++ ) & 0xfff;
/* try to construct type3 from type1 */
if(type1 & C1_SPACE) type3 |= C3_SYMBOL;
if(type1 & C1_ALPHA) type3 |= C3_ALPHA;
if ((c>=0x30A0)&&(c<=0x30FF)) type3 |= C3_KATAKANA;
if ((c>=0x3040)&&(c<=0x309F)) type3 |= C3_HIRAGANA;
if ((c>=0x4E00)&&(c<=0x9FAF)) type3 |= C3_IDEOGRAPH;
if ((c>=0x0600)&&(c<=0x06FF)) type3 |= C3_KASHIDA;
if ((c>=0x3000)&&(c<=0x303F)) type3 |= C3_SYMBOL;
if ((c>=0xFF00)&&(c<=0xFF60)) type3 |= C3_FULLWIDTH;
if ((c>=0xFF00)&&(c<=0xFF20)) type3 |= C3_SYMBOL;
if ((c>=0xFF3B)&&(c<=0xFF40)) type3 |= C3_SYMBOL;
if ((c>=0xFF5B)&&(c<=0xFF60)) type3 |= C3_SYMBOL;
if ((c>=0xFF21)&&(c<=0xFF3A)) type3 |= C3_ALPHA;
if ((c>=0xFF41)&&(c<=0xFF5A)) type3 |= C3_ALPHA;
if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_FULLWIDTH;
if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_SYMBOL;
if ((c>=0xFF61)&&(c<=0xFFDC)) type3 |= C3_HALFWIDTH;
if ((c>=0xFF61)&&(c<=0xFF64)) type3 |= C3_SYMBOL;
if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_KATAKANA;
if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_ALPHA;
if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_HALFWIDTH;
if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_SYMBOL;
*chartype++ = type3;
}
break;
}
default:
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
return TRUE;
}
/******************************************************************************
* GetStringTypeExW (KERNEL32.@)
*/
BOOL WINAPI GetStringTypeExW( LCID locale, DWORD type, LPCWSTR src, INT count, LPWORD chartype )
{
/* locale is ignored for Unicode */
return GetStringTypeW( type, src, count, chartype );
}
/******************************************************************************
* GetStringTypeA (KERNEL32.@)
*/
BOOL WINAPI GetStringTypeA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
{
UINT cp;
INT countW;
LPWSTR srcW;
BOOL ret = FALSE;
if(count == -1) count = strlen(src) + 1;
if (!(cp = get_lcid_codepage( locale )))
{
FIXME("For locale %04lx using current ANSI code page\n", locale);
cp = GetACP();
}
countW = MultiByteToWideChar(cp, 0, src, count, NULL, 0);
if((srcW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
{
MultiByteToWideChar(cp, 0, src, count, srcW, countW);
/*
* NOTE: the target buffer has 1 word for each CHARACTER in the source
* string, with multibyte characters there maybe be more bytes in count
* than character space in the buffer!
*/
ret = GetStringTypeW(type, srcW, countW, chartype);
HeapFree(GetProcessHeap(), 0, srcW);
}
return ret;
}
/******************************************************************************
* GetStringTypeExA (KERNEL32.@)
*/
BOOL WINAPI GetStringTypeExA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
{
return GetStringTypeA(locale, type, src, count, chartype);
}
/*************************************************************************
* LCMapStringW (KERNEL32.@)
*/
INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen,
LPWSTR dst, INT dstlen)
{
LPWSTR dst_ptr;
if (!src || !srclen || dstlen < 0)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
/* mutually exclusive flags */
if ((flags & (LCMAP_LOWERCASE | LCMAP_UPPERCASE)) == (LCMAP_LOWERCASE | LCMAP_UPPERCASE) ||
(flags & (LCMAP_HIRAGANA | LCMAP_KATAKANA)) == (LCMAP_HIRAGANA | LCMAP_KATAKANA) ||
(flags & (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH)) == (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH) ||
(flags & (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE)) == (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE))
{
SetLastError(ERROR_INVALID_FLAGS);
return 0;
}
if (!dstlen) dst = NULL;
lcid = ConvertDefaultLocale(lcid);
if (flags & LCMAP_SORTKEY)
{
if (src == dst)
{
SetLastError(ERROR_INVALID_FLAGS);
return 0;
}
if (srclen < 0) srclen = strlenW(src);
TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
lcid, flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
return wine_get_sortkey(flags, src, srclen, (char *)dst, dstlen);
}
/* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
if (flags & SORT_STRINGSORT)
{
SetLastError(ERROR_INVALID_FLAGS);
return 0;
}
if (srclen < 0) srclen = strlenW(src) + 1;
TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
lcid, flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
if (!dst) /* return required string length */
{
INT len;
for (len = 0; srclen; src++, srclen--)
{
WCHAR wch = *src;
/* tests show that win2k just ignores NORM_IGNORENONSPACE,
* and skips white space and punctuation characters for
* NORM_IGNORESYMBOLS.
*/
if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
continue;
len++;
}
return len;
}
if (flags & LCMAP_UPPERCASE)
{
for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
{
WCHAR wch = *src;
if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
continue;
*dst_ptr++ = toupperW(wch);
dstlen--;
}
}
else if (flags & LCMAP_LOWERCASE)
{
for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
{
WCHAR wch = *src;
if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
continue;
*dst_ptr++ = tolowerW(wch);
dstlen--;
}
}
else
{
if (src == dst)
{
SetLastError(ERROR_INVALID_FLAGS);
return 0;
}
for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
{
WCHAR wch = *src;
if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
continue;
*dst_ptr++ = wch;
dstlen--;
}
}
return dst_ptr - dst;
}
/*************************************************************************
* LCMapStringA (KERNEL32.@)
*/
INT WINAPI LCMapStringA(LCID lcid, DWORD flags, LPCSTR src, INT srclen,
LPSTR dst, INT dstlen)
{
WCHAR bufW[128];
LPWSTR srcW, dstW;
INT ret = 0, srclenW, dstlenW;
UINT locale_cp;
if (!src || !srclen || dstlen < 0)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
locale_cp = get_lcid_codepage(lcid);
srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, bufW, 128);
if (srclenW)
srcW = bufW;
else
{
srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, NULL, 0);
srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
if (!srcW)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return 0;
}
MultiByteToWideChar(locale_cp, 0, src, srclen, srcW, srclenW);
}
if (flags & LCMAP_SORTKEY)
{
if (src == dst)
{
SetLastError(ERROR_INVALID_FLAGS);
goto map_string_exit;
}
ret = wine_get_sortkey(flags, srcW, srclenW, dst, dstlen);
goto map_string_exit;
}
if (flags & SORT_STRINGSORT)
{
SetLastError(ERROR_INVALID_FLAGS);
goto map_string_exit;
}
dstlenW = LCMapStringW(lcid, flags, srcW, srclenW, NULL, 0);
dstW = HeapAlloc(GetProcessHeap(), 0, dstlenW * sizeof(WCHAR));
if (!dstW)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
goto map_string_exit;
}
LCMapStringW(lcid, flags, srcW, srclenW, dstW, dstlenW);
ret = WideCharToMultiByte(locale_cp, 0, dstW, dstlenW, dst, dstlen, NULL, NULL);
HeapFree(GetProcessHeap(), 0, dstW);
map_string_exit:
if (srcW != bufW) HeapFree(GetProcessHeap(), 0, srcW);
return ret;
}
/******************************************************************************
* CompareStringW (KERNEL32.@)
*/
INT WINAPI CompareStringW(LCID lcid, DWORD style,
LPCWSTR str1, INT len1, LPCWSTR str2, INT len2)
{
INT ret, len;
if (!str1 || !str2)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
if (len1 < 0) len1 = lstrlenW(str1);
if (len2 < 0) len2 = lstrlenW(str2);
len = (len1 < len2) ? len1 : len2;
ret = (style & NORM_IGNORECASE) ? strncmpiW(str1, str2, len) :
strncmpW(str1, str2, len);
if (ret) /* need to translate result */
return (ret < 0) ? CSTR_LESS_THAN : CSTR_GREATER_THAN;
if (len1 == len2) return CSTR_EQUAL;
/* the longer one is lexically greater */
return (len1 < len2) ? CSTR_LESS_THAN : CSTR_GREATER_THAN;
}
/******************************************************************************
* CompareStringA (KERNEL32.@)
*/
INT WINAPI CompareStringA(LCID lcid, DWORD style,
LPCSTR str1, INT len1, LPCSTR str2, INT len2)
{
WCHAR buf1W[128], buf2W[128];
LPWSTR str1W, str2W;
INT len1W, len2W, ret;
UINT locale_cp;
if (!str1 || !str2)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
if (len1 < 0) len1 = strlen(str1);
if (len2 < 0) len2 = strlen(str2);
locale_cp = get_lcid_codepage(lcid);
len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 128);
if (len1W)
str1W = buf1W;
else
{
len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, NULL, 0);
str1W = HeapAlloc(GetProcessHeap(), 0, len1W * sizeof(WCHAR));
if (!str1W)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return 0;
}
MultiByteToWideChar(locale_cp, 0, str1, len1, str1W, len1W);
}
len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 128);
if (len2W)
str2W = buf2W;
else
{
len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, NULL, 0);
str2W = HeapAlloc(GetProcessHeap(), 0, len2W * sizeof(WCHAR));
if (!str2W)
{
if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return 0;
}
MultiByteToWideChar(locale_cp, 0, str2, len2, str2W, len2W);
}
ret = CompareStringW(lcid, style, str1W, len1W, str2W, len2W);
if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
if (str2W != buf2W) HeapFree(GetProcessHeap(), 0, str2W);
return ret;
}
/*************************************************************************
* lstrcmp (KERNEL32.@)
* lstrcmpA (KERNEL32.@)
*/
int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2)
{
int ret = CompareStringA(GetThreadLocale(), 0, str1, -1, str2, -1);
if (ret) ret -= 2;
return ret;
}
/*************************************************************************
* lstrcmpi (KERNEL32.@)
* lstrcmpiA (KERNEL32.@)
*/
int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
{
int ret = CompareStringA(GetThreadLocale(), NORM_IGNORECASE, str1, -1, str2, -1);
if (ret) ret -= 2;
return ret;
}
/*************************************************************************
* lstrcmpW (KERNEL32.@)
*/
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
{
int ret = CompareStringW(GetThreadLocale(), 0, str1, -1, str2, -1);
if (ret) ret -= 2;
return ret;
}
/*************************************************************************
* lstrcmpiW (KERNEL32.@)
*/
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
{
int ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, -1, str2, -1);
if (ret) ret -= 2;
return ret;
}
/******************************************************************************
* LOCALE_Init
*/
void LOCALE_Init(void)
{
UINT ansi_cp = 1252, oem_cp = 437, mac_cp = 10000, unix_cp = ~0U;
LCID lcid = init_default_lcid( &unix_cp );
NtSetDefaultLocale( FALSE, lcid );
NtSetDefaultLocale( TRUE, lcid );
ansi_cp = get_lcid_codepage(lcid);
GetLocaleInfoW( lcid, LOCALE_IDEFAULTMACCODEPAGE | LOCALE_RETURN_NUMBER,
(LPWSTR)&mac_cp, sizeof(mac_cp)/sizeof(WCHAR) );
GetLocaleInfoW( lcid, LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
(LPWSTR)&oem_cp, sizeof(oem_cp)/sizeof(WCHAR) );
if (unix_cp == ~0U)
GetLocaleInfoW( lcid, LOCALE_IDEFAULTUNIXCODEPAGE | LOCALE_RETURN_NUMBER,
(LPWSTR)&unix_cp, sizeof(unix_cp)/sizeof(WCHAR) );
CODEPAGE_Init( ansi_cp, oem_cp, mac_cp, unix_cp, lcid );
update_registry( lcid );
}
static HKEY NLS_RegOpenKey(HKEY hRootKey, LPCWSTR szKeyName)
{
UNICODE_STRING keyName;
OBJECT_ATTRIBUTES attr;
HKEY hkey;
RtlInitUnicodeString( &keyName, szKeyName );
InitializeObjectAttributes(&attr, &keyName, 0, hRootKey, NULL);
if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) != STATUS_SUCCESS)
hkey = 0;
return hkey;
}
static HKEY NLS_RegOpenSubKey(HKEY hRootKey, LPCWSTR szKeyName)
{
HKEY hKey = NLS_RegOpenKey(hRootKey, szKeyName);
if (hRootKey)
NtClose( hRootKey );
return hKey;
}
static BOOL NLS_RegEnumSubKey(HKEY hKey, UINT ulIndex, LPWSTR szKeyName,
ULONG keyNameSize)
{
BYTE buffer[80];
KEY_BASIC_INFORMATION *info = (KEY_BASIC_INFORMATION *)buffer;
DWORD dwLen;
if (NtEnumerateKey( hKey, ulIndex, KeyBasicInformation, buffer,
sizeof(buffer), &dwLen) != STATUS_SUCCESS ||
info->NameLength > keyNameSize)
{
return FALSE;
}
TRACE("info->Name %s info->NameLength %ld\n", debugstr_w(info->Name), info->NameLength);
memcpy( szKeyName, info->Name, info->NameLength);
szKeyName[info->NameLength / sizeof(WCHAR)] = '\0';
TRACE("returning %s\n", debugstr_w(szKeyName));
return TRUE;
}
static BOOL NLS_RegEnumValue(HKEY hKey, UINT ulIndex,
LPWSTR szValueName, ULONG valueNameSize,
LPWSTR szValueData, ULONG valueDataSize)
{
BYTE buffer[80];
KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
DWORD dwLen;
if (NtEnumerateValueKey( hKey, ulIndex, KeyValueFullInformation,
buffer, sizeof(buffer), &dwLen ) != STATUS_SUCCESS ||
info->NameLength > valueNameSize ||
info->DataLength > valueDataSize)
{
return FALSE;
}
TRACE("info->Name %s info->DataLength %ld\n", debugstr_w(info->Name), info->DataLength);
memcpy( szValueName, info->Name, info->NameLength);
szValueName[info->NameLength / sizeof(WCHAR)] = '\0';
memcpy( szValueData, buffer + info->DataOffset, info->DataLength );
szValueData[info->DataLength / sizeof(WCHAR)] = '\0';
TRACE("returning %s %s\n", debugstr_w(szValueName), debugstr_w(szValueData));
return TRUE;
}
static BOOL NLS_RegGetDword(HKEY hKey, LPCWSTR szValueName, DWORD *lpVal)
{
BYTE buffer[128];
const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
DWORD dwSize = sizeof(buffer);
UNICODE_STRING valueName;
RtlInitUnicodeString( &valueName, szValueName );
TRACE("%p, %s\n", hKey, debugstr_w(szValueName));
if (NtQueryValueKey( hKey, &valueName, KeyValuePartialInformation,
buffer, dwSize, &dwSize ) == STATUS_SUCCESS &&
info->DataLength == sizeof(DWORD))
{
memcpy(lpVal, info->Data, sizeof(DWORD));
return TRUE;
}
return FALSE;
}
static BOOL NLS_GetLanguageGroupName(LGRPID lgrpid, LPWSTR szName, ULONG nameSize)
{
HMODULE hModule = GetModuleHandleW(kernel32W);
LANGID langId;
LPCWSTR szResourceName = (LPCWSTR)(((lgrpid + 0x2000) >> 4) + 1);
HRSRC hResource;
BOOL bRet = FALSE;
/* FIXME: Is it correct to use the system default langid? */
langId = GetSystemDefaultLangID();
if (SUBLANGID(langId) == SUBLANG_NEUTRAL)
langId = MAKELANGID( PRIMARYLANGID(langId), SUBLANG_DEFAULT );
hResource = FindResourceExW( hModule, (LPWSTR)RT_STRING, szResourceName, langId );
if (hResource)
{
HGLOBAL hResDir = LoadResource( hModule, hResource );
if (hResDir)
{
ULONG iResourceIndex = lgrpid & 0xf;
LPCWSTR lpResEntry = LockResource( hResDir );
ULONG i;
for (i = 0; i < iResourceIndex; i++)
lpResEntry += *lpResEntry + 1;
if (*lpResEntry < nameSize)
{
memcpy( szName, lpResEntry + 1, *lpResEntry * sizeof(WCHAR) );
szName[*lpResEntry] = '\0';
bRet = TRUE;
}
}
FreeResource( hResource );
}
return bRet;
}
/* Registry keys for NLS related information */
static const WCHAR szNlsKeyName[] = {
'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
'C','o','n','t','r','o','l','\\','N','l','s','\0'
};
static const WCHAR szLangGroupsKeyName[] = {
'L','a','n','g','u','a','g','e',' ','G','r','o','u','p','s','\0'
};
static const WCHAR szCountryListName[] = {
'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
'T','e','l','e','p','h','o','n','y','\\',
'C','o','u','n','t','r','y',' ','L','i','s','t','\0'
};
/* Callback function ptrs for EnumSystemLanguageGroupsA/W */
typedef struct
{
LANGUAGEGROUP_ENUMPROCA procA;
LANGUAGEGROUP_ENUMPROCW procW;
DWORD dwFlags;
LONG_PTR lParam;
} ENUMLANGUAGEGROUP_CALLBACKS;
/* Internal implementation of EnumSystemLanguageGroupsA/W */
static BOOL NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS *lpProcs)
{
WCHAR szNumber[10], szValue[4];
HKEY hKey;
BOOL bContinue = TRUE;
ULONG ulIndex = 0;
if (!lpProcs)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
switch (lpProcs->dwFlags)
{
case 0:
/* Default to LGRPID_INSTALLED */
lpProcs->dwFlags = LGRPID_INSTALLED;
/* Fall through... */
case LGRPID_INSTALLED:
case LGRPID_SUPPORTED:
break;
default:
SetLastError(ERROR_INVALID_FLAGS);
return FALSE;
}
hKey = NLS_RegOpenSubKey( NLS_RegOpenKey( 0, szNlsKeyName ), szLangGroupsKeyName );
if (!hKey)
WARN("NLS registry key not found. Please apply the default registry file 'winedefault.reg'\n");
while (bContinue)
{
if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
szValue, sizeof(szValue) ))
{
BOOL bInstalled = szValue[0] == '1' ? TRUE : FALSE;
LGRPID lgrpid = strtoulW( szNumber, NULL, 16 );
TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber),
bInstalled ? "" : "not ");
if (lpProcs->dwFlags == LGRPID_SUPPORTED || bInstalled)
{
WCHAR szGrpName[48];
if (!NLS_GetLanguageGroupName( lgrpid, szGrpName, sizeof(szGrpName) / sizeof(WCHAR) ))
szGrpName[0] = '\0';
if (lpProcs->procW)
bContinue = lpProcs->procW( lgrpid, szNumber, szGrpName, lpProcs->dwFlags,
lpProcs->lParam );
else
{
char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
char szGrpNameA[48];
/* FIXME: MSDN doesn't say which code page the W->A translation uses,
* or whether the language names are ever localised. Assume CP_ACP.
*/
WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
WideCharToMultiByte(CP_ACP, 0, szGrpName, -1, szGrpNameA, sizeof(szGrpNameA), 0, 0);
bContinue = lpProcs->procA( lgrpid, szNumberA, szGrpNameA, lpProcs->dwFlags,
lpProcs->lParam );
}
}
ulIndex++;
}
else
bContinue = FALSE;
if (!bContinue)
break;
}
if (hKey)
NtClose( hKey );
return TRUE;
}
/******************************************************************************
* EnumSystemLanguageGroupsA (KERNEL32.@)
*
* Call a users function for each language group available on the system.
*
* PARAMS
* pLangGrpEnumProc [I] Callback function to call for each language group
* dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
* lParam [I] User parameter to pass to pLangGrpEnumProc
*
* RETURNS
* Success: TRUE.
* Failure: FALSE. Use GetLastError() to determine the cause.
*/
BOOL WINAPI EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc,
DWORD dwFlags, LONG_PTR lParam)
{
ENUMLANGUAGEGROUP_CALLBACKS procs;
TRACE("(%p,0x%08lX,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
procs.procA = pLangGrpEnumProc;
procs.procW = NULL;
procs.dwFlags = dwFlags;
procs.lParam = lParam;
return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
}
/******************************************************************************
* EnumSystemLanguageGroupsW (KERNEL32.@)
*
* See EnumSystemLanguageGroupsA.
*/
BOOL WINAPI EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc,
DWORD dwFlags, LONG_PTR lParam)
{
ENUMLANGUAGEGROUP_CALLBACKS procs;
TRACE("(%p,0x%08lX,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
procs.procA = NULL;
procs.procW = pLangGrpEnumProc;
procs.dwFlags = dwFlags;
procs.lParam = lParam;
return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
}
/******************************************************************************
* IsValidLanguageGroup (KERNEL32.@)
*
* Determine if a language group is supported and/or installed.
*
* PARAMS
* lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
* dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
*
* RETURNS
* TRUE, if lgrpid is supported and/or installed, according to dwFlags.
* FALSE otherwise.
*/
BOOL WINAPI IsValidLanguageGroup(LGRPID lgrpid, DWORD dwFlags)
{
static const WCHAR szFormat[] = { '%','x','\0' };
WCHAR szValueName[16], szValue[2];
BOOL bSupported = FALSE, bInstalled = FALSE;
HKEY hKey;
switch (dwFlags)
{
case LGRPID_INSTALLED:
case LGRPID_SUPPORTED:
hKey = NLS_RegOpenSubKey( NLS_RegOpenKey( 0, szNlsKeyName ), szLangGroupsKeyName );
sprintfW( szValueName, szFormat, lgrpid );
if (NLS_RegGetDword( hKey, szValueName, (LPDWORD)&szValue ))
{
bSupported = TRUE;
if (szValue[0] == '1')
bInstalled = TRUE;
}
if (hKey)
NtClose( hKey );
break;
}
if ((dwFlags == LGRPID_SUPPORTED && bSupported) ||
(dwFlags == LGRPID_INSTALLED && bInstalled))
return TRUE;
return FALSE;
}
/* Callback function ptrs for EnumLanguageGrouplocalesA/W */
typedef struct
{
LANGGROUPLOCALE_ENUMPROCA procA;
LANGGROUPLOCALE_ENUMPROCW procW;
DWORD dwFlags;
LGRPID lgrpid;
LONG_PTR lParam;
} ENUMLANGUAGEGROUPLOCALE_CALLBACKS;
/* Internal implementation of EnumLanguageGrouplocalesA/W */
static BOOL NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS *lpProcs)
{
static const WCHAR szLocaleKeyName[] = {
'L','o','c','a','l','e','\0'
};
static const WCHAR szAlternateSortsKeyName[] = {
'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
};
WCHAR szNumber[10], szValue[4];
HKEY hKey;
BOOL bContinue = TRUE, bAlternate = FALSE;
LGRPID lgrpid;
ULONG ulIndex = 1; /* Ignore default entry of 1st key */
if (!lpProcs || !lpProcs->lgrpid || lpProcs->lgrpid > LGRPID_ARMENIAN)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (lpProcs->dwFlags)
{
SetLastError(ERROR_INVALID_FLAGS);
return FALSE;
}
hKey = NLS_RegOpenSubKey( NLS_RegOpenKey( 0, szNlsKeyName ), szLocaleKeyName );
if (!hKey)
WARN("NLS registry key not found. Please apply the default registry file 'winedefault.reg'\n");
while (bContinue)
{
if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
szValue, sizeof(szValue) ))
{
lgrpid = strtoulW( szValue, NULL, 16 );
TRACE("lcid %s, grpid %ld (%smatched)\n", debugstr_w(szNumber),
lgrpid, lgrpid == lpProcs->lgrpid ? "" : "not ");
if (lgrpid == lpProcs->lgrpid)
{
LCID lcid;
lcid = strtoulW( szNumber, NULL, 16 );
/* FIXME: native returns extra text for a few (17/150) locales, e.g:
* '00000437 ;Georgian'
* At present we only pass the LCID string.
*/
if (lpProcs->procW)
bContinue = lpProcs->procW( lgrpid, lcid, szNumber, lpProcs->lParam );
else
{
char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
bContinue = lpProcs->procA( lgrpid, lcid, szNumberA, lpProcs->lParam );
}
}
ulIndex++;
}
else
{
/* Finished enumerating this key */
if (!bAlternate)
{
/* Enumerate alternate sorts also */
hKey = NLS_RegOpenKey( hKey, szAlternateSortsKeyName );
bAlternate = TRUE;
ulIndex = 0;
}
else
bContinue = FALSE; /* Finished both keys */
}
if (!bContinue)
break;
}
if (hKey)
NtClose( hKey );
return TRUE;
}
/******************************************************************************
* EnumLanguageGroupLocalesA (KERNEL32.@)
*
* Call a users function for every locale in a language group available on the system.
*
* PARAMS
* pLangGrpLcEnumProc [I] Callback function to call for each locale
* lgrpid [I] Language group (LGRPID_ values from "winnls.h")
* dwFlags [I] Reserved, set to 0
* lParam [I] User parameter to pass to pLangGrpLcEnumProc
*
* RETURNS
* Success: TRUE.
* Failure: FALSE. Use GetLastError() to determine the cause.
*/
BOOL WINAPI EnumLanguageGroupLocalesA(LANGGROUPLOCALE_ENUMPROCA pLangGrpLcEnumProc,
LGRPID lgrpid, DWORD dwFlags, LONG_PTR lParam)
{
ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks;
TRACE("(%p,0x%08lX,0x%08lX,0x%08lX)\n", pLangGrpLcEnumProc, lgrpid, dwFlags, lParam);
callbacks.procA = pLangGrpLcEnumProc;
callbacks.procW = NULL;
callbacks.dwFlags = dwFlags;
callbacks.lgrpid = lgrpid;
callbacks.lParam = lParam;
return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc ? &callbacks : NULL );
}
/******************************************************************************
* EnumLanguageGroupLocalesW (KERNEL32.@)
*
* See EnumLanguageGroupLocalesA.
*/
BOOL WINAPI EnumLanguageGroupLocalesW(LANGGROUPLOCALE_ENUMPROCW pLangGrpLcEnumProc,
LGRPID lgrpid, DWORD dwFlags, LONG_PTR lParam)
{
ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks;
TRACE("(%p,0x%08lX,0x%08lX,0x%08lX)\n", pLangGrpLcEnumProc, lgrpid, dwFlags, lParam);
callbacks.procA = NULL;
callbacks.procW = pLangGrpLcEnumProc;
callbacks.dwFlags = dwFlags;
callbacks.lgrpid = lgrpid;
callbacks.lParam = lParam;
return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc ? &callbacks : NULL );
}
/******************************************************************************
* EnumSystemGeoID (KERNEL32.@)
*
* Call a users function for every location available on the system.
*
* PARAMS
* geoclass [I] Type of information desired (SYSGEOTYPE enum from "winnls.h")
* reserved [I] Reserved, set to 0
* pGeoEnumProc [I] Callback function to call for each location
*
* RETURNS
* Success: TRUE.
* Failure: FALSE. Use GetLastError() to determine the cause.
*/
BOOL WINAPI EnumSystemGeoID(GEOCLASS geoclass, GEOID reserved, GEO_ENUMPROC pGeoEnumProc)
{
static const WCHAR szCountryCodeValueName[] = {
'C','o','u','n','t','r','y','C','o','d','e','\0'
};
WCHAR szNumber[10];
HKEY hKey;
ULONG ulIndex = 0;
TRACE("(0x%08lX,0x%08lX,%p)\n", geoclass, reserved, pGeoEnumProc);
if (geoclass != GEOCLASS_NATION || reserved || !pGeoEnumProc)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
hKey = NLS_RegOpenKey( 0, szCountryListName );
while (NLS_RegEnumSubKey( hKey, ulIndex, szNumber, sizeof(szNumber) ))
{
BOOL bContinue = TRUE;
DWORD dwGeoId;
HKEY hSubKey = NLS_RegOpenKey( hKey, szNumber );
if (hSubKey)
{
if (NLS_RegGetDword( hSubKey, szCountryCodeValueName, &dwGeoId ))
{
TRACE("Got geoid %ld\n", dwGeoId);
if (!pGeoEnumProc( dwGeoId ))
bContinue = FALSE;
}
NtClose( hSubKey );
}
if (!bContinue)
break;
ulIndex++;
}
if (hKey)
NtClose( hKey );
return TRUE;
}
/******************************************************************************
* InvalidateNLSCache (KERNEL32.@)
*
* Invalidate the cache of NLS values.
*
* PARAMS
* None.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE.
*/
BOOL WINAPI InvalidateNLSCache(void)
{
FIXME("() stub\n");
return FALSE;
}