summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/chat.c7
-rw-r--r--mbbsd/go.c8
-rw-r--r--mbbsd/io.c21
-rw-r--r--mbbsd/mbbsd.c7
-rw-r--r--mbbsd/screen.c33
-rw-r--r--mbbsd/talk.c10
6 files changed, 62 insertions, 24 deletions
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);
diff --git a/mbbsd/go.c b/mbbsd/go.c
index 4c20df0b..0cff7430 100644
--- a/mbbsd/go.c
+++ b/mbbsd/go.c
@@ -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;
diff --git a/mbbsd/io.c b/mbbsd/io.c
index 1f7658f2..d0bb1db6 100644
--- a/mbbsd/io.c
+++ b/mbbsd/io.c
@@ -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;