From 60c7059c312f02d1dd5738d7e9c2872a1a123657 Mon Sep 17 00:00:00 2001 From: piaip Date: Wed, 19 Dec 2007 15:39:37 +0000 Subject: - isolate low level termial i/o api calls, prepare for pfterm (piaip's flat terminal system) git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3710 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 43 ++++++++--------- mbbsd/kaede.c | 93 +++++++++++++++++++++++++++++++++++++ mbbsd/screen.c | 141 ++++++++++---------------------------------------------- mbbsd/term.c | 16 ++----- 4 files changed, 140 insertions(+), 153 deletions(-) diff --git a/include/proto.h b/include/proto.h index 2746a05b..849a8d42 100644 --- a/include/proto.h +++ b/include/proto.h @@ -228,6 +228,8 @@ void addsignature(FILE *fp, int ifuseanony); void auto_backup(void); void restore_backup(void); char *ask_tmpbuf(int y); +void edit_outs(const char *text); +void edit_outs_n(const char *text, int n); /* fav */ void fav_set_old_folder(fav_t *fp); @@ -335,7 +337,13 @@ int ochar(int c); /* kaede */ char *Ptt_prints(char *str, size_t size, int mode); -char *my_ctime(const time4_t *t, char *ans, int len); +void prints(const char *fmt, ...) GCC_CHECK_FORMAT(1,2); +void mouts(int y, int x, const char *str); +void outmsg(const char *msg); +void outmsglr(const char *msg, int llen, const char *rmsg, int rlen); +void outs_n(const char *str, int n); +void outslr(const char *left, int leftlen, const char *right, int rightlen); +void out_lines(const char *str, int line); /* lovepaper */ int x_love(void); @@ -552,43 +560,30 @@ int reversi_personal(void); int reversi_watch(void); ChessInfo* reversi_replay(FILE* fp); -/* screen */ -void mouts(int y, int x, const char *str); +/* screen/pfterm */ +void initscr(void); +int resizescr(int rows, int cols); +void getyx(int *y, int *x); void move(int y, int x); void move_ansi(int y, int x); +void outc(unsigned char ch); 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); -void clrtoeol(void); void clear(void); -void refresh(void); +void clrtoeol(void); void clrtobot(void); -void outmsg(const char *msg); -void outmsglr(const char *msg, int llen, const char *rmsg, int rlen); -void prints(const char *fmt, ...) GCC_CHECK_FORMAT(1,2); -void region_scroll_up(int top, int bottom); -void outc(unsigned char ch); -void redoscr(void); -void redoln(void); void clrtoline(int line); +void refresh(void); +void redoscr(void); void standout(void); void standend(void); -void edit_outs(const char *text); -void edit_outs_n(const char *text, int n); -void outch(unsigned char c); -void rscroll(void); void scroll(void); -void getyx(int *y, int *x); -void initscr(void); -void out_lines(const char *str, int line); +void rscroll(void); +void region_scroll_up(int top, int bottom); void screen_backup(screen_backup_t *buf); void screen_restore(const screen_backup_t *buf); - #define HAVE_SCREEN_GRAYOUT -void grayout_line(int y, int level); void grayout_lines(int start, int end, int level); - /* stuff */ #define isprint2(ch) ((ch & 0x80) || isprint(ch)) #define not_alpha(ch) (ch < 'A' || (ch > 'Z' && ch < 'a') || ch > 'z') diff --git a/mbbsd/kaede.c b/mbbsd/kaede.c index 8e328e5d..92b26885 100644 --- a/mbbsd/kaede.c +++ b/mbbsd/kaede.c @@ -1,6 +1,9 @@ /* $Id$ */ #include "bbs.h" +// TODO move stuff to libbbs(or util)/string.c, ... +// this file can be removed (or not?) + char * Ptt_prints(char *str, size_t size, int mode) { @@ -71,3 +74,93 @@ Ptt_prints(char *str, size_t size, int mode) return str; } +// utility from screen.c +void +outs_n(const char *str, int n) +{ + while (*str && n--) { + outc(*str++); + } +} + +// XXX left-right (for large term) +// TODO someday please add ANSI detection version +void +outslr(const char *left, int leftlen, const char *right, int rightlen) +{ + if (left == NULL) + left = ""; + if (right == NULL) + right = ""; + if(*left && leftlen < 0) + leftlen = strlen(left); + if(*right && rightlen < 0) + rightlen = strlen(right); + // now calculate padding + rightlen = t_columns - leftlen - rightlen; + outs(left); + + // ignore right msg if we need to. + if(rightlen >= 0) + { + while(--rightlen > 0) + outc(' '); + outs(right); + } else { + rightlen = t_columns - leftlen; + while(--rightlen > 0) + outc(' '); + } +} + + +/* Jaky */ +void +out_lines(const char *str, int line) +{ + while (*str && line) { + outc(*str); + if (*str == '\n') + line--; + str++; + } +} + +void +outmsg(const char *msg) +{ + move(b_lines - msg_occupied, 0); + clrtoeol(); + outs(msg); +} + +void +outmsglr(const char *msg, int llen, const char *rmsg, int rlen) +{ + move(b_lines - msg_occupied, 0); + clrtoeol(); + outslr(msg, llen, rmsg, rlen); + outs(ANSI_RESET ANSI_CLRTOEND); +} + +void +prints(const char *fmt,...) +{ + va_list args; + char buff[1024]; + + va_start(args, fmt); + vsnprintf(buff, sizeof(buff), fmt, args); + va_end(args); + outs(buff); +} + +void +mouts(int y, int x, const char *str) +{ + move(y, x); + clrtoeol(); + outs(str); +} + +// vim:ts=4 diff --git a/mbbsd/screen.c b/mbbsd/screen.c index 941ad015..7bc61e54 100644 --- a/mbbsd/screen.c +++ b/mbbsd/screen.c @@ -24,6 +24,30 @@ initscr(void) } } +int +resizescr(int w, int h) +{ + screenline_t *new_picture; + + /* make sure reasonable size */ + h = MAX(24, MIN(100, h)); + w = MAX(80, MIN(200, w)); + + if (h > t_lines && big_picture) { + new_picture = (screenline_t *) + calloc(h, sizeof(screenline_t)); + if (new_picture == NULL) { + syslog(LOG_ERR, "calloc(): %m"); + return 0; + } + memcpy(new_picture, big_picture, t_lines * sizeof(screenline_t)); + free(big_picture); + big_picture = new_picture; + return 1; + } + return 0; +} + void move(int y, int x) { @@ -170,34 +194,6 @@ redoscr(void) oflush(); } -// deprecated? -#if 0 -void -redoln(void) -{ - screenline_t *slp = GetCurrentLine(); - int len, mode; - - len = slp->len; - rel_move(tc_col, tc_line, 0, cur_ln); - if (len) - { - if ((mode = slp->mode) & STANDOUT) - standoutput((char*)slp->data, 0, len, slp->sso, slp->eso); - else - output((char*)slp->data, len); - - slp->mode = mode & ~(MODIFIED); - - slp->oldlen = tc_col = len; - } - else - clrtoeol(); - rel_move(tc_col, tc_line, cur_col, cur_ln); - oflush(); -} -#endif - void refresh(void) { @@ -448,94 +444,6 @@ outs(const char *str) } } -void -outs_n(const char *str, int n) -{ - while (*str && n--) { - outc(*str++); - } -} - -// XXX left-right (for large term) -// TODO someday please add ANSI detection version -void -outslr(const char *left, int leftlen, const char *right, int rightlen) -{ - if (left == NULL) - left = ""; - if (right == NULL) - right = ""; - if(*left && leftlen < 0) - leftlen = strlen(left); - if(*right && rightlen < 0) - rightlen = strlen(right); - // now calculate padding - rightlen = t_columns - leftlen - rightlen; - outs(left); - - // ignore right msg if we need to. - if(rightlen >= 0) - { - while(--rightlen > 0) - outc(' '); - outs(right); - } else { - rightlen = t_columns - leftlen; - while(--rightlen > 0) - outc(' '); - } -} - - -/* Jaky */ -void -out_lines(const char *str, int line) -{ - while (*str && line) { - outc(*str); - if (*str == '\n') - line--; - str++; - } -} - -void -outmsg(const char *msg) -{ - move(b_lines - msg_occupied, 0); - clrtoeol(); - outs(msg); -} - -void -outmsglr(const char *msg, int llen, const char *rmsg, int rlen) -{ - move(b_lines - msg_occupied, 0); - clrtoeol(); - outslr(msg, llen, rmsg, rlen); - outs(ANSI_RESET ANSI_CLRTOEND); -} - -void -prints(const char *fmt,...) -{ - va_list args; - char buff[1024]; - - va_start(args, fmt); - vsnprintf(buff, sizeof(buff), fmt, args); - va_end(args); - outs(buff); -} - -void -mouts(int y, int x, const char *str) -{ - move(y, x); - clrtoeol(); - outs(str); -} - void scroll(void) { @@ -622,6 +530,7 @@ grayout_lines(int y, int end, int level) if (y < 0) y = 0; if (end > b_lines) end = b_lines; + // TODO change to y <= end someday // loop lines for (; y < end; y ++) { diff --git a/mbbsd/term.c b/mbbsd/term.c index 2ef13ed0..202ea582 100644 --- a/mbbsd/term.c +++ b/mbbsd/term.c @@ -40,25 +40,15 @@ sig_term_resize(int sig) void term_resize(int w, int h) { - screenline_t *new_picture; - Signal(SIGWINCH, SIG_IGN); /* Don't bother me! */ /* make sure reasonable size */ h = MAX(24, MIN(100, h)); w = MAX(80, MIN(200, w)); - if (h > t_lines && big_picture) { - new_picture = (screenline_t *) - calloc(h, sizeof(screenline_t)); - if (new_picture == NULL) { - syslog(LOG_ERR, "calloc(): %m"); - return; - } - memcpy(new_picture, big_picture, t_lines * sizeof(screenline_t)); - free(big_picture); - big_picture = new_picture; - } + // invoke terminal system resize + resizescr(h, w); + t_lines = h; t_columns = w; scr_lns = t_lines; /* XXX: scr_lns 跟 t_lines 有什麼不同, 為何分成兩個 */ -- cgit v1.2.3