diff options
author | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-08-15 18:09:51 +0800 |
---|---|---|
committer | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-08-15 18:09:51 +0800 |
commit | a8cfec296b543e31bf596b61c86473d094afc5fc (patch) | |
tree | 8766f9f2d9ac385652ae4a07d217ae906a6aa32d | |
parent | 7cf467de869336579256b535fa605b0aa53b991c (diff) | |
download | pttbbs-a8cfec296b543e31bf596b61c86473d094afc5fc.tar pttbbs-a8cfec296b543e31bf596b61c86473d094afc5fc.tar.gz pttbbs-a8cfec296b543e31bf596b61c86473d094afc5fc.tar.bz2 pttbbs-a8cfec296b543e31bf596b61c86473d094afc5fc.tar.lz pttbbs-a8cfec296b543e31bf596b61c86473d094afc5fc.tar.xz pttbbs-a8cfec296b543e31bf596b61c86473d094afc5fc.tar.zst pttbbs-a8cfec296b543e31bf596b61c86473d094afc5fc.zip |
screen-resize awareness between screen_backup() and screen_restore().
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3038 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/proto.h | 4 | ||||
-rw-r--r-- | include/pttstruct.h | 5 | ||||
-rw-r--r-- | mbbsd/chat.c | 10 | ||||
-rw-r--r-- | mbbsd/go.c | 10 | ||||
-rw-r--r-- | mbbsd/io.c | 33 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 10 | ||||
-rw-r--r-- | mbbsd/screen.c | 22 |
7 files changed, 56 insertions, 38 deletions
diff --git a/include/proto.h b/include/proto.h index a39a65c7..981a7ba4 100644 --- a/include/proto.h +++ b/include/proto.h @@ -554,9 +554,9 @@ void scroll(void); void getyx(int *y, int *x); void initscr(void); void out_lines(const char *str, int line); -void screen_backup(int len, const screenline_t *bp, void *buf); +void screen_backup(int len, const screenline_t *bp, screen_backup_t *buf); size_t screen_backupsize(int len, const screenline_t *bp); -void screen_restore(int len, screenline_t *bp, const void *buf); +void screen_restore(int len, screenline_t *bp, const screen_backup_t *buf); /* stuff */ #define isprint2(ch) ((ch & 0x80) || isprint(ch)) diff --git a/include/pttstruct.h b/include/pttstruct.h index 1167fb33..9866b679 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -426,6 +426,11 @@ typedef struct water_t { } water_t; typedef struct { + int row, col; + void *raw_memory; +} screen_backup_t; + +typedef struct { fileheader_t *header; char mtitle[STRLEN]; char *path; diff --git a/mbbsd/chat.c b/mbbsd/chat.c index 7f5e4939..0caa88f5 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -527,14 +527,14 @@ t_chat(void) } else if (ch == Ctrl('E')) { currchar = strlen(inbuf); } else if (ch == Ctrl('I')) { - void *screen0; + screen_backup_t old_screen; - screen0=malloc(screen_backupsize(t_lines, big_picture)); - screen_backup(t_lines, big_picture, screen0); + old_screen.raw_memory = malloc(screen_backupsize(t_lines, big_picture)); + screen_backup(t_lines, big_picture, &old_screen); add_io(0, 0); t_idle(); - screen_restore(t_lines, big_picture, screen0); - free(screen0); + screen_restore(t_lines, big_picture, &old_screen); + free(old_screen.raw_memory); redoscr(); add_io(cfd, 0); } else if (ch == Ctrl('Q')) { @@ -864,11 +864,11 @@ gochess(int fd) if (ch == 'v') { - void *screen0; + screen_backup_t old_screen; int y, x; - screen0=malloc(screen_backupsize(t_lines, big_picture)); - screen_backup(t_lines, big_picture, screen0); + old_screen.raw_memory = malloc(screen_backupsize(t_lines, big_picture)); + screen_backup(t_lines, big_picture, &old_screen); add_io(0, 0); getyx(&y, &x); if (ch == 'v') @@ -887,8 +887,8 @@ gochess(int fd) } */ move(y, x); - screen_restore(t_lines, big_picture, screen0); - free(screen0); + screen_restore(t_lines, big_picture, &old_screen); + free(old_screen.raw_memory); add_io(fd, 0); scr_need_redraw = 1; continue; @@ -425,22 +425,21 @@ igetch(void) if (currutmp != NULL && currutmp->mode != EDITING && currutmp->mode != LUSERS && currutmp->mode) { - void *screen0; + screen_backup_t old_screen; int oldroll = roll; int y, x, my_newfd; - // FIXME reveal heap data or crash if screen resize getyx(&y, &x); - screen0=malloc(screen_backupsize(t_lines, big_picture)); - screen_backup(t_lines, big_picture, screen0); + old_screen.raw_memory = malloc(screen_backupsize(t_lines, big_picture)); + screen_backup(t_lines, big_picture, &old_screen); my_newfd = i_newfd; i_newfd = 0; t_users(); i_newfd = my_newfd; - screen_restore(t_lines, big_picture, screen0); - free(screen0); + screen_restore(t_lines, big_picture, &old_screen); + free(old_screen.raw_memory); roll = oldroll; move(y, x); redoscr(); @@ -463,18 +462,18 @@ igetch(void) if (currutmp->msgs[0].pid && WATERMODE(WATER_OFO) && wmofo == NOTREPLYING) { - int y, x, my_newfd; - void *screen0; + int y, x, my_newfd; + screen_backup_t old_screen; - screen0=malloc(screen_backupsize(t_lines, big_picture)); - screen_backup(t_lines, big_picture, screen0); + old_screen.raw_memory = malloc(screen_backupsize(t_lines, big_picture)); + screen_backup(t_lines, big_picture, &old_screen); getyx(&y, &x); my_newfd = i_newfd; i_newfd = 0; my_write2(); - screen_restore(t_lines, big_picture, screen0); - free(screen0); + screen_restore(t_lines, big_picture, &old_screen); + free(old_screen.raw_memory); i_newfd = my_newfd; move(y, x); redoscr(); @@ -494,11 +493,11 @@ igetch(void) continue; } else if (watermode == -1 && currutmp->msgs[0].pid) { /* 第一次按 Ctrl-R (必須先被丟過水球) */ - void *screen0; + screen_backup_t old_screen; int y, x, my_newfd; getyx(&y, &x); - screen0=malloc(screen_backupsize(t_lines, big_picture)); - screen_backup(t_lines, big_picture, screen0); + old_screen.raw_memory = malloc(screen_backupsize(t_lines, big_picture)); + screen_backup(t_lines, big_picture, &old_screen); /* 如果正在talk的話先不處理對方送過來的封包 (不去select) */ my_newfd = i_newfd; @@ -528,8 +527,8 @@ igetch(void) i_newfd = my_newfd; /* 還原螢幕 */ - screen_restore(t_lines, big_picture, screen0); - free(screen0); + screen_restore(t_lines, big_picture, &old_screen); + free(old_screen.raw_memory); move(y, x); redoscr(); continue; diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index d5693304..f9cd01c4 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -268,17 +268,17 @@ talk_request(int sig) } else { unsigned char mode0 = currutmp->mode; char c0 = currutmp->chatid[0]; - void *screen0; + screen_backup_t old_screen; currutmp->mode = 0; currutmp->chatid[0] = 1; - screen0=malloc(screen_backupsize(t_lines, big_picture)); - screen_backup(t_lines, big_picture, screen0); + old_screen.raw_memory = malloc(screen_backupsize(t_lines, big_picture)); + screen_backup(t_lines, big_picture, &old_screen); talkreply(); currutmp->mode = mode0; currutmp->chatid[0] = c0; - screen_restore(t_lines, big_picture, screen0); - free(screen0); + screen_restore(t_lines, big_picture, &old_screen); + free(old_screen.raw_memory); redoscr(); } } diff --git a/mbbsd/screen.c b/mbbsd/screen.c index b9b57b90..b7bde5ff 100644 --- a/mbbsd/screen.c +++ b/mbbsd/screen.c @@ -15,7 +15,6 @@ static int scrollcnt, tc_col, tc_line; #define MODIFIED (1) /* if line has been modifed, screen output */ #define STANDOUT (2) /* if this line has a standout region */ - void initscr(void) { @@ -522,11 +521,15 @@ standend(void) } } -// XXX race: signal handler write to screen, data larger than allocated buf -void screen_backup(int len, const screenline_t *bp, void *buf) +void screen_backup(int len, const screenline_t *bp, screen_backup_t *old) { int i; size_t offset=0; + void *buf = old->raw_memory; + + old->col = t_columns; + old->row = t_lines; + for(i=0;i<len;i++) { memcpy((char*)buf+offset, &bp[i], ((char*)&bp[i].data-(char*)&bp[i])); offset+=((char*)&bp[i].data-(char*)&bp[i]); @@ -544,10 +547,21 @@ size_t screen_backupsize(int len, const screenline_t *bp) return sum; } -void screen_restore(int len, screenline_t *bp, const void *buf) +void screen_restore(int len, screenline_t *bp, const screen_backup_t *old) { int i; size_t offset=0; + void *buf = old->raw_memory; + + // TODO try to be more user friendly. + if (old->col > t_columns || old->row > t_lines) { + move(1, 0); + clrtobot(); + move(2, 2); + outs("偵測到視窗改變大小,畫面繪製將會暫時失效"); + return; + } + for(i=0;i<len;i++) { memcpy(&bp[i], (char*)buf+offset, ((char*)&bp[i].data-(char*)&bp[i])); offset+=((char*)&bp[i].data-(char*)&bp[i]); |