📄 getqloc.c
字号:
/***
*BOOL 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
* TRUE if string translated, FALSE if unchanged
*
*Exceptions:
*
*******************************************************************************/
static BOOL TranslateName (
const LOCALETAB * lpTable,
int high,
const 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;
}
return !cmp;
}
/***
*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 (_psetloc_struct _psetloc_data)
{
// initialize static variables for callback use
_psetloc_data->bAbbrevLanguage = strlen(_psetloc_data->pchLanguage) == 3;
_psetloc_data->bAbbrevCountry = strlen(_psetloc_data->pchCountry) == 3;
_psetloc_data->lcidLanguage = 0;
_psetloc_data->iPrimaryLen = _psetloc_data->bAbbrevLanguage ?
2 : GetPrimaryLen(_psetloc_data->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 (!(_psetloc_data->iLcidState & __LCID_LANGUAGE) ||
!(_psetloc_data->iLcidState & __LCID_EXISTS) ||
!(_psetloc_data->iLcidState & (__LCID_FULL |
__LCID_PRIMARY |
__LCID_DEFAULT)))
_psetloc_data->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)
{
_psetloc_struct _psetloc_data = &_getptd()->_setloc_data;
LCID lcid = LcidFromHexString(lpLcidString);
char rgcInfo[120];
// test locale country against input value
if (GetLocaleInfoA(lcid,
_psetloc_data->bAbbrevCountry ?
LOCALE_SABBREVCTRYNAME : LOCALE_SENGCOUNTRY,
rgcInfo, sizeof(rgcInfo)) == 0)
{
// set error condition and exit
_psetloc_data->iLcidState = 0;
return TRUE;
}
if (!_stricmp(_psetloc_data->pchCountry, rgcInfo))
{
// country matched - test for language match
if (GetLocaleInfoA(lcid,
_psetloc_data->bAbbrevLanguage ?
LOCALE_SABBREVLANGNAME : LOCALE_SENGLANGUAGE,
rgcInfo, sizeof(rgcInfo)) == 0)
{
// set error condition and exit
_psetloc_data->iLcidState = 0;
return TRUE;
}
if (!_stricmp(_psetloc_data->pchLanguage, rgcInfo))
{
// language matched also - set state and value
_psetloc_data->iLcidState |= (__LCID_FULL |
__LCID_LANGUAGE |
__LCID_EXISTS);
_psetloc_data->lcidLanguage = _psetloc_data->lcidCountry = lcid;
}
// test if match already for primary langauage
else if (!(_psetloc_data->iLcidState & __LCID_PRIMARY))
{
// if not, use _psetloc_data->iPrimaryLen to partial match language string
if (_psetloc_data->iPrimaryLen && !_strnicmp(_psetloc_data->pchLanguage, rgcInfo, _psetloc_data->iPrimaryLen))
{
// primary language matched - set state and country LCID
_psetloc_data->iLcidState |= __LCID_PRIMARY;
_psetloc_data->lcidCountry = lcid;
// if language is primary only (no subtype), set language LCID
if ((int)strlen(_psetloc_data->pchLanguage) == _psetloc_data->iPrimaryLen)
_psetloc_data->lcidLanguage = lcid;
}
// test if default language already defined
else if (!(_psetloc_data->iLcidState & __LCID_DEFAULT))
{
// if not, test if locale language is default for country
if (TestDefaultCountry(lcid))
{
// default language for country - set state, value
_psetloc_data->iLcidState |= __LCID_DEFAULT;
_psetloc_data->lcidCountry = lcid;
}
}
}
}
// test if input language both exists and default primary language defined
if ((_psetloc_data->iLcidState & (__LCID_LANGUAGE | __LCID_EXISTS)) !=
(__LCID_LANGUAGE | __LCID_EXISTS))
{
// test language match to determine whether it is installed
if (GetLocaleInfoA(lcid, _psetloc_data->bAbbrevLanguage ? LOCALE_SABBREVLANGNAME
: LOCALE_SENGLANGUAGE,
rgcInfo, sizeof(rgcInfo)) == 0)
{
// set error condition and exit
_psetloc_data->iLcidState = 0;
return TRUE;
}
if (!_stricmp(_psetloc_data->pchLanguage, rgcInfo))
{
// language matched - set bit for existance
_psetloc_data->iLcidState |= __LCID_EXISTS;
if (_psetloc_data->bAbbrevLanguage)
{
// abbreviation - set state
// also set language LCID if not set already
_psetloc_data->iLcidState |= __LCID_LANGUAGE;
if (!_psetloc_data->lcidLanguage)
_psetloc_data->lcidLanguage = lcid;
}
// test if language is primary only (no sublanguage)
else if (_psetloc_data->iPrimaryLen && ((int)strlen(_psetloc_data->pchLanguage) == _psetloc_data->iPrimaryLen))
{
// primary language only - test if default LCID
if (TestDefaultLanguage(lcid, TRUE, _psetloc_data))
{
// default primary language - set state
// also set LCID if not set already
_psetloc_data->iLcidState |= __LCID_LANGUAGE;
if (!_psetloc_data->lcidLanguage)
_psetloc_data->lcidLanguage = lcid;
}
}
else
{
// language with sublanguage - set state
// also set LCID if not set already
_psetloc_data->iLcidState |= __LCID_LANGUAGE;
if (!_psetloc_data->lcidLanguage)
_psetloc_data->lcidLanguage = lcid;
}
}
else if (!_psetloc_data->bAbbrevLanguage && _psetloc_data->iPrimaryLen
&& !_stricmp(_psetloc_data->pchLanguage, rgcInfo))
{
// primary language match - test for default language only
if (TestDefaultLanguage(lcid, FALSE, _psetloc_data))
{
// default primary language - set state
// also set LCID if not set already
_psetloc_data->iLcidState |= __LCID_LANGUAGE;
if (!_psetloc_data->lcidLanguage)
_psetloc_data->lcidLanguage = lcid;
}
}
}
// if LOCALE_FULL set, return FALSE to stop enumeration,
// else return TRUE to continue
return (_psetloc_data->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 (_psetloc_struct _psetloc_data)
{
// initialize static variables for callback use
_psetloc_data->bAbbrevLanguage = strlen(_psetloc_data->pchLanguage) == 3;
_psetloc_data->iPrimaryLen = _psetloc_data->bAbbrevLanguage ? 2 : GetPrimaryLen(_psetloc_data->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 (!(_psetloc_data->iLcidState & __LCID_FULL))
_psetloc_data->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)
{
_psetloc_struct _psetloc_data = &_getptd()->_setloc_data;
LCID lcid = LcidFromHexString(lpLcidString);
char rgcInfo[120];
// test locale for language specified
if (GetLocaleInfoA(lcid, _psetloc_data->bAbbrevLanguage ? LOCALE_SABBREVLANGNAME
: LOCALE_SENGLANGUAGE,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -