summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-10-31 10:42:22 +0800
committerkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-10-31 10:42:22 +0800
commit70fb5e79c69a2a7bfa09abc5ad54685b573af58c (patch)
tree88816410528068f2a4f6a800cd9822b4f95af87e
parent8d2c3174b3841d6dda2958b3fdfbad7a121bab0c (diff)
downloadpttbbs-70fb5e79c69a2a7bfa09abc5ad54685b573af58c.tar
pttbbs-70fb5e79c69a2a7bfa09abc5ad54685b573af58c.tar.gz
pttbbs-70fb5e79c69a2a7bfa09abc5ad54685b573af58c.tar.bz2
pttbbs-70fb5e79c69a2a7bfa09abc5ad54685b573af58c.tar.lz
pttbbs-70fb5e79c69a2a7bfa09abc5ad54685b573af58c.tar.xz
pttbbs-70fb5e79c69a2a7bfa09abc5ad54685b573af58c.tar.zst
pttbbs-70fb5e79c69a2a7bfa09abc5ad54685b573af58c.zip
eliminate 132 bytes global array
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2296 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--mbbsd/chat.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/mbbsd/chat.c b/mbbsd/chat.c
index caf3f1b8..ac8ace57 100644
--- a/mbbsd/chat.c
+++ b/mbbsd/chat.c
@@ -57,23 +57,26 @@ chat_send(int fd, char *buf)
return (send(fd, genbuf, len, 0) == len);
}
+struct ChatBuf {
+ char buf[128];
+ int bufstart;
+};
+
static int
-chat_recv(int fd, char chatroom[IDLEN], char *chatid)
+chat_recv(struct ChatBuf *cb, int fd, char chatroom[IDLEN], char *chatid)
{
- static char buf[128];
- static int bufstart = 0;
int c, len;
char *bptr;
- len = sizeof(buf) - bufstart - 1;
- if ((c = recv(fd, buf + bufstart, len, 0)) <= 0)
+ len = sizeof(cb->buf) - cb->bufstart - 1;
+ if ((c = recv(fd, cb->buf + cb->bufstart, len, 0)) <= 0)
return -1;
- c += bufstart;
+ c += cb->bufstart;
- bptr = buf;
+ bptr = cb->buf;
while (c > 0) {
len = strlen(bptr) + 1;
- if (len > c && (unsigned)len < (sizeof(buf)/ 2) )
+ if (len > c && (unsigned)len < (sizeof(cb->buf)/ 2) )
break;
if (*bptr == '/') {
@@ -103,10 +106,10 @@ chat_recv(int fd, char chatroom[IDLEN], char *chatid)
}
if (c > 0) {
- memmove(buf, bptr, sizeof(buf)-(bptr-buf));
- bufstart = len - 1;
+ memmove(cb->buf, bptr, sizeof(cb->buf)-(bptr-cb->buf));
+ cb->bufstart = len - 1;
} else
- bufstart = 0;
+ cb->bufstart = 0;
return 0;
}
@@ -306,6 +309,9 @@ t_chat()
int newmail;
int chatting = YEA;
char fpath[80];
+ struct ChatBuf chatbuf;
+
+ memset(&chatbuf, 0, sizeof(chatbuf));
outs(" 驅車前往 請梢候........ ");
if (!(h = gethostbyname("localhost"))) {
@@ -415,7 +421,7 @@ t_chat()
printchatline("◆ 噹!郵差又來了...");
}
if (ch == I_OTHERDATA) {/* incoming */
- if (chat_recv(cfd, chatroom, chatid) == -1) {
+ if (chat_recv(&chatbuf, cfd, chatroom, chatid) == -1) {
chatting = chat_send(cfd, "/b");
break;
}