📄 getqloc.c
字号:
rgcInfo, sizeof(rgcInfo)) == 0)
{
// set error condition and exit
_psetloc_data->iLcidState = 0;
return TRUE;
}
if (!_stricmp(_psetloc_data->pchLanguage, rgcInfo))
{
// language matched - test if locale country is default
// or if locale is implied in the language string
if (_psetloc_data->bAbbrevLanguage || TestDefaultLanguage(lcid, TRUE, _psetloc_data))
{
// this locale has the default country
_psetloc_data->lcidLanguage = _psetloc_data->lcidCountry = lcid;
_psetloc_data->iLcidState |= __LCID_FULL;
}
}
else if (!_psetloc_data->bAbbrevLanguage && _psetloc_data->iPrimaryLen
&& !_stricmp(_psetloc_data->pchLanguage, rgcInfo))
{
// primary language matched - test if locale country is default
if (TestDefaultLanguage(lcid, FALSE, _psetloc_data))
{
// this is the default country
_psetloc_data->lcidLanguage = _psetloc_data->lcidCountry = lcid;
_psetloc_data->iLcidState |= __LCID_FULL;
}
}
return (_psetloc_data->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 (_psetloc_struct _psetloc_data)
{
_psetloc_data->bAbbrevCountry = strlen(_psetloc_data->pchCountry) == 3;
EnumSystemLocalesA(CountryEnumProc, LCID_INSTALLED);
// locale value is invalid if the country was not defined or
// no default language was found
if (!(_psetloc_data->iLcidState & __LCID_FULL))
_psetloc_data->iLcidState = 0;
}
/***
*BOOL CALLBACK CountryEnumProc - callback routine for GetLcidFromCountry
*
*Purpose:
* Determine if LCID given matches the default language for the
* 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:
* lcidLanguage - lcidCountry - LCID matched
* FALSE if match occurred to terminate enumeration, else TRUE.
*
*Exceptions:
*
*******************************************************************************/
static BOOL CALLBACK CountryEnumProc (LPSTR lpLcidString)
{
_psetloc_struct _psetloc_data = &_getptd()->_setloc_data;
LCID lcid = LcidFromHexString(lpLcidString);
char rgcInfo[120];
// test locale for country specified
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))
{
// language matched - test if locale country is default
if (TestDefaultCountry(lcid))
{
// this locale has the default language
_psetloc_data->lcidLanguage = _psetloc_data->lcidCountry = lcid;
_psetloc_data->iLcidState |= __LCID_FULL;
}
}
return (_psetloc_data->iLcidState & __LCID_FULL) == 0;
}
/***
*void GetLcidFromDefault - get default LCIDs
*
*Purpose:
* Set both language and country LCIDs to the system default.
*
*Entry:
* None.
*
*Exit:
* lcidLanguage - set to system LCID
* lcidCountry - set to system LCID
*
*Exceptions:
*
*******************************************************************************/
static void GetLcidFromDefault (_psetloc_struct _psetloc_data)
{
_psetloc_data->iLcidState |= (__LCID_FULL | __LCID_LANGUAGE);
_psetloc_data->lcidLanguage = _psetloc_data->lcidCountry = GetUserDefaultLCID();
}
/***
*int ProcessCodePage - convert codepage string to numeric value
*
*Purpose:
* Process codepage string consisting of a decimal string, or the
* special case strings "ACP" and "OCP", for ANSI and OEM codepages,
* respectively. Null pointer or string returns the ANSI codepage.
*
*Entry:
* lpCodePageStr - pointer to codepage string
*
*Exit:
* Returns numeric value of codepage.
*
*Exceptions:
*
*******************************************************************************/
static int ProcessCodePage (LPSTR lpCodePageStr, _psetloc_struct _psetloc_data)
{
int iCodePage;
if (!lpCodePageStr || !*lpCodePageStr || !strcmp(lpCodePageStr, "ACP"))
{
// get ANSI codepage for the country LCID
if (GetLocaleInfoW(_psetloc_data->lcidCountry, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
(LPWSTR) &iCodePage, sizeof(iCodePage) / sizeof(wchar_t)) == 0)
return 0;
if (iCodePage == 0) // for locales have no assoicated ANSI codepage, e.g. Hindi locale
return GetACP();
}
else if (!strcmp(lpCodePageStr, "OCP"))
{
// get OEM codepage for the country LCID
if (GetLocaleInfoW(_psetloc_data->lcidCountry, LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
(LPWSTR) &iCodePage, sizeof(iCodePage) / sizeof(wchar_t)) == 0)
return 0;
}
else
{
// convert decimal string to numeric value
iCodePage = (int)atol(lpCodePageStr);
}
return iCodePage;
}
/***
*BOOL TestDefaultCountry - determine if default locale for country
*
*Purpose:
* Using a hardcoded list, determine if the locale of the given LCID
* has the default sublanguage for the locale primary language. The
* list contains the locales NOT having the default sublanguage.
*
*Entry:
* lcid - LCID of locale to test
*
*Exit:
* Returns TRUE if default sublanguage, else FALSE.
*
*Exceptions:
*
*******************************************************************************/
static BOOL TestDefaultCountry (LCID lcid)
{
LANGID langid = LANGIDFROMLCID(lcid);
int i;
for (i = 0; i < sizeof(__rglangidNotDefault) / sizeof(LANGID); i++)
{
if (langid == __rglangidNotDefault[i])
return FALSE;
}
return TRUE;
}
/***
*BOOL TestDefaultLanguage - determine if default locale for language
*
*Purpose:
* Determines if the given LCID has the default sublanguage.
* If bTestPrimary is set, also allow TRUE when string contains an
* implicit sublanguage.
*
*Entry:
* LCID - lcid of locale to test
* bTestPrimary - set if testing if language is primary
*
*Exit:
* Returns TRUE if sublanguage is default for locale tested.
* If bTestPrimary set, TRUE is language has implied sublanguge.
*
*Exceptions:
*
*******************************************************************************/
static BOOL TestDefaultLanguage (LCID lcid, BOOL bTestPrimary, _psetloc_struct _psetloc_data)
{
DWORD dwLanguage;
LCID lcidDefault = MAKELCID(MAKELANGID(PRIMARYLANGID(LANGIDFROMLCID(lcid)),
SUBLANG_DEFAULT), SORT_DEFAULT);
if (GetLocaleInfoW(lcidDefault, LOCALE_ILANGUAGE | LOCALE_RETURN_NUMBER,
(LPWSTR) &dwLanguage, sizeof(dwLanguage) / sizeof(wchar_t)) == 0)
return FALSE;
if (lcid != dwLanguage)
{
// test if string contains an implicit sublanguage by
// having a character other than upper/lowercase letters.
if (bTestPrimary && GetPrimaryLen(_psetloc_data->pchLanguage) == (int)strlen(_psetloc_data->pchLanguage))
return FALSE;
}
return TRUE;
}
/***
*LCID LcidFromHexString - convert hex string to value for LCID
*
*Purpose:
* LCID values returned in hex ANSI strings - straight conversion
*
*Entry:
* lpHexString - pointer to hex string to convert
*
*Exit:
* Returns LCID computed.
*
*Exceptions:
*
*******************************************************************************/
static LCID LcidFromHexString (LPSTR lpHexString)
{
char ch;
DWORD lcid = 0;
while (ch = *lpHexString++)
{
if (ch >= 'a' && ch <= 'f')
ch += '9' + 1 - 'a';
else if (ch >= 'A' && ch <= 'F')
ch += '9' + 1 - 'A';
lcid = lcid * 0x10 + ch - '0';
}
return (LCID)lcid;
}
/***
*int GetPrimaryLen - get length of primary language name
*
*Purpose:
* Determine primary language string length by scanning until
* first non-alphabetic character.
*
*Entry:
* pchLanguage - string to scan
*
*Exit:
* Returns length of primary language string.
*
*Exceptions:
*
*******************************************************************************/
static int GetPrimaryLen (LPSTR pchLanguage)
{
int len = 0;
char ch;
ch = *pchLanguage++;
while ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
{
len++;
ch = *pchLanguage++;
}
return len;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -