📄 winucs.c
字号:
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 + -