diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2007-12-01 18:01:51 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2007-12-01 18:01:51 +0800 |
commit | 4c256182f70ad244e0ec40af45c0c0857abb0a01 (patch) | |
tree | f2663fd39c9234b611a9d3fb8f01fcc3cecaf008 | |
parent | d2e9ddb320e18206dcb54e7d8476fdc73e489fa9 (diff) | |
download | pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.tar pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.tar.gz pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.tar.bz2 pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.tar.lz pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.tar.xz pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.tar.zst pttbbs-4c256182f70ad244e0ec40af45c0c0857abb0a01.zip |
- add move_ansi() to support moving to lines with prior ANSI code.
- general improvement
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3602 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/proto.h | 2 | ||||
-rw-r--r-- | mbbsd/bbs.c | 10 | ||||
-rw-r--r-- | mbbsd/fav.c | 1 | ||||
-rw-r--r-- | mbbsd/io.c | 81 | ||||
-rw-r--r-- | mbbsd/screen.c | 30 | ||||
-rw-r--r-- | mbbsd/talk.c | 5 |
6 files changed, 103 insertions, 26 deletions
diff --git a/include/proto.h b/include/proto.h index bc4a2b08..25bcedd7 100644 --- a/include/proto.h +++ b/include/proto.h @@ -330,6 +330,7 @@ int oldgetdata(int line, int col, const char *prompt, char *buf, int len, int ec void output(const char *s, int len); int num_in_buf(void); int ochar(int c); +int strlen_noansi(const char *buf); /* kaede */ int Rename(const char* src, const char* dst); @@ -556,6 +557,7 @@ ChessInfo* reversi_replay(FILE* fp); /* screen */ void mouts(int y, int x, const char *str); void move(int y, int x); +void move_ansi(int y, int x); void outs(const char *str); void outs_n(const char *str, int n); void outslr(const char *left, int leftlen, const char *right, int rightlen); diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 51f45a54..116bfe17 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -3278,15 +3278,15 @@ b_config(void) " 回文 (群組長以上才可設定此項)", (bp->brdattr & BRD_NOREPLY) ? "不可以" : "可以" ); - move(b_lines - 10, 62); + move_ansi(b_lines - 10, 52); prints("發文限制"); - move(b_lines - 9, 64); + move_ansi(b_lines - 9, 54); prints("上站次數 %d 次以上", (int)bp->post_limit_logins * 10); - move(b_lines - 8, 64); + move_ansi(b_lines - 8, 54); prints("文章篇數 %d 篇以上", (int)bp->post_limit_posts * 10); - move(b_lines - 7, 64); + move_ansi(b_lines - 7, 54); prints("註冊時間 %d 個月以上", (int)bp->post_limit_regtime); - move(b_lines - 6, 64); + move_ansi(b_lines - 6, 54); prints("劣文篇數 %d 篇以下", 255 - (int)bp->post_limit_badpost); move(b_lines, 0); diff --git a/mbbsd/fav.c b/mbbsd/fav.c index e28ddf0d..b01ba1b9 100644 --- a/mbbsd/fav.c +++ b/mbbsd/fav.c @@ -510,6 +510,7 @@ static int read_favrec(FILE *frp, fav_t *fp) /** * 從記錄檔中 load 出我的最愛。 + * TODO create default fav, and add SYSOP/PttNewHand */ int fav_load(void) { @@ -646,30 +646,31 @@ wait_input(float f, int flDoRefresh) * ONLY_COLOR: ?? * NO_RELOAD: 不 strip (?) */ +static const char EscapeFlag[] = { + /* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* 10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, + /* 20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* 30 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, /* 0~9 ;= */ + /* 40 */ 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, /* ABCDHIJK */ + /* 50 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* 60 */ 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 2, 2, 0, 0, /* fhlm */ + /* 70 */ 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* su */ + /* 80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* 90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* A0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* B0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* C0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* D0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* E0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* F0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; +#define isEscapeParam(X) (EscapeFlag[(int)(X)] & 1) +#define isEscapeCommand(X) (EscapeFlag[(int)(X)] & 2) + int strip_ansi(char *buf, const char *str, int mode) { register int count = 0; - static const char EscapeFlag[] = { - /* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, - /* 20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 30 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, /* 0~9 ;= */ - /* 40 */ 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, /* ABCDHIJK */ - /* 50 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 60 */ 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 2, 2, 0, 0, /* fhlm */ - /* 70 */ 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* su */ - /* 80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* A0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* B0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* C0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* D0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* E0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* F0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - }; -#define isEscapeParam(X) (EscapeFlag[(int)(X)] & 1) -#define isEscapeCommand(X) (EscapeFlag[(int)(X)] & 2) for(; *str; ++str) if( *str != ESC_CHR ){ @@ -701,6 +702,46 @@ strip_ansi(char *buf, const char *str, int mode) return count; } +int +strlen_noansi(const char *s) +{ + register int count = 0, mode = 0; + + if (!s || !*s) + return 0; + + for (; *s; ++s) + { + // 0 - no ansi, 1 - [, 2 - param+cmd + switch (mode) + { + case 0: + if (*s == ESC_CHR) + mode = 1; + else + count ++; + break; + + case 1: + if (*s == '[') + mode = 2; + else + mode = 0; // unknown command + break; + + case 2: + if (isEscapeParam(*s)) + continue; + else if (isEscapeCommand(*s)) + mode = 0; + else + mode = 0; + break; + } + } + return count; +} + void strip_nonebig5(unsigned char *str, int maxlen) { diff --git a/mbbsd/screen.c b/mbbsd/screen.c index ee3f44f8..a9af6747 100644 --- a/mbbsd/screen.c +++ b/mbbsd/screen.c @@ -34,6 +34,23 @@ move(int y, int x) } void +move_ansi(int y, int x) +{ + // take ANSI length in consideration + register screenline_t *slp; + cur_ln = y; + cur_col = x; + + if (y >= scr_lns || x < 1) + return; + + slp = &big_picture[y]; + slp->data[slp->len] = 0; + x += (strlen((char*)slp->data) - strlen_noansi((char*)slp->data)); + cur_col = x; +} + +void getyx(int *y, int *x) { *y = cur_ln; @@ -256,9 +273,22 @@ clrtoeol(void) register int ln; standing = NA; + if (cur_col <= slp->sso) slp->mode &= ~STANDOUT; + /* + if (cur_col == 0) // TODO and contains ANSI + { + // workaround poor ANSI issue + size_t sz = (slp->len > slp->oldlen) ? slp->len : slp->oldlen; + sz = (sz < ANSILINELEN) ? sz : ANSILINELEN; + memset(slp->data, ' ', sz); + slp->len = 0; + return; + } + */ + if (cur_col > slp->oldlen) { for (ln = slp->len; ln <= cur_col; ln++) slp->data[ln] = ' '; diff --git a/mbbsd/talk.c b/mbbsd/talk.c index d7eccb6a..b518f1a7 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -86,7 +86,10 @@ int query_online(const char *userid) { userinfo_t *uentp; - if (!userid || !*userid || *userid == '-') + if (!userid || !*userid) + return 0; + + if (!isalnum(*userid)) return 0; if (strchr(userid, '.') || SHM->GV2.e.noonlineuser) |