?? mbctype.c
字號:
/***
*mbctype.c - MBCS table used by the functions that test for types of char
*
* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
*
*Purpose:
* table used to determine the type of char
*
*******************************************************************************/
#ifdef _MBCS
#if defined (_WIN32)
#include <windows.h>
#else /* defined (_WIN32) */
#include <fltintrn.h>
#endif /* defined (_WIN32) */
#include <mtdll.h>
#include <cruntime.h>
#include <mbdata.h>
#include <mbctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <internal.h>
#if defined (_WIN32)
#include <setlocal.h>
#endif /* defined (_WIN32) */
#if defined (_WIN32)
#include <awint.h>
#endif /* defined (_WIN32) */
#ifdef _MAC
#include <macos\language.h>
#include <macos\script.h>
void __cdecl __initmbctable(void);
#pragma data_seg(".CRT$XIC")
const PFV __pinitmbctable = __initmbctable;
#pragma data_seg()
static short tmpScriptID;
static short mbScriptID;
#endif /* _MAC */
#ifndef CRTDLL
void __cdecl __initmbctable(void);
/*
* Flag to ensure multibyte ctype table is only initialized once
*/
extern int __mbctype_initialized;
#pragma data_seg(".CRT$XIC")
static _PVFV pinit = __initmbctable;
#pragma data_seg()
#endif /* CRTDLL */
#define _CHINESE_SIMP_CP 936
#define _KOREAN_WANGSUNG_CP 949
#define _CHINESE_TRAD_CP 950
#define _KOREAN_JOHAB_CP 1361
#define NUM_CHARS 257 /* -1 through 255 */
#define NUM_CTYPES 4 /* table contains 4 types of info */
#define MAX_RANGES 8 /* max number of ranges needed given languages so far */
/* character type info in ranges (pair of low/high), zeros indicate end */
typedef struct
{
int code_page;
unsigned short mbulinfo[NUM_ULINFO];
unsigned char rgrange[NUM_CTYPES][MAX_RANGES];
} code_page_info;
/* MBCS ctype array */
unsigned char _mbctype[NUM_CHARS];
unsigned char _mbcasemap[256];
/* global variable to indicate current code page */
int __mbcodepage;
/* global flag indicating if current code page is a multibyte code page */
int __ismbcodepage;
#ifdef _WIN32
/* global variable to indicate current LCID */
int __mblcid;
#endif /* _WIN32 */
/* global variable to indicate current full-width-latin upper/lower info */
unsigned short __mbulinfo[NUM_ULINFO];
static int fSystemSet;
static char __rgctypeflag[NUM_CTYPES] = { _MS, _MP, _M1, _M2 };
static code_page_info __rgcode_page_info[] =
{
{
_KANJI_CP, /* Kanji (Japanese) Code Page */
{ 0x8260, 0x8279, /* Full-Width Latin Upper Range 1 */
0x8281 - 0x8260, /* Full-Width Latin Case Difference 1 */
0x0000, 0x0000, /* Full-Width Latin Upper Range 2 */
0x0000 /* Full-Width Latin Case Difference 2 */
#ifndef _WIN32
,
0x8281, 0x829A, /* Full-Width Latin Lower Range 1 */
0x0000, 0x0000, /* Full-Width Latin Lower Range 2 */
0x824F, 0x8258 /* Full-Width Latin Digit Range */
#endif /* _WIN32 */
},
{
{ 0xA6, 0xDF, 0, 0, 0, 0, 0, 0, }, /* Single Byte Ranges */
{ 0xA1, 0xA5, 0, 0, 0, 0, 0, 0, }, /* Punctuation Ranges */
{ 0x81, 0x9F, 0xE0, 0xFC, 0, 0, 0, 0, }, /* Lead Byte Ranges */
{ 0x40, 0x7E, 0x80, 0xFC, 0, 0, 0, 0, }, /* Trail Byte Ranges */
}
},
{
_CHINESE_SIMP_CP, /* Chinese Simplified (PRC) Code Page */
{ 0xA3C1, 0xA3DA, /* Full-Width Latin Upper Range 1 */
0xA3E1 - 0xA3C1, /* Full-Width Latin Case Difference 1 */
0x0000, 0x0000, /* Full-Width Latin Upper Range 2 */
0x0000 /* Full-Width Latin Case Difference 2 */
#ifndef _WIN32
,
0xA3E1, 0xA3FA, /* Full-Width Latin Lower Range 1 */
0x0000, 0x0000, /* Full-Width Latin Lower Range 2 */
0xA3B0, 0xA3B9 /* Full-Width Latin Digit Range */
#endif /* _WIN32 */
},
{
{ 0, 0, 0, 0, 0, 0, 0, 0, }, /* Single Byte Ranges */
{ 0, 0, 0, 0, 0, 0, 0, 0, }, /* Punctuation Ranges */
{ 0x81, 0xFE, 0, 0, 0, 0, 0, 0, }, /* Lead Byte Ranges */
{ 0x40, 0xFE, 0, 0, 0, 0, 0, 0, }, /* Trail Byte Ranges */
}
},
{
_KOREAN_WANGSUNG_CP, /* Wangsung (Korean) Code Page */
{ 0xA3C1, 0xA3DA, /* Full-Width Latin Upper Range 1 */
0xA3E1 - 0xA3C1, /* Full-Width Latin Case Difference 1 */
0x0000, 0x0000, /* Full-Width Latin Upper Range 2 */
0x0000 /* Full-Width Latin Case Difference 2 */
#ifndef _WIN32
,
0xA3E1, 0xA3FA, /* Full-Width Latin Lower Range 1 */
0x0000, 0x0000, /* Full-Width Latin Lower Range 2 */
0xA3B0, 0xA3B9 /* Full-Width Latin Digit Range */
#endif /* _WIN32 */
},
{
{ 0, 0, 0, 0, 0, 0, 0, 0, }, /* Single Byte Ranges */
{ 0, 0, 0, 0, 0, 0, 0, 0, }, /* Punctuation Ranges */
{ 0x81, 0xFE, 0, 0, 0, 0, 0, 0, }, /* Lead Byte Ranges */
{ 0x41, 0xFE, 0, 0, 0, 0, 0, 0, }, /* Trail Byte Ranges */
}
},
{
_CHINESE_TRAD_CP, /* Chinese Traditional (Taiwan) Code Page */
{ 0xA2CF, 0xA2E4, /* Full-Width Latin Upper Range 1 */
0xA2E9 - 0xA2CF, /* Full-Width Latin Case Difference 1 */
0xA2E5, 0xA2E8, /* Full-Width Latin Upper Range 2 */
0xA340 - 0XA2E5 /* Full-Width Latin Case Difference 2 */
#ifndef _WIN32
,
0xA2E9, 0xA2FE, /* Full-Width Latin Lower Range 1 */
0xA340, 0xA343, /* Full-Width Latin Lower Range 2 */
0xA2AF, 0xA2B8 /* Full-Width Latin Digit Range */
#endif /* _WIN32 */
},
{
{ 0, 0, 0, 0, 0, 0, 0, 0, }, /* Single Byte Ranges */
{ 0, 0, 0, 0, 0, 0, 0, 0, }, /* Punctuation Ranges */
{ 0x81, 0xFE, 0, 0, 0, 0, 0, 0, }, /* Lead Byte Ranges */
{ 0x40, 0x7E, 0xA1, 0xFE, 0, 0, 0, 0, }, /* Trail Byte Ranges */
}
},
{
_KOREAN_JOHAB_CP, /* Johab (Korean) Code Page */
{ 0xDA51, 0xDA5E, /* Full-Width Latin Upper Range 1 */
0xDA71 - 0xDA51, /* Full-Width Latin Case Difference 1 */
0xDA5F, 0xDA6A, /* Full-Width Latin Upper Range 2 */
0xDA91 - 0xDA5F /* Full-Width Latin Case Difference 2 */
#ifndef _WIN32
,
0xDA71, 0xDA7E, /* Full-Width Latin Lower Range 1 */
0xDA91, 0xDA9C, /* Full-Width Latin Lower Range 2 */
0xDA40, 0xDA49 /* Full-Width Latin Digit Range */
#endif /* _WIN32 */
},
{
{ 0, 0, 0, 0, 0, 0, 0, 0, }, /* Single Byte Ranges */
{ 0, 0, 0, 0, 0, 0, 0, 0, }, /* Punctuation Ranges */
{ 0x81, 0xD3, 0xD8, 0xDE, 0xE0, 0xF9, 0, 0, }, /* Lead Byte Ranges */
{ 0x31, 0x7E, 0x81, 0xFE, 0, 0, 0, 0, }, /* Trail Byte Ranges */
}
}
};
/***
*getSystemCP - Get system default CP if requested.
*
*Purpose:
* Get system default CP if requested.
*
*Entry:
* codepage - user requested code page/world script
*Exit:
* requested code page
*
*Exceptions:
*
*******************************************************************************/
static int getSystemCP (int codepage)
{
#ifdef _WIN32
/* get system code page values if requested */
fSystemSet = 0;
if (codepage == _MB_CP_OEM)
{
fSystemSet = 1;
return GetOEMCP();
}
else if (codepage == _MB_CP_ANSI)
{
fSystemSet = 1;
return GetACP();
}
else
if (codepage == _MB_CP_LOCALE)
{
fSystemSet = 1;
return __lc_codepage;
}
return codepage;
#endif /* _WIN32 */
#ifdef _MAC
tmpScriptID = 0;
fSystemSet = 0;
/* get system Script ID */
if (codepage == _MB_CP_OEM || codepage == _MB_CP_ANSI)
{
fSystemSet = 1;
tmpScriptID = (short) GetEnvirons(smSysScript);
}
/* or convert user Script ID */
else if (codepage > 0 && codepage < 32)
tmpScriptID = (short) codepage;
if (tmpScriptID)
{
switch (tmpScriptID) {
case smJapanese:
return _KANJI_CP;
case smKorean:
return _KOREAN_WANGSUNG_CP;
case smTradChinese:
return _CHINESE_TRAD_CP;
case smSimpChinese:
return _CHINESE_SIMP_CP;
default:
tmpScriptID = 0;
}
}
return codepage;
#endif /* _MAC */
}
#ifdef _WIN32
/***
*CPtoLCID() - Code page to LCID.
*
*Purpose:
* Some API calls want an LCID, so convert MB CP to appropriate LCID,
* and then API converts back to ANSI CP for that LCID.
*
*Entry:
* codepage - code page to convert
*Exit:
* returns appropriate LCID
*
*Exceptions:
*
*******************************************************************************/
static int CPtoLCID (int codepage)
{
switch (codepage) {
case 932:
return MAKELCID(MAKELANGID(LANG_JAPANESE,SUBLANG_DEFAULT),
SORT_DEFAULT);
case 936:
return MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),
SORT_DEFAULT);
case 949:
return MAKELCID(MAKELANGID(LANG_KOREAN,SUBLANG_DEFAULT),
SORT_DEFAULT);
case 950:
return MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_TRADITIONAL),
SORT_DEFAULT);
}
return 0;
}
#endif /* _WIN32 */
/***
*setSBCS() - Set MB code page to SBCS.
*
*Purpose:
* Set MB code page to SBCS.
*Entry:
*
*Exit:
*
*Exceptions:
*
*******************************************************************************/
static void setSBCS (void)
{
int i;
/* set for single-byte code page */
for (i = 0; i < NUM_CHARS; i++)
_mbctype[i] = 0;
/* code page has changed, set global flag */
__mbcodepage = 0;
/* clear flag to indicate single-byte code */
__ismbcodepage = 0;
#ifdef _WIN32
__mblcid = 0;
#endif /* _WIN32 */
for (i = 0; i < NUM_ULINFO; i++)
__mbulinfo[i] = 0;
}
/***
*setSBUpLow() - Set single byte upper/lower mappings
*
*Purpose:
* Set single byte mapping for tolower/toupper.
*Entry:
*
*Exit:
*
*Exceptions:
*
*******************************************************************************/
static void setSBUpLow (void)
{
#ifdef _WIN32
BYTE * pbPair;
UINT ich;
CPINFO cpinfo;
UCHAR sbVector[256];
UCHAR upVector[256];
UCHAR lowVector[256];
USHORT wVector[256];
// test if codepage exists
if (GetCPInfo(__mbcodepage, &cpinfo) == TRUE)
{
// if so, create vector 0-255
for (ich = 0; ich < 256; ich++)
sbVector[ich] = (UCHAR) ich;
// set byte 0 and any leading byte value to non-alpha char ' '
sbVector[0] = (UCHAR)' ';
for (pbPair = &cpinfo.LeadByte[0]; *pbPair; pbPair += 2)
for (ich = *pbPair; ich <= *(pbPair + 1); ich++)
sbVector[ich] = (UCHAR)' ';
// get char type for character vector
__crtGetStringTypeA(CT_CTYPE1, sbVector, 256, wVector,
__mbcodepage, __mblcid, FALSE);
// get lower case mappings for character vector
__crtLCMapStringA(__mblcid, LCMAP_LOWERCASE, sbVector, 256,
lowVector, 256, __mbcodepage, FALSE);
// get upper case mappings for character vector
__crtLCMapStringA(__mblcid, LCMAP_UPPERCASE, sbVector, 256,
upVector, 256, __mbcodepage, FALSE);
// set _SBUP, _SBLOW in _mbctype if type is upper. lower
// set mapping array with lower or upper mapping value
for (ich = 0; ich < 256; ich++)
if (wVector[ich] & _UPPER)
{
_mbctype[ich + 1] |= _SBUP;
_mbcasemap[ich] = lowVector[ich];
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -