📄 mbctype.c
字号:
/***
*mbctype.c - MBCS table used by the functions that test for types of char
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* table used to determine the type of char
*
*******************************************************************************/
#ifdef _MBCS
#include <windows.h>
#include <sect_attribs.h>
#include <cruntime.h>
#include <dbgint.h>
#include <mbdata.h>
#include <mbctype.h>
#include <mtdll.h>
#include <stdlib.h>
#include <stdio.h>
#include <internal.h>
#include <locale.h>
#include <setlocal.h>
#include <awint.h>
#include <rterr.h>
#ifndef CRTDLL
extern "C" int __cdecl __initmbctable(void);
/*
* Flag to ensure multibyte ctype table is only initialized once
*/
extern "C" int __mbctype_initialized;
_CRTALLOC(".CRT$XIC") static _PIFV pinit = __initmbctable;
#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;
extern "C"
{
threadmbcinfo __initialmbcinfo =
{
0,
_CLOCALECP, /* _MB_CP_ANSI */
0,
0,
{ 0, 0, 0, 0, 0, 0 },
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00 /* rest is zero */
},
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,
0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00 /* rest is zero */
}
};
/* MBCS ctype array */
unsigned char _mbctype[NUM_CHARS] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00 /* rest is zero */
};
unsigned char _mbcasemap[256] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,
0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00 /* rest is zero */
};
/* global variable to indicate current code page */
int __mbcodepage = _CLOCALECP; /* __initialmbcinfo.mbcodepage; */
/* global flag indicating if current code page is a multibyte code page */
int __ismbcodepage = 0; /*__initialmbcinfo.ismbcodepage; */
/* global variable to indicate current LCID */
int __mblcid = 0; /* __initialmbcinfo.mblcid; */
/* global variable to indicate current full-width-latin upper/lower info */
unsigned short __mbulinfo[NUM_ULINFO]; /* __initialmbcinfo.mbulinfo */
/* global pointer to the current per-thread mbc information structure. */
pthreadmbcinfo __ptmbcinfo = &__initialmbcinfo;
}
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 */
}
}
};
extern "C" int __cdecl _setmbcp_nolock(int, pthreadmbcinfo);
/***
*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)
{
_locale_t plocinfo = NULL;
_LocaleUpdate _loc_update(plocinfo);
fSystemSet = 0;
/* get system code page values if requested */
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(_loc_update.GetLocaleT()->locinfo);
}
return codepage;
}
/***
*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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -