📄 unicode.c
字号:
0x68, 0x2C, 0x1E29}, {
0x4B, 0x27, 0x1E30}, {
0x6B, 0x27, 0x1E31}, {
0x4D, 0x27, 0x1E3E}, {
0x6D, 0x27, 0x1E3F}, {
0x50, 0x27, 0x1E54}, {
0x70, 0x27, 0x1E55}, {
0x56, 0x7E, 0x1E7C}, {
0x76, 0x7E, 0x1E7D}, {
0x57, 0x60, 0x1E80}, {
0x77, 0x60, 0x1E81}, {
0x57, 0x27, 0x1E82}, {
0x77, 0x27, 0x1E83}, {
0x57, 0x22, 0x1E84}, {
0x77, 0x22, 0x1E85}, {
0x58, 0x22, 0x1E8C}, {
0x78, 0x22, 0x1E8D}, {
0x5A, 0x5E, 0x1E90}, {
0x7A, 0x5E, 0x1E91}, {
0x74, 0x22, 0x1E97}, {
0x77, 0x2A, 0x1E98}, {
0x79, 0x2A, 0x1E99}, {
0x45, 0x7E, 0x1EBC}, {
0x65, 0x7E, 0x1EBD}, {
0x59, 0x60, 0x1EF2}, {
0x79, 0x60, 0x1EF3}, {
0x59, 0x7E, 0x1EF8}, {
0x79, 0x7E, 0x1EF9},
/* Compatible/possibles from UCS */
{
0x49, 0x4A, 0x0132}, {
0x69, 0x6A, 0x0133}, {
0x4C, 0x4A, 0x01C7}, {
0x4C, 0x6A, 0x01C8}, {
0x6C, 0x6A, 0x01C9}, {
0x4E, 0x4A, 0x01CA}, {
0x4E, 0x6A, 0x01CB}, {
0x6E, 0x6A, 0x01CC}, {
0x44, 0x5A, 0x01F1}, {
0x44, 0x7A, 0x01F2}, {
0x64, 0x7A, 0x01F3}, {
0x2E, 0x2E, 0x2025}, {
0x21, 0x21, 0x203C}, {
0x3F, 0x21, 0x2048}, {
0x21, 0x3F, 0x2049}, {
0x52, 0x73, 0x20A8}, {
0x4E, 0x6F, 0x2116}, {
0x53, 0x4D, 0x2120}, {
0x54, 0x4D, 0x2122}, {
0x49, 0x49, 0x2161}, {
0x49, 0x56, 0x2163}, {
0x56, 0x49, 0x2165}, {
0x49, 0x58, 0x2168}, {
0x58, 0x49, 0x216A}, {
0x69, 0x69, 0x2171}, {
0x69, 0x76, 0x2173}, {
0x76, 0x69, 0x2175}, {
0x69, 0x78, 0x2178}, {
0x78, 0x69, 0x217A}, {
0x31, 0x30, 0x2469}, {
0x31, 0x31, 0x246A}, {
0x31, 0x32, 0x246B}, {
0x31, 0x33, 0x246C}, {
0x31, 0x34, 0x246D}, {
0x31, 0x35, 0x246E}, {
0x31, 0x36, 0x246F}, {
0x31, 0x37, 0x2470}, {
0x31, 0x38, 0x2471}, {
0x31, 0x39, 0x2472}, {
0x32, 0x30, 0x2473}, {
0x31, 0x2E, 0x2488}, {
0x32, 0x2E, 0x2489}, {
0x33, 0x2E, 0x248A}, {
0x34, 0x2E, 0x248B}, {
0x35, 0x2E, 0x248C}, {
0x36, 0x2E, 0x248D}, {
0x37, 0x2E, 0x248E}, {
0x38, 0x2E, 0x248F}, {
0x39, 0x2E, 0x2490}, {
0x64, 0x61, 0x3372}, {
0x41, 0x55, 0x3373}, {
0x6F, 0x56, 0x3375}, {
0x70, 0x63, 0x3376}, {
0x70, 0x41, 0x3380}, {
0x6E, 0x41, 0x3381}, {
0x6D, 0x41, 0x3383}, {
0x6B, 0x41, 0x3384}, {
0x4B, 0x42, 0x3385}, {
0x4D, 0x42, 0x3386}, {
0x47, 0x42, 0x3387}, {
0x70, 0x46, 0x338A}, {
0x6E, 0x46, 0x338B}, {
0x6D, 0x67, 0x338E}, {
0x6B, 0x67, 0x338F}, {
0x48, 0x7A, 0x3390}, {
0x66, 0x6D, 0x3399}, {
0x6E, 0x6D, 0x339A}, {
0x6D, 0x6D, 0x339C}, {
0x63, 0x6D, 0x339D}, {
0x6B, 0x6D, 0x339E}, {
0x50, 0x61, 0x33A9}, {
0x70, 0x73, 0x33B0}, {
0x6E, 0x73, 0x33B1}, {
0x6D, 0x73, 0x33B3}, {
0x70, 0x56, 0x33B4}, {
0x6E, 0x56, 0x33B5}, {
0x6D, 0x56, 0x33B7}, {
0x6B, 0x56, 0x33B8}, {
0x4D, 0x56, 0x33B9}, {
0x70, 0x57, 0x33BA}, {
0x6E, 0x57, 0x33BB}, {
0x6D, 0x57, 0x33BD}, {
0x6B, 0x57, 0x33BE}, {
0x4D, 0x57, 0x33BF}, {
0x42, 0x71, 0x33C3}, {
0x63, 0x63, 0x33C4}, {
0x63, 0x64, 0x33C5}, {
0x64, 0x42, 0x33C8}, {
0x47, 0x79, 0x33C9}, {
0x68, 0x61, 0x33CA}, {
0x48, 0x50, 0x33CB}, {
0x69, 0x6E, 0x33CC}, {
0x4B, 0x4B, 0x33CD}, {
0x4B, 0x4D, 0x33CE}, {
0x6B, 0x74, 0x33CF}, {
0x6C, 0x6D, 0x33D0}, {
0x6C, 0x6E, 0x33D1}, {
0x6C, 0x78, 0x33D3}, {
0x6D, 0x62, 0x33D4}, {
0x50, 0x48, 0x33D7}, {
0x50, 0x52, 0x33DA}, {
0x73, 0x72, 0x33DB}, {
0x53, 0x76, 0x33DC}, {
0x57, 0x62, 0x33DD}, {
0x66, 0x66, 0xFB00}, {
0x66, 0x69, 0xFB01}, {
0x66, 0x6C, 0xFB02}, {
0x73, 0x74, 0xFB06}, {
0, 0, 0}
}, *c;
int nc = -1;
for (c = composetbl; c->first; c++) {
if (c->first == first && c->second == second)
return c->composed;
}
if (recurse == 0) {
nc = check_compose_internal(second, first, 1);
if (nc == -1)
nc = check_compose_internal(toupper(first), toupper(second), 1);
if (nc == -1)
nc = check_compose_internal(toupper(second), toupper(first), 1);
}
return nc;
}
int check_compose(int first, int second)
{
return check_compose_internal(first, second, 0);
}
int decode_codepage(char *cp_name)
{
char *s, *d;
const struct cp_list_item *cpi;
int codepage = -1;
CPINFO cpinfo;
if (!*cp_name) {
/*
* Here we select a plausible default code page based on
* the locale the user is in. We wish to select an ISO code
* page or appropriate local default _rather_ than go with
* the Win125* series, because it's more important to have
* CSI and friends enabled by default than the ghastly
* Windows extra quote characters, and because it's more
* likely the user is connecting to a remote server that
* does something Unixy or VMSy and hence standards-
* compliant than that they're connecting back to a Windows
* box using horrible nonstandard charsets.
*
* Accordingly, Robert de Bath suggests a method for
* picking a default character set that runs as follows:
* first call GetACP to get the system's ANSI code page
* identifier, and translate as follows:
*
* 1250 -> ISO 8859-2
* 1251 -> KOI8-U
* 1252 -> ISO 8859-1
* 1253 -> ISO 8859-7
* 1254 -> ISO 8859-9
* 1255 -> ISO 8859-8
* 1256 -> ISO 8859-6
* 1257 -> ISO 8859-13 (changed from 8859-4 on advice of a Lithuanian)
*
* and for anything else, choose direct-to-font.
*/
int cp = GetACP();
switch (cp) {
case 1250: cp_name = "ISO-8859-2"; break;
case 1251: cp_name = "KOI8-U"; break;
case 1252: cp_name = "ISO-8859-1"; break;
case 1253: cp_name = "ISO-8859-7"; break;
case 1254: cp_name = "ISO-8859-9"; break;
case 1255: cp_name = "ISO-8859-8"; break;
case 1256: cp_name = "ISO-8859-6"; break;
case 1257: cp_name = "ISO-8859-13"; break;
/* default: leave it blank, which will select -1, direct->font */
}
}
if (cp_name && *cp_name)
for (cpi = cp_list; cpi->name; cpi++) {
s = cp_name;
d = cpi->name;
for (;;) {
while (*s && !isalnum(*s) && *s != ':')
s++;
while (*d && !isalnum(*d) && *d != ':')
d++;
if (*s == 0) {
codepage = cpi->codepage;
if (codepage == CP_UTF8)
goto break_break;
if (codepage == -1)
return codepage;
if (codepage == 0) {
codepage = 65536 + (cpi - cp_list);
goto break_break;
}
if (GetCPInfo(codepage, &cpinfo) != 0)
goto break_break;
}
if (tolower(*s++) != tolower(*d++))
break;
}
}
if (cp_name && *cp_name) {
d = cp_name;
if (tolower(d[0]) == 'c' && tolower(d[1]) == 'p')
d += 2;
if (tolower(d[0]) == 'i' && tolower(d[1]) == 'b'
&& tolower(d[1]) == 'm')
d += 3;
for (s = d; *s >= '0' && *s <= '9'; s++);
if (*s == 0 && s != d)
codepage = atoi(d); /* CP999 or IBM999 */
if (codepage == CP_ACP)
codepage = GetACP();
if (codepage == CP_OEMCP)
codepage = GetOEMCP();
if (codepage > 65535)
codepage = -2;
}
break_break:;
if (codepage != -1) {
if (codepage != CP_UTF8 && codepage < 65536) {
if (GetCPInfo(codepage, &cpinfo) == 0) {
codepage = -2;
} else if (cpinfo.MaxCharSize > 1)
codepage = -3;
}
}
if (codepage == -1 && *cp_name)
codepage = -2;
return codepage;
}
const char *cp_name(int codepage)
{
const struct cp_list_item *cpi, *cpno;
static char buf[32];
if (codepage == -1) {
sprintf(buf, "Use font encoding");
return buf;
}
if (codepage > 0 && codepage < 65536)
sprintf(buf, "CP%03d", codepage);
else
*buf = 0;
if (codepage >= 65536) {
cpno = 0;
for (cpi = cp_list; cpi->name; cpi++)
if (cpi == cp_list + (codepage - 65536)) {
cpno = cpi;
break;
}
if (cpno)
for (cpi = cp_list; cpi->name; cpi++) {
if (cpno->cp_table == cpi->cp_table)
return cpi->name;
}
} else {
for (cpi = cp_list; cpi->name; cpi++) {
if (codepage == cpi->codepage)
return cpi->name;
}
}
return buf;
}
/*
* Return the nth code page in the list, for use in the GUI
* configurer.
*/
const char *cp_enumerate(int index)
{
if (index < 0 || index >= lenof(cp_list))
return NULL;
return cp_list[index].name;
}
void get_unitab(int codepage, wchar_t * unitab, int ftype)
{
char tbuf[4];
int i, max = 256, flg = MB_ERR_INVALID_CHARS;
if (ftype)
flg |= MB_USEGLYPHCHARS;
if (ftype == 2)
max = 128;
if (codepage == CP_UTF8) {
for (i = 0; i < max; i++)
unitab[i] = i;
return;
}
if (codepage == CP_ACP)
codepage = GetACP();
else if (codepage == CP_OEMCP)
codepage = GetOEMCP();
if (codepage > 0 && codepage < 65536) {
for (i = 0; i < max; i++) {
tbuf[0] = i;
if (mb_to_wc(codepage, flg, tbuf, 1, unitab + i, 1)
!= 1)
unitab[i] = 0xFFFD;
}
} else {
int j = 256 - cp_list[codepage & 0xFFFF].cp_size;
for (i = 0; i < max; i++)
unitab[i] = i;
for (i = j; i < max; i++)
unitab[i] = cp_list[codepage & 0xFFFF].cp_table[i - j];
}
}
int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen,
char *mbstr, int mblen, char *defchr, int *defused,
struct unicode_data *ucsdata)
{
char *p;
int i;
if (ucsdata && codepage == ucsdata->line_codepage && ucsdata->uni_tbl) {
/* Do this by array lookup if we can. */
if (wclen < 0) {
for (wclen = 0; wcstr[wclen++] ;); /* will include the NUL */
}
for (p = mbstr, i = 0; i < wclen; i++) {
wchar_t ch = wcstr[i];
int by;
char *p1;
if (ucsdata->uni_tbl && (p1 = ucsdata->uni_tbl[(ch >> 8) & 0xFF])
&& (by = p1[ch & 0xFF]))
*p++ = by;
else if (ch < 0x80)
*p++ = (char) ch;
else if (defchr) {
int j;
for (j = 0; defchr[j]; j++)
*p++ = defchr[j];
if (defused) *defused = 1;
}
#if 1
else
*p++ = '.';
#endif
assert(p - mbstr < mblen);
}
return p - mbstr;
} else
return WideCharToMultiByte(codepage, flags, wcstr, wclen,
mbstr, mblen, defchr, defused);
}
int mb_to_wc(int codepage, int flags, char *mbstr, int mblen,
wchar_t *wcstr, int wclen)
{
return MultiByteToWideChar(codepage, flags, mbstr, mblen, wcstr, wclen);
}
int is_dbcs_leadbyte(int codepage, char byte)
{
return IsDBCSLeadByteEx(codepage, byte);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -