diff options
author | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-06-29 15:37:22 +0800 |
---|---|---|
committer | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-06-29 15:37:22 +0800 |
commit | ec1c94c5dd76df278b9d99e583c325c6baec989d (patch) | |
tree | 6f7a85cacc9d16b36047a546a2aa92f6cc61ec49 /mbbsd/term.c | |
parent | e01d79c4da7f943576b8c9118c1a807277a09e0c (diff) | |
download | pttbbs-ec1c94c5dd76df278b9d99e583c325c6baec989d.tar pttbbs-ec1c94c5dd76df278b9d99e583c325c6baec989d.tar.gz pttbbs-ec1c94c5dd76df278b9d99e583c325c6baec989d.tar.bz2 pttbbs-ec1c94c5dd76df278b9d99e583c325c6baec989d.tar.lz pttbbs-ec1c94c5dd76df278b9d99e583c325c6baec989d.tar.xz pttbbs-ec1c94c5dd76df278b9d99e583c325c6baec989d.tar.zst pttbbs-ec1c94c5dd76df278b9d99e583c325c6baec989d.zip |
Parse a little TELNET control string.
Support big screen on telnet connection.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2098 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/term.c')
-rw-r--r-- | mbbsd/term.c | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/mbbsd/term.c b/mbbsd/term.c index 555840d1..f58bbfb8 100644 --- a/mbbsd/term.c +++ b/mbbsd/term.c @@ -53,21 +53,10 @@ outcf(int ch) #endif static void -term_resize(int sig) -{ - struct winsize newsize; +term_resize(int row, int col){ screenline_t *new_picture; - - signal(SIGWINCH, SIG_IGN); /* Don't bother me! */ - ioctl(0, TIOCGWINSZ, &newsize); - - /* make sure reasonable size */ - newsize.ws_row = MAX(24, MIN(100, newsize.ws_row)); - newsize.ws_col = MAX(80, MIN(200, newsize.ws_col)); - - if (newsize.ws_row > t_lines) { - new_picture = (screenline_t *) calloc(newsize.ws_row, - sizeof(screenline_t)); + if (big_picture != NULL && row > t_lines) { + new_picture = (screenline_t *) calloc(row, sizeof(screenline_t)); if (new_picture == NULL) { syslog(LOG_ERR, "calloc(): %m"); return; @@ -76,19 +65,52 @@ term_resize(int sig) free(big_picture); big_picture = new_picture; } - t_lines = newsize.ws_row; - t_columns = newsize.ws_col; - scr_lns = t_lines; /* XXX: scr_lns 跟 t_lines 有什麼不同, 為何分成兩個 */ + t_lines = row; + t_columns = col; b_lines = t_lines - 1; p_lines = t_lines - 4; +} - signal(SIGWINCH, term_resize); +static void +term_resize_catch(int sig) +{ + struct winsize newsize; + + signal(SIGWINCH, SIG_IGN); /* Don't bother me! */ + ioctl(0, TIOCGWINSZ, &newsize); + + /* make sure reasonable size */ + newsize.ws_row = MAX(24, MIN(100, newsize.ws_row)); + newsize.ws_col = MAX(80, MIN(200, newsize.ws_col)); + + term_resize(newsize.ws_row, newsize.ws_col); + + signal(SIGWINCH, term_resize_catch); +} + +#ifndef SKIP_TELNET_CONTROL_SIGNAL +void +telnet_parse_size(const unsigned char* msg){ + /* msg[0] == IAC, msg[1] == SB, msg[2] = TELOPT_NAWS */ + int i = 4, row, col; + + col = msg[3] << 8; + if(msg[i] == 0xff) + ++i; /* avoid escaped 0xff */ + col |= msg[i++]; + + row = msg[i++] << 8; + if(msg[i] == 0xff) + ++i; + row |= msg[i]; + term_resize(row, col); } +#endif int term_init() { - signal(SIGWINCH, term_resize); + signal(SIGWINCH, term_resize_catch); return YEA; } |