Ejemplo n.º 1
0
/* Helper function to determine if we are running on DBCS */
BOOL IsDBCS()
{
    if (!bIsDBCSSet) {
        // the following lines of code determine whether the system is a DBCS country
        APIRET rc;
        COUNTRYCODE ctrycodeInfo = {0};
        CHAR        achDBCSInfo[12] = {0};                  // DBCS environmental vector
        ctrycodeInfo.country  = 0;                          // current country
        ctrycodeInfo.codepage = 0;                          // current codepage

        rc = DosQueryDBCSEnv(sizeof(achDBCSInfo), &ctrycodeInfo, achDBCSInfo);
        if (rc == NO_ERROR) {
            // Non-DBCS countries will have four bytes in the first four bytes of the
            // DBCS environmental vector
            if (achDBCSInfo[0] != 0 || achDBCSInfo[1] != 0 ||
                achDBCSInfo[2] != 0 || achDBCSInfo[3] != 0)
            {
                bIsDBCS = TRUE;
            } else {
                bIsDBCS = FALSE;
            }
        } else {
            bIsDBCS = FALSE;
        } /* endif */
        bIsDBCSSet = TRUE;
    } /* endif */
    return bIsDBCS;
}
Ejemplo n.º 2
0
BOOL nlsDBCS(VOID)
{
    APIRET arc;

    if (G_fDBCS != 2)
        // already queried:
        return G_fDBCS;

    // V0.9.20 (2002-07-03) [umoeller]
    // assume a non-DBCS system UNLESS the below
    // loop gives us something meaningful; even
    // on non-DBCS systems like mine, DosQueryDBCSEnv
    // does not return an error
    G_fDBCS = FALSE;

    if (!(arc = DosQueryDBCSEnv(8 * sizeof(DBCSVECTOR),
                                &G_cc,
                                (PCHAR)G_aDBCSVector)))
    {
        int i;
        for (i = 0;
             i < 8;
             ++i)
        {
            if (    (G_aDBCSVector[i].bLow)
                 && (G_aDBCSVector[i].bHigh)
               )
            {
                int n;
                for (n = G_aDBCSVector[i].bLow;
                     n <= G_aDBCSVector[i].bHigh;
                     ++n)
                    G_afLeadByte[n] = TRUE;

                G_fDBCS = TRUE;
            }
            else
                break;
        }
    }

    return G_fDBCS;
}
Ejemplo n.º 3
0
/* Helper function to determine if we are running on DBCS */
static bool
IsDBCS()
{
  if (!bIsDBCSSet) {
    APIRET rc;
    COUNTRYCODE ctrycodeInfo = {0};
    CHAR        achDBCSInfo[12] = {0};  // DBCS environmental vector
    ctrycodeInfo.country  = 0;          // current country
    ctrycodeInfo.codepage = 0;          // current codepage

    rc = DosQueryDBCSEnv(sizeof(achDBCSInfo), &ctrycodeInfo, achDBCSInfo);
    if (rc == NO_ERROR) {
      // DBCS countries will have at least one nonzero byte in the
      // first four bytes of the DBCS environmental vector
      bIsDBCS = (achDBCSInfo[0] != 0 || achDBCSInfo[1] != 0 ||
                 achDBCSInfo[2] != 0 || achDBCSInfo[3] != 0);
    } else {
      bIsDBCS = false;
    }
    bIsDBCSSet = true;
  }
  return bIsDBCS;
}
Ejemplo n.º 4
0
int __mbinit( int codepage )
{
#ifdef __NT__
    CPINFO                  cpInfo;
    BOOL                    rc;
#elif defined __OS2__
    COUNTRYCODE             countryInfo;
    unsigned short          leadBytes[6];
    APIRET                  rc;
    OS_UINT                 buf[8];
    OS_UINT                 bytes;
#elif defined __OSI__
#elif defined __DOS__
    unsigned short          __far *leadBytes;
#elif defined __WINDOWS__
    DWORD                   version;
#elif defined __LINUX__
#elif defined __RDOS__
#endif

    clear_dbcs_table();
    /*** Handle values from _setmbcp ***/
    if( codepage == _MBINIT_CP_ANSI ) {
#ifdef __NT__
        codepage = GetACP();
#else
        codepage = 0;
#endif
    } else if( codepage == _MBINIT_CP_OEM ) {
#ifdef __NT__
        codepage = GetOEMCP();
#else
        codepage = 0;
#endif
    } else if( codepage == _MBINIT_CP_SBCS ) {
        return( 0 );
    } else if( codepage == _MBINIT_CP_932 ) {
        _set_dbcs_table( 0x81, 0x9F );
        _set_dbcs_table( 0xE0, 0xFC );
        __IsDBCS = 1;
        __MBCodePage = 932;
        return( 0 );
    }

#ifdef __NT__
    /*** Initialize the __MBCSIsTable values ***/
    if( codepage == 0 )
        codepage = CP_OEMCP;
    rc = GetCPInfo( codepage, &cpInfo );    /* get code page info */
    if( rc == FALSE )
        return( 1 );
    set_dbcs_table( (unsigned short *)cpInfo.LeadByte );
    /*** Update __MBCodePage ***/
    if( codepage == CP_OEMCP ) {
        __MBCodePage = GetOEMCP();
    } else {
        __MBCodePage = codepage;
    }
#elif defined __OS2__
    /*** Initialize the __MBCSIsTable values ***/
    countryInfo.country = 0;                /* default country */
    countryInfo.codepage = codepage;        /* specified code page */
  #if defined(__WARP__)
    rc = DosQueryDBCSEnv( sizeof( leadBytes ), &countryInfo, (PCHAR)leadBytes );
  #else
    rc = DosGetDBCSEv( sizeof( leadBytes ), &countryInfo, (PCHAR)leadBytes );
  #endif
    if( rc != 0 )
        return( 1 );
    set_dbcs_table( leadBytes );
    /*** Update __MBCodePage ***/
    if( codepage == 0 ) {
  #if defined(__386__) || defined(__PPC__)
        rc = DosQueryCp( sizeof( buf ), &buf, &bytes );
  #else
        rc = DosGetCp( sizeof( buf ), &buf, &bytes );
  #endif
        if( rc != 0 ) {
            __MBCodePage = 0;
        } else {
            __MBCodePage = (unsigned int)buf[0];
        }
    } else {
        __MBCodePage = codepage;
    }
#elif defined __OSI__
#elif defined __DOS__
    /*** Initialize the __MBCSIsTable values ***/
    if( codepage != 0 )
        return( 1 );        /* can only handle default */
    leadBytes = dos_get_dbcs_lead_table();
    if( leadBytes == NULL )
        return( 0 );
    set_dbcs_table( leadBytes );
    __MBCodePage = dos_get_code_page();
#elif defined __WINDOWS__
    /*** Initialize the __MBCSIsTable values ***/
    if( codepage != 0 )
        return( 1 );        /* can only handle default */
    version = GetVersion();
    if( LOWORD(version) < 0x0A03 )
        return( 1 );        /* 3.1+ needed */
    set_dbcs_table();
    __MBCodePage = GetKBCodePage();
#elif defined __LINUX__
#elif defined __RDOS__
#endif
    return( 0 );                                /* return success code */
}
Ejemplo n.º 5
0
static void MBInit( void )
/************************/
{
#if defined( __NT__ ) && !defined( __UNIX__ )
    int                 countRange, countVal;
    CPINFO              cpInfo;
    BOOL                rc;
#elif defined __OS2__ || defined __OS2_PM__
    int                 countRange, countVal;
    COUNTRYCODE         countryInfo;
    CHAR                leadBytes[12];
  #ifdef _M_I86
        USHORT          rc;
  #else
        APIRET          rc;
  #endif
#elif defined( __WINDOWS__ ) || defined( __UNIX__ )
    int                 countVal;
    DWORD               version;
#endif

    memset( __CharLenTable, 1, sizeof( __CharLenTable ) );              /* zero table to start */

    #if defined( __NT__) && !defined( __UNIX__ )
        /*** Initialize the __CharLenTable values ***/
        rc = GetCPInfo( CP_OEMCP, &cpInfo );    /* get code page info */
        if( rc == FALSE )  return;
        for( countRange=0; !(cpInfo.LeadByte[countRange]==0x00 &&
             cpInfo.LeadByte[countRange+1]==0x00); countRange+=2 ) {
            for( countVal=cpInfo.LeadByte[countRange];
                 countVal<=cpInfo.LeadByte[countRange+1]; countVal++) {
                __CharLenTable[countVal] = 2;
                IsDBCS = TRUE;
            }
        }
    #elif defined __OS2__ || defined __OS2_PM__
        /*** Initialize the __CharLenTable values ***/
        countryInfo.country = 0;                /* default country */
        countryInfo.codepage = 0;       /* specified code page */
      #ifdef _M_I86
        rc = DosGetDBCSEv( 12, &countryInfo, leadBytes );
      #else
        rc = DosQueryDBCSEnv( 12, &countryInfo, leadBytes );
      #endif
        if( rc != 0 )  return;
        for( countRange=0; !(leadBytes[countRange]==0x00 &&
             leadBytes[countRange+1]==0x00); countRange+=2 ) {
            for( countVal=leadBytes[countRange];
                 countVal<=leadBytes[countRange+1]; countVal++) {
                __CharLenTable[countVal] = 2;
                IsDBCS = TRUE;
            }
        }
    #elif defined( __WINDOWS__ ) || defined( __UNIX__ )
        /*** Initialize the __CharLenTable values ***/
        version = GetVersion();
        if( LOWORD(version) < ((10<<8)+3) )  return;   /* 3.1+ needed */
        for( countVal=0; countVal<256; countVal++ ) {
            if( IsDBCSLeadByte( (BYTE)countVal ) ) {
                __CharLenTable[countVal] = 2;
                IsDBCS = TRUE;
            }
        }
    #endif

}