⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getqloc.c

📁 C标准库源代码
💻 C
📖 第 1 页 / 共 3 页
字号:

    //  locale value is invalid if the country was not defined or
    //  no default language was found
    if (!(iLcidState & __LCID_FULL))
        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)
{
    LCID    lcid = LcidFromHexString(lpLcidString);
    char    rgcInfo[120];

    //  test locale for country specified
    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))
    {
        //  language matched - test if locale country is default
        if (TestDefaultCountry(lcid))
        {
            //  this locale has the default language
            lcidLanguage = lcidCountry = lcid;
            iLcidState |= __LCID_FULL;
        }
    }
    return (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 (void)
{
    iLcidState |= (__LCID_FULL | __LCID_LANGUAGE);
    lcidLanguage = 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)
{
    char    chCodePage[8];

    if (!lpCodePageStr || !*lpCodePageStr || !strcmp(lpCodePageStr, "ACP"))
    {
        //  get ANSI codepage for the country LCID
        if ((*pfnGetLocaleInfoA)(lcidCountry, LOCALE_IDEFAULTANSICODEPAGE,
                                 chCodePage, sizeof(chCodePage)) == 0)
            return 0;
        lpCodePageStr = chCodePage;
    }
    else if (!strcmp(lpCodePageStr, "OCP"))
    {
        //  get OEM codepage for the country LCID
        if ((*pfnGetLocaleInfoA)(lcidCountry, LOCALE_IDEFAULTCODEPAGE,
                                 chCodePage, sizeof(chCodePage)) == 0)
            return 0;
        lpCodePageStr = chCodePage;
    }

    //  convert decimal string to numeric value
    return (int)atol(lpCodePageStr);
}

/***
*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)
{
    char    rgcInfo[120];
    LCID    lcidDefault = MAKELCID(MAKELANGID(PRIMARYLANGID(LANGIDFROMLCID(lcid)),
                                                  SUBLANG_DEFAULT), SORT_DEFAULT);

    if ((*pfnGetLocaleInfoA)(lcidDefault, LOCALE_ILANGUAGE, rgcInfo,
                                          sizeof(rgcInfo)) == 0)
        return FALSE;

    if (lcid != LcidFromHexString(rgcInfo))
    {
        //  test if string contains an implicit sublanguage by
        //  having a character other than upper/lowercase letters.
        if (bTestPrimary && GetPrimaryLen(pchLanguage) == (int)strlen(pchLanguage))
            return FALSE;
    }
    return TRUE;
}

/***
*BOOL IsThisWindowsNT(void) - operating system test
*
*Purpose:
*   Test whether CRT is running in Windows 95 or NT.
*
*Entry:
*   None.
*
*Exit:
*   Return TRUE if Windows NT, FALSE if Windows 95.
*
*Exceptions:
*
*******************************************************************************/
static BOOL IsThisWindowsNT (void)
{
    OSVERSIONINFO       osVersionInfo;

    osVersionInfo.dwOSVersionInfoSize = sizeof(osVersionInfo);

    return (GetVersionEx(&osVersionInfo)
                  && osVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
}

/***
*int crtGetLocalInfoA - get locale information for Win95
*
*Purpose:
*   For Win95, some calls to GetLocaleInfoA return incorrect results.
*       Simulate these calls with values looked up in a hard-coded table.
*
*Entry:
*       lcid - LCID of locale to get information from
*       lctype - index of information selection
*   lpdata - pointer to output string
*       cchdata - size of output string (including null)
*
*Exit:
*   lpdata - return string of locale information
*   returns TRUE if successful, else FALSE
*
*Exceptions:
*
*******************************************************************************/
static int __stdcall crtGetLocaleInfoA (LCID lcid, LCTYPE lctype, LPSTR lpdata,
                                                                  int cchdata)
{
    int     i;
    int     low = 0;
    int         high = sizeof(__rgLocInfo) / sizeof(RGLOCINFO) - 1;
    char *      pchResult = NULL;

    //  typical binary search - do until no more to search
    while (low <= high)
    {
        i = (low + high) / 2;
        if (lcid == __rgLocInfo[i].lcid)
        {
            //  LCID matched - test for valid LCTYPE to simulate call
            switch (lctype)
            {
                case LOCALE_ILANGUAGE:
                    pchResult = __rgLocInfo[i].chILanguage;
                    break;
                case LOCALE_SENGLANGUAGE:
                    pchResult = __rgLocInfo[i].pchSEngLanguage;
                    break;
                case LOCALE_SABBREVLANGNAME:
                    pchResult = __rgLocInfo[i].chSAbbrevLangName;
                    break;
                case LOCALE_SENGCOUNTRY:
                    pchResult = __rgLocInfo[i].pchSEngCountry;
                    break;
                case LOCALE_SABBREVCTRYNAME:
                    pchResult = __rgLocInfo[i].chSAbbrevCtryName;
                    break;
                case LOCALE_IDEFAULTCODEPAGE:
                    pchResult = __rgLocInfo[i].chIDefaultCodepage;
                    break;
                case LOCALE_IDEFAULTANSICODEPAGE:
                    pchResult = __rgLocInfo[i].chIDefaultAnsiCodepage;
                default:
                    break;
            }
            if (!pchResult || cchdata < 1)
                //      if LCTYPE did not match, break to use normal routine
                break;
            else
            {
                //      copy data as much as possible to result and null-terminate
                strncpy(lpdata, pchResult, cchdata - 1);
                *(lpdata + cchdata - 1) = '\0';
                return 1;
            }
        }
        else if (lcid < __rgLocInfo[i].lcid)
            high = i - 1;
        else
            low = i + 1;
    }
    //  LCID not found or LCTYPE not simulated
    return GetLocaleInfoA(lcid,lctype, lpdata, cchdata);
}


/***
*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 + -