diff options
author | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-11-30 15:26:24 +0800 |
---|---|---|
committer | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-11-30 15:26:24 +0800 |
commit | 9e5acf2b2b13eea84df06c2e3dad581f18eaca20 (patch) | |
tree | 779359df99db8e677ae72ae4f079bab1cf64ce9c /mbbsd/convert.c | |
parent | d20e94f8c91ef1ffd2f30a4ddbd48a7426558f56 (diff) | |
download | pttbbs-9e5acf2b2b13eea84df06c2e3dad581f18eaca20.tar pttbbs-9e5acf2b2b13eea84df06c2e3dad581f18eaca20.tar.gz pttbbs-9e5acf2b2b13eea84df06c2e3dad581f18eaca20.tar.bz2 pttbbs-9e5acf2b2b13eea84df06c2e3dad581f18eaca20.tar.lz pttbbs-9e5acf2b2b13eea84df06c2e3dad581f18eaca20.tar.xz pttbbs-9e5acf2b2b13eea84df06c2e3dad581f18eaca20.tar.zst pttbbs-9e5acf2b2b13eea84df06c2e3dad581f18eaca20.zip |
update big5<->gb table, thanks smth
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1384 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/convert.c')
-rw-r--r-- | mbbsd/convert.c | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/mbbsd/convert.c b/mbbsd/convert.c index 133c249d..141548d1 100644 --- a/mbbsd/convert.c +++ b/mbbsd/convert.c @@ -8,14 +8,9 @@ #include "convert.h" -#define BtoG_bad1 0xa1 -#define BtoG_bad2 0xf5 -#define GtoB_bad1 0xa1 -#define GtoB_bad2 0xbc - char *hzconvert(char *, int *, char *, void (*dbcvrt)()); -extern unsigned char GtoB[], BtoG[]; +extern const unsigned char GtoB[], BtoG[]; #define c1 (unsigned char)(s[0]) #define c2 (unsigned char)(s[1]) @@ -24,36 +19,48 @@ static void g2b(char *s) { unsigned int i; - if ((c2 >= 0xa1) && (c2 <= 0xfe)) { - if ((c1 >= 0xa1) && (c1 <= 0xa9)) { - i = ((c1 - 0xa1) * 94 + (c2 - 0xa1)) * 2; - s[0] = GtoB[i++]; s[1] = GtoB[i]; - return; - } else if ((c1 >= 0xb0) && (c1 <= 0xf7)) { - i = ((c1 - 0xb0 + 9) * 94 + (c2 - 0xa1)) * 2; - s[0] = GtoB[i++]; s[1] = GtoB[i]; - return; + if ((c1 >= 0x81) && (c1 <= 0xfe) && (c2 >= 0x40) && (c2 <= 0xfe) && (c2 != 0x7f)) { + /* + * c1c2 in the table + */ + if (c2 < 0x7f) + i = ((c1 - 0x81) * 190 + (c2 - 0x40)) * 2; + else + i = ((c1 - 0x81) * 190 + (c2 - 0x41)) * 2; + s[0] = GtoB[i++]; + s[1] = GtoB[i]; + } else { /* c1c2 not in the table */ + if ((char) s[1] >= 0) /* half HANZI-character */ + s[0] = '?'; + else { /* invalid gbk-character */ + s[0] = GtoB_bad1; + s[1] = GtoB_bad2; } } - s[0] = GtoB_bad1; s[1] = GtoB_bad2; } static void b2g(char *s) { - int i; + unsigned int i; - if ((c1 >= 0xa1) && (c1 <= 0xf9)) { - if ((c2 >= 0x40) && (c2 <= 0x7e)) { - i = ((c1 - 0xa1) * 157 + (c2 - 0x40)) * 2; - s[0] = BtoG[i++]; s[1] = BtoG[i]; - return; - } else if ((c2 >= 0xa1) && (c2 <= 0xfe)) { - i = ((c1 - 0xa1) * 157 + (c2 - 0xa1) + 63) * 2; - s[0] = BtoG[i++]; s[1] = BtoG[i]; - return; - } + if ((c1 >= 0x81) && (c1 <= 0xfe) && (c2 >= 0x40) && (c2 <= 0xfe) && (c2 != 0x7f)) { + /* + * c1c2 in the table + */ + if (c2 < 0x7f) + i = ((c1 - 0x81) * 190 + (c2 - 0x40)) * 2; + else + i = ((c1 - 0x81) * 190 + (c2 - 0x41)) * 2; + s[0] = BtoG[i++]; + s[1] = BtoG[i]; + } else { /* c1c2 not in the table */ + if ((char) s[1] >= 0) /* half HANZI-character */ + s[0] = '?'; + else { /* invalid big5-character */ + s[0] = BtoG_bad1; + s[1] = BtoG_bad2; + } } - s[0] = BtoG_bad1; s[1] = BtoG_bad2; } unsigned char *gb2big(unsigned char *s, int plen) |