mbinit.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 443 行 · 第 1/2 页
C
443 行
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include "variety.h"
#ifdef __NT__
#include <windows.h>
#include <winnls.h>
#elif defined __OS2__
#define INCL_DOSNLS
#include <wos2.h>
#elif defined __OSI__
#elif defined __DOS__
#include <dos.h>
#ifndef __386__
#include <i86.h>
#else
#include "dpmi.h"
#include "extender.h"
#endif
#elif defined __WINDOWS__
#include <windows.h>
#elif defined __LINUX__
#endif
#include <string.h>
#include <mbstring.h>
#include "mbchar.h"
#if defined(__DOS__) && !defined(__OSI__)
unsigned short _WCFAR * dos_get_dbcs_lead_table( void );
#endif
#if defined(__DOS__) || defined(__WINDOWS__)
unsigned short dos_get_code_page( void );
#endif
#ifdef __NT__
unsigned int __MBCodePage = CP_OEMCP; /* default code page */
#elif defined( __LINUX__ )
unsigned int __MBCodePage = 0; /* default code page */
#elif !defined(__UNIX__)
unsigned int __MBCodePage = 0; /* default code page */
#endif
static void set_dbcs_table( int low, int high )
{
memset( __MBCSIsTable + low + 1, _MB_LEAD, high - low + 1 );
}
static void clear_dbcs_table( void )
{
__IsDBCS = 0; /* SBCS for now */
__MBCodePage = 0;
memset( __MBCSIsTable, 0, 257 );
}
/****
***** Initialize a multi-byte character set. Returns 0 on success.
****/
int __mbinit( int codepage )
{
#ifdef __NT__
int countRange;
CPINFO cpInfo;
BOOL rc;
#elif defined __OS2__
int countRange;
COUNTRYCODE countryInfo;
unsigned char leadBytes[12];
APIRET rc;
OS_UINT buf[8];
OS_UINT bytes;
#elif defined __OSI__
#elif defined __DOS__
int countRange;
unsigned short _WCFAR * leadBytes;
unsigned char lowerBound, upperBound;
#elif defined __WINDOWS__
DWORD version;
int countVal;
#elif defined __LINUX__
#endif
/*** 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 ) {
clear_dbcs_table();
return( 0 );
} else if( codepage == _MBINIT_CP_932 ) {
clear_dbcs_table();
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 );
clear_dbcs_table();
if( cpInfo.LeadByte[0] ) __IsDBCS = 1; /* set __IsDBCS if needed */
for( countRange=0; !(cpInfo.LeadByte[countRange]==0x00 &&
cpInfo.LeadByte[countRange+1]==0x00); countRange+=2 ) {
set_dbcs_table( cpInfo.LeadByte[countRange],
cpInfo.LeadByte[countRange+1] );
}
/*** 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( 12, &countryInfo, leadBytes );
#else
rc = DosGetDBCSEv( 12, &countryInfo, leadBytes );
#endif
if( rc != 0 ) return( 1 );
clear_dbcs_table();
if( leadBytes[0] ) __IsDBCS = 1; /* set __IsDBCS if needed */
for( countRange=0; !(leadBytes[countRange]==0x00 &&
leadBytes[countRange+1]==0x00); countRange+=2 ) {
set_dbcs_table( leadBytes[countRange],
leadBytes[countRange+1] );
}
/*** 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 );
clear_dbcs_table();
if( leadBytes[0] )
__IsDBCS = 1; /* set __IsDBCS if needed */
for( countRange=0; leadBytes[countRange]!=0x0000; countRange++ ) {
lowerBound = (unsigned char) leadBytes[countRange];
upperBound = (unsigned char) (leadBytes[countRange] >> 8);
set_dbcs_table( lowerBound, upperBound );
}
__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 */
clear_dbcs_table();
for( countVal=0; countVal<256; countVal++ ) {
if( IsDBCSLeadByte( (BYTE)countVal ) ) {
__MBCSIsTable[countVal+1] = _MB_LEAD;
__IsDBCS = 1; /* set __IsDBCS if needed */
}
}
__MBCodePage = GetKBCodePage();
#elif defined __LINUX__
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?