📄 charset.c
字号:
left -= 1; } return -1;}#ifdef _UNICODE_SUPPORTstatic unsigned short ksc5601_0_conv_to_uc16 (const unsigned char* mchar, int len){ unsigned char ucs_code = ksc5601_0_unicode_map [ksc5601_0_char_offset (mchar)]; if (ucs_code == 0) return '?'; return ucs_code;}#endifstatic CHARSETOPS CharsetOps_ksc5601_0 = { 8836, 2, 2, FONT_CHARSET_EUCKR, {'\xA1', '\xA1'}, ksc5601_0_len_first_char, ksc5601_0_char_offset, db_nr_chars_in_str, ksc5601_0_is_this_charset, ksc5601_0_len_first_substr, db_get_next_word, ksc5601_0_pos_first_char,#ifdef _UNICODE_SUPPORT ksc5601_0_conv_to_uc16#endif};/************************* End of EUCKR *************************************/#endif /* _EUCKR_SUPPORT */#ifdef _EUCJP_SUPPORT/************************* EUCJP Specific Operations ************************/static int jisx0201_0_len_first_char (const unsigned char* mstr, int len){ unsigned char ch1; unsigned char ch2; ch1 = mstr [0]; if (ch1 == '\0') return 0; ch2 = mstr [1]; if (ch1 == 0x8E && ch2 >= 0xA1 && ch2 <= 0xDF) return 2; else return 1; return 0;}static unsigned int jisx0201_0_char_offset (const unsigned char* mchar){ if (mchar [0] == 0x8E) return mchar [1]; else return mchar [0];}static int jisx0201_0_nr_chars_in_str (const unsigned char* mstr, int mstrlen){ unsigned char ch1; unsigned char ch2; int left; int nr_chars = 0; left = mstrlen; while (left > 0) { ch1 = mstr [0]; if (ch1 == '\0') return nr_chars; ch2 = mstr [1]; if (ch1 == 0x8E && ch2 >= 0xA1 && ch2 <= 0xDF) { nr_chars ++; left -= 2; mstr += 2; } else { nr_chars ++; left -= 1; mstr += 1; } } return nr_chars;}static int jisx0201_0_is_this_charset (const unsigned char* charset){ int i; char name [LEN_FONT_NAME + 1]; for (i = 0; i < LEN_FONT_NAME + 1; i++) { if (charset [i] == '\0') break; name [i] = toupper (charset [i]); } name [i] = '\0'; if (strstr (name, "JISX0201") && strstr (name, "-0")) return 0; return 1;}#ifdef _UNICODE_SUPPORTstatic unsigned short jisx0201_0_conv_to_uc16 (const unsigned char* mchar, int len){ unsigned char ch1; unsigned char ch2; ch1 = mchar [0]; ch2 = mchar [1]; if (ch1 == 0x8E && ch2 >= 0xA1 && ch2 <= 0xDF) return 0xFF61 + ch2 - 0xA1; else if (ch1 == 0x5C) return 0x00A5; else if (ch1 == 0x80) return 0x005C; return ch1;}#endifstatic CHARSETOPS CharsetOps_jisx0201_0 = { 190, 1, 2, FONT_CHARSET_JISX0201_0, {' '}, jisx0201_0_len_first_char, jisx0201_0_char_offset, jisx0201_0_nr_chars_in_str, jisx0201_0_is_this_charset, sb_len_first_substr, sb_get_next_word, sb_pos_first_char,#ifdef _UNICODE_SUPPORT jisx0201_0_conv_to_uc16#endif};static int jisx0208_0_len_first_char (const unsigned char* mstr, int len){ unsigned char ch1; unsigned char ch2; if (len < 2) return 0; ch1 = mstr [0]; if (ch1 == '\0') return 0; ch2 = mstr [1]; if (ch1 >= 0xA1 && ch1 <= 0xFE && ch2 >= 0xA1 && ch2 <= 0xFE) return 2; return 0;}static unsigned int jisx0208_0_char_offset (const unsigned char* mchar){#if 1 return ((mchar [0] - 0xA1) * 94 + mchar [1] - 0xA1);#else if(mchar [0] > 0xAA) return ((mchar [0] - 0xA6 - 0x02) * 94 + mchar [1] - 0xC1 - 0xC4); else return ((mchar [0] - 0xA1 - 0x02) * 83 + mchar [1] - 0xA1 + 0x7E);#endif}static int jisx0208_0_is_this_charset (const unsigned char* charset){ int i; char name [LEN_FONT_NAME + 1]; for (i = 0; i < LEN_FONT_NAME + 1; i++) { if (charset [i] == '\0') break; name [i] = toupper (charset [i]); } name [i] = '\0'; if ((strstr (name, "JISX0208") && strstr (name, "-0")) || (strstr (name, "EUC") && strstr (name, "JP"))) return 0; return 1;}static int jisx0208_0_len_first_substr (const unsigned char* mstr, int mstrlen){ unsigned char ch1; unsigned char ch2; int i, left; int sub_len = 0; left = mstrlen; for (i = 0; i < mstrlen; i += 2) { if (left < 2) return sub_len; ch1 = mstr [i]; if (ch1 == '\0') return sub_len; ch2 = mstr [i + 1]; if (ch1 >= 0xA1 && ch1 <= 0xFE && ch2 >= 0xA1 && ch2 <= 0xFE) sub_len += 2; else return sub_len; left -= 2; } return sub_len;}static int jisx0208_0_pos_first_char (const unsigned char* mstr, int mstrlen){ unsigned char ch1; unsigned char ch2; int i, left; i = 0; left = mstrlen; while (left) { if (left < 2) return -1; ch1 = mstr [i]; if (ch1 == '\0') return -1; ch2 = mstr [i + 1]; if (ch1 >= 0xA1 && ch1 <= 0xFE && ch2 >= 0xA1 && ch2 <= 0xFE) return i; i += 1; left -= 1; } return -1;}#ifdef _UNICODE_SUPPORTstatic unsigned short jisx0208_0_conv_to_uc16 (const unsigned char* mchar, int len){ unsigned short ucs_code = jisx0208_0_unicode_map [jisx0208_0_char_offset (mchar)]; if (ucs_code == 0) return '?'; return ucs_code;}#endifstatic CHARSETOPS CharsetOps_jisx0208_0 = { 8836, 2, 2, FONT_CHARSET_JISX0208_0, {'\xA1', '\xA1'}, jisx0208_0_len_first_char, jisx0208_0_char_offset, db_nr_chars_in_str, jisx0208_0_is_this_charset, jisx0208_0_len_first_substr, db_get_next_word, jisx0208_0_pos_first_char,#ifdef _UNICODE_SUPPORT jisx0208_0_conv_to_uc16#endif};/************************* End of EUCJP *************************************/#endif /* _EUCJP_SUPPORT */#ifdef _SHIFTJIS_SUPPORT/************************* SHIFTJIS Specific Operations ************************/static int jisx0201_1_is_this_charset (const unsigned char* charset){ int i; char name [LEN_FONT_NAME + 1]; for (i = 0; i < LEN_FONT_NAME + 1; i++) { if (charset [i] == '\0') break; name [i] = toupper (charset [i]); } name [i] = '\0'; if (strstr (name, "JISX0201") && strstr (name, "-1")) return 0; return 1;}#ifdef _UNICODE_SUPPORTstatic unsigned short jisx0201_1_conv_to_uc16 (const unsigned char* mchar, int len){ unsigned char ch1 = mchar [0]; if (ch1 >= 0xA1 && ch1 <= 0xDF) return 0xFF61 + ch1 - 0xA1; else if (ch1 == 0x5C) return 0x00A5; else if (ch1 == 0x80) return 0x005C; return ch1;}#endifstatic CHARSETOPS CharsetOps_jisx0201_1 = { 190, 1, 1, FONT_CHARSET_JISX0201_1, {' '}, sb_len_first_char, sb_char_offset, sb_nr_chars_in_str, jisx0201_1_is_this_charset, sb_len_first_substr, sb_get_next_word, sb_pos_first_char,#ifdef _UNICODE_SUPPORT jisx0201_1_conv_to_uc16#endif};static int jisx0208_1_len_first_char (const unsigned char* mstr, int len){ unsigned char ch1; unsigned char ch2; if (len < 2) return 0; ch1 = mstr [0]; if (ch1 == '\0') return 0; ch2 = mstr [1]; if (((ch1 >= 0x81 && ch1 <= 0x9F) || (ch1 >= 0xE0 && ch1 <= 0xEF)) && ((ch2 >= 0x40 && ch2 <= 0x7E) || (ch2 >= 0x80 && ch2 <= 0xFC))) return 2; return 0;}static unsigned int jisx0208_1_char_offset (const unsigned char* mchar){ unsigned char ch1 = mchar [0]; unsigned char ch2 = mchar [1]; if (ch1 >= 0x81 && ch1 <= 0x9F) { if (ch2 >= 0x40 && ch2 <= 0x7E) { return ((ch1 - 0x81) * 0x3F + ch2 - 0x40); } else { return (ch1 - 0x81) * 0x7D + ch2 - 0x80 + (0x1F * 0x3F); } } else { if (ch2 >= 0x40 && ch2 <= 0x7E) { return ((ch1 - 0xE0) * 0x3F + ch2 - 0x40) + 0x1F * (0x3F + 0x7D); } else { return ((ch1 - 0xE0) * 0x7D + ch2 - 0x80) + 0x1F * (0x3F + 0x7D) + 0x10 * 0x3F; } }}static int jisx0208_1_is_this_charset (const unsigned char* charset){ int i; char name [LEN_FONT_NAME + 1]; for (i = 0; i < LEN_FONT_NAME + 1; i++) { if (charset [i] == '\0') break; name [i] = toupper (charset [i]); } name [i] = '\0'; if ((strstr (name, "JISX0208") && strstr (name, "-1")) || (strstr (name, "SHIFT") && strstr (name, "JIS"))) return 0; return 1;}static int jisx0208_1_len_first_substr (const unsigned char* mstr, int mstrlen){ unsigned char ch1; unsigned char ch2; int i, left; int sub_len = 0; left = mstrlen; for (i = 0; i < mstrlen; i += 2) { if (left < 2) return sub_len; ch1 = mstr [i]; if (ch1 == '\0') return sub_len; ch2 = mstr [i + 1]; if (((ch1 >= 0x81 && ch1 <= 0x9F) || (ch1 >= 0xE0 && ch1 <= 0xEF)) && ((ch2 >= 0x40 && ch2 <= 0x7E) || (ch2 >= 0x80 && ch2 <= 0xFC))) sub_len += 2; else return sub_len; left -= 2; } return sub_len;}static int jisx0208_1_pos_first_char (const unsigned char* mstr, int mstrlen){ unsigned char ch1; unsigned char ch2; int i, left; i = 0; left = mstrlen; while (left) { if (left < 2) return -1; ch1 = mstr [i]; if (ch1 == '\0') return -1; ch2 = mstr [i + 1]; if (((ch1 >= 0x81 && ch1 <= 0x9F) || (ch1 >= 0xE0 && ch1 <= 0xEF)) && ((ch2 >= 0x40 && ch2 <= 0x7E) || (ch2 >= 0x80 && ch2 <= 0xFC))) return i; i += 1; left -= 1; } return -1;}#ifdef _UNICODE_SUPPORTstatic unsigned short jisx0208_1_conv_to_uc16 (const unsigned char* mchar, int len){ unsigned short ucs_code = jisx0208_1_unicode_map [jisx0208_1_char_offset (mchar)]; if (ucs_code == 0) return '?'; return ucs_code;}#endifstatic CHARSETOPS CharsetOps_jisx0208_1 = { 8836, 2, 2, FONT_CHARSET_JISX0208_1, {'\xA1', '\xA1'}, jisx0208_1_len_first_char, jisx0208_1_char_offset, db_nr_chars_in_str, jisx0208_1_is_this_charset, jisx0208_1_len_first_substr, db_get_next_word, jisx0208_1_pos_first_char,#ifdef _UNICODE_SUPPORT jisx0208_1_conv_to_uc16#endif};/************************* End of SHIFTJIS *************************************/#endif /* _SHIFTJIS_SUPPORT */#ifdef _UNICODE_SUPPORT/************************* UNICODE Specific Operations ************************/static int utf8_len_first_char (const unsigned char* mstr, int len){ int c = *((unsigned char *)mstr); int n = 1; if (c & 0x80) { while (c & (0x80 >> n)) n++; } return n;}static unsigned short utf8_conv_to_uc16 (const unsigned char* mchar, int len){ int c = *((unsigned char *)(mchar++)); int n, t; if (c & 0x80) { n = 1; while (c & (0x80 >> n)) n++; c &= (1 << (8-n)) - 1; while (--n > 0) { t = *((unsigned char *)(mchar++)); if ((!(t & 0x80)) || (t & 0x40)) return '^'; c = (c << 6) | (t & 0x3F); } } return (unsigned short) c;}static unsigned int utf8_char_offset (const unsigned char* mchar){ return utf8_conv_to_uc16 (mchar, 0);}static int utf8_nr_chars_in_str (const unsigned char* mstr, int mstrlen){ int charlen; int n = 0; int left = mstrlen; while (left >= 0) { charlen = utf8_len_first_char (mstr, left); if (charlen > 0) n ++; left -= charlen; mstr += charlen; } return n;}static int utf8_is_this_charset (const unsigned char* charset){ int i; char name [LEN_FONT_NAME + 1]; for (i = 0; i < LEN_FONT_NAME + 1; i++) { if (charset [i] == '\0') break; name [i] = toupper (charset [i]); } name [i] = '\0'; if (strstr (name, "UTF") && strstr (name, "8")) return 0; return 1;}static int utf8_len_first_substr (const unsigned char* mstr, int mstrlen){ return mstrlen;}static int utf8_pos_first_char (const unsigned char* mstr, int mstrlen){ return 0;}static CHARSETOPS CharsetOps_utf8 = { 65536, 2, 2, FONT_CHARSET_UTF8, {'\xA1', '\xA1'}, utf8_len_first_char, utf8_char_offset, utf8_nr_chars_in_str, utf8_is_this_charset, utf8_len_first_substr, sb_get_next_word, utf8_pos_first_char,#ifdef _UNICODE_SUPPORT utf8_conv_to_uc16#endif};/************************* End of UNICODE *************************************/#endif /* _UNICODE_SUPPORT */static CHARSETOPS* Charsets [] ={ &CharsetOps_ascii,#ifdef _LATIN10_SUPPORT &CharsetOps_iso8859_16,#endif#ifdef _LATIN9_SUPPORT &CharsetOps_iso8859_15,#endif#ifdef _LATIN8_SUPPORT &CharsetOps_iso8859_14,#endif#ifdef _LATIN7_SUPPORT &CharsetOps_iso8859_13,#endif#ifdef _THAI_SUPPORT &CharsetOps_iso8859_11,#endif#ifdef _LATIN6_SUPPORT &CharsetOps_iso8859_10,#endif#ifdef _LATIN5_SUPPORT &CharsetOps_iso8859_9,#endif#ifdef _HEBREW_SUPPORT &CharsetOps_iso8859_8,#endif#ifdef _GREEK_SUPPORT &CharsetOps_iso8859_7,#endif#ifdef _ARABIC_SUPPORT &CharsetOps_iso8859_6,#endif#ifdef _CYRILLIC_SUPPORT &CharsetOps_iso8859_5,#endif#ifdef _LATIN4_SUPPORT &CharsetOps_iso8859_4,#endif#ifdef _LATIN3_SUPPORT &CharsetOps_iso8859_3,#endif#ifdef _LATIN2_SUPPORT &CharsetOps_iso8859_2,#endif &CharsetOps_iso8859_1,#ifdef _GB_SUPPORT &CharsetOps_gb2312_0,#endif#ifdef _GBK_SUPPORT &CharsetOps_gbk,#endif#ifdef _GB18030_SUPPORT &CharsetOps_gb18030_0,#endif#ifdef _BIG5_SUPPORT &CharsetOps_big5,#endif#ifdef _EUCKR_SUPPORT &CharsetOps_ksc5601_0,#endif#ifdef _EUCJP_SUPPORT &CharsetOps_jisx0201_0, &CharsetOps_jisx0208_0,#endif#ifdef _SHIFTJIS_SUPPORT &CharsetOps_jisx0201_1, &CharsetOps_jisx0208_1,#endif#ifdef _UNICODE_SUPPORT &CharsetOps_utf8,#endif};#define NR_CHARSETS (sizeof(Charsets)/sizeof(CHARSETOPS*))CHARSETOPS* GetCharsetOps (const char* charset_name){ int i; for (i = 0; i < NR_CHARSETS; i++) { if ((*Charsets [i]->is_this_charset) (charset_name) == 0) return Charsets [i]; } return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -