📄 getqloc.c
字号:
/***
*void TranslateName - convert known non-NLS string to NLS equivalent
*
*Purpose:
* Provide compatibility with existing code for non-NLS strings
*
*Entry:
* lpTable - pointer to LOCALETAB used for translation
* high - maximum index of table (size - 1)
* ppchName - pointer to pointer of string to translate
*
*Exit:
* ppchName - pointer to pointer of string possibly translated
*
*Exceptions:
*
*******************************************************************************/
static void TranslateName (LOCALETAB * lpTable, int high, char ** ppchName)
{
int i;
int cmp = 1;
int low = 0;
// typical binary search - do until no more to search or match
while (low <= high && cmp != 0)
{
i = (low + high) / 2;
cmp = _stricmp(*ppchName, (const char *)(*(lpTable + i)).szName);
if (cmp == 0)
*ppchName = (*(lpTable + i)).chAbbrev;
else if (cmp < 0)
high = i - 1;
else
low = i + 1;
}
}
/***
*void GetLcidFromLangCountry - get LCIDs from language and country strings
*
*Purpose:
* Match the best LCIDs to the language and country string given.
* After global variables are initialized, the LangCountryEnumProc
* routine is registered as an EnumSystemLocalesA callback to actually
* perform the matching as the LCIDs are enumerated.
*
*Entry:
* pchLanguage - language string
* bAbbrevLanguage - language string is a three-letter abbreviation
* pchCountry - country string
* bAbbrevCountry - country string ia a three-letter abbreviation
* iPrimaryLen - length of language string with primary name
*
*Exit:
* lcidLanguage - LCID of language string
* lcidCountry - LCID of country string
*
*Exceptions:
*
*******************************************************************************/
static void GetLcidFromLangCountry (void)
{
// initialize static variables for callback use
bAbbrevLanguage = strlen(pchLanguage) == 3;
bAbbrevCountry = strlen(pchCountry) == 3;
lcidLanguage = 0;
iPrimaryLen = bAbbrevLanguage ? 2 : GetPrimaryLen(pchLanguage);
EnumSystemLocalesA(LangCountryEnumProc, LCID_INSTALLED);
// locale value is invalid if the language was not installed or the language
// was not available for the country specified
if (!(iLcidState & __LCID_LANGUAGE) || !(iLcidState & __LCID_EXISTS) ||
!(iLcidState & (__LCID_FULL | __LCID_PRIMARY | __LCID_DEFAULT)))
iLcidState = 0;
}
/***
*BOOL CALLBACK LangCountryEnumProc - callback routine for GetLcidFromLangCountry
*
*Purpose:
* Determine if LCID given matches the language in pchLanguage
* and country in pchCountry.
*
*Entry:
* lpLcidString - pointer to string with decimal LCID
* pchCountry - pointer to country name
* bAbbrevCountry - set if country is three-letter abbreviation
*
*Exit:
* iLcidState - status of match
* __LCID_FULL - both language and country match (best match)
* __LCID_PRIMARY - primary language and country match (better)
* __LCID_DEFAULT - default language and country match (good)
* __LCID_LANGUAGE - default primary language exists
* __LCID_EXISTS - full match of language string exists
* (Overall match occurs for the best of FULL/PRIMARY/DEFAULT
* and LANGUAGE/EXISTS both set.)
* lcidLanguage - LCID matched
* lcidCountry - LCID matched
* FALSE if match occurred to terminate enumeration, else TRUE.
*
*Exceptions:
*
*******************************************************************************/
static BOOL CALLBACK LangCountryEnumProc (LPSTR lpLcidString)
{
LCID lcid = LcidFromHexString(lpLcidString);
char rgcInfo[120];
// test locale country against input value
if ((*pfnGetLocaleInfoA)(lcid, bAbbrevCountry ? LOCALE_SABBREVCTRYNAME
: LOCALE_SENGCOUNTRY,
rgcInfo, sizeof(rgcInfo)) == 0)
{
// set error condition and exit
iLcidState = 0;
return TRUE;
}
if (!_stricmp(pchCountry, rgcInfo))
{
// country matched - test for language match
if ((*pfnGetLocaleInfoA)(lcid, bAbbrevLanguage ? LOCALE_SABBREVLANGNAME
: LOCALE_SENGLANGUAGE,
rgcInfo, sizeof(rgcInfo)) == 0)
{
// set error condition and exit
iLcidState = 0;
return TRUE;
}
if (!_stricmp(pchLanguage, rgcInfo))
{
// language matched also - set state and value
iLcidState |= (__LCID_FULL | __LCID_LANGUAGE | __LCID_EXISTS);
lcidLanguage = lcidCountry = lcid;
}
// test if match already for primary langauage
else if (!(iLcidState & __LCID_PRIMARY))
{
// if not, use iPrimaryLen to partial match language string
if (iPrimaryLen && !_strnicmp(pchLanguage, rgcInfo, iPrimaryLen))
{
// primary language matched - set state and country LCID
iLcidState |= __LCID_PRIMARY;
lcidCountry = lcid;
// if language is primary only (no subtype), set language LCID
if ((int)strlen(pchLanguage) == iPrimaryLen)
lcidLanguage = lcid;
}
// test if default language already defined
else if (!(iLcidState & __LCID_DEFAULT))
{
// if not, test if locale language is default for country
if (TestDefaultCountry(lcid))
{
// default language for country - set state, value
iLcidState |= __LCID_DEFAULT;
lcidCountry = lcid;
}
}
}
}
// test if input language both exists and default primary language defined
if ((iLcidState & (__LCID_LANGUAGE | __LCID_EXISTS)) !=
(__LCID_LANGUAGE | __LCID_EXISTS))
{
// test language match to determine whether it is installed
if ((*pfnGetLocaleInfoA)(lcid, bAbbrevLanguage ? LOCALE_SABBREVLANGNAME
: LOCALE_SENGLANGUAGE,
rgcInfo, sizeof(rgcInfo)) == 0)
{
// set error condition and exit
iLcidState = 0;
return TRUE;
}
if (!_stricmp(pchLanguage, rgcInfo))
{
// language matched - set bit for existance
iLcidState |= __LCID_EXISTS;
if (bAbbrevLanguage)
{
// abbreviation - set state
// also set language LCID if not set already
iLcidState |= __LCID_LANGUAGE;
if (!lcidLanguage)
lcidLanguage = lcid;
}
// test if language is primary only (no sublanguage)
else if (iPrimaryLen && ((int)strlen(pchLanguage) == iPrimaryLen))
{
// primary language only - test if default LCID
if (TestDefaultLanguage(lcid, TRUE))
{
// default primary language - set state
// also set LCID if not set already
iLcidState |= __LCID_LANGUAGE;
if (!lcidLanguage)
lcidLanguage = lcid;
}
}
else
{
// language with sublanguage - set state
// also set LCID if not set already
iLcidState |= __LCID_LANGUAGE;
if (!lcidLanguage)
lcidLanguage = lcid;
}
}
else if (!bAbbrevLanguage && iPrimaryLen
&& !_strnicmp(pchLanguage, rgcInfo, iPrimaryLen))
{
// primary language match - test for default language only
if (TestDefaultLanguage(lcid, FALSE))
{
// default primary language - set state
// also set LCID if not set already
iLcidState |= __LCID_LANGUAGE;
if (!lcidLanguage)
lcidLanguage = lcid;
}
}
}
// if LOCALE_FULL set, return FALSE to stop enumeration,
// else return TRUE to continue
return (iLcidState & __LCID_FULL) == 0;
}
/***
*void GetLcidFromLanguage - get LCIDs from language string
*
*Purpose:
* Match the best LCIDs to the language string given. After global
* variables are initialized, the LanguageEnumProc routine is
* registered as an EnumSystemLocalesA callback to actually perform
* the matching as the LCIDs are enumerated.
*
*Entry:
* pchLanguage - language string
* bAbbrevLanguage - language string is a three-letter abbreviation
* iPrimaryLen - length of language string with primary name
*
*Exit:
* lcidLanguage - lcidCountry - LCID of language with default
* country
*
*Exceptions:
*
*******************************************************************************/
static void GetLcidFromLanguage (void)
{
// initialize static variables for callback use
bAbbrevLanguage = strlen(pchLanguage) == 3;
iPrimaryLen = bAbbrevLanguage ? 2 : GetPrimaryLen(pchLanguage);
EnumSystemLocalesA(LanguageEnumProc, LCID_INSTALLED);
// locale value is invalid if the language was not installed
// or the language was not available for the country specified
if (!(iLcidState & __LCID_FULL))
iLcidState = 0;
}
/***
*BOOL CALLBACK LanguageEnumProc - callback routine for GetLcidFromLanguage
*
*Purpose:
* Determine if LCID given matches the default country for the
* language in pchLanguage.
*
*Entry:
* lpLcidString - pointer to string with decimal LCID
* pchLanguage - pointer to language name
* bAbbrevLanguage - set if language is three-letter abbreviation
*
*Exit:
* lcidLanguage - lcidCountry - LCID matched
* FALSE if match occurred to terminate enumeration, else TRUE.
*
*Exceptions:
*
*******************************************************************************/
static BOOL CALLBACK LanguageEnumProc (LPSTR lpLcidString)
{
LCID lcid = LcidFromHexString(lpLcidString);
char rgcInfo[120];
// test locale for language specified
if ((*pfnGetLocaleInfoA)(lcid, bAbbrevLanguage ? LOCALE_SABBREVLANGNAME
: LOCALE_SENGLANGUAGE,
rgcInfo, sizeof(rgcInfo)) == 0)
{
// set error condition and exit
iLcidState = 0;
return TRUE;
}
if (!_stricmp(pchLanguage, rgcInfo))
{
// language matched - test if locale country is default
// or if locale is implied in the language string
if (bAbbrevLanguage || TestDefaultLanguage(lcid, TRUE))
{
// this locale has the default country
lcidLanguage = lcidCountry = lcid;
iLcidState |= __LCID_FULL;
}
}
else if (!bAbbrevLanguage && iPrimaryLen
&& !_strnicmp(pchLanguage, rgcInfo, iPrimaryLen))
{
// primary language matched - test if locale country is default
if (TestDefaultLanguage(lcid, FALSE))
{
// this is the default country
lcidLanguage = lcidCountry = lcid;
iLcidState |= __LCID_FULL;
}
}
return (iLcidState & __LCID_FULL) == 0;
}
/***
*void GetLcidFromCountry - get LCIDs from country string
*
*Purpose:
* Match the best LCIDs to the country string given. After global
* variables are initialized, the CountryEnumProc routine is
* registered as an EnumSystemLocalesA callback to actually perform
* the matching as the LCIDs are enumerated.
*
*Entry:
* pchCountry - country string
* bAbbrevCountry - country string is a three-letter abbreviation
*
*Exit:
* lcidLanguage - lcidCountry - LCID of country with default
* language
*
*Exceptions:
*
*******************************************************************************/
static void GetLcidFromCountry (void)
{
bAbbrevCountry = strlen(pchCountry) == 3;
EnumSystemLocalesA(CountryEnumProc, LCID_INSTALLED);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -