msvcrt: Move locale string interpretation to MSVCRT_locale_to_LCID.
This commit is contained in:
parent
20b77f4428
commit
6ad7b4ff5c
|
@ -193,65 +193,85 @@ find_best_locale_proc(HMODULE hModule, LPCSTR type, LPCSTR name, WORD LangID, LO
|
||||||
extern int atoi(const char *);
|
extern int atoi(const char *);
|
||||||
|
|
||||||
/* Internal: Find the LCID for a locale specification */
|
/* Internal: Find the LCID for a locale specification */
|
||||||
static LCID MSVCRT_locale_to_LCID(locale_search_t* locale)
|
static LCID MSVCRT_locale_to_LCID(const char *locale)
|
||||||
{
|
{
|
||||||
LCID lcid;
|
LCID lcid;
|
||||||
|
locale_search_t search;
|
||||||
|
char *cp, *region;
|
||||||
|
|
||||||
|
memset(&search, 0, sizeof(locale_search_t));
|
||||||
|
|
||||||
|
cp = strchr(locale, '.');
|
||||||
|
region = strchr(locale, '_');
|
||||||
|
|
||||||
|
lstrcpynA(search.search_language, locale, MAX_ELEM_LEN);
|
||||||
|
if(region) {
|
||||||
|
lstrcpynA(search.search_country, region+1, MAX_ELEM_LEN);
|
||||||
|
if(region-locale < MAX_ELEM_LEN)
|
||||||
|
search.search_language[region-locale] = '\0';
|
||||||
|
} else
|
||||||
|
search.search_country[0] = '\0';
|
||||||
|
|
||||||
|
if(cp) {
|
||||||
|
lstrcpynA(search.search_codepage, cp+1, MAX_ELEM_LEN);
|
||||||
|
if(cp-region < MAX_ELEM_LEN)
|
||||||
|
search.search_country[cp-region] = '\0';
|
||||||
|
if(cp-locale < MAX_ELEM_LEN)
|
||||||
|
search.search_language[cp-locale] = '\0';
|
||||||
|
} else
|
||||||
|
search.search_codepage[0] = '\0';
|
||||||
|
|
||||||
|
/* FIXME: MSVCRT_locale_to_LCID is not finding remaped values */
|
||||||
|
remap_synonym(search.search_country);
|
||||||
|
|
||||||
EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), (LPSTR)RT_STRING,
|
EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), (LPSTR)RT_STRING,
|
||||||
(LPCSTR)LOCALE_ILANGUAGE,find_best_locale_proc,
|
(LPCSTR)LOCALE_ILANGUAGE,find_best_locale_proc,
|
||||||
(LONG_PTR)locale);
|
(LONG_PTR)&search);
|
||||||
|
|
||||||
if (!locale->match_flags)
|
if (!search.match_flags)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* If we were given something that didn't match, fail */
|
/* If we were given something that didn't match, fail */
|
||||||
if (locale->search_country[0] && !(locale->match_flags & FOUND_COUNTRY))
|
if (search.search_country[0] && !(search.match_flags & FOUND_COUNTRY))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
lcid = MAKELCID(locale->found_lang_id, SORT_DEFAULT);
|
lcid = MAKELCID(search.found_lang_id, SORT_DEFAULT);
|
||||||
|
|
||||||
/* Populate partial locale, translating LCID to locale string elements */
|
/* Populate partial locale, translating LCID to locale string elements */
|
||||||
if (!locale->found_codepage[0])
|
if (!search.found_codepage[0]) {
|
||||||
{
|
|
||||||
/* Even if a codepage is not enumerated for a locale
|
/* Even if a codepage is not enumerated for a locale
|
||||||
* it can be set if valid */
|
* it can be set if valid */
|
||||||
if (locale->search_codepage[0])
|
if (search.search_codepage[0]) {
|
||||||
{
|
if (IsValidCodePage(atoi(search.search_codepage)))
|
||||||
if (IsValidCodePage(atoi(locale->search_codepage)))
|
memcpy(search.found_codepage,search.search_codepage,MAX_ELEM_LEN);
|
||||||
memcpy(locale->found_codepage,locale->search_codepage,MAX_ELEM_LEN);
|
else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Special codepage values: OEM & ANSI */
|
/* Special codepage values: OEM & ANSI */
|
||||||
if (strcasecmp(locale->search_codepage,"OCP"))
|
if (strcasecmp(search.search_codepage,"OCP")) {
|
||||||
{
|
|
||||||
GetLocaleInfoA(lcid, LOCALE_IDEFAULTCODEPAGE,
|
GetLocaleInfoA(lcid, LOCALE_IDEFAULTCODEPAGE,
|
||||||
locale->found_codepage, MAX_ELEM_LEN);
|
search.found_codepage, MAX_ELEM_LEN);
|
||||||
}
|
} else if (strcasecmp(search.search_codepage,"ACP")) {
|
||||||
else if (strcasecmp(locale->search_codepage,"ACP"))
|
|
||||||
{
|
|
||||||
GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE,
|
GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE,
|
||||||
locale->found_codepage, MAX_ELEM_LEN);
|
search.found_codepage, MAX_ELEM_LEN);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!atoi(locale->found_codepage))
|
if (!atoi(search.found_codepage))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Prefer ANSI codepages if present */
|
/* Prefer ANSI codepages if present */
|
||||||
GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE,
|
GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE,
|
||||||
locale->found_codepage, MAX_ELEM_LEN);
|
search.found_codepage, MAX_ELEM_LEN);
|
||||||
if (!locale->found_codepage[0] || !atoi(locale->found_codepage))
|
if (!search.found_codepage[0] || !atoi(search.found_codepage))
|
||||||
GetLocaleInfoA(lcid, LOCALE_IDEFAULTCODEPAGE,
|
GetLocaleInfoA(lcid, LOCALE_IDEFAULTCODEPAGE,
|
||||||
locale->found_codepage, MAX_ELEM_LEN);
|
search.found_codepage, MAX_ELEM_LEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE|LOCALE_NOUSEROVERRIDE,
|
GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE|LOCALE_NOUSEROVERRIDE,
|
||||||
locale->found_language, MAX_ELEM_LEN);
|
search.found_language, MAX_ELEM_LEN);
|
||||||
GetLocaleInfoA(lcid, LOCALE_SENGCOUNTRY|LOCALE_NOUSEROVERRIDE,
|
GetLocaleInfoA(lcid, LOCALE_SENGCOUNTRY|LOCALE_NOUSEROVERRIDE,
|
||||||
locale->found_country, MAX_ELEM_LEN);
|
search.found_country, MAX_ELEM_LEN);
|
||||||
return lcid;
|
return lcid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,35 +592,7 @@ MSVCRT__locale_t _create_locale(int category, const char *locale)
|
||||||
*/
|
*/
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
locale_search_t search;
|
lcid = MSVCRT_locale_to_LCID(locale);
|
||||||
char *cp, *region;
|
|
||||||
|
|
||||||
memset(&search, 0, sizeof(locale_search_t));
|
|
||||||
|
|
||||||
cp = strchr(locale, '.');
|
|
||||||
region = strchr(locale, '_');
|
|
||||||
|
|
||||||
lstrcpynA(search.search_language, locale, MAX_ELEM_LEN);
|
|
||||||
if(region) {
|
|
||||||
lstrcpynA(search.search_country, region+1, MAX_ELEM_LEN);
|
|
||||||
if(region-locale < MAX_ELEM_LEN)
|
|
||||||
search.search_language[region-locale] = '\0';
|
|
||||||
} else
|
|
||||||
search.search_country[0] = '\0';
|
|
||||||
|
|
||||||
if(cp) {
|
|
||||||
lstrcpynA(search.search_codepage, cp+1, MAX_ELEM_LEN);
|
|
||||||
if(cp-region < MAX_ELEM_LEN)
|
|
||||||
search.search_country[cp-region] = '\0';
|
|
||||||
if(cp-locale < MAX_ELEM_LEN)
|
|
||||||
search.search_language[cp-locale] = '\0';
|
|
||||||
} else
|
|
||||||
search.search_codepage[0] = '\0';
|
|
||||||
|
|
||||||
/* FIXME: MSVCRT_locale_to_LCID is not finding remaped values */
|
|
||||||
remap_synonym(search.search_country);
|
|
||||||
|
|
||||||
lcid = MSVCRT_locale_to_LCID(&search);
|
|
||||||
if(!lcid)
|
if(!lcid)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue