diff options
author | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-11-06 06:09:09 +0800 |
---|---|---|
committer | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-11-06 06:09:09 +0800 |
commit | 761f24e6af4c4691bcc0bcabba0197c0426d233d (patch) | |
tree | f0951ec853524f391fdc7785f11744ea42c13212 | |
parent | 0e4f3ac7f8a565f8aebf8a337f648a36d3ab86fe (diff) | |
download | pttbbs-761f24e6af4c4691bcc0bcabba0197c0426d233d.tar pttbbs-761f24e6af4c4691bcc0bcabba0197c0426d233d.tar.gz pttbbs-761f24e6af4c4691bcc0bcabba0197c0426d233d.tar.bz2 pttbbs-761f24e6af4c4691bcc0bcabba0197c0426d233d.tar.lz pttbbs-761f24e6af4c4691bcc0bcabba0197c0426d233d.tar.xz pttbbs-761f24e6af4c4691bcc0bcabba0197c0426d233d.tar.zst pttbbs-761f24e6af4c4691bcc0bcabba0197c0426d233d.zip |
Backup screen without hole. Save 8~11kb for normal user.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2314 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/proto.h | 3 | ||||
-rw-r--r-- | include/pttstruct.h | 1 | ||||
-rw-r--r-- | mbbsd/chat.c | 7 | ||||
-rw-r--r-- | mbbsd/go.c | 8 | ||||
-rw-r--r-- | mbbsd/io.c | 21 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 7 | ||||
-rw-r--r-- | mbbsd/screen.c | 33 | ||||
-rw-r--r-- | mbbsd/talk.c | 10 |
8 files changed, 66 insertions, 24 deletions
diff --git a/include/proto.h b/include/proto.h index ee39868e..da996846 100644 --- a/include/proto.h +++ b/include/proto.h @@ -496,6 +496,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, screenline_t *bp, void *buf); +size_t screen_backupsize(int len, screenline_t *bp); +void screen_restore(int len, screenline_t *bp, void *buf); /* stuff */ #define isprint2(ch) ((ch & 0x80) || isprint(ch)) diff --git a/include/pttstruct.h b/include/pttstruct.h index 5edc79c4..6689e851 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -499,6 +499,7 @@ typedef struct { unsigned char emod; /* end of modified data */ unsigned char sso; /* start stand out */ unsigned char eso; /* end stand out */ + /* data 必需是最後一個欄位, see screen_backup() */ unsigned char data[ANSILINELEN + 1]; } screenline_t; diff --git a/mbbsd/chat.c b/mbbsd/chat.c index ac8ace57..5e9be5e3 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -493,12 +493,13 @@ t_chat() } else if (ch == Ctrl('E')) { currchar = strlen(inbuf); } else if (ch == Ctrl('I')) { - screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + void *screen0; - memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + screen0=malloc(screen_backupsize(t_lines, big_picture)); + screen_backup(t_lines, big_picture, screen0); add_io(0, 0); t_idle(); - memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); + screen_restore(t_lines, big_picture, screen0); free(screen0); redoscr(); add_io(cfd, 0); @@ -865,11 +865,11 @@ gochess(int fd) if (ch == 'v') { - //extern screenline *big_picture; - screenline_t* screen0 = calloc(t_lines, sizeof(screenline_t)); + void *screen0; int y, x; - memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + screen0=malloc(screen_backupsize(t_lines, big_picture)); + screen_backup(t_lines, big_picture, screen0); add_io(0, 0); getyx(&y, &x); if (ch == 'v') @@ -888,7 +888,7 @@ gochess(int fd) } */ move(y, x); - memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); + screen_restore(t_lines, big_picture, screen0); free(screen0); add_io(fd, 0); scr_need_redraw = 1; @@ -253,20 +253,23 @@ igetch() if (currutmp != NULL && currutmp->mode != EDITING && currutmp->mode != LUSERS && currutmp->mode) { - screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + void *screen0; int oldroll = roll; int y, x, my_newfd; getyx(&y, &x); - memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + screen0=malloc(screen_backupsize(t_lines, big_picture)); + screen_backup(t_lines, big_picture, screen0); my_newfd = i_newfd; i_newfd = 0; + t_users(); + i_newfd = my_newfd; - memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); + screen_restore(t_lines, big_picture, screen0); + free(screen0); roll = oldroll; move(y, x); - free(screen0); redoscr(); continue; } @@ -315,11 +318,11 @@ igetch() continue; } else if (watermode == -1 && currutmp->msgs[0].pid) { /* 第一次按 Ctrl-R (必須先被丟過水球) */ - screenline_t *screen0; + void *screen0; int y, x, my_newfd; - screen0 = calloc(t_lines, sizeof(screenline_t)); getyx(&y, &x); - memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + screen0=malloc(screen_backupsize(t_lines, big_picture)); + screen_backup(t_lines, big_picture, screen0); /* 如果正在talk的話先不處理對方送過來的封包 (不去select) */ my_newfd = i_newfd; @@ -348,9 +351,9 @@ igetch() i_newfd = my_newfd; /* 還原螢幕 */ - memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); - move(y, x); + screen_restore(t_lines, big_picture, screen0); free(screen0); + move(y, x); redoscr(); continue; } diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 80b541b0..090c887a 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -224,15 +224,16 @@ talk_request(int sig) } else { unsigned char mode0 = currutmp->mode; char c0 = currutmp->chatid[0]; - screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + void *screen0; currutmp->mode = 0; currutmp->chatid[0] = 1; - memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + screen0=malloc(screen_backupsize(t_lines, big_picture)); + screen_backup(t_lines, big_picture, screen0); talkreply(); currutmp->mode = mode0; currutmp->chatid[0] = c0; - memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); + screen_restore(t_lines, big_picture, screen0); free(screen0); redoscr(); } diff --git a/mbbsd/screen.c b/mbbsd/screen.c index 6ad8920b..a58be429 100644 --- a/mbbsd/screen.c +++ b/mbbsd/screen.c @@ -452,3 +452,36 @@ standend() slp->eso = MAX(slp->eso, cur_col); } } + +void screen_backup(int len, screenline_t *bp, void *buf) +{ + int i; + size_t offset=0; + 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]); + memcpy((char*)buf+offset, &bp[i].data, bp[i].len); + offset+=bp[i].len; + } +} + +size_t screen_backupsize(int len, screenline_t *bp) +{ + int i; + size_t sum=0; + for(i=0;i<len;i++) + sum+=((char*)&bp[i].data-(char*)&bp[i]) + bp[i].len; + return sum; +} + +void screen_restore(int len, screenline_t *bp, void *buf) +{ + int i; + size_t offset=0; + 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]); + memcpy(&bp[i].data, (char*)buf+offset, bp[i].len); + offset+=bp[i].len; + } +} diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 33daeda5..9f2791b9 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -3137,22 +3137,22 @@ TalkToAngel(){ void CallAngel(){ static int entered = 0; - screenline_t *screen0; + void *screen0; int x, y; if (!HAS_PERM(PERM_LOGINOK) || entered) return; entered = 1; - screen0 = calloc(t_lines, sizeof(screenline_t)); getyx(&y, &x); - memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + screen0=malloc(screen_backupsize(t_lines, big_picture)); + screen_backup(t_lines, big_picture, screen0); TalkToAngel(); - memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); - move(y, x); + screen_restore(t_lines, big_picture, screen0); free(screen0); + move(y, x); redoscr(); entered = 0; |