summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-09-06 22:49:08 +0800
committerkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-09-06 22:49:08 +0800
commit471a65e552f18963ef2fa976663bdb61f9c8236c (patch)
treeeafd56689d9da646d682113c6c0f4c6ca302fee6 /mbbsd
parente22d3269f7d450ba90e42073943fc16bcc81a568 (diff)
downloadpttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.tar
pttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.tar.gz
pttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.tar.bz2
pttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.tar.lz
pttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.tar.xz
pttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.tar.zst
pttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.zip
code cleanup
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1162 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/cal.c4
-rw-r--r--mbbsd/friend.c25
-rw-r--r--mbbsd/gomo.c27
-rw-r--r--mbbsd/gomo1.c15
-rw-r--r--mbbsd/io.c78
-rw-r--r--mbbsd/mail.c2
-rw-r--r--mbbsd/page.c4
-rw-r--r--mbbsd/stuff.c5
8 files changed, 65 insertions, 95 deletions
diff --git a/mbbsd/cal.c b/mbbsd/cal.c
index 1567f0c2..89383f99 100644
--- a/mbbsd/cal.c
+++ b/mbbsd/cal.c
@@ -1,4 +1,4 @@
-/* $Id: cal.c,v 1.27 2003/06/22 04:32:38 in2 Exp $ */
+/* $Id$ */
#include "bbs.h"
/* 防堵 Multi play */
@@ -8,7 +8,7 @@ count_multiplay(int unmode)
register int i, j;
register userinfo_t *uentp;
- for (i = j = 0; i < USHM_SIZE; i++) {
+ for (i = j = 0; i < USHM_SIZE; i++) { // XXX linear search
uentp = &(SHM->uinfo[i]);
if (uentp->uid == usernum)
if (uentp->lockmode == unmode)
diff --git a/mbbsd/friend.c b/mbbsd/friend.c
index 39ef2148..16e36c63 100644
--- a/mbbsd/friend.c
+++ b/mbbsd/friend.c
@@ -56,22 +56,15 @@ setfriendfile(char *fpath, int type)
setbfile(fpath, currboard, friend_file[type]);
}
-static unsigned int
+static int
friend_count(char *fname)
{
FILE *fp;
int count = 0;
char buf[200];
-#if 0
- if ((fp = fopen(fname, "r")))
- while (fgets(buf, 200, fp))
- count++;
-#endif
-
- /* rocker.011018: 忘記關檔了... */
if ((fp = fopen(fname, "r"))) {
- while (fgets(buf, 200, fp))
+ while (fgets(buf, sizeof(buf), fp))
count++;
fclose(fp);
}
@@ -218,7 +211,7 @@ friend_delete(char *uident, int type)
setfriendfile(fn, type);
sprintf(fnnew, "%s-", fn);
- if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { // XXX fclose(fp) if nfp fail
+ if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) {
int length = strlen(uident);
while (fgets(genbuf, STRLEN, fp))
@@ -235,11 +228,11 @@ friend_delete(char *uident, int type)
static void
friend_editdesc(char *uident, int type)
{
- FILE *fp, *nfp;
- char fnnew[200], genbuf[200], fn[200];
+ FILE *fp=NULL, *nfp=NULL;
+ char fnnew[200], genbuf[STRLEN], fn[200];
setfriendfile(fn, type);
snprintf(fnnew, sizeof(fnnew), "%s-", fn);
- if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { // XXX fclose(fp) if nfp fail
+ if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) {
int length = strlen(uident);
while (fgets(genbuf, STRLEN, fp)) {
@@ -251,10 +244,12 @@ friend_editdesc(char *uident, int type)
fprintf(nfp, "%-13s%s\n", uident, buf);
}
}
- fclose(fp);
- fclose(nfp);
Rename(fnnew, fn);
}
+ if(fp)
+ fclose(fp);
+ if(nfp)
+ fclose(nfp);
}
/* type == 0 : load all */
diff --git a/mbbsd/gomo.c b/mbbsd/gomo.c
index 3a8fcd5f..0b64e709 100644
--- a/mbbsd/gomo.c
+++ b/mbbsd/gomo.c
@@ -1,4 +1,4 @@
-/* $Id: gomo.c,v 1.12 2003/01/19 16:06:06 kcwu Exp $ */
+/* $Id$ */
#include "bbs.h"
static char *chess[] = {"●", "○"};
@@ -113,7 +113,7 @@ gomo_key(int fd, int ch, Horder_t * mv)
if (ch >= 'a' && ch <= 'o') {
char pbuf[4], vx, vy;
- *pbuf = ch;
+ pbuf[0] = ch;
if (fd)
add_io(0, 0);
oldgetdata(17, 0, "直接指定位置 :", pbuf, sizeof(pbuf), DOECHO);
@@ -130,16 +130,20 @@ gomo_key(int fd, int ch, Horder_t * mv)
} else {
switch (ch) {
case KEY_RIGHT:
- mv->x = (mv->x == BRDSIZ - 1) ? mv->x : mv->x + 1;
+ if(mv->x<BRDSIZ-1)
+ mv->x++;
break;
case KEY_LEFT:
- mv->x = (mv->x == 0) ? 0 : mv->x - 1;
+ if(mv->x>0)
+ mv->x--;
break;
case KEY_UP:
- mv->y = (mv->y == BRDSIZ - 1) ? mv->y : mv->y + 1;
+ if(mv->y<BRDSIZ-1)
+ mv->y++;
break;
case KEY_DOWN:
- mv->y = (mv->y == 0) ? 0 : mv->y - 1;
+ if(mv->y>0)
+ mv->y--;
break;
case ' ':
case '\r':
@@ -164,7 +168,7 @@ int
gomoku(int fd)
{
Horder_t mv;
- int me, he, win, ch;
+ int me, he, ch;
int hewantpass, iwantpass;
userinfo_t *my = currutmp;
Horder_t pool[BRDSIZ*BRDSIZ];
@@ -172,7 +176,6 @@ gomoku(int fd)
HO_init(pool);
me = !(my->turn) + 1;
he = my->turn + 1;
- win = 1;
tick = now + MAX_TIME;
lastcount = MAX_TIME;
setutmpmode(M_FIVE);
@@ -227,7 +230,6 @@ gomoku(int fd)
if (lastcount <= -5 && !my->turn) {
move(19, 40);
outs("對手太久沒下, 你贏了!");
- win = 1;
cuser.five_lose--;
cuser.five_win++;
my->five_win++;
@@ -276,7 +278,6 @@ gomoku(int fd)
}
continue;
} else if (hewantpass) {
- win = 0;
cuser.five_lose--;
cuser.five_tie++;
my->five_tie++;
@@ -292,7 +293,6 @@ gomoku(int fd)
if (ch != sizeof(Horder_t)) {
lastcount = tick - now;
if (lastcount >= 0) {
- win = 1;
cuser.five_lose--;
if (countgomo(pool) >= 10) {
cuser.five_win++;
@@ -302,14 +302,12 @@ gomoku(int fd)
outmsg("對方認輸了!!");
break;
} else {
- win = 0;
outmsg("你超過時間未下子, 輸了!");
my->five_lose++;
break;
}
} else if (mv.x == -2 && mv.y == -2) {
if (iwantpass == 1) {
- win = 0;
cuser.five_lose--;
cuser.five_tie++;
my->five_tie++;
@@ -329,6 +327,7 @@ gomoku(int fd)
continue;
}
if (!my->turn) {
+ int win;
win = chkmv(&mv, he, he == BBLACK);
HO_add(&mv);
hislasttick = tick;
@@ -347,7 +346,6 @@ gomoku(int fd)
passwd_update(usernum, &cuser);
} else
my->five_lose++;
- win = -win;
break;
}
my->turn = 1;
@@ -361,6 +359,7 @@ gomoku(int fd)
continue;
if (!my->turn) {
+ int win;
HO_add(&mv);
BGOTO(mv.x, mv.y);
outs(chess[me - 1]);
diff --git a/mbbsd/gomo1.c b/mbbsd/gomo1.c
index 260ce88f..49d484a5 100644
--- a/mbbsd/gomo1.c
+++ b/mbbsd/gomo1.c
@@ -1,4 +1,4 @@
-/* $Id: gomo1.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */
+/* $Id$ */
#include "bbs.h"
#define QCAST int (*)(const void *, const void *)
@@ -11,12 +11,15 @@ intrevcmp(const void *a, const void *b)
return (*(int *)b - *(int *)a);
}
+// 以 (x,y) 為起點, 方向 (dx,dy), 傳回以 bit 表示相鄰哪幾格有子
+// 如 10111 表示該方向相鄰 1,2,3 有子, 4 空地
+// 最高位 1 表示對方的子, 或是牆
/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; dx,dy: -1,0,+1 */
static int
gomo_getindex(int x, int y, int color, int dx, int dy)
{
int i, k, n;
- for (n = -1, i = 0, k = 1; i < 5; i++, k <<= 1) {
+ for (n = -1, i = 0, k = 1; i < 5; i++, k*=2) {
x += dx;
y += dy;
@@ -73,9 +76,12 @@ dirchk(int x, int y, int color, int limit, int dx, int dy)
if ((style == 3) || (style == 2)) {
int i, n = 0, tmp, nx, ny;
- n = adv[loc >> 1];
+ n = adv[loc / 2];
- ((loc & 1) == 0) ? (n >>= 4) : (n &= 0x0f);
+ if(loc%2==0)
+ n/=16;
+ else
+ n%=16;
ku[x][y] = color;
@@ -110,6 +116,7 @@ getstyle(int x, int y, int color, int limit)
if (ku[x][y] != BBLANK)
return 0x0d;
+ // (-1,1), (0,1), (1,0), (1,1)
for (i = 0; i < 4; i++)
dir[i] = dirchk(x, y, color, limit, i ? (i >> 1) : -1, i ? (i & 1) : 1);
diff --git a/mbbsd/io.c b/mbbsd/io.c
index 0a48893d..6f3cff9e 100644
--- a/mbbsd/io.c
+++ b/mbbsd/io.c
@@ -324,8 +324,6 @@ igetch()
return 0;
}
-#define min(a, b) (((a) > (b)) ? (b) : (a))
-
int
oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo)
{
@@ -338,15 +336,12 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo)
strip_ansi(buf, buf, STRIP_ALL);
if (prompt) {
-
move(line, col);
-
clrtoeol();
-
outs(prompt);
-
x += strip_ansi(NULL, prompt, 0);
}
+
if (!echo) {
len--;
clen = 0;
@@ -357,32 +352,15 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo)
continue;
}
clen--;
- if (echo) {
- ochar(Ctrl('H'));
- ochar(' ');
- ochar(Ctrl('H'));
- }
continue;
}
- //Ptt
-#ifdef BIT8
- if (!isprint2(ch))
-#else
- if (!isprint(ch))
-#endif
- {
- if (echo)
- bell();
+ if (!isprint(ch)) {
continue;
}
if (clen >= len) {
- if (echo)
- bell();
continue;
}
buf[clen++] = ch;
- if (echo)
- ochar(ch);
}
buf[clen] = '\0';
outc('\n');
@@ -392,31 +370,26 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo)
int currchar = 0;
standout();
- for (clen = len--; clen; clen--)
+ for(i=0; i<len; i++)
outc(' ');
standend();
- buf[len] = 0;
+ len--;
+ buf[len] = '\0';
move(y, x);
edit_outs(buf);
clen = currchar = strlen(buf);
while (move(y, x + currchar), (ch = igetkey()) != '\r') {
switch (ch) {
- case KEY_DOWN:
- case Ctrl('N'):
- buf[clen] = '\0'; /* Ptt */
- strncpy(lastcmd[cmdpos], buf, min(clen, 79));
- cmdpos += MAXLASTCMD - 2;
- case Ctrl('P'):
- case KEY_UP:
- if (ch == KEY_UP || ch == Ctrl('P')) {
- buf[clen] = '\0'; /* Ptt */
- strncpy(lastcmd[cmdpos], buf, min(clen, 79));
- }
- cmdpos++;
+ case KEY_DOWN: case Ctrl('N'):
+ case KEY_UP: case Ctrl('P'):
+ strlcpy(lastcmd[cmdpos], buf, sizeof(lastcmd[0]));
+ if (ch == KEY_UP || ch == Ctrl('P'))
+ cmdpos++;
+ else
+ cmdpos += MAXLASTCMD - 1;
cmdpos %= MAXLASTCMD;
- strncpy(buf, lastcmd[cmdpos], min(len, 79));
- buf[len] = 0;
+ strlcpy(buf, lastcmd[cmdpos], len+1);
move(y, x); /* clrtoeof */
for (i = 0; i <= clen; i++)
@@ -449,7 +422,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo)
case Ctrl('Y'):
currchar = 0;
case Ctrl('K'):
- buf[currchar] = 0;
+ buf[currchar] = '\0';
move(y, x + currchar);
for (i = currchar; i < clen; i++)
outc(' ');
@@ -489,20 +462,18 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo)
} /* end case */
} /* end while */
- if (clen > 1)
- for (cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) {
- strlcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1],
- sizeof(lastcmd[cmdpos]));
- strncpy(lastcmd[0], buf, len);
- }
- if (echo)
- outc('\n');
+ if (clen > 1) {
+ strlcpy(lastcmd[0], buf, sizeof(lastcmd[0]));
+ memmove(lastcmd+1, lastcmd, (MAXLASTCMD-1)*sizeof(lastcmd[0]));
+ }
+ outc('\n');
refresh();
}
- if ((echo == LCECHO) && ((ch = buf[0]) >= 'A') && (ch <= 'Z'))
- buf[0] = ch | 32;
+ if ((echo == LCECHO) && isupper(buf[0]))
+ buf[0] = tolower(buf[0]);
#ifdef SUPPORT_GB
if (echo == DOECHO && current_font_type == TYPE_GB) {
+ // FIXME check buffer length
strcpy(buf, hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE));
}
#endif
@@ -528,9 +499,8 @@ getans(char *prompt)
int
getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char *defaultstr)
{
- strncpy(buf, defaultstr, len);
+ strlcpy(buf, defaultstr, len);
- buf[len - 1] = 0;
return oldgetdata(line, col, prompt, buf, len, echo);
}
@@ -553,7 +523,7 @@ rget(int x, char *prompt)
ch = igetch();
if (ch >= 'A' && ch <= 'Z')
- ch |= 32;
+ ch = tolower(ch);
return ch;
}
diff --git a/mbbsd/mail.c b/mbbsd/mail.c
index bca23743..b45bde0c 100644
--- a/mbbsd/mail.c
+++ b/mbbsd/mail.c
@@ -1,6 +1,6 @@
/* $Id$ */
#include "bbs.h"
-char currmaildir[32];
+static char currmaildir[32];
static char msg_cc[] = "\033[32m[群組名單]\033[m\n";
static char listfile[] = "list.0";
static int mailkeep = 0, mailsum = 0;
diff --git a/mbbsd/page.c b/mbbsd/page.c
index e1bcd052..9583f4c9 100644
--- a/mbbsd/page.c
+++ b/mbbsd/page.c
@@ -1,10 +1,10 @@
-/* $Id: page.c,v 1.11 2003/02/11 06:03:31 victor Exp $ */
+/* $Id$ */
#include "bbs.h"
#define hpressanykey(a) {move(22, 0); prints(a); pressanykey();}
#define TITLE "\033[1;37;45m 火車查詢系統 \033[1;44;33m原作者:Heat\033[m"
-void
+static void
print_station(const char *addr[6][100], int path, int *line, int *num)
{
int i;
diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c
index 80428954..9f13b2ef 100644
--- a/mbbsd/stuff.c
+++ b/mbbsd/stuff.c
@@ -1,4 +1,4 @@
-/* $Id: stuff.c,v 1.13 2003/07/20 00:55:34 in2 Exp $ */
+/* $Id$ */
#include "bbs.h"
/* ----------------------------------------------------- */
@@ -158,8 +158,7 @@ trim(char *buf)
int
isprint2(char ch)
{
- return ((ch & 0x80) ? 1 : isprint(ch));
- //return 1;
+ return ((ch & 0x80) || isprint(ch));
}
int