diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-06-07 12:13:59 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-06-07 12:13:59 +0800 |
commit | 6d2c21c4eb53964be68892a738e103c85421cf89 (patch) | |
tree | 18cea23db2d13fffdff2a67dd3d4c697d4bceda3 /mbbsd/io.c | |
parent | 0a67db88f03c6d12a6da5e8a61f78e4e56d88672 (diff) | |
download | pttbbs-6d2c21c4eb53964be68892a738e103c85421cf89.tar pttbbs-6d2c21c4eb53964be68892a738e103c85421cf89.tar.gz pttbbs-6d2c21c4eb53964be68892a738e103c85421cf89.tar.bz2 pttbbs-6d2c21c4eb53964be68892a738e103c85421cf89.tar.lz pttbbs-6d2c21c4eb53964be68892a738e103c85421cf89.tar.xz pttbbs-6d2c21c4eb53964be68892a738e103c85421cf89.tar.zst pttbbs-6d2c21c4eb53964be68892a738e103c85421cf89.zip |
DBCS Aware for getdata and edit.
Thanks to Michael Hsin (mhsin) for his patching edit.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2781 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/io.c')
-rw-r--r-- | mbbsd/io.c | 66 |
1 files changed, 60 insertions, 6 deletions
@@ -529,6 +529,32 @@ strip_nonebig5(unsigned char *str, int maxlen) str[len]='\0'; } +#ifdef DBCSAWARE_GETDATA + +int getDBCSstatus(unsigned char *s, int pos) +{ + int sts = DBCS_ASCII; + while(pos >= 0) + { + if(sts == DBCS_LEADING) + sts = DBCS_TRAILING; + else if (*s >= 0x80) + { + sts = DBCS_LEADING; + } else { + sts = DBCS_ASCII; + } + s++, pos--; + } + return sts; +} + +#else + +#define dbcs_off (1) + +#endif + int oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo) { @@ -604,22 +630,42 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo) clen = currchar = strlen(buf); break; case KEY_LEFT: - if (currchar) + if (currchar > 0) + { --currchar; +#ifdef DBCSAWARE_GETDATA + if(currchar > 0 && + getDBCSstatus(buf, currchar) == DBCS_TRAILING) + currchar --; +#endif + } break; case KEY_RIGHT: if (buf[currchar]) + { ++currchar; +#ifdef DBCSAWARE_GETDATA + if(buf[currchar] && + getDBCSstatus(buf, currchar) == DBCS_TRAILING) + currchar++; +#endif + } break; case '\177': case Ctrl('H'): if (currchar) { - currchar--; - clen--; +#ifdef DBCSAWARE_GETDATA + int dbcs_off = (getDBCSstatus(buf, currchar-1) == DBCS_TRAILING) ? 2 : 1; +#endif + currchar -= dbcs_off; + clen -= dbcs_off; for (i = currchar; i <= clen; i++) - buf[i] = buf[i + 1]; + buf[i] = buf[i + dbcs_off]; move(y, x + clen); outc(' '); +#ifdef DBCSAWARE_GETDATA + if(dbcs_off > 1) outc(' '); +#endif move(y, x); edit_outs(buf); } @@ -627,6 +673,7 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo) case Ctrl('Y'): currchar = 0; case Ctrl('K'): + /* we shoud be able to avoid DBCS issues in ^K mode */ buf[currchar] = '\0'; move(y, x + currchar); for (i = currchar; i < clen; i++) @@ -636,11 +683,18 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo) case Ctrl('D'): case KEY_DEL: if (buf[currchar]) { - clen--; +#ifdef DBCSAWARE_GETDATA + int dbcs_off = (buf[currchar+1] && + getDBCSstatus(buf, currchar+1) == DBCS_TRAILING) ? 2 : 1; +#endif + clen -= dbcs_off; for (i = currchar; i <= clen; i++) - buf[i] = buf[i + 1]; + buf[i] = buf[i + dbcs_off]; move(y, x + clen); outc(' '); +#ifdef DBCSAWARE_GETDATA + if(dbcs_off > 1) outc(' '); +#endif move(y, x); edit_outs(buf); } |